akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
// Type alias
using ll=long long;
using ld=double;
 
using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;
 
using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;
 
// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();
 
// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl
 
#define ALL(a) a.begin(),a.end()
 
// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
  if (a > b) return a = b, true; else return false;
}
 
template<typename T> bool chmax(T& a, const T& b) {
  if (a < b) return a = b, true; else return false;
}
 
 
void solve(){
  int N, M;
  cin >> N >> M;
 
  int C[105][105] = {};
  vector<vector<pi>> w(N, vector<pi>(0));
 
  rep(i, N)rep(j, N) C[i][j] = inf / 2;
  rep(i, N) C[i][i] = 0;
 
  rep(i, M){
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    C[a][b] = c;
    C[b][a] = c;
    w[a].emplace_back(make_pair(b, c));
    w[b].emplace_back(make_pair(a, c));
  }
 
  rep(k, N){
    rep(i, N){
      rep(j, N){
        C[i][j] = min(C[i][j], C[i][k] + C[k][j]);
      }
    }
  }
 
  bool used[105][105] = {};
  rep(i, N){
    rep(j, N){
      for(auto e: w[j]){
        int node = e.first;
        int cost = e.second;
        if(C[i][node] + cost == C[i][j]){
          used[node][j] = true;
          used[j][node] = true;
        }
      }
    }
  }
 
  int sum = 0;
  rep(i, N){
    rep(j, N){
      if(used[i][j]) sum++;
    }
  }
 
  cout << M - sum / 2 << endl;
}
 
int main(){
// FastIO
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
  solve();
  return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a
    k = II()
    ans = 0
    for i in range(1, k + 1):
        for j in range(1, k + 1):
            ij = gcd(i, j)
            for l in range(1, k + 1):
                ans += gcd(ij, l)
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()


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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    int a, b;
    cin >> a >> b;
    a--; b--;

    cout << a*b << endl;
    
    return 0;
}   
/** atcoder **/


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int r,D,x;cin>>r>>D>>x;
  repeat(i,10){
    x = r*x-D;
    cout<<x<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
# abc147_b.py
# https://atcoder.jp/contests/abc147/tasks/abc147_b

# B - Palindrome-philia /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# 高八士君は回文が大好きで、回文でない文字列が許せません。
# 高八士君は文字列を 1回ハグするごとに、文字列から 1文字を選んで任意の文字に変えることができます。
# 文字列 Sが与えられます。Sを回文にするために必要なハグの最小回数を答えてください。

# 制約
#     Sは半角英小文字のみから成る文字列
#     Sの長さは 1 以上 100以下

# 入力
# 入力は以下の形式で標準入力から与えられます。
# S

# 出力
# Sを回文にするために必要なハグの最小回数を出力してください。

# 入力例 1
# redcoder

# 出力例 1
# 1

# たとえば、4文字目を o に変えて redooder にすることで回文になります。

# 入力例 2
# vvvvvv

# 出力例 2
# 0

# 一度も文字を変えなくてよい場合もあります。

# 入力例 3
# abcdabc

# 出力例 3
# 2


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    S = lines[0]
    # N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    # 文字が奇数だったら真ん中の1文字を削る
    q, mod = divmod(len(S), 2)
    if mod != 0:
        S = S[:q] + S[-q:]

    result = 0
    for i in range(q):
        log(f'S[i:i+1]=[{S[i:i+1]}]')
        log(f'S[2*q-i-1:2*q-i]=[{S[2*q-i-1:2*q-i]}]')
        if S[i:i+1] != S[2*q-i-1:2*q-i]:
            result += 1

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['redcoder']
        lines_export = [1]
    if pattern == 2:
        lines_input = ['vvvvvv']
        lines_export = [0]
    if pattern == 3:
        lines_input = ['abcdabc']
        lines_export = [2]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat (i, a, b) for (int i = (a); i < (b); i++)
#define rep (i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 300 + 5;
const int MAX_N = 1e5 + 5;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a >= b + c) {
        cout << 0 << endl;
    } else {
        cout << c - a + b << endl;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = std::numeric_limits<T>::max() / 10;
std::mt19937 mt{std::random_device{}()};
int main()
{
    constexpr int NUM = 100000;
    std::vector<int> num1(NUM + 1, 0), num2(NUM + 1, 0);
    int N;
    std::cin >> N;
    for (int i = 0; i < N; i++) {
        int v;
        std::cin >> v;
        (i % 2 == 0 ? num1 : num2)[v]++;
    }
    using P = std::pair<int, int>;
    std::vector<P> v1{{0, 0}}, v2{{0, 0}};
    for (int i = 0; i <= NUM; i++) {
        if (num1[i] != 0) { v1.push_back({num1[i], i}); }
        if (num2[i] != 0) { v2.push_back({num2[i], i}); }
    }
    std::sort(v1.begin(), v1.end()), std::sort(v2.begin(), v2.end());
    const int N1 = v1.back().first, N2 = v2.back().first;
    int ans = N - N1 - N2;
    const int V1 = v1.back().second, V2 = v2.back().second;
    v1.pop_back(), v2.pop_back();
    if (V1 == V2) {
        ans += std::min(N1 - v1.back().first, N2 - v2.back().first);
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
struct edge{int to,cost;};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=MOD;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    int memo=modpow(a,b/2);
    return memo*memo%MOD;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
    x=modpow(x,MOD-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
double dist(double ax,double ay,double bx,double by){
    return sqrt((bx-ax)*(bx-ax)+(ay-by)*(ay-by));
}
set<int>st;
signed main(){
    int n;
    cin>>n;
    rep(i,n){
        int a;
        cin>>a;
        st.insert(a);
    }
    cout<<st.size()<<endl;
    return 0;
}



Measured memory_bytes: 7684
A, B = map(int, input().split())

def gcd(x, y):
    X = max(x, y)
    Y = min(x, y)

    while True:
        r = X % Y
        X = Y
        Y = r
        if r == 0:
            break
    return X

print(int((A * B) / gcd(A, B)))

Measured memory_bytes: 38384
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

N = int(input())
A = list(map(int, input().split()))
divisors = sorted(make_divisors(A[0]) + make_divisors(A[1]), reverse=True)

ans = 0
for d in divisors:
    ok_cnt = 0
    for a in A:
        if a % d == 0:
            ok_cnt += 1
    if ok_cnt >= N-1:
        ans = d
        break
print(ans)

Measured memory_bytes: 63984
#include<stdio.h>

int main(){
    int m,f,r;
    while (1)
    {
        scanf("%d",&m);
        scanf("%d",&f);
        scanf("%d",&r);
        if(m ==  -1 && f == -1 && r == -1)break;

        if(f == -1 || m == -1)printf("F\n");
       else if((m + f)>=80)printf("A\n");
       else if((m+f)>=65 && (m+f)<80)printf("B\n");
       else if((m+f)>=50 && (m+f)<65 || r >= 50)printf("C\n");
       else if((m+f)>=30 && (m+f)<50)printf("D\n");
       else if((m+f)<30)printf("F\n");
       

    }
    
    return 0 ;
}


Measured memory_bytes: 2084
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for(int i=0;i<N;i++)cin >> A[i];
  for(int i=0;i<N;i++){A[i]-=i+1;}
  sort(A.begin(),A.end());
  if(N%2==1){
    long long ans=0;
    for(int i=0;i<N;i++){ans+=abs(A[i]-A[(N-1)/2]);}
    cout << ans << endl;
  }
  else{
    long long q=A[N/2]; long long w=A[N/2+1];
    long long e=0; long long r=0;
    for(int i=0;i<N;i++){e+=abs(A[i]-q); r+=abs(A[i]-w);}
    cout << min(e,r) << endl;
  }
}

Measured memory_bytes: 1792
N = int(input())
T = list(map(int, input().split()))
M = int(input())
P, X = [], []
for i in range(M):
    p, x = map(int, input().split())
    P.append(p)
    X.append(x)

total_time = sum(T)
for i in range(M):
    index = P[i] - 1
    tmp_diff = X[i] - T[index]
    print(total_time + tmp_diff)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;++i)

int m[55][55];
void dfs(int x,int y){
  m[y][x]=0;
  FOR(i,y-1,y+2) FOR(j,x-1,x+2)
    if(i>=0 && j>=0 && m[i][j]) dfs(j,i);
}

int main(){
  int w,h;
  while(cin>>w>>h,w){
    int ans=0;
    
    FOR(i,0,h) FOR(j,0,w){
      int c; cin>>c;
      m[i][j]=c;
    }
    
    FOR(i,0,h) FOR(j,0,w){
      if(m[i][j]){
	dfs(j,i);
	ans++;
      }
    }
    
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3280
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
struct ModInt {
    static const ll MOD = 998244353;

    // constructors etc
    ModInt() :num(1ll) {}
    ModInt(ll num_) :num(num_%MOD) {}
    ModInt(const ModInt& modint) :num(modint.num%MOD) {}
    ll get()const { return num; }

    // operator etc
    // operator ll() const { return num; }
    // ll operator*() { return num; }
    ModInt& operator+=(const ModInt& r) { (num += r.num) %= MOD; return *this; }
    ModInt& operator-=(const ModInt& r) { (num += -r.num + MOD) %= MOD; return *this; }
    ModInt& operator*=(const ModInt& r) { (num *= r.num) %= MOD; return *this; }
    ModInt& operator/=(const ModInt& r) { (num *= r.inv().num) %= MOD; return *this; }
    ModInt pow(const ModInt& r)const {
        ll res = 1;
        ll x = num;
        ll n = r.num;
        while (n > 0) {
            if (n & 1)res = (res*x) % MOD;
            x = (x*x) % MOD;
            n >>= 1;
        }
        return res;
    }
    ModInt inv()const { return this->pow(MOD - 2); }

    ModInt operator+(const ModInt& r)const { return ModInt(*this) += r; }
    ModInt operator-(const ModInt& r)const { return ModInt(*this) -= r; }
    ModInt operator*(const ModInt& r)const { return ModInt(*this) *= r; }
    ModInt operator/(const ModInt& r)const { return ModInt(*this) /= r; }
    ModInt operator+(const ll& r)const { return *this + ModInt(r); }
    ModInt operator-(const ll& r)const { return *this - ModInt(r); }
    ModInt operator*(const ll& r)const { return *this * ModInt(r); }
    ModInt operator/(const ll& r)const { return *this / ModInt(r); }

private:
    ll num;
};
ostream& operator<<(ostream& stream, const ModInt& val) { stream << val.get(); return stream; }
// ============ template finished ============

int main()
{
    ll N, S;
    cin >> N >> S;
    vector<ll> A(N);
    rep(i, N)cin >> A[i];

    vector<vector<ModInt>> dp(N + 1, vector<ModInt>(S + 1, 0));
    dp[0][0] = ModInt(2).pow(N);
    rep(i, N)rep(j, S + 1) {
        // not use
        dp[i + 1][j] += dp[i][j];

        // use
        if (j + A[i] <= S) {
            dp[i + 1][j + A[i]] += dp[i][j] / 2;
        }
    }
    cout << dp.back().back() << endl;
    return 0;
}


Measured memory_bytes: 73688
#include <bits/stdc++.h>
#define ri register
//#define int long long
#define E (n+1)
using namespace std; const int N=210;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
signed main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    printf("%lld\n",max(a*b,c*d));
    return 0;
}

Measured memory_bytes: 3720
import java.util.*;

public class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int socket = 1;
    int tap = 0;
    while(b > socket + tap * a - tap)
    {
      tap++;
    }

    System.out.println(tap);
  }

}


Measured memory_bytes: 23764
package main

import "fmt"

func main() {
	m := make(map[string]int)
	var n int
	var s string
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		m[s]++
	}
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		m[s]--
	}
	max := 0
	for _, c := range m {
		if max < c {
			max = c
		}
	}
	fmt.Println(max)
}


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

typedef vector<vector<int> > Matrix;
const int INF=100000000;
Matrix d;

void warshall_floyd(int n) {
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)
            for (int k=0;k<n;k++)
                d[j][k]=min(d[j][k], d[j][i]+d[i][k]);
    }

int main(){
    int mod=1000000007;
    int n,m,x=0,ans=0;
    scanf("%d %d",&n,&m);
    int chk[m][3]={0};
    d=Matrix(n, vector<int>(n,INF));
    for (int i=0;i<n;i++) d[i][i]=0;
    for (int i=0;i<m;i++) {
        int from,to,cost;
        scanf("%d %d %d",&from,&to,&cost);
        from--;
        to--;
        d[from][to]=cost; //0-index or 1-index
        d[to][from]=cost; //0-index or 1-index
        chk[i][0]=from;
        chk[i][1]=to;
        chk[i][2]=cost;
    }
    warshall_floyd(n);
    for (int i=0;i<m;i++) {
        if (d[chk[i][0]][chk[i][1]]<chk[i][2]) ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
// Aizu Vol-1 0145: Cards
// 2017.9.3 bal4u@uu
// ???????¨??????????????????????????????????

#include <stdio.h>

#define INF 0x7fffffff
int a[102][2], c[102][102];

int main()
{
	int n;
	int i, j, k, l, min;

	scanf("%d", &n);
	for (i = 0; i < n; i++) for (j = i+1; j < n; j++) c[i][j] = INF;
	for (i = 0; i < n; i++) c[i][i] = 0;
	for (i = 0; i < n; i++) scanf("%d%d", &a[i][0], &a[i][1]);
	for(l = 1; l < n ; l++) {
		for(i = 0 ; i < n - l; i++) {
			j = i + l;
			for (k = i; k < j; k++) {
				min = c[i][k] + +a[i][0]*a[k][1]*a[k+1][0]*a[j][1] + c[k+1][j];
				if (min < c[i][j]) c[i][j] = min;
			}
		}
	}
	printf("%d\n", c[0][n-1]);
	return 0;
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main()
{
    ll n, m;
    cin >> n >> m;
    ll h[n];
    rp(i, 0, n) cin >> h[i];
    ll a[m], b[m];
    rp(i, 0, m) cin >> a[i] >> b[i];
    ll hh[n];
    za(n, hh);
    rp(i, 0, m)
    {
        hh[a[i] - 1] = max(hh[a[i] - 1], h[b[i] - 1]);
        hh[b[i] - 1] = max(hh[b[i] - 1], h[a[i] - 1]);
    }
    ll ans = 0;
    rp(i, 0, n)
    {
        if (hh[i] < h[i])
            ans++;
    }
    ce(ans);
}

Measured memory_bytes: 6760
import std;


long calc(string s) {
    int n = cast(int)s.length;

    auto acc = new int[][](3, n);
    foreach (i; 0..n) {
        acc[0][i] = (s[i] == 'R') + (i > 0 ? acc[0][i-1] : 0);
        acc[1][i] = (s[i] == 'G') + (i > 0 ? acc[1][i-1] : 0);
        acc[2][i] = (s[i] == 'B') + (i > 0 ? acc[2][i-1] : 0);
    }

    // "RGB" の使っていない文字
    int get(char a, char b) {
        foreach (i, c; "RGB") {
            if (c != a && c != b) return cast(int)i;
        }
        assert(false);
    }

    long ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            if (s[i] == s[j]) continue;

            int p = get(s[i], s[j]);
            ans += acc[p][$-1] - acc[p][j-1];
            int k = 2*j - i;
            if (k < n && s[k] == "RGB"[p]) ans--;
        }
    }
    return ans;

}

void main() {
    readint;
    string s = read!string;
    writeln(calc(s));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 3708
#include <bits/stdc++.h>
 
typedef unsigned long long int ull;
typedef long double ldb;
typedef long long int ll;
 
#define for01(k,n)  for (ll i=k; i<n; i++)
#define for02(k,n)  for (ll j=k; j<n; j++)
#define for03(k,n)  for (ll k=k; k<n; k++)
#define for11(k,n)  for (ll i=k; i<=n; i++)
#define for12(k,n)  for (ll j=k; j<=n; j++)
#define for13(k,n)  for (ll k=k; k<=n; k++)

#define pb push_back
#define mp make_pair
#define pf push_front
#define popf pop_front
#define popb pop_back
#define vll vector<ll>
#define F first
#define S second
#define pp pair <ll, ll>
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define si size()
#define bk back()
#define deci(n)  fixed<<setprecision(n)

#define p0(a) cout << a << " "
#define p1(a) cout << a << "\n"

#define mem(a,n) memset(a, n, sizeof(a)); // n = 0 OR -1 only

#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define MOD 1000000007
#define MOD2 998244353

#include <boost/algorithm/string/replace.hpp>

using namespace std;


int main()
{
  string s;
  
  cin >> s;
  
  string str[4];
  str[0] = "dream";
  str[1] = "dreamer";
  str[2] = "erase";
  str[3] = "eraser";
  
  string temp = s;
  do
  {
  	for(int i = 0 ; i < 4; i++)
 		 boost::algorithm::replace_all(s, str[i],"");
    
    if( s == "")
    {
      p1("YES");
      return 0;
    }
    s = temp;
  }while(next_permutation(str,str+4));
 
   p1("NO");
   return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> d(K);
 
  int A[K][N];
  for(int i = 0; i < K; i++) {
    cin >> d[i];
    
    for(int j = 0; j < d[i]; j++) {
      cin >> A[i][j];
    }
  }

  vector<int> b(N);
  for(int i = 0; i < K; i++) {
    for(int j = 0; j < d[i]; j++) {
      b[A[i][j] - 1] += 1; 
    }
  }
  int sum = 0;
  for(int i = 0; i < N; i++) {
    if(b[i] == 0) sum += 1; 
  }
  cout << sum;
  return 0;
}


Measured memory_bytes: 3664
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
	double xA, yA, xB, yB, xC, yC, xD, yD;
	while(cin >> xA >> yA >> xB >> yB >> xC >> yC >> xD >> yD) {
		if((xA - xB) * (xC - xD) + (yA - yB) * (yC - yD) == 0) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}

Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, t, r;
	cin >> s >> t >> r;
	if(s.back() == t[0] && t.back() == r[0]) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}



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

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

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 main() {
	int n,x,y;
	cin >> n >> x >> y;
	map<int, int> mp;
	for(int i=1; i<=n-1; i++) mp[i] = 0;

	for(int i=1; i<=n-1; i++) {
		for(int j=i+1; j<=n; j++){
			mp[min(j-i, abs(i-x) + 1 + abs(j-y))]++;
		}
	}

	for(int i=1; i<=n-1; i++) {
		cout << mp[i] << endl;
	}

  return 0;
}


Measured memory_bytes: 384
a,b,k = map(int,input().split())

cnt = 0

i = min(a,b)
for x in range(min(a,b)):
    
    if ( a % i == 0 and b % i ==0):
        cnt += 1       

    if (cnt == k):
        print(i)
        exit()
    i -= 1

Measured memory_bytes: 38384
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
s=input()

r=''

for i in range(0,len(s)):
  if s[i]=='0' or s[i]=='1':
    r=r+s[i]
  elif len(s)>0:
    r=r[:-1]
print(r)


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

int main() {

    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int ans = 0;
    for (int i = 0; i <= 100; i++) {
        if(a <= i && i <= b-1 && c <= i && i <= d-1){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3508
#include<stdio.h>
#define D 200000
int main(void)
{
    int i,n,a,b;
    int r[D];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&r[i]);
    }
    for(i=0;i<n-1;i++){
        if(i == 0 || a>r[i]){
            a=r[i];
        }if(i == 0 || b<r[i+1]-a){
            b=r[i+1]-a;
        }
    }
    printf("%d\n",b);
    return 0;
}


Measured memory_bytes: 2512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <map>
#include<queue>

const int INF = 1 << 28;
const long long MOD = 1000000007;
using namespace std;
using Graph = vector<vector<int>>;

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

vector<int> seen(50,-1);
int counter_for_dfs = 0;
void dfs(Graph &G, int v) {
	seen[v] = counter_for_dfs;
	counter_for_dfs++;
	for (auto v_next : G[v]) {
		if (seen[v_next]>=0)continue;

		dfs(G, v_next);
	}
}

void bfs(Graph &G) {
	vector<int> dist(G.size(), -1);
	queue<int> que;
	
	dist[0] = 0;
	que.push(0);
	while (!que.empty()) {
		int v = que.front();
		que.pop();

		for (int g : G[v]) {
			if (dist[g] != -1)continue;
			dist[g] = dist[v] + 1;
			que.push(g);
		}
	}
	for (auto i : dist) {
		cout << i << " ";
	}
}

int counter[200005] = {};
void bfs2(Graph &G,int p,int x) {
	vector<int> dist(G.size() , -1);
	queue<int> que;
	
	dist[p] = 0;
	que.push(p);
	while (!que.empty()) {
		int v = que.front();
		que.pop();

		for (int g : G[v]) {
			if (dist[g] != -1)continue;
			dist[g] = dist[v] + 1;
			que.push(g);
			counter[g] += x;
		}
	}
}
int main()
{
	int n;
	int a[20], b[20], c[20];
	int rslt = 0;
	std::cin >> n;
	int indx_prev = -1;
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		std::cin >> b[i];
	}
	for (int i = 0; i < n-1; i++) {
		std::cin >> c[i];
	}
	for (int i = 0; i < n; i++) {
		int index = a[i]-1;
		rslt += b[index];
		if (indx_prev == index - 1 && indx_prev >= 0) {
			rslt += c[indx_prev];
		}
		indx_prev = index;
	}
	std::cout << rslt;

	return 0;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream> // cin, cout, string
#include <algorithm> // sort, min, max
#include <vector>
#include <utility> // pair, swap
#include <functional>

using namespace std;

// #define int long long

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

using vi = vector<int>;
using pii =  pair<int, int>;

const int IINF =  0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
// const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9+7;

#define for_(i, a, b) for(int i = (a);i < (b);++i)
#define rfor_(i, a, b) for(int i = (b)-1;i >= (a);--i)

#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

const int limit = 100007;

int N, M;
vector<vector<int>> G;

bool A[limit];

int ans;

void dfs(int i) {
  if(A[i])return ;
  A[i] = true;
  for(int j: G[i]) {
    dfs(j);
  }
}

signed main() {
  cin.tie(0);cout.tie(0);
  ios_base::sync_with_stdio(false);

  cin >> N >> M;
  G.resize(N+1);
  rep(i, M) {
    int x, y, z;
    cin >> x >> y >> z;
    G[x].pb(y);
    G[y].pb(x);
  }

  for_(i, 1, N+1) {
    if(A[i]) continue;
    ++ans;
    dfs(i);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 2e7 + 9, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
AC;
int n,m;
cin>>n>>m;
printf("%d",(n-1)*(m-1));



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 30) - 1;
int main()
{
	int D, G;
	int p[15], c[15];
	int minv = INF;
	cin >> D >> G;
	for ( int i = 0; i < D; i++ ) {
		cin >> p[i] >> c[i];
	}

	for ( int i = 0; i < (1 << D); i++ ) {
		int sum = 0;
		int cnt = 0;
		for ( int j = 0; j < D; j++ ) {
			if ( (i >> j) & 1 ) {
				sum += p[j] * (j + 1) * 100 + c[j];
				cnt += p[j];
			}
		}
		int j = D - 1;
		while ( j >= 0 && sum < G ) {
			if ( !((i >> j) & 1) ) {
				int point = (j + 1) * 100;
				int cn = min(p[j], (G - sum + point - 1) / point);
				cnt += cn;
				sum += cn * point;
				if ( cn == p[j] ) sum += c[j];
			}
			j--;
		}
		minv = min(cnt, minv);
	}

	cout << minv << endl;

	return ( 0 );
}


Measured memory_bytes: 256
#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(){
  int n,m;
  cin >> n >> m;

  vector<int> x(m);
  rep(i,m) cin >> x.at(i);

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

  vector<int> d(m-1);
  rep(i,m-1) d.at(i) = x.at(i+1)-x.at(i);
  sort(d.begin(), d.end());

  ll ans=0;
  int count = max(0, m-n);
  rep(i,count) ans += d.at(i);

  cout << ans;
  
}

Measured memory_bytes: 4028
#include<bits/stdc++.h>
#define re register
using namespace std;
bool v[100002];
char c[1002];
int num[100002];
signed main(){
int n,m,k,a,sum,ans1=0,ans2=0;
cin>>n>>m;
for(re int i=1;i<=m;++i){
	cin>>a>>c;
	if(v[a])continue;
	if(c[0]=='W')++num[a];
	else ++ans1,v[a]=1;
}
for(re int i=1;i<=n;++i)if(v[i])ans2+=num[i];
cout<<ans1<<" "<<ans2;
	}

Measured memory_bytes: 768
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

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

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	X, A := getInt(), getInt()
	if X < A {
		out(0)
	} else {
		out(10)
	}
}


Measured memory_bytes: 640
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();

        }
        boolean isFinish = false;
        int initial = 1;
        int result = 0;
        for (int i = 0; i < n; i++) {
            initial = a[initial - 1];
            result++;
            if (initial == 2) {
                isFinish = true;
                break;
            }
        }

        if (isFinish) {
            System.out.println(result);
        } else {
            System.out.println(-1);

        }
    }
}

Measured memory_bytes: 52208
#include<cstdio>
int main() {
	int a,b,c;
	if (~scanf("%d",&a))
		if (~scanf("%d",&b) && b>a)
			if (~scanf("%d",&c) && c>b)
				printf("Yes\n");
			else
				printf("No\n");
		else
			printf("No\n");
	else
		printf("No\n");
	return 0;}

Measured memory_bytes: 2596
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define hello std::ios::sync_with_stdio(false);
#define world cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N=1e5+5;
int ans=0;
int main()
{
	hello world;
	int n,m;
	cin>>n>>m;
	for(int i=22;i<=m;i++)
	{
		if((i/10)*(i%10)<=n&&(i/10)>=2&&i%10>=2)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
  s <- B.getLine
  putStrLn . toString . none' $ s

none'
  :: B.ByteString -> Maybe Char
none' x 
  = if B.null fx then Nothing
                 else Just $ B.head fx
  where
    fx = B.dropWhile (`B.elem` x) $ B.pack ['a' .. 'z']

toString
  :: Maybe Char -> String
toString (Just c) = [c]
toString Nothing  = "None"

Measured memory_bytes: 636
// Last Change: 04/17/2019 21:21:05.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  ll N, M, C;
  cin >> N >> M >> C;

  vector<ll> B(M);
  for (auto &&e : B) {
    cin >> e;
  }

  ll ans = 0;
  for (ll i = 0; i < N; ++i) {
    ll tmp = C, ipt;
    for (ll j = 0; j < M; ++j) {
      cin >> ipt;
      tmp += ipt * B[j];
    }
    if (tmp > 0) {
      ++ans;
    }
  }

  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
a,b,c = map(int,input().split())
count = 0
num = a
while True:
  if c % num == 0:
      count += 1
      num += 1
      if num == b+1:
          break
  elif c % num != 0:
      num += 1
      if num == b+1:
          break

print(count)


Measured memory_bytes: 5596
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int INF = 1 << 30;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */

/* function */
void printAns(bool can);

/* main */
int main(){
    int q, option, num, num2; 
    // multiset : multiple elements can have equivalent values in S
    multiset<int> S;
    using iterator = decltype(S)::iterator;
    cin >> q;
    for (int i  = 0; i < q; i++) {
        cin >> option >> num;
        // cout << option << ' ' << num << '\n';
        switch(option) {
        case 0: {
            // insert(x): Insert x to S 
            //            and report the number of elements 
            //            in S after the operation
            S.insert(num);
            cout << S.size() << '\n';
            break;
                }
        case 1: {
            // find(x): Report the number of x in S
            cout << S.count(num) << '\n';
            break;
            }
        case 2: {
            // delete(x): Delete all x from S
            // 1
            /*
            pair<iterator, iterator> ret = S.equal_range(num);
            for (iterator it = ret.first; it != ret.second; ) {
                it = S.erase(it);
            }
            */
            //2 
            S.erase(num);
            break;
            }
        case 3: {
            // dump(L, R): Print elements x in S 
            //             such that L <= x <= R
            cin >> num2;
            iterator cur = S.lower_bound(num);
            iterator last = S.upper_bound(num2);
            for (; cur != last ; cur++)
                cout << *cur << '\n';
            break;
            }
        }
    }
}


void printAns(bool can) {
    if (can) cout << 1 << '\n';
    else cout << 0 << '\n';
}



Measured memory_bytes: 12352
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll a,b,k; cin>>a>>b>>k;
    if(k<=a) printf("%lld %lld\n",a-k,b);
    else if(k>a+b) printf("0 0\n");
    else printf("%lld %lld\n",0LL,a+b-k);
}


Measured memory_bytes: 3720
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h,w = map(int, input().split())
ch,cw = map(int, input().split())
dh,dw = map(int, input().split())
ch -= 1
cw -= 1
dh -= 1
dw -= 1
rows,cols = h,w

OK = "."
NG = "#"

from collections import defaultdict

ns = defaultdict(set)
ss = [None] * rows
for i in range(rows):
    s = input()
    ss[i] = s
n = rows * cols
start = ch*w+cw
goal = dh*w+dw
seen = [None]*n
seen[start] = 0
from queue import deque 
q = deque([(0, start)]) # ワープ回数, 現在位置, 最後の道の位置
# dx = [0,1,0,-1]
# dy = [1,0,-1,0]
dx = []
dy = []
vvs = []
for i in range(-2,3):
    for j in range(-2,3):
        if not (i==j==0):
            dx.append(i)
            dy.append(j)
            if abs(i)+abs(j)>1:
                vvs.append(1)
            else:
                vvs.append(0)
while q:
    pnum,pu = q.popleft()
    ux,uy = divmod(pu,w)
    # print(pnum,divmod(pu,w))
    if pu==goal:
        break
    for xx,yy,vv in zip(dx,dy,vvs):
#         x = ux+xx
#         y = uy+yy
        x,y = ux+xx, uy+yy
        u = x*w + y
        num = pnum+vv
        if x<0 or y<0 or x>=h or y>=w or ss[x][y]=="#":
            continue
#         print(x,y)
        if seen[u] is None or seen[u]>num:
            seen[u] = num
            if vv==0:
                q.appendleft((num, u))
            else:
                q.append((num,u))
val = seen[goal]
if val is None:
    print(-1)
else:
    print(val)

Measured memory_bytes: 98736
import sys
input = sys.stdin.readline

X,Y,A,B,C=map(int,input().split())
P=sorted(map(int,input().split()),reverse=True)
Q=sorted(map(int,input().split()),reverse=True)
R=list(map(int,input().split()))

C=P[:X]+Q[:Y]+R
C.sort(reverse=True)

print(sum(C[:X+Y]))


Measured memory_bytes: 23472
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum
import sys

iimr = lambda: map(int, sys.stdin.readline().rstrip().split())
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
MOD = (10 ** 9) + 7  # operować sobie na typie int32_t


def 関数(l,r,d):
    res = 0
    for i in range(l, r+1):
        res += i % d == 0
    return res

def çözmek():
    L, R, d = iimr()
    res = []
    res.append(関数(L, R, d))
    print(*res, sep="\n")

if __name__ == "__main__":
    çözmek()


Measured memory_bytes: 9196
function main(input) {
  const args = input.split(' ');
  const N = args[0];
  const K = args[1];
  
  if (N % K === 0) {
    console.log(0);
  } else {
    console.log(1);
  }
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int64_t GCD(int64_t a, int64_t b){
  if(a < b){
    swap(a,b);
  }
  int64_t r = a%b;
  while(r != 0){
    a = b;
    b = r;
    r = a %b;
  }
  return b;
}

//最小公倍数
int64_t LCM(int64_t a, int64_t b){
  int64_t x = GCD(a,b);
  return a * b / x;
}


int main(){
  int64_t N, M;
  cin >> N >> M;
  vector<int64_t> vec(N);
  vector<int64_t> ans(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
    ans.at(i) = vec.at(i);
  }
  
  int two = -1;
  bool flag = true;
  for(int i=0; i<N; i++){
    int x = 0;
    while(vec.at(i) %2 == 0){
      vec.at(i) /= 2;
      x++;
    }
    if(two == -1){
      two = x;
    }
    else if(x != two){
      flag = false;
      break;
    }
  }
  
  if(flag){
    int64_t lcm = ans.at(0) /2;
    for(int i=1; i<N; i++){
      lcm = LCM(lcm,ans.at(i)/2);
    }
    lcm = M / lcm;
    if(lcm %2 != 0){
      lcm++;
    }
    cout << lcm /2 << endl;
  }
  else{
    cout << 0 << endl;
  }
        
    
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int mod = (int)1e9 + 7;
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
const int maxN = 4005;
int c[maxN][maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    int S;
    cin >> S;
    c[0][0] = 1;
    for (int i = 1; i < maxN; i++) {
        c[i][0] = 1;
        for (int j = 1; j <= i; j++) c[i][j] = sum(c[i - 1][j - 1], c[i - 1][j]);
    }
    int ans = 0;
    for (int cnt = 1; cnt * 3 <= S; cnt++) {
        ans = sum(ans, c[S - 3 * cnt + cnt - 1][cnt - 1]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 48940
use std::cmp::max;
use std::collections::HashMap;
use std::error::Error;
use std::io;

pub fn main() {
    if let Err(_e) = run() {
        panic!("failed.");
    }
}

fn run() -> Result<(), Box<Error>> {
    let mut input = String::new();
    io::stdin().read_line(&mut input);
    let n = input.trim().parse::<i32>().unwrap();
    input.clear();
    let mut matrix = vec![];
    for _i in 0..n {
        io::stdin().read_line(&mut input);
        let row: Vec<i64> = input
            .trim()
            .split_whitespace()
            .map(|s| s.parse::<i64>().unwrap())
            .collect();
        matrix.push(row);
        input.clear();
    }

    let mut cache_sum: HashMap<i64, i64> = HashMap::new();
    cache_sum.insert(0, 0);

    let variations = 2.0f64.powi(n) as i32;
    for vairation in 1..variations {
        let mut new_one = vairation & -vairation;
        let previous_state = vairation - new_one;
        let mut new_one_index = 0;
        while new_one & 1 != 1 {
            new_one >>= 1;
            new_one_index += 1;
        }

        let mut sum = cache_sum.get(&(previous_state as i64)).unwrap().clone();
        for i in 0..n {
            if (previous_state >> i) & 1 == 1 {
                sum += matrix[i as usize][new_one_index as usize];
            }
        }
        cache_sum.insert(vairation as i64, sum);
    }

    //dp
    let mut dp = vec![0i64; variations as usize];
    let mut used = 0;
    while used < (1 << n) {
        let unused = used ^ ((1 << n) - 1);
        let mut use_ = unused;
        while use_ > 0 {
            if !(use_ > used) {
                use_ = (use_ - 1) & unused;
                continue;
            }
            dp[use_ | used] = max(
                dp[use_ | used],
                dp[used] + cache_sum.get(&(use_ as i64)).unwrap().clone(),
            );
            use_ = (use_ - 1) & unused;
        }
        used += 1;
    }
    println!("{}", dp[((1 << n) as usize - 1)]);
    Ok(())
}


Measured memory_bytes: 13592
package main

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

/*-----------Main-----------*/

func main() {
	a, b, c, d := readI(), readI(), readI(), readI()

	for i := 0; ; i++ {
		if i%2 == 0 {
			c -= b
			if c <= 0 {
				fmt.Println("Yes")
				return
			}
		} else {
			a -= d
			if a <= 0 {
				fmt.Println("No")
				return
			}
		}
	}
}

/*-----------Utilities-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const maxBuf = 200100
	var buf []byte = make([]byte, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error : There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readSs(a int) []string {
	b := make([]string, a)
	for i := 0; i < a; i++ {
		b[i] = readS()
	}
	return b
}

func readI() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readIs(a int) []int {
	b := make([]int, a)
	for i := 0; i < a; i++ {
		b[i] = readI()
	}
	return b
}

func readF() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

func readFs(a int) []float64 {
	b := make([]float64, a)
	for i := 0; i < a; i++ {
		b[i] = readF()
	}
	return b
}

func max(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] > m {
			m = a[i]
		}
	}
	return m
}

func min(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] < m {
			m = a[i]
		}
	}
	return m
}

func sortI(a []int) []int {
	sort.Ints(a)
	return a
}

func reverse(a []int) []int {
	l := len(a)
	r := make([]int, l)
	for i := 0; i < l; i++ {
		r[i] = a[l-i-1]
	}
	return r
}

func countI(a []int, b int) int {
	l := len(a)
	var c int
	for i := 0; i < l; i++ {
		if a[i] == b {
			c++
		}
	}
	return c
}


Measured memory_bytes: 1780