akhauriyash/Code-Regression huggingface dataset:
import Data.List
import Debug.Trace

main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- map read . words <$> getLine :: IO [Int]
  print $ solve as

solve :: [Int] -> Int
solve as = let (x, y) = go as' in
             x * y
  where
    as' = filter ((> 1) . length) $
          group $ sortBy (flip compare) as
    go [] = (0, 0)
    go (xs:xss) = case length xs of
                    2 -> ((head xs), fst (go xss))
                    3 -> ((head xs), fst (go xss))
                    _ -> ((head xs), (head xs))


Measured memory_bytes: 38524
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e2 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	string str;
	cin >> n >> str;
	int ans = 0;
	int sum = 0;
	for (auto& c : str)
	{
		if (c == 'I') sum++;
		else sum--;
		ans = max(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
//typedef __int128_t lll;
using namespace std;

int main(int argc, char const *argv[]) {
  string s;std::cin >> s;
  if(s[2]==s[3]&&s[4]==s[5]) std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';
  return 0;
}


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

int main(){
  int N;
  int K;
  int a[50];
  int ans;
  cin >> N >> K;
  for ( int i=0; i <N; ++i) cin >> a[i];
  sort(a, a+N, greater<int>());
  for (int i =0; i <K; ++i) {
  ans += a[i];
  }
  cout << ans << endl;
}

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

int main()
{
	ios::sync_with_stdio(0);
	int N; std::cin >> N;
	vector<int>p;
	while (N-- != 0) {
		int number;
		cin >> number;
		p.push_back(number);
	}
	if (is_sorted(p.begin(), p.end())) {
		cout << "YES";
		return 0;
	}
	int noSwaps=0;
	for (int i = 0; i < p.size(); i++)
		if (p[i] != i+1)
			noSwaps++;
	if (noSwaps > 2)
		cout << "NO";
	else
		cout << "YES";
	return 0;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 1;
//---------------------------------//

int n, cnt;
int v[112345];

int main() {
	cin >> n;
	REP(i, n) scanf("%d", v + i);
	
	map<int, int> mm[2];
	REP(i, n) mm[i & 1][v[i]]++;
	
	pii dat[2][2];
	
	REP(i, 2) {
		vector<pii> tmp;
		for (map<int, int>::iterator it = mm[i].begin(); it != mm[i].end(); it++)
			tmp.push_back(pii(it->se, it->fi));
		
		sort(tmp.begin(), tmp.end(), greater<pii>());
		
		REP(j, 2) if (j < tmp.size()) dat[i][j] = tmp[j];
	}
	
	int ans = INF;
	REP(i, 2) REP(j, 2) {
		if (i >= mm[0].size()) continue;
		if (j >= mm[1].size()) continue;
		
		if (dat[0][i].se == dat[1][j].se) chmin(ans, n - max(dat[0][i].fi, dat[1][j].fi));
		else chmin(ans, n - dat[0][i].fi - dat[1][j].fi);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 6256
#A
"""
H, W = map(int, input().split())
h, w = map(int, input().split())
print(H*W-h*W-w*H+h*w)
"""
#B
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
ansb = 0
for i in range(n):
    ans = 0
    a = list(map(int, input().split()))
    for k in range(m):
        ans += a[k]*b[k]
    ans += c
    if ans > 0:
        ansb += 1
print(ansb)
#C

#D

Measured memory_bytes: 38384
#include<iostream>
#include<algorithm>
int main(){
    int N, K, h[1000001];
    std::cin >> N >> K;
    for(int i=1; i<=N; ++i) std::cin >> h[i];
    std::sort(h+1, h+N+1);
    //for(int i=1; i<=N; ++i) std::cout << h[i] << std::endl;
    int min = 2147483647;
    for(int i=1; i <= N-K+1; ++i){ 
        //std::cout << i << ":" << h[i] << std::endl;
        //std::cout << h[i+K-1] << "-" << h[i] << std::endl;
        if(h[i+K-1] - h[i] < min) min = h[i+K-1] - h[i];
    }
    std::cout << min << std::endl;
    return 0;
}


Measured memory_bytes: 2560
# -*- coding: utf-8 -*-
from itertools import groupby

S = input()

L = [[k, len(list(g))] for k, g in groupby(S)]

ans = 0
i = 0
while i != len(L):
    if i == 0 and L[i][0] == ">":
        ans += ((L[i][1] * (L[i][1] + 1)) / 2)
        i += 1
    elif i == len(L) - 1:
        ans += ((L[i][1] * (L[i][1] + 1)) / 2)
        i += 1
    else:
        if L[i][1] > L[i+1][1]:
            ans += ((L[i][1] * (L[i][1] + 1)) / 2) + (((L[i+1][1] - 1) * (L[i+1][1])) / 2)
        else:
            ans += ((L[i+1][1] * (L[i+1][1] + 1)) / 2) + (((L[i][1] - 1) * (L[i][1]) / 2))
        i += 2
print(int(ans))

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

char S[ 10 ];

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

	cin >> S;

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

	return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main ()
{
  int N;
  cin >> N;
  int A[N];
  int max=0;
  int res=0;
  for (int i = 0; i < N ; i++)
    {
      cin >> A[i];
      if(max < A[i])
        max=A[i];
    }
  int F[max+1]={0};
  sort(A,A+N);
  for(int i = 0; i < N ; i++)
    {
      //if((i==0 && A[i]==A[i+1]) || (i==N-1 && A[i]==A[i-1]))
      //        continue;
      //else if(A[i]==A[i-1] || A[i]==A[i+1])
      //        continue;
      int num=A[i];
      while(num <= max)
        {
          F[num]++;
          num += A[i];
        }
    }
  for(int i = 0 ; i < N ; i++)
    {
      if(F[A[i]]==1)
        res++;
    }
  cout << res << endl;
  return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

int main(){
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll ans[4];
  ans[0] = a*c;
  ans[1] = a*d;
  ans[2] = b*c;
  ans[3] = b*d;

  ll ansm=ans[0];
  rep(i,4) ansm = max(ansm, ans[i]);

  cout << ansm;
}

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

typedef long long int ll;
using namespace std;
 
int main() {
    char s[10];
    int x = 0;
    scanf("%s", s);
 
    rep(i,0,strlen(s)){
      if(s[i] == '0'){
        s[x] ='0';
        x++;
      }
      else if(s[i] == '1'){
        s[x] = '1';
        x++;
      }
      else if(s[i] == 'B'){
        if(x != 0) x--;
      }
    }

    rep(i,0,x){
      printf("%c",s[i]);
    }
    printf("\n");
    return 0;
}

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

int main(){
    int N, K, sum = 0;
    int p[1010];
    cin >> N >> K;
    for (int i = 0; i < N; i++){
        cin >> p[i];
    }
    sort(p, p+N);
    for (int j = 0; j < K; j++){
        sum += p[j];
    }

    cout << sum << endl;
}

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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define outl(x) cout<< (x) << '\n'
#define pb(a) push_back(a)
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
  return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
  return a / gcd(a, b) * b;
}

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

int main()
{
  int n, m, x, y;
  ci >> n >> m >> x >> y;

  int xx[101];
  int yy[101];

  for(int i = 0; i < n; i++) ci >> xx[i]; xx[n] = x;
  for(int i = 0; i < m; i++) ci >> yy[i]; yy[m] = y;

  sort(xx, xx + n + 1);
  sort(yy, yy + m + 1);

  if(xx[n] < yy[0]) {
    co << "No War" << en;
  } else {
    co << "War" << en;
  }
  
  return 0;
}


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

int main(){
    // 入力
    int A, B, M; cin >> A >> B >> M;
    vector<int> a(A), b(B);
    for(int i=0; i<A; i++) cin >> a[i];
    for(int i=0; i<B; i++) cin >> b[i];

    // a, bそれぞれの最小値を求める
    int mina = *min_element(a.begin(), a.end());
    int minb = *min_element(b.begin(), b.end());

    // 最小値を更新していく変数 minv をつくる
    int minv = mina + minb;

    int x, y, c;
    int v;
    for(int i=0; i<M; i++){
        cin >> x >> y >> c; // 入力
        // インデックスとして扱いたいので、1-origin(1,2,3,...)から0-origin(0,1,2,...)にする
        x--; y--;

        v = a[x]+b[y]-c; // 割引になる組み合わせで買ったときの合計金額

        minv = min(minv, v); // 現時点での最小値 minv と比較、小さい方を minv にする
    }

    cout << minv << endl;
    return 0;
}

Measured memory_bytes: 1024
s = input()
n = len(s) + 1
a = [0 for _ in range(n)]
for i in range(n-1):
    if s[i] == '<':
        a[i+1] = a[i] + 1
for i in reversed(range(1, n)):
    if s[i-1] == '>':
        a[i-1] = max(a[i-1], a[i]+1)
print(sum(a))

Measured memory_bytes: 23976
#include<stdio.h>
#define MAX 101

void print(int n,int *A){
  int i;
  for(i=0;i<n-1;i++)
    printf("%d ",A[i]);
  printf("%d\n",A[i]);
}

void insertion_sort(int n,int *A){
  int i,j,v;
  for(i=0;i<n;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    print(n,A);
  } 
}

int main(){
  int n,i;
  int a[MAX];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  insertion_sort(n,a);
  return 0;
}



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

using ll = long long;
using ld = long double;

const int nax = 405;
const  int mod =  1e9+7;
const ll INFL = 1e18L + 5;

//Modular Addition
inline void add_self(int& a, int b){
    a+=b;
    if(a>=mod)
        a-=mod;
}

//Modular Subtraction
inline void sub_self(int& a , int b){
    a -= b;
    if(a < 0)
        a+= mod;
}


ll dp[nax][nax];




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

    int n; cin>>n;

    vector<ll>a(n);
    for(auto& x : a)cin>>x;

    auto sum = [&](int L , int R){
        ll s = 0;
        for(int i = L; i <= R; ++i){
            s += a[i];
        }
        return s;
    };

    vector<ll> pre(n);
    pre[0] = a[0];
    for(int i = 1; i < n; i++)
        pre[i] = pre[i-1] + a[i];

    for(int gap = 1; gap <= n; gap++){
        for(int l = 0; l < n-gap+1; ++l){
            int r = l + gap;
            dp[l][r] = INFL;
            ll s = (l==0 ? pre[r] : pre[r]-pre[l-1]);
            for(int i = l; i <= r; i++){
                dp[l][r] = min(dp[l][r], dp[l][i] + dp[i+1][r] + s);
            }
        }
    }

    cout<<dp[0][n-1];


}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

string s;

signed main() {
	int i;
	
	cin >> s;
	int n = s.length();
	
	int cnt = 0;
	rep(i, n) {
		if (i % 2 == 0) if (s[i] == '1') cnt++;
		if (i % 2 == 1) if (s[i] == '0') cnt++;
	}
	
	int cnt2 = 0;
	rep(i, n) {
		if (i % 2 == 0) if (s[i] == '0') cnt2++;
		if (i % 2 == 1) if (s[i] == '1') cnt2++;
	}
	
	cout << min(cnt, cnt2) << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,k=0,x=100;
    cin>>a;
    while(1)
    {
        x+=(x/100);
        k++;
        if(x>=a) break;
    }
    cout<<k<<endl;
    return 0;
}


Measured memory_bytes: 3592
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (writeln!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      aa: [i64; n],
    }

    let mut x1 = aa[0];
    for i in 1..n {
        if i%2 == 1 {
            x1 -= aa[i];
        } else {
            x1 += aa[i];
        }
    }
    let mut ans = vec![];
    ans.push(x1);

    let mut prev = x1/2;
    for i in 0..n-1 {
        let temp = aa[i] - prev;
        ans.push(temp * 2);
        prev = temp;
    }

    for a in ans {
        print!("{} ", a);
    }
    println!();
}


Measured memory_bytes: 7420
import Control.Applicative
import Control.Monad
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B8
import Data.List

main :: IO ()
main = do
    n <- readLn :: IO Int
    adjL <-  map (map (read :: String -> Int) . drop 2 . words) . lines <$> getContents
    let vecs = replicate n (VU.replicate n 0)
    let adjM = zipWith uparr adjL vecs
    mapM_ putStrLn $ map (intersperse ' ' . concatMap show . VU.toList) adjM


uparr :: [Int] -> VU.Vector Int -> VU.Vector Int
uparr adj vec =
    vec VU.// (uplist adj)
  where
    uplist :: [Int] -> [(Int, Int)]
    uplist = foldr (\n -> ((n - 1, 1) :) ) []


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


Measured memory_bytes: 128
N = int(input())
K = int(input())
S = str(N)
L = len(S)
# dp0 N未満であることが未確定
# dp1 N未満であることが確定
# [上から何桁][0以外を選んだ回数]
dp0 = [[0 for _ in range(5)] for _ in range(L+1)]
dp1 = [[0 for _ in range(5)] for _ in range(L+1)]
dp0[0][0] = 1
dp0[0][1] = 0
for i in range(L):
    D = int(S[i])
    for j in range(4):
        if D > 0:
            # 0を選ぶ
            dp1[i+1][j] += dp1[i][j] + dp0[i][j]
            # 1~9を選ぶ
            dp0[i+1][j+1] += dp0[i][j]
            dp1[i+1][j+1] += dp1[i][j]*9 + dp0[i][j]*(D-1)
        else:
            # 0を選ぶ
            dp0[i+1][j] += dp0[i][j]
            dp1[i+1][j] += dp1[i][j]
            # 1~9を選ぶ
            dp1[i+1][j+1] += dp1[i][j]*9
print(dp0[L][K]+dp1[L][K])


Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define pq priority_queue
#define mp make_pair
#define cauto const auto &

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define clr(ar, val) memset(ar, val, sizeof(ar))

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 (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

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

using namespace std;

typedef long long int64;
typedef long long lint;
typedef long long lli;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

char s[200000],t[200000];
char stot[26],ttos[26];
int main() {
    cin>>s>>t;
    REP(i,sizeof(s)/sizeof(char)){
        if(stot[s[i]-'a']==0){
            stot[s[i]-'a']=t[i];
        }else{
            if(stot[s[i]-'a']!=t[i]) {cout<<"No"<<endl;return 0;}
        }
        if(ttos[t[i]-'a']==0){
            ttos[t[i]-'a']=s[i];
        }else{
            if(ttos[t[i]-'a']!=s[i]) {cout<<"No"<<endl;return 0;}
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
  int i=1;
  int n;
  int x=1;
  
  cin >> n;
//  cout <<"a\n";
  for(i=1;i<=n;i++)
  {
//  cout <<"a\n";
    x=i;
    if(x%3==0)
    {
      cout <<" " << i;
      continue;
    }
    
    do
    {
      if(x%10==3)
      {
        cout <<" " << i;
        break;
      }
      x=x/10;
    }while(x);
  }
  cout <<"\n";
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n; cin >> n;
	ll ans=0;
	REP(i,n)REP(j,n)REP(k,n)
		ans+=gcd(gcd(i+1,j+1),k+1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3624
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())

def f(x):
  A=[]
  for _ in range(n):
    A.append(x%10)
    x//=10
  return A[::-1]

def g(X):
  cur=X[0]
  ret=-1
  for i in range(1,n):
    if X[i]+1<=cur+1 and X[i]+1<=i:
      ret=i
    cur=max(cur,X[i])
  return ret
Ans=[0]

a=f(0)
b=g(a)
while b>=0:
  next=0
  for i in range(n):
    if i<b:
      next+=a[i]*(10**(n-1-i))
    elif i==b:
      next+=(a[i]+1)*(10**(n-1-i))
  Ans.append(next)
  a=f(next)
  b=g(a)
for a in Ans:
  ans=""
  for x in f(a):
    ans+=chr(97+x)
  print(ans)







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

int N,K;
string S;

int main(){
    cin>>N>>K>>S;
    vector<pair<int,int>>v(1);
    char pre='1';
    for(int i=0;i<N;i++){
        if(S[i]!=pre&&S[i]=='1'){
            v.push_back({0,0});
        }
        if(S[i]=='1')v.back().first++;
        else v.back().second++;
        pre=S[i];
    }
    if(v.size()<K){
        cout<<N<<endl;
        return 0;
    }
    v.push_back({0,0});
    int cur=0;
    for(int i=0;i<K;i++){
        cur+=v[i].first;
        cur+=v[i].second;
    }
    cur+=v[K].first;
    int ans=cur;
    for(int i=0;i<v.size()-K-1;i++){
        cur-=v[i].first+v[i].second;
        cur+=v[i+K].second+v[i+K+1].first;
        ans=max(ans,cur);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1020
/*

    author : s@if

*/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			1e9
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> new_data_set;

//*find_by_order(k)  gives the kth element;
//order_of_key(item)   gives the index(number of element strictly less than item) of item;


inline int in() {int x; scanf("%d", &x); return x; }
bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};    // King's move
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hx[]={-2,-2,-1,+1,+2,+2,-1,+1};    // Knight's move
int hy[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)2e5+9;


int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    int i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    int a[6]; for(i=1; i<=5; i++) cin>>a[i];

    for(i=1; i<=5; i++)
    {
        if(a[i]==0) break;
    }

    cout<<i<<endl;

    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


Measured memory_bytes: 3600
// She is Pretty pretty!
#include <bits/stdc++.h>
using namespace std;

#define int long long 
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

const int N = 1e6 + 100;
const int mod = 1e9 + 7;
vector<int> v[N];
int ans1[N], ans2[N];
int n, x, y;
void dfs(int x, int fa) {
    ans1[x] = ans2[x] = 1;
    for (int i = 0; i < v[x].size(); i++) {
        if (v[x][i] != fa) {
            dfs(v[x][i], x);
            ans1[x] = ans1[x] * (ans1[v[x][i]] + ans2[v[x][i]]) % mod;
            ans2[x] = ans2[x] * ans1[v[x][i]] % mod;
        }
    }
}
int32_t main() {
    cin >> n;
    for (int i = 1; i < n; i++) {
        cin >> x >> y;
        v[x].pb(y);
        v[y].pb(x);
    }
    dfs(1, 0);
    return cout << (ans1[1] + ans2[1]) % mod, 0;
}

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

int read(){
	int x=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x;
}
int n,m,k;
int maxx,maxy;
unordered_map<int,int> x,y;
#define P pair<int,int>
map<pair<int,int>,bool> vis;
bool pd(int xx,int yy){
	return vis[P(xx,yy)];
}
vector<int> Ax,Ay;

int main()
{
	n = read();m = read();k =read();
	for(int i = 1;i <= k;i++)
	{
		int a = read(), b = read();
		x[a] ++;
		y[b] ++;
		vis[P(a,b)] = 1;
		if(x[a] > maxx)
		{
			Ax.clear();maxx = x[a];Ax.push_back(a);
		} 
		else if(x[a] == maxx) Ax.push_back(a);
		if(y[b] > maxy) 
		{
			Ay.clear();maxy = y[b];Ay.push_back(b);
		}
		else if(y[b] == maxy) Ay.push_back(b);
	}
	int ans = 0;
	for(int i = 0;i < Ax.size();i++)
	{
		for(int j = 0;j < Ay.size();j++){
			ans = maxx+maxy-pd(Ax[i],Ay[j]);
			if(ans == maxy + maxx) {
				cout << ans << endl;
				return 0;
			}
		}
	}
	cout << maxx+maxy - 1 << endl;
	return 0;
	return 0;
}


Measured memory_bytes: 51224
import java.util.*;

public class Main{

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

        int N = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        int[] C = new int[N-1];
        long sum = 0;
        for(int i = 0; i < N; i++)
            A[i] = sc.nextInt();
        for(int i = 0; i < N; i++){
            B[i] = sc.nextInt();
            sum += B[i];
        }
        for(int i = 0; i < N-1; i++){
            C[i] = sc.nextInt();
        }
        sc.close();
        for(int i = 0; i < N-1; i++){
            if(A[i+1] == A[i] + 1)
                sum += C[A[i]-1];
        }
        

        System.out.println(sum);

       
    }
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)


using Graph = vector<vector<int>>;


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

    Graph g(n);
    rep(i, n-1) {
        int a,b; cin >> a >> b;
        g[a-1].push_back(b-1);
    }

    vector<int> add_nums(n,0);
    rep(i, q) {
        int p,x; cin >> p >> x;
        add_nums[p-1] += x;
    }

    queue<int> que;
    que.push(0);

    // 1つ目のやつをあげる
    while(!que.empty()) {
        int v = que.front();
        que.pop();
        for(int nv : g[v]) {
            add_nums[nv] += add_nums[v];
            que.push(nv);
        }
    }

    // 出力
    rep(i, n-1) {
        cout << add_nums[i] << " ";
    }
    cout << add_nums[n-1] << endl;

    return 0;
}


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


// æ­Ôá¤Æ±ëB
// âè¶É¢ÄÈ­ÄàâèZbgÍ¡Åæªª0ÅI¹Å éB
// âèZbgÌJèÔµÉú»Rê

// 2011/10/18

//@0101
public class Main {

	
	// C return falseÅ¨µÜ¢
	boolean main() throws IOException {

		String s = reader.readLine();
		s = s.replaceAll("Hoshino", "Hoshina");
		
		System.out.printf("%s\n", s);
		
		return true; /* ³íI¹ Ö */
	}
	

//	private final static boolean DEBUG = true;  // debug
	private final static boolean DEBUG = false; // release

	public static void main(String[] args) throws IOException {

		if (DEBUG) {
			log = System.out;
			
			String inputStr = "4\n0 0 10 0 10 10 0 10\n10\n12\n0 5\n9 5\n0\n"; // 108.0
//			String inputStr = "4\n0 0 10 0 10 10 0 10\n10\n12\n0 0\n9 1\n0\n"; // 96.63324958071081
//			String inputStr = "4\n0 0 10 0 10 10 0 10\n10\n12\n0 1\n9 1\n0\n"; // 103.2664991614216
//			String inputStr = "8\n2 0 4 0 6 2 6 4 4 6 2 6 0 4 0 2\n10\n12\n3 0\n3 5\n0\n"; // 60.0

			reader = new BufferedReader(new StringReader(inputStr)); 

		}
		else {
			log = new PrintStream(new OutputStream() { public void write(int b) {} } ); // «ÌÄ
			reader = new BufferedReader(new InputStreamReader(System.in)); // R\[©ç
		}
		
		int N = readIntArray()[0];

		for(int i = 0; i < N; i++) {
			boolean b = new Main().main();
			if (!b)
				break;
		}		
		
		reader.close();
	}

	
	static PrintStream log;
	static BufferedReader reader;
	

	// WüÍæè@1sªÌXy[XæØèÌ®lðÇÞ
	private static int[] readIntArray() throws IOException {
		
		String s = reader.readLine();
		String[] sp = s.split(" ");
		int[] a = new int[sp.length];
		for(int i = 0; i < sp.length; i++) {
			a[i] = Integer.parseInt(sp[i]);
		}
		return a;
	}
		
}

Measured memory_bytes: 11000
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <ctime>
#include <memory.h>
#include <bitset>
#include <climits>
#include <iomanip>

#define F first
#define S second
#define endl "\n"
#define pb push_back
#define mp make_pair
#define bs 1000000007
#define pi 3.141592653589793
#define y1 kjdfshnvoavaofobiopj
#define ends wieyryrqayreryueyrye
using namespace std;

int n, ary[100010], m;
long long sum;


int main(){
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);

cin>>n;
for(int i = 1; i <= n; i++)
{
    cin>>ary[i];
    sum += ary[i];
}
cin>>m;
for(int i = 0; i < m; i++)
{
    int x, y; cin>>x>>y;
    cout<<sum-(ary[x]-y)<<endl;
}


return 0;}


Measured memory_bytes: 504
from collections import defaultdict
from math import sqrt,floor
N,P=map(int,input().split())
m=int(sqrt(P)+2)
dd=defaultdict(int)
for i in range(2,m):
    if P%i==0:
        a=0
        while P%i==0:
            a+=1
            P=P//i
        dd[i]=a
if P!=1:
    dd[P]=1
ans=1
for p,n in dd.items():
    ans*=pow(p,floor(n/N))
print(ans)

Measured memory_bytes: 40044
#include <iostream>
#include <iomanip>
#define pi 3.14159265358979323846
using namespace std;

int main()
{
	int H,W,i,j;
	while(true)
	{
		cin>>H>>W;
		if(H!=0||W!=0){
			
			for(i=1;i<=H;i++)
			{
				for(j=1;j<=W;j++)
					{
						cout<<'#';
					}
				cout<<endl;
			}
		
		}
		else
			return 0; 
		cout<<endl;
	}
}


Measured memory_bytes: 3124
import fractions
N,X = map(int,input().split())
x = [int(i) for i in input().split()]
ans = abs(x[0]-X)
if len(x) != 1:
    for i in range(N):
        ans1 = abs(X-x[i])
        ans = fractions.gcd(ans,ans1) 
print(ans)


Measured memory_bytes: 88172
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define F(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define FD(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define pii pair<int,int>
#define reset(x,y) memset(x, y,sizeof(x))
#define MIN(x,y) if (x > (y)) x = (y)
#define MAX(x,y) if (x < (y)) x = (y)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define EL putchar('\n');
#define mod 1000000007
#define oo 3003
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 * 10 + c - '0'; c = getchar();}
    return x * f;
}
void write(int x)
{
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
int n;
int a[oo],mina=1e6;
int f[oo][oo];
void ReadInPut()
{
    n=read();
    F(i,1,n)a[i]=read();
}
int tinh(int i,int j)
{
	if(f[i][j]!=-1) return f[i][j];
	if(i>j)return 0;
    int res;
    if((i-1+n-j)%2)res=min(tinh(i+1,j)-a[i],tinh(i,j-1)-a[j]);
    else res=max(tinh(i+1,j)+a[i],tinh(i,j-1)+a[j]);
    f[i][j]=res;
    return res;
}
void Solve()
{
    reset(f,-1);
    cout<<tinh(1,n);
}
main()
{
//    freopen("t.INP","r",stdin);
  //  freopen(".OUT","w",stdout);
    int sotest=1;
    //cin>>sotest;
    for(int i=1;i<=sotest;i++)
    {
        ReadInPut();
        Solve();
    }
}

Measured memory_bytes: 70784
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    a,b = LI()
    s = min(str(a)*b,str(b)*a)
    print(s)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38384
s=[]
for i in range(201)[105::2]:
  d=1;k=i
  for h in range(2,i+1):
    if i%h==0:
      cnt=0
      while i%h==0:
        cnt+=1
        i//=h
      d*=(cnt+1)
  if d==8:
    s.append(k)
ans=0;n=int(input())
for f in s:
  if n>=f:ans+=1
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		
		int a = 0;
		
		if(0 <= x - r && x + r <= W) {
			if(0 <= y - r && y + r <= H) {
				a = 1;
			}
		}
		
		if(a == 1) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
		
		sc.close();
	}

}



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

int main(){
    int a, b;
    cin >> a >> b;
    int count = 0;
    for(int i = a ; i < b + 1 ; i++){
        int left1st = i / 10000;
        int right1st = i % 10; 
        int left2nd = (i - left1st * 10000) / 1000;
        int right2nd = (i % 100) / 10;

        if(left1st == right1st && left2nd == right2nd){
            count += 1;
        }
    }

    cout << count << endl;
}

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

int main(){
  string s;
  cin >> s;
  int n;
  int odda =0;
  int oddb =0;
  int evena =0;
  int evenb =0;
  int a =0;
  int b =0;
  n =s.size();
  for(int i=0; i< n; i++){
    if(i%2==1){
      if(s[i]=='1'){
        odda++;
      }
      else{
        oddb++;
      }
    }
    else{
      if(s[i]=='1'){
        evena++;
      }
      else{
        evenb++;
      }
    }
  }
  a = evena + oddb;
  b = evenb + odda;
  if(a<b){
    cout << a <<endl;
  }
  else{
    cout << b <<endl;
  }
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<long long,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
P pa1[100005];
P pa2[100005];
int h,w,n;
bool comp1(P a,P b){
	return a.first<b.first;
}
bool comp2(P a,P b){
	return a.second<b.second;
}
bool decide(P1 a,P1 b){
	if(a.first<b.first){
		return true;
	}else if(a.first>b.first){
		return false;
	}else{
		if(a.second.first<b.second.first){
			return true;
		}else if(a.second.first>b.second.first){
			return false;
		}else{
			return a.second.second<b.second.second;
		}
	}
}
int main(){
	scanf("%d %d",&h,&w);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x,y;
		scanf("%d %d",&x,&y);
		pa1[i]=mp(x,y);
		pa2[i]=pa1[i];
	}
	sort(pa2+1,pa2+(n+1),comp2);
	sort(pa1+1,pa1+(n+1),comp1);
	int ha=(n+1)/2;
	int ax=pa1[ha].first;
	int ay=pa2[ha].second;
	vector<P1>vec;
	vector<int>dx,dy;
	if(pa1[ha+1].first!=ax){
		dx.pb(ax);
		dx.pb(pa1[ha+1].first);
	}
	else{
		dx.pb(ax);
		dx.pb(ax-1);	
		dx.pb(ax+1);		
	}
	if(pa2[ha+1].second!=ay){
		dy.pb(ay);
		dy.pb(pa2[ha+1].second);
	}
	else{
		dy.pb(ay);
		dy.pb(ay-1);	
		dy.pb(ay+1);		
	}

	for(int i=0;i<dx.size();i++){
		for(int j=0;j<=dy.size();j++){
			long long sd=0;
			int maxi=0;
			for(int g=1;g<=n;g++){
				sd+=(abs(pa1[g].first-dx[i])+abs(pa1[g].second-dy[j]));
				maxi=max(maxi,(abs(pa1[g].first-dx[i])+abs(pa1[g].second-dy[j])));
			}
			vec.pb(mp(sd*2-maxi,mp(dx[i],dy[j])));
		}
	}
sort(vec.begin(),vec.end(),decide);
printf("%lld\n%d %d\n",vec[0].first,vec[0].second.first,vec[0].second.second);
return 0;
}

Measured memory_bytes: 2776
pre = [
    ((0, 1, 2), (1, 0, 1), (2, 1, 0)),
    ((3, 2, 2), (2, 1, 1), (2, 1, 1)),
    ((1, 1, 2), (1, 1, 2), (2, 2, 3)),
    ((3, 2, 2), (2, 2, 2), (2, 2, 3)),
]

q = int(input())
for _ in range(q):
    n = int(input())
    books = [c == 'Y' for c in input()]
    books = [(0, 0)] + list(zip(books[:2 * n], books[2 * n:])) + [(0, 0)]
    shelves = [(u1 | u2) * 2 + (l1 | l2) for (u1, l1), (u2, l2) in zip(*[iter(books)] * 2)]
    ans = [0, 1, 2]
    for key in shelves:
        new_ans = [min(a + c for a, c in zip(ans, costs)) for costs in pre[key]]
        ans = new_ans
    print(ans[0] + n)

Measured memory_bytes: 9624
#include <iostream>

using namespace std;

int main()
{
    int A, B, total;
    cin >> A >> B;
    total = B;

    if (A<=5) {
        cout << "0" << endl;
    } else if (A>5 && A<=12) {
        total = total * 0.5;
        cout << total << endl;
    } else {
        cout << total << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include<bitset>
#include<stdio.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF = 100000000;

bool isOK(int a[],int index,int key){
    if(a[index] >= key){
        return true;
    }else{
        return false;
    }
}

int binary_search(int a[],int n,int key){
    int left = -1;
    int right = n;

    while(right-left>1){
        int mid = left + (right - left)/2;
        if(isOK(a,mid,key)){
            right = mid;
        }else{
            left = mid;
        }
    }
    return right;
}

int factrial(int n){
    if(n==0){
        return 1;
    }else{
        return n*factrial(n-1);
    }
}

struct restaurant{
    string name;
    int point;
    int number;
};

int main(void){
    int n;
    cin >> n;
    struct restaurant data[n];

    rep(i,n){
        cin >> data[i].name >> data[i].point;
        data[i].number = i+1;
    }

    for(int i=0;i<n;++i){
        for(int j=0;j<n-1;++j){
            if(data[j].name > data[j+1].name){
                struct restaurant temp;
                temp = data[j];
                data[j] = data[j+1];
                data[j+1] = temp;
            }
            if(data[j].name == data[j+1].name && data[j].point < data[j+1].point){
                struct restaurant temp;
                temp = data[j];
                data[j] = data[j+1];
                data[j+1] = temp;
            }
        }
    }

    rep(i,n){
        cout << data[i].number << endl;
    }
    return 0;
}



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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(i, v) for(auto i =  v.begin(); i !=  v.end(); ++i)
#define RFOR(i, v) for(auto i = v.rbegin(); i != v.rend(); ++i)

template<typename T> bool setmin(T & a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T & a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T> ostream & operator<<(ostream & os, const vector<T> & v) {
	os << "[";
	FOR(it, v) {
		if(it != v.begin()) { os << ", "; }
		os << *it;
	}
	os << "]";
	return os;
}
template<typename F, typename S> ostream & operator<<(ostream & os, const pair<F, S> & p) {
	os << "<" << p.FI << ", " << p.SE << ">";
	return os;
}

// ---- ----

int n, m, a[1000], b[1000], c[1000];
int e[100][100];
int d[100][100];
int ans;
int INF = 100000000;

int main() {
	cin >> n >> m;
	inc(i, m) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; }
	
	inc(i, n) {
	inc(j, n) {
		d[i][j] = (i == j ? 0 : INF);
	}
	}
	
	inc(i, m) {
		d[ a[i] ][ b[i] ] = c[i];
		d[ b[i] ][ a[i] ] = c[i];
		e[ a[i] ][ b[i] ] = c[i];
		e[ b[i] ][ a[i] ] = c[i];
	}
	
	inc(k, n) {
	inc(i, n) {
	inc(j, n) {
		setmin(d[i][j], d[i][k] + d[k][j]);
	}
	}
	}
	
	inc(i, n) {
	inc(j, n) {
		if(e[i][j] < INF && d[i][j] < e[i][j] ) { ans++; }
	}
	}
	
	cout << ans / 2 << endl;
	
	return 0;
}


Measured memory_bytes: 384
N = int(input())
Ts = list(map(int, input().split()))
M = int(input())
PX_list = [list(map(int, input().split())) for _ in range(M)]

original_sum = sum(Ts)

for p, x in PX_list:
  print(original_sum - Ts[p-1] + x)

Measured memory_bytes: 3060
#include <iostream>
   using namespace std;
   
   int main(){
           int a,b,c;
           cin >> a >> b >> c;
   
           //find max
           int money;
          if(a > b && a > c){
                  money = a * 10 + b + c;
          }else if(b > c){
                  money = b * 10 + a + c;
          }else money = a + b + c * 10;
  
          cout << money;
}

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

K = input()
D = int(input())

N = len(K)

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

for i in range(1,N+1):
    for j in range(D):
        dp[i][(j+int(K[i-1])) % D][0] += dp[i-1][j][0]
        for k in range(int(K[i-1])):
            dp[i][(j+k) % D][1] += dp[i-1][j][0]
        for k in range(10):
            dp[i][(j+k) % D][1] += dp[i-1][j][1]
        
        dp[i][j][0] %= mod
        dp[i][j][1] %= mod

ans = (dp[N][0][0] + dp[N][0][1] - 1) % mod
print(ans)

Measured memory_bytes: 129756
x,y = list(map(int,input().split()))
g1 = [1,3,5,7,8,10,12]
g2 = [4,6,9,11]
g3 = [2]
if x in g1  and y in g1:
  print('Yes')
elif   x in g2 and y in g2:
  print('Yes')
else:
  print('No')
  
  
  

Measured memory_bytes: 3060
from collections import deque

N = int(input())
graph = [[] for _ in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append([b, i])
    graph[b].append([a, i])

ans = [0] * (N - 1)
q = deque([[1, 0, -1]])
while q:
    node, pcol, p_node = q.popleft()
    cnt = 1
    for n_node in graph[node]:
        if n_node[0] == p_node: continue
        if cnt == pcol: cnt += 1
        ans[n_node[1]] = cnt
        q.append([n_node[0], cnt, node])
        cnt += 1
print(max(ans))
print(*ans, sep="\n")

Measured memory_bytes: 108476
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa
from operator import mul
from functools import reduce


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, M, K = map(int, input().split())

    MOD = 998244353

    fact = [1, 1]  # fact[n] = (n! mod MOD)
    factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod MOD)
    inv = [0, 1]

    for i in range(2, N + 1):
        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, p):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return fact[n] * factinv[r] * factinv[n - r] % p

    E = [1]
    for _ in range(N):
        e = E[-1] * (M - 1)
        e %= MOD
        E.append(e)

    res = 0
    for k in range(0, K + 1):
        a = N - 1 - k

        b = cmb(N - 1, a, MOD) % MOD
        b *= M
        b %= MOD
        b *= E[a]
        b %= MOD

        res += b
        res %= MOD

    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 125772
// A.

#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	int ans = a[0] + a[1] + a[2] * 10;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 888
import numpy as np
n = int(input())
weight = np.array(list(map(int, input().split())))
w_left = weight[0]
w_right = sum(weight[1:])
min_w = abs(w_left - w_right)
for i in range(1, n):
    w_left += weight[i]
    w_right -= weight[i]
    min_w = min(min_w, abs(w_left-w_right))
print(min_w)


Measured memory_bytes: 12504
group1 = [1, 3, 5, 7, 8, 10, 12]
group2 = [2]
group3 = [4, 6, 9, 11]
table = {}

for i in group1:
    table[i] = 1

for i in group2:
    table[i] = 2

for i in group3:
    table[i] = 3

[x, y] = map(int, raw_input().strip().split())
if table[x] == table[y]:
    print "Yes"
else:
    print "No"


Measured memory_bytes: 2568
#include<stdio.h>

int main(void){
    int H,W,i,j;
    while ( 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: 2072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
  int n,s;
  cin >> n;
  vector<int>a(n+1);
  a[n] = 0;
  cin >> a[0];
  s = abs(a[0]);
  for(int i = 1;i <= n;i++){
    cin >> a[i];
    s += abs(a[i]-a[i-1]);
  }
  rep(i,n){
    cout << s+abs(a[i-1]-a[i+1])-abs(a[i]-a[i-1])-abs(a[i]-a[i+1]) << endl;
  }
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using ll = long long int;
using namespace std;

int main()
{
    int N, cnt = 0;
    cin >> N;
    vector<int> A(N, 0);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        if (A[i] & 1)
        {
            cnt++;
        }
    }
    if (cnt & 1)
    {
        cout << "NO" << endl;
    }
    else
    {
        cout << "YES" << endl;
    }

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int main()
{
    vector<int>v;
    int x,n,ok=1;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(x%2==0&&(x%3!=0&&x%5!=0))ok=0;
    }
    if(ok)cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;

}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int n; 
  cin >> n;
  
  bool ok = true;
  REP(i,n){
    int a;
    cin >> a;
    if(a % 2 == 0){
      if(a % 3 != 0 && a % 5 != 0){
        ok = false;
      }
    }
  }
  
  if(ok) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;

  
  
}

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

int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if (A+B > C+D)
    {
        cout << "Left";
    }else if (A+B == C+D)
    {
        cout << "Balanced";
    }else
    {
        cout << "Right";
    }
}

Measured memory_bytes: 256