akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int ma = -1e9, mi = 1e9;
  int mai,mii;
  rep(i,n){
    cin >> a[i];
    ma = max(ma,a[i]);
    mi = min(mi,a[i]);
    if(ma==a[i]) mai=i;
    if(mi==a[i]) mii=i;
  }
  ++mai; ++mii;

  vector<P> ans;
  if(abs(ma)>=abs(mi)){
    rep(i,n) if(a[i]<0) ans.emplace_back(mai,i+1);
    rep(i,n-1) ans.emplace_back(i+1,i+2);
  }else{
    rep(i,n) if(a[i]>0) ans.emplace_back(mii,i+1);
    rep(i,n-1) ans.emplace_back(n-i,n-i-1);
  }
  int m = ans.size();
  cout << m << endl;
  rep(i,m) cout << ans[i].first << " " << ans[i].second << endl;
}

Measured memory_bytes: 256
#lines = <<'EOS'
#2 4
#EOS

lines = $stdin.read
array = lines.split("\n")
x,y = array[0].split(" ").map(&:to_i)

group_a = [1, 3, 5, 7, 8, 10, 12]
group_b = [4, 6, 9, 11]
group_c = [2]

def contain?(group, x, y)
  true if group.include?(x) and group.include?(y)
end

ret = if contain?(group_a, x, y) or contain?(group_b, x, y) or contain?(group_c, x, y)
        "Yes"
      else
        "No"
      end

puts ret


Measured memory_bytes: 1788
package main

import "fmt"

var (
	n, k int
)

func main() {
	fmt.Scan(&n, &k)

	fmt.Println(k * exp((k-1), (n-1)))
}

func exp(x, n int) int {
	ans := 1
	for ; n > 0; n-- {
		ans *= x
	}

	return ans
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <utility>
#include <queue>
#define ull unsigned long long
#define ll long long
#define mod 1000000007
using namespace std;

vector <bool> flag(100001, true);
vector <int> dp(100001, 0);
int n,m;

int main()
{
    cin>>n;

    cin>>m;

    for (int i=0;i<m;i++){
        int a;
        cin>>a;
        flag[a] = false;
    }

    dp[0] = 1;
    for (int i=0;i<n;i++){
        if ( i + 1 <= n && flag[i+1] ){
            dp[i+1] = (dp[i+1] + dp[i]) % mod;
        }
        if ( i + 2 <= n && flag[i+2] ){
            dp[i+2] = (dp[i+2] + dp[i]) % mod;
        }
    }

    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 640
def gcd(a, b):
    a, b = min(a, b), max(a, b)
    while b % a != 0:
        a, b = b % a, a
    return a


n = int(input())
a = list(map(int, input().split()))

# s = [-1, *a[:-1]]
# t = [*a[1:], -1]
s = [-1] * n
t = [-1] * n
for x in range(0, n - 1):
    s[x + 1] = a[x]
for x in range(1, n):
    t[x - 1] = a[x]

for x in range(1, n - 1):
    s[x + 1] = gcd(s[x + 1], s[x])
for x in range(n - 2, 0, -1):
    t[x - 1] = gcd(t[x - 1], t[x])

ans = -float('inf')
for x, y in zip(s, t):
    if x == -1:
        ans = max(ans, y)
    elif y == -1:
        ans = max(ans, x)
    else:
        ans = max(ans, gcd(x, y))
    
print(ans)

Measured memory_bytes: 14076
l = list(map(int, input().split()))
l.sort()

hoge = l[2] - l[1]
ans = hoge

l[0] += hoge
fuga = l[2] - l[0]

if fuga % 2 == 0:
    ans += fuga // 2
else:
    ans += fuga // 2 + 2

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(void)
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll x, y;
  cin >> x >> y;
  if (x % y == 0)
    cout << -1 << '\n';
  else 
    cout << x << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INFL = (1LL << 60);
 const int INFI = (1 << 30);

 int main() {
   int N; cin >> N;
   vector<vector<int>> Graph(N);
   map<pii, int> weight;

   rep(i, 0, N - 1) {
     int u, v, w; cin >> u >> v >> w;
     Graph.at(u - 1).push_back(v - 1);
     Graph.at(v - 1).push_back(u - 1);
     weight[{u - 1, v - 1}] = w;
     weight[{v - 1, u - 1}] = w;
   }

   vector<int> ans(N, -1);
   ans.at(0) = 0;
   queue<int> path;
   path.push(0);

   while(!path.empty()) {
     int pv = path.front();
     path.pop();
     for (int nv: Graph.at(pv)) {
       if (ans.at(nv) != -1) continue;
       else {
         path.push(nv);
         ans.at(nv) = (ans.at(pv) + weight.at({nv, pv})) % 2;
       }
     }
   }

   rep(i, 0, N) cout << ans.at(i) << endl;
 }


Measured memory_bytes: 18816
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
D = {}
for a in A:
    bit = bin(a)[2:][::-1]
    for i in range(len(bit)):
        if bit[i] == '1':
            if i not in D:
                D[i] = 1
            else:
                D[i] += 1

ans = 0
for k, v in D.items():
    ans += (N-v)*v*2**k % mod
    ans = ans % mod

print(ans)

Measured memory_bytes: 124656
package main

import (
	"fmt"
)

const mod = 1000000007

func main() {
	var s int
	fmt.Scan(&s)
	dp := make([]int, s+1)
	dp[0] = 1
	for i := 1; i <= s; i++ {
		if i < 3 {
			dp[i] = 0
			continue
		}
		dp[i] = dp[i-1] + dp[i-3]
		dp[i] %= mod
	}
	ans := dp[s]
	ans %= mod
	fmt.Println(ans)
}


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

int main() {
  string s;
  cin >> s;
  
  int size=s.size();
  
  int a=0,b=0;
  for(int i=0; i<size; i++){
    if(s[i]=='0') a++;
    else b++;
  }

  if(a>b) swap(a,b);
  
  cout << a*2 << endl;
  
}


Measured memory_bytes: 512
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

ll N;
ll ans = 0;

signed main(){
    cin >> N;
    for(ll i=1; i<=N; i++){
        ll tmp = N/i;
        ans += i*tmp*(tmp+1)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  vector<int> p;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    int a;
    cin >> a;
    p.push_back(a);
  }
  int ans = 0;
  for (int i = 0; i < n - 2; i++)
  {
    if ((p[i] > p[i + 1] && p[i + 1] > p[i + 2]) || (p[i] < p[i + 1] && p[i + 1] < p[i + 2]) || (p[i] == p[i + 2] && p[i] > p[i + 1]))
    {
      ans++;
    }
  }
  cout << ans << endl;
}

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

using namespace std;
long long num=100000;
vector<long long>arr(num+1);
int main()
{
    long long n,i,temp;
    cin>>n;
    fill(arr.begin(),arr.end(),0);
    for(i=0;i<n;i++){
        cin>>temp;
        if(arr[temp]==0)
            arr[temp]=1;
        else if(arr[temp]==1)
            arr[temp]=2;
        else if(arr[temp]==2)
            arr[temp]=1;
    }
    long long count1=0,count2=0;
    for(i=0;i<num;i++){
        if(arr[i]!=0){
            count1++;
            if(arr[i]%2==0)
                count2++;
        }
    }
    if(count2%2==0)
        cout<<count1<<endl;
    else
        cout<<count1-1<<endl;
    return 0;
}


Measured memory_bytes: 1024
from operator import mul
from functools import reduce
from collections import Counter
# from itertools import combinations as comb
# from itertools import permutations as perm
# from copy import copy
# 配列二分法アルゴリズム
# https://docs.python.jp/3/library/bisect.html
# import bisect
# 桁数指定
# print('{:.3f}'.format(X))
# from collections import defaultdict
# dic = defaultdict(lambda: ...)
# 値で辞書をソート
# sorted(dic.items(), key=lambda x:x[1])
# ヒープキュー
# https://docs.python.org/ja/3/library/heapq.html
# import heapq
# 正規表現(regular expression)のためのモジュール
# import re

import sys

sys.setrecursionlimit(2000)


def inpl():
    return list(map(int, input().split()))


# 重複組み合わせは nHr = (n + r - 1)Cn
def cmb(n, r):
    # combination
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def gcd(a, b):
    # greatest common divisor
    while b > 0:
        a, b = b, a % b

    return a


def lcm(a, b):
    # least common multiple
    return a * b // gcd(a, b)


N, A, B = inpl()
S = input()

a = 0
b = 0
for s in S:
    if s == 'c':
        print('No')
        continue
    elif a + b >= A + B:
        print('No')
        continue

    if s == 'a':
        print('Yes')
        a += 1
    elif s == 'b' and b < B:
        print('Yes')
        b += 1
    else:
        print('No')


Measured memory_bytes: 4556
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define PI acos(-1.0)
#define lowbit(x) (x&-x)
#define pb(x) push_back(x)
#define mp(x) make_pair(x)

typedef long long ll;
typedef long double ld;
const int maxn=1e5+10;
char s[maxn];

int main()
{
    int n;
    scanf("%s",s);
    int len=strlen(s);
    for(int i=0;i<len-8;i++)
        printf("%c",s[i]);
    puts("");
    return 0;
}


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

using namespace std;

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)



vector<int> read_array()
{
    int n;
    scanf("%d", &n);

    vector<int> v(n);
    REP(i, n) {
        scanf("%d", &v[i]);
    }

    return v;
}

int bubble(vector<int>& v)
{
    int n_swap = 0;

    for(int jmax = v.size()-1; jmax >= 1; --jmax) {
        for(int j = 1; j <= jmax; ++j) {
            if(v[j-1] > v[j]){
                swap(v[j-1], v[j]);
                ++n_swap;
            }
        }
    }

    return n_swap;
}

int main()
{
    vector<int> v = read_array();

    int n_swap = bubble(v);

    REP(i, v.size()) {
        printf("%d%c", v[i], i == v.size()-1 ? '\n' : ' ');
    }
    printf("%d\n", n_swap);

    return 0;
}

Measured memory_bytes: 2736
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define INF 1145141919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long int ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
////////////////////////////////////////////////////////////////////
int main()
{
    int N; cin >> N;
    vector<pair<int,int>> pairs(N);
    REP(i,N) cin >> pairs[i].first;
    REP(i,N) cin >> pairs[i].second;

    vector<int> diff(N);

    REP(i,N) diff[i]=pairs[i].first-pairs[i].second;

    sort(diff.begin(), diff.end(), greater<int>());

    ll ans=0;

    REP(i,N){
        if(diff[i]<0) break;
        else ans+=diff[i];
    }

    cout << ans << endl;


    return 0;
}


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

Measured memory_bytes: 1008
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
#include <string>
#include <limits>
using namespace std;
int gcd(int a, int b)//最大公約数
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc
{
    // 宣言
    long long a;

    public:
        // 素因数分解
        void decompositPrime(long long a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(long long n)
{
    // 割る数の初期値
    a = 2;
    // √n ≧ a ( n ≧ a * a ) の間ループ処理
    while (n >= a * a) {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0) {
            //printf("%d * ", a);
             v.push_back(a);
            n /= a;
        } else {
            a++;
        }
    }
    // 最後に残った n は素因数
    v.push_back(n);
    //printf("%d\n", n);
}
vector<int> divisor(int n) {//約数発見
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    std::sort(ret.begin(), ret.end());
    return ret;
}
long nc2(long n){
    return n*(n-1)/2;
}
template<typename TypeInt>
std::string Itoa(const TypeInt v, int base)
{
	static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	string ret;
	static numeric_limits<TypeInt> t;
	TypeInt n = v;
	if (t.is_signed) {
		if (v < 0) n *= -1;
	}

	while (n >= base) {
		ret += table[n%base];
		n /= base;
	}
	ret += table[n];
	if (t.is_signed) {
		if (v < 0 && base == 10) ret += '-';
	}
	// 文字列の順番を逆にする
	std::reverse(ret.begin(), ret.end());

	return ret;
}

int main(){
    //std::stack<int> stack;
    long n;
    
    cin >> n;
    string ans  ="";
    while(n){
        n --;
        ans += ('a' + n%26);
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}






Measured memory_bytes: 3576
local max = math.max
local n_t = {}
for i = 1, 4 do
	n_t[i] = io.read("n")
end

print(max(n_t[1]*n_t[3], n_t[1]*n_t[4], n_t[2]*n_t[3], n_t[2]*n_t[4]))

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

 using namespace std;
 typedef long long ll;

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

   vector<int> X(N), L(N);
   vector<pair<int, int>> p(N);

   for (int i = 0; i < N; i++) {
     cin >> X.at(i) >> L.at(i);
     p.at(i) = make_pair(X.at(i) + L.at(i), X.at(i) - L.at(i));
   }
   sort(p.begin(), p.end());

   int ans = N;
   int max_pf = p.at(0).first;
   for (int i = 1; i < N; i++) {
     if (max_pf > p.at(i).second) ans--;
     else max_pf = p.at(i).first;
   }

   cout << ans << endl;
  }


Measured memory_bytes: 1792
/**
*	created: 13.09.2020 21:24:16
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
using ll = long long;
using P = pair<int,int>;
// #define endl '\n'
#define int long long
#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 rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1ll << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;
template<typename T> inline bool chmax(T &a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T> inline bool chmin(T &a, T b) {if (b < a) {a = b; return 1;} return 0;}
template<typename T> T pow(T a, ll n) {T r(1); while(n) {if (n & 1) r *= a; a *= a; n >>= 1;} return r;}
struct faster_io {faster_io() {cin.tie(0); ios_base::sync_with_stdio(false);}} faster_io_;

// ModInt
template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {if ((x = x_ % mod + mod) >= mod) x -= mod;}
    ModInt inv() const {return pow(*this, mod - 2);}
    ModInt& operator+=(ModInt rhs) {if ((x += rhs.x) >= mod) x -= mod; return *this;}
    ModInt& operator-=(ModInt rhs) {if ((x -= rhs.x) < 0) x += mod; return *this;}
    ModInt& operator*=(ModInt rhs) {x = (unsigned long long)x * rhs.x % mod; return *this;}
    ModInt& operator/=(ModInt rhs) {x = (unsigned long long)x * rhs.inv().x % mod; return *this;}
    ModInt operator-() const {return -x < 0 ? mod - x : -x;}
    ModInt operator+(ModInt rhs) const {return ModInt(*this) += rhs;}
    ModInt operator-(ModInt rhs) const {return ModInt(*this) -= rhs;}
    ModInt operator*(ModInt rhs) const {return ModInt(*this) *= rhs;}
    ModInt operator/(ModInt rhs) const {return ModInt(*this) /= rhs;}
    bool operator==(ModInt rhs) const {return x == rhs.x;}
    bool operator!=(ModInt rhs) const {return x != rhs.x;}
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {s << a.x; return s;}
    friend istream& operator>>(istream& s, ModInt<mod>& a) {s >> a.x; return s;}
};

using mint = ModInt<MOD>;

// table
mint fac[MAX], finv[MAX], inv[MAX];

void make_table() {
    fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1;
    rep2(i,2,MAX){
        fac[i] = fac[i-1] * (mint)i;
        inv[i] = (mint)MOD - inv[MOD%i] * (mint)(MOD/i);
        finv[i] = finv[i-1] * inv[i];
    }
}

struct table {table() {make_table();}} table_init;

mint COM(int n,int k) {
    if (n < k || n < 0 || k < 0) return 0;
    return fac[n] * finv[k] * finv[n-k];
}

mint PER(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;
    return fac[n] / fac[n-k];
}

signed main() {
    int n; cin >> n;
    if (n < 3) {
        cout << 0 << endl;
        return 0;
    }
    mint ans = 0;
    int t = n / 3;
    rep2(i,1,t+1) {
        int num = n - 3 * i;
        ans += COM(num+i-1,num);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 27076
n=int(input())
if n%2==0:
  print((n*(n-1)//2-n//2))
  for i in range(1,n):
    for j in range(i+1,n+1):
      if i+j!=n+1:
        print(i,j)
else:
  print((n*(n-1)//2-(n-1)//2))
  for i in range(1,n):
    for j in range(i+1,n+1):
      if j==n:
        print(i,j)
      elif j+i!=n:
        print(i,j)

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
using namespace std;
int main()
{
    int h,w,n;
    cin >> h >> w >> n;
    int num = max(h, w);
    int ans = (n+num-1) / num;
    cout << ans << endl;

}

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

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);		
		int a=in.nextInt();
		int b=in.nextInt();
		int ans=a*b;
		if(a>9||b>9)
		{
			ans=-1;
		}
		System.out.println(ans);
	}
}
	

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vii         vector<pair<int,int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define endl '\n'
#define int long long int
using namespace std;
vi adj[(int)1e5 + 5];
int vals[(int)1e5 + 5];
bool fail = false;
int check(int cur, int P){
   //debug(cur); 
    int ans =0;
    int sum  =0;
    int mx = 0;
    int childs = 0;
    for(int child: adj[cur]){
        if(child == P)continue;
        int pass = check(child, cur);
        sum += pass;
        mx = max(mx, pass);
        childs++;
        if(fail)return 0;
    }
    // sum - inner == vals[cur]
    if(childs == 0)return vals[cur];

    int mxPaths = vals[cur];
    if(mx > sum/2){
        mxPaths=  min(mxPaths, sum - mx);
    }
    mxPaths = min(mxPaths, sum/2);
    int inner = sum - vals[cur];
    if(inner > mxPaths)fail = true;
    if(inner < 0)fail = true;
//    debug(cur);
 //   debug(sum);
  //  debug(sum - inner*2);
    return sum - inner*2;
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    int n;cin >> n;
    FOR(i, n)cin >> vals[i];
    int x,y;
    FOR(i, n-1){
        cin >>  x >> y;
        x--, y--;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    FOR(i, n)
       if(adj[i].size() > 1){
        int pass =check(i, -1);
        if(pass != 0)fail = true;
        cout << (!fail ? "YES" : "NO") << endl;
        return 0;
    }
    cout << (vals[0] == vals[1] ? "YES" : "NO") << endl;

}




Measured memory_bytes: 13184
from collections import deque

h, w = map(int, input().split())
maze = {(i,j):c for i in range(h) for j, c in enumerate(input())}

blacks = sum(c == '#' for c in maze.values())

def bfs(i, j):
    dq = deque()
    dq.appendleft((1, (i, j)))
    while dq:
        steps, (i, j) = dq.pop()
        if (i, j) == (h-1, w-1):
            return steps
        if maze.get((i, j), '#') == '#':
            continue
        maze[(i, j)] = '#'
        dirs = ((-1, 0), (1, 0), (0, 1), (0, -1))
        dq.extendleft((steps+1, (i+di, j+dj)) for di, dj in dirs)

res = bfs(0, 0)
print(-1 if res is None else h*w - res - blacks)

Measured memory_bytes: 3700
import java.util.*;

import javax.xml.crypto.Data;

import java.math.*;

public class Main {
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[] {1,5,10,50,100,500};
		int sum = 0;
		for(int i = 0; i < a.length; i++) {
			sum += sc.nextInt() * a[i];
		}
		System.out.println((sum >= 1000)?"1":"0");
		
	}
	
}

Measured memory_bytes: 17300
H, W = map(int, input().split())
S = {}
for _ in range(H):
    S[_] = input()
    
def change(S_str, x, j):
    s_list = list(S_str)
    s_list[j] = str(x.count('#'))
    S_str = "".join(s_list)
    return S_str

for i in range(H):
    for j in range(W):
        s = S[i][j]
        if s == '.':
            if H == 1 and W == 1:
                S[i] = '0'
            elif H == 1 and j == 0:
                x = S[i][j+1]
                S[i] = change(S[i], x, j)
            elif H == 1 and j == W-1:
                x = S[i][j-1]
                S[i] = change(S[i], x, j)
            elif H == 1:
                x = S[i][j-1] + S[i][j+1]
                S[i] = change(S[i], x, j)
            elif W == 1 and i == 0:
                x = S[i+1][j]
                S[i] = change(S[i], x, j)
            elif W == 1 and i == W-1:
                x = S[i-1][j]
                S[i] = change(S[i], x, j)
            elif W == 1:
                x = S[i-1][j] + S[i+1][j]
                S[i] = change(S[i], x, j)
            elif i == 0 and j == 0:
                x = S[i][j+1] + S[i+1][j] + S[i+1][j+1]
                S[i] = change(S[i], x, j)
            elif i == 0 and j == W-1:
                x = S[i][j-1] + S[i+1][j-1] + S[i+1][j]
                S[i] = change(S[i], x, j)
            elif i == 0:
                x = S[i][j-1] + S[i][j+1] + S[i+1][j-1] + S[i+1][j] + S[i+1][j+1]
                S[i] = change(S[i], x, j)
            elif i == H-1 and j == 0:
                x = S[i][j+1] + S[i-1][j] + S[i-1][j+1]
                S[i] = change(S[i], x, j)
            elif i == H-1 and j == W-1:
                x = S[i][j-1] + S[i-1][j-1] + S[i-1][j]
                S[i] = change(S[i], x, j)
            elif i == H-1:
                x = S[i][j-1] + S[i][j+1] + S[i-1][j-1] + S[i-1][j] + S[i-1][j+1]
                S[i] = change(S[i], x, j)
            elif j == 0:
                x = S[i-1][j] + S[i-1][j+1] + S[i][j+1] + S[i+1][j] + S[i+1][j+1]
                S[i] = change(S[i], x, j)
            elif j == W-1:
                x = S[i-1][j-1] + S[i-1][j] + S[i][j-1] + S[i+1][j-1] + S[i+1][j]
                S[i] = change(S[i], x, j)
            else:
                x = S[i-1][j-1] + S[i-1][j] + S[i-1][j+1] + S[i][j-1] + S[i][j+1] + S[i+1][j-1] + S[i+1][j] + S[i+1][j+1]
                S[i] = change(S[i], x, j)
                
for k in range(H):
    print(S[k])

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

using namespace std;

typedef long long int lli;

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

    int n, m, x, y;
    vector<vector<int>> g(100001, vector<int>());
    vector<int> h(100001, 0), lng(100001, 0);

    cin >> n >> m;
    for (int i=0; i<m; i++) {
        cin >> x >> y;
        g[x].push_back(y);
        h[y]++;
    }

    queue<int> tmp, tp;
    for (int i=1; i<=n; i++) if (h[i] == 0) tmp.push(i);
    while (!tmp.empty()) {
        int i = tmp.front(); tmp.pop();

        for (int a : g[i]) if (--h[a] == 0) tmp.push(a);
        tp.push(i);
    }

    int ans = 0;
    while (!tp.empty()) {
        int t = tp.front(); tp.pop();
        for (int gg : g[t]) {
            lng[gg] = max(lng[gg], lng[t]+1);
            ans = max(ans, lng[gg]);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6912
function main()
  
  (A, B, C, D) = map(x -> parse(Int, x), split(readline()))
  
  while true
    C -= B
    if C <= 0
      break
    end
    A -= D
    if A <= 0
      break
    end
  end
  
  if C <= 0
    println("Yes")
  else
    println("No")
  end

end

main()

Measured memory_bytes: 160536
a[100],v,j,n;p(){for(v=0;v<n;printf("%d%s",a[v++],v-n+1?" ":"\n"));}main(i){scanf("%d",&n);for(;j<n;scanf("%d",&a[j++]));p();for(;i<n;){j=i-1;v=a[i++];for(;a[j]>v;a[j+1]=a[j--]);a[j+1]=v;p();}exit(0);}

Measured memory_bytes: 600
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

string abc,ans;
	
int main(){
    int a,b;

    cin >> a >> b;

    abc = to_string(min(a,b));

    for(int i = 0;i < max(a,b); i++){
        ans += abc;
    }

    cout << ans << endl;

    

    return 0;

}


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

int main(void) {
    int A, B, C, D, sum = 0;
    cin >> A >> B >> C >> D;
    if (A < C) {
        if (B < C) {}
        else if (D < B) sum = D - C;
        else sum = B - C;
    }
    else {
        if (D < A) {}
        else if (B < D) sum = B - A;
        else sum = D - A;
    }
    cout << sum << endl;

}

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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< pair<int,int> > vpii;
typedef vector< pair<ll,ll> > vpll;
typedef vector< vector<int> > matrix;

#define SET(Ar,val) memset(Ar,val,sizeof(Ar))
#define rep(i,val,n)  for(int i=val;i<n;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LMAX LONG_LONG_MAX
#define LMIN LONG_LONG_MIN
#define IMAX INT_MAX
#define IMIN INT_MIN
#define Modulo 1000000007ll

/*--------------------------------------------------------------------------------------------------------------------------------*/

template <class T> T modpower(T a,T b,T MOD)
{
    T ans=1;
    while(b!=0)
    {
        if(b%2==1)
        ans=(ans*a)%MOD;
        a=(a*a)%MOD;
        b/=2;
    }
    return ans;
}


void init()
{
    int r;
    cin >> r ;
    if(r < 1200)
        cout << "ABC";
    else if(r < 2800)
        cout << "ARC";
    else
        cout << "AGC";
}

int main()
{
    clock_t time1 = clock();
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    init();
    clock_t time2 = clock();
    cerr <<"Time: " <<(double)(time2-time1)/CLOCKS_PER_SEC * 100000 <<" seconds" <<endl;
	return 0;
    }


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

int main(){
  int n, k;
  cin >> n >> k;
  vi h(n);
  rep(i, 0, n)
    cin >> h[i];
  
  sort(h.begin(), h.end());
  reverse(h.begin(), h.end());
  
  ll ans = 0;
  
  rep(i, k, n){
    ans += h[i];
  }
  
  cout << ans << endl;
  
  return 0;
  
}

Measured memory_bytes: 3964
n=int(input())
a=list(map(int,input().split()))
p=1
if(a.count(0)>=1):
  print("0")
  exit()
for i in range(n):
  p*=a[i]
  if(p>1000000000000000000):
    print("-1")
    exit()
print(p)

Measured memory_bytes: 21788
#include <iostream>
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define decimal(x) cout<<fixed<<setprecision(x);
#define hackercup(x) cout<<"Case #"<<x<<": ";
void solve()
{
    string s;
    cin>>s;
    int c=0,ans=0;
    for(int i=0;i<3;i++)
    {
        if(s[i]=='R')
        c++;
        else
        {
            ans=max(ans,c);
            c=0;
        }
    }
    ans=max(ans,c);
    cout<<ans<<endl;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
     //  cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 3648
/*
	http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0010
	Circumscribed Circle of a Triangle
*/

#include <stdio.h>
#include <math.h>
int main(void)
{
	int n,i;
	double x1, x2, x3, y1, y2, y3;
	double px, py, r;
	double a, b, c, a2, b2, c2, s, S2;
	scanf("%d", &n);
	for (i = 1; i <= n; ++i)
	{
		scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);

		/* ??¨????????????3???????????????2???????±??????? */
		a2 = pow(x2 - x3, 2.0) + pow(y2 - y3, 2.0);
		b2 = pow(x3 - x1, 2.0) + pow(y3 - y1, 2.0);
		c2 = pow(x1 - x2, 2.0) + pow(y1 - y2, 2.0);

		a = sqrt(a2);
		b = sqrt(b2);
		c = sqrt(c2);

		/* ??????????????¬??? */
		s = (a + b + c) / 2;
		/* ??¢??????2??? */
		S2 = s * (s-a) * (s-b) * (s-c);

		/* Wikipedia????????£????????¬??? */
		px = (a2*(b2+c2-a2)*x1 + b2*(c2+a2-b2)*x2 + c2*(a2+b2-c2)*x3) / (16 * S2);
		py = (a2*(b2+c2-a2)*y1 + b2*(c2+a2-b2)*y2 + c2*(a2+b2-c2)*y3) / (16 * S2);
		r = ( a*b*c ) / ( sqrt( (a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c) ) );

		printf("%.3f %.3f %.3f\n", px, py, r);
	}
	return 0;
}

Measured memory_bytes: 664
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
ll a[10000004];
ll b[10000004];
int main()
{
	ll n;
	ll sum=0;
	scanf("%lld",&n);
	for(ll i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(ll i=0;i<n;i++)
	{
		for(ll j=i+1;j<n;j++)
		sum+=a[i]*a[j];
	}
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 2304
def move_dice(d, dir):
    if(dir == 'N'):
        d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4]
    if(dir == 'S'):
        d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1]
    if(dir == 'E'):
        d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2]
    if(dir == 'W'):
        d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3]


dice = list(map(int, input().split()))
command = input()
for c in command:
    move_dice(dice, c)
print(dice[0])

Measured memory_bytes: 7792
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 15
#define PI 3.141592653589793
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)
#define mem(x, a) memset(x, a, sizeof x)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pcl pair<char, ll>
#define psl pair<string, ll>


ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;
unordered_map<ll, ll> mp;
set<ll> s;
string S = "";
ll cases;

int main() {
	go;
    cin >> N;
   	fel(i, 1, 100, 1) {
   		fel(j, 1, 100, 1) {
   			fel(k, 1, 100, 1) {
   				mp[(i * i) + (j * j) + (k * k) + (i * k) + (i * j) + (j * k)]++;
   			}
   		}
   	}
   	// cout << mp[6];
   	fei(i, 1, N, 1) {
   		cout << mp[i] << "\n";
   	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/




Measured memory_bytes: 5108
H,W = map(int,input().split())
grid = [None for _ in range(H)]
for i in range(H):
  s = input()
  grid[i] = s
dire = [[0,-1],[-1,0],[1,0],[0,1]]
for r in range(H):
  for c in range(W):
    if grid[r][c] == "#":
      ok = False
      for d in dire:
        if 0 <= r+d[0] and r+d[0] < H and 0 <= c+d[1] and c+d[1] < W and grid[r+d[0]][c+d[1]] == "#":
          ok = True
          break
      if not ok:
        print("No")
        exit()
print("Yes")


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; ++i) cin >> h[i];
    sort(h.begin(), h.end());
    reverse(h.begin(), h.end());
    for (int i = 0; i < min(n, k); ++i) {
        h[i] = 0;
    }
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        ans = ans + h[i];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1024
from sys import stdin

def main():
    S = input()

    case1 = '10' * (len(S) // 2)
    case2 = '01' * (len(S) // 2)
    if len(S) % 2:
        case1 += '1'
        case2 += '0'

    cnt1 = 0
    for s1, s2 in zip(S, case1):
        if s1 != s2:
            cnt1 += 1

    cnt2 = 0
    for s1, s2 in zip(S, case2):
        if s1 != s2:
            cnt2 += 1

    print(min(cnt1, cnt2))

input = lambda: stdin.readline().rstrip()
main()


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
using pi=pair<int,int>;
#define mp make_pair
signed main(){
  int h,w;
  cin>>h>>w;
  vector<vector<bool>> maze(h,vector<bool>(w,false));
  for(int i=0;i<h;++i){
    string s;
    cin>>s;
    for(int j=0;j<w;++j)if(s[j]=='.')maze[i][j]=true;
  }
  int res=0;
  for(int srcy=0;srcy<h;++srcy)for(int srcx=0;srcx<w;++srcx){
    if(!maze[srcy][srcx])continue;
    queue<pair<pi,int>> que;
    que.push(mp(pi(srcy,srcx),0));
    vector<vector<bool>> vis(h,vector<bool>(w,false));
    vector<vector<int>> cost(h,vector<int>(w,1e7));
    vis[srcy][srcx]=true;
    while(!que.empty()){
      pair<pi,int> q=que.front();
      que.pop();
      int &cury=q.first.first,&curx=q.first.second;
      assert(maze[cury][curx]);
      cost[cury][curx]=min(cost[cury][curx],q.second);
      if(cury-1>=0&&maze[cury-1][curx]&&!vis[cury-1][curx])que.push(mp(pi(cury-1,curx),q.second+1)),vis[cury-1][curx]=true;
      if(cury+1<h&&maze[cury+1][curx]&&!vis[cury+1][curx])que.push(mp(pi(cury+1,curx),q.second+1)),vis[cury+1][curx]=true;
      if(curx-1>=0&&maze[cury][curx-1]&&!vis[cury][curx-1])que.push(mp(pi(cury,curx-1),q.second+1)),vis[cury][curx-1]=true;
      if(curx+1<w&&maze[cury][curx+1]&&!vis[cury][curx+1])que.push(mp(pi(cury,curx+1),q.second+1)),vis[cury][curx+1]=true;
    }
    for(int i=0;i<h;++i)for(int j=0;j<w;++j)if(maze[i][j])res=max(res,cost[i][j]);
  }
  cout<<res;
}


Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int i,j,p1,p2,n,a[100000],s[4],l,h,mx,mj;
	long long sum;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&a[i]);
	sort(a,a+n);
	p1=0;	p2=n-1;
	l=a[p1];	h=a[p2];
	p1++;	p2--;
	sum=h-l;
	for(i=0;i<n-2;i++)	{
		s[0]=l-a[p1];
		s[1]=l-a[p2];
		s[2]=h-a[p1];
		s[3]=h-a[p2];
		mx=-1;
		for(j=0;j<4;j++)	{
			if(s[j]<0)	s[j]=-s[j];
			if(mx<s[j])	{
				mx=s[j];	mj=j;
			}
		}
		if(mj==0)	{
			l=a[p1];	p1++;
		}
		if(mj==1)	{
			l=a[p2];	p2--;
		}
		if(mj==2)	{
			h=a[p1];	p1++;
		}
		if(mj==3)	{
			h=a[p2];	p2--;
		}
		sum+=mx;
	}
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <queue>
#include <functional>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#define ll long long
#define REP(i,n) for(int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
using namespace std;
int main(){
    int n,m,t,p;
    while(cin>>n>>m>>t>>p){
        if(n==0 && m==0 && t==0 && p==0){
            break;
        }
        
        ll d[t], c[t] , x[p], y[p];
        for(int i=0; i<t; i++){
            cin >> d[i] >> c[i];
        }
        for(int i=0; i<p; i++){
            cin >> x[i] >> y[i];
        }
        
        ll matrix[1000][1000]={};
        
        ll left=0;
        ll bottom=0;
     
        
        for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
                matrix[i][j]=1;
            }
        }
        
        
        for(int i=0; i<t; i++){
            
            if(d[i]==1){
                for(int yoko=0; yoko<c[i]; yoko++){
                    for(int tate=bottom; tate<bottom+m; tate++){
                        matrix[left+c[i]+yoko][tate]+=matrix[left+c[i]-1-yoko][tate];
                    }
                }
                
                left+=c[i];
            }
            
            else if(d[i]==2){
                for(int tate=0; tate<c[i]; tate++){
                    for(int yoko=left; yoko<left+n; yoko++){
                        matrix[yoko][bottom+c[i]+tate]+=matrix[yoko][bottom+c[i]-1-tate];
                    }
                }
                
                bottom+=c[i];
            }
            
        }
        
        
        for(int i=0; i<p; i++){
            cout<<matrix[left+x[i]][bottom+y[i]]<<endl;
        }
        
    }
    return 0;
}



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

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define rep(i, N) for (ll i = 0; i < (N); i++)
#define For(i, a, b) for (ll i = (a); i < (b); i++)
#define all(A) (A).begin(), (A).end()

int main(){
    int N;
    cin >> N;
    int tmp1 = 0;
    int tmp2 = 0;
    int A[N];
    rep(i, N) {
        cin >> A[i];
        if (A[i] >= tmp1) {
            tmp2 = tmp1;
            tmp1 = A[i];
        }
        else if (A[i] >= tmp2) {
            tmp2 = A[i];
        }
    }
    rep(i, N) {
        if (tmp1 == A[i]) cout << tmp2 << endl;
        else cout << tmp1 << endl;
    }

    return 0;
}


Measured memory_bytes: 2432
module DLinkedList = struct
  type 'a element =
    { value : 'a;
      mutable next : 'a element option;
      mutable prev : 'a element option
    }
  type 'a t = {
    mutable first : 'a element option;
    mutable last  : 'a element option
  }

  let create () = {first = None; last = None}
  let is_empty t = t.first = None && t.last = None
  let value elt = elt.value
  let next elt = elt.next

  let insert_first t value =
    let new_elt = {prev = None; next = t.first; value} in
    begin match t.first with
      | Some old_first -> old_first.prev <- Some new_elt
      | None -> ()
    end;
    t.first <- Some new_elt;
    begin match t.last with
      | Some _ -> ()
      | None -> t.last <- Some new_elt
    end

  let remove t elt =
    let {prev; next; _} = elt in
    begin match prev with
      | Some prev -> prev.next <- next
      | None -> t.first <- next
    end;
    begin match next with
      | Some next -> next.prev <- prev
      | None -> t.last <- prev
    end;
    elt.prev <- None;
    elt.next <- None
      
  let find t (v:int) =
    let rec loop = function
      | None -> ()
      | Some elt ->
        if v = (value elt) then remove t elt
        else loop (next elt)
    in
    loop t.first

  let remove_first t =
    begin match t.first with
      | Some first ->
        begin match first.next with
          | Some e -> e.prev <- None; t.first <- first.next
          | None -> t.first <- None; t.last <- None
        end
      | None -> ()
    end

  let remove_last t =
    begin match t.last with
      | Some last ->
        begin match last.prev with
          | Some e -> e.next <- None; t.last <- last.prev
          | None -> t.first <- None; t.last <- None
        end
      | None -> ()
    end

  let iter t ~f =
    let rec loop = function
      | None -> ()
      | Some elt -> f elt; loop (next elt)
    in loop t.first
end

let () =
  let open DLinkedList in
  let (n: int) = read_int () in
  let (dll: int t) = create () in
  for i=1 to n do
    begin match read_line () with
      | "deleteFirst" -> remove_first dll
      | "deleteLast" -> remove_last dll
      | s ->
        begin match String.sub s 0 6,
                    (String.sub s 7 (String.length s - 7)
                     |> int_of_string) with
        | "insert", n -> insert_first dll n
        | "delete", n -> find dll n
        | _ -> ()
        end
    end
  done;
  iter dll
    ~f:(fun e -> match next e with
          Some _ -> Printf.printf "%d " (value e)
        | None -> Printf.printf "%d\n" (value e))

Measured memory_bytes: 77972
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.typecons;
  
  int n, p; rd(n, p);
  alias T=Tuple!(int, "w", int, "b");
  auto data=new T[](n);
  foreach(i; 0..n) rd(data[i].w, data[i].b);

  auto g(long w, long b){return (100-p)*w+p*b;}
  sort!((l, r)=>(g(l.w, l.b)>g(r.w, r.b)))(data);
  long yes=0, no=reduce!((r, e)=>(r+e.b))(0L, data);
  foreach(i, e; data){
    yes+=e.w; no-=e.b;
    if(yes*100>=(yes+no)*p){// yes/(yes+no)>=p/100 , yes*100>=(yes+no)p
      writeln(i+1); return;
    }
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) write(e, " ");
  writeln();
}


Measured memory_bytes: 4092
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <cmath>

using namespace std;



int main(int argc, const char * argv[]) {


    double x1,x2;
    double y1,y2;
    
    cin >> x1 >> y1 >> x2 >> y2;
    
    double d;
    
    d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    printf("%5f",d);

 
    return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

int main(){
    ll N,Y;cin>>N>>Y;
    REP(i,N+1){//10000
        REP(j,N-i+1){//5000
            if( (Y-10000*i-5000*j)/1000 == N-i-j)
            {
                cout<<i<<" "<<j<<" "<<(Y-10000*i-5000*j)/1000<<endl;
                return 0;
            }
        }
    }
    cout<<"-1 -1 -1"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPP(i, n) for(int i = 1; i <= n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll MOD = 1000000007;

bool judgePrimeNumber(int n) {
    if(n==1) return 0;
    for(int i = 2; i <= sqrt(n); i ++) {
        if(n%i==0) return 0;
    }
    return 1;
}

int main() {
    ll n; cin >> n;
    vector<int> p;
    REPP(i,n) {
        if(judgePrimeNumber(i)) {
            p.push_back(i);
        }
    }
    vector<vector<int>> l(p.size(), vector<int>(2));
    REP(i,p.size()) l[i][0] = p[i];
    REPP(i,n) {
        int tmp = i;
        int index = 0;
        while (tmp>1) {
            if(tmp%l[index][0]==0) {
                l[index][1]++;
                tmp /= l[index][0];
            }
            else index ++;
        }
    }
    ll ans = 1;
    REP(i,p.size()) {
        if(l[i][1]>0) ans *= l[i][1]+1;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n,m,sum=0,p,x;
  cin >> n;
  int t[n];
  REP(i,n) { cin >> t[i]; sum += t[i]; }
  cin >> m;
  REP(i,m) { cin >> p >> x; cout << sum - (t[p-1] - x) << endl; }
}

Measured memory_bytes: 256
def die(matrix, n):
	for i in range(n-2):
		if matrix[i][0] == matrix[i][1]:
			if matrix[i+1][0] == matrix[i+1][1]:
				if matrix[i+2][0] == matrix[i+2][1]:
					return("Yes")

	return("No")			



n = int(input())
matrix = []
for i in range(n):
   row = list(map(int, input().split()))
   matrix.append(row)


print(die(matrix, n))

Measured memory_bytes: 9192
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <map>
#include <string>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <algorithm> 
#include <ctime>
#include <deque>

#define INF 2140000000
#define MaxN 100005

using namespace std;

int N,M,K,X1,X2,Y1,Y2,Size=0,Stack[2*MaxN],SSize=0;
bool found[MaxN];
struct spec
{
	int type,coord;
}Line[2*MaxN];
bool cond(spec a,spec b)
{
	return a.coord<b.coord;
}
bool border(int x,int y)
{
	if(x==0||x==N||y==M||y==0)
		return true;
	else return false;
}
void Add(int x,int y,int t)
{
	if(y==0)
		Line[++Size].coord=x;
	else if(x==N)
		Line[++Size].coord=N+y;
	else if(y==M)
		Line[++Size].coord=2*N+M-x;
	else if(x==0)
		Line[++Size].coord=2*N+2*M-y;
	Line[Size].type=t;
}

int main()
{
	cin>>N>>M>>K;
	for(int i=1;i<=K;i++)
	{
		cin>>X1>>Y1>>X2>>Y2;
		if(border(X1,Y1)&&border(X2,Y2))
		{
			Add(X1,Y1,i);
			Add(X2,Y2,i);
		}
	}
	sort(Line+1,Line+1+Size,cond);
	for(int i=1;i<=Size;i++)
	{
		if(!found[Line[i].type])
		{
			Stack[++SSize]=Line[i].type;
			found[Line[i].type]=true;
		}
		else if(Stack[SSize]!=Line[i].type)
		{
			cout<<"NO\n";
			return 0;
		}
		else SSize--;
	}
	cout<<"YES\n";
	return 0;
}

Measured memory_bytes: 2048
import java.util.Scanner
import scala.io.StdIn._
object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val arr: Array[Map[Int, Boolean]] = Array.fill(n){
    Array.fill(sc.nextInt)(sc.nextInt - 1 -> (sc.nextInt == 1)).toMap
  }
 
  val valids = (1 until (1 << n)).map{ i =>
    val valid = (0 until n)
      .filter{j => ((1 << j) & i) != 0}
      .forall{j => arr(j).forall{case (k, b) => (((1 << k) & i) != 0) == b}
    }
    if (valid) Integer.bitCount(i) else 0
  }
 
  println(valids.max)
}

Measured memory_bytes: 41836
program ABC106B
    implicit none
    integer(8)::i,j
    integer(8)::N,sqrt_N,divisor
    integer(8)::result=0
    
    read(5,*)N

    do i=1,N
        if(mod(i,2)==1)then
            divisor=0
            sqrt_N=int(sqrt(real(i)))
            do j=1,sqrt_N
                if(mod(i,j)==0)then
                    divisor=divisor+1
                    if(j/=i/j)then
                        divisor=divisor+1
                    end if
                end if
            end do
            
            if(divisor==8)then
                result=result+1
            end if
        end if
    end do

    print'(i0)',result
end program ABC106B

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//educational dp contest, task b, 2020/09/14
//ms

/*
https://atcoder.jp/contests/dp
*/

#define BIG 100000000000

int main(void){
  int N, K;
  vector<int64_t> h;
  vector<int64_t> cost(100001);

  cin >>N >>K;
  for(int i=0;i<N;i++){
    int tmp;
    cin >>tmp;
    h.push_back(tmp);
  }

  cost[0]=0;
  for(int i=1;i<K;i++){
    cost[i]=BIG;
    for(int j=0;j<i;j++) cost[i]=min(abs(h[i]-h[j])+cost[j], cost[i]);
  }

  for(int i=K;i<N;i++){
    cost[i]=BIG;
    for(int j=i-K;j<i;j++) cost[i]=min(abs(h[i]-h[j])+cost[j], cost[i]);
  }

  cout <<cost[N-1]<<endl;

  return 0;
}
/*
n-1, n-2, ......, n-K番目までいく最小コストがそれぞれわかればn番目もわかる！
*/


Measured memory_bytes: 5000
from itertools import permutations
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

a, b = 0, 0
perms = list(permutations(range(1, N + 1)))

for per in perms:
    if P == per:
        a = perms.index(per) + 1
    if Q == per:
        b = perms.index(per) + 1

print(abs(a - b))

Measured memory_bytes: 45040
def f(n, s, min)
    if n == 1
        min <= s && s <= 9 ? 1 : 0
    else
        (min..9).map{|x| f(n-1, s-x, x+1)}.inject(0, :+)
    end
end

loop {
    n, s = gets.split.map(&:to_i)
    break if n == 0
    p f(n, s, 0)
}

Measured memory_bytes: 6108