akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N = ii()
    A = lmis()
    l = 1
    for a in A:
        l = lcm(l, a)
    print(sum(l//a for a in A) % N1097)


main()


Measured memory_bytes: 6196
def C_AntiDivision():
    from sys import version_info
    try:
        from math import gcd
    except:
        from fractions import gcd
    a,b,c,d = map(int, input().split())
    total = b - a + 1
    total_c = (b // c) + (-a // c) + 1
    total_d = (b // d) + (-a // d) + 1
    gcd_cd = c*d // gcd(c,d)
    total_cd = (b // gcd_cd) + (-a // gcd_cd) + 1
    #print(total_c, total_d, total_cd, gcd_cd)
    print(int(total - total_c - total_d + total_cd))

if __name__ == "__main__":
    C_AntiDivision()

Measured memory_bytes: 5048
n = int(input())
w = [input() for i in range(n)]
    
for i in range(n-1):
    if w[i][-1] != w[i+1][0]:
        print("No")
        break
    elif w[i] in w[i+1:]:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 3060
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ a, b ] <- readInts
	putStrLn $ min ( replicate a ( intToDigit b ) ) ( replicate b ( intToDigit a ) )

Measured memory_bytes: 380
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
int a[114514],gu[114514],ki[114514];
signed main(){
	ic(n)
	int ue=0;
	int keta=0;
	int nn=n;
	if(n<10){
		c(n)
		return 0;
	}	
	rep(0,i,20){
		if(nn<10){
			ue=nn;
			keta=i;
			break;
		}
		nn=nn/10;
	}
	int ss=n+1;
	rep(0,i,20){
		if(ss%10==0)ss=ss/10;
		else break;
		if(ss<10){
			c(ue+keta*9)
			return 0;
		}
	}
	c(ue-1+keta*9)
}					

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAX =1e5+5;
int dp[MAX],h[MAX];
int n,k;
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++)    cin>>h[i];

    for(int i=1;i<n;i++)
        {
                 dp[i]=INT_MAX;
            for(int j=1;j<=k;j++){
            if(i-j>=0)
                dp[i]=min(dp[i],dp[i-j]+(abs(h[i]-h[i-j])));

            }

        }

   //     for(int i=0;i<n;i++)    cout<<dp[i]<<" ";
        cout<<dp[n-1];
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define debug(x) cerr << "\n" \
                      << #x << " = " << x << ".\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define print(xx) cout << (xx) << endl
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
const int INF = ((1LL << 30) + (1LL << 29));
const ll MOD = 1000000007;

/* 
*/
//================== INPUT ========================
int N;
vector<int> A;
vector<int> B;
//=================================================
//=================================================
void input()
{
    cin >> N;
    A.resize(N+1);
    B.resize(N);
    rep(i,N+1){
        cin>>A[i];
    }
    rep(i,N){
        cin>>B[i];
    }
}
//=================================================
void solve()
{
    // monster A[i]
    // hero B[i]

    int ans = 0;
    // 各勇者について
    for (int i=N-1; i>=0; --i){
        if (A[i+1] > 0){
            if (A[i+1] <= B[i]){
                B[i] -= A[i+1];
                ans += A[i+1];
                ans += min(A[i],B[i]);
                A[i] = max(0LL, A[i]-B[i]);
            }
            else {
                ans += B[i];
            }
        }
        else {
            ans += min(A[i],B[i]);
            A[i] = max(0LL,A[i]-B[i]);
        }
        

    }
    cout<<ans<<endl;
}

//=================================================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 1920
function Main(input) {
	input = input.split(" ");
    const a = parseInt(input[0], 10);
    const b = parseInt(input[1], 10);

    if (b % a == 0) {
        console.log(b + a);
    } else {
        console.log(b - a);
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;

#define INF 100000000

typedef pair < int, int >P;

int di[4] = { 1, 0, -1, 0 };
int dj[4] = { 0, 1, 0, -1 };

int main()
{
	int H, W;
	cin >> H >> W;
	vector < string > S(H);
	for (int i = 0; i < H; i++) {
		cin >> S[i];
	}

	int ans = 0;

	for (int si = 0; si < H; si++) {
		for (int sj = 0; sj < W; sj++) {
			if (S[si][sj] == '#')
				continue;
			vector < vector < int >>dist(H, vector < int >(W, INF));
			dist[si][sj] = 0;

			queue < P > q;
			q.push(P(si, sj));
			while (!q.empty()) {
				P p = q.front();
				q.pop();
				for (int idx = 0; idx < 4; idx++) {
					int dx = p.second + dj[idx];
					int dy = p.first + di[idx];
					if (0 <= dx && dx < W && 0 <= dy
					    && dy < H && S[dy][dx] != '#'
					    && dist[dy][dx] == INF) {
						dist[dy][dx] =
						    dist[p.first][p.second] + 1;
						q.push(P(dy, dx));
					}
				}
			}

			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if (dist[i][j] != INF) {
						ans = max(ans, dist[i][j]);
					}
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

for a,b in zip(sorted(A), sorted(B)):
    if a>b:
        print('No')
        exit()

BA = [(b,a) for a,b in zip(A,B)]
BA.sort()

AI = [(a,i) for i,(b,a) in enumerate(BA)]
AI.sort()

class UnionFind:
    def __init__(self,N):
        self.parent = [i for i in range(N)]
        self.rank = [0] * N
        self.count = 0
    def root(self,a):
        if self.parent[a] == a:
            return a
        else:
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]
    def is_same(self,a,b):
        return self.root(a) == self.root(b)
    def unite(self,a,b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb: return
        if self.rank[ra] < self.rank[rb]:
            self.parent[ra] = rb
        else:
            self.parent[rb] = ra
            if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1
        self.count += 1

uf = UnionFind(N)
for j,(a,i) in enumerate(AI):
    uf.unite(i,j)
roots = set()
for i in range(N):
    roots.add(uf.root(i))
if(len(roots) > 1):
    print('Yes')
    exit()

for a,b in zip(list(sorted(A))[1:], sorted(B)):
    if a <= b:
        print('Yes')
        exit()
print('No')

Measured memory_bytes: 33608
N = int(input())
A = [[] for _ in range(2)]
for i in range(2):
    A[i] = list(map(int,(input().split())))
u = [0]*N
d = [0]*N
u[0] = A[0][0]
d[0] = sum(A[1])
for i in range(1,N):
    u[i] = u[i-1] + A[0][i]
for i in range(1,N):
    d[i] = d[i-1] - A[1][i-1]
ans = []
for i in range(N):
    ans.append(u[i]+d[i])

print(max(ans))

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

/*
#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")*/

#define I inline void 
#define S struct 
#define vi vector<int> 
#define vii vector<pair<int,int>>
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std ; 
using ll = long long ; 
using ld = long double ; 

const int N = 1e5 + 7 , mod = 1e9 + 7 ; 
const int inf = N ; 
// How interesting!

int n ;

ll faspow(ll x , ll y){
        if(!y)
                return 1ll ; 
        ll ret = faspow(x , y/2) ; 
        ret = 1ll * ret * ret %mod ; 
        if(y&1)
                ret = 1ll * ret * x % mod ; 
        return ret; 
}

int main(){
        ios_base::sync_with_stdio(0) ; 
        cin.tie(0) ;
       // freopen("in.in" , "r" , stdin) ; 
     
        cin >> n; 

        ll ans = faspow(10 , n) ; 
        ans -= faspow(9 , n) ; 
        ans -= faspow(9 , n) ; 
        ans += faspow(8 , n) ; 
        ans = (ans % mod + mod) %mod ; 
        cout<< ans; 

        return 0 ; 
}

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

/* REPmacro */
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)

/*alias*/
//#define ALL(x) (x).begin(),(x).end()
//#define SZ(x) ((int)(x).size())
//#define F first
//#define S second
#define PB push_back
#define MP make_pair 

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

/* func */
int gcd(int a,int b){return b?gcd(b,a%b):a;}

/*struct*/
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;


/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;

//#define int long long

signed main()
{
  string s;
  cin >> s;
  if(s[3] == '7') s[3] = '8';
  cout << s;
  
  return 0;
}

Measured memory_bytes: 256
from itertools import product

n = int(input())
s = input()
ans = 0
for a, b, c in product(map(str, range(10)), repeat=3):
    ai = s.find(a)
    bi = s.find(b, ai + 1)
    ci = s.find(c, bi + 1)
    if ai != -1 and bi != -1 and ci != -1:
        ans += 1
print(ans)


Measured memory_bytes: 63216
#include <cstdint>

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

  u64 a;

public:
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

#include <utility>

template <class T, class U> constexpr T power(T x, U exp) {
  T ret = static_cast<T>(1);
  while (exp) {
    if (exp % static_cast<U>(2) == static_cast<U>(1))
      ret *= x;
    exp /= static_cast<U>(2);
    x *= x;
  }
  return ::std::move(ret);
}

#include <iostream>
#include <vector>

int main() {
  using mint = modint<1000000007>;

  int b, w;
  std::cin >> b >> w;
  int n = b + w;

  std::vector<mint> fact(n);
  fact[0] = 1;
  for (int i = 1; i < n; ++i) {
    fact[i] = fact[i - 1] * i;
  }
  const auto comb = [&fact](int n, int r) {
    return fact[n] / fact[r] / fact[n - r];
  };

  mint p = 0, q = 0;

  for (int i = 1; i <= n; ++i) {
    std::cout << ((mint(1) - p + q) / 2).value() << std::endl;

    if (i >= b) {
      p += comb(i - 1, b - 1) / power(mint(2), i);
    }
    if (i >= w) {
      q += comb(i - 1, w - 1) / power(mint(2), i);
    }
  }

  return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 50;
int n, m;
int far[maxn];
int Rank[maxn];
int find(int x){
	if(far[x] == x)return x;
	else return far[x] = find(far[x]);
}
void unite(int x,int y){
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(Rank[x] > Rank[y]) far[y] = x;
	else
	{
		far[x] = y;
		if(Rank[x] == Rank[y]) Rank[y]++;
	}
}
bool check(int x,int y){
	return find(x) == find(y);
}
void init(int n){
	for(int i = 0;i <= n;i++)
	{
		far[i] = i;
		Rank[i] = 0;
	}
}
int vis[maxn];
int main()
{
    std::ios::sync_with_stdio(false);
    cin >> n >> m;
    init(n);
    while(m--)
    {
        int a, b;
        cin >> a >> b;
        if(!check(a, b)){
            unite(a, b);
        }
    }
    int ans = 0;
    for(int i = 1;i <= n;i++){
        vis[find(i)]++;
        ans = max(vis[find(i)], ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5920
//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e5 + 10;
const ll mod = 1e9 + 7;

ll dp[N];
vector < int > d[N];

ll Pow(ll a, ll b){
    if (b == 0)
        return 1;
    ll res = Pow(a, b / 2);
    res = res * res % mod;
    if (b & 1)
        res = res * a % mod;
    return res;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, k;
    cin >> n >> k;
    for (int i = 2; i <= k; i ++)
        for (int j = i; j <= k; j += i)
            d[j].push_back(i);
    for (int i = 1; i <= k; i ++){
        dp[i] = (Pow(i, n) - Pow(i - 1, n)) % mod;
        for (int x : d[i])
            dp[i] = (dp[i] - dp[i / x]) % mod;
    }
    for (int i = 1; i <= k; i ++)
        dp[i] = (dp[i] + dp[i - 1]) % mod;
    ll ans = 0;
    for (int i = 1; i <= k; i ++)
        ans = (ans + i * dp[k / i] % mod) % mod;
    ans = (ans + mod) % mod;
    cout << ans;
    return 0;
}


Measured memory_bytes: 14260
def ok?(s, t)
  hs = Hash.new(0)
  s.chars.map { |c| hs[c] += 1 }
  t.chars.map { |c| return if hs[c] == 0 }
  true
end

s = gets.chomp
t = gets.chomp

if !ok?(s, t)
  p -1
  exit
end

pos = Hash.new{|h,k| h[k]=[]}
s.each_char.with_index do |c, i|
  pos[c] << i
end
l = 0
prev_i = pos[t[0]][0]
t[1..-1].each_char do |c|
  j = pos[c].bsearch{|x| x > prev_i}
  prev_i = j || pos[c][0]
  l += 1 if !j
end

p s.size * l + (prev_i + 1)





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

// #define TEST_CASES
using ll = long long;
#define ff first
#define ss second
const int N = 2001;
const ll mod = 1e9 + 7;
ll memo[N][N];

ll c(ll n, ll k)
{
	if (k > n or k < 0)
		return 0LL;
	if (k == n or k == 0)
		return 1LL;
	if (k == n - 1 or k == 1)
		return n;
	if (memo[n][k] != 0) 
		return memo[n][k];
	return memo[n][k] = 
		( c(n - 1, k) + c(n - 1, k - 1) ) % mod;
}

void solve()
{
	int n, k;
	cin>>n>>k;
	for (ll i = 1; i <= k; i++)
	{
		ll ans = c(n - k + 1LL, i);
		ans = (ans * c(k - 1, i - 1)) % mod;
		cout<<ans<<endl;
	}
}

int main()
{
	int t = 1;
#ifdef TEST_CASES
	cin>>t;
#endif
	while(t--)
	{
		solve();
	}
}



Measured memory_bytes: 30080
#include <iostream>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  if((n-k)%(k-1)!=0) cout << (n-k)/(k-1)+2<<endl;
  else{
    cout << (n-1)/(k-1)<<endl;//(n-k)/(k-1)+1
  }
}


Measured memory_bytes: 256
n=int(input())
T=[int(input()) for i in range(n)]

#最大公約数
def gcd(x,y):
  r=x%y
  return gcd(y,r) if r else y
#最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

k=T[0]
#リスト内最小公倍数
for i in T:
  k=lcm(k,i)
print(k)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

int tts[1000];

int main() {
    int n;
    while (cin >> n, n) {
        bool god_p = false;
        int p_max = -1;
        map<int, int> ts;
        fill_n(tts, sizeof(tts) / sizeof(tts[0]), 0);
        for (int i = 0; i < n; i++) {
            string d;
            int hh, mm, p;
            char e;
            cin >> d >> hh >> e >> mm >> e >> p;
            p_max = max(p_max, p);
            int t1 = hh * 60 + mm;
            if (e == 'I') {
                ts[p] = t1;
                if (p == 0) {
                    god_p = true;
                }
                continue;
            }
            int t0 = ts[p];
            ts.erase(p);
            if (p == 0) {
                for (map<int, int>::iterator it = ts.begin(); it != ts.end(); it++) {
                    tts[it->first] += t1 - max(t0, it->second);
                }
                god_p = false;
                continue;
            }
            if (god_p) {
                tts[p] += t1 - max(t0, ts[0]);
            }
        }
        int tt_max = 0;
        for (int i = 1; i <= p_max; i++) {
            tt_max = max(tt_max, tts[i]);
        }
        cout << tt_max << endl;
    }
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,i,k;
  cin>>n;
  k=0;
  for(i=0;i<n;i++){
    cin>>a;
    if(a==k+1) k++;
  }
  if(k==0) cout<<-1<<endl;
  else cout<<n-k<<endl;
}

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


int main(){
  int n,m,x;
  cin>>n>>m>>x;
  int a[n][m];
  vector <int> c(n);
  rep(i,n){
    cin>>c[i];
    rep(j,m) cin>>a[i][j];
  }
  
  int ans=INF;
  rep(s,1<<n){
    int cost=0;
    vector<int>d(m);
    rep(i,n){
      if(s>>i&1){
        cost +=c[i];
        rep(j,m) d[j] +=a[i][j];
      }
    }
    bool ok=true;
    rep(j,m) if(d[j]<x) ok=false;
    if(ok) ans=min(ans,cost);
  }
  if(ans==INF) cout<<-1<<endl;
  else cout<<ans<<endl;
  return 0;
}
        
    
     
      
    
  
  
  
 



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

const int MAX_N=50;
int k=1;
int N;
pair<int,int> v[MAX_N+1];

int main(){
  while(1){
    float ans=0;
    cin >> N;
    if(N==0)break;
    for(int i=0;i<N;i++){
      cin >> v[i].first >> v[i].second;
    }
    for(int i=1;i<N-1;i++){
      ans+=(v[i].first-v[0].first) * (v[i+1].second-v[0].second)
	- (v[i].second-v[0].second) * (v[i+1].first-v[0].first);
    }
    if(ans < 0) ans=-ans;
    ans*=0.5;
    cout << fixed << setprecision(1) << k << " " << ans << endl;
    k++;
  }
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str;
  int ans,snokazu;
  ans=0;
  snokazu=0;
  cin>>str;
  for(int i=0; i<str.size(); i++){
    if(str.at(i)=='S'){
      snokazu=snokazu+1;
    }
    else if(snokazu==0){
      ans=ans+1;
    }
    else{
      snokazu=snokazu-1;
    }
  }
  cout<<ans*2;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    string O, E;
    string ans = "";
    cin >> O;
    cin >> E;

    for(int i = 0; i < E.size(); i++){
        ans += O[i];
        ans += E[i];
    }
    if(O.size() - E.size() != 0) ans += O[O.size()-1];

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


Measured memory_bytes: 256
# -*- coding:utf-8 -*-
import collections
n = int(input())
ans = collections.deque()

for i in range(n):
    command = input().split()
    if command[0] == "insert":
        ans.appendleft(command[1])
    elif ans == []:
        continue
    elif command[0] == "delete":
        try:
            ans.remove(command[1])
        except:
            pass
    elif command[0] == "deleteFirst":
        ans.popleft()
    else:
        ans.pop()

print (' '.join(ans))

Measured memory_bytes: 71928
K=int(input())

from collections import deque

d=deque([1,2,3,4,5,6,7,8,9])

k=1
while True:
    a=d.popleft()
    if k==K:
        print(a)
        exit()
    else:
        k+=1
    r=a%10
    if 0<r<=9:
        temp = a * 10 + (r -1)
        d.append(temp)
    temp=a*10+r
    d.append(temp)
    if 0<=r<9:
        temp=a*10+(r+1)
        d.append(temp)


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

int main() {
  int x, n; cin >>x >>n;
  vector<bool> p(101);
  for (int i = 1; i <= 100; i++) p[i] = true;

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

  // 読み落とし：整数列 p1,…,pN に含まれない整数 (正とは限らない) のうち X に最も近いもの、つまり X との差の絶対値が最小のものを求めてください。３つ
  int ret = (abs(-1-x) < abs(0-x)) ? -1 : 0;
  for (int i = 1; i <= 100; i++) {
    if (!p[i]) continue;
    int t = abs(i-x);
    if (t < abs(ret-x)) {ret = i;}
    else {break;}
  }
  // 上限についての考慮漏れ1つ
  ret = (abs(ret-x) <= abs(101-x)) ? ret : 101;

  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3628
#define _USE_MATH_DEFINES

#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
#include <ctgmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll inf = 10e17;
const ld eps = 10e-9;



ll solve(void);
ll gcd(ll x, ll y);

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

ll gcd(ll x, ll y)
{
	if (y == 1) { return 1;}
	if (x % y == 0) { return y; }
	return gcd(y, x % y);
}


ll solve(void)
{
	ll n, r;
	cin >> n >> r;

	ll ans = (n >= 10) ? r : r + 100 * ( 10 - n );

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
//
// Created by munaiyi on 2020/3/18.
//

#include <bits/stdc++.h>

using namespace std;
const int maxn = 200005;
double sum[maxn];

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    double ans = 0;
    sum[0] = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        scanf("%d", &x);
        sum[i] = sum[i - 1] + (x + 1) / 2.0;
        if (i >= k) {
            ans = max(ans, sum[i] - sum[i - k]);
        }
    }
    printf("%.7f\n", ans);
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define LL long long
using namespace std;
const int N=100007;
int n,m;
struct P {
	LL x,l,r,sc;
	bool operator < (const P &_) const {
		return sc+l*x>_.sc+_.l*_.x;
	}
}A[N];
int win(LL s) {
	int x=s/m,y=s%m;
	LL t=0;
	For(i,1,x) t+=A[i].sc;
	For(i,x+1,n) t-=A[i].l*A[i].x;
	if(t>=0) return 1;
	For(i,1,n) {
		LL w;
		if(y<A[i].x) w=-A[i].l*(A[i].x-y);
		else w=A[i].r*(y-A[i].x);
		if(i<=x) {
			LL r=t+A[x+1].l*A[x+1].x+A[x+1].sc-A[i].sc+w;
			if(r>=0) return 1;
		}
		else {
			LL r=t+A[i].l*A[i].x+w;
			if(r>=0) return 1;
		}
	}
	return 0;
}
int main() {
	scanf("%d%d",&n,&m);
	For(i,1,n) {
		scanf("%lld%lld%lld",&A[i].x,&A[i].l,&A[i].r);
		A[i].sc=(m-A[i].x)*A[i].r;
	}
	sort(A+1,A+1+n);
	LL l=0,r=0;
	For(i,1,n) r+=A[i].x;
	while(l<=r) {
		LL mi=(l+r)>>1;
		if(win(mi)) r=mi-1;
		else l=mi+1;
	}
	printf("%lld",l);
	return 0;
}

Measured memory_bytes: 3456
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
x, y = map(int, input().split())

if x%y==0:
    print(-1)
    exit()

ans = x
while ans<=10**18:
    if x%y!=0:
        print(x)
        exit()
    else:
        ans+=x


Measured memory_bytes: 2940
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = stdin.nextInt();
        int x = stdin.nextInt();

        if (x == 1 || x == 2 * n - 1) {
            System.out.println("No");
            System.exit(0);
        }

        List<Integer> digits = IntStream.range(2, 2 * n - 1).filter(v -> v != x).boxed().collect(Collectors.toList());


        int len = digits.size();
        int mid = len / 2;

        System.out.println("Yes");
        for (int i = 0; i < mid; i++) System.out.println(digits.get(i));
        System.out.println(1);
        System.out.println(x);
        System.out.println(2 * n - 1);
        for (int i = mid; i < len; i++) System.out.println(digits.get(i));
    }

}

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

int main(){
    long n,s; cin>>n>>s;
    int ansx=-1,ansy=-1,ansz=-1;
    for(long x=0;x<=n;x++){
        for(long y=0;y<=n-x;y++){
            if(s==10000*x+5000*y+1000*(n-x-y)){
                ansx=x;
                ansy=y;
                ansz=n-x-y;
                break;
            } 
        }
    }
    cout<<ansx<<" "<<ansy<<" "<<ansz<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>//大きい順
#define pqg priority_queue<int,vec,greater<int>>//小さい順
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
char charin() {char c; cin>>c; return c;}
string strin() {string s; cin>>s; return s;}
int main(){
    int a=in()-1;
    int b=in()-1;
    int ans=(b+a-1)/a;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<queue>
#include<vector>
#include<utility>
#include<functional>
#include<algorithm>
typedef long long ll;
using namespace std;

vector<int> X;
vector<int> Y;

int main(){
  int N,M,ans;
  cin >> N >> M;
  for(int i=0;i<M;i++){
    int tmp;
    cin >>tmp;
    X.push_back(tmp);
  }
  sort(X.begin(),X.end());
  /*int min = 10000000;
  for(int i=0;i<M-N;i++){
    if(min >= X[N + i] - X[i]){
      min = X[N + i] - X[i];
    }
  }
  cout << min+1 << endl;*/
  if(N>=M){
    ans = 0;
    cout << ans << endl;
  }else{
    for(int i=0;i<M-1;i++){
      int tmp = X[i+1] - X[i];
      Y.push_back(tmp);
      //cout << tmp << endl;
    }
    sort(Y.begin(),Y.end());
    //cout << Y[M-2] << endl;
    int sum = 0;
    for(int i=M-N;i<M-1;i++){
      //cout << Y[i] << endl;
      sum += Y[i];
    }
    cout << X[M-1] - X[0] - sum << endl;
  }
  return 0;
  //ダメでした
}

Measured memory_bytes: 1400
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
ll MOD = 1e9 + 7;
/* 
int main(){
    int n, m; 
    cin >> n >> m;
    vector<ll> a(n);
    vector<pair<ll,int>> b(m);

    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i].second >> b[i].first;

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

    priority_queue<pair<ll,int>> que;
    for(int i = 0;i < m;i++) {
            que.push(b[i]);
    }
    int k = 0;
    bool ok = false;
    while(que.size()){
        pair<ll,int> f = que.top();
        que.pop();
        ll p = f.first;
        int q = f.second;
        for(int i = 0; i < q;i++){
            if(a[k] < p){
                a[k] = p;
                k++;
            }else{
                ok = true;
                break;
            }
        }
        if(ok) break; 
    }
    ll ans = 0;
    rep(i,n) ans += a[i];
    cout << ans << endl;
}
*/

int main(){
    int n, m; cin >> n >> m;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<pair<ll,int>> b(m);
    rep(i,m) cin >> b[i].second >> b[i].first;

    sort(a.begin(),a.end());
    sort(b.rbegin(),b.rend());

    int k = 0;
    bool ok = false;
    for(int i = 0;i < m;i++){
        for(int j = 0;j < b[i].second;j++){
            if(a[k] < b[i].first){
                a[k] = b[i].first;
                k++;
            }else{
                ok = true;
                break;
            }
        }
        if(ok) break;
    }
    ll ans = 0;
    rep(i,n) ans += a[i];
    cout << ans << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#define FLAME_MAX 10000
#define REP(i, n) for(int i = 0; i < (n); i++)
#define linear(x, A, B, C) ((A) * (x) + (B)) % (C)
using namespace std;

int main()
{
  while(1){
    int N, A, B, C, X;
    cin >> N >> A >> B >> C >> X;
    if(N == 0 && A == 0 && B == 0 && C == 0 && X == 0){
      break;
    }else{
      int Y;
      int x = X;
      int f = 0;
      REP(i, N){
        cin >> Y;
        if(x != Y){
          while(x != Y && f <= FLAME_MAX){
            f++;
            x = linear(x, A, B, C);
          }
        }
        if(i > 0)
          f++;
        x = linear(x, A, B, C);
      }
      if(f <= FLAME_MAX)
        cout << f << endl;
      else
        cout << "-1" << endl;
    }
  }
}

Measured memory_bytes: 1160
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr = (input.trim()).split("\n");

const binarySearch = (key, arr, N) => {
  let mid, left = 0, right = N;
  while (left < right) {
    mid = Math.floor((left + right) / 2);
    if (key < arr[mid]) right = mid;
    else if (key > arr[mid]) left = mid + 1;
    else return 1;
  }
  return 0;
}


(function() {
  const N1 = Number(Arr[0]);
  const arr1 = Arr[1].split(" ").map(Number);
  // const N2 = Number(Arr[2]);
  const arr2 = Arr[3].split(" ").map(Number);
  console.log(arr2.map(e => binarySearch(e, arr1, N1)).reduce((a, b) => a + b, 0));
})();



Measured memory_bytes: 34888
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int n, m;
    cin>>n>>m;
    vector<pair<int, int> > v(m);
    rep(i, m){
        int a, b;
        cin>>a>>b;
        --a;
        v[i]=make_pair(a, b);
    }
    sort(v.begin(), v.end());
    vector<int> ans(n);
    if(n==1){
        if(m>=1) ans[0]=v[0].second;
        rep(i, m-1){
            if(v[i].second !=v[i+1].second) {
                cout<<-1<<endl;
                return 0;
            }
        }
        rep(i, n) cout<<ans[i];
        cout<<endl;
        return 0;
    }
    bool ok=true;
    int befidx=-1;
    int befitem=-1;
    rep(i, m) {
        if(v[i].first==0 && v[i].second==0 || (v[i].first==befidx && v[i].second != befitem)) {
            ok=false;
            break;
        }
        else {
            ans[v[i].first]=v[i].second;
            befidx=v[i].first;
            befitem=v[i].second;
        }
    }
    if(ans[0]==0) ans[0]=1;
    for(int i=1;i<=n-1;i++){
        if(ans[i]==0) ans[i]=0; 
    }
    if(ok) {
        rep(i, n) cout<<ans[i];
        cout<<endl;
    }
    else cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n;
ll a[100005],b[100005],f[100005];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%lld%lld",a+i,b+i);
    for(int i=n;i;--i){
        ll o=a[i]+f[i+1];
        if(o%b[i])o=o-o%b[i]+b[i];
        f[i]=o-a[i];
    }
    printf("%lld\n",f[1]);
    //system("pause");
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<vector<int>> d;
  for(int i=0;i<n;i++){
    int x,l;
    cin>>x>>l;
    d.push_back({x-l,1,i});
    d.push_back({x+l,0,i});
  }
  sort(d.begin(),d.end());
  int a=0;
  vector<bool> c(n,1);
  queue<int> q;
  for(int i=0;i<(int)d.size();i++){
    int x=d.at(i).at(0);
    int f=d.at(i).at(1);
    int j=d.at(i).at(2);
    if(f==0){
      if(c.at(j)){
        a++;
        while(!q.empty()){
          c.at(q.front())=0;
          q.pop();
        }
      }
    }else
      q.push(j);
  }
  cout<<a<<endl;
}

Measured memory_bytes: 14364
def main():
    n,m=map(int,input().split())
    s=input()
    masu = n
    res = []
    while masu>m:
        tm = m
        while s[masu - tm]=="1":
            tm -= 1
            if tm == 0:
                return -1
        res.append(tm)
        masu -= tm
    res.append(masu)
    res.reverse()
    return " ".join(map(str,res))


print(main())

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

int main()
{

    lint x,a,b;
    cin >> x >> a >>b;

    
    lint n;
    cin >> n;

    lint ans, tmp;
    ans = x;


    REP(i, n) {
        string s;
        cin >> s;
        if(s=="nobiro"){
            ans += a;
        }else if(s=="tidime"){
            ans += b;
        }else{
            ans = 0;
        }
        if(ans<0)
            ans = 0;
    }

    cout << ans <<"\n";

    return 0;
}


Measured memory_bytes: 3172
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        BigInteger bi = BigInteger.ZERO;

        for (int i = 1; i <= N; i++) {
            if (!fizzOrBuzz(i)) {
                bi = bi.add(new BigInteger("" + i));
            }
        }

        System.out.println(bi.toString());
    }

    public static boolean fizzOrBuzz(int i) {
        if (i % 15 == 0) {
            return true;
        } else if (i % 3 == 0) {
            return true;
        } else if (i % 5 == 0) {
            return true;
        } else {
            return false;
        }
    }
}


Measured memory_bytes: 57648
import java.util.Scanner;

public class Main {
    static int w, h, c;
    static int[][] map;

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

        while (true) {
            w = sc.nextInt();
            h = sc.nextInt();
            if (w == 0 && h == 0) {
                break;
            }
            map = new int[h][w];

            int sx = 0;
            int sy = 0;

            for (int i = 0; i < h; i++) {
                String line = sc.next();
                for (int j = 0; j < w; j++) {
                    char c = line.charAt(j);
                    if (c == '#') {
                        map[i][j] = 1;
                    } else if (c == '.') {
                        map[i][j] = 0;
                    } else {
                        sx = j;
                        sy = i;
                        map[i][j] = 0;
                    }
                }
            }
            // printArray(map);
            c = 0;
            check(sy, sx);
            System.out.println(c);
        }
    }

    public static void check(int y, int x) {
        if (y < 0 || x < 0 || y >= h || x >= w) {
            return;
        }
        if (map[y][x] == 1) {
            return;
        }
        map[y][x] = 1;
        c++;
        check(y + 1, x);
        check(y - 1, x);
        check(y, x + 1);
        check(y, x - 1);
    }

    public static void printArray(int[][] a) {
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a[0].length; j++) {
                System.out.print(a[i][j] + " ");
            }
            System.out.println();
        }
        System.out.println();
    }
}

Measured memory_bytes: 38300
#include <bits/stdc++.h>
using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long

const int N = 2e5 + 5;
const int mod = 1e9 + 7;

int dp[N], ans[N], sz[N];
int n;
int fac[N], inv[N], inv_fac[N];
vector<int> g[N];

int binpow(int x, int y) {
    int res = 1LL;
    x %= mod;
    while (y) {
        if (y & 1) res = (res * x) % mod;
        y >>= 1;
        x = (x * x) % mod;
    }
    return res;
}

int mod_inv(int x) {
    return binpow(x, mod - 2);
}

void init() {
    fac[0] = 1;
    for (int i = 1; i < N; i++)
        fac[i] = (i * fac[i - 1]) % mod;
    inv[1] = 1;
    for (int i = 2; i < N; i++)
        inv[i] = (mod - (mod / i) * inv[mod % i]) % mod;
    inv_fac[N - 1] = mod_inv(fac[N - 1]);
    for (int i = N - 2; i >= 0; i--) {
    	inv_fac[i] = (inv_fac[i + 1] * (i + 1)) % mod;
    }
}

int choose(int n, int r) {
    if (n < r) return 0;
    return (fac[n] * ((inv_fac[r] * inv_fac[n - r]) % mod)) % mod;
}

void dfs(int u = 1, int p = 1) {
	sz[u] = 1;
	int temp = 1;
	for (int v : g[u]) {
		if (v == p) continue;
		dfs(v, u);
		temp *= dp[v]; temp %= mod;
		temp *= inv_fac[sz[v]]; temp %= mod;
		sz[u] += sz[v];
	}
	temp *= fac[sz[u] - 1]; temp %= mod;
	dp[u] = temp;
}

void getAns(int u = 1, int p = 1) {
	for (int v : g[u]) {
		if (v == p) continue;
		ans[v] = ans[u] * sz[v]; ans[v] %= mod;
		ans[v] *= mod_inv(n - sz[v]); ans[v] %= mod;
		getAns(v, u);
	}
}
				
int32_t main() {
	fast_cin();  
 	
 	init();
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int u, v; cin >> u >> v;
		g[u].push_back(v), g[v].push_back(u);
	}
	dfs();
	ans[1] = dp[1];
	getAns();
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << endl;
	}

	
	return 0;
}

Measured memory_bytes: 24048
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    double* a=new double[n];
    for(int i=0;i<n;i++)cin>>a[i];
    double dp[n+1][n+1];
    ///row=>minreq,col=>atpres
    memset(dp,0.0,sizeof(dp));
    dp[0][0]=1.0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=i;j++)
        {

            if(j==0)dp[i][j]=dp[i-1][j]*(1.0-a[i-1]);
            else
            dp[i][j]=(a[i-1]*dp[i-1][j-1])+((1-a[i-1])*dp[i-1][j]);

        }
    }
    double ans=0;
    for(int i=(n+1)/2;i<=n;i++)
    ans+=dp[n][i];
    // for(int i=(n+1)/2;i<=n;i++)
    // cout<<dp[i][n]<<" ";
    cout << fixed << setprecision(9);
    cout<<ans;
}

Measured memory_bytes: 70528
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

void fc(string &s, string &res){
  int index = 0;
  rep(i, s.size()){
    if(s.at(i) == '.') index = i;
  }
  res = s.substr(index+1);
  if(index != 0){
    rep2(i, res.size(), 9){
      res.push_back('0');
    }
    res = s.substr(0, index) + res;
  }else{
    res = s;
    rep(i, 9) res.push_back('0');
  }
}

ll tolonglong(string s){
  ll res = 0;
  rep(i, s.size()){
    res *= 10;
    res += s.at(i) - '0';
  }
  return res;
}

void make_p2p5(ll n, int &p2, int &p5){
  p2 = p5 = 0;
  while(n != 0 && n % 2 == 0){
    p2++;
    n /= 2;
  }
  while(n != 0 && n % 5 == 0){
    p5++;
    n /= 5;
  }
}

void update(vector<vector<ll>> &sums, pair<int, int> p){
  rrep(i, p.first+1){
    rrep(j, p.second+1){
      sums.at(i).at(j)++;
    }
  }
}

int main(){
  int n;
  cin >> n;
  vector<string> v;
  rep(i, n){
    string s;
    cin >> s;
    string add;
    fc(s, add);
    v.push_back(add);
  }
  vector<ll> vv(v.size());
  rep(i, v.size()) vv.at(i) = tolonglong(v.at(i));

  vector<vector<ll>> sums(55, vector<ll>(25, 0));
  vector<pair<int, int>> p2p5(vv.size());
  rep(i, vv.size()){
    int p2, p5;
    make_p2p5(vv.at(i), p2, p5);
    p2p5.at(i) = {p2, p5};
  }

  // rrep(i, sums.size()){
  //   rrep(j, sums.at(i).size()){
  //     cerr << sums.at(i).at(j) << " ";
  //     if(i != sums.size()-1 && j != sums.at(i).size()-1) sums.at(i).at(j) -= sums.at(i+1).at(j+1);
  //     if(i != 0) sums.at(i-1).at(j) += sums.at(i).at(j);
  //     if(j != 0) sums.at(i).at(j-1) += sums.at(i).at(j);
  //   }
  //   cerr << endl;
  // }

  ll ans = 0;
  // int co = 0;
  for(auto p : p2p5){
    int np2 = 18-p.first;
    int np5 = 18-p.second;
    if(np2 < 0) np2 = 0;
    if(np5 < 0) np5 = 0;
    // cerr << vv.at(co++) << " " << np2 << " " << np5 << " " << sums.at(np2).at(np5) << endl;
    ans += sums.at(np2).at(np5);
    update(sums, p);
    // rep(i, sums.size()){
    //   rep(j, sums.at(i).size()){
    //     printf("%2d ", sums.at(i).at(j));
    //   }
    //   cerr << endl;
    // }
    // cerr << "----------------------" << endl;
  }
  cout << ans << endl;
  return 0;
}

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

int sum[1001][1001] = {};

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

    for(int i = 0; i < n; i++){
        cin >> a >> b >> c >> d;
        sum[a][b]++;
        sum[c][d]++;
        sum[a][d]--;
        sum[c][b]--;
    }

    for(int i = 1; i < 1001; i++){
        for(int j = 0; j < 1001; j++){
            sum[i][j] += sum[i-1][j];
        }
    }

    for(int i = 0; i < 1001; i++){
        for(int j = 1; j < 1001; j++){
            sum[i][j] += sum[i][j-1];
        }
    }

    int ans = 1;
    for(int i = 0; i < 1001; i++){
        for(int j = 0; j < 1001; j++){
            ans = max(ans, sum[i][j]);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7000
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>

typedef long long ll;
#define fi first
#define se second

int a[212345];

using namespace std;

int main(){
  
  ll A, B, C;
  ll AB, BC, CA;
  
  cin>>A>>B>>C;
  
  AB = A*B;
  BC = B*C;
  CA = C*A;
  
  if( A % 2 && B % 2 && C % 2 ){
    cout<<min( AB, min( BC, CA ) )<<endl;
  }
  else{
    puts("0");
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

const int MAXN = 5000;
const int MOD = 1000000007;
const int INF = 2000000000;
const double PI = 3.14159265358979;
const int dir_4r[] = { -1, 1, 0, 0 };
const int dir_4c[] = { 0, 0, -1, 1 };
const int dir_8r[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
const int dir_8c[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() 
{
	int n, m;
	while (cin >> n >> m)
		cout << (n - 1)*(m - 1) << endl;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int bingo[3][3];
  cin >>bingo[0][0] >> bingo[0][1] >> bingo[0][2];
  cin >>bingo[1][0] >> bingo[1][1] >> bingo[1][2]; 
  cin >>bingo[2][0] >> bingo[2][1] >> bingo[2][2];
  int N;
  int num[110];
  cin >> N;
  for(int i = 0; i < N; i++){
   cin >> num[i];
  }
  bool check[3][3];
     for(int j = 0; j < 3; j++){
    for(int k = 0; k < 3; k++){
    check[j][k] = 0;
    }
     }
  for(int i = 0; i < N; i++){
   for(int j = 0; j < 3; j++){
    for(int k = 0; k < 3; k++){
      if(num[i] == bingo[j][k]){
       check[j][k] = 1;  
      }
    }
   }
  }
  bool ans = 0;
      for(int j = 0; j < 3; j++){
if(check[j][0] == 1 && check[j][1] == 1 && check[j][2] == 1){
  ans = 1;
}
     }
  
        for(int j = 0; j < 3; j++){
if(check[0][j] == 1 && check[1][j] == 1 && check[2][j] == 1){
  ans = 1;
}
     }
  if(check[0][0] == 1 && check[1][1] == 1 && check[2][2] == 1){
   ans = 1; 
  }
 if(check[2][0] == 1 && check[1][1] == 1 && check[0][2] == 1){
   ans = 1; 
  }  
  
  if(ans == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
}



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

int d[111111];
int main() {
    int n, p = 1e9 + 7, c = 0;
    cin >> n;
    long r = 1;
    for(int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        if(a)
            (r *= d[a - 1]--) %= p;
        else
            c++;
        d[a]++;
    }
    if(c > 3)
        r = 0;
    cout << r * (c < 2 ? 3 : 6) % p << endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem0515 : School Road **/
int W, H;
int N;
vector<P> b;
int dp[16][16];

int solve(int x, int y)
{
	if (x==W-1 && y==H-1)
		return 1;
	else if (x>=W || y>=H)
		return 0;
	
	
	if (dp[x][y] != -1)
		return dp[x][y];
	
	int res=0;
	vector<P>::iterator it = find(b.begin(), b.end(), P(x+1, y));
	if (it == b.end())
		res += solve(x+1, y);
	
	it = find(b.begin(), b.end(), P(x, y+1));
	if (it == b.end())
		res += solve(x, y+1);
	
	return dp[x][y] = res;
}

int main()
{
	while (cin>>W>>H, W||H) {
		cin>>N;
		b.resize(N);
		memset(dp, -1, sizeof(dp));
		
		rep(i, N) {
			cin>>b[i].first>>b[i].second;
			b[i].first--, b[i].second--;
		}
		cout << solve(0, 0) << endl;
	}
}

Measured memory_bytes: 1200