akhauriyash/Code-Regression huggingface dataset:
def main():
    import sys
    input = lambda : sys.stdin.readline().rstrip()
    sys.setrecursionlimit(max(1000, 10**9))
    write = lambda x: sys.stdout.write(x+"\n")


    ### 木の読み込み tree

    # サイズが大きいとdefaultdictが早い(for文を書かなくて済む)
    from collections import defaultdict
    # import numpy as np
    # from numba import njit
    n = int(input())
    ns = defaultdict(set)
    for _ in range(n-1):
        u,v = map(int, input().split())
        u -= 1
        v -= 1
        ns[u].add(v)
        ns[v].add(u)


    # 再帰を用いないver.
    def dfs(start):
        q = [start]
        # 行きがけ順
        seen = [None]*n
        # 帰りがけ順
        done = [None]*n
        parent = [None]*n
        parent[start] = -1
        d0 = 0
        d1 = n
        while q:
            u = q.pop()
            if u>=0:
                if seen[u] is not None:
                    continue
                seen[u] = d0
                d0 += 1
                q.append(~u)
                for v in ns[u]:
                    if seen[v] is None:
                        q.append(v)
                        parent[v] = u
            else:
                d1 -= 1
                done[~u] = d1
        return seen, done, parent
    seen, done, parent = dfs(0)
    done = [(u,d) for u,d in enumerate(done)]
    done.sort(key = lambda x: -x[1])
    bs = {}
    for u,_ in done:
        p = parent[u]
        bs[p,u] = 1 + sum(bs[u,v] for v in ns[u] if v!=p)

    bs[0,-1] = 0
    for u,_ in reversed(done):
        p = parent[u]
        for v in ns[u]:
            if v==p:
                continue
            bs[v,u] = bs[p,u] - bs[u,v] + bs[u,p]

    M = 10**9 + 7
    p1 = pow(2, n-1, M)
    p2 = pow(2, n, M)
    p3 = pow(p2, M-2, M)
    ans = 0
    for u in range(n):
        s = 0
        for v in ns[u]:
            s += pow(2, bs[u,v], M) - 1
            s %= M
        val = p1 - s - 1
        ans += val
        ans %= M
    ans *= p3
    ans %= M
    print(ans%M)
# from line_profiler import LineProfiler
# lp = LineProfiler()
# lp.add_function(main)
# lp.runcall(main)
# lp.print_stats()
main()

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

int main() {
    string S;
    cin >> S;
    int n = S.size();
    ll fac = 1;
  	ll cur = 0;
    
    vector<ll> dp(2019, 0);
  	dp[0]++;
    for (int i = 0; i < n; i++)
    {
      	ll a = S[n-i-1]-'0';
        cur = (cur+a*fac)%2019;
        fac = (fac*10)%2019;      	
        dp[cur]++;
    }
    ll ans = 0;
    for (int i = 0; i < 2019; i++)
    {
          int m = dp[i];
          ans += m*(m-1)/2;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3744
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n;
    cin >> n;
    vector<int> v(2*n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &v[i]);
        v[i+n] = v[i];
    }
    auto dp = make_v(2*n+1, 2*n+1, (ll)0);
    for (int len = 1; len <= n; ++len) {
        for (int i = 0; i+len <= 2*n; ++i) {
            if((len&1) == (n&1)){
                chmax(dp[i][i+len], dp[i][i+len-1]+v[(i+len+2*n-1)%(2*n)]);
                chmax(dp[i][i+len], dp[i+1][i+len]+v[i]);
            }else {
                if(v[(i+len+2*n-1)%(2*n)] > v[i]){
                    chmax(dp[i][i+len], dp[i][i+len-1]);
                }else {
                    chmax(dp[i][i+len], dp[i+1][i+len]);
                }
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i <= n; ++i) {
        chmax(ans, dp[i][i+n]);
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 128020
N, K = map(int, input().split())
A = list(map(int, input().split()))

less = -float('inf')
eq = 0

for d in range(60)[::-1]:
    mask = (1 << d)

    one = len([0 for a in A if (a & mask) != 0])
    zero = N - one

    l = less + mask * max(one, zero)

    if (K & mask) != 0:
        l = max(l, eq + mask * one)

    less = l
    eq += mask * (one if (K & mask == 0) else zero)

print(max(less, eq))


Measured memory_bytes: 14620
#include<iostream>
#include<math.h>
#include<cstdio>
#include<cstring>
#include<string>
#include<string.h>
#include<cmath>
#include<map>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
int main()
{
	int m,n,s;
	cin>>m>>n;
	s=(m-1)*(n-1);
	cout<<s;
}

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

#define VARNAME(x) #x
#define show(x) cerr << #x << " = " << x << endl

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

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll x, y;
    cin >> x >> y;
    const ll N = s.size();
    ll len = 0;
    bool yoko = true;
    vector<ll> vertical;
    vector<ll> horizontal;
    for (ll i = 0; i < N; i++) {
        if (s[i] == 'F') {
            len++;
        } else {
            (yoko ? horizontal : vertical).push_back(len);
            len = 0;
            yoko = not yoko;
        }
    }
    (yoko ? horizontal : vertical).push_back(len);
    const ll yokosum = accumulate(horizontal.begin(), horizontal.end(), 0LL);
    vector<bool> yokodp(2 * yokosum + 1, false);
    yokodp[yokosum] = true;
    for (ll i = 0; i < horizontal.size(); i++) {
        vector<bool> tmp(2 * yokosum + 1, false);
        for (ll j = 0; j <= 2 * yokosum; j++) {
            if (yokodp[j]) {
                tmp[j + horizontal[i]] = true;
                if (i != 0) {
                    tmp[j - horizontal[i]] = true;
                }
            }
        }
        yokodp = tmp;
    }
    const ll tatesum = accumulate(vertical.begin(), vertical.end(), 0LL);
    vector<bool> tatedp(2 * tatesum + 1, false);
    tatedp[tatesum] = true;
    for (ll i = 0; i < vertical.size(); i++) {
        vector<bool> tmp(2 * tatesum + 1, false);
        for (ll j = 0; j <= 2 * tatesum; j++) {
            if (tatedp[j]) {
                tmp[j + vertical[i]] = true;
                tmp[j - vertical[i]] = true;
            }
        }
        tatedp = tmp;
    }
    cout << (abs(y) <= tatesum and abs(x) <= yokosum and tatedp[y + tatesum] and yokodp[x + yokosum] ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
     
double getTime() { 
  return clock() / (double) CLOCKS_PER_SEC;
}
     
void read() {};
     
template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}
     
void print() {};
     
template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

int main() {
  int n, k; read(n, k);
  vector <ll> p(n);
  for(int i = 0; i < n; i++) {
    cin >> p[i];
  }
  sort(p.rbegin(), p.rend());
  ll ans = 0;
  for(int i = k; i < n; i++) {
    ans += p[i];
  }
  print(ans);
}

Measured memory_bytes: 1792
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int H = Integer.parseInt(sc.next());
		int W = Integer.parseInt(sc.next());
		String s[][] = new String[H][W];
		int score = 0;
		for(int i = 0; i < H; i++) {
			String temp = sc.next();
			for(int j = 0; j < W; j++) {
				s[i][j] = temp.substring(j, j + 1);
				if(s[i][j].equals(".")) score++;
			}
		}
		int minus = BFS(s, H, W);
		if(minus == 0) {
			System.out.println(-1);
			return;
		}
		System.out.println(score - minus - 1);
	}
	
	public static int BFS(String s[][], int H, int W) {
		int cnt[][] = new int[H][W];
		for(int i = 0; i < H; i++) {
			Arrays.fill(cnt[i], 0);
		}
		Queue<Integer> queue_x = new ArrayDeque<>();
		Queue<Integer> queue_y = new ArrayDeque<>();
		int x = 0;
		int y = 0;
		queue_x.add(x);
		queue_y.add(y);
		cnt[y][x] = 0;
		s[y][x] = "!";
		
		while(queue_x.size() != 0 && queue_y.size() != 0) {
			int dx[] = {0, 1, 0, -1};
			int dy[] = {1, 0, -1, 0};
			x = queue_x.poll();
			y = queue_y.poll();
			
			in : for(int i = 0; i < 4; i++) {
				if(x + dx[i] < 0) continue in;
				if(x + dx[i] >= W) continue in;
				if(y + dy[i] < 0) continue in;
				if(y + dy[i] >= H) continue in;
				
				if(s[y + dy[i]][x + dx[i]].equals(".")) {
					queue_x.add(x + dx[i]);
					queue_y.add(y + dy[i]);
					cnt[y + dy[i]][x + dx[i]] = cnt[y][x] + 1;
					s[y + dy[i]][x + dx[i]] = "!";
				}
			}
		}
		
		return cnt[H - 1][W - 1];
	}
}


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

import sys, re

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 ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S=input()

if re.match(r'^(A?)KIH(A?)B(A?)R(A?)$', S):
    YES()
else:
    NO()


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

int main() {
  int N, A, app = 0;
  cin >> N;

  for ( int i = 0 ; i < N ; i++ ){
    int amari2 = 0, amari3 = 0, amari5 = 0;
    cin >> A;
    amari2 = A % 2;
    amari3 = A % 3;
    amari5 = A % 5;
    if (i != (N -1) && amari2 != 0) continue;
    else if (amari2 == 0 && amari3 != 0 && amari5 != 0) {
        cout << "DENIED" << endl;
        app = 2;
        break;
        }
     else if (amari2 == 0 && (amari3 == 0 || amari5 == 0)) {
          app = 1;
     }
     else if (i == (N - 1) && amari2 != 0 && app == 0) {
       app = 1;
     }
  }
    if (app == 1){
      cout << "APPROVED" << endl; 
        }
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 1000

int main(){
  int i, j, k, v, a_length;
  int A[N];

  scanf("%d", &a_length);

  for(i = 0; i < a_length; i++){
    scanf("%d", &A[i]);
  }

  for(i = 1; i <= a_length; i++){
    v = A[i];
    j = i - 1;
    for(k = 0; k < a_length - 1; k++)
      {
        printf("%d ", A[k]);
      }
    printf("%d", A[k]);
    printf("\n");
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }
  }
  
  return 0;
}



Measured memory_bytes: 2144
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll quick_pow(ll a,ll b){
	ll ans=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1) ans=ans*a%mod;
	return ans;
}
ll n,K,ans=0,op[100005],s[100005],sum[100005];
int top;
int main(){
	scanf("%lld%lld",&n,&K);
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			s[++top]=i;
			if(n!=i*i) s[++top]=n/i;
		}
	}
	sort(s+1,s+top+1);
	for(int i=1;i<=top;i++) sum[i]=quick_pow(K,(s[i]+1)/2);
	for(int i=1;i<=top;i++){
		ll tot=sum[i];
		for(int p=1;p<i;p++) if(s[i]%s[p]==0){
			tot=(tot-sum[p])%mod;
		}
		sum[i]=tot;
		ans=(ans+tot*((s[i]&1)?s[i]:(s[i]>>1)))%mod;
	}
	ans=(ans+mod)%mod;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
from collections import Counter

input = stdin.readline

n = int(input())
if n == 1:
  print(1)
  exit()

xy = [tuple(map(int, input().split())) for _ in range(n)]

l = []
append = l.append
for i in range(n):
  for j in range(n):
    if not i == j:
      append((xy[j][0]-xy[i][0], xy[j][1]-xy[i][1]))
c = Counter(l)
print(n-c.most_common()[0][1])

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

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

  vector<ll> dp(13, 0);
  dp[0] = 1;
  ll mul = 1;

  const ll mod = 1e9 + 7;

  for (ll i = s.length() - 1; i >= 0; i--) {
    vector<ll> next_dp(13, 0);
    for (ll j = 0; j < 13; j++) {
      if (s[i] == '?') {
        for (ll k = 0; k < 10; k++) {
          next_dp[(k * mul + j) % 13] += dp[j];
          next_dp[(k * mul + j) % 13] %= mod;
        }
      }
      else {
        ll k = s[i] - '0';
        next_dp[(k * mul + j) % 13] += dp[j];
        next_dp[(k * mul + j) % 13] %= mod;
      }
    }
    mul = (mul * 10) % 13;
    dp = next_dp;
  }

  cout << dp[5] << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

const int nm = 1e5;
int main(){
    int n; cin >> n;
    int h[nm];
    string ans = "Yes";

    rep(i, n) cin >> h[i];

    for(int i=n-2; i>=0; i--){
        if(h[i]-h[i+1] == 1) h[i]--;
        else if(h[i]-h[i+1] >=2){
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.array;
  
  int n; long c; rd(n, c);
  auto x=new long[](n), v=new long[](n);
  foreach(i; 0..n) rd(x[i], v[i]);

  // import std.exception;
  // enforce(n<=100);

  x=0L~x~c;
  v=0L~v~0L;

  long mx=0, inf=2e18.to!(long);
  mx=max(mx, fun(n, x, v));
  x=x.map!(e=>(c-e)).array;
  reverse(x); reverse(v);
  mx=max(mx, fun(n, x, v));

  long tot=reduce!"a+b"(0L, v);
  for(int i=0; i<=n; i++){
    long cl=x[i], cr=c-x[i+1];
    long cost=cl+cr+min(cl, cr);
    mx=max(mx, tot-cost);
  }
  writeln(mx);
}

long fun(int n, long[] d, long[] v){ // 0->l->0->r (l<r) distance : l*2+r
  import std.algorithm;
  auto best=new long[](n+2); // [i, $)
  fill(best, -2_000_000_000_000_000_000);
  best[n+1]=0;
  for(auto r=n, s=0L; r>0; r--){
    s+=v[r];
    best[r]=max(best[r+1], s-(d[$-1]-d[r]));
  }
  long ret=0;
  for(auto l=0, s=0L; l<=n; l++){
    s+=v[l];
    ret=max(ret, (s-d[l]*2)+best[l+1]);
  }
  return ret;
}

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));
}


Measured memory_bytes: 8700
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=1000000000;
const int MOD=1000000007;

int main()
{
 ll n, k;
 cin >> n >> k;
 cout << min(n%k,k-n%k);
  return 0;
}

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

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[] arr = new int[n];
        int sum = 0;

        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            sum += arr[i];
        }
        Arrays.sort(arr);

        boolean works = true;
        for (int i = n - 1; i > (n-1)-m; i--) {
            if (arr[i] < 1.0 * sum / 4 / m) {
                works = false;
            }
        }
        System.out.println(works ? "Yes" : "No");

    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,a;
  int o=0;
  cin >> s >> a;
  for(int i=0;i<s.length();i++){
  if(s[i]!=a[i]) {o++;}
  }
  cout << o;
return 0;
}

Measured memory_bytes: 3840
import sys
readline = sys.stdin.readline
from math import floor, ceil
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

def round(f, r=0):
    return Decimal(str(f)).quantize(Decimal(str(r)), rounding=ROUND_HALF_UP)

def main():
    H, W = map(int, readline().rstrip().split())
    ans = H * W
    if H >= 3:
        y1 = int(round(H/3))
        y2 = (H-y1) // 2
        y3 = H - y1 - y2
        ans = min(ans, max(W*y1, W*y2, W*y3)-min(W*y1, W*y2, W*y3))
    if W >= 3:
        x1 = int(round(W/3))
        x2 = (W-x1) // 2
        x3 = W - x1 - x2
        ans = min(ans, max(x1*H, x2*H, x3*H)-min(x1*H, x2*H, x3*H))
    
    # 縦にスライス + 残りに横にスライス
    x1_cand = [int(round(W/3))]
    y1 = H
    for x1 in x1_cand:
        x2 = W - x1
        x3 = x2
        y2 = H // 2
        y3 = H - y2
        ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))

    # 横にスライス + 残りに縦にスライス
    y1_cand = [int(round(H/3))]
    x1 = W
    for y1 in y1_cand:
        y2 = H - y1
        y3 = y2
        x2 = W // 2
        x3 = W - x2
        ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))

    print(ans)

if __name__ == '__main__':
    main()

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

const int N = 3e3 + 3;

int n,a[N];

long long dp[N][N];

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
    	cin >> a[i];	
    }
    for(int l = n; l >= 1; l--){
    	for(int r = l; r <= n; r++){
    		if(l == r)
    			dp[l][r] = a[l];
    		else
    			dp[l][r] = max(a[l] - dp[l + 1][r],a[r] - dp[l][r - 1]);
    	}
    }
    cout << dp[1][n];
	return 0;
}

Measured memory_bytes: 70016
n,m=map(int,input().split())
ac=[0]*(n+1)
wa=[0]*(n+1)
for i in range(m):
  p,s=input().split()
  if ac[int(p)]!=1:
    if s=='WA':
      wa[int(p)]=wa[int(p)]+1
    else:
      ac[int(p)]=1
for i in range(n+1):
  if ac[i]==0:
    wa[i]=0
print(sum(ac),sum(wa))

Measured memory_bytes: 4596
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

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


    cout << (1-x) << endl;

    return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  string s; cin >> s;
  ll N = s.size();

  ll cnt = 0;
  rep(i,N){
    if(s[i] == '?'){
      s[i] = 'D';
    }
  }
  cout << s << endl;
}


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


MOD=10**9+7
def mod(a):
    return a%MOD

x,y=map(int,input().split())

if((x+y)%3!=0):
    print(0)  
    exit()
n=(x+y)/3
x-=n
y-=n
if x<0 or y<0:
    print(0) 
    exit()

def po(a,b):
    if(b==0):return 1
    if(b==1):return mod(a)
    if(b%2==0):return mod(po(mod(a*a),b/2))
    return mod(po(a,b-1)*a)
    
def bunbo(a):
    return po(a,MOD-2)
    
def comb(a,b):
    res=kai[a]
    res=mod(res*bunbo(kai[b]))
    res=mod(res*bunbo(kai[a-b]))
    return res
    
N=(10**6)*2+5
#N=100
kai=[0]*N

kai[0]=1
for i in range(1,N-1):
    kai[i]=mod(kai[i-1]*i)

#print(kai)
print(comb(int(x+y),int(x)))
"""
for i in range(8):
    for j in range(i):
        print(comb(i,j),end=" ")
    print()
"""

Measured memory_bytes: 82164
x, y = map(int, input().split())
PRIME = 10 ** 9 + 7
if (x + y) % 3 == 0:
    n = (x + y) // 3
    if x >= n and y >= n:
        up = 2 * n - x
        factorial = 1
        for i in range(1, n + 1):
            factorial *= i
            factorial %= PRIME
        inv = pow(factorial, PRIME - 2, PRIME)
        invs = [1 for _ in range(n + 1)]
        invs[n] = inv
        for i in range(n, min(n - up, up), -1):
            inv *= i
            inv %= PRIME
            invs[i - 1] = inv
        print((factorial * invs[n - up] * invs[up]) % PRIME)
    else:
        print(0)
else:
    print(0)

Measured memory_bytes: 20888
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
    int N;
    std::cin >> N;
    std::vector<std::pair<std::pair<int, int>, int>> xyh(N);  // N<=100
    for (int i = 0; i < N; ++i) {
        int x, y, h;
        std::cin >> x >> y >> h;
        xyh.at(i) = std::make_pair(std::make_pair(x, y), h);
    }
    std::sort(xyh.begin(), xyh.end(),
              [](const std::pair<std::pair<int, int>, int>& p1,
                 const std::pair<std::pair<int, int>, int>& p2) {
                  return p1.second < p2.second;
              });

    for (int Cx = 0; Cx <= 100; ++Cx) {
        for (int Cy = 0; Cy <= 100; ++Cy) {
            int x         = xyh.at(N - 1).first.first;
            int y         = xyh.at(N - 1).first.second;
            int h         = xyh.at(N - 1).second;           // h!=0
            int H         = h + abs(x - Cx) + abs(y - Cy);  // H <= 1e9+200
            bool isCenter = true;
            for (int i = 0; i < N - 1; ++i) {
                x = xyh.at(i).first.first;
                y = xyh.at(i).first.second;
                h = xyh.at(i).second;
                if (h != std::max(H - abs(x - Cx) - abs(y - Cy), 0)) {
                    isCenter = false;
                    break;
                }
            }
            if (isCenter) {
                std::cout << Cx << ' ' << Cy << ' ' << H << '\n';
                return 0;
            }
        }
    }

    return 1;
}

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

typedef double Real;
typedef complex<Real> Point;
typedef pair<Point,Point> Line;

const Real EPS=1e-10;


inline Point vec(const Line& a){
    return a.second-a.first;
}

Real dot(Point a,Point b){
    return (conj(a)*b).real();
}

Real cross(Point a,Point b){
    return (conj(a)*b).imag();
}

inline int sgn(Real a,Real b=0){
    return a < b - EPS ? -1 : a > b + EPS ? 1 : 0;
}

inline bool near(Point a,Point b){
    return !sgn(abs(a-b));
}

inline bool is_orthogonal(Line la,Line lb){
    return !sgn(dot(vec(la),vec(lb)));
}

inline bool is_parallel(Line la,Line lb){
    return !sgn(cross(vec(la),vec(lb)));
}

inline bool is_intersected_line(Line la,Line lb){
    return !is_parallel(la,lb);
}

inline Real arg(const Point& base,const Point& a,const Point& b){
    return arg((b-base)/(a-base));
}

inline Real sr(Real a){
    return sqrt(max(a,(Real)0));
}

inline Real dist(Point a,Point b){
    return abs(a-b);
}

inline Real length(Point a){
    return abs(a);
}

inline Point unit_vector(Point a){
    return a / abs(a);
}


Point rotate(Point x,Real rad){
    return Point(x.real()*cos(rad)-x.imag()*sin(rad),x.real()*sin(rad)+x.imag()*cos(rad));
}                             



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

    int n;
    Point A[4];

    cin>>n;
    for(int i=0;i<n;i++){
        for(auto &t:A){
            double x,y;
            cin>>x>>y;
            t=Point(x,y);
        }

        Line la=make_pair(A[0],A[1]),lb=make_pair(A[2],A[3]);

        cout << (is_parallel(la,lb) ? "YES" : "NO") << endl;
    }

    return 0;
}

Measured memory_bytes: 1236
#include<iostream>
using namespace std;
int main()
{
	int A[4][3][10] = { 0 };
	int n;
	cin >> n;
	for (int nn=0; nn<n; nn++)
	{
		int b;
		int f;
		int r;
		int v;
		cin >> b >> f >> r >> v;
		A[b-1][f-1][r-1] += v;
	}
	for (int bb = 0; bb <4; bb++)
	{
		for (int ff = 0; ff<3; ff++)
		{
			for (int rr = 0; rr < 10; rr++)
			{
				cout << " ";
				cout << A[bb][ff][rr];
			}
			cout << endl;
		}
		if (bb!=3){ cout << "####################"<<endl; }
	}
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <fstream>
#include <set>
#include <cmath>
#include <array>
#include <iomanip>
#include <cassert>

using namespace std;

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

    int n, k;
    cin >> n >> k;

    std::vector<long long> sums(n);
    std::vector<long long> pos(n);

    for (int i = 0; i < n; i++) {
        long long x;
        cin >> x;
        sums[i] = x + (i > 0 ? sums[i - 1] : 0LL);
        pos[i] = max(x, 0LL) + (i > 0 ? pos[i - 1]: 0LL);
    }

    auto get_value = [&](std::vector<long long>& v, int l, int r) {
        if (l == 0) {
            return v[r];
        }
        return v[r] - v[l - 1];
    };

    long long answer = 0;
    for (int i = 0; i < n; i++) {
        if (i >= k - 1) {
            auto pos_sum = get_value(pos, i - k + 1, i);
            auto sum_sum = get_value(sums, i - k + 1, i);

            answer = max(answer, pos.back() - pos_sum + max(sum_sum, 0LL));
        }
    }
    cout << answer << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int top,S[1000];

int push(int x){
  S[++top]=x;
}
int pop(){
  top--;
  return S[top+1];
}

int main(){
  int a,b;
  top = 0;
  char s[100];
  while(scanf("%s",s)!=EOF){
    if(s[0] == '+'){
      a = pop();
      b = pop();
      push(a+b);
    } else if(s[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    }else if(s[0]=='*'){
      a = pop();
      b = pop();
      push(a*b);
    }else{
      push(atoi(s));
    }
  }
  printf("%d\n",pop());
return 0;
}




Measured memory_bytes: 2128
/*16D8103008D 西村　悠輝　ALDS10C*/

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

string X, Y;
int v[1001][1001];

int  dp(string X, string Y) {
	int n = X.size();
	int m = Y.size();

	
	for (int i = 0; i <= n; i++) {
		v[i][0] = i;											///０のテーブル
		for (int j = 0; j <= m; j++) {
			v[0][j] = j;
		}
	}
	

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (X[i-1] == Y[j-1]) {

				v[i][j]= v[i-1][j-1];
			}
			else {
				int y = min(v[i][j - 1] + 1, v[i - 1][j] + 1);
				if (y > v[i - 1][j - 1] + 1) {
					v[i][j] = v[i - 1][j - 1] + 1;
				}else{
					v[i][j] = y;
				}
			}
		}
	}
	return v[n][m];
}

int main(void)
{
	
	cin >> X >> Y;
	int ans = dp(X, Y);
	cout << ans << endl;
	
	
}
/*
acac
acm
2
*/


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

int main()
{
	long long int n,sum=0;
	vector<vector<long long  int > > gcde(201,vector<long long  int >(201,0));
	cin>>n;
	for(long long int i=1;i<=n;i++)
	{
		gcde[i][1]=1;
	}
	for(long long int i=1;i<=n;i++)
	{
		gcde[1][i]=1;
	}
	
	for(long long int i=1;i<=n;i++)
	{
		if(i==1)
		{
			sum += n*n;
			continue;
		}
		for(long long int j=1;j<=n;j++)
		{
			if(j==1)
			{
				sum += n;
				continue;
			}
			for(long long int k=1;k<=n;k++)
			{
				if(k==1)
				{
					sum++;
				}
				else{
					if(gcde[j][k] == 0)
					{
						gcde[j][k]= __gcd(j,k);
					}
					sum = sum + gcde[i][gcde[j][k]];
				}
			}
		}
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 3952
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N;

int main() {
  cin >> N;
  if (N % 2 == 0) {
    cout << N;
  } else {
    cout << N * 2;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 1e9 + 7;
vector<pair<int,int> >g[maxn];
int ans[maxn];
int mx;
void dfs(int now,int pre,int c){
    int cur = 1;
    for(auto i:g[now]){
        if(i.F == pre){
            continue;
        }
        if(cur == c){
            cur++;
        }
        ans[i.S] = cur;
        mx = max(mx,cur);
        dfs(i.F,now,cur++);
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    n--;
    f(n){
        int add1, add2;
        cin >> add1 >> add2;
        g[add1].pb({add2,i});
        g[add2].pb({add1,i});
    }
    dfs(1,0,0);
    cout << mx << '\n';
    f(n){
        cout << ans[i] << '\n';
    }
}

Measured memory_bytes: 13952
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a+b+c>=22)
    {
        printf("bust");
    }
    else
        printf("win");
  //ug02-50-19-0025
    return 0;



}


Measured memory_bytes: 128
// Original macro is in https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = || -> String {
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// for adhoc read (ex. https://atcoder.jp/contests/abc112/tasks/abc112_a)
#[allow(dead_code)]
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    input!{ mut n: i32 }
    if n == 0 {
        println!("{}", 0);
    } else {
        let mut ans = String::from("");
        while n != 0 {
            let r = if n%2 == 0 { 0 } else { 1 };
            ans = format!("{}{}", r, ans);
            n -= r;
            n /= -2;
        }
        println!("{}", ans);
    }
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
long long int n, idx, i, j, k, ans,curr;
void rec(long long int num)
{
    if(num > n)
        return;
    long long int temp = num;
    int valid = 0;
    int cek[10];
    memset(cek,0,sizeof(cek));
    while(temp > 0)
    {
        cek[temp%10] = 1;
        temp/=10;
    }
    if(cek[3] == 1 && cek[5] == 1 && cek[7] == 1)
        valid = 1;
    if(num <= n && valid == 1)
    {
        ans++;
    }
    rec(num*10+3);
    rec(num*10+5);
    rec(num*10+7);
}
int main()
{
    ans = 0;
    scanf("%lld",&n);;
    rec(3);
    rec(5);
    rec(7);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int n; cin >> n;
	int h, max = 0, ans = 0;
	for (int i = 0; i < n; ++i) {
		cin >> h;
		if (max <= h) {
			ans++;
			max = h;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

input = raw_input()
num_input = int(input)
if num_input < 1000:
    input = '%03d' % num_input
    output = "ABC"
else:
    input ='%03d' % (num_input - 999)
    output = "ABD"

print output

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

long long n,k,pot;

int main(){

	cin>>n;
	
	k=n;
	pot=1;
	
	while(k%2==0){
        k/=2;
        pot*=2;
    }
	
	if(n<=2 || k==1)cout<<"No\n";
	else{
	    
	    cout<<"Yes\n";
	    
	    cout<<n+1<<" 3"<<endl;
	    
	    for(int i=3;i<=n;i+=2){
	        cout<<i-1<<" "<<1<<endl;
	        cout<<i<<" "<<i-1<<endl;
	        cout<<n+i<<" "<<1<<endl;
	        cout<<n+i-1<<" "<<n+i<<endl;
        }
        
        if(n%2==0){
            cout<<n+pot+1<<" "<<n<<endl;
            cout<<2*n<<" "<<(n^pot)<<endl;
	    }
	   
    }

return 0;
}


Measured memory_bytes: 2304
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author emli
 */


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

typedef long long ll;
class BMagic2 {
public:
    void solve(std::istream& cin, std::ostream& cout) {
		ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int a,b,c,k;
        cin >> a >> b >> c >> k;


        for(int i = 0; i <= 999; i++){
            int x = i;
            int d3 = x % 10; x = x / 10;
            int d2 = x % 10; x = x / 10;
            int d1 = x % 10;

            if (d3 + d2 + d1 > k){
                continue;
            }
            int a1 = a;
            int b1 = b;
            int c1 = c;

            while (d1 > 0){
                a1 *= 2;
                d1--;
            }
            while (d2 > 0){
                b1 *= 2;
                d2--;
            }
            while (d3 > 0){
                c1 *= 2;
                d3--;
            }
            if (c1 > b1 && b1 > a1){
                cout << "Yes" << endl;
                return;
            }
        }

        cout << "No" << endl;

	}
};


int main() {
	BMagic2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3648
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let a: i64 = input();
    let b: i64 = input();
    let c: i64 = input();
    let d: i64 = input();
    println!(
        "{}",
        std::cmp::max(0, std::cmp::min(b, d) - std::cmp::max(a, c))
    );
}


Measured memory_bytes: 4352
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
using ld = long double;
 
// ------------------------------------------------------------------------------------------------

string w;
vll p;

int main() {
    fast_io; cout_precision;
    cin >> w;
    p.assign(26, 0);
    for (ll i = 0; i < (ll) w.length(); i++) {
        p[w[i] - 'a'] ^= 1;
    }
    for (ll i = 0; i < (ll) w.length(); i++) {
        if (p[w[i] - 'a']) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
//2019/3/15
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		int ans = 0;

		char c;

		int[] array = new int[2];

		for(int i=0;i<s.length();i++) {

			c = s.charAt(i);

			if(c=='0') array[0]++;

			else if(c=='1') array[1]++;

			if(array[0]!=0 && array[1]!=0) {

				array[0]--;

				array[1]--;

				ans += 2;
			}
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 26676
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;

int main(){
    int r;
    cin >> r;
    if(r<1200) puts("ABC");
    else if(r<2800) puts("ARC");
    else puts("AGC"); 
    return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def LI(): return list(map(int, stdin.readline().split()))
def LS(): return list(stdin.readline())

n = int(input())
a = sorted(LI())
ans = 0
for i in range(1, n):
    ans += a[n-1-(i//2)]
print(ans)

Measured memory_bytes: 31412
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

ans = 0
n.times{|i|
  if a[i]<=b[i]
    b[i] -= a[i]
    ans += a[i]
    a[i] = 0
  else
    a[i] -= b[i]
    ans += b[i]
    b[i] = 0
  end
  
  if a[i+1]<=b[i]
    b[i] -= a[i+1]
    ans += a[i+1]
    a[i+1] = 0
  else
    a[i+1] -= b[i]
    ans += b[i]
    b[i] = 0
  end
}

p ans

Measured memory_bytes: 15388
n = gets.chomp.to_i
t = gets.split.map(&:to_i)
m = gets.chomp.to_i
pxs = []
m.times do
  pxs.push gets.split.map(&:to_i)
end
pxs.each do |px|
  tt = t.dup
  tt[px.first - 1] = px.last
  puts tt.reduce(:+)
end


Measured memory_bytes: 1788
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main(){
    int n,max = -1000000,min = 1000000,a;
    double sum = 0;
    
    cin >> n;
    
    for(int i = 0;i < n;i++){
        cin >> a;
        sum += (double)a;
        
        if(a > max)
            max = a;
        if(a < min)
            min = a;
    }
    
    printf("%d %d %.0f\n",min,max,sum);
    
    return 0;

}



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

int main(){
    int n;
    cin >> n;
    if(n<4){
        cout << 0 << endl;
        return 0;
    }else{
        if(n % 2 == 0){
            cout << (n/2)-1 << endl;
            return 0;
        }else{
            cout << n/2 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>

using namespace std;
using PII = pair<int, int>;

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

	map<int, int> nums;
	int tmp = 0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		nums[a]++;
	}

	bool ok = false;
	if (nums.size() > 3) {
		ok = false;
	} else if (nums.size() == 1) {
		// 全部0
		ok = nums.count(0) > 0;
	} else if (n % 3 != 0) {
		ok = false;
	} else {
		vector<PII> v(nums.begin(), nums.end());
		if (v.size() == 2) {
			ok = 2 * v[0].second == v[1].second || v[0].second == 2 * v[1].second;
		} else if (v.size() == 3) {
			ok = (v[0].first ^ v[1].first ^ v[2].first) == 0 &&
				v[0].second == n / 3 &&
				v[1].second == n / 3 &&
				v[2].second == n / 3;
		} else {
			// ここにはこないはず
			ok = false;
			cerr << "来ないはずなのに来ちゃった" << endl;
		}
	}

	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 3840
#include <stdio.h>
#include <string.h>

int main()
{
	int room[16][9];
	int n;
	int s, t, b;
	char buf[16];

	while (scanf("%d", &n), n){
		scanf(" %[^\n]", buf);
		s = buf[0] - 'A';
		t = buf[2] - 'A';
		b = buf[4] - 'A';

		memset(room, 0, sizeof(room));
		room[0][s] = 1;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < 9; j++){
				if (room[i][j]){
					if ((j % 3) + 1 <= 2 && j + 1 != b) {
						room[i + 1][j + 1] += room[i][j];
					}
					else {
						room[i + 1][j] += room[i][j];
					}
					if ((j % 3) - 1 >= 0 && j - 1 != b) {
						room[i + 1][j - 1] += room[i][j];
					}
					else {
						room[i + 1][j] += room[i][j];
					}

					if (j / 3 + 1 <= 2 && j + 3 != b){
						room[i + 1][j + 3] += room[i][j];
					}
					else {
						room[i + 1][j] += room[i][j];
					}

					if (j / 3 - 1 >= 0 && j - 3 != b){
						room[i + 1][j - 3] += room[i][j];
					}
					else {
						room[i + 1][j] += room[i][j];
					}
				}
			}
		}

		int total_pattern = 0;
		for (int i = 0; i < 9; i++){
			total_pattern += room[n][i];
		}

		printf("%.8lf\n", (double)room[n][t] / total_pattern);
	}

	return (0);
}

Measured memory_bytes: 1068
N=gets.to_i

points=N.times.map{gets.split.map(&:to_i)}

diffs=Hash.new(0)
N.times do |i|
  N.times do |j|
    next if i==j
    str="#{points[i][0]-points[j][0]},#{points[i][1]-points[j][1]}"
    diffs[str]+=1
  end
end
max=0
diffs.each do |str,i|
  max=[max,i].max
end
puts N-max

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

int main() {
    int n;
    cin >> n;
    vector<int> perm(n);
    rep(i,n) perm[i] = i+1;
    vector<int> p(n);
    vector<int> q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    int a = 0;
    int b = 0;
    int ct = 0;
    do {
        bool ok_p = true;
        rep(i,n) {
            if (p[i] != perm[i]) ok_p = false;
        }
        if (ok_p) a = ct;
        bool ok_q = true;
        rep(i,n) {
            if (q[i] != perm[i]) ok_q = false;
        }
        if (ok_q) b = ct;
        ct++;
    } while (next_permutation(perm.begin(),perm.end()));
    cout << abs(a-b) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
    while(1){
 
        int h,w;
 
        cin >> h >> w;
 
        int diagonal = h*h + w*w;
 
        if(h==0 && w==0) break;
 
        pair<int,int> ans = make_pair(500,500); //first = h , second = w
 
        for(int i=1; i<151; i++){
            for(int j=i+1; j<151; j++){
 
                int check_rect_diagonal = i*i + j*j;
 
                if(diagonal < check_rect_diagonal || (diagonal == check_rect_diagonal && h < i)){
 
                    int ans_h = ans.first;
                    int ans_w = ans.second;
 
                    int ans_rect_diagonal = ans_h*ans_h + ans_w*ans_w;
 
                    if(check_rect_diagonal < ans_rect_diagonal || (check_rect_diagonal == ans_rect_diagonal && i < ans_h )){
                        ans = make_pair(i,j);
                    }
 
 
 
                }
            }
        }
 
        cout << ans.first << " " << ans.second << endl;
 
 
 
 
    }
 
 
 
    return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if((a<=9 && a>=1 )&& (b<=9 && b>=1))
        cout<<a*b<<endl;
    else
        cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	xlist := make([]int, n)

	for i := 0; i < n; i++ {
		xlist[i] = nextInt()
	}

	tailist := make([]int, 101)
	for p := 0; p < 101; p++ {

		tai := 0
		for i := 0; i < n; i++ {
			//fmt.Println(tai, (xlist[i] - p))
			tai += (xlist[i] - p) * (xlist[i] - p)
		}

		tailist[p] = tai
	}

	sort.Ints(tailist)

	fmt.Println(tailist[0])

}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int minv = Integer.MAX_VALUE;
		int maxv = Integer.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			int j = Integer.parseInt(reader.readLine());
			maxv = Math.max(maxv, j-minv);
			minv = Math.min(minv, j);
		}
		System.out.println(maxv);
	}
}

Measured memory_bytes: 37776
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;
#define FIN freopen("in.txt", "r", stdin);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string op;
    cin >> op;
    int l = 0;
    for(int i = 0; i < op.size(); i++)
    {
        if(op[i] == ',')
        {
            op[i] = ' ';
        }
    }
    cout << op << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1'000'000'007;
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

// 0-indexed
struct TopologicalSort {
    int n;
    vector<set<int>> G;
    vector<bool> used;
    vector<int> indeg, p;

    TopologicalSort(int size) : n(size), G(n), used(n), indeg(n), p(0) {}

    void addEdge(int s, int t) {
        G[s].insert(t);
    }
    void bfs(int s) {
        queue<int> q;
        q.push(s);
        used[s] = 1;
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            p.push_back(v);
            for (int u : G[v]) {
                indeg[u]--;
                if (indeg[u] == 0 && !used[u]) {
                    used[u] = 1;
                    q.push(u);
                }
            }
        }
    }
    // returns topologically sorted nodes
    vector<int> build() {
        fill(used.begin(), used.end(), 0);
        fill(indeg.begin(), indeg.end(), 0);
        for (int i = 0; i < n; ++i) {
            for (int v : G[i])
                indeg[v]++;
        }
        for (int i = 0; i < n; ++i) {
            if (indeg[i] == 0 && !used[i])
                bfs(i);
        }
        return p;
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    vi x(M), y(M);
    vector<vector<int>> in(N);
    TopologicalSort tp(N);
    for (int i = 0; i < M; ++i) {
        cin >> x[i] >> y[i];
        in[y[i] - 1].push_back(x[i] - 1);
        tp.addEdge(x[i] - 1, y[i] - 1);
    }
    vi p = tp.build();
    vi dp(N, 0);
    for (int pp : p) {
        int max = 0;
        for (int from : in[pp]) {
            chmax(max, dp[from] + 1);
        }
        dp[pp] = max;
    }
    int ret = 0;
    for (int i = 0; i < N; ++i) {
        chmax(ret, dp[i]);
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 17536