akhauriyash/Code-Regression huggingface dataset:
module WeightedGraph
  (Vertex : sig
    type t
    val compare : t -> t -> int
  end)
  (Weight : sig
    type t
    val compare : t -> t -> int
  end) :
sig
  val prim :
    (* 隣接リスト *)
    (Vertex.t -> (Vertex.t * Weight.t) list) ->
    (* 始点 *)
    Vertex.t ->
    (* 最小全域木に含まれる辺のリスト *)
    (Vertex.t * Vertex.t * Weight.t) list
end =
struct
  module VSet = Set.Make (Vertex)
  module WMap = Map.Make (Weight)
 
  (*
   * プリム法のメインループ
   * es : 隣接リスト
   * vs : 訪れた頂点の集合
   * q : 訪れた頂点から伸びる辺が重み順に入ったヒープ
   * acc : 最小全域木に使うのが確定した辺を入れるやつ
   *)
  let rec prim_aux es acc vs q =
    match WMap.min_binding q with
    | exception Not_found -> acc
    | (w, []) -> prim_aux es acc vs (WMap.remove w q)
    | (w, (u, v) :: rest) ->
        if VSet.mem v vs then
          (* vは既に訪れていた *)
          prim_aux es acc vs (WMap.add w rest q)
        else
          (* vはまだ訪れていなかった *)
          prim_aux es ((u, v, w) :: acc) (VSet.add v vs) @@
            (* vから伸びる辺をキューに追加 *)
            List.fold_left (fun q (u, w) ->
              (* 現時点で既に訪れている頂点への辺は追加しない *)
              if VSet.mem u vs then q
              else WMap.add w ((v, u) :: try WMap.find w q with Not_found -> []) q) (WMap.add w rest q) (es v)
 
  let prim es s =
    prim_aux es [] (VSet.singleton s) @@
      (* 始点から伸びる辺をキューに入れておく *)
      List.fold_left (fun q (v, w) ->
        WMap.add w ((s, v) :: try WMap.find w q with Not_found -> []) q) WMap.empty (es s)
end

module Int = struct
  type t = int
  let zero = 0
  let ( + ) = ( + )
  let compare = compare
end

module G = WeightedGraph (Int) (Int)
 
let () = Scanf.scanf "%d\n" (fun n ->
  let xys = Array.to_list @@ Array.init n (fun i -> Scanf.scanf "%d %d\n" (fun x y -> x, y, i)) in
  let es = Array.make n [] in
  begin match List.sort (fun (x, _, _) (x', _, _) -> compare x x') xys with
  | [] -> ()
  | (x, y, i) :: rest ->
      ignore @@ List.fold_left (fun (x, y, i) (x', y', j) ->
        es.(i) <- (j, min (abs (x - x')) (abs (y - y'))) :: es.(i);
        es.(j) <- (i, min (abs (x - x')) (abs (y - y'))) :: es.(j);
        (x', y', j)) (x, y, i) rest
  end;
  begin match List.sort (fun (_, y, _) (_, y', _) -> compare y y') xys with
  | [] -> ()
  | (x, y, i) :: rest ->
      ignore @@ List.fold_left (fun (x, y, i) (x', y', j) ->
        es.(i) <- (j, min (abs (x - x')) (abs (y - y'))) :: es.(i);
        es.(j) <- (i, min (abs (x - x')) (abs (y - y'))) :: es.(j);
        (x', y', j)) (x, y, i) rest
  end;
  G.prim (fun i -> es.(i)) 0
  |> List.map (fun (_, _, w) -> w)
  |> List.fold_left ( + ) 0
  |> Printf.printf "%d\n")

Measured memory_bytes: 65532
#include <bits/stdc++.h>
using namespace std;
#define lo long
const int lmax=1999999999;
const long long lmx=1999999999999999999;
long long n,m,ans;
vector<long long>v;
int main(){std::ios::sync_with_stdio(false);
cin>>n>>m;
for(long long i=1;i*i<=m;i++)
{
	if(m%i==0)
	{
		v.push_back(i);
		if(i!=m/i)
		{
			v.push_back(m/i);
		}
	}
}
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++)
{
	long long q=m/v[i];
	if(q>=n)
	{
		ans=v[i];
	}
}
cout<<ans<<endl;
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
               *       * *       *
               *        *        *
                *               *
                 *             *
                  *           *
                   *         *
                    *       *
                     *     *
                      *   *
                       * *
                        *



*/





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

#define task "D"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;

// Limit
const int N=1e6+1;
// Struct

// Variables
ll a,b,snt[N];
vi pr;
// Function
int factorize(long long n)
{
    int cnt = 0;
    if (n%2==0) cnt++;
    while (!(n % 2)) {
        n >>= 1; // equivalent to n=n/2;
    }
    for (long long i = 3; i <= sqrt(n); i += 2) {
        if (n%i==0) cnt++;
        while (n % i == 0) n = n / i;
    }
    if (n>2) cnt++;
    return cnt;
}
int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> a >> b;
	ll g=__gcd(a,b);
	cout << factorize(g)+1;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int d, n;
  cin >> d >> n;
  if(n==100)n++;
  if(d==0) cout<<n<<endl;
  if(d==1) cout<<n*100<<endl;
  if(d==2) cout<<n*10000<<endl;
}


Measured memory_bytes: 256
import sys

abc_list = []
for i in range(5):
    abc_list.append(int(input()))

k = int(input())

for i in range(0, len(abc_list)):
    for j in range(0, len(abc_list)):
        if i == j:
            continue
        if abs(abc_list[i] - abc_list[j]) > k:
            print(':(')
            sys.exit()

print('Yay!')


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

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

    // p=2またはp=5の場合は,10の約数であるため個別に計算
    // s[i]がpで割り切れるなら，i+1個の部分文字列がpで割り切れる．
    // ex. p=2, s=24567, i=1のとき，s[i]=4. 具体的には，4と24の2つがpで割り切れる文字列となる
    if (p == 2 || p == 5) {
        long long ans = 0;
        for (int i=0; i<n; i++) {
            if( (s[i]-'0') % p == 0 ) {
                ans += (i+1);
            }
        }
        cout << ans << endl;
        return 0;
    }

    // pが2でも5でもない場合は，ある数にいくら10をかけてもpで割りきれるかは変わらないことを利用して，
    // 10^5桁のような大きな数にも対応できるようにする

    // 10^i の値をpで割った余り pow10p[i] を求める
    // 10^i % p = { (10^(i-1) % p) * (10 % p) } % p
    int pow10p[n+1];
    pow10p[0] = 1;
    for (int i=1; i<=n; i++) {
        pow10p[i] = ( (pow10p[i-1] % p) * (10 % p) ) % p;
    }

    // sのi桁目より先を0にした値をpで割った余り mod[i] を求める
    // ex. n=4,p=11,i=2のとき，3300 % 11 = (3000 % 11 + 300 % 11) % 11
    // mod[i] = { mod[i-1] + (s[i-1] * 10^(n-i)) % p } % p ; s[i-1] * 10^(n-i)の計算は大きすぎることがあるので分割
    // = { mod[i-1] + ( s[i-1]%p * (10^(n-i)%p) % p } % p  ; 10^(n-i)%pは先ほどpow10pで求めた
    // = { mod[i-1] + ( s[i-1]%p * pow10p[n-i] ) % p } % p
    int mod[n+1];
    mod[0] = 0; // 0 はいかなる素数で割った余りも自明に0
    for (int i=1; i<=n; i++) {
        int c = s[i-1]-'0';
        mod[i] = ( mod[i-1] + (c%p * pow10p[n-i])%p ) % p;
    }

    // 例えば，33883 という文字列の中の 88 という部分文字列をp=11で割った余りの有無は次のように分解できる
    // 88 % 11 ≡ 880 % 11 ; 88に何度10をかけても，追加される素因数は2と5のみ．今pは2でも5でもないと仮定しているので余りの有無は変わらない
    // = (33880 - 33000) % 11
    // = { (33880 % 11) - (33000 % 11) + p} % 11 ; 引き算の分解は結果が負の余りになることがあるので，pを足す．pを足しても余りは変わらない．
    // = (mod[4] - mod[2] + p) % 11
    // この値が0かどうかが，部分文字列の余りの有無となる．
    // 従って，全てのmodの組み合わせn(n+1)/2個に対して上記を一般化した式を適用し，その結果が0であるかを確かめれば良い．

    // しかし，全てのmodのペアを確かめていたらO(n^2)かかってしまうので，工夫が必要．
    // modに記録される全ての値はpで割った余りであるため，p未満であることに注意すると，
    // 先ほどの式の例の「mod[4] - mod[2]」の部分が0の時，すなわち mod[4] = mod[2] の時に限り，
    // その組み合わせからなる部分文字列がpで割り切れる．
    // 従って先ほどの命題は，mod内の同じ値を持つ組み合わせの数を数えることと等価である．
    
    // modに入っている全ての値はp<10000未満であることに注意すると，
    // 上記のタスクはmodに出現する整数をカウントし，
    // 同じmod値が出てきたら「それまでのカウント数」をansに追加することで，
    // O(n)で達成できる．
    // あるmod値が現れた時，増加する組み合わせの数は「それまでのカウント数」であるためである．
    // 例えば，mod値0が2回現れていた時，新たにmod値0が出現したら，新たに2つの同じ値の組み合わせが増えることとなる．
    long long ans=0, cnt[10000] = {}; // 0初期化．10000のところをpにするとエラー

    for (int i=0; i<=n; i++) {
        ans += cnt[mod[i]];
        cnt[mod[i]]++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 2180
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>

using namespace std;

typedef long long ll;


int N;
vector<int> c[300000];
int m[300000];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> m[i];
		for (int j = 0; j < m[i]; j++) {
			int c1;
			cin >> c1;
			c[i].push_back(c1);
		}
	}

	priority_queue<int> pq;
	ll ans = 0;
	for (int i = N - 1; i >= 0; i--) {
		for (int j = 0; j < m[i]; j++) {
			pq.push(c[i][j]);
		}

		ans += pq.top();
		pq.pop();
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 20672
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  set<ll> vs;
  vector<ll> a(n);
  rep(i,n) {
    cin >> a[i];
    vs.insert(a[i]);
  }

  unordered_map<ll,ll> cnts;
  rep(i,n) {
    ++cnts[a[i]];
  }

  ll maxV = 0;
  for (ll v : vs) {
    chmax(maxV, v);
  }
  vector<ll> dp(maxV+1,true);
  for (ll v : vs) {
    for (ll k = 2; k*v <= maxV; ++k) {
      dp[k*v] = false;
    }
  }

  ll ans = 0;
  for (ll v : vs) {
    if (cnts[v] >= 2) { continue; } // skip with multiple one
    if (dp[v]) { // valid
      ++ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 30204
N = int(input())

def divisor_pairs(n):
  # n の正の約数の数
  # ペアの数を保存しておけばいい
  pairs = 0

  # 約数判定はO(√N)で出来るということを知っておく
  i = 1

  while i * i <= n:
    if n % i == 0:
      pairs += 1
    i += 1
  return pairs

result = 0

# 奇数なのでステップ数を2に指定
for x in range(1, N+1, 2):
  if divisor_pairs(x) == 4:
    result += 1

print(result)

Measured memory_bytes: 9116
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str
odd = ['R', 'U', 'D']
even = ['L', 'U', 'D']

def solve(S: str):
    for i in range(len(S)):
        if i % 2 == 0:
            if not S[i] in odd:
                print(NO)
                sys.exit(0)
        else:
            if not S[i] in even:
                print(NO)
                sys.exit(0)
    print(YES)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
// header file section
#include <iostream>
#include <cstdio>
#include <cfloat>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <numeric>
#include <algorithm>

using namespace std;
using llong = long long;

// library section
// ===

int main() {
    llong a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
    return 0;
};



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

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

    int ans = 0;
    for (int i = s.size() - 2; i >= 2; i -= 2) {
        if (s.substr(0, i / 2) == s.substr(i / 2, i / 2)) {
            ans = i;
            break;
        }
    }

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


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];
#define int long long

const int MOD = 1e9+7;

int modinv(int a){
    int b = MOD, p = 1, q = 0;
    int temp;
    while(b>0){
        temp = a/b;
        a -= temp * b; swap(a, b);
        p -= temp * q; swap(p, q);
    }
    p %= MOD; if(p<0) p += MOD;
    return p;
}

int modinvfact(int n){
    int a = 1;
    rep(i,n) a = a * modinv(i+1) % MOD;
    return a;
}

int modfact(int n){
    int a = 1;
    rep(i,n) a = a * (i+1) % MOD;
    return a;
}

signed main(){
    int X,Y; cin >> X >> Y;
    int a = (2*X-Y)/3, b = (2*Y-X)/3;
    if((2*X-Y) % 3 != 0 || a < 0 || b < 0){
        cout << 0 << endl;
        return 0;
    }
    int ans = modfact(a+b);
    ans *= (modinvfact(a) * modinvfact(b)) % MOD;
    ans %= MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def makelist2(n, m):
    return [[0 for k in range(m)] for i in range(n)]

n, m = map(int, input().split())
switches = makelist2(n,m)
for i in range(m):
    tmp = list(map(int, input().split()))
    for j in range(len(tmp)-1):
        switches[tmp[j+1]-1][i] = 1

p = list(map(int, input().split()))

ans = 0
for i in range(pow(2,n)):
    frag = True
    target = "{:0>{}b}".format(i, n)
    for j in range(m):
        kosuu = 0
        for k in range(n):
            if(target[k]=="1"):
                if(switches[k][j]==1):
                    kosuu += 1
        if(kosuu%2 != p[j]):
            frag = False
    if(frag):
        ans += 1

print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll N;
    cin >> N;
    vec A(N);
    Rep (i, N) {
        cin >> A[i];
    }

    ll dp[N+2][3];
    Rep (i, N+2) {
        Rep (j, 3) {
            dp[i][j] = -inf;
        }
    }
    dp[0][0] = 0;

    Rep (i, N+1) {
        Rep (j, 3) {
            if (i+2 < N+2) chmax(dp[i+2][j], dp[i][j] + A[i]);
            if (j+1 < 3) chmax(dp[i+1][j+1], dp[i][j]);
        }
    }

    // Rep (i, N+2) {
    //     Rep (j, 3) {
    //         cout << dp[i][j] << " \n"[j==2];
    //     }
    // }

    if (N%2 == 0) {
        cout << dp[N+1][1] << endl;
    } else {
        cout << dp[N+1][2] << endl;
    }

}

Measured memory_bytes: 9504
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll a,b,c;
    std::cin >> a>>b>>c;
    std::cout << min(b/a,c) << std::endl;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int K, X;
        Scanner scan = new Scanner(System.in);
        K = scan.nextInt();
        X = scan.nextInt();
        if(K*500>=X){
            System.out.print("Yes");
        }else{
            System.out.print("No");
        }
    }
}

Measured memory_bytes: 22612
def d(u):
 global t
 C[u]=1;t+=1;D[u]=t
 for v in range(N):
  if M[u][v]and C[v]==0:d(v)
 C[u]=2;t+=1;F[u]=t
N=int(input())
M=[[0]*N for _ in[0]*N]
for e in[input().split()for _ in[0]*N]:
 for v in e[2:]:M[int(e[0])-1][int(v)-1]=1
C,D,F=[0]*N,[0]*N,[0]*N
t=0
for i in range(N):
 if C[i]==0:d(i)
for i in range(N):print(i+1,D[i],F[i])


Measured memory_bytes: 5800
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

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

func main() {
	n := nextInt()
	v := nextStrings(n)
	m := make(map[string]int)
	ans := 0

	for i := 0; i < n; i++ {
		s := strings.Split(v[i], "")
		sort.Strings(s)
		sorted := strings.Join(s, "")

		if _, ok := m[sorted]; ok {
			m[sorted]++
		} else {
			m[sorted] = 1
		}
	}

	for _, v := range m {
		p := v * (v - 1) / 2
		ans += p
	}

	fmt.Println(ans)
}

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

var dx = []int{0, 1, 0, -1, 0}
var dy = []int{1, 0, -1, 0, 0}
var inf = int(1e9)

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}

func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}

func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}

var nextReader func() []byte

func init() {
	nextReader = newScanner()
	log.SetFlags(log.Lshortfile)
}

func newScanner() func() []byte {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() []byte {
		r.Scan()
		return r.Bytes()
	}
}

func nextBytes() []byte {
	return nextReader()
}

func nextString() string {
	return string(nextReader())
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(string(nextReader()), 10, 64)
	return v
}

func nextInt() int {
	v, _ := strconv.Atoi(string(nextReader()))
	return v
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextStrings(n int) []string {
	r := make([]string, n)
	for i := 0; i < n; i++ {
		r[i] = nextString()
	}
	return r
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(string(nextReader()), 64)
	return f
}


Measured memory_bytes: 18048
#include <stdio.h>

int main(void){
	int h, w;
	int i, j;

	while(1){
		scanf("%d %d ", &h, &w);
		if(h==0&&w==0)break;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 576
_ = input()
aa = list(map(int, input().split()))

prev = aa[0]
cnt = 1
ops = 0
for a in aa[1:]:
    if a == prev:
        cnt += 1
    else:
        ops += cnt // 2
        cnt = 1
    prev = a

ops += cnt // 2

print(ops)


Measured memory_bytes: 2940
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;

int main(){
	int n;
	while(scanf("%d",&n)==1,n){
		vector<int> table;
		for(int x=0;x<n;++x){
			int j;scanf("%d",&j);
			table.push_back(j);
		}
		sort(table.begin(),table.end());
		stringstream buf;
		buf.str("");
		for(int x=0;x<table.size();){
			int i = x;
			while(x+1<table.size() && table[x] == table[x+1]-1){
					++x;
			}
			int j = x;
			if(buf.str()!=""){
				buf<<" ";
			}
			if(j==i){
				buf<<table[i];
			}else{
				buf<<table[i]<<"-"<<table[j];
			}
			++x;
		}
		cout<<buf.str()<<endl;
	}
	return 0;
}

Measured memory_bytes: 1264
#include <iostream>
using namespace std;
int main(){
    int n ;
    cin >> n ;
    int a[n] ;
    for(int i = 1 ; i <= n ; i++){
        cin >> a[i] ;
    }
    for(int j = 1 ; j <= n - 1 ; j++){
        cout << a[n - j + 1] << " " ;
    }
    cout << a[1] << endl ;
}



Measured memory_bytes: 3084
M = 998244353
n, m, k = map(int, input().split())
k = n - k - 1
p = n - 1
F = [1]
for i in range(n + 1091):
    F.append((F[-1] * (i + 1)) % M)


def C(k, n): return (F[n] * pow(F[k] * F[n - k], M - 2, M))


ans = pow(m, n, M)
for x in range(k):
    ans -= C(x, p) * m * pow(m - 1, x, M)
    ans %= M
print(ans)


Measured memory_bytes: 16932
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

template <typename T>
inline T gi()
{
	T f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 100003, M = N << 2;

int n, a[N][3];
int dp[N][3];

int main()
{
	//File("");
	n = gi <int> ();
	for (int i = 1; i <= n; i+=1)
		for (int j = 0; j < 3; j+=1) a[i][j] = gi <int> ();
	for (int i = 1; i <= n; i+=1)
		for (int j = 0; j < 3; j+=1)
			for (int k = 0; k < 3; k+=1)
				if (j != k)
					dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]);
	printf("%d\n", max(dp[n][0], max(dp[n][1], dp[n][2])));
	return 0;
}


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

int main(){
	string s;
	cin >> s;
	map<int,int> a;
	LL n = s.size();
	LL ans = n*(n-1)/2;
	for(int i = 0; i < s.size(); i++){
		ans -= a[s[i]-'a'];
		a[s[i]-'a']++;
	}
	cout << ans + 1 << endl;
}


Measured memory_bytes: 640
a = input()
b=int(a[0:2])
c=int(a[2:4])
if 1<=b<=12 and 1<=c<=12:
    print('AMBIGUOUS')
elif 1<=b<=12 :
    print('MMYY') 
elif 1<=c<=12:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
import sys, math
from collections import defaultdict
from itertools import product
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N, K = mi()
    A = list(mi())
    for i in range(K, N):
        if A[i-K] < A[i]:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 106084
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h> 
#include<random>
#define int long long   
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
#define for1(i,a,n)  for(int i=0;i<n;i++)
#define rep(i, c) for(int i = 0; i < (int)c; i++)
#define set(x) cout<<fixed<<setprecision(x);
using namespace std;
//**********************************************DO IT NO****************************************************************
void fastio()
{  
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
int a[1000000];
signed main()
{   
    fastio();
    int t=1;
    //cin>>t;
    while(t--)
    {  
      string s;
      cin>>s;
      int n=s.length();
      int x=0,xx=0;
      for(int i=0;i<n;i++)
      {
          if(s[i]=='A')
          {
              x=i;
              break;
          }
      }
      for(int i=n-1;i>=0;i--)
      {
          if(s[i]=='Z')
          {
              xx=i;
              break;
          }
      }
      cout<<xx-x+1;
    }
}
// 🍪 🍪 🍪


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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  int i;
  for(i = 0; i<n;i++){
    cin >> h[i];
  }
  sort(h.begin(),h.end());
  vector<int> g(n-k+1);
  int j;
  for(i = 0;i < n-k+1;i++){
    g[i] = h[i+k-1] - h[i];
  }
  j = g[0];
  for(i = 1;i<n-k+1;i++){
    if(g[i] < j){
      j = g[i];
    }
  }
  cout << j << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#define ll long long int
int gcd(int i, int j) {
  if (i == 0) return j;
  return gcd(j%i, i);
}

int main() {
  int n, k;
  std::cin >> n;
  std::vector<int> a;
  for(int i = 0; i < n; i++) {
    std::cin >> k;
    a.push_back(k);
  }
  /*
  int big = 0;
  for(int i = 0; i < n-1; i++) {
    for(int j = i + 1; j < n; j++) {
      int gcdij = gcd(a[i], a[j]);
      if(big < gcdij) big = gcdij;
    }
  }
  std::cout << big << std::endl;
  */
  std::vector<int> left(n), right(n);
  left[0] = a[0];
  right[n-1] = a[n-1];
  for(int i = 1; i < n; i++) {
    left[i] = gcd(left[i-1], a[i]);
  }

  for(int i = n-2; i >= 0; i--) {
    right[i] = gcd(a[i], right[i+1]);
  }
  int max = 0;
  for(int j = 1; j < n-1; j++) {
    int g = gcd(left[j-1], right[j+1]);
    if(g > max) {
      max = g;
    }
  }
  if(max < left[n-2]) max = left[n-2];
  if(max < right[1]) max = right[1];
  std::cout << max << std::endl;

  // scanl
  /*
  vector<int> a = {1, 2, 3, 4, 5};
  int r = a[0];
  vector<int> v;
  v.push_back(r);
  for (int i = 1; i < 5; i++) {
    if (r > a[i]) r = a[i];
    else r = r;
    v.push_back(r);
    }
  */
}


Measured memory_bytes: 1528
/**
 * Created by akensho on 2015/11/22.
 */
import java.util.*;
class Main {
    static int n;
    static int[] a;
    static Scanner scanner = new Scanner(System.in);
    public static void main(String[] args){
        while( read() ){
            insertionSort(a);
        }
    }

    static boolean read(){
        if( !scanner.hasNext() ) return false;
        n = scanner.nextInt();
        a = new int[n];
        for(int i = 0; i < a.length; i++){
            a[i] = scanner.nextInt();
        }
        return true;
    }

    /**
     * ?????\??????????????????????????????
     * @param array := 0-indexed ??§ N ??????????´????????????????
     * return ????????????????????????
     */
    static int[] insertionSort(int[] array){
        for (int i = 0; i < array.length; i++) {
            int v = array[i];
            int j = i-1;
            while ( j >= 0 && array[j] > v ){
                array[j+1] = array[j];
                j--;
            }
            array[j+1] = v;
            traceArray(array);
        }
        return array;
    }

    static void traceArray(int[] array){
        for(int i = 0; i < array.length; i++){
            if (i == array.length - 1) {
                System.out.print(array[i]);
                continue;
            }
            System.out.print(array[i] + " ");
        }
        System.out.println();
    }

}

Measured memory_bytes: 33512
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <utility>
#include <set>
#include <unordered_map>
#include <cassert>

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define IPSILON 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
  int r;
  cin >> r;
  cout << r*r << endl;
  return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
int main(void){
    long A,B,K;
    
    cin >> A >> B >> K;
    long resultB;
    if(A-K>=0){
        cout << A-K << " " << B << endl;//自分のクッキーを食べるだけ
    }else{
        resultB=B-(K-A);
        if(resultB>=0){
            cout << 0 << " " << resultB << endl;
        }else{
            cout << 0 << " " << 0 << endl;
        }
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
int main(){
	int n,i,a,b,c;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a>>b>>c;
		if(a*a==b*b+c*c||b*b==a*a+c*c||c*c==b*b+a*a){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}

	}
    return 0;
	
}

Measured memory_bytes: 1152
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
using namespace std;

int main(void)
{
    int n;
    string a;
    int i;

    ios::sync_with_stdio(false);
    cin >> n >> a;
    for(i = 0; i < (signed)a.size(); i ++)
        cout << (char)((a[i] - 65 + n) % 26 + 65);
    cout << endl;

    return 0;
}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  llvec s(N);
  ll A=0,B=0;
  rep(i, N){
    ll a, b;
    cin >> a >> b;
    A+=a;
    B+=b;
    s[i] = a+b;
  }
  sort(rALL(s));
  ll ans = -B;
  rep(i, N){
    if(i%2==0){
      ans += s[i];
    }
  }
  cout << ans <<endl;
  return 0;
}


Measured memory_bytes: 4060
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-2;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n;
int a[1 << 17];

struct SegT {
private:
	int sz; vector<LP> node;
	const LP init_c = { 0,0 };
public:
	SegT(int n) {
		sz = 1;
		while (sz < n)sz *= 2;
		node.resize(2 * sz - 1, init_c);
	}
	LP f(LP a, LP b) {
		return max(a, b);
	}
	void update(int k, LP a) {
		k += sz - 1;
		node[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			node[k] = f(node[k * 2 + 1], node[k * 2 + 2]);
		}
	}
	LP query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = sz;
		if (r <= a || b <= l)return init_c;
		else if (a <= l && r <= b)return node[k];
		else {
			LP vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			LP vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return f(vl, vr);
		}
	}
};
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	SegT st(100001);
	rep(i, n) {
		LP z = st.query(0, a[i]);
		z.first++; z.second += a[i];
		st.update(a[i], z);
	}
	LP z = st.query(0, 100001);
	cout << z.second << endl;
	//stop
	return 0;
}



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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n), b(n), ab;
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  ll ans = 0, s = 0;
  rep(i, n) {
    if (a[i] < b[i]) {
      ans++;
      s += b[i] - a[i];
    } else {
      ab.push_back(a[i] - b[i]);
    }
  }
  sort(ab.rbegin(), ab.rend());
  if (s > 0) {
    rep(i, ab.size()) {
      s -= ab[i];
      ans++;
      if (s < 0) break;
    }
  }
  if (s > 0) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 5708
n = int(input())
S = input()

left = [0]
right = [0]

for s in S:
    left.append(left[-1] + (1 if s == '#' else 0))

for s in S[::-1]:
    right.append(right[-1] + (1 if s == '.' else 0))

ans = n

for i in range(0, n + 1):
    ans = min(ans, left[i] + right[n - i])

print(ans)

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

using namespace std;
int main(){
    int K;
    cin >> K;
    if(K % 2 == 0){
        cout << K * K / 4 << endl;
    }else{
        cout << (K - 1) * (K + 1) / 4 << endl;
    }
}

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

int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    vector<ll> ans;
    
    ll bl=0,wh=0;
    rep(i,n){
        if(s[i]=='.'){
            wh++;
        }
    }
    rep(i,n){
        if(s[i]=='.')wh--;
        ans.push_back(wh+bl);
        if(s[i]=='#'){
            bl++;
        }
    }
    sort(ans.begin(),ans.end());
    cout << ans[0] << endl;
}

Measured memory_bytes: 2680
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	string s; cin >> s;
 	int n = s.l_ength();
  	int ans = n;
	for( int i = 0; i < n-1; ++i ){
		if( s[i] != s[i+1] ){
			ans = min(ans, max(i+1, n-i-1));
		}
	}
	cout << ans << endl;
}

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

struct food {
	string f;
	int w, s;

	food(string f_, int w_, int s_) {
		f = f_; w = w_, s = s_;
	}
};

int N;
vector<food> v;
const int INF = 1000000000;

int G[1 << 10][10];

bool withstand(int status, int next) {
	int sw = 0;
	for(int i = 0; i < N; i++) {
		if(status & (1 << i)) {
			sw += v[i].w;
		}
	}

	return v[next].s >= sw;
}

int DP(int status, int bottom) {
	if(!withstand(status & ~(1 << bottom), bottom))
		return INF;

	if(G[status][bottom] != -1) {
		return G[status][bottom];
	}

	G[status][bottom] = INF;

	int depth = 0;
	for(int i = 0; i < N; i++)
		if(status & (1 << i))
			depth++;

	for(int i = 0; i < N; i++) {
		if(status & (1 << i)) {
			G[status][bottom] = min(G[status][bottom], DP(status & ~(1 << bottom), i) + (N - depth + 1) * v[bottom].w);
		}
	}

	return G[status][bottom];
}

int main() {
	while(cin >> N, N) {
		v.clear();
		for(int i = 0; i < N; i++) {
			string f;
			int w, s;
			cin >> f >> w >> s;
			v.push_back(food(f, w, s));
		}
		for(int i = 0; i < 1 << N; i++) {
			for(int j = 0; j < N; j++) {
				G[i][j] = -1;
			}
		}
		for(int i = 0; i < N; i++) {
			G[0][i] = 0;
		}
		int ret = INF;
		for(int i = 0; i < N; i++) {
			int tmp = DP((1 << N) - 1, i);
			ret = min(ret, tmp < 0 ? INF : tmp);
		}
//		cout << ret << endl;
		queue<int> q;
		int status = (1 << N) - 1;
		while(status) {
			for(int i = 0; i < N; i++) {
				if(ret == G[status][i] && (status & (1 << i))) {
					q.push(i);
					ret -= v[i].w * q.size();
					status &= ~(1 << i);
					break;
				}
			}
		}

		while(!q.empty()) {
			cout << v[q.front()].f << endl;
			q.pop();
		}
	}
}

Measured memory_bytes: 1252
#include <stdio.h>
int main(void) {
    int x,y,temp;
    while (1) {
        scanf("%d %d",&x,&y);
        if (x==0&&y==0) break;
        if (x<y) {
            printf("%d %d\n",x,y);
        } else {
            printf("%d %d\n",y,x);
        }
    }
    return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=1e6+5;
int num[maxn];
int main()
{
    string ss;
    cin>>ss;
    reverse(ss.begin(),ss.end());
    for(int i=1;i<=ss.length();i++)
        num[i]=(ss[i-1]-'0');
    int ans=0;
    for(int i=1;i<=ss.length()+1;i++)
    {
        if(num[i]<=4) ans+=num[i];
        else if(num[i]==5)
        {
            if(num[i+1]>=5)
            {
                ans+=(10-num[i]);
                num[i+1]++;
            }
            else ans+=num[i];
        }
        else
        {
            ans+=(10-num[i]);
            num[i+1]++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 5252
import java.util.*;

class Main {
    //Floyd Warshall's Algorithm
    private static final long MAX = (long) (2e10 + 1);
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        int V = scanner.nextInt();
        int E = scanner.nextInt();

        long[][] dist = new long[V][V];

        for(int i = 0; i < V; ++i){
            Arrays.fill(dist[i], MAX);
            dist[i][i] = 0;
        }

        for(int i = 0; i < E; ++i){
            int u = scanner.nextInt();
            int v = scanner.nextInt();
            int weight = scanner.nextInt();

            dist[u][v] = weight;
        }

        for(int k = 0; k < V; ++k){
            for(int i = 0; i < V; ++i){
                for(int j = 0; j < V; ++j){
                    if(dist[i][k] != MAX && dist[k][j] != MAX && dist[i][k] + dist[k][j] < dist[i][j]){
                        dist[i][j] = dist[i][k] + dist[k][j];
                    }
                }
            }
        }

        for(int i = 0; i < V; ++i){
            if(dist[i][i] < 0){
                System.out.println("NEGATIVE CYCLE");
                return;
            }
        }

        for(int i = 0; i < V; ++i){
            for(int j = 0; j < V; ++j){
                System.out.print(dist[i][j] == MAX ? "INF" : dist[i][j]);
                if(j != V - 1){
                    System.out.print(" ");
                }
            }
            System.out.println("");
        }
    }
}

Measured memory_bytes: 59756
#include <bits/stdc++.h>
using namespace std;
uint64_t numbers(uint64_t &B, uint64_t &C, uint64_t &D){
  uint64_t h=C;
  uint64_t g=D;
  uint64_t cd=C*D;
  uint64_t t;
  while (h%g!=0){
    t=g;
    g=h%g;
    h=t;
  }
  
  uint64_t l =cd/g; //6
  uint64_t n = B/C + B/D;// 4,3 7
  
  n-=B/l;
  n=B-n;
  
  return n;
}
int main(){
  uint64_t A,B,C,D;
  cin>>A>>B>>C>>D;
  A--;
  uint64_t a=numbers(A,C,D);
  uint64_t b=numbers(B,C,D);
  uint64_t total = b-a;
  printf("%lld",total);
}
      

Measured memory_bytes: 256
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int a, b; cin >> a >> b;
	if(a > 9 or b > 9) { println(-1); return 0; }
	println(a*b);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		UL C, K; cin >> C >> K;
		vector<UL> buf(N); rep(i, N) cin >> buf[i];
		sort(buf.begin(), buf.end());
		deque<UL> T;
		UL ans = 0;
		rep(i, N) {
			UL t = buf[i];
			if (T.size()) {
				if (T.front() + K < t) {
					ans++;
					T.clear();
				}
			}
			T.push_back(t);
			if (T.size() >= C) {
				ans++; T.clear();
			}
		}
		if (T.size()) { ans++; T.clear(); }
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 640
N = int(input())
candyNum1 = list(map(int, input().split()))
candyNum2 = list(map(int, input().split()))
totalList = list()

for i in range(N):
	j = 0
	temp1 = 0
	temp2 = 0
	
	while j <= i:
		temp1 += candyNum1[j]
		j += 1
		
	for k in range(j-1, N):
		temp2 += candyNum2[k]
	
	totalList.append(temp1 + temp2)

print(max(totalList))
	

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;

int main(){
  long long count[5]={0};
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    if(s[0]=='M'){
      count[0]++;
    }
    else if(s[0]=='A') count[1]++;
    else if(s[0]=='R') count[2]++;
    else if(s[0]=='C') count[3]++;
    else if(s[0]=='H') count[4]++;
  }
  long long ans=0;
  for(int i=0;i<5;i++){
    for(int k=0;k<5;k++){
      for(int j=0;j<5;j++){
        if(i!=k && k!=j && j!=i){
          ans+=count[i]*count[k]*count[j];
        }
      }
    }
  }
  cout<<ans/6<<endl;

}


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

using namespace std;
int main() {
    string s;
    cin >> s;
    if(s == "SUN"){
        cout << "7" << endl;
    }
    if(s == "MON"){
        cout << "6" << endl;
    }
    if(s == "TUE"){
        cout << "5" << endl;
    }
    if(s == "WED"){
        cout << "4" << endl;
    }
    if(s == "THU"){
        cout << 3 << endl;
    }
    if(s == "FRI"){
        cout << 2 << endl;
    }
    if(s == "SAT"){
        cout << 1 << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
    char a[10], b[10], c[10];
    scanf("%s %s %s", a, b, c);
    printf("%c%c%c\n", toupper(a[0]), toupper(b[0]), toupper(c[0]));
    return 0;
}


Measured memory_bytes: 128
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=0
y=0
for i in range(n-1):
  for j in range(i+1,n):
    if a[i]>a[j]:
      x+=1
for l in range(n):
  for m in range(n):
    if a[l]>a[m]:
      y+=1
ans=((k*(k-1)*y)//2)%(1000000007)+(k*x)%1000000007
print(ans%1000000007)

Measured memory_bytes: 42092
#!/usr/bin/env python3
import sys


def solve(A: "List[int]"):
    if sum(A) >= 22:
        print('bust')
    else:
        print('win')
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = [int(next(tokens)) for _ in range(3)]  # type: "List[int]"
    solve(A)

if __name__ == '__main__':
    main()


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

int main() {
  int N,M;
  cin >> N >> M;
  vector<int> cnt(M);
  for (int i=0; i<N; i++) {
    int K;
    cin >> K;
    for (int j=0; j<K; j++) {
      int A;
      cin >> A;
      A--;
      cnt[A]++;
    }
  }
  int ans=0;
  for (int i=0; i<M; i++) {
    if (cnt[i] == N) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

inline char gc()
{
	static char buf[524288],*p1 = buf,*p2 = buf;
	return p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,524288,stdin),p1 == p2) ? EOF : *p1++;
}

inline void read(int &v)
{
	v = 0;
	char c = gc();
	bool fl = 0;
	while ((c < '0' || c > '9') && c != '-')
		c = gc();
	if (c == '-')
	{
		fl = 1;
		c = gc();
	}
	while (c >= '0' && c <= '9')
	{
		v = v * 10 + c - '0';
		c = gc();
	}
	if (fl)
		v = -v;
}

const int MAXN = 500005;
const int INF = 1 << 30;
const int MOD = 1000000007;

struct River
{
	int b,k;
}r[MAXN];

int n;
int f[MAXN];
int L[MAXN];
int R[MAXN];
int sum[MAXN];
int val[MAXN << 1];

vector<int> e[MAXN];

bool cmp1(const River &a,const River &b)
{
	return a.b < b.b;
}

bool cmp2(const River &a,const River &b)
{
	return a.k == b.k ? a.b < b.b : a.k < b.k;
}

int SUM(int l,int r)
{
	if (!l)
		return sum[r];
	return (sum[r] - sum[l - 1] + MOD) % MOD;
}

void mdf(int p,int v)
{
	p += n + 1;
	while (p <= (n << 1 | 1))
	{
		val[p] = min(val[p],v);
		p += p & -p;
	}
}

int qry(int p)
{
	p += n + 1;
	int res = INF;
	while (p >= 1)
	{
		res = min(res,val[p]);
		p -= p & -p;
	}
	return res;
}

int main()
{
	read(n);
	for (int i = 1;i <= n;i++)
		read(r[i].b),read(r[i].k);
	sort(r + 1,r + n + 1,cmp1);
	for (int i = 1;i <= n;i++)
		r[i].b = i;
	sort(r + 1,r + n + 1,cmp2);
	for (int i = 1;i <= n;i++)
		val[i] = INF;
	r[0].k = -INF;
	r[n + 1].k = INF;
	for (int i = 1;i <= n;i++)
	{
		L[i] = min(i,qry(-r[i].b));
		if (r[i].k != r[i + 1].k)
		{
			for (int j = i;j >= 1 && r[j].k == r[i].k;j--)
				mdf(-r[j].b,j);
		}
	}
	for (int i = 1;i <= n;i++)
		val[i] = INF;
	for (int i = n;i >= 1;i--)
	{
		R[i] = max(i,-qry(r[i].b));
		if (r[i].k != r[i - 1].k)
		{
			for (int j = i;j <= n && r[j].k == r[i].k;j++)
				mdf(r[j].b,-j);
		}
	}
	for (int i = 1;i <= n;i++)
		e[R[i]].push_back(L[i]);
	for (int i = 1;i <= n;i++)
		sort(e[i].begin(),e[i].end());
	sum[0] = 1;
	for (int i = 1;i <= n;i++)
	{
		sum[i] = sum[i - 1];
		for (int j = 0;j < e[i].size();j++)
			(sum[i] += SUM(e[i][j] - 1,i)) %= MOD;
	}
	printf("%d\n",(sum[n] - sum[n - 1] + MOD) % MOD);
	return 0;
}

Measured memory_bytes: 31616
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(f.readLine());
		int[] p = new int[n];
		StringTokenizer st = new StringTokenizer(f.readLine());
		for(int i = 0; i < n; i++) {
			p[i] = Integer.parseInt(st.nextToken()) - 1;
		}
		int counter = 0;
		for(int i = 0; i < n - 1; i++) {
			if(p[i] == i) {
				int temp = p[i + 1];
				p[i + 1] = p[i];
				p[i] = temp;
				counter++;
			}
		}
		if(p[n - 1] == n - 1) {
			counter++;
		}
		System.out.println(counter);
	}
}


Measured memory_bytes: 33672