akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  int A,B;
  cin>>A>>B;
  cout<<(A+B)%24<<endl;

  
  

  return; 
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N,Y = inputIL()

for i in range(2000+1):
  for j in range(2000-i+1):
    if (Y-i*10000-j*5000)//1000 +i + j == N and N-i-j >= 0:
      print(i,j,N-i-j)
      exit()
print(-1,-1,-1)


Measured memory_bytes: 66536
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n; cin >> n;

    vector<queue<ll>> vec(n);

    rep(i, n){
        rep(j, n-1){
            ll tmp; cin >> tmp; tmp--;
            vec[i].push(tmp);
        }
    }

    
    ll day = 0;
    for(ll x = 0; x < n*(n-1)/2; x++){
        bool flag = true;
        ll count = 0;
        vector<ll> tmp(n);
        rep(i, n){
            if(tmp[i] > 0){
                continue;
            }
            ll player1, player2;
            if(!vec[i].empty()){
                player1 = vec[i].front();
            }else{
                //cout << "empty" << endl;
                count++;
                continue;
            }
            if(tmp[player1] > 0){
                continue;
            }

            if(!vec[player1].empty()){
                player2 = vec[player1].front();
            }else{
                continue;
            }
            
            if(i == player2){
                //cout << day << " " << i << " " << player1 << endl;
                tmp[i]++;
                tmp[player1]++;
                vec[i].pop();
                vec[player1].pop();
                flag = false;
            }
        }

        if(count == n){
            break;
        }

        if(!flag){
            day++;
            /*
            rep(i, n){
                if(tmp[i] > 0){
                    vec[i].pop();
                }
            }
            */
        }else{
            cout << -1 << endl;
            return 0;
        }
    }

    cout << day << endl;

    /*
    while(!vec[0].empty()){
        cout << vec[0].front() << endl;
        vec[0].pop();
    }
    */





}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

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

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) {
        cin >> a[i];
        --a[i];
    }
    vi m(n);
    rep(i, n) ++m[a[i]];
    ll total = 0;
    rep(i, n) {
        total += choose2(m[i]);
    }
    rep(i, n) {
        ll ans = total;
        ans -= choose2(m[a[i]]);
        ans += choose2(m[a[i]]-1);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 4096
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

const ll mod = 1000000007;

int main () {
    ll n; cin >> n;
    ll zero = 0;
    map<pair<ll, ll>, pair<ll, ll>> mp;
    rep(i, n) {
        ll x, y; cin >> x >> y;
        if (x == 0 && y == 0) {
            zero++;
            continue;
        }
        ll g = __gcd(x, y);
        x /= g; y /= g;
        if (y < 0) x = -x, y = -y;
        if (y == 0 && x < 0) x = -x, y = -y;
        bool rot = (x <= 0);
        if (x <= 0) {
            ll tmp = x;
            x = y; y = -tmp;
        }
        if (rot) mp[{x, y}].first++;
        else mp[{x, y}].second++;
    }

    auto ex2 = [&] (ll m) {
        ll res = 1;
        rep(i, m) {
            res *= 2;
            res %= mod;
        }
        return res;
    };
    ll ans = 1;
    for (auto p : mp) {
        ll y = p.second.first;
        ll z = p.second.second;
        //cout << y << endl;
        //cout << z << endl;
        ll now = 1;
        now += ex2(y)-1;
        now += ex2(z)-1;
        now %= mod;
        ans *= now;
        ans %= mod;
        //cout << ans << endl;
    }
    ans += zero;
    ans--;
    ans %= mod;
    if (ans < 0) ans += mod;
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 19060
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

def lcm(n,m):
    return int(n*m/gcd(n,m))

import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace

from queue import PriorityQueue as pq

# from itertools import accumulate
# from collections import deque
import random


def main():
    l = input().strip()
    cnt=0
    for c in l:
        if c=="o":
            cnt+=1
    eprint(cnt)
    eprint(len(l))
    if 15-len(l)  + cnt >= 8:
        eprint(15-len(l)  + cnt)
        print("YES")
    else:
        eprint(15-len(l)  + cnt)
        print("NO")
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 67436
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int h,w,k;cin >> h >> w >> k;
    rep(a,h+1)rep(b,w+1){
        if(w*a + h*b-a*b*2 == k ){
            cout << "Yes" << endl;
            return 0;
        }

    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
        long[] a = Read.longs();
        Console.WriteLine(Math.Abs(a[0]*a[1]-(a[0]+a[1]+a[0]+a[1]-4)));
        Console.ReadLine();
    }
    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
    public static bool IsPrime(int num)
    {
        if (num < 2) return false;
        else if (num ==2) return true;
        else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2)
        {
            if (num % i == 0)
            {
                // 素数ではない
                return false;
            }
        }

        // 素数である
        return true;
    }
}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long() { return long.Parse(Console.ReadLine()); }
    public static long[] longs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); }
    public static int Int() { return int.Parse(Console.ReadLine()); }
    public static int[] ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

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

int main(){
    string str1, str2;

    cin >> str1 >> str2;

    int i = 0;
    if(str2.size() > str1.size()){  
        while(str1[i] != '\0'){
            cout << str1[i] << str2[i];
            i++;
        }
        cout << str2[str2.size() - 1];
    }
    else if(str2.size() < str1.size()){
        while(str2[i] != '\0'){
            cout << str1[i] << str2[i];
            i++;
        }
        cout << str1[str1.size() - 1];
    }
    else{
        while(str1[i] != '\0'){
            cout << str1[i] << str2[i];
            i++;
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
bs = {}
gets.to_i.times{ s = gets.chomp; bs[s] = (bs[s] || 0) + 1 }
rs = {}
gets.to_i.times{ s = gets.chomp; rs[s] = (rs[s] || 0) + 1 }
p [bs.map{ |s,n| n - (rs[s] || 0) }.max, 0].max

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

int main(void){
  int n, k, ans;
  cin >> n >> k;
  int p[n];

  for(int i = 0; i < n; i++){
    cin >> p[i];
  }
  sort(p, p + n);

  ans = 0;
  for (int i = 0; i < k; i++){
    ans += p[i];
  }
  cout <<ans << endl;

}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin>>n;
  int a[n+1]={};
  int two=0,four=0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    if(a[i]%4==0) four++;
    else if(a[i]%2==0) two++;
  }
  if(four>=n/2||2*four+two>=n) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#pragma GCC optimize("O2")
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline int compare(const int*a,const int*b){return *a-*b;}
static inline long IN(void)
{
  long x=0;int f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
int main(void)
{
  int N=IN(),x,p=0,m=0,z=0,sign=0,A[200000],B[200000];
  long K=IN(),count=0,l=-2e18,r=-l,mid;
  while(N--){x=IN();if(x>0)A[p++]=x;else if(x<0)B[m++]=-x;else z++;}
  if(K>1l*m*p&&K<1l*m*p+1l*z*(N-1)/2)return puts("0"),0;
  qsort(A,p,sizeof(int),(int(*)(const void*,const void*))compare);
  qsort(B,m,sizeof(int),(int(*)(const void*,const void*))compare);
  if(K<=1l*m*p)r=1l;else l=-1l;
  while(l<=r)
  {
    mid=(l+r)/2;count=0;
    if(mid>=0)
    {
      int plus=p-1,minus=m-1;count+=1l*z*(p+m)+1l*z*(z-1)/2+1l*p*m;
      rep(i,plus){while(1l*A[i]*A[plus]>mid){plus--;}if(i>=plus){break;}count+=1l*plus-i;}
      rep(i,minus){while(1l*B[i]*B[minus]>mid){minus--;}if(i>=minus){break;}count+=1l*minus-i;}
    }
    else{mid*=-1l;sign=1;int low=0;rep(i,m){while(1l*A[low]*B[m-1-i]<mid&&low<p){low++;}count+=1l*p-low;}}
    if(count>=K){if(sign)r=-mid-1l;else r=mid-1l;}else{if(sign)l=-mid+1l;else l=mid+1l;}
  }
  return OUT(l),0;
}

Measured memory_bytes: 2556
from collections import Counter
from itertools import permutations

n,c = map(int,input().split())
D = []
for i in range(c):
    D.append(list(map(int,input().split())))

co = [Counter() for i in range(3)]
for i in range(n):
    C = list(map(int,input().split()))
    for j in range(n):
        co[(i+j)%3][C[j]-1] +=1
ans = 10**15
perm = permutations([i for i in range(c)],3)

for t in perm:
    temp = 0
    for i in range(3):
        color = t[i]
        for num,cnt in co[i].items():
            temp += D[num][color] * cnt
    ans = min(temp,ans)
print(ans)


Measured memory_bytes: 3436
import java.io.*;
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
       try{ //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        Scanner in = new Scanner(System.in);
        int num[] = {};
        num = new int [3];
        int n = in.nextInt();
        num[0] = n;
        n = in.nextInt();
        num[1] = n;
        n = in.nextInt();
        num[2] = n;
        in.close();

        int t;
        if(num[0] > num[2]){
            t = num[0];
            num[0] = num[2];
            num[2] = t;
        }

       

        int s;
        for(int i = 0; i < 2; i++){
            if(num[i+1] < num[i]){
                s = num[i];
                num[i] = num[i+1];
                num[i+1] = s;
            }
        }
        for(int j = 0; j < 3; j++){
            
        if(j == 2){
            System.out.printf("%d", num[2]);
        }else{
            System.out.printf("%d ", num[j]);
        }
    }
        System.out.printf("\n"); 
    /*}catch(IOException e){
        System.out.println(e);*/
    }  catch(NumberFormatException e){
        System.out.println(e);
    }
    }
}


Measured memory_bytes: 26248
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>

using namespace std;

int main(){
	int num = 1000000;
	int n, m; cin >> n >> m;
	vector<int> a;
	vector<long long> cb;
	for(int i = 0; i < n; i++){
		int a_; cin >> a_;
		a.push_back(a_);
	}
	for(int i = 0; i < m; i++){
		long long b_, c_; cin >> b_ >> c_;
		cb.push_back(c_ * num + b_);
	}
	sort(cb.begin(), cb.end(), greater<long long>());

	vector<int> v;
	v.resize(3 * num);

  
	v.insert(v.end(), a.begin(), a.end());
	int count = 0;
	int cb_num = 0;
  
	while(count < n && cb_num < m){
		vector<int> tmp;
        for(int i = 0; i < cb[cb_num]%num; i++){
        	v.push_back(cb[cb_num]/num);
        }
		count += cb[cb_num]%num;
		cb_num += 1;
	}

	sort(v.begin(), v.end(), greater<int>());
	
	long long ans = 0;
	for(int i = 0; i < n; i++){
		ans += v[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 27252
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;

int main()
{
    int A;
    cin >> A;
    ll index = 1;
    ll res = 0;
loop:
    while (index <= A)
    {
        vector<int> exist(3, false);
        string s = to_string(index);
        rep0(i, s.length())
        {
            if (s[i] == '3')
            {
                exist[0] = true;
            }
            else if (s[i] == '5')
            {
                exist[1] = true;
            }
            else if (s[i] == '7')
            {
                exist[2] = true;
            }
            else
            {
                index += pow(10, s.length() - i - 1);
                goto loop;
            }
        }
        rep0(i, 3)
        {
            if (!exist[i])
            {
                index++;
                goto loop;
            }
        }
        res++;
        index++;
    }
    cout << res;
}


Measured memory_bytes: 4064
def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


n = int(input())

tmp = n - 1
ret = len(make_divisors(tmp)) - 1

tmplen = make_divisors(n)

for item in tmplen:
    if item == 1:
        continue
    val = n
    while True:
        if val % item == 0:
            val = val // item
        else:
            if val % item == 1:
                ret += 1
            break

print(ret)


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

int main(void) {
    int a, b, c;
    cin  >> a >> b >> c;
    if ((100 * a + 10 * b + c) % 4 == 0)
        cout << "YES" << '\n';
    else
        cout << "NO" << '\n';
    return 0;
}

Measured memory_bytes: 256
T=input()
P=input()

class RollingHash():
    BASE1 = 1007
    BASE2 = 2009
    MOD1 = 1000000007
    MOD2 = 1000000009
 
    def __init__(self, s, opt=2):
        self.n = len(s)
        self.opt = opt
        self.hash1 = [0] * (self.n + 1)
        self.power1 = [1] * (self.n + 1)
        if opt == 2:
            self.hash2 = [0] * (self.n + 1)
            self.power2 = [1] * (self.n + 1)
        for i, e in enumerate(s):
            self.hash1[i + 1] = (self.hash1[i] * self.__class__.BASE1 + ord(e)) % self.__class__.MOD1
            self.power1[i + 1] = (self.power1[i] * self.__class__.BASE1) % self.__class__.MOD1
            if opt == 2:
                self.hash2[i + 1] = (self.hash2[i] * self.__class__.BASE2 + ord(e)) % self.__class__.MOD2
                self.power2[i + 1] = (self.power2[i] * self.__class__.BASE2) % self.__class__.MOD2
 
    def get(self, l: int, r: int):
        res1 = self.hash1[r] - self.hash1[l] * self.power1[r - l] % self.__class__.MOD1
        if(res1 < 0):
            res1 += self.__class__.MOD1
        if self.opt == 2:
            res2 = self.hash2[r] - self.hash2[l] * self.power2[r - l] % self.__class__.MOD2
            if(res2 < 0):
                res2 += self.__class__.MOD2
        return (res1, res2) if self.opt == 2 else res1

rh=RollingHash(P+T,opt=1)
ph=rh.get(0,len(P))
N=len(P)
for i in range(N,len(T)+1):
    g=rh.get(i,i+N)
    if g==ph:
        print(i-N)



Measured memory_bytes: 87452
#include <iostream>
#include <string.h>
#include <algorithm>
 
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>
using namespace std;
 
const int N=200010;
int n;
ll a[N];
 
int main() {
scanf("%d",&n);
ll sum=0;
for (int i=0;i<n;i++) {
scanf("%lld",a+i);
sum+=a[i];
}
ll x=0,y=sum;
ll ans=1e18;
for (int i=0;i<n-1;i++) {
x+=a[i];
y-=a[i];
ans=min(ans,abs(x-y));
}
printf("%lld\n",ans);
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define le 1003
using namespace std;
int dp[le][le];
char ch[le][le];
int mod = 1000000007;
int main(){
    //freopen("input.txt", "r", stdin);
    int r, c;
    string s;
    cin >> r >> c;
    for(int i = 0; i < r; i++){
        cin >> s;
        for(int j = 0; j < s.size(); j++) ch[i][j] = s[j];
    }
    dp[0][1] = 1;
    for(int i = 1; i < r + 1; i++){
        for(int j = 1; j < c + 1; j++){
            if(ch[i - 1][j - 1] != '#') dp[i][j] = ((dp[i - 1][j] % mod) + (dp[i][j - 1] % mod)) % mod;
        }
    }
    cout << dp[r][c] << endl;
    return 0;
}


Measured memory_bytes: 8452
N=input()
Z=int(input())
for i in range(Z):
    C=list(input().split())
    at=int(C[1])
    bt=int(C[2])
    if C[0]=="print":
      print(N[at:bt+1])
    elif C[0]=="replace":
      N=N[:at]+C[3]+N[bt+1:]
    else:
      re=N[at:bt+1]
      N=N[:at]+re[::-1]+N[bt+1:]
        



Measured memory_bytes: 5608
# D - Line++

n, x, y = map(int, input().split())
x, y = x - 1, y - 1

cnt = [0] * n
for i in range(n):
    for j in range(i + 1, n):
        dist = min(j - i, abs(x - i) + abs(y - j) + 1)
        cnt[dist] += 1

for i in range(1, len(cnt)):
    print(cnt[i])


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#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 all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 987654321;
const ll MOD = 1000000007;



int main(void) {
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL); 
  cout.tie(NULL);
  //freopen("in.txt", "r", stdin);
  string s;
  ll k;
  cin >> s;
  cin >> k;

  int n = sz(s);
  vl ret;
  ll len = 1;

  rep(i,1,n) {
    if(s[i] != s[i-1]) {
      ret.pb(len/2);
      len = 1;
    } else {
      len++;
    }
  }
  ret.pb(len/2);

  if(s[0] != s[n-1]) {
    ll sum = 0;
    rep(i,0,sz(ret)) {
      sum += ret[i];
    }
    cout << (ll)k * sum << endl;
  } else {
    bool allSame = false;
    len = 0;

    rep(i,0,n) {
      if(s[i] == s[0]) {
        len++;
        if(i == n-1) {
          allSame = true;
        }
      } else {
        break;
      }
    }

    if(allSame) {
      cout << (ll)(n * k) / 2LL << endl;
      return 0;
    } else {
      per(i,0,n) {
        if(s[i] == s[0]) {
          len++;
        } else {
          break;
        }
      }
    }

    int a = ret[0];
    int b = ret[sz(ret)-1];
    int c = len/2;

    ret[0] = 0;
    ret[sz(ret)-1] = 0;
    int sum = 0;
    rep(i,0,sz(ret)) {
      sum += ret[i];
    }
    cout << (ll)sum * k + a + b + (ll)c * (k-1) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<tuple>
#include<stack>
#include<cstdio>
#include<iomanip>
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<string> vs;
Def inf = sizeof(Def) == sizeof(ll) ?2e18:1e9+10;
typedef tuple<int,int,int> tp;

class DIJ{
public:
  struct edge{
    Def to,cost,hu;
  };
  vector<vector<edge> >G;
  Def n,L;
  Def d[100][110];
  DIJ(Def size,Def l){
    n=size;
    L=l;
    G=vector<vector<edge> >(n);
  }
  void add_edge(Def a,Def b,Def c,Def d){
    edge e={b,c,d},ee={a,c,d};
    G[a].pb(e);
    G[b].pb(ee);
  }
  void dij(){
    rep(i,100)rep(j,110)d[i][j]=inf;
    d[0][0]=0;
    priority_queue<tp> q;
    q.push(tp(0,0,0));
    while(!q.empty()){
      Def pos,cost,t;
      tie(cost,pos,t)=q.top();
      q.pop();
      cost*=-1;
      if(cost>d[pos][t])continue;
      rep(i,G[pos].size()){
	edge e=G[pos][i];
	Def to=e.to;
	Def ncost=cost;//ninz
	Def nt=t;//yosan
	if(ncost+e.hu<d[to][nt]){
	  d[to][nt]=ncost+e.hu;
	  q.push(tp(-ncost-e.hu,to,nt));
	}
	//	cout<<to<<" "<<ncost<<" "<<nt<<" "<<e.cost<<endl;
	if(nt+e.cost<=L&&ncost<d[to][nt+e.cost]){
	  d[to][nt+e.cost]=ncost;
	  q.push(tp(-ncost,to,nt+e.cost));
	}
	
      }
    }
    int out = inf;
    rep(i,L+1)out=min((ll)out,(ll)d[n-1][i]);
    cout<<out<<endl;
  }
  
};



int main(){

  int n,m,l;
  while(cin>>n>>m>>l,n){
    DIJ dij(n,l);
    rep(i,m){
      int a,b,c,d;cin>>a>>b>>c>>d;
      a--;b--;
      dij.add_edge(a,b,c,d);
    }
    dij.dij();
  }
}



Measured memory_bytes: 3504
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
int S[10010],T[510],n,q;
int linearsearchS(int t)
{
	int i;
	for(i=1;i<=n;i++)
		if(S[i]==t)
			return 1;
	return 0;
}
int main()
{
	int C=0,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&S[i]);
	scanf("%d",&q);
	for(i=1;i<=q;i++)
		scanf("%d",&T[i]);
	for(i=1;i<=q;i++)
		C+=linearsearchS(T[i]);
	printf("%d\n",C);
	return 0;
}


Measured memory_bytes: 2072
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    int m = 0;
    yukari<int> g(n + 1);
    for (int i = 1; i <= n; i++)
    {
        for (int j = i + 1; j <= n; j++)
        {
            if (j == n + 1 - (n & 1) - i)
            {
                continue;
            }
            g[i].push_back(j);
            m++;
        }
    }
    cout << m << endl;
    for (int i = 1; i <= n; i++)
    {
        for (int j : g[i])
        {
            print(i, j);
        }
    }
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fr(i,a,n) for(i=a;i<n;i++)
#define frn(i,a,n) for(i=a;i<=n;i++)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
//#define map map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>
#define ma 500000
 
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
ll nCrModPFermat(ll n, ll r, ll p) 
{ 
   if (r==0) 
      return 1; 
    ll fac[n+1]; 
    fac[0] = 1; 
    for (int i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
} 

int main()
{
    ll h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    ll count=0;
    count=60-m1;
    count=count+m2;
    count=count+(h2-(h1+1))*60;
    count=count-k;
    cout<<count<<endl;
}
    


Measured memory_bytes: 3636
H,W = map(int,input().split())

Ans = H*W
if H%3==0 or W%3==0:
    Ans = 0
elif H%2==0 and W%2==0:
    Ans = min(H//2,W//2)
else:
    # 全探索するしかない？
    for i in range(1,H):
        t = W//2
        Ans = min(Ans, max(W*i,(H-i)*t,(H-i)*(W-t))-min(W*i,(H-i)*t,(H-i)*(W-t)))
        t = (H-i)//2
        Ans = min(Ans, max(W*i,W*t,W*(H-i-t))-min(W*i,W*t,W*(H-i-t)))
    H,W = W,H
    for i in range(1,H):
        t = W//2
        Ans = min(Ans, max(W*i,(H-i)*t,(H-i)*(W-t))-min(W*i,(H-i)*t,(H-i)*(W-t)))
        t = (H-i)//2
        Ans = min(Ans, max(W*i,W*t,W*(H-i-t))-min(W*i,W*t,W*(H-i-t)))

print(Ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>
#include <cassert>

using namespace std;



int main(){
  long long N, K;
  cin >> N >> K;
  vector<long long> A(N);

  for (int i = 0; i < N; ++i) {
    cin >> A.at(i);
  }

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

  // x以下の組(n)がK個以上ならばtrue
  auto isOK = [&] (long long x) {
    long long n = 0;
    for (const auto a : A) {
      if (a > 0) {
        if (x < 0) {
          n += static_cast<long long>(upper_bound(A.begin(), A.end(), (x-a+1)/a) - A.begin()); //x=-4,-5,-6 a=3 then b<=-2
        } else {
          n += static_cast<long long>(upper_bound(A.begin(), A.end(), x/a) - A.begin()); // x=6,7,8 a=3 then b<=2
        }
      } else if (a < 0) {
        if (x < 0) {
          n += N - static_cast<long long>(lower_bound(A.begin(), A.end(), (x+a+1)/a) - A.begin()); // x=-4,-5,-6 a=-3 then b>=2
        } else {
          n += N - static_cast<long long>(lower_bound(A.begin(), A.end(), x/a) - A.begin()); // x=6,7,8 a=-3 then b>=-2
        }
      } else {
        if (x >= 0) n += N;
      }
      if (a*a <= x) n--;
    }
    assert(n%2==0);
    return n/2 >= K;
  };

  long long ng, ok, mid;
  ng = -1000000000000000001;  // 必ずK番目にくる数より小さい
  ok = 1000000000000000001;  // 必ずK番目にくる数以上
  // 小さい方からK番目にくる数以上の最小(=K番目にくる数)を求める。
  while(abs(ok-ng) > 1) {
    mid = (ng + ok) / 2;
    if (isOK(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }

  std::cout << ok << std::endl;

  return 0;
}


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


int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i=0; i < N; i++){
    cin >> d.at(i);
  }

  int sum = 0;
  for(int i=0; i < d.size(); i++){
    for(int j = i+1; j < d.size(); j++){
      sum += d.at(i) * d.at(j);
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
  const ull mod = 1000000007;

  int n;
  ull tmp;
  vector<ull> a;
  vector<vector<int>> bins;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    a.push_back(tmp);
  }

  for (int i = 0; i < n; i++) {
    vector<int> bin;
    for (int j = 0; j < 60; j++) {
      bin.push_back(a[i] % 2);
      a[i] /= 2;
    }
    bins.push_back(bin);
  }

  ull ans = 0;
  for (int j = 0; j < 60; j++) {
    ull zeros = 0, ones = 0;
    for (int i = 0; i < n; i++) {
      if (bins[i][j] == 0) {
        zeros++;
      } else {
        ones++;
      }
    }

    tmp = (zeros * ones) % mod;
    for (int k = 0; k < j; k++) {
      tmp *= 2;
      tmp %= mod;
    }
    ans += tmp;
    ans %= mod;
  }

  cout << ans << endl;
}


Measured memory_bytes: 87012
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
  
  long N, K;
  unsigned long long ans = 1000000000;

  cin >> N >> K;

  vector<long> h(N), diff(N-1);

  REP(i,N){
    cin >> h[i];
  }

  VSORT(h);

  int tmp = 0;

  REP(i,N-K+1){
    FOR(j, i, i+K-1){
      tmp += h[j+1] - h[j];
    }
    if(tmp < ans) ans = tmp;
    tmp = 0;
  }

  cout << ans << endl;

  
}


Measured memory_bytes: 1792
a =(input().split())
b = [int(b) for b in a]
if abs(b[2] - b[1]) <= b[3] and abs(b[1] - b[0]) <= b[3]:
    print("Yes")
elif abs(b[2] - b[0]) <= b[3]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int a, b;
    cin >> a >> b;
    cout << a*b << "\n";
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
	int number_of_heights;
	cin >> number_of_heights;
	int heghts[number_of_heights];
	for(int i = 0; i < number_of_heights; ++i){
		cin >> heghts[i];
	}
	int ans_assume = 1;
	for(int i = 0; i < number_of_heights - 1; ++i){
		if( heghts[i+1] > heghts[i] )	--heghts[i+1];
      	else if(heghts[i+1] < heghts[i])	ans_assume = 0;
    }
	if(ans_assume == 1){
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
 
}

Measured memory_bytes: 768
c = [[0]*10 for i in range(10)]
for i in range(1,int(input())+1):
  i = str(i)
  c[int(i[0])][int(i[-1])] += 1
ans = 0
for i in range(10):
  for j in range(10):
    ans += c[i][j]*c[j][i]
print(ans)

Measured memory_bytes: 40528
<?php
$s = trim(fgets(STDIN));
$t = trim(fgets(STDIN));

$sAry = str_split($s);
$tAry = str_split($t);
sort($sAry);
rsort($tAry);

$yn = "No";
$m = max(strlen($s), strlen($t));

for($i = 0; $i < $m; $i++) {
	if(!isset($tAry[$i])) break;
	if(!isset($sAry[$i]) || $sAry[$i] < $tAry[$i]) $yn = 'Yes';
	if($sAry[$i] > $tAry[$i]) break;
}
echo $yn."\n";
?>

Measured memory_bytes: 4604
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vint ans(n-1);
    vector<vector<pair<int, int> > > cld(n);
    int k = 0;
    REP(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        cld[a].pb(make_pair(b,i));
        cld[b].pb(make_pair(a,i));
    }
    vint used(n);
    queue<int> q;
    q.push(0);
    vint visited(n,0);
    while(!q.empty()){
        int now = q.front();
        q.pop();
        visited[now]=1;
        int nc = 1;
        for(auto p : cld[now]){
            if(visited[p.fi]==1)continue;
            if(nc==used[now]) nc++;
            ans[p.se]=nc;
            used[p.fi]=nc;
            k = max(k,nc);
            q.push(p.fi);
            nc++;
        }
    }
    cout << k << endl;
    REP(i,n-1){
        cout << ans[i] << endl;
    }
    return 0;
}

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

int main(){
    ll n;cin>>n;
    ll sqrt=pow(n,0.5);
    ll ans=100000000000;
    for(int i=1;i<sqrt+1;i++){
        if(n%i==0){
            int d=max(log10(i)+1,log10(n/i)+1);
            ans=min(ans,(ll)d);
        }
    }
    cout<<ans<<endl;
}

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

const int divisor = 1000000007;

int main(){
	vector<int> ansvec;

	// 100000!までの数をdivisorで割った余りを格納しておく
	long long* factmodary = new long long[100001];
	long long fact = 1;
	for (int i = 1; i <= 100000; i++){
		fact *= i;
		fact %= divisor;
		factmodary[i] = fact;
	}

	for (;;){
		int N, R;
		cin >> N;
		if (N == 0) break;
		cin >> R;

		int* word = new int[N];
		for (int i = 0; i < N; i++) word[i] = i + 1; //まず0番目の単語を入れておく

		for (int i = 0; i < R; i++){
			int s, t;
			cin >> s >> t;
			/* swap */
			int tmp = word[s - 1]; word[s - 1] = word[t - 1]; word[t - 1] = tmp;
		}

		long long ans = 0;
		map<int, int> bubblehist;
		int tmpN = N-1;
		for (int i = 0; i < tmpN; i++){
			int facttime = word[i] - 1;
			int bubblenum;
			map<int, int>::iterator it = bubblehist.find(word[i] - 1);

			if (it != bubblehist.end()){
				bubblenum = it->second + 1;
			}
			else {
				it = bubblehist.find(word[i] + 1);
				if (it != bubblehist.end()){
					bubblenum = it->second;
				}
				else{
					bubblenum = 0;
					for (int j = 0; j < i; j++){
						if (word[j] < word[i]) bubblenum++;
					}
				}
			}
			pair<int, int> p;
			p.first = word[i];
			p.second = bubblenum;
			bubblehist.insert(it, p);
			for (map<int, int>::iterator it2 = bubblehist.upper_bound(word[i]); it2 != bubblehist.end(); it2++) ++(it2->second);

			facttime -= bubblenum;
			ans += factmodary[N - (i + 1)] * facttime;
			ans %= divisor;
		}

		delete[] word;
		ansvec.push_back((int)ans);
	}

	for (vector<int>::iterator it = ansvec.begin(); it != ansvec.end(); it++){
		cout << *it << endl;
	}

	delete[] factmodary;
	return 0;
}

Measured memory_bytes: 6860
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include<cstring>

using namespace std;

typedef long long ll;
ll INF=1e9+7;
ll exgcd(ll a,ll b,ll& x,ll& y)
{
    if(a%b==0)
    {
        x=0,y=1;
        return b;
    }
    ll r,tx,ty;
    r=exgcd(b,a%b,tx,ty);
    x=ty;
    y=tx-a/b*ty;
}

ll comp(ll a,ll b,ll m)
{
    if(a<b)
        return 0;
    if(a==b)
        return 1;
    if(b>a-b)
        b=a-b;
    ll ans=1,ca=1,cb=1;
    for(int i=0; i<b; i++)
    {
        ca=ca*(a-i)%m;
        cb=cb*(b-i)%m;
    }
    ll x,y;
    exgcd(cb,m,x,y);
    x=(x%m+m)%m;
    ans=ca*x%m;
    return ans;
}

ll lucas(ll a,ll b,ll m)
{
    ll ans=1;
    while(a&&b)
    {
        ans=(ans*comp(a%m,b%m,m))%m;
        a=a/m;
        b=b/m;
    }
    return ans;
}

long long fast_power(long long x,long long y)
{
    long long ans=1;
    while (y)
    {
        if (y&1)
            ans=ans*x%INF;
        x=x*x%INF;
        y>>=1;
    }
    return ans;
}
int main()
{
    ll a,b;
    int sum=0;
    int n;
    ll m=1e9+7;

    cin>>n>>a>>b;
    sum=(m*2+fast_power(2,n)-lucas(n,a,m)-lucas(n,b,m)-1)%m;
    cout<<sum<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();
		if(Math.abs(a-b)<=d&&Math.abs(b-c)<=d||Math.abs(a-c)<=d) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

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

ll p[1000001];
void init(){
    for(ll i=0;i<1000001;i++)p[i]=i;
    for(ll i=2;i*i<1000001;i++){
        if(p[i]<i)continue;
        for(ll j=i*i;j<1000001;j+=i){
            if(p[j]==j)p[j]=i;
        }
    }
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    init();
    ll n,maki;
    cin>>n;
    ll a[n];
    map<ll,ll> mp,mp1;
    for(int i=0;i<n;i++){
        cin>>a[i];
        maki=a[i];
        mp1.clear();
        while(maki!=1){
            mp1[p[maki]]++;
            maki/=p[maki];
        }
        for(auto x:mp1){
            mp[x.first]=max(mp[x.first],x.second);
        }
    }
    ll ans=0,lcm=1;
    for(auto x:mp){
        lcm*=modpow(x.first,x.second);
        lcm%=mod;
    }
    for(int i=0;i<n;i++){
        ans+=lcm*modpow(a[i],mod-2);
        ans%=mod;
    }
    cout << ans%mod<<endl;
    return 0;
}


Measured memory_bytes: 8832
N = int(input())
if N <= 9:
    ans = N
elif N <= 99:
    ans = 9
elif N <= 999:
    ans = N - 90
elif N <= 9999:
    ans = 909
elif N <= 99999:
    ans = N - 9090
else:
    ans = 90909

print(ans)


Measured memory_bytes: 38384
#include "bits/stdc++.h"
using namespace std;
//#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}

#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)

// insert→solveでansに全クエリに対する結果が格納
// add,del を変更していろいろなクエリに対応する
// 以下は区間内の数の種類数についてのクエリが飛んでくる場合
 
//現在の状態および値
const int MAX_VAL = 500050;
int a[MAX_VAL]; //要素
int cnt[MAX_VAL]; //区間内のiの個数
int res;        //区間内の種類の数
 
class Mo{
private:
    vector<int> left, right;
    const int width;
    void add(const int id);
    void del(const int id);
 
public:
    vector<int> ans;
 
    Mo(const int n) : width((int)sqrt(n)){}
    //クエリ[l,r)
    void insert(const int l, const int r){
        left.push_back(l), right.push_back(r);
    }
    void solve(){
        const int sz = (int)left.size();
        int nl = 0, nr = 0;
        vector<int> ord(sz);
        iota(ord.begin(), ord.end(), 0);
        sort(ord.begin(), ord.end(), [&](const int a, const int b){
            const int c = left[a] / width, d = left[b] / width;
            return (c == d) ? ((c & 1) ? (right[b] < right[a]) : (right[a] < right[b])) : (c < d);
        });
        ans.resize(sz);
        for(const int id : ord){
            while(nl > left[id]) add(--nl);
            while(nr < right[id]) add(nr++);  //add
            while(nl < left[id]) del(nl++);
            while(nr > right[id]) del(--nr);  //del
            ans[id] = res;
        }
    }
};
 
//idは元の配列のインデックス
void Mo::add(const int id)
{
    if(cnt[a[id]] == 0){
        //cnt[a[id]]++;
        res++;
    }
    cnt[a[id]]++;
}
 
void Mo::del(const int id)
{
    if(cnt[a[id]] == 1){
        //cnt[a[id]]--;
        res--;
    }
    cnt[a[id]]--;
}


int main() {
    IOS();
  int N, Q;
  cin >> N >> Q;
  for(int i = 0; i < N; i++) {
    cin >> a[i];--a[i];
  }
  Mo mo(N);
  for(int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    mo.insert(--l, r);
  }
  mo.solve();
  for(int i = 0; i < Q; i++) {
    cout << mo.ans[i] << "\n";
  }
}


Measured memory_bytes: 15064