akhauriyash/Code-Regression huggingface dataset:
# from functools import reduce
# N,M = map(int, input().split())
# a = list(map(int, input().split()))
# maxmax = 0.5
# List =list()
# for i in range(len(a)):
#     l = list()
#     while a[i]*maxmax<M:
#         l.append(a[i]*maxmax)
#         maxmax+=1
#     maxmax = 0.5
#     List.append(l)
# res = reduce(set.intersection, [set(l_) for l_ in List])
# print(len(res))
from fractions import gcd
 
N, M = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
a = set(a)
 
c = set()
l = 1
for ai in a:
    l *= ai // gcd(l, ai)
    if 0.5 * l > M:
        ans = 0
        break
    j = 0
    while True:
        if (ai >> j) % 2 == 0:
            j += 1
        else:
            c.add(j)
            break
    if len(c) > 1:
        ans = 0
        break
else:
    ans = (M + l // 2) // l
 
print(ans)

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

int main(){
  int x,n,a,tmp;
  int p[102]={0};
  cin >> x >> n;
  if (n ==0){
    cout << x << endl;
    return 0;
  }
  for(int i=0;i<n;i++){
    cin >> tmp;
    p[tmp] += 1;
  }
  for(int i=0;i<=x;i++){
    a = x - i;
    if (p[a] == 0){
      cout << a << endl;
      return 0;
    }
    a = x + i;
    if (p[a] == 0){
      cout << a << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

const int MAX = 100005;
int H[MAX], n, dp[MAX], inf = 1e9;

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

  cin >> n;
  forn(i, 0, n)cin >> H[i];
  fill(dp, dp+n, inf);
  dp[n-1] = 0;
  for(int i = n-1; i >= 0; i--){
      if(i-1 >= 0)dp[i-1] = min(dp[i-1], dp[i]+abs(H[i]-H[i-1]));
      if(i-2 >= 0)dp[i-2] = min(dp[i-2], dp[i]+abs(H[i]-H[i-2]));
  }
  cout << dp[0] << endl;

}





Measured memory_bytes: 4404
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; ++i)
    cin >> a[i];
  auto dave = static_cast<double>(accumulate(a.begin(), a.end(), 0))/N;
  auto iave = (dave < 0. ? -1 : 1)*static_cast<int>(abs(dave) + .5);
  int sum = 0;
  for (int i = 0; i < N; ++i)
    sum += (a[i] - iave)*(a[i] - iave);
  cout << sum;
  return 0;
}


Measured memory_bytes: 256
( N, D) = gets.split(' ').map(&:to_i)
x = []
N.times {|i| 
  a = gets.split(' ').map(&:to_i)
  x.push(a)
}

ret = 0
x.each_with_index { |b, c| 
  (c+1...N).each{|i|
    sum = 0
    (0...D).each{|j|
      sum += (x[c][j] - x[i][j]) ** 2
    }
    ret += 1 if (Math.sqrt(sum).to_i - Math.sqrt(sum)).abs < 0.00001
  }
}
puts ret

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

int main(){
    int N, K, C;
    string S;
    cin >> N >> K >> C >> S;
    vector<int> L(K);
    vector<int> R(K);
    int holiday = 0;
    int x = 0;
    for (int i=0; i<N; i++) {
        if (S.at(i) == 'o' && holiday == 0) {
            L.at(x) = i + 1;
            x++;
            holiday = C;
            if (x == K) break;
        }
        else if (holiday > 0) {
            holiday--;
        }
    }
    holiday = 0;
    x = K-1;
    for (int i=N-1; i>=0; i--) {
        if (S.at(i) == 'o' && holiday == 0) {
            R.at(x) = i + 1;
            x--;
            holiday = C;
            if (x == -1) break;
        }
        else if (holiday > 0) {
            holiday--;
        }
    }
    int count = 0;
    for (int i=0; i<K; i++) {
        if (L.at(i) == R.at(i)) {
            cout << L.at(i) << endl;
        }
    }

}

Measured memory_bytes: 3332
#include <iostream>

using namespace std;
int main()
{
   int N;

    cin >> N;

    unsigned int A[N];
    unsigned int R[N];
    for ( int i=0; i < N; i ++ ) cin >> A[i];

    unsigned long S = 0;
    for ( int i=0; i < N; i ++ ) S += A[i];

    R[0] = S;
    for ( int i = 1; i < N; i += 2 ) {
        R[0] -= 2 * A[i];
    }
//    cout << "S " << S << "  R0 " << R[0] << endl;
    for ( int i = 1; i < N; i ++ ) {
        R[i] = 2 * A[i-1] - R[i-1];
    }

    for ( int i = 0; i < N; i ++ ) {
        cout << R[i] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 2048
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] a = new int[n];
        String[] t = br.readLine().split(" ");
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(t[i]);
        }

        trace(a, n);
        insertionSort(a, n);
    }

    public static void trace(int[] a, int n){
        int i;
        for(i = 0; i < n; i++){
            if(i > 0) System.out.print(" ");
            System.out.print(a[i]);
        }
        System.out.println();
    }

    public static void insertionSort(int[] a, int n){
        int j, i, v;
        for(i = 1; i < n; i++){
            v = a[i];
            j = i - 1;
            while(j >= 0 && a[j] > v){
                a[j+1] = a[j];
                j--;
            }
            a[j+1] = v;
            trace(a, n);
        }
    }

}

Measured memory_bytes: 30440
n,k = map(int,input().split())
l = list(map(int,input().split()))

ans = 10**9

for i in range(n-k+1):
    if l[i] * l[i + k -1] >= 0:
        t = max(abs(l[i]),abs(l[i + k -1]))
    else:    
        t = l[i + k -1] - l[i] + min(abs(l[i]),abs(l[i + k - 1]))
    ans = min(ans,t)
print(ans)

Measured memory_bytes: 14252
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var num = int.Parse(ReadLine());
        int count = 0;
        if (105 <= num) ++count;
        if (135 <= num) ++count;
        if (165 <= num) ++count;
        if (189 <= num) ++count;
        if (195 <= num) ++count;
        WriteLine(count);
    }
}


Measured memory_bytes: 13140
import math
N, M = map(int,input().split())
j=1
for i in range(1, int(math.sqrt(M))+2):
    if M%i==0:
        if i <= M//N and j < i:
            j=i
        if M//i <= M//N and j < M//i:
            j=M//i
print(j)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    int x, t;
    cin >> x >> t;
    cout << max(0, x - t) << endl;
}




Measured memory_bytes: 3596
N, X = map(int, input().split())
l_list = list(map(int, input().split()))

bounce_list = [0] * (N + 1)
for i in range(1, N + 1):
    bounce_list[i] = bounce_list[i - 1] + l_list[i - 1]

print(len([i for i in bounce_list if i <= X]))


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

using namespace std;

const int M = 1046527;
string table[M];

int get_char(char c) {
    if (c == 'A') return 1;
    else if (c == 'C') return 2;
    else if (c == 'G') return 3;
    else if (c == 'T') return 4;
    else return 0;
}

long long get_key(string &text) {
    long long sum = 0, p = 1;
    for (auto &e : text) {
        sum += p * get_char(e);
        p *= 5;    // 5 ** (text.size())
    }
    return sum;
}

int h1(int k) {
    return k % M;
}

int h2(int k) {
    return 1 + (k % (M-1));
}

bool insert(string &text) {
    int i = 0;
    long long k = get_key(text);
    while (true) {
        long long j = (h1(k) + i * h2(k)) % M; 
        if (table[j] == text) return true;
        else if (table[j].empty()) { table[j] = text; return false; }
        else i += 1;
    }
    return false;
}

bool find(string &text) {
    int i = 0;
    long long k = get_key(text);
    while (true) {
        long long j = (h1(k) + i * h2(k)) % M;
        if (table[j] == text) return true;
        else if (table[j].empty()) return false;
        else i += 1;
    }
    return false;
}

int
main(int argc, const char *argv[])
{
    int n;
    cin >> n;
    while (n--) {
        string order, text;
        cin >> order >> text;
        if (order[0] == 'i') {
            insert(text);
        } else {
            if (find(text)) cout << "yes";
            else cout << "no";
            cout << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 24224
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

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

    if(a==b && a==c){
        cout << 1 << endl;
    }
    else if(a==b){
        cout << 2 << endl;
    }
    else if(b==c){
        cout << 2 << endl;
    }
    else if(c==a){
        cout << 2 << endl;
    }
    else{
        cout << 3 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Mx 1000000000005 
#define ll long long  
#define pi 3.141592653
#define vi vector<ll>
#define Mo 1000000007
#define mp make_pair
#define M map<ll,ll>
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define vii vector<pair<ll,ll> > 
#define fi first
#define se second
#define pb push_back
#define ld long double
#define fill(a,x) memset(a,x,sizeof(a))
using namespace std;
bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
  return a.second<b.second;
}
/*vi b=v;
   sort(b.begin(), b.end());
  b.resize(unique(b.begin(), b.end()) - b.begin());
  ll t; cin>>t; fr(f,0,t){ 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 */
int main()
{
  ll n,k; cin>>n>>k;
  ll a[n];
  fr(i,0,n)
    cin>>a[i];

  ll dp[n+1]={0};

  fr(i,2,n+1)
  {
    dp[i]=Mx;
    fr(j,1,k+1)
      if(i-1-j>=0)
        dp[i]=min(dp[i], dp[i-j]+abs(a[i-1]-a[i-1-j]));
  }

  cout<<dp[n];
}

Measured memory_bytes: 5072
#include <stdio.h>

int main() {
    int i,h,m,s=0;
    scanf("%d", &i);
    h = i / 3600;
    m = (i / 60) - (h * 60);
    s = i - (h * 3600) - (m * 60);
    
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k<=a){
        cout << k << endl;
        return 0;
    }else if(k<=a+b){
        cout << a << endl;
        return 0;
    }else{
        int num=k-(a+b);
        cout << a-num << endl;
        return 0;
    }
}

Measured memory_bytes: 3632
from collections import deque

N = int(input())
edges = [[] for i in range(N)]
e_list = []

for i in range(N-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    e_list.append((a,b))
    edges[a].append((b,i))
    edges[b].append((a,i))
ans = [0] * (N-1)

"""
bfs pattern
"""
q = deque()
next_v = edges[0]
for c, (u,i) in enumerate(next_v):
    q.append((u, i, c+1))
    ans[i] = c+1

while q:
    u_p, _, c_p = q.popleft()
    next_v = edges[u_p]
    cnt = 1
    for j, (u, i) in enumerate(next_v):
        # すでに彩色されている辺はダメ
        if ans[i] > 0:
            continue
        # 親と色がかぶったら+1
        if cnt == c_p:
            cnt += 1
        ans[i] = cnt
        q.append((u,i,cnt))
        
        cnt += 1

print(max(ans))
for a in ans:
    print(a)

Measured memory_bytes: 47388
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,a,b,c;
vector<int> L;
void input(){
    fast_io();
    cin >> N >> a >> b >> c;
    for (int i = 0; i < N; i++)
    {
        int l; cin >> l;
        L.push_back(l);
    }
}

int dfs(int i, int x, int y, int z){
    if(i==N){
        if(min({x,y,z})>0) return abs(x-a)+abs(y-b)+abs(z-c)-30;
        else return (int)1e8;
    }
    int ret0 = dfs(i+1,x,y,z);
    int reta = dfs(i+1,x+L[i],y,z)+10;
    int retb = dfs(i+1,x,y+L[i],z)+10;
    int retc = dfs(i+1,x,y,z+L[i])+10;
    return min({ret0,reta,retb,retc});
}

int solve1(){
    // aのために使う棒をきめる。
    int ans = (int)1e9;
    for (int bita = 1; bita < (1<<N); bita++)
    {
        int unuse = ((1<<N)-1)&~bita;
        for (int bitb = unuse; bitb > 0; bitb=(bitb-1)&unuse)
        {
            int unuseC = unuse&~bitb;
            for (int bitc = unuseC; bitc > 0; bitc=(bitc-1)&unuseC)
            {
                int mp = 0;
                mp += 10*(__builtin_popcount(bita)-1);
                mp += 10*(__builtin_popcount(bitb)-1);
                mp += 10*(__builtin_popcount(bitc)-1);
                int la = 0;
                int lb = 0;
                int lc = 0;
                for (int i = 0; i < N; i++)
                {
                    if((bita>>i)&1) la += L[i];
                    if((bitb>>i)&1) lb += L[i];
                    if((bitc>>i)&1) lc += L[i];
                }
                mp += abs(a-la);
                mp += abs(b-lb);
                mp += abs(c-lc);
                ans = min(ans,mp);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

int solve(){
    cout << dfs(0,0,0,0) << endl;
    return 0;
}   

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

Measured memory_bytes: 256
{-# LANGUAGE PartialTypeSignatures #-}
module Main (main) where

import Control.Monad
import qualified Data.ByteString.Char8 as C8
import qualified Data.Char as C
import qualified Data.List as L

main :: IO ()
main = do
  [n,m,q] <- readInts
  replicateM q readInts >>= output . solve n m

solve :: Int -> Int -> [[Int]] -> _
solve n m xs = maximum . map go $ genAscList m n
  where
    go as = sum [ d | [a,b,c,d] <- xs, (as!!(b-1)) - (as!!(a-1)) == c ]

genAscList :: Int -> Int -> [[Int]]
genAscList = gen 1
  where
    gen _ m 0 = [ [] ]
    gen a m n = [ i:is | i <- [a..m], is <- gen i m (pred n) ]

output :: _ -> IO ()
output = print

-- utils
readInts :: IO [Int]
readInts = L.unfoldr (C8.readInt . C8.dropWhile C.isSpace) <$> C8.getLine

Measured memory_bytes: 6624
# Strange Bank
# https://atcoder.jp/contests/abc099/tasks/abc099_c

class MemoizeRecursive
  SIXES = [1, 6, 36, 216, 1296, 7776, 46656].freeze
  NINES = [1, 9, 81, 729, 6561, 59049].freeze

  def main
    @upper_w = gets.chomp.to_i

    @memo = Array.new(@upper_w+1)

    ans = recurse(@upper_w)
    puts ans
  end

  def recurse(rest)
    return rest if rest < 6

    # 既に計算済みの場合はそれを返す
    return @memo[rest] unless @memo[rest].nil?

    # 6円シリーズのrest内最大金額と9円シリーズのrest内最大金額を試す
    result = @upper_w

    w = SIXES.select{|i| i <= rest}.max
    result = [recurse(rest - w) + 1, result].min

    w = NINES.select{|i| i <= rest}.max
    result = [recurse(rest - w) + 1, result].min

    @memo[rest] = result
  end
end

if __FILE__ == $0
  MemoizeRecursive.new.main
end


Measured memory_bytes: 4092
h, w = map(int, raw_input().split())
d = {}
for i in range(h):
    ai = raw_input()
    for j in ai:
        d[j] = d.get(j, 0) + 1

o = len(filter(lambda a:a%2==1, d.values()))
t = len(filter(lambda a:a%4==2, d.values()))

ol = 0
if w % 2 == 1 and h % 2 == 1:
    ol = 1
    tl = (w-1)/2 + (h-1)/2
elif w % 2 == 1:
    tl = h/2
elif h % 2 == 1:
    tl = w/2
else:
    tl = 0

if ol < o:
    print 'No'
elif tl < t:
    print 'No'
else:
    print 'Yes'


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

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

#define sz(v) ((int) v.size())
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())

using namespace std;

int n;
int a[3111];
long long dp[3111][3111];

long long solve(int l, int r) {
    if (l > r) return 0;
    if (dp[l][r] != -1) return dp[l][r];
    return dp[l][r] = max(a[l] - solve(l + 1, r), a[r] - solve(l, r - 1));
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    FOR(i, 1, n) cin >> a[i];
    memset(dp, -1, sizeof dp);
    cout << solve(1, n) << "\n";
    return 0;
}


Measured memory_bytes: 76032
N,K = map(int,input().split())
XY = [list(map(int,input().split())) for _ in [0]*N]

iX = sorted(x for x,y in XY)
iY = sorted(y for x,y in XY)
X = {x:i for i,x in enumerate(iX)}
Y = {y:i for i,y in enumerate(iY)}

c = [[0]*(N+1) for i in [0]*(N+1)]
for x,y in XY:
    c[Y[y]+1][X[x]+1] = 1

for i in range(N):
    ci1 = c[i+1]
    for j in range(N):
        ci1[j+1] += ci1[j]
for i in range(N):
    ci1 = c[i+1]
    ci = c[i]
    for j in range(N):
        ci1[j+1] += ci[j+1]

ans = 10**20
for u in range(N):
    for d in range(u+1,N):
        l = 0
        r = 1
        dY = iY[d]-iY[u]
        cd = c[d+1]
        cu = c[u]
        while r<N:
            if cd[r+1]+cu[l]-cu[r+1]-cd[l] >=K:
                ans = min(ans, (iX[r] - iX[l])*dY)
                l+=1
            else:r+=1

print(ans)

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

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

    ll n;cin >> n;
    vector<ll> mp(3);

    ll ans = 1;
    REP(i, n){
        int a;cin >> a;
        ll cou = 0;
        REP(j, 3){
            if(mp[j] == a){
                cou++;
            }
        }
        REP(j, 3){
            if(mp[j] == a){
                mp[j]++;
                break;
            }
        }
        ans = (ans * cou) % MOD;
    }

    cout << ans << endl;

	return 0;
}


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

int main(void){
	int N,niseN,sum=0;
	cin >> N;
	niseN = N;
	for(int i=0;i<10;i++){
		sum = sum + niseN%10;
		niseN = niseN/10;
	}
	if(N%sum==0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <utility>
#include <algorithm>

using namespace std;

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

    vector<long long int> a(N);
    long long int mx=-1e9, mn=1e9;
    int ix=0, in=0;
    int flag=0;
    bool is_unified=true;
    for(int n=0; n<N; n++) {
        cin >> a[n];
        if(a[n]>mx) ix=n;
        if(a[n]<mn) in=n;
        mx = max(mx, a[n]);
        mn = min(mn, a[n]);
        if((flag==1 && a[n]<0) || (flag==-1 && a[n]>0)) {
            is_unified = false;
        } else if(flag==0) {
            if(a[n]<0) {
                flag=-1;
            } else if(a[n]>0) {
                flag=1;
            }
        }
    }
    if(flag==0) {
        cout << 0 << endl;
    } else {
        if(is_unified) {
            cout << N-1 << endl;
            if(flag==1) {
                for(int n=1; n<N; n++) {
                    cout << n << " " << n+1 << endl;
                }
            } else {
                for(int n=N; n>1; n--) {
                    cout << n << " " << n-1 << endl;
                }
            }
        } else {
            cout << (N-1)*2 << endl;
            if(abs(mx)>abs(mn)) {
                for(int n=1; n<=N; n++) {
                    if(n==ix+1) continue;
                    cout << ix+1 << " " << n << endl;
                }
                for(int n=1; n<N; n++) {
                    cout << n << " " << n+1 << endl;
                }
            } else {
                for(int n=1; n<=N; n++) {
                    if(n==in+1) continue;
                    cout << in+1 << " " << n << endl;
                }
                for(int n=N; n>1; n--) {
                    cout << n << " " << n-1 << endl;
                }
            }
        }
    }


    return 0;
    
}

Measured memory_bytes: 3604
import bisect


def resolve():
    A, B, Q = map(int, input().split())
    INF = 10 ** 18
    s = [-INF] + list(int(input()) for _ in range(A)) + [INF]
    t = [-INF] + list(int(input()) for _ in range(B)) + [INF]
    for q in range(Q):
        x = int(input())
        b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
        res = INF
        for S in [s[b - 1], s[b]]:
            for T in [t[d - 1], t[d]]:
                d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
                res = min(res, d1, d2)
        print(res)


if __name__ == "__main__":
    resolve()


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

using namespace std;

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

    for(int i=0;i<input.length();i++){
        int cnt = 0;
        bool flg = false;
        for(int j=i+1;j<input.length();j++){
            if(input[j]=='B')cnt--;
            else cnt++;
            if(cnt<0)flg = true;
        }
        if(!flg && input[i]!='B')cout << input[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
def solve(N, K, Ds):
    while True:
        c = set([int(c) for c in str(N)])
        if len(c.intersection(Ds)) == 0:
            return N
        N += 1


if __name__ == "__main__":
    N, K = map(int, input().split(" "))
    Ds = set(map(int, input().split(" ")))
    print(solve(N, K, Ds))

Measured memory_bytes: 3060
($n,$m)=glob<>;
$s=0;
$t=1e6;
for(1..$m){
    ($l,$r)=glob<>;
    $s=($l>$s)?$l:$s;
    $t=($t>$r)?$r:$t;
}
print+($s<=$t)?$t-$s+1:0

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int64_t kRem = 1000000007;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	int nums[3] = { -1, -1, -1 };

	int64_t ans = 1;
	FOR_LT(i, 0, n) {
		int num; cin >> num;
		int64_t c = 0;
		bool sumi = false;
		FOR_LT(j, 0, 3) {
			if (nums[j] == num - 1) {
				c++;
				if (!sumi) {
					nums[j]++;
					sumi = true;
				}
			}
		}
		if (!sumi) {
			cout << 0 << endl;
			return 0;
		}
		ans *= c;
		ans %= kRem;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
arr = []
org = gets.split
org.each { |i| arr[i.to_i] = arr[i.to_i].to_i + 1 }
sum = 0
d = []
arr.each_with_index do |g, idx|
  next if g.nil?

  sum += g * (g - 1) / 2
  d[idx] = g - 1
end

org.each do |j|
  puts sum - d[j.to_i]
end

Measured memory_bytes: 23172
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000



int main(){
	
	int N;
	cin>>N;
	
	vector<int> A(N),B(N);
	
	for(int i=0;i<N;i++){
		scanf("%d %d",&A[i],&B[i]);
	}
	
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	
	if(N%2==1){
		cout<<B[N/2]-A[N/2]+1<<endl;
	}
	else{
		int R = B[N/2]+B[N/2-1];
		int L = A[N/2]+A[N/2-1];
		
		cout<<R-L+1<<endl;
	}
		
	
	return 0;
}

Measured memory_bytes: 4844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long ans=0;
		for(long i= 1;i<N+1;i++) {
			if(i%3!=0&&i%5!=0) {
				ans += i;
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 35828
#include <iostream>
#include <stdio.h>
using namespace std;

const int MAXN = 2e5 + 10;
int a[MAXN], vis[MAXN];

int main(void){
    int n, m, cnt = 0;
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++){
        int x, y;
        scanf("%d%d", &x, &y);
        if(x == 1) a[cnt++] = y;
        if(y == 1) a[cnt++] = x;
        if(x == n) vis[y] = 1;
        if(y == n) vis[x] = 1;
    }
    for(int i = 0; i < cnt; i++){
        if(vis[a[i]]){
            puts("POSSIBLE");
            return 0;
        }
    }
    puts("IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 1408
// #include "d.h"
#include <bits/stdc++.h>

using namespace std;

const int L = 128;
const string C = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

int query(const string &t)
{
	cout << "? " << t << "\n";
	int r;
	cin >> r;
	return r;
}

int n, cnt[62];

string f(int l, int r)
{
	if (l == r)
		return string(cnt[l], C[l]);
	string a = f(l, (l+r)/2), b = f((l+r)/2+1, r);
	for (size_t i=0, j=0; i <= a.size(); i++)
		for (; j < b.size() && query(a.substr(0, i) +
				b[j] + a.substr(i)) == n - (int)a.size() - 1;
					i++, j++)
			a.insert(a.begin() + i, b[j]);
	return a;
}

string find_password()
{
	for (int i=0; i<62; i++)
		cnt[i] = L - query(string(L, C[i]));
	n = accumulate(cnt, end(cnt), 0);
	return f(0, 61);
}

int main()
{
	ios_base::sync_with_stdio(false);
	string s = find_password();
	cout << "! " << s << "\n";
	return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INFL = 1e18;
const int MN = 5050;
ll dp[MN][MN];
ll dt[MN];
ll ord[MN];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	ll n,a,b;
	cin >> n >> a >> b;
	for(int i=0;i<n;i++) {
		int t;
		cin >> t;t--;
		ord[t] = i+1;
	}
	memset(dp,0,sizeof(dp));
	for(int i=0;i<n;i++) {
		ll ma = INFL;
		for(int j=0;j<=n;j++) {
			if(i > 0) {
				if(j >= ord[i-1]) {
					ma = min(ma,dt[i-1]);
				}
				ma = min(ma,dp[i-1][j]);
			} else {
				ma = 0;
			}
			if(j == ord[i]) {
				dt[i] = ma;
			}
			dp[i][j] = ma+(j >= ord[i]?a:b);
		}
	}
	ll res = INFL;
	for(int i=0;i<=n;i++) {
		res = min(res,dp[n-1][i]);
	}
	res = min(res,dt[n-1]);
	cout << res << '\n';
}


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

int main() {
  string s;
  cin >> s;
  if(s[2] == s[3]){
    if(s[4] == s[5]){
      cout << "Yes";
    }else{
      cout << "No";
    }
  }else{
    cout << "No";
  }
}

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


class Graph:
    class Edge:
        def __init__(self, to, cost):
            """
            :param to:  終点ノード
            :param cost: 辺の重み
            """
            self.to, self.cost = to, cost

    def __init__(self, n, directed=False, decrement=True, edges=[]):
        self.n = n
        self.directed = directed
        self.decrement = decrement
        self.edges2 = []
        self.parent = [-1]*self.n
        self.info = [-1]*self.n
        for x, y, cost in edges:
            self.add_edge(x, y, cost)

    def add_edge(self, x, y, cost):
        if self.decrement:
            x -= 1
            y -= 1
        self.edges2.append((x, y, cost))
        if self.directed == False:
            self.edges2.append((y, x, cost))

    def bellman_ford(self, start, INF=10**18):
        """
        :return: 負の閉路が存在する場合は -1 を返す
        """
        dist = [INF] * self.n
        if self.decrement:
            start -= 1
        dist[start] = 0
        for cnt in range(self.n):
            for x, y, cost in self.edges2:
                if dist[x] != INF and dist[x] + cost < dist[y]:
                    if cnt == self.n - 1:
                        return -1
                    dist[y] = dist[x] + cost
        return dist

    def bellman_ford2(self, start, goal, INF=10**18):
        """
        :return: 負の閉路が存在する場合は -1 を返す
        """
        dist = [INF] * self.n
        if self.decrement:
            start -= 1
            goal -= 1
        dist[start] = 0
        for cnt in range(2*self.n):
            for x, y, cost in self.edges2:
                if dist[x] != INF and dist[x] + cost < dist[y]:
                    dist[y] = dist[x] + cost
                    if cnt >= self.n:
                        dist[y] = -INF
                if cnt == self.n - 1:
                    res = dist[goal]
        if res == dist[goal]:
            return res

    def draw(self):
        """
        :return: グラフを可視化
        """
        import matplotlib.pyplot as plt
        import networkx as nx

        if self.directed:
            G = nx.DiGraph()
        else:
            G = nx.Graph()
        for x, y, cost in self.edges2:
            G.add_edge(x + self.decrement, y + self.decrement, weight=cost)

        edge_labels = {(i, j): w['weight'] for i, j, w in G.edges(data=True)}
        pos = nx.spring_layout(G)
        nx.draw_networkx(G, pos, with_labels=True)
        nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels)
        plt.axis("off")
        plt.show()



##############################################################################################################

N, M, P = map(int, input().split())
graph = Graph(N, directed=True, decrement=True)
for _ in range(M):
    x, y, cost = map(int, input().split())
    graph.add_edge(x, y, P-cost)

res = graph.bellman_ford2(1,N)
if res is None:
    print(-1)
else:
    print(max(-graph.bellman_ford2(1,N),0))

Measured memory_bytes: 68908
{-# LANGUAGE BangPatterns #-}

import           Control.Monad
import           Data.Bits

main :: IO ()
main = do
    q <- readLn
    replicateM_ q $ do
        [a, b] <- map read.words <$> getLine
        print $ solve a b

solve :: Int -> Int -> Int
solve a b
    | a > b = solve b a
    | a == b = a + b - 2
    | fa 1 >= fb 1 = (a - 1) + fb 1
    | otherwise = (a - 1) + dd + max 0 (fb (dd + 1))
  where
    fa d = a + d
    fb d = b - quot (d * b + fa d) (fa d)
    dd = upperBound 1 b $ \d -> fa d < fb d

-- | assert (p high)
lowerBound :: Int -> Int -> (Int -> Bool) -> Int
lowerBound low high p = go low high
  where
    go !low !high
        | high <= low = high
        | p mid       = go low       mid
        | otherwise   = go (mid + 1) high
      where
        mid = low + unsafeShiftR (high - low) 1
{-# INLINE lowerBound #-}

-- | assert (p low)
upperBound :: Int -> Int -> (Int -> Bool) -> Int
upperBound low high p
    | p high = high
    | otherwise = lowerBound low high (not.p) - 1
{-# INLINE upperBound #-}


Measured memory_bytes: 4932
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

#define Pcll pair<char,ll>

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,pos=0,addb=0,adde=0;cin>>n;
  string s,ans;cin>>s;
  rep(i,n) {
    if(s[i]=='(') adde++;
    else if(adde==0) addb++;
    else adde--;
  }
  rep(i,addb) ans+='(';
  ans+=s;
  rep(i,adde) ans+=')';
  print(ans);
  return 0;
}

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

const int mod = 1e9 + 7;
const int max_n = 2*2000 + 9;

vector<int> fac;

inline int add(int a, int b)
{
	return (0LL + a + b) % mod;
}

inline int mult(int a, int b)
{
	return (1LL*a*b) % mod;
}

int power(int base, int exp)
{
	if(exp == 0)
		return 1;

	auto half = power(base, exp/2);
	auto full = mult(half, half);
	if(exp%2 != 0)
		full = mult(full, base);

	return full;
}

int comb(int n, int r)
{
	if( n == 0 or r == 0)
		return 1;

	auto res = fac[n];
	res = mult(res, power(fac[r], mod - 2));
	res = mult(res, power(fac[n - r], mod - 2));

	return res;
}

int stars(int n, int r)
{
	if(n < 0)
		return 0;
	if(n == 0)
		return 1;

	return comb(n + r - 1, r - 1);
}

void compute_fac()
{
	fac.resize(max_n + 1);
	fac[0] = 1;
	for(int i = 1; i < max_n; i++)
		fac[i] = mult(fac[i - 1], i);
}

void solve()
{
	int n;
	cin >> n;
	int ans = 0;
	for(int r = 1; r <= n; r++)
	{
		ans = add(ans, stars(n - 3*r, r));
	}

	cout << ans << endl;
}

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

	compute_fac();
	solve();
	return 0;
}


Measured memory_bytes: 3676
#include<stdio.h>
int main()
{

    int a,b,z;
    char op;
    char c= '+';
    char d='-';




        while (scanf("%d %c %d",&a,&op,&b)!=EOF)
        {

            if(op== c )
            {
                z=a+b;
                printf("%d\n",z);
            }
            else if(op== d)
            {
                z=a-b;
                printf("%d\n",z);
            }
        }

    return 0;





}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

int main()
{
	string s, t;
	cin >> s >> t;

	string res = "UNRESTORABLE";
	if (s.length() >= t.length())
	{

		for (int i = s.length() - 1; i >= 0; i--)
		{
			bool b = true;
			for (int j = 0; j < t.length(); j++)
			{
				if (s[i + j] == '?')
				{
					continue;
				}
				else if (s[i + j] == t[j])
				{
					continue;
				}
				else
				{
					b = false;
					break;
				}
			}

			if (b)
			{

				res = "";
				for (int j = 0; j < t.length(); j++)
				{
					s[i + j] = t[j];
				}
				for (int j = 0; j < s.length(); j++)
				{
					if (s[j] == '?')
					{
						s[j] = 'a';
					}
				}
				res = s;
			}
		}
	}
	

	cout << res << endl;
}


Measured memory_bytes: 256
n = int(input())

s1 = input()
s2 = input()



i = 0
while i < n:
    #最初ならば表示
    if i==0:
        if s1[i] == s2[i]:
            r = 3
        else:
            r = 6
    else:
        if (s1[i - 1]==s2[i - 1]):
            r *= 2
        elif (s1[i - 1]!=s2[i - 1]) and (s1[i]!=s2[i]):
            r *= 3
    if s1[i]!=s2[i]:
        i += 1
    i += 1
print(r % 1000000007)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc168/abc108_e.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

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

long long modpow(long long a, long long n, long long mod = MOD) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// 有理数の逆を取る
pair<ll, ll> rev_rational(pair<ll, ll> x) {
    ll a = -x.first;
    ll b = x.second;

    if (a < 0) return make_pair(-b, -a);
    return make_pair(b, a);
}
/**
 * 有理数（rational number）クラス
 * 約分された分数表現
 * A / B => {A / gcd(A, B)} / {B / gcd(A, B)}
 * B が負のときは -A, -B と両方にマイナスをかけて分子にマイナスを押し付けておく
 * 
 * A/B <=> -B/A とキャンセルし合う.
 * 数え上げの際は、 2 ^ count(A/B) + 2 ^ count(-B/A) -1 (ゼロの場合を除く)
 */
int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  vector<ll> c(N);
  int zero_zero = 0;
  int no_zero = 0;
  int zero_no = 0;
  map<pl, int> cnt;

  rep(i, N) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) zero_zero++;
    else if (a == 0)
      zero_no++;
    else if (b == 0)
      no_zero++;
    else {
      ll gcdab = gcd(abs(a), abs(b));
      ll A = a / gcdab;
      ll B = b / gcdab;
      if (b < 0) {
        A *= -1;
        B *= -1;
      }
      cnt[make_pair(A, B)]++;
    }
  }

  ll ans = 0;
  // どちらかが１の組み合わせ
  ans = modpow(2, zero_no) + modpow(2, no_zero) - 1;
  ans %= MOD;
  set<pl> used;
  for (auto kv : cnt) {
    auto pa = kv.first;
    if (used.count(pa)) continue;
    auto rev = rev_rational(pa);
    ans *= modpow(2, cnt[pa]) + modpow(2, cnt[rev]) - 1;
    ans %= MOD;
    used.insert(rev);
  }

  ans += zero_zero;
  ans %= MOD;
  ans -= 1;
  if (ans < 0) ans += MOD;

  cout << ans << endl;
}

Measured memory_bytes: 42220
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,ct=1;
    string s;
    cin>>n;
    cin>>s;
    for(i=1; i<n; i++)
    {
        if(s[i]!=s[i-1])
            ct++;
    }
    cout<<ct<<endl;
    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

ll lcm(ll a,ll b){
	return a * b / gcd(a,b);
}





signed main(){
	ll n,ans = 0,memo = 0;
	cin >> n;

	char s[n][10];
	string t[n];

	rep(i,0,n){
		cin >> s[i];

		sort(s[i],s[i]+10);
		t[i] = s[i];
	}

	sort(t,t+n);

	rep(i,1,n){
		if(t[i] == t[i-1]){
			memo++;
		}
		else{
			ans += memo*(memo+1)/2;
			memo = 0;
		}
	}

	ans += memo*(memo+1)/2;

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

Measured memory_bytes: 6656
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int X, A;

void solve() {
	cin >> X >> A;
	cout << (X < A ? 0 : 10) << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
import math

n, a, b= map(int, input().split())  #1行に複数の入力値を取得し、異なる変数に入れる

def digit(n):	#ある整数の１の位を導出する関数を定義
	ans = n % 10
	return ans

total = 0

for i in range (1, n + 1):      #１からNまでの全ての整数について探索
	ans = digit(i)             #ansにiの一の位を追加    834 → 8
	x = math.floor(i / 10)     #xにiの十の位以降を代入、一の位は切り捨て   834 → 83

	while x != 0:              #834→83→8→0のように、０になるまで上記の作業を繰り返す
		ans = ans + digit(x)
		x = math.floor(x / 10)

	if 	a <= ans <= b:         #各桁の値の合計がa以上b以下ならtotalに追加
		total = total + i

print(total)


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<int> a(n);
    cin >> a;
    each (i, a) --i;
    int curr = 0;
    map<int, int> cost;
    cost[curr] = 0;
    while (curr != 1) {
      int next = a[curr];
      if (cost.count(next)) break;
      cost[next] = cost[curr] + 1;
      curr = next;
    }
    cout << (cost.count(1) ? cost[1] : -1) << endl;
  }

  return 0;
}


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

Measured memory_bytes: 596
N = int(input())
T, A = map(int, input().split())
H = [int(i) for i in input().split()]
CT, Ans = float("inf"), 0
for i in range(N):
    Av = T - H[i] * 0.006
    if CT > abs(Av - A):
        CT, Ans = abs(Av-A), i
print(Ans+1)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=100005;
i64 f[maxn],g[maxn];
int n,m,a,b;
int main(){
	read(n);read(m);read(a);
	i64 sum=0,ans=1e18;
	rep(i,1,n-1){
		read(b);
		sum+=b-a;
		f[a+1]+=a+1;
		f[b+1]-=a+1;
		g[a+1]++;
		g[b+1]--;
		if(a>b){
			sum+=m;
			f[1]+=a+1-m;
			f[b+1]+=m;
			g[1]++;
		}a=b;
	}
	ans=sum;
	rep(i,1,m){
		f[i]+=f[i-1];
		g[i]+=g[i-1];
		ans=min(ans,sum+f[i]-g[i]*i);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

P rotate(P p){
    P ans;
    ans = mp(-p.se, p.fi);
    return ans;
}

int main() {
    vec x(4), y(4);
    P p;
    rep(i,2) cin>>x[i]>>y[i];
    p = mp(x[1] - x[0], y[1] - y[0]);

    rep(i,2){
        p = rotate(p);
        x[i+2] = x[i+1] + p.fi;
        y[i+2] = y[i+1] + p.se;
        cout<<x[i+2]<<' '<<y[i+2];
        if(i == 0) cout<<' ';
    }
    cout<<endl;
}


Measured memory_bytes: 256
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
// https://atcoder.jp/contests/abc169/tasks/abc169_b
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll ans = 1;
    ll limit = 1e18;
    ll n;
    cin >> n;
    vector<ll> v(n);
    for(int i = 0;i<n;i++){
        cin >> v[i];
        if(v[i] == 0)
            ans = 0;
    }
    if(ans != 0){
        for(int i = 0;i<n;i++){
            ll e = v[i];
            if(ans > limit / e){
                ans = -1;
                break;
            }
            else{
                ans *= e;
            }
        }
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 3984
bingo = [list(map(int, input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]

aa = [0] * 8
for i in range(3):
    for j in range(3):
        if bingo[i][j] in b:
            aa[i] += 1
            aa[j+3] += 1
            if i == j:
                aa[-2] += 1
            if i + j == 2:
                aa[-1] += 1
ans = 'No'
for a in aa:
    if a >= 3:
        ans = "Yes"
        break
print(ans)


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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N; i++) {
        cin >> h.at(i);
    }
    int sum = 0;
    int sum_0 = 0;
    int start = 0;
    int fin = N;
    bool flag = true;
    while (flag) {
        for (int i = 0; i < N-1; i++) {
            sum_0 += h.at(i);
            if (h.at(i) == 0 && h.at(i+1) != 0) {
                start = i+1;
            }
            if (h.at(i) != 0 && h.at(i+1) == 0) {
                fin = i+1;
                break;
            }
        }
        if (sum_0 == 0 && h.at(N-1) == 0) {
            flag = false;
            continue;
        }
        for (int i = start; i < fin; i++) {
            h.at(i)--;
        }
        sum++;
        sum_0 = 0;
        start = 0;
        fin = N;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second

using namespace std;
typedef long long ll;
const int MAXN = 1005;
int n,m,a,b,ans[MAXN][MAXN];
priority_queue<pii> pq;
queue<pii> tmp;

int main()
{
	cin >> n >> m >> a >> b;
	int x = -1, y = -1;
	for(int i = 0; i<=n; i++)
	    for(int j = 0; j<=m; j++)
			if((2*a-m)*i-a*n==(2*b-n)*j-b*m)
				x = i, y = j;
	if(x<0)
	{
	    cout << -1 << endl;
		return 0;
	}
	for(int i = 1; i<=m; i++)
		pq.push(mp(i<=y?b:n-b,i));
	for(int i = 1; i<=n; i++)
	{
		int t = i<=x?a:m-a;
		pii now;
		for(int j = 1; j<=t; j++)
		{
			now = pq.top(), pq.pop();
			ans[i][now.se] = 1, now.fi--;
			tmp.push(now);
		}
		while(!tmp.empty())
			pq.push(tmp.front()), tmp.pop(); 
	}
	for(int i = 1; i<=n; i++)
	{
		for(int j = 1; j<=m; j++)
			printf("%d",ans[i][j]);
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 5120