akhauriyash/Code-Regression huggingface dataset:
module DoublyChainedTree = struct
  let nil = -1

  type t = {
    mutable parent : int;
    mutable child : int;
    mutable bro : int;
    mutable depth : int;
  }

  let make () = { parent = nil; child = nil; bro = nil; depth = nil }
end

module T = DoublyChainedTree

let () =
  let n = Scanf.scanf "%d " (fun i -> i) in
  let t = Array.init n (fun _ -> T.make ()) in
  Array.iteri (fun i _ ->
    let id, k = Scanf.scanf "%d %d " (fun id k -> id, k) in
    let rec read_node j left_child =
      if j < k then begin
        let c = Scanf.scanf "%d " (fun c -> c) in
        t.(c).T.parent <- id;
        if j = 0 then t.(id).T.child <- c else t.(left_child).T.bro <- c;
        read_node (j + 1) c
      end
    in
    read_node 0 0
  ) t;
  let rec search_root i =
    if i = n then T.nil
    else if t.(i).T.parent = T.nil then i
    else search_root (i + 1)
  in
  let root = search_root 0 in
  let rec set_depth i d =
    t.(i).T.depth <- d;
    if t.(i).T.bro <> T.nil then set_depth t.(i).T.bro d;
    if t.(i).T.child <> T.nil then set_depth t.(i).T.child (d + 1);
  in
  set_depth root 0;
  let print i =
    print_string "node "; print_int i;
    print_string ": parent = "; print_int t.(i).T.parent;
    print_string ", depth = "; print_int t.(i).T.depth;
    print_string (if t.(i).T.parent = T.nil then ", root, " else if t.(i).T.child = T.nil then ", leaf, " else ", internal node, ");
    print_string "[";
    let rec print_children c =
      if c <> T.nil then begin
        if c <> t.(i).T.child then print_string ", ";
        print_int c;
        print_children t.(c).T.bro
      end
    in
    print_children t.(i).T.child;
    print_endline "]"
  in
  Array.iteri (fun i _ -> print i) t

Measured memory_bytes: 13232
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var s string
	fmt.Scan(&s)

	min := 1000
	for i := 0; i < len(s)-2; i++ {
		now := string(s[i]) + string(s[i+1]) + string(s[i+2])
		nowNum, _ := strconv.Atoi(now)
		absNow := nowNum - 753
		if absNow < 0 {
			absNow *= -1
		}
		if min > absNow {
			min = absNow
		}
	}
	fmt.Println(min)

}


Measured memory_bytes: 512
from functools import reduce
memo = {}
def gcd(a, b):
  x, y = a, b = (a, b) if a >= b else (b, a)
  if (a, b) in memo:
    return memo[(a, b)]
  while b > 0:
    a, b = b, a % b
  memo[(x, y)] = a
  return a

N, X = map(int, input().split())
xs = list(map(int, input().split()))

xs.append(X)
m = min(xs)
arr = [x - m for x in xs]
print(reduce(gcd, arr))

Measured memory_bytes: 27800
LARGE = 10 ** 9 + 7


def solve_a(test=False, a=2, b=16):

    if not test:
        a, b = map(int, input().split())
    if (b - a) % 2 == 0:
        print((a + b) // 2)
    else:
        print("IMPOSSIBLE")


def solve_b(test=False, n=5, p_list=[5, 2, 3, 4, 1]):

    if not test:
        n = int(input())
        p_list = list(map(int, input().split()))

    r = 0
    for i in range(n):
        if p_list[i] != i + 1:
            r += 1
    if r == 0 or r == 2:
        print("YES")
    else:
        print("NO")


def solve_c(test=False, n=2, a_list=[3, 5, 2], b_list=[4, 5]):

    if not test:
        n = int(input())
        a_list = list(map(int, input().split()))
        b_list = list(map(int, input().split()))

    res = 0
    for i in range(n):
        if b_list[i] <= a_list[i]:
            res += b_list[i]
            a_list[i] -= b_list[i]
        elif b_list[i] < a_list[i] + a_list[i + 1]:
            res += b_list[i]
            a_list[i + 1] -= b_list[i] - a_list[i]
            a_list[i] = 0
        else:
            res += a_list[i] + a_list[i + 1]
            a_list[i] = 0
            a_list[i + 1] = 0

    print(res)


def solve_d(test=False, s='??2??5'):

    if not test:
        s = input()

    l = len(s)
    res_list_new = [0] * 13
    res_list_old = [0] * 13
    zero_mod = int(s.replace('?', '0')) % 13
    res_list_new[zero_mod] += 1

    for i in range(1, l + 1):
        if s[-i] == '?':
            for k in range(13):
                res_list_old[k] = res_list_new[k] % LARGE
            base_mod = pow(10, i-1, 13)
            for j in range(1, 10):
                for k in range(13):
                    res_list_new[(k + base_mod * j) % 13] += res_list_old[k]

    print(res_list_new[5] % LARGE)


# solve_a(test=True, a=2, b=16)
# solve_a(test=True, a=0, b=3)
# solve_a(test=True, a=998244353, b=99824435)

# solve_b(test=True, n=5, p_list=[5, 2, 3, 4, 1])
# solve_b(test=True, n=5, p_list=[2, 4, 3, 5, 1])
# solve_b(test=True, n=7, p_list=[1, 2, 3, 4, 5, 6, 7])

# solve_c(test=True, n=2, a_list=[3, 5, 2], b_list=[4, 5])
# solve_c(test=True, n=3, a_list=[5, 6, 3, 8], b_list=[5, 100, 8])
# solve_c(test=True, n=2, a_list=[100, 1, 1], b_list=[1, 100])

# solve_d(test=True, s='??2??5')
# solve_d(test=True, s='?44')
# solve_d(test=True, s='7?4')
# solve_d(test=True, s='?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???')

solve_d()


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


ll t[200001];
int main(){
  ll ans = 0;
  ll n,T;
  cin>>n>>T;

  for(int i=0;i<n;i++)cin>>t[i];
  
  for(int i=1;i<n;i++){
    if(t[i] - t[i-1]>=T)ans+=T;
    else ans +=t[i] - t[i-1];
  }
  cout<<ans+T<<endl;

  return 0;
}


Measured memory_bytes: 1792
def prime_t(t):
    i=2
    while i**2<=t:
        if t%i==0:
            return 0
        i+=1
    return 1

def prime_list(tt):
    p_list=[]
    for i in range(2,tt+1):
        if prime_t(i):
            p_list.append(i)
    return p_list

l=prime_list(201)

d={}

n=int(input())
chk=tmp=1
ans=0

for p in range(3,n+1,2):
    for i in l:
        chk=1
        while p%i==0:
            p//=i
            chk+=1
        tmp*=chk
    if tmp==8:
        ans+=1
    tmp=1
print(ans)

Measured memory_bytes: 3064
using System;
class Program
{
	static void Main()
	{
	string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
	int h = int.Parse(input[0]);
	int w = int.Parse(input[1]);
  int[,] matrix = new int [h,w];//行列
  
  for(int i = 0; i < h; i++)
    {
      int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
      for(int j = 0; j < w; j++)matrix[i,j] = nums[j];
    }

  int moveTime = 0;

  int pickUp = 0;//持っている時１

  for(int i = 0; i < h; i++)//全部の行を調べる
    {
    if(i % 2 == 0)//偶数行の時
      {
      for(int j = 0; j < w; j++)//全部の列を調べる
        {
        if(matrix[i,j] % 2 == 1)
          {
          if(pickUp == 1)pickUp = 0;
          else pickUp = 1;
          }
        if(pickUp == 1)
          {
          if(j+1 < w) moveTime++;
          else if(i+1 < h) moveTime++;
          }

        }

      }

      if(i % 2 == 1)//奇数行の時
        {
        for(int j = w-1; j >= 0; j--)//全部の列を調べる
          {
          if(matrix[i,j] % 2 == 1)
            {
            if(pickUp == 1)pickUp = 0;
            else pickUp = 1;
            }
          if(pickUp == 1)
            {
            if(j-1 >= 0) moveTime++;
            else if(i+1 < h) moveTime++;
            }

          }

        }

	  }

    Console.WriteLine(moveTime);
    pickUp = 0;

    for(int i = 0; i < h; i++)//全部の行を再び調べる
      {
      if(i % 2 == 0)//偶数行の時
        {
        for(int j = 0; j < w; j++)//全部の列を調べる
          {
          if(matrix[i,j] % 2 == 1)
            {
            if(pickUp == 1)pickUp = 0;
            else pickUp = 1;
            }
          if(pickUp == 1)
            {
            if(j+1 < w) Console.WriteLine(((int)i+1) + " " + ((int)j+1) + " " + ((int)i+1) + " " + ((int)j+2));
            else if(i+1 < h) Console.WriteLine(((int)i+1) + " " + ((int)j+1) + " " + ((int)i+2) + " " + ((int)j+1));
            }

          }

        }

        if(i % 2 == 1)//奇数行の時
          {
          for(int j = w-1; j >= 0; j--)//全部の列を調べる
            {
            if(matrix[i,j] % 2 == 1)
              {
              if(pickUp == 1)pickUp = 0;
              else pickUp = 1;
              }
            if(pickUp == 1)
              {
              if(j-1 >= 0) Console.WriteLine(((int)i+1) + " " + ((int)j+1) + " " + ((int)i+1) + " " + j);
              else if(i+1 < h) Console.WriteLine(((int)i+1) + " " + ((int)j+1) + " " + ((int)i+2) + " " + ((int)j+1));
              }

            }

          }

  	  }
    
  }
}

Measured memory_bytes: 17944
#include <stdio.h>
#include <stdlib.h>
int main()
{
    char s[10000];
    int a,b,i,j;
    while(~scanf("%d %d",&a,&b))
    {
         for(i=0;i<a;i++)
         {
             scanf("%s",s);
             printf("%s\n",s);
             printf("%s\n",s);
         }
    }
    return 0;
}


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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pull pair<ull, ull>
#define m_p make_pair

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, m;;
	cin >> n >> m;
	
	int x=0, y=0;
	if(n > 1){
		x = (n*(n-1)) / 2;
	}
	if(m > 1){
		y = (m*(m-1)) / 2;
	}
	
	cout << x + y;
}


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

// #define ANS  //for answer
#define CMP  //for compe

#define REP(i, n) for (int i = 0; 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 INF 2e9
#define ALL(v) v.begin(), v.end()
#define nv(x) #x,(x)
#define ncv(x) #x,":",(x)
#define ncvc(x) #x,":",(x),","
using ll = long long;
void pPRINT(std::ostream& ost) {}
template <class T, class... U>void pPRINT(std::ostream& ost,const T t,const U... u) {ost<<t<<" ";pPRINT(ost, u...);}
template <class... T>void PRINT(const T... t) {pPRINT(std::cout, t...);}
template <class... T>void PRINTl(const T... t){pPRINT(std::cout,t...);std::cout<<"\n";}
template <class T>void PRINTa(const T* const t,const ll size){REP(i,size)PRINT(t[i]);PRINTl();}
template <class T>void PRINTal(const T* const t,const ll size){REP(i,size)PRINTl(i,":",t[i]);}
#ifdef CMP
using namespace std;
#else
#endif
#ifndef DBG
#define DEBUG(...)
void init(){}
#else
#define DEBUG(...) PRINT("##DEBUG##","file :",__FILE__,", line :",__LINE__,"[");PRINT(__VA_ARGS__);PRINTl("]");
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}
#endif
#ifdef ANS
#else
#endif

void solve();

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

  init();
  DEBUG();
  solve();

  return 0;
}

void solve(){
  ll k,x;
  cin>>k>>x;

  ll mn = max(x-k+1,(ll)-1000000);
  ll mx = min(x+k-1, (ll)1000000);
  FOR(i,mn,mx+1)PRINT(i);

  DEBUG("SOLVE START");

}

Measured memory_bytes: 256
//
// Created by Hideaki Imamura on 2020-03-18.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

int N, Q;
vector<vector<int>> G;
vector<ll> p, x, c;

int main() {
    cin >> N >> Q;
    G.assign(N, vector<int>());
    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    p.assign(Q, 0);
    x.assign(Q, 0);
    c.assign(N, 0);
    for (int i = 0; i < Q; ++i) {
        cin >> p[i];
        p[i]--;
        cin >> x[i];
        c[p[i]] += x[i];
    }

    queue<int> q;
    q.push(0);
    vector<int> visit(N, 0);
    visit[0] = 1;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int v : G[u]) {
            if (visit[v] == 1) continue;
            visit[v] = 1;
            c[v] += c[u];
            q.push(v);
        }
    }

    for (int i = 0; i < N; ++i) {
        cout << c[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 20212
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b;
	if(a==1&&b==2||a==2&&b==1)
	c=3;
	else if(a==2&&b==3||a==3&&b==2)
	c=1;
	else
	c=2;
	cout<<c;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vvl = vector<vector<ll>>;
using vl  = vector<ll>;
#define _GLIBCXX_DEBUG
#define acc_io cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define DBG(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
const ll MOD = 1000000007;
const double PI = acos(-1);  
//name[i]   -> vl  name(i)
//name[i][j]-> vvl name(i,vl(j))
//or-> ||
//map<int,int>mp

ll n;
ll ans;
//string s;
signed main(){
	acc_io;
	ans=0;
	cin>>n;
	ll a;
	rep(i,0,n){
		cin>>a;
		while(1){
			if(a%2==0){
				++ans;
				a/=2;
			}
			else{
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=1e5+5;
const int maxm=5e2+5;
const int maxq=55;
const int INF=0x3f3f3f3f;
int main()
{
    ll n;
    while(~scanf("%lld",&n))
    {
        if(n%2==0)
            printf("%lld\n",n);
        else
            printf("%lld\n",n*2);
    }
}


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

using namespace std;

int main()
{
  string s;
  int a=s.size();
  cin>>s;
	if(s[0]=='A'&&s[1]=='A'&&s[2]=='A'||s[0]=='B'&&s[1]=='B'&&s[2]=='B')
    cout<<"No";
  else 
     cout<<"Yes";
  return 0;
}

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

class UnionFind {
public:
    vector < ll > par; // 各元の親を表す配列
    vector < ll > siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1);
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main()
{
  int A, B, N, M;

  cin >> N >> M;

  UnionFind uf(N);

  for(int i=0; i<M; ++i){
    cin >> A >> B;
    uf.merge(A-1, B-1);
  }

  int ret = 0;

  for(int i=0; i<N; ++i){
    ret = max(ret, (int)(uf.size(i)));
  }

  cout << ret << endl;

  return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

const ll N_MAX = 400005;

ll inv[N_MAX],fac[N_MAX],finv[N_MAX];
void make(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll) i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}

ll Combination(ll C, ll D){
    if(C<D||C<1) return 0;
    return fac[C]*(finv[D]*finv[C-D]%mod)%mod;
}

int main(){
	ll N, A, B, K;
	cin >> N >> A >> B >> K;
	make();
	ll res = 0;
	REP(i, N+1){
		if((K-A*i)%B==0){
			ll j = (K-A*i)/B;
			if(j>=0&&j<=N)res += (Combination(N, i)*Combination(N, j)%mod);
			res %= mod;
		}
	}
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;

typedef struct
{
    int me;
    vi child;
} node;

const int N_MAX = 200010;

int ans[N_MAX];
node tree[N_MAX];
int dp[N_MAX];

void solve(int id, int p = -1)
{
    auto itr = lower_bound(dp, dp + 200010, tree[id].me);
    int d = distance(dp, itr);
    int old = dp[d];
    dp[d] = tree[id].me;

    int e = distance(dp, lower_bound(dp, dp + 200010, INF)) - 1;
    ans[id] = e;

    REP(i, tree[id].child.size())
    {
        if (tree[id].child[i] == p)
            continue;
        solve(tree[id].child[i], id);
    }
    dp[d] = old;
}

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;

    REP(i, N)
    {
        cin >> tree[i].me;
    }
    REP(i, N - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        tree[a].child.push_back(b);
        tree[b].child.push_back(a);
    }

    REP(i, N_MAX)
    {
        dp[i] = INF;
    }
    dp[0] = -1;

    solve(0);

    REP(i, N)
    {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 33436
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

#define MAX 10
typedef long long ll;

ll d[MAX],v[MAX];

ll gcd(ll a,ll b){
  return __gcd(a,b);
}

ll lcm(ll a,ll b){
  return a * b / gcd(a,b);
}

int main(){
  int n;

  while(scanf("%d" ,&n) ,n){
    for(int i = 0 ; i < n ; i++){
      scanf("%lld %lld" ,&d[i] ,&v[i]);
      ll a = gcd(d[i],v[i]);
      d[i] /= a;
      v[i] /= a;
    }       
    
    ll T = d[0],V = v[0];
    for(int i = 1 ; i < n ; i++){
      T = lcm(T,d[i]);
      V = gcd(V,v[i]);
    }
    
    for(int i = 0 ; i < n ; i++){
      ll div = T / d[i];
      printf("%lld\n" ,div*v[i]/V);
    }
  }
  
  return 0;
}

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

struct union_find {
	vector<ll> p;
	union_find(ll n) {
		p = vector<ll>(n,-1);
	}

	ll find(ll x) {
		if (p[x] < 0)
			return x;
		else {
			p[x] = find(p[x]);
			return p[x];
		}
	}

  	bool unite(ll x, ll y) {
    	ll xp = find(x);
		ll yp = find(y);
    	if (xp == yp)
			return false;
    	if (p[xp] > p[yp])
			swap(xp,yp);
    	p[xp] += p[yp];
		p[yp] = xp;
    	return true;
  	}

  	ll size(ll x) {
		return -p[find(x)];
	}
};

int main() {
	ll n,m; cin>>n>>m;
	vector<ll> a(m),b(m);
	union_find uf(n+1);
	for (ll i=0; i<m; i++)
		cin>>a[i]>>b[i];
	vector<ll> ans(m);
	ll current = n*(n-1)/2;
	for (ll i=m-1; i>=0; i--) {
		ans[i]=current;
		if (uf.find(a[i]) != uf.find(b[i]))
			current -= uf.size(a[i]) * uf.size(b[i]);
		uf.unite(a[i],b[i]);
	}

	for (ll i : ans) cout << i << endl;
	return 0;
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
*/
int main()
{
    int N;
    string S;
    cin >> N >> S;
    for(char s : S) cout << (char)(s + N > 90 ? s + N - 26 : s + N);
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<tuple>
#include<stdio.h>
#include<math.h>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Q;
typedef pair<Q,ll> R;
ll longinf=1ll<<60;
int inf=1<<29;
//mleしなければぜんぶllでかく。
//↑はあんまり気にしなくていい。

vector<P> adj[100001];
ll ans[100001];
bool visited[100001];

void dfs(int pp,int node){
    for(P q: adj[node]){
        int u=q.first;
        int w=q.second;
        if(!visited[u]){
            ans[u]=((pp+w)&1);
            visited[q.first]=true;
            dfs(ans[u],q.first);
        }
    }
}

int main(){
    int n;
    cin>>n;
    rep0(i,n-1){
        int u,v,w;
        cin>>u>>v>>w;
        u--,v--;
        adj[u].push_back({v,w});
        adj[v].push_back({u,w});
    }
    fill(visited,visited+n+1,false);
    ans[0]=0;
    visited[0]=true;
    dfs(ans[0],0);
    rep0(i,n){
        cout<<ans[i]<<endl;
    }


    return 0;
}

Measured memory_bytes: 9472
n, m = map(int, input().split())
p_s = [ list(map(str, input().split())) for _ in range(m) ]
ac = [False] * n
wa = [0] * n
for p, s in p_s:
    if ac[int(p)-1] is False:
        if s == 'AC':
            ac[int(p)-1] = True
        else:
            wa[int(p)-1] += 1
print(sum([1 for i in ac if i == True ]), sum([i for i,j in zip(wa,ac) if j == True ]))

Measured memory_bytes: 35636
#include<bits/stdc++.h>
using namespace std;
unsigned long long int dp[105][100005];
unsigned long long int knapsack(unsigned long long int *wt,unsigned long long int *val,unsigned long long int w,unsigned long long int n)
{
for(int i=0;i<=n;i++)
{
for(int j=0;j<=w;j++)
{
if(i==0 || j==0)
{
dp[i][j]=0;
}
else
{
if(wt[i-1]>j)
{
dp[i][j]=dp[i-1][j];
}
else
{
dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
}
}
}
}
return dp[n][w];

}
int main()
{
int n,w;
cin>>n;
cin>>w;
unsigned long long int wt[n];
unsigned long long int val[n];
for(int i=0;i<n;i++)
{
cin>>wt[i];
cin>>val[i];
}
cout<<knapsack(wt,val,w,n)<<endl;
return 0;
}


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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll A, B; cin >> A >> B;
  cout << (A+B) % 24 << endl;

  return 0;
}



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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  cin >> N;

  bool fl = false;
  deque<int> dq;
  REP(i,N){
	int x;
	cin >> x;
	if(!fl)
	  dq.push_back(x);
	else
	  dq.push_front(x);
	fl = !fl;
  }

  if(!fl){
	REP(i,N)
	  cout << (i?" ":"") << dq[i];
	cout << endl;
  }
  else{
	REP(i,N)
	  cout << (i?" ":"") << dq[N-1-i];
	cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3072
/**
 * Author : RDP
 * There are no two words in the English language more harmful than "good job".
 * 1729 ;)
**/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <numeric>
using namespace std;
using ll = long long;
#define endl '\n'
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) 
{
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define FAST_IO ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
#define bp(x) __builtin_popcount(x)
#define zf(x) __builtin_clz(x)
#define zl(x) __builtin_ctz(x)
#define par(x) __bultin_parity(x)
#define all(x) (x).begin(), (x).end()
/* **************************************************************************************** */
vector <ll> factor;

void sive(ll MAX) 
{
    factor.resize(MAX + 1);
    factor[1] = 1; 
    for (ll i = 2; i < MAX; i++) 
        factor[i] = i; 
    for (ll i = 4; i < MAX; i += 2) 
        factor[i] = 2; 
    for (ll i = 3; i * i < MAX; i++) 
    { 
        if (factor[i] == i) 
        { 
            for (ll j = i * i; j < MAX; j += i) 
            { 
                if (factor[j] == j) 
                    factor[j] = i; 
            } 
        } 
    } 
} 
  
ll ways(ll n) 
{ 
    if (n == 1) 
        return 1; 
  
    ll ans = 1, dup = factor[n], c = 1, j = n / factor[n]; 
  
    while (j != 1) 
    { 
        if (factor[j] == dup) 
            c += 1; 

        else 
        { 
            dup = factor[j]; 
            ans = ans * (c + 1); 
            c = 1; 
        } 
        j = j / factor[j]; 
    } 
    ans = ans * (c + 1); 
    return ans; 
} 
void test_case()
{   
    ll n, ans = 0;
    cin >> n;
    for(int i = 1; i <= n - 1; i ++)
    {
        ans += ways(i);
    }
    cout << ans;    
	return ;
}
int main()
{
	FAST_IO
    sive(1e6 + 1);
    test_case();
	return 0;
}



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

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if(A==5){
        if(B==5){
            if(C==7) cout << "YES" << endl;
            else
            {
                cout << "NO" << endl;
            }
            
        }else if(B==7){
            if(C==5) cout << "YES" << endl;
            else
            {
                cout << "NO" << endl;
            }
        }
    }else if(A==7){
        if(B==5&&C==5){
            cout << "YES" << endl;
        }else
            {
                cout << "NO" << endl;
            }
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

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

int main() {

  unsigned int a, b, _b, i, cnt = 0;
  scanf("%u %u", &a, &b);
  _b = b;

  for(i=0;i<a-1;i++) {
    _b *= b - 1;
  }

  printf("%u\n", _b);

  return 0;
}



Measured memory_bytes: 128
import math
 
N, D = list(map(int, input().split(' ')))
 
cnt = 0
def check(p, q):
  r = p**2 + q**2
  return math.sqrt(r)
 
for i in range(N):
  p, q = list(map(int, input().split(' ')))
  if check(p, q) <= D:
    cnt += 1
 
print(cnt)

Measured memory_bytes: 9188
def resolve():
    '''
    code here
    '''
    import collections
    K , T = [int(item) for item in input().split()]
    As = [int(item) for item in input().split()]
    As.sort(reverse=True)

    cnt = collections.Counter(As)
    interval_num = As[0]-1

    res = interval_num - sum(As[1:])

    if res <= 0:
        print(0)
    else:
        print(res)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9424
import java.util.*;
//import java.lang.Math;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true){
            int N=sc.nextInt();
            if(N==0) break;
            double ave=0;
            double ans=0;
            double A[]=new double[N];
            for(int i=0;i<N;i++) A[i]=sc.nextInt();
            for(int i=0;i<N;i++) ave+=A[i]/N;
            for(int i=0;i<N;i++) ans+=(A[i]-ave)*(A[i]-ave)/N;
            System.out.println(Math.sqrt(ans));
        }
    }
}


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

int main() {
	long int N;
  	cin >>N;
  	vector<ll>A(3*N);
  	priority_queue<long int,vector<long int>,greater<long int>> minia;//小さい順にでる
  	priority_queue<long int> maxa;//大きい順、後半部分
  
  	vector<long long int>maea(N+1);//前半Nこの最大和（K-N番目のセルにK番目入る）
  	vector<long long int>usia(N+1);//後半Nこの最小和
	long long int summae=0,sumusi=0;
  	rep(i,3*N){
    	cin >>A[i];
      	if(i<N){
        	minia.push(A[i]);
          	summae+=A[i];
        }
      	if(2*N<=i){
        	maxa.push(A[i]);
          	sumusi+=A[i];//2N+1以降の項の総和
        }
    }
  	maea[0]=summae;
  	usia[N]=sumusi;
  	for(long int i=N;i<2*N;i++){
    	minia.push(A[i]);
      	summae+=A[i];
      	long int g=minia.top();minia.pop();
      	summae-=g;
      	maea[i-N+1]=summae;
    }
  	for(long int i=(2*N)-1;i>=N;i--){
    	maxa.push(A[i]);
      	sumusi+=A[i];
      	long int h=maxa.top();maxa.pop();
      	sumusi-=h;
      	usia[i-N]=sumusi;
    }
  
  	long long int ans=-10000000000000000;
  	for(long int i=0;i<=N;i++){
    	ans=max(ans,maea[i]-usia[i]);
    }
  	cout<<ans<<endl; 
}

Measured memory_bytes: 6516
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };


int n;
double x_1, y_1, r_1, x_2, y_2, r_2;

int main() {
	scanf( "%d", &n );
	for ( int i = 0; i < n; i++ ) {
		scanf( "%lf %lf %lf %lf %lf %lf", &x_1, &y_1, &r_1, &x_2, &y_2, &r_2 );
		int ans = 0;
		double _range = sqrt( sq( x_1 - x_2 ) + sq( y_1 - y_2 ) );
		if ( _range <= r_1 + r_2 ) {
			ans = 1;
			if ( _range + r_1 < r_2 && r_2 > r_1) {
				ans = -2;
			}
			else if ( _range + r_2 < r_1 && r_1 > r_2) {
				ans = 2;
			}
		}
		printf( "%d\n", ans );
	}
	return 0;
}

Measured memory_bytes: 1224
n = int(input())
a = list(map(int,input().split()))
print(" ".join(map(str,a)))
for i in range(1,n):
    for j in range(i):
        if a[i] > a[i-j-1]:
            temp = a.pop(i)
            a.insert(i-j,temp)
            break
        elif j == i - 1:
            temp = a.pop(i)
            a.insert(0,temp)
    print(" ".join(map(str,a)))


Measured memory_bytes: 5596
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          pb push_back
#define          N (int)2e5+5
#define          PI acos(-1.0)
#define          int long long 
#define          vi vector<int>
#define          mod 1000000007
#define          ld long double
#define          eb emplace_back
#define          mii map<int,int>
#define          vpii vector<pii>
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

void go()
{
	cin >> n;
	int ans = 0;

	fo(i,1,n+1)
	{
		fo(j,1,n+1)
		{
			fo(k,1,n+1)
			{
				int xx = __gcd( i , __gcd( j, k) );

				ans += xx;
			}
		}
	}

	cout << ans << endl;
}

int32_t main()
{
	FAST;     
	int t=1; 
	// cin>>t;
	test(t) go();
}

 

Measured memory_bytes: 8324
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N, M = getNM()
query = [getList() for i in range(M)]
S, T = getNM()

def build_tree_dis(N, edge_list):

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

    for i in range(len(edge_list)):
        a, b = edge_list[i]
        G[a - 1].append(b - 1)

    # 葉（末端の数）
    leaves = []
    for i in range(N):
        if len(G[i]) == 1:
            leaves.append(i)

    return G

edges = build_tree_dis(N, query)

ignore = [[-1] * 3 for i in range(N)]
ignore[S - 1][0] = 0

pos = deque([[S - 1, 0]])

while len(pos) > 0:
    u, t = pos.popleft()
    t += 1
    j = t % 3
    for i in edges[u]:
        if ignore[i][j] == -1:
            ignore[i][j] = t
            pos.append([i, t])

if ignore[T - 1][0] % 3 == 0:
    print(ignore[T - 1][0] // 3)
    exit()
else:
    print(-1)

Measured memory_bytes: 125644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(){
  vector<int> num(3);
  cin >> num[0] >> num[1] >> num[2];
  sort(num.begin(),num.end());
  if((num[1] - num[0]) % 2 == 0){
    cout << num[2] - num[1] + (num[1] - num[0]) / 2 << endl;
  }
  else{
    cout << num[2] - num[1] + (num[1] - num[0]) / 2 + 2 << endl;
  }
  return 0;
}

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

int main() {
	string s;
	int w;
	cin >> s >> w;
	
	int i = 0;
	string ans = "";
	while (i < s.size()) {
		ans.push_back(s[i]);
		i += w;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N - 2 + 1);
  vector<ll> t(N, 0);
  for (int i = 0; i < N - 2 + 1; i++)
  {
    scanf("%lld", &A[i]);
    t[A[i] - 1]++;
  }
  for (auto &e : t)
    cout << e << endl;

  return 0;
}


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

using namespace std;

int main()
{
  int Q;
  bool prime[100001] = {};
  vector< int > v;

  for(int i = 2; i * i < 100001; i++) {
    if(prime[i]) continue;
    for(int j = i + i; j < 100001; j += i) {
      prime[j] = true;
    }
  }

  for(int i = 3; i < 100001; i++) {
    if(i & 1 && !prime[i] && !prime[(i + 1) / 2]) {
      v.push_back(i);
    }
  }

  cin >> Q;
  while(Q--) {
    int L, R;
    cin >> L >> R;
    int ret = 0;
    for(auto &s : v) ret += L <= s && s <= R;
    cout << ret << endl;
  }

}

Measured memory_bytes: 768
#include <iostream>
#define r(i,n)for(int i=0;i<=n;i++)
using namespace std;main() {int h,w,y[15][15],a,s=0;cin>>h>>w;r(i,9)r(j,9)cin>>y[i][j];r(k,9)r(i,9)r(j,9)y[i][j]=min(y[i][j],y[i][k]+y[k][j]);r(i,h-1)r(j,w-1){cin>>a;if(a!=-1)s+=y[a][1];}cout<<s;}

Measured memory_bytes: 256
n = int(input())
s = input()
r = [0] * (n + 1)
g = [0] * (n + 1)
b = [0] * (n + 1)
for i in range(n):
    r[i + 1] = r[i]
    g[i + 1] = g[i]
    b[i + 1] = b[i]
    if s[i] == 'R':
        r[i + 1] += 1
    elif s[i] == 'G':
        g[i + 1] += 1
    else:
        b[i + 1] += 1
ans = 0
for i, c1 in enumerate(s):
    for j in range(i + 1, n):
        c2 = s[j]
        if c1 == c2:
            continue
        if c1 != 'R' and c2 != 'R':
            if (j - i) % 2:
                ans += r[j + 1] - r[i]
            else:
                ans += r[j + 1] - r[i] - \
                    (r[(i + j) // 2 + 1] - r[(i + j) // 2])
        elif c1 != 'G' and c2 != 'G':
            if (j - i) % 2:
                ans += g[j + 1] - g[i]
            else:
                ans += g[j + 1] - g[i] - \
                    (g[(i + j) // 2 + 1] - g[(i + j) // 2])
        else:
            if (j - i) % 2:
                ans += b[j + 1] - b[i]
            else:
                ans += b[j + 1] - b[i] - \
                    (b[(i + j) // 2 + 1] - b[(i + j) // 2])
print(ans)


Measured memory_bytes: 68832
n,m,k=map(int,input().split())

mod = 10**9+7
f = [1]
for i in range(n*m):
  f += [f[-1]*(i+1) % mod]
def comb(a, b):
  return f[a]*pow(f[b], mod-2, mod)*pow(f[a-b], mod-2, mod) % mod

ans=0
for dist in range(1,n):
  c=n-dist
  p=(c*m*m)%mod
  ans+=p*dist
for dist in range(1,m):
  c=m-dist
  p=(c*n*n)%mod
  ans+=p*dist
ans%=mod
print(ans*comb(n*m-2,k-2)%mod)

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

int main(){
	stack<long long>st;
	string c;
	while(cin>>c){
		if(c=="+"){
			long long a=st.top();
			st.pop();
			long long b=st.top();
			st.pop();
			st.push(a+b);
		}
		else if(c=="-"){
			long long a=st.top();
			st.pop();
			long long b=st.top();
			st.pop();
			st.push(b-a);
		}
		else if(c=="*"){
			long long a=st.top();
			st.pop();
			long long b=st.top();
			st.pop();
			st.push(a*b);
		}
		else{
			st.push(stoi(c));
		}
	}
	cout<<st.top()<<endl;
	return 0;
}

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

def solve(S):
    s = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")

    if(s==""):
        print("YES")
    else:
        print("NO")
    
if __name__ == '__main__':
    S = input()
  
    solve(S)

Measured memory_bytes: 3188
N=gets.chomp.to_i
A=gets.chomp.split(" ").map { |e| e.to_i  }

def number_of_diveide_N(n,x)
  ans =0
  while (x % n == 0) do
    ans += 1
    x = x/2
  end
  return ans
end

ans = 0

for i in A do
  ans += number_of_diveide_N(2,i)
end

puts ans

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

int main() {
  int M, D; cin >> M >> D;
  int ans =0;
  
  for(int i=1; i<=M; i++) {
    for(int j=12; j<=D; j++) {
    
      if(j/10 ==1 ){continue;}
      else if(j%10 ==1){continue;}
      
      if(i == (j/10)*(j%10)){
        ans++;
      }
    }
  }
  cout << ans << endl;
}


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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

void solve() {
  int k, x;
  cin >> k >> x;
  if (500 * k >= x) {
    cout << "Yes\n";
    return;
  }
  cout << "No\n";
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 256
#
import sys
import time

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

def main():
    n = int(input())
    agrid = []
    agrid_pointer = [0] * n

    start = time.time()

    for i in range(n):
        al = list(map(int, input().split()))
        agrid.append(al)

    ans = 0

    while True:
        match = set()
        for i in range(n):
            if agrid_pointer[i] == n - 1 or i in match:  # もう全部対戦済み or この日対戦済み
                continue

            target = agrid[i][agrid_pointer[i]] - 1
            if agrid_pointer[target] == n - 1 or target in match:  # もう全部対戦済み or この日対戦済み
                continue
            # i, target は対戦可能

            if agrid[target][agrid_pointer[target]] - 1 != i:
                continue

            # can match
            agrid_pointer[i] += 1
            agrid_pointer[target] += 1

            match.add(i)
            match.add(target)

            if len(match) == n or len(match) == n - 1:  # 全員試合することが決まったら
                break

        # print(match)
        if len(match) == 0:  # 対戦がなくなったら
            break
        elapsed_time = time.time() - start
        if elapsed_time > 1.5:
            print(n * (n-1)//2)
            return

        ans += 1

    # print(aconditions)
    # 対戦が残ってたら
    for p in agrid_pointer:
        if p != n - 1:
            print(-1)
            return
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 53592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

struct UnionFindTree {
    vector<int> par;
    vector<int> rank;
    vector<int> siz;

    void init(int n) {
        par.resize(n);
        rank.resize(n);
        siz.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        siz[x] += siz[y];
    }
    bool is_same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        x = find(x);
        return siz[x];
    }
};

int main() {
    int n, k, l;
    cin >> n >> k >> l;
    UnionFindTree a, b;
    a.init(n);
    b.init(n);
    for(int i=0;i<k;i++){
        int p, q;
        cin >> p >> q;
        p--; q--;
        a.unite(p, q);
    }
    for(int i=0;i<l;i++){
        int r, s;
        cin >> r >> s;
        r--; s--;
        b.unite(r, s);
    }
    map<P,int> cnt;
    for(int i=0;i<n;i++){
        ++cnt[make_pair(a.find(i), b.find(i))];
    }
    for(int i=0;i<n;i++){
        cout << cnt[make_pair(a.find(i), b.find(i))] << " \n"[i==n-1];
    }
    return 0;
}


Measured memory_bytes: 16640
#include <stdio.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <math.h>
#include <vector>
#include <list>
using namespace std;
#define NIL -1

int n;
struct node
{
    int parent, sibling, depth, height;
    vector<int> child;
};
node nd[25];

int getRoot()
{
    int k = 0;
    while (nd[k].parent > NIL)
    {
        k = nd[k].parent;
    }
    return k;
}

void CalcDepth(int r)
{
    if (nd[r].child.size() != 0)
    {
        for (int i = 0; i < nd[r].child.size(); i++)
        {
            nd[nd[r].child[i]].depth = nd[r].depth + 1;
            CalcDepth(nd[r].child[i]);
        }
    }
    return;
}

void CalcHeight(int r)
{
    if (nd[r].child.empty())
    {
        nd[r].height = 0;
    }
    else
    {
        for (int i = 0; i < nd[r].child.size(); i++)
        {
            CalcHeight(nd[r].child[i]);
            nd[r].height = max(nd[nd[r].child[i]].height + 1, nd[r].height);
        }
    }
}

int main()
{
    cin >> n;
    int x, l, r;
    for (int i = 0; i < n; i++)
    {
        nd[i].parent = NIL;
        nd[i].sibling = NIL;
        nd[i].depth = NIL;
        nd[i].height = NIL;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> x >> l >> r;
        if (l > NIL)
        {
            nd[x].child.push_back(l);
            nd[l].parent = x;
            nd[l].sibling = r;
        }
        if (r > NIL)
        {
            nd[x].child.push_back(r);
            nd[r].parent = x;
            nd[r].sibling = l;
        }
    }
    x = getRoot();
    nd[x].depth = 0;
    CalcDepth(x);
    CalcHeight(x);

    for (int i = 0; i < n; i++)
    {
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d,",
               i, nd[i].parent, nd[i].sibling, (int)nd[i].child.size(), nd[i].depth, nd[i].height);
        if (nd[i].parent == NIL)
            printf(" root");
        else if (nd[i].child.size() == 0)
            printf(" leaf");
        else
            printf(" internal node");

        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 3208