akhauriyash/Code-Regression huggingface dataset:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right
from heapq import heappush, heappop

import re
# import numpy as np
# from scipy.misc import comb

# 再帰がやばいとき
import sys
sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e30)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

def solve(G):
    N = len(G)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                G[i][j] = min(G[i][j], G[i][k] + G[k][j])
    return G

def main():
    N, M = l_inpl()
    G = create_grid(N, N, INF)

    for i in range(N):
        G[i][i] = 0

    a, b, c = [], [], []
    for _ in range(M):
        ai, bi, ci = l_inpl()
        ai, bi = ai-1, bi-1
        a.append(ai)
        b.append(bi)
        c.append(ci)
        G[ai][bi] = ci
        G[bi][ai] = ci
    
    G = solve(G)

    ans = M
    for i in range(M):
        flag = False
        for j in range(N):
            # dist(j, a[i]) + edge(a[i], b[i]) == dist(j, b[i])のとき
            # j~b[i]の最短経路にedge(a[i], b[i])が含まれる
            if G[j][a[i]]+c[i] == G[j][b[i]]:
                flag = True
        if flag:
            ans -= 1
    
    print(ans)
if __name__ == "__main__":
    main()


Measured memory_bytes: 44784
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<cmath>

using namespace std;

int main(void)
{
    int n;
    vector<long long> a;
    
    cin>>n;

    for(int i = 0;i < n;i++)
    {
	long long temp;
	cin>>temp;

	a.push_back(temp);

    }

    long long x = a[0];
    long long y = 0;

    for(int i = 1;i < a.size();i++)
    {
	y += a[i];
    }

    long long diff;
    diff = abs(x-y);

    if(n == 2)
    {
	cout<<diff<<endl;

	return 0;
    }

    long long sum = 0;
    for(int i = 1;i < a.size()-1;i++)
    {
	x += a[i];
	y -= a[i];
	if(diff > abs(x - y))
	    diff = abs(x - y);
    }

    cout<<diff<<endl;

    return 0;
}


Measured memory_bytes: 2420
#include<iostream>
#include<vector>
#include<math.h>
#include <stdlib.h>
using namespace std;

int main() {
  int a, c, ans = 0;
  double b;
  cin >> a >> b;
  for(int i = 0; i < b; i++) {
    cin >> c;
    if(a / 2 < c) {
      if((c - a / 2 <= 1) && (a % 2 == 1)) {
        ans = 0;
      }else {
        ans += (c - a / 2) * 2 - 1;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
/*************************************************************************
	> File Name: B.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com 
	> Created Time: 2020/4/12 20:21:16
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define LL long long
using namespace std;
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
LL num=0;
char s[5000];
int r=0,g=0,b=0,n;
int R[9000],G[9000];
bool B[9000];
LL count(int x,int y){
	if(x>y) swap(x,y);
	int a=0;
	if(2*y-x<=n && B[2*y-x]) ++a;
	if((y+x)%2==0 && B[(x+y)/2]) ++a;
	if(2*x-y>0 && B[2*x-y]) ++a;
	return a;
}
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	For(i,1,n)
		if(s[i]=='R')
			R[++r]=i;
		else if(s[i]=='G')
			G[++g]=i;
		else{
			B[i]=1;
			++b;
		}
	For(i,1,r)
		For(j,1,g)
			num+=(long long)b-count(R[i],G[j]);
			
	printf("%lld\n",num);
	return 0;
}


Measured memory_bytes: 3852
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);


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

  int n, m;
  cin >> n >> m;
  vector<vector<int>> ab(100005);
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    ab[a].push_back(b);
  }

  priority_queue<int> pq;

  ll ans = 0;

  // i 日以内に報酬がもらえるアルバイトの内，最も報酬が多いものを選ぶ（但し未だやってないもの）
  for (int i = 1; i <= m; i++) {
    for (auto& x : ab[i]) pq.push(x);
    if (pq.empty()) continue;
    ans += pq.top();
    pq.pop();
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8596
#include <cstdio>
#include <cstring>

char arr[100010];
int prv[100010];

int main() {
	scanf("%s", arr + 1);
	int n = strlen(arr + 1);
	if (arr[1] == '0' || arr[n] == '1') {
		puts("-1");
		return 0;
	}
	for (int i = n - 1; i; --i)
		if (arr[i] != arr[n - i]) {
			puts("-1");
			return 0;
		
		}
	int pos = 1;
	for (int i = 2; i < n; ++i)
		if (arr[i] == '1') {
			prv[i] = pos;
			pos = i;
		}
	int ct = 1, pp = n, cur = 1;
	for (int i = pos; i; i = prv[i]) {
		int nx = ct;
		for (int j = i; j < pp; ++j) {
			printf("%d %d\n", cur, ++ct);
		}
		cur = nx + 1;
		pp = i;
	}
	return 0;
}


Measured memory_bytes: 2140
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
a=list(range(1,n+1))
import itertools
a_list=list(itertools.permutations(a))
import math
p_=0
q_=0
for i in range(math.factorial(n)):
  if p==a_list[i]:
    p_=i
  if q==a_list[i]:
    q_=i

print(abs(p_-q_))

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

int f(int h) {
	if (h == 1)return 1;
	return 1 + f(h / 2) * 2;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int H; cin >> H;
	cout << f(H) << endl;

	return 0;
}


Measured memory_bytes: 764
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n,m,q = gets.chomp.split.map(&:to_i)

grid = Array.new(n+1){Array.new(n+1, 0)}
m.times do
  l, r = gets.chomp.split.map(&:to_i)
  grid[l][r] += 1
end
# grid.each{|l|p l}

rui = Array.new(n+1){Array.new(n+1, 0)}
1.upto(n) do |i|
  1.upto(n) do |j|
    rui[i][j] = rui[i][j-1] + rui[i-1][j] - rui[i-1][j-1] + grid[i][j]
  end
end
# rui.each{|l|p l}

q.times do
  l, r = gets.chomp.split.map(&:to_i)
  puts rui[r][r] - rui[l-1][r] - rui[r][l-1] + rui[l-1][l-1]
end


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

const int MAX = 20;

int main(){
    int n, p[MAX];
    cin >> n;
    rep(i,n) cin >> p[i];

    int cnt = 0;
    rep(i,n-2){
        if(max({p[i], p[i+1], p[i+2]}) != p[i+1] && min({p[i], p[i+1], p[i+2]}) != p[i+1]) cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
let rec solve s i =
  if s.[i - 1] < s.[i] then i
  else solve s (i - 1)

let () =
  let s = read_line () in
  print_endline @@
  if s = "zyxwvutsrqponmlkjihgfedcba" then "-1"
  else if String.length s = 26 then
    solve s 25
    |> (fun n ->
        String.sub s 0 (n - 1) ^
        String.make 1 (
        Array.init (26 - n) (fun i ->
          if s.[n + i] < s.[n - 1] then '\255'
          else s.[n + i])
        |> Array.fold_left min '\255'))
  else
    Array.init 26 (fun i -> Char.chr (Char.code 'a' + i))
    |> Array.to_list
    |> List.find (fun c ->
        Array.init (String.length s) (fun i -> s.[i])
        |> Array.to_list
        |> List.for_all (( <> ) c))
    |> String.make 1
    |> ( ^ ) s

Measured memory_bytes: 2432
import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
G = [[] for i in range(N)]

for i in range(M):
  a,b = map(int,readline().split())
  G[a - 1].append(b - 1)
  G[b - 1].append(a - 1)
  
for child in G[0]:
  for gchild in G[child]:
    if gchild == N - 1:
      print("POSSIBLE")
      exit(0)
print("IMPOSSIBLE")  

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

long long lcm(int a, int b)
{
    return 1LL * a / __gcd(a, b) * b;
}
int main()
{
    int N, M;
    cin >> N >> M;

    string S, T;
    cin >> S >> T;

    long long L = lcm(N, M);

    map<int, char> mp;

    for (int i = 0; i < N; i++) {
        mp[i * (L / N)] = S[i];
    }
    for (int i = 0; i < M; i++) {
        if (mp.find(i * (L / M)) == mp.end()) {
            mp[i * (L / M)] = T[i];
            continue;
        }
        if (T[i] != mp[i * (L / M)]) {
            return cout << -1 << endl, 0;
        }
    }
    cout << L << endl;

    return 0;
}


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

int main() {
    int n,m;
    cin >> n >> m;
    vector<pair<ll,int>> ab (n);
    for(int i=0; i<n; i++){
        ll a; int b;
        cin >> a >> b;
        ab.at(i) = make_pair(a,b);
    }
    sort(ab.begin(),ab.end());
    ll ans = 0;
    for(int i=0; i<n; i++){
        if(ab.at(i).second > m){
            ans += ab.at(i).first * m;
            break;
        }
        ans += ab.at(i).first * ab.at(i).second;
        m -= ab.at(i).second;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n; cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(RALL(p));
    p[0]/=2;
    int ans = 0;
    rep(i,n) ans += p[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007

void solve()
{
    int n,k;cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    int dp[n];
    for(int i=0;i<n;i++)
        dp[i]=LONG_MAX;
    dp[0]=0;dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
        int cost;
        for(int j=1;j<=k;j++)
        {
            if(i-j>=0)
            {
                cost=abs(h[i]-h[i-j]);
                dp[i]=min(dp[i],dp[i-j]+cost);
            }
            else
                break;
        }
    }
    cout<<dp[n-1]<<nl;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    //cin>>t;

    while(t--)
    {
      solve();
    }
    return 0;
}


Measured memory_bytes: 1792
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
nodes = [[] for i in range(N)]
for i in range(N-1):
    a, b = MAP()
    a -= 1; b -= 1
    nodes[a].append(b)
    nodes[b].append(a)

# dp1[i] := 頂点iを白にしてその先の全体を塗り分ける通り数
dp1 = [1] * N
# dp2[i] := 頂点iを黒にしてその先の全体を塗り分ける通り数
dp2 = [1] * N
def rec(u, prev):
    for v in nodes[u]:
        if v != prev:
            rec(v, u)
            # 白 <= 白+黒 の遷移
            dp1[u] *= dp1[v] + dp2[v]
            dp1[u] %= MOD
            # 黒 <= 白 の遷移 
            dp2[u] *= dp1[v]
            dp2[u] %= MOD

rec(0, -1)
ans = (dp1[0]+dp2[0]) % MOD
print(ans)


Measured memory_bytes: 101424
#include <cstdio>
char* s[] = {
    "* = ****",
    "* =* ***",
    "* =** **",
    "* =*** *",
    "* =**** ",
    " *= ****",
    " *=* ***",
    " *=** **",
    " *=*** *",
    " *=**** "
};
char a[5][8];
int n;
int main()
{
    bool f = false;
    while (scanf("%d", &n) != EOF) {
        if (f) puts(""); else f = true;
        for (int i = 0; i < 5; ++i) {
            int t = n % 10;
            for (int j = 0; j < 8; ++j) a[4-i][j] = s[t][j];
            n /= 10;
        }
        for (int j = 0; j < 8; ++j) {
            for (int i = 0; i < 5; ++i) putchar(a[i][j]);
            puts("");
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
const double EPS=1e-10;
double add(double l, double r){
    if(abs(l+r)<EPS*(abs(l)+abs(r))) return 0;
    return l+r;
}
struct Pt{
    double x, y;
    Pt(double xx=0, double yy=0){x=xx; y=yy;}
    Pt& operator=(const Pt &rhs){x=rhs.x; y=rhs.y; return *this;}
    Pt& operator+=(const Pt &rhs){x = add(x,rhs.x); y = add(y,rhs.y); return *this;}
    Pt& operator-=(const Pt &rhs){x = add(x,-rhs.x); y = add(y,-rhs.y); return *this;}
    Pt& operator*=(const double &rhs){x *= rhs; y *= rhs; return *this;}
    Pt& operator/=(const double &rhs){x /= rhs; y /= rhs; return *this;}
};
Pt operator+(const Pt &a){return a;}
Pt operator-(const Pt &a){return Pt(-a.x,-a.y);}
Pt operator+(const Pt &lhs, const Pt &rhs){Pt ans=lhs; ans += rhs; return ans;}
Pt operator-(const Pt &lhs, const Pt &rhs){Pt ans=lhs; ans -= rhs; return ans;}
Pt operator*(const Pt &lhs, const double &rhs){Pt ans=lhs; ans *= rhs; return ans;}
Pt operator*(const double &lhs, const Pt &rhs){Pt ans=rhs; ans *= lhs; return ans;}
Pt operator/(const Pt &lhs, const double &rhs){Pt ans=lhs; ans /= rhs; return ans;}
bool operator==(const Pt &lhs, const Pt &rhs){return add(lhs.x,-rhs.x)==0 && add(lhs.y,-rhs.y)==0;}
bool operator!=(const Pt &lhs, const Pt &rhs){return !(lhs==rhs);}
bool operator<(const Pt &lhs, const Pt &rhs){return add(lhs.x,-rhs.x)!=0 ? add(lhs.x,-rhs.x)<0 : add(lhs.y,-rhs.y)<0;}
bool operator>(const Pt &lhs, const Pt &rhs){return rhs<lhs;}
bool operator<=(const Pt &lhs, const Pt &rhs){return !(lhs>rhs);}
bool operator>=(const Pt &lhs, const Pt &rhs){return !(lhs<rhs);}
istream& operator>>(istream &is, Pt &rhs){double x, y; is >> x >> y; rhs=Pt(x,y); return is;}
ostream& operator<<(ostream &os, const Pt &rhs){ os << rhs.x << " " << rhs.y; return os;}
double norm(const Pt &a){return add(a.x*a.x,a.y*a.y);}
double abs(const Pt &a){return sqrt(norm(a));}

int main(){
	int n; cin >> n;
    vector<Pt> p(n);
    for(Pt &i : p) cin >> i;

    double ans=0;
    for(Pt i : p){
        for(Pt j: p){
            ans += abs(i-j);
        }
    }

    cout << fixed << setprecision(10);
	cout << ans/n << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

int main() {
    char s[1234];
    while (~scanf("%s", s)) {
          int w;
          scanf("%d", &w);
          int n = strlen(s);
          for (int i = 0; i < n; i += w) {
              printf("%c", s[i]);
          }
          puts("");
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

void enqueue(P);
P dequeue(void);

P queue[LEN];
int head ,tail;
int n;

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", queue[i].name);
    scanf("%d", &queue[i].t);
  }

head = 1;
tail = n+1;

while(head != tail)
{
u=dequeue();
    if(u.t>=q)
    c = q;
    else
    c = u.t;
u.t-=c;
elaps+=c;
if(u.t>0)enqueue(u);
else 
{printf("%s %d\n",u.name,elaps);}
}
  return 0;
}

void enqueue(P x)
{
    int next = (tail+1)%LEN;

    if(next == head){
        printf("Queue overflow\n");
        exit(2);
    }
    queue[tail] = x;
    tail = next;
}

P dequeue(void)
{
    P val;

    if(head == tail){
        printf("Queue is empty\n");
        exit(3);
    }
    val=queue[head];
    head=(head+1)%LEN;
    return val;
}


Measured memory_bytes: 11936
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main() { 
  int n,k;
  cin>>n>>k;
  
  vector<int> A(n);
  rep(i,n) cin>>A[i];
  
  sort(ALL(A));
  int mi=1e9;
  for(int i=0;i+k-1<n;i++){
    mi=min(mi,A[i+k-1]-A[i]);
  }
  
  cout<<mi<<endl;
  
  return 0;
}

Measured memory_bytes: 3720
#include<stdio.h>
#include<iostream>
#include<algorithm> // sort(ALL())
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue> // push(), front(), pop() 先入れ先出し
#include<map> // 連想配列 map<string, int>
#include<iomanip>
#include<set>
#include<utility>
#include <numeric>
using namespace std;
#define FOR(i, a, b) for(int i=(a); i<(b);  i++)
#define REP(i, n)    for(int i=0;   i<(n);  i++)
#define REP1(i, n)   for(int i=1;   i<=(n); i++)
#define pb push_back
#define mp make_pair
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define EPS 1e-7
#define ALL(obj) (obj).begin(), (obj).end()
using ul    = unsigned long;
using ll    = long long;
using ld    = long double;
using vint  = vector<int>;
using vll   = vector<ll>;
using pint  = pair<int, int>;
using pll   = pair<ll, ll>;
using vpint = vector<pint>;
using vpll  = vector<pll>;
const int INF = (int)1e9 + 1;
const int MOD = (int)1e9 + 7;
#define INT(argu) (int)(argu+eps)

ll a, b, c, d;

ll lcm(int x, int y){
  ll x_ = x;
  ll y_ = y;
  x = max(x_, y_);
  y = min(x_, y_);

  ll r = x%y;
  while(r!=0){
    x = y;
    y = r;
    r = x % y;
  }

  return x_ * y_ / y;
}

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

  scan(a>>b>>c>>d);
//  vint s(n);
//  REP(i, n) scan(s[i]);
  ll cd = lcm(c, d);

  a = a-1;
   ll ans = (b - b/c - b/d + b/cd) - (a - a/c - a/d + a/cd);

  cout << ans << endl;

  return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[101010];
int cnt[3];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>x;
		if(x%4==0) cnt[2]++;
		else if(x%2==0) cnt[1]++;
		else cnt[0]++;
	}
	
	int pre=2;
	FOR(i,N) {
		if(pre==2) {
			if(cnt[0]) {
				pre=0;
				cnt[0]--;
			}
			else if(cnt[1]) {
				pre=1;
				cnt[1]--;
			}
			else if(cnt[2]) {
				pre=2;
				cnt[2]--;
			}
			else {
				return _P("No\n");
			}
		}
		else if(pre==1) {
			if(cnt[1]) {
				pre=1;
				cnt[1]--;
			}
			else if(cnt[2]) {
				pre=2;
				cnt[2]--;
			}
			else {
				return _P("No\n");
			}
		}
		else {
			if(cnt[2]) {
				pre=2;
				cnt[2]--;
			}
			else {
				return _P("No\n");
			}
		}
	}
	_P("Yes\n");
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "map"
using namespace std;

long long n,a,cnt=0;
map<long long, long long> m;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(m[a]==0){
			m[a]++;
			cnt++;
		}
		else{
			m[a]=0;
			cnt--;
		}
	}
	cout<<cnt;
	return 0;
}

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


int main() {
  int n;
  cin >> n;
  vector<int>x(n),y(n),h(n);
  rep(i,n){
    cin>>x.at(i)>>y.at(i)>>h.at(i);
  }
  if(n==1){
    cout<<x.at(0)<<" "<<y.at(0)<<" "<<h.at(0)<<endl;
  }
  else{
  int a,b,c;
  
  rep(i,101){
    rep(j,101){
      bool ch=true;
      int now=-1;
      rep(k,n){
        if(h.at(k)!=0){
          if(now==-1){
            now=abs(x.at(k)-i)+abs(y.at(k)-j)+h.at(k);
          }
          else{
            if(now!=abs(x.at(k)-i)+abs(y.at(k)-j)+h.at(k)){
              ch=false;
            }
          }
        }      
      }
      rep(k,n){
        if(h.at(k)==0){
          if(now-abs(x.at(k)-i)-abs(y.at(k)-j)>0){
            ch=false;
          }
        }
      }
      if(ch){
        a=i;
        b=j;
        c=now;
      }
    }
  }
  
  cout<<a<<" "<<b<<" "<<c<<endl;
  }
  
}



Measured memory_bytes: 256
#include<stdio.h>
     
    int main(int argc, char *argv[]){
        int X;
        int A;
        int B;        
    

            scanf( "%d", &X);
    
            scanf( "%d", &A);
           
            scanf("%d",&B);
     

        if(B<=A){
             printf("delicious\n");
               
            }else if(B<=X+A){
                printf("safe\n");

            
        }else{
            
                printf("dangerous\n");
            
               

        }        return 0;
    }

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

int main(){
    ll n, k;
    cin >> n >> k;
    vector<P> suji(n);
    REP(i, n) {
        cin >> suji[i].first >> suji[i].second;
    }
    sort(suji.begin(), suji.end());
    ll wa = 0, idx = 0;
    ll ans = 0;
    while(k > wa) {
        wa += suji[idx].second;
        ans = suji[idx].first;
        idx++;
    }

    cout << ans << endl;

}


Measured memory_bytes: 1792
a, b, c = map(int, input().split())
li = [a, b, c]
li.sort()
ans = li[2] - li[1]
if (li[2] - li[0] - ans ) % 2 == 0:
    print(ans + (li[2] - li[0] - ans) // 2)
else:
    print(ans + (li[2] - li[0] - ans) // 2 + 2)

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(1000000)

def solve(X):
    k = 100
    ans = 0
    while k < X:
        k = k + int(k * 0.01)
        ans += 1
    return ans

if __name__ == "__main__":
    X = int(input())
    print(solve(X))


Measured memory_bytes: 9164
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	string s, t;
	cin >> s;
	cin >> t;
	int n = s.size();
	int m = t.size();
	int ans = INF;
	for (int i = 0; i <= n-1 - (m-1); i++) {
		string u = s.substr(i, m);
		int c = 0;
		for (int j = 0; j < m; j++) {
			if (u[j] != t[j]) c++;
		}
		ans = min(ans, c);
	}
	cout << ans << endl;
}

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

using namespace std;

int main()
{
  int N, M, T, A[100];
  cin >> N >> M >> T;
  for(int i = 0; i < N; i++) cin >> A[i];

  int ret = 0, time = 0;
  for(int i = 0; i < N; i++) {
    ret += max(0, A[i] - M - time);
    if(i == N - 1 || A[i] + M + M <= A[i + 1]) time = A[i] + M;
    else time = A[i + 1] + M;
  }
  cout << ret + max(0, T - time) << endl;
}

Measured memory_bytes: 3096
N = int(input())
A = []
max1 = 0
max2 = 0
index = 0
for i in range(N):
    a = int(input())
    A.append(a)
    if a > max1:
        max2 = max1
        max1 = a
        index = i
    elif a == max1:
        max2 = a
    elif a > max2:
        max2 = a
for i in range(N):
    if i == index:
        print(max2)
    else:
        print(max1)

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

using namespace std;

int dirs[4][2]={{-1, 0}, {0, 1}, {1, 0}, {0, -1}};

int main()
{
    //freopen("inp.in", "r", stdin);
    //freopen("outp.out", "w", stdout);
    //ios::sync_with_stdio(false);
    long long a, b, c, k;
    scanf("%lld %lld %lld %lld", &a, &b, &c, &k);
    if(k%2==0) printf("%lld\n", a-b);
    else printf("%lld\n", b-a);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication17
{
    class Program
    {
        static void Main(string[] args)
        {
            string str1 = Console.ReadLine();
            int n = int.Parse(str1);

            int hanakoPoint = 0;
            int taroPoint = 0;

            for (int i = 0; i < n; ++i)                             
            {
                string[] str2 = Console.ReadLine().Split(' ');
                string taro = str2[0];
                string hanako = str2[1];

                int x = taro.CompareTo(hanako);         //taro????????????????????????hanako????????????????????§????????????????????????

               if (x < 0)
               {
                   hanakoPoint += 3;
               }
               else if (x > 0)
               {
                   taroPoint += 3;
               }
               else
               {
                   ++hanakoPoint;
                   ++taroPoint;
               }

            }

            Console.WriteLine("{0} {1}", taroPoint, hanakoPoint);
        }
    }
}

Measured memory_bytes: 6404
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
fn abssub(x: usize, y: usize) -> usize {
    if x > y {
        x - y
    } else {
        y - x
    }
}
fn main() {
    input! { h, w, a: [[i64; w]; h], b: [[i64; w]; h] };
    let c = (0..h)
        .map(|i| {
            (0..w)
                .map(|j| (a[i][j] - b[i][j]).abs() as usize)
                .collect::<Vec<_>>()
        })
        .collect::<Vec<_>>();
    let mut dp = vec![vec![vec![false; 7000]; w]; h];
    dp[0][0][c[0][0]] = true;
    for i in 0..h {
        for j in 0..w {
            for k in 0..6500 {
                if dp[i][j][k] {
                    if i + 1 < h {
                        dp[i + 1][j][k + c[i + 1][j]] = true;
                        dp[i + 1][j][abssub(k, c[i + 1][j])] = true;
                    }
                    if j + 1 < w {
                        dp[i][j + 1][k + c[i][j + 1]] = true;
                        dp[i][j + 1][abssub(k, c[i][j + 1])] = true;
                    }
                }
            }
        }
    }
    for k in 0..6500 {
        if dp[h - 1][w - 1][k] {
            println!("{}", k);
            break;
        }
    }
}


Measured memory_bytes: 49404
#include<stdio.h>
int main(){
	int r,c,a,b,d[102][102],e,f;
	scanf("%d %d",&r,&c);
	for(a=1;a<=r;a++){
		for(b=1;b<=c;b++){
			scanf("%d",&d[a][b]);
		}
	}
	for(a=1;a<=r;a++){
		d[a][c+1]=0;
	}
	for(b=1;b<=c;b++){
		d[r+1][b]=0;
	}
	for(a=1;a<=r;a++){
		for(b=1;b<=c;b++){
			d[a][c+1]=d[a][c+1]+d[a][b];
			d[r+1][b]=d[r+1][b]+d[a][b];
			d[r+1][c+1]=d[r+1][c+1]+d[a][b];
		}
	}
	for(a=1;a<=r+1;a++){
		for(b=1;b<=c+1;b++){
			printf("%d",d[a][b]);
			if(b<=c)printf(" ");
		}
	printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2028
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int n; cin >> n;
	set<int> st1, st2;

	for (int i = 1; i <= n; i++)
	{
		if ((n % i == 0) && (i<=9)) st1.insert(i);
	}

	st2 = st1;
	int flg = 0;

	for (auto itr1 = st1.begin(); itr1 != st1.end(); ++itr1) {
		for (auto itr2 = st2.begin(); itr2 != st2.end(); ++itr2) {
			if (*itr1 * *itr2 == n) flg = 1;
		}
	}

	if (flg == 0) cout << "No" << endl;
	else cout << "Yes" << endl;

}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C: Multiple Clocks
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

typedef long long ll;

/* global variables */

ll ts[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) scanf("%lld\n", &ts[i]);

  ll lcm = ts[0];
  for (int i = 1; i < n; i++)
    lcm = lcm / __gcd(lcm, ts[i]) * ts[i];
  printf("%lld\n", lcm);
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=1e5+7;
vi G[maxn];
vi ng[maxn];
vi col;
bool dfs(int u,int fa=-1)
{
    bool ret=col[u];
    for(auto v:G[u])if(v!=fa)
    {
        bool cur=dfs(v,u);
        if(cur)
        {
            ng[u].push_back(v);
            ng[v].push_back(u);
        }
        ret|=cur;
    }
    return ret;
}
int ma=0;
int dfs2(int u,int fa=-1)
{
    vi son(2,0);
    for(auto v:ng[u])if(v!=fa)
        son.push_back(dfs2(v,u));
    sort(son.begin(),son.end());
    reverse(son.begin(),son.end());
    ma=max(ma,col[u]+son[0]+son[1]);
    return col[u]+son[0];
}
int main()
{
    int n;
    cin>>n;
    string s;
    col=vi(n+1);
    for(int i=1,u,v;i<n;i++)
    {
        cin>>u>>v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    cin>>s;
    int tot=0;
    int rt=-1;
    for(int i=1;i<=n;i++)
    {
        col[i]=s[i-1]=='W';
        if(s[i-1]=='W')
        {
            tot++;
            rt=i;
        }
    }
    if(tot==0) print(0);
    if(tot==1) print(1);
    if(tot<=1) return 0;
    dfs(rt);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        ans+=ng[i].size();
        col[i]^=((int)ng[i].size()&1);
        if(col[i]==1) ans++;
    }
    dfs2(rt);
    //dbg(ans,ma);
    print(ans-2*ma);
}

Measured memory_bytes: 25728
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i ++)
using ll = long long;
const int M = 5000;
string s, t;
int m, n;
struct str { int len; char c; int i; int j; };
str dp[M+1][M+1];

void run(int i, int j) {
    if (!(i < m && j < n)) return;
    str st = {0, 0, -1, -1};
    if (s[i] == t[j] && st.len < dp[i][j].len + 1) st = {dp[i][j].len + 1, s[i], i, j};
    if (st.len < dp[i][j+1].len) st = dp[i][j+1];
    if (st.len < dp[i+1][j].len) st = dp[i+1][j];
    dp[i+1][j+1] = st;
    //cout << "(" << (i+1) << "," << (j+1) << "): {" << st.len << "," << st.c << "," << st.i << "," << st.j << "}" << endl;
}

int main() {
    rep(i, M) rep(j, M) dp[i][j] = {0, 0, -1, -1};
    cin >> s >> t;
    m = s.size(), n = t.size();
    rep(l, max(m, n)) {
        rep(i, l) {
            run(i, l);
        }
        rep(j, l) {
            run(l, j);
        }
        run(l, l);
    }
    string ans = "";
    int i = m, j = n;
    while (dp[i][j].i >= 0) {
        ans += dp[i][j].c;
        int nexti = dp[i][j].i, nextj = dp[i][j].j;
        i = nexti, j = nextj;
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
    return 0;
}

Measured memory_bytes: 394276
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
template <class T> void chmax(T& x, T y) { if (x < y) x = y; }
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N, T; cin >> N >> T;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
    vector<int> dp1(T), dp2(T);
    for (int i = 0; i < N; i++) {
        for (int j = T - 1; j >= 0; j--) {
            if (j + A[i] < T) {
                chmax(dp2[j + A[i]], dp2[j] + B[i]);
                chmax(dp1[j + A[i]], dp1[j] + B[i]);
            }
            chmax(dp2[j], dp1[j] + B[i]);
        }
    }
    cout << dp2[T - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
// D - Match Matching

// DFSを用いる解法

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int N, M;
vector<pair<int, int>> A;
int m[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string k;
string ans;
int ans_len = -1;

bool dfs(int n) {
	// 最初の候補が見つかったら最後の2桁だけ全探索して終了
	if ((int)k.size() < ans_len - 3) return true;

	if (n == 0) {
		ans_len = max(ans_len, (int)k.size());

		string tmp_k = k;
		sort(tmp_k.begin(), tmp_k.end(), greater<char>());

		if (k.size() == ans_len && tmp_k > ans) {
			ans = tmp_k;
		}

		return false;
	}

	if (n < 0) return false;

	for (auto a : A) {
		k.push_back('0' + a.second);
		if (dfs(n - a.first)) return true;
		k.pop_back();
	}

	return false;
}

int main() {
	cin >> N >> M;

	for (int i=0; i<M; i++) {
		int a;
		cin >> a;
		A.push_back(make_pair(m[a], -a));
	}

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

	for (int i=0; i<M; i++) {
		A[i] = make_pair(A[i].first, -A[i].second);
	}

	dfs(N);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4276
import math
import collections
import fractions
import itertools
import functools
import operator
import numpy as np

def solve():
    h, w = map(int, input().split())
    maze = [input() for _ in range(h)]
    ans = 0
    can_move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
    for x in range(h):
        for y in range(w):
            if maze[x][y] == "#":
                continue
            dist = [[0]*w for _ in range(h)]
            stack = collections.deque()
            stack.append([x,y])
            while stack:
                h2, w2 = stack.popleft()
                for i, j in can_move:
                    newh, neww = h2+i, w2+j
                    if newh < 0 or neww < 0 or newh >= h or neww >= w:
                        continue
                    elif maze[newh][neww] != "#" and dist[newh][neww] == 0:
                        dist[newh][neww] = dist[h2][w2]+1
                        stack.append([newh, neww])
            dist[x][y] = 0
            ans = max(ans, np.max(dist))
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 27068
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PAIR pair<double, double>
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
#define PI acos(-1)
const LL MOD = (LL)1e9+7;
const LL INF = (LL)1e9+7;
const LL INFLL = (LL)1e18;
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	string str;
	cin >> str;
	bool flag = true;
	REP(i, str.size()){
		if(i&1){
			if(str[i]=='R')flag = false;
		}else if(str[i]=='L')flag = false;
	}
	
	cout << (flag?"Yes":"No") << endl;
	return 0;

}


Measured memory_bytes: 256
s = int(input())
s_1 = s // 100 #4桁の数字列の上2桁を取り出す
s_2 = s % 100  #4桁の数字列の下2桁を取り出す

if 1 <= s_1 <=12 and 1 <= s_2 <= 12:
    print("AMBIGUOUS")
elif 1 <= s_1 <= 12:
    print("MMYY")
elif 1 <= s_2 <= 12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){
    int i,N,M;
    int a[100000];
    int ana[100000];
    unsigned long sum[100000];
    int mod=1000000007;

    scanf("%d %d", &N, &M);
    for(i=0;i<M;i++){
        scanf("%d", &a[i]);
        ana[a[i]]=1;
    }

    if(ana[N] != 1){
        sum[N]=1;
    }
    else{
        sum[N]=0;
    }
    if(ana[N-1] != 1){
        sum[N-1]=1;
    }
    else{
        sum[N-1]=0;
    }
    for(i=N-2;i>=0;i--){
        if(ana[i] == 1){
            sum[i] = 0;
            continue;
        }
        sum[i] = (sum[i+1]+sum[i+2]) % mod;
    }

    printf("%lu\n", sum[0]);
    return 0;
}


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

void solve()
{
    int r, d, x2000; cin >> r >> d >> x2000;
    for (int i = 1; i <= 10; ++i) {
        x2000 = (x2000 * r) - d;
        cout << x2000 << '\n';
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int D, N;
  cin >> D >> N;
  if(D == 0) {
    if(N == 100) {
      cout << 101 << endl;
    }
    else {
      cout << N << endl;
    }
  }
  else if(D == 1) {
    if(N == 100) {
      cout << 10100 << endl;
    }
    else {
      cout << 100 * N << endl;
    }
  }
  else {
    if(N == 100) {
      cout << 1010000 << endl;
    }
    else {
      cout << 10000 * N << endl;
    }
  }
}

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


int main() {
  int N=0;
  int K=0;
  cin >> N >> K;
  vector<int>Score(N);
  for(int i=0;i<N;i++){
    cin >> Score.at(i);
  }
  
  for(int i=0;i+K+1<=N;i++){
    if(Score.at(i)<Score.at(i+K)){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }

  
}

Measured memory_bytes: 4044
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7

# l = 10**6 + 3

# M = [1]  # i!のmod
# m = 1
# for i in range(1, l):
#     m = (m * i) % mod
#     M.append(m)

def pow(x, y, mod):  # x**y の mod を返す関数
    ans = 1
    while y > 0:
        if y % 2 == 1:
            ans = (ans * x) % mod
        x = (x**2) % mod
        y //= 2
    return ans

def inv(x, mod):  # x の mod での逆元を返す関数
    return pow(x, mod-2, mod)

# print(inv(8,13))

# MI = [0] * (l-1) +[inv(M[l-1], mod)]  # i!の逆元
# for i in range(l-2, -1, -1):
#     MI[i] = MI[i+1] * (i+1) % mod

# def C(x, y):  # コンビネーション
#     if y < 0 or y > x:
#         return 0
#     ans = M[x]
#     ans = (ans * MI[y]) % mod
#     return (ans * MI[x-y]) % mod

from fractions import gcd


def lcm(x, y):
    return (x*y) // gcd(x,y)
    # return int((x * y) * inv(gcd(x, y), mod)) % mod


def lcm_list(A):
    ans = A[0] % mod
    for i in range(1, len(A)):
        ans = lcm(ans, A[i]) #% mod
    return ans % mod

lc = lcm_list(A)
# print(lc)
ans = 0
for i in range(n):
    ans = (ans + (lc * inv(A[i], mod))% mod) % mod
print(ans%mod)

Measured memory_bytes: 68868
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Program
    {

        static void Main(string[] args)
        {
            String S = Console.ReadLine();
            if(S[2] == S[3] && S[4] == S[5])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

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

    ll c1[3] = {};
    ll c2[3] = {};

    ll total = 1;
    ll r = n;

    rep(i, s.length()){
        ll idx = s[i]=='R'? 0 : s[i]=='G'? 1 : 2;
        if(c2[idx]>0){
            total = total * c2[idx] % 998244353;
            total = total * r % 998244353;
            --c2[idx];
            --r;
        }
        else if(c1[(idx+1)%3]>0){
            total = total * c1[(idx+1)%3] % 998244353;
            --c1[(idx+1)%3];
            ++c2[(idx+2)%3];
        }
        else if(c1[(idx+2)%3]>0){
            total = total * c1[(idx+2)%3] % 998244353;
            --c1[(idx+2)%3];
            ++c2[(idx+1)%3];
        }
        else ++c1[idx];
    }
    cout << total << endl;
}


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

int n,m=0,tmp,p[110],ans=0,a,b,c; //m:辺の数
tuple<int,int,int> line[10010]; //辺

void init(int n){ //初期化
    for(int i=0;i<n;i++){p[i]=i;}
}

int root(int a){ //根を求める
    if(p[a]==a){return a;}
    return (p[a]=root(p[a])); //親の根を親とする
}

bool is_same_set(int a,int b){ //根が同じか判定
    return root(a)==root(b);
}

void unite(int a,int b){ //結合
    p[root(a)]=root(b);
}

int main(){
    cin>>n;
    init(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>tmp;
            if(j>i){
                if(tmp!=-1){
                    line[m]=make_tuple(tmp,i,j);
                    m++;
                }
            }
        }
    }
    sort(line,line+m);
    init(n);
    for(int i=0;i<m;i++){
        c=get<0>(line[i]);
        a=get<1>(line[i]);
        b=get<2>(line[i]);
        if(!(is_same_set(a,b))){
            unite(a,b);
            ans+=c;
        }
        //cout<<c<<a<<b<<endl;
    }
    cout<<ans<<endl;
}


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

h,w,d=map(int,input().split())
A=[0]*(h*w)
for i in range(h):
    l=list(map(int,input().split()))
    for j in range(w):
        A[l[j]-1]=[i,j]
q=int(input())
l=[0]*q
r=[0]*q
for i in range(q):
    l[i],r[i]=map(int,input().split())
ans=[0]*(h*w)
for i in range(d,h*w):
    ans[i]=ans[i-d]+abs(A[i][0]-A[i-d][0])+abs(A[i][1]-A[i-d][1])
for i in range(q):
    print(ans[r[i]-1]-ans[l[i]-1])

Measured memory_bytes: 25012
fun main(args: Array<String>){
    
    val (k,s) = readLine()!!.split(" ").map { it.toInt() }
    
    var ans = 0

    for (x in 0..k){
        for (y in 0..k){
            var z = s-x-y
            if (z <= k && 0 <= z) { ans++ }
        }
    }

    println(ans)
}

Measured memory_bytes: 37672