akhauriyash/Code-Regression huggingface dataset:
L, R = map(int, input().split())

mod = 10 ** 9 + 7

dp = [[[0] * 2 for _ in range(2)] for _ in range(2)]
dp[0][0][0] = 1

for i in range(60, -1, -1) :
    lb, rb = (L >> i) & 1, (R >> i) & 1
    dp_ = [[[0] * 2 for _ in range(2)] for _ in range(2)]
    for lf in range(2) :
        for rf in range(2) :
            for msb in range(2) :
                for l in range(2) :
                    for r in range(2) :
                        nlf, nrf, nmsb = lf, rf, msb
                        if l > r : continue
                        if not msb and l != r : continue
                        if l and r :
                            nmsb = 1
                        if not lf and l < lb : continue
                        if l > lb :
                            nlf = 1
                        if not rf and r > rb : continue
                        if r < rb :
                            nrf = 1
                        dp_[nlf][nrf][nmsb] += dp[lf][rf][msb]
                        dp_[nlf][nrf][nmsb] %= mod
    dp = dp_
    
ret = 0
for i in range(2) :
    for j in range(2) :
        for k in range(2) :
            ret += dp[i][j][k]
            
print(ret % mod)

Measured memory_bytes: 39792
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using static System.Console;
using static System.Math;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            MyInputStream cin = new MyInputStream();

            var n = cin.ReadInt();
            var k = cin.ReadInt();

            WriteLine(k * Pow(k - 1, n - 1));
        }
    }

    public static class MyExtensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class MyInputStream
    {
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(char separator = ' ')
        {
            this.separator = separator;
            inputStream = new Queue<string>();
        }

        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = Console.ReadLine().Split(separator);
            for (int i = 0; i < tmp.Length; i++)
            {
                inputStream.Enqueue(tmp[i]);
            }
            return inputStream.Dequeue();
        }
        public string ReadLine() => Console.ReadLine();
        public int ReadInt() => int.Parse(Read());
        public long ReadLong() => long.Parse(Read());
        public double ReadDouble() => double.Parse(Read());
    }

    public class Pair<T1, T2>
    {
        public T1 First;
        public T2 Second;
        public Pair() { First = default(T1); Second = default(T2); }
        public Pair(T1 f, T2 s) { First = f; Second = s; }
        public override string ToString() { return "(" + First + ", " + Second + ")"; }
        public override int GetHashCode() { return First.GetHashCode() ^ Second.GetHashCode(); }
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(this, obj)) return true;
            else if (obj == null) return false;
            var tmp = obj as Pair<T1, T2>;
            return (object)tmp != null && First.Equals(tmp.First) && Second.Equals(tmp.Second);
        }
    }

    #region HashMap
    public class HashMap<K, V> : Dictionary<K, V>
    {
        public HashMap() : base() { }
        public HashMap(int cap) : base(cap) { }
        public HashMap(IDictionary<K, V> dictionary) : base(dictionary) { }
        new public V this[K i]
        {
            get
            {
                V v;
                return TryGetValue(i, out v) ? v : base[i] = default(V);
            }
            set { base[i] = value; }
        }
    }
    #endregion
}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;


//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;
typedef set<int> si;


/*
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
*/
/*
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
*/

const ll mod = 1e9 + 7;
const ll modl=998244353;
const double pie=3.1415926535;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ll gcd(ll x,ll y){
   if(y==0)return x;
   return gcd(y,x%y);
}
                                              // SIEVE

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/


int main(){
    boost;
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        int n;
        cin>>n;
        string s;
        cin>>s;
        if(n%2==0){
            string t="";
            string x="";
            for(int i=0;i<n/2;i++){
                t+=s[i];
            }
            for(int i=n/2;i<n;i++)x+=s[i];
            if(t==x){
                cout<<"Yes"<<endl;
            }else cout<<"No"<<endl;
        }else cout<<"No"<<endl;
    }
}















Measured memory_bytes: 3596
N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i in range(3**N):
    ii = i
    res = 1
    for j in range(N):
        k = ii % 3
        ii = ii // 3
        res *= (A[j]-1+k)
    if res % 2 == 0:
        cnt += 1
print(cnt)

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

int main(){
  int n, m, d;
  cin >> n >> m;
  vector <int> vec(m, 0);
  for(int i=0;i<n;++i){
    int k;
    cin >> k;
    for(int j=0;j<k;++j){
      cin >> d;
      vec.at(d-1)++;
    }
  }
  int c=0;
  for(int i=0;i<m;++i){
    if(vec.at(i)==n) c++;
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n; cin >> n;
    vector<int> t(n);
    rep(i, n) cin >> t[i];
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> mint(n);
    vector<int> maxt(n);
    int cur = 0;
    rep(i, n) {
        if (t[i]>cur) {
            mint[i] = t[i];
            maxt[i] = t[i];
            cur = t[i];
        } else {
            mint[i] = 1;
            maxt[i] = maxt[i-1];
        }
    }
    debug(mint, maxt);
    reverse(all(a));
    vector<int> mina(n);
    vector<int> maxa(n);
    cur = 0;
    rep(i, n) {
        if (a[i]>cur) {
            mina[i] = a[i];
            maxa[i] = a[i];
            cur = a[i];
        } else {
            mina[i] = 1;
            maxa[i] = maxa[i-1];
        }
    }
    reverse(all(mina));
    reverse(all(maxa));
    debug(mina, maxa);
    ll ans = 1;
    rep(i, n) {
        int lb = max(mint[i], mina[i]);
        int ub = min(maxt[i], maxa[i]);
        if (ub<lb) {
            cout << 0 << endl;
            return 0;
        }
        ans *= ub-lb+1ll;
        ans %= MOD;
        debug(lb, ub, ans);
    }
    cout << ans << endl;
}

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

int main(){
    long long N,M;
    cin >> N >> M;
    long long a=M/N;
    long long ans=0;
    for(long long i=a;i>0;i--){
        if(M%i==0){
            cout << i << endl;
            return 0;
        }
    }
}

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

typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;

ll gcd( ll a, ll b ){//最大公約数
    ll tmp;
    if( a < b ) { tmp = a; a = b; b = tmp; }
    if( b < 1 ) return -1;

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

ll lcm(ll a, ll b){//最小公倍数
    return a * b / gcd(a, b);
}


//入力

int main(){

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

    cout << lcm(a, b) << endl;

    return 0;
}

Measured memory_bytes: 256
MOD = 10**9 + 7

N = gets.to_i
s = gets.chomp
cnt = Hash.new(0)
N.times do |i|
  c = s[i]
  cnt[c] += 1
end
ans = 1
cnt.each_value do |v|
  ans = (ans*(v+1)) % MOD
end
p ans-1

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

int n;
void dfs(string s, char mx) {
    if (s.size() == n) {
        cout << s << endl;
        return;
    }
    for (char c = 'a'; c <= mx+1; c++) {
        string t = s;
        t += c;
        dfs(t, max(mx,c));
    }
}

int main() {
    cin >> n;
    dfs("", 'a' - 1);
    return 0;
}

Measured memory_bytes: 1536
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from collections import defaultdict
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(readline())
    A = list(map(int, readline().split()))

    d = defaultdict(list)
    for i in range(N+1):
        d[A[i]].append(i)

    for i in range(1,N+1):
        if len(d[i]) == 2:
            left, right = d[i]
            break

    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]

    for i in range(2, N + 2):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)

    def cmb(n, r, mod):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return fact[n] * factinv[r] * factinv[n - r] % mod

    for k in range(1,N+2):
        ans = cmb(N+1,k,MOD) - cmb(left-1+N-right+1,k-1,MOD)
        print(ans%MOD)


if __name__ == '__main__':
    main()


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

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

    if (s[0] == s[1] && s[1] == s[2]) {
        cout << "Yes" << endl;
    }
    else if (s[1] == s[2] && s[2] == s[3]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
from math import gcd
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [i // 2 for i in A]
lcd = 1
for a in A:
    lcd *= a // gcd(lcd, a)
for a in A:
    if lcd // a % 2 == 0:
        print(0)
        exit()
print((M//lcd+1)//2)


Measured memory_bytes: 20208
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<set<ll>> vsll;
typedef set<pair<ll, ll>> spll;
typedef vector<spll> vspll;
typedef vector<pll> vpll;
const ll MOD = 1e9 + 7;
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
#define round(x, y) ((2 * x + y) / (2 * y))
#define ce(x, y) ((x + y - 1) / y)
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define sz(x) (ll) x.size()
#define sq(x) ((x) * (x))
 
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
 
void solve() {

    ll a,b,k;
    cin >>a>>b>>k;
    if(a>=k)
    {
        a-=k;
        cout <<a<<" "<<b<<"\n";
        return;
    }
    k-=a;
    a=0;
    if(b>=k)
    {
        b-=k;
        cout <<a<<" "<<b<<"\n";
        return;
    }
    b=0;
    cout <<a<<" "<<b<<"\n";
}
 
int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    solve();
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  int count = 0;
  if (s[0] == 'o') count++;
  if (s[1] == 'o') count++;
  if (s[2] == 'o') count++;
  
  cout << 700 + 100*count << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int x,y;
    bool a=false;
    
    cin>>x>>y;

    for(int i=0;i<=x;i++){
        if(2*i+4*(x-i)==y){
            a=true;
        }
    }

    if(a) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3596
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int AC=0;
        int WA=0;
        int TLE=0;
        int RE=0;
        for(int i = 0;i <= A;i++){
            String B = sc.nextLine();
            if(B.equals("AC")){
                AC++;
            }else if(B.equals("WA")){
                WA++;
            }else if(B.equals("TLE")){
                TLE++;
            }else if(B.equals("RE")){
                RE++;
            }
        }
        System.out.println("AC" + " x " +AC);
        System.out.println("WA"+ " x " +WA);
        System.out.println("TLE"+ " x " +TLE);
        System.out.println("RE"+ " x " +RE);
    }
}


Measured memory_bytes: 59692
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func init() {
	sc = bufio.NewScanner(os.Stdin)
	buffsize := 1000000
	buff := make([]byte, buffsize)
	sc.Buffer(buff, buffsize)
	sc.Split(bufio.ScanWords)
}

func loadint() (result int) {
	sc.Scan()
	result, _ = strconv.Atoi(sc.Text())
	return
}

func main() {
	n := loadint()
	var j int
EXIT:
	for i := 0; i <= n; i += 4 {
		for j = i; j <= n; j += 7 {
			if j == n {
				break EXIT
			}
		}
	}
	if j == n {
		fmt.Print("Yes")
	} else {
		fmt.Print("No")
	}
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int		main()
{
	int		N, K, k, A;
	int		*a, ans = 0;

	a = (int *)calloc(101, sizeof(int));
	scanf("%d %d\n", &N, &K);
	for (int i = 0; i < K; i++)
	{
		scanf("%d\n", &k);
		for (int n = 0; n < k; n++)
		{
			scanf("%d ", &A);
			a[A]++;
		}
	}
	for (int i = 1; i <= N; i++)
	{
		if (a[i] == 0)
			ans++;
	}
	printf("%d\n", ans);
	return (0);
}

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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    string S;
    cin >> S;
    if(S.back()=='s')  S += "es";
    else S += "s";

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 3664
mod = 1000000007
str = gets.split
N,K = str[0].to_i, str[1].to_i
r = Array.new(N+1){Array.new(0)}

a = 0
b = 0
for x in 1...N do
    str = gets.split
    a,b = str[0].to_i, str[1].to_i
    r[a].push(b)
    r[b].push(a)
end

s = Array.new(0)
s.push(1)
answer = K
now = s.pop
if r[now].size > 0
    a = r[now].size
    for x in 1..a do
        answer = answer * (K-x) % mod
    end
    while r[now].size > 0
        b = r[now].pop
        if r[b].size != 0
            s.push(b)
        end 
    end
end
while s.size > 0
    now = s.pop
    if r[now].size > 0
        a = r[now].size
        for x in 1...a do
            answer = answer * (K-1-x) % mod
        end
        while r[now].size > 0
            b = r[now].pop
            if r[b].size != 0
                s.push(b)
            end 
        end
    end
end

puts answer

Measured memory_bytes: 11260
#include<bits/stdc++.h>
#define loop(i,start,end) for(int i=start;i<end;i++)
using namespace std;
int main(){
    int n;
    cin>>n;
    double pi=3.1415926;
    double area=(double)n*2*pi;
    cout<<fixed<<setprecision(20)<<area;
}

Measured memory_bytes: 3776
n = int(input())
memo = [{} for _ in range(n+1)]

def ok(last4):
  if "AGC" in last4:
    return False
  if "ACG" in last4:
    return False
  if "GAC" in last4:
    return False
  if last4[0] == "A" and last4[2:] == "GC":
  	return False
  if last4[:2] == "AG" and last4[3] == "C":
    return False
  return True

def dfs(cur, last3):
  if last3 in memo[cur]:
    return memo[cur][last3]
  if cur == n:
    return 1
  ret = 0
  for c in "ACGT":
    if (ok(last3 + c)):
      ret += dfs(cur+1, last3[1:] + c)
  memo[cur][last3] = ret
  return ret

print(dfs(0, "TTT") % 1000000007)

Measured memory_bytes: 3952
# 2部グラフは特別ケース。
# 2部グラフの時、各ノードは色の違うノードとしか奇数長サイクルを持たない。
# 2部グラフでない時、各ノードは必ず全ノードと奇数長サイクルを持つ。
import queue
from collections import Counter
N,M = map(int,input().split())
ans = [-1]*N
pas = [[] for _ in range(N)]
for i in range(M):
    u,v = map(int,input().split())
    pas[u-1].append(v-1)
    pas[v-1].append(u-1)

q = queue.Queue()
q.put(0)
ans[0] = 0
flag = True
while (not q.empty()):
    now = q.get()
    nowa = ans[now]
    for i in pas[now]:
        if ans[i] == -1:
            if nowa == 0:
                ans[i] = 1
            else:
                ans[i] = 0
            q.put(i)
        else:
            if ans[i] == nowa:
                flag = False

if flag:
    c = Counter(ans)
    zer = c[0]
    one = c[1]
    print(zer*one-M)
else:
    print(N*(N-1)//2-M)


Measured memory_bytes: 78364
#include<stdio.h>
#define N 2000
#define INF 9999999
#define NIL -1 

int G[N][N], n, k, s, u, v;

void dijkstra(){

  int i, j, color[N], mincost, d[N], pi[N];
  
  for(u =0 ; u < n ; u++){
    d[u] = INF;
    pi[u] = NIL;
    color[u] = 0;
  }
  d[0] = 0;
  
  while(1){
    mincost = INF;
    for(i = 0 ; i < n ; i++){
      if(color[i] != 1 && d[i] < mincost){
	mincost = d[i];
	u = i;
      }
    }
    if(mincost == INF){
      break;
    }
    color[u] = 1;
    for(v = 0 ; v < n ; v++){
      if(color[v] != 1 && d[u] + G[u][v] < d[v] && G[u][v] != -1){
	pi[v] = u;
	d[v] = d[u] + G[u][v];
      }
    }
  }

  for(i = 0 ; i < n ; i++){
    if(d[i] != INF){
      printf("%d %d\n", i, d[i]);
    }
  }
  
}

int main(){

  int i, j;

  scanf("%d", &n);
  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      G[i][j] = INF;
    }
  }
  
  for(i = 0 ; i < n ; i++){
    scanf("%d%d", &u, &k);
    for(j = 0 ; j < k ; j++){
      scanf("%d", &v);
      scanf("%d", &G[u][v]);
    }
  }

  dijkstra();

  return 0;
}

Measured memory_bytes: 1052
def gcd(a, b):
  if a == 0:
    return b
  if b == 0:
    return a
  if a > b:
    return gcd(a%b, b)
  return gcd(a, b%a)

a, b = input().split()
a, b = int(a), int(b)
print(a * b // gcd(a, b))


Measured memory_bytes: 2940
use std::cmp::min;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: i64 = sc.read();
    let a: i64 = sc.read();
    let b: i64 = sc.read();

    let mut ans = b - 1;
    ans = min(ans, n - a);

    if (b - a) % 2 == 0 {
        ans = min((b - a) / 2, ans);
    }

    let next_a = a + (n - b) + 1;
    let next_b = n;
    if (next_b - next_a) % 2 == 0 {
        ans = min((next_b - next_a) / 2 + (n - b) + 1, ans);
    }

    let next_a = 1;
    let next_b = b - (a - 1) - 1;
    if (next_b - next_a) % 2 == 0 {
        ans = min((next_b - next_a) / 2 + a, ans);
    }

    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4476
N = gets.to_i
ps = gets.split.map(&:to_i)
rs = (1..N).to_a

sum = 0
while ps.length > 0 do
    if ps[0] == rs[0]
        ps.shift
        rs.shift
        sum += 1
    end
    if ps.length > 0
        ps.shift
        rs.shift
    end
end

puts sum

Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  bool K=false;
  bool L=false;
  for (int X=0; X<S.size(); X++){
    if (S.at(X)=='A'){
      K=true;
    }
    else if (S.at(X)=='B'){
      L=true;
    }
  }
  if (K==true && L==true){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
int main(){
    ll n;
    cin >> n;
    int i,j;
    ll go=1e6;
    for(i=1;i<n;i++){
        ll n1,n2;
        ll sum=0;
        n1=i;
        n2=n-i;
        while(n1!=0){
            sum+=n1%10;
            n1/=10;
        }
        while(n2!=0){
            sum+=n2%10;
            n2/=10;
        }
        go=min({go,sum});
    }
    cout << go << endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        h: usize,
        w: usize,
        k: usize,
        s: [chars; h],
    }
    let mut cnt = 1;
    let mut ans = vec![vec![0; w]; h];
    let mut flag = false;
    let mut l = 0;
    let mut r = 0;
    for h_ in 0..h {
        for w_ in 0..w {
            if s[h_][w_] == '#' {
                ans[h_][w_] = cnt;
                cnt += 1;
            }
        }
    }
    for h_ in 0..h {
        for w_ in 1..w {
            if ans[h_][w_] == 0 {
                ans[h_][w_] += ans[h_][w_ - 1];
            }
        }
    }
    for h_ in 0..h {
        for w_ in (0..w-1).rev() {
            if ans[h_][w_] == 0 {
                ans[h_][w_] += ans[h_][w_ +1 ];
            }
        }
    }
    for w_ in 0..w {
        for h_ in 1..h {
            if ans[h_][w_] == 0 {
                ans[h_][w_] += ans[h_- 1][w_]
            }
        }
    }
    for w_ in 0..w {
        for h_ in (0..h-1).rev() {
            if ans[h_][w_] == 0 {
                ans[h_][w_] += ans[h_ + 1][w_];
            }
        }
    }

    for i in 0..h {
        for j in 0..w{
            if j != w-1 {
                print!("{} ", ans[i][j]);
            } else {
                println!("{}", ans[i][j])
            }
        } 
    }
}


Measured memory_bytes: 4860
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	s = readline() |> chomp
	f = 0
	for i in 1:length(s)
		if s[i] == 'C'
			f = 1
		elseif f==1&&s[i] == 'F'
			f = 2
		end
	end
	println(f==2?"Yes":"No")
end
main()


Measured memory_bytes: 166048
#include <stdio.h>
#pragma warning (disable:4996)
//FILE *in = fopen("input.txt", "r"), *out = fopen("output.txt", "w");
FILE *in = stdin, *out = stdout;
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF 1e18
#define NM 20005
#define MOD 1000000000
#define FOR(i,n,m) for (int i=(n);i<=(m);i++)
#define si(n) fscanf(in,"%d",&n)
#define sd(n) fscanf(in,"%lf",&n)
typedef long long int ll;
int main(){
int A, B, C, X,ans=0;
si(A),si(B),si(C),si(X);
FOR (i,0,A) FOR (j,0,B) FOR (k,0,C){
if (500*i+100*j+50*k==X) ans++;
}
fprintf(out,"%d",ans);
return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<string.h>
using namespace std;
int main() {
	long long a,b;
	cin >> a >> b;
	if (a ==  1 || b == 1) {
		cout << "1";
	}
	else {
		cout << (a * b + 1) / 2;
	}
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N,K;
  cin >> N >> K;
  string S;
  cin >> S;
  int ele = 1;
  for (int i = 1; i < N; i++) {
    if (S[i] != S[i - 1]) {
      ele++;
    }
  }
  cout << min(N - 1,N - ele + (2 * K)) << endl;
  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
 
int main(){
  int n;
  scanf("%d\n",&n);
  char bin;
  int s[n];
  int t[n];//s[0],...,s[i]のwhite数
  int white = 0, black = 0;
  for(int i = 0; i < n; ++i){
    scanf("%c",&bin);
    if(bin == '.'){
      s[i] = 0;//white
      white++;
      t[i] = white;
    }
    else if(bin == '#'){
      s[i] = 1;//black
      black++;
      t[i] = white;
    }
  }
  int answer = white;//1色にする場合
  if(white > black) answer = black;
  int left,right;//左のblack,右のwhite
  for(int i = 0; i < n - 1; ++i){//0..01..1
    left = i + 1 - t[i];
    right = white - t[i];
    if(right + left < answer) answer = right + left;
  }
  printf("%d\n",answer);
  return 0;
}

Measured memory_bytes: 1664
<?php 
fscanf(STDIN,"%d%d%d",$a,$b,$c);

$sum = 0;
$patern = array();
for($i=1;$i<10**6;$i++){
  //echo ($sum%$b)."\n";
  $sum=$a*$i;
  if($sum%$b==$c){
    echo "YES\n";
    exit;
  }
  if($sum%$b==$first){
    break;
  }
}

echo "NO\n";




Measured memory_bytes: 4604
#include<vector>
#include<iostream>
#include<map>

using namespace std;

struct UnionFind{
    vector<int> par;
    vector<int> rank;

    void init(int n) {
        par = vector<int>(n);
        rank = vector<int>(n);

        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] > rank[y]) {
            par[y] = x;
        } else {
            par[x] = y;
            if (rank[x] == rank[y]) ++rank[x];
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

int main() {
    int N, K, L;

    cin >> N >> K >> L;

    UnionFind road;
    UnionFind train;

    road.init(N);
    train.init(N);

    for (int i = 0; i < K; ++i) {
        int p, q;
        cin >> p >> q;
        p--; q--;
        road.unite(p, q);
    }

    for (int i = 0; i < L; ++i) {
        int r, s;
        cin >> r >> s;
        r--; s--;
        train.unite(r, s);
    }

    map<pair<int, int>, int > m;
    for (int i = 0; i < N; ++i) {
        m[make_pair(road.find(i), train.find(i))] += 1;
    }

    for (int i = 0; i < N; ++i) {
        cout << m[make_pair(road.find(i), train.find(i))] << endl;
    }
}

Measured memory_bytes: 12288
x=[0 for i in range(26)]
a="abcdefghijklmnopqrstuvwxyz"
while True :
    try:
        b=input()
    except:
        break
    for j in b:
        y=0
        for k in a:
            if j == k or j == k.upper():
                x[y]+=1
                break
            y+=1
for i in range(len(a)):
    print("%s : %d"%(a[i],x[i]))


Measured memory_bytes: 5568
# input
A, B = (int(i) for i in input().split())


# the total num of 1 at i index under a
def num_bin(a, i):
    mod = 2 ** (i+1)
    hlf = 2 ** i
    base = (a-1) // mod * hlf
    resm = max(((a-1) % mod) - hlf + 1, 0)
    return base + resm

xor = ''

max_index = len(bin(B + 1)) - 2

for i in range(max_index):
    xor = str(num_bin(A, i) % 2 ^ num_bin(B + 1, i) % 2) + xor
    
print(int(xor, 2))


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <iomanip>
#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;
    for (int i = 1; i <= 10000; ++i) {
        if(i*8/100 == a && i*10/100 == b){
            cout << i << "\n";
            return 0;
        }
    }
    puts("-1");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) (1e9 + 7);
//const ll MOD = 998244353;
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << setiosflags(ios::fixed);

    string s, t;
    cin >> s >> t;
    int cnt = 0;

    rep(i, 3) {
        if (s[i] == t[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}



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

if B - 1 <= N:
    bunshi = math.floor(A * (B - 1)) // B
    bunbo = A * math.floor((B - 1) // B)
    print(bunshi - bunbo)
else:
    bunshi = math.floor(A * N) // B
    bunbo = A * math.floor(N // B)
    print(bunshi - bunbo)


Measured memory_bytes: 9180
#include <stdio.h>

int main(){
  int t,sum=0;
  scanf("%d",&t);
  if(t%1000==0){
    printf("");
  }else if(1000>t){
    sum=1000-t;
  }else if(t>1000){
    sum=1000-(t%1000);
  }
  printf("%d\n",sum);
return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> PIP;

#define INF INT_MAX/3

int a[300][300], b[300][300];

int main(){
    cin.sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i, n)rep(j, n) cin >> a[i][j];
    bool ok = true;
    rep(i, n)rep(j, n)rep(k, n) if (a[j][i] + a[i][k] < a[j][k]) ok = false;
    if (ok) {
        ll ans = 0;
        rep(i, n)repl(j, i, n) {
            bool used = true;
            rep(k, n) if (i != k && j != k && a[i][j] == a[i][k] + a[k][j]) used = false;
            if (used) ans += a[i][j];
        }
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 640
# coding:utf-8

import sys
# from collections import Counter, defaultdict

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


G = [[] for _ in range(4)]
for i in range(3):
    a, b = LI_()
    G[a].append(b)
    G[b].append(a)

for v in G:
    if len(v) % 2 == 0:
        print('YES')
        break
else:
    print('NO')


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 1000010
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int mx,n,a[N],b[N];
char s[N];
void init(){
	int sum=0;
	for(int i=1;i<=n;++i){
		sum+=(s[i]=='1'?1:-1);
		mx=max(mx,sum);
		a[i]=sum;
	}
	b[n]=a[n];
	for(int i=n-1;i>=0;--i){
		b[i]=max(a[i],b[i+1]);
	}
}
int calc(int lim){
	int mn=0,sum=0;
	for(int i=1;i<=n;++i){
		if(s[i]=='1')++sum;
		else if(s[i]=='0')--sum;
		else{
			if(b[i]-a[i-1]+sum+2<=lim)++sum;
			else --sum;
		}
		mn=min(mn,sum);
	}
	return mn;
}
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	init();
	printf("%d\n",min(mx-calc(mx),mx+1-calc(mx+1)));
	return 0;
}



Measured memory_bytes: 12620
import java.io.*;

public class Main{
	public static void main(String[] args)throws IOException{
			BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		String s;
		int x;		
		s= buf.readLine();
		x= Integer.parseInt(s);
		System.out.println(x*x*x);		
	}
}

Measured memory_bytes: 17020
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var a = cin.ReadInt;
            var b = cin.ReadInt;
            var c = cin.ReadInt;
            
            if (a < b) {
                if (c < a || b < c) {
                    WriteLine("No");
                    return;
                }
            } else {
                if (c < b || a < c) {
                    WriteLine("No");
                    return;
                }
            }
            WriteLine("Yes");
            
        }

        private double MultipleCeil(double value, double multiple) {return Math.Ceiling(value / multiple) * multiple;}

    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 13268
#include <iostream>

using namespace std;

int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    if(A < B)
    {
        cout << A << ' ';
    }
    else
    {
        cout << B << ' ';
    }
    if(A + B > N)
    {
        cout << A + B - N;
    }
    else
    {
        cout << 0;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[10], ans = 0;
int dfs(int k, int b[10]){
	if(k == 6){
		int s[3] = {}, f[10] = {};
		s[0] = b[0], s[1] = b[1]*10+b[2], s[2] = b[3]*100+b[4]*10+b[5];
		int sum = s[0]+s[1]+s[2];
		s[0] = sum/100, s[1] = (sum/10)%10, s[2] = sum%10;
		rep(i,6)f[b[i]]++;
		rep(i,3){
			if(a[6+i] != -1 and s[i] != a[6+i])return 0;
			if(s[i] < 1 or 9 < s[i] or f[s[i]])return 0;
			else f[s[i]]++;
		}
		//rep(i,6)printf("%lld ", b[i]);
		//rep(i,3)printf("%lld ", s[i]);
		//printf("\n");
		ans++;return 0;
	}
	int f[10] = {};
	rep(i,k)f[b[i]]++;
	if(a[k] != -1){
		if(f[a[k]])return 0;
		b[k] = a[k];
		dfs(k+1, b);
		return 0;
	}
	rrep(i,9){
		if(f[i] == 1)continue;
		b[k] = i;
		dfs(k+1, b);
	}
	return 0;
}

signed main(){
	rep(i,9)scanf("%lld", &a[i]);
	int b[10] = {};
	dfs(0, b);
	printf("%lld\n", ans);
	return 0;
}








Measured memory_bytes: 3236
def Checknum(str_num, input_list):
  for i in input_list:
    if i % 2 == 0:
      if not (i % 3 == 0 or i % 5 == 0):
        return "DENIED"
  return "APPROVED"

stranger_num = input()
input_list = list(map(int, input().split()))
print(Checknum(stranger_num, input_list))

Measured memory_bytes: 2940
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

N = int(input())
A = list(map(int, input().split()))

ans = 0
for i in range(1,N):
    if A[i-1] > A[i]:
        ans += A[i - 1] - A[i]
        A[i] = A[i-1]


print(ans)



















Measured memory_bytes: 34060
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n == 0)break;
			int[] a = new int[n];
			int x,y,z,v;
			int babaa = 0;
			v = 0;
			
			for(int i = 0; i < n; i++){
				a[i] = sc.nextInt();
				x = sc.nextInt();
				y = sc.nextInt();
				z = x + y;
				if(v < z){
					babaa = a[i];
					v = z;
				}
			}
			System.out.println(babaa + " " + v);
		}sc.close();
	}
}

Measured memory_bytes: 157788
#include<stdio.h>
int main(){
  int a, b;
  scanf("%d %d", &a, &b);
  if(a < b){
    printf("a < b\n");
  }else if(a > b){
    printf("a > b\n");
  } else if(a == b){
    printf("a == b\n");
  }
  return 0;
}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

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

    ll ans = 0;
    rep(i, n){
        int ii = i+1;
        if(ii%3 != 0 && ii%5 !=0){
            ans += ii;
        }
    }
    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<ll> d;

int main() {
    ll n, k;
    string s;
    cin >> n >> k;
    cin >> s;

    if (s[0] == '0') d.push_back(0);
    
    ll cnt = 0;
    rep(i, n) {
        ++cnt;
        if (s[i] != s[i+1]) {
            d.push_back(cnt);
            cnt = 0;
        }
    }

    if (cnt != 0) d.push_back(cnt);

    if (s[n-1] == '0') d.push_back(0);

    ll ans = -1;

    vector<ll> sum((int)d.size()+1, 0);

    for(int i=0; i<d.size(); ++i) sum[i+1] = sum[i] + d[i];

    for(int left=0; left<sum.size(); left+=2) {
        int right = left + 2*k+1;

        if (right>sum.size()) right =(int) sum.size()-1;

        ans = max(ans, sum[right]-sum[left]);
    }

    cout << ans << endl;

        
}



Measured memory_bytes: 2164
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
int n,ans,jc[1000001]={1};
int qpow(int i,int j){return j?j&1?qpow(i*i%mod,j>>1)*i%mod:qpow(i*i%mod,j>>1):1;}
int c(int i,int j)
{
	return jc[i]*qpow(jc[j]*jc[i-j]%mod,mod-2)%mod;
}
signed main()
{
	for(int i=1;i<=1000000;i++)jc[i]=jc[i-1]*i%mod;
	scanf("%lld",&n);
	for(int i=2;i<=n;i++)ans=(ans+(mod+qpow(2,i)-2)*qpow(8,n-i)%mod*c(n,i))%mod;
	printf("%lld",ans);
	return 0;
}


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

using namespace std;
using ll = long long;

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

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

    ll L = S.length();
    ll cnt = 0;
    REP(i,0,L/2){
        if(S[i] != S[L-i-1]) ++cnt;
    }
    _PR(cnt);

    return 0;
}

/*



*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
#define fori(a,b) for(int i=a;i<b;i++)
#define forj(a,b) for(int j=a;j<b;j++)
#define fork(a,b) for(int k=a;k<b;k++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define seto(x,i) memset(x,i,sizeof x)
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pf first
#define ps second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int N=300010;
int n,f[N],x,sum[N],mid;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("", "r", stdin);
    cin>>n;
    fori(0,n)
    {
        cin>>x;
        f[x]++;
    }
    f[0]=inf; sort(f,f+n+1); reverse(f,f+n+1);
    fori(1,n+1)
        sum[i]=sum[i-1]+f[i];
    mid=1;
    fori(1,n+1)
    {
        x=sum[n]-sum[i];
        while(f[mid]*(i-mid)-(sum[i]-sum[mid])>x)
            mid++;
        cout<<f[mid]+(x-f[mid]*(i-mid)+sum[i]-sum[mid])/(i-mid+1)<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3200