akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    ll count = 1, ans = 0;
    vector<ll> stand, handstand;
    for(int i=1;i<N;i++){
        if(S[i] != S[i-1]){
            if(S[i-1] == '1'){    
                handstand.push_back(count);
                if(count > ans)
                    ans = count;
            }else{
                stand.push_back(count);
            }
            count = 1;
        }else{
            count++;
        }
    }
    if(S[N-1] == '1'){
        handstand.push_back(count);
        if(count > ans)
            ans = count;
    }else{
        stand.push_back(count);
    }

    ll HS_size = handstand.size(), S_size = stand.size();
    if(HS_size == 0 || S_size <= K){
        cout << N << endl;
        return 0;
    }

    ll HS_count;
    for(int i=0;i<(S_size - K + 1);i++){
        HS_count = 0;
        for(int j=i;j<i+K && j<S_size;j++){
            HS_count += stand[j];
            if(j < HS_size)
                HS_count += handstand[j];
            if(S[0] == '0' && j == i && j != 0)
                HS_count += handstand[j-1];
            if(S[0] == '1' && j == i+K-1 && j+1 < HS_size)
                HS_count += handstand[j+1];
        }
 
        if(HS_count > ans)
            ans = HS_count;
    }

    cout << ans << endl;

}


Measured memory_bytes: 1404
import sys
from collections import defaultdict
from collections import deque
from sys import stdin
sys.setrecursionlimit(10**7)
input = stdin.readline


def main():
  # input
  N, Q = list(map(int, input().split()))

  G = [[] for _ in range(N+1)]
  for _ in range(N-1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)

  PX = defaultdict(int)
  for _ in range(Q):
    p, x = map(int, input().split())
    PX[p] += x

  # solve
  ans = [0]*(N+1)
  visited = set()
  # temp = PX[1]
  # S = [1] # Stack
  # S = deque([1])

  # while len(S):
  #   now = S[-1]
  #   visited.add(now)

  #   for next_ in G[now]:
  #     if next_ not in visited:
  #       S.append(next_)
  #       temp += PX[next_]
  #       break
  #   else:
  #     S.pop()
  #     ans[now] = temp
  #     temp -= PX[now]

  def dfs(now, sum_):
    visited.add(now)
    for next_ in G[now]:
      if next_ not in visited:
        sum_ += PX[next_]
        sum_ = dfs(next_, sum_)

    ans[now] = sum_
    sum_ -= PX[now]
    return sum_

  dfs(1, PX[1])

  print(*ans[1:], sep=' ')


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


Measured memory_bytes: 316084
#[doc = " Ported from [bluss/permutohedron](https://github.com/bluss/permutohedron)"]
pub trait LexicalPermutation {
#[doc = " Return \'true\' if the slice was permuted, \'false\' if it is already "]
#[doc = " at the last ordered permutation."]
    fn next_permutation(&mut self) -> bool;
#[doc = " Return \'true\' if the slice was permuted, \'false\' if it is already "]
#[doc = " at the first ordered permutation."]
    fn prev_permutation(&mut self) -> bool;
}
impl<T> LexicalPermutation for [T]
where
    T: Ord,
{
#[doc = " Original author in Rust: Thomas Backman <serenity@exscape.org>"]
    fn next_permutation(&mut self) -> bool {
        if self.len() < 2 {
            return false;
        }
        let mut i = self.len() - 1;
        while i > 0 && self[i - 1] >= self[i] {
            i -= 1;
        }
        if i == 0 {
            return false;
        }
        let mut j = self.len() - 1;
        while j >= i && self[j] <= self[i - 1] {
            j -= 1;
        }
        self.swap(j, i - 1);
        self[i..].reverse();
        true
    }
#[doc = " Original author in Rust: Thomas Backman <serenity@exscape.org>"]
    fn prev_permutation(&mut self) -> bool {
        if self.len() < 2 {
            return false;
        }
        let mut i = self.len() - 1;
        while i > 0 && self[i - 1] <= self[i] {
            i -= 1;
        }
        if i == 0 {
            return false;
        }
        self[i..].reverse();
        let mut j = self.len() - 1;
        while j >= i && self[j - 1] < self[i - 1] {
            j -= 1;
        }
        self.swap(i - 1, j);
        true
    }
}

fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn fractorial(n: u64) -> u64 {
    if n == 1 { 1 }
    else { n * fractorial(n - 1) }
}

fn main() {
    let n = get_line().parse::<usize>().unwrap();
    let mut coord: Vec<Vec<f64>> = Vec::new();
    let mut order = (0..n).collect::<Vec<usize>>();

    for _ in 0..n {
        let xy = get_line().split_whitespace()
            .map(|n| n.parse().unwrap())
            .collect::<Vec<f64>>();
        coord.push(xy);
    }

    let mut sum = 0f64;
    loop {
        for i in 0..n-1 {
            let (xy1, xy2) = (&coord[order[i]], &coord[order[i + 1]]);
            sum += (xy1[0] - xy2[0]).hypot(xy1[1] - xy2[1]);
        }
        if !order.next_permutation() { break; }
    }

    println!("{}", sum / fractorial(n as u64) as f64);
}


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

using namespace std;

void calc(int n,int s,vector<int> adj[],vector<int> &u){
	u[s] = s;
	vector<bool> visited(n,false);
	priority_queue<int> np;
	np.push(s);
	while(!np.empty()){
		int now = np.top(); np.pop();
		visited[now] = true;
		for(int i = 0; i < adj[now].size(); ++i){
			int next = adj[now][i];
			if(visited[next])continue;
			np.push(next);
			u[next] = s;
		}
	}
	return;
}


int main(){
	int n,m; cin >> n >> m;
	vector<int> adj[n];
	for(int i = 0; i < m; ++i){
		int s,t; cin >> s >>t;
		adj[s].push_back(t);
		adj[t].push_back(s);
	}
	vector<int> u(n,-1);
	for(int i = 0; i < n; i++){
		if(u[i] != -1)continue;
		calc(n,i,adj,u);
	}
	int q; cin >> q;
	for(int i = 0; i < q; i++){
		int s,t; cin >> s >> t;
		if(u[s] == u[t])cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}

Measured memory_bytes: 8680
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
int main()
{
  ll N, P;
  cin >> N >> P;
  if (N == 1)
  {
    cout << P << endl;
    return 0;
  }
  if (N > sqrt(P))
  {
    cout << 1 << endl;
    return 0;
  }
  ll ans = 1;
  for (int i = 2; i <= sqrt(P) + 2; i++)
  {
    int cnt = 0;
    while (P % i == 0)
    {
      P /= i;
      cnt++;
      if (cnt == N)
      {
        ans *= i;
        cnt = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back

double ave(double a, double b){
    return (a+b)/2;
}


signed main(){
    int W,H,w,h,x,y;
    cin>>W>>H>>w>>h>>x>>y;
    
    printf("%.20lf\n",ave(y-h/2,min(y+h/2,H/2))/ave(x-w/2,min(x+w/2,W/2)));
}



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

int main() {
	int num[100];
	for(int i = 0; i < 100; i++){
		num[i] = i + 1;
		if(i == 99){
			num[i] = i + 2;
		}
	}
	int D,N;
	cin >> D >> N;
	if(D == 0){
		cout << num[N - 1]<< endl;
	}
	else if(D == 1){
		cout << num[N - 1] * 100  << endl;
	}
	else{
		cout << num[N - 1] * 10000<< endl;
	}
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	x, y := sc.NextInt(), sc.NextInt()

	if x >= 0 && y >= 0 {
		if y == 0 {
			fmt.Println(x + 1)
		} else if x < y {
			fmt.Println(y - x)
		} else {
			fmt.Println(x - y + 2)
		}
	} else if x < 0 && y >= 0 {
		if y == 0 {
			fmt.Println(y - x)
		} else {
			fmt.Println(abs(y+x) + 1)
		}

	} else if x >= 0 && y < 0 {
		if -y >= x {
			fmt.Println(-y - x + 1)
		} else {
			fmt.Println(x + y + 1)
		}
	} else {
		if x < y {
			fmt.Println(y - x)
		} else {
			fmt.Println(x - y + 2)
		}
	}

}

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

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
N = int(input())
for l in range(N):
    r,t = [int(i) for i in input().split()]
    
    rr = []
    tt = []
    
    if r % 100 == 0:
        rr.append(r // 100)
    else:
        rr.append(r // 100)
        rr.append(r // 100 + 1)

    if t % 30 == 0:
        tt.append(t // 30)
    else:
        tt.append(t // 30)
        tt.append(t // 30 + 1)

    ans = []
    for i in range(len(tt)):
        for j in range(len(rr)):
            ans.append(5*tt[i]+rr[j])

    for i in range(len(ans)):
        if i == len(ans)-1:
            print(ans[i], end="")
        else:
            print(ans[i], end=" ")

    print("")


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

using namespace std;

const int max_n = 2022, inf = 1000111222;

char buf[max_n];
bitset<max_n> a[max_n], dp0[max_n], dp1[max_n], dp2[max_n];

int n;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d", &n);
    for (int i = 1; i < n; ++i) {
        scanf("%s", buf);
        for (int j = 0; j < i; ++j) {
            a[i][j] = buf[j] - '0';
            a[j][i] = 1 ^ a[i][j];
        }
    }
    for (int i = 0; i < n; ++i) {
        dp0[i][i] = 1;
        dp1[i][i] = 1;
        dp2[i][i] = 1;
    }
    for (int len = 2; len <= n; ++len) {
        for (int l = 0; l + len <= n; ++l) {
            int r = l + len - 1;
            if (len == 2) {
                dp2[l][r] = 1;
            } else {
                dp2[l][r] = (dp2[l] & dp2[r] & (a[l] | a[r])).any();
            }
            dp2[r][l] = dp2[l][r];

            if (a[l][r] && dp2[l][r]) {
                dp0[l][r] = 1;
            } else {
                dp0[l][r] = (a[l] & dp0[l] & dp0[r]).any();
            }
            dp0[r][l] = dp0[l][r];

            if (a[r][l] && dp2[l][r]) {
                dp1[l][r] = 1;
            } else {
                dp1[l][r] = (a[r] & dp1[l] & dp1[r]).any();
            }
            dp1[r][l] = dp1[l][r];
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        bool ok = dp1[0][i] & dp0[i][n - 1];
        ans += ok;
    }
    printf("%d\n", ans);
    return 0;
}


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

int N;
string s;
set<string> used;
int main(){

  cin>>N;
  for(int i=0;i<N;i++){
    char ch;
    cin>>ch;
    s += ch;
  }
  for(int i=0;i<N;i++){
    for(int j=i;j<N;j++){
      used.insert(s.substr(i, j - i + 1));
    }
  }
  for(int i=0;;i++){
    string s = to_string(i);
    if(used.count(s)){
      continue;
    }
    else{
      cout<<i<<endl;
      break;
    }
  }
  
  return 0;
}

Measured memory_bytes: 209524
n = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(n):
    x = input()
    if x == "AC":
        AC += 1
    elif x == "WA":
        WA += 1
    elif x == "TLE":
        TLE += 1
    elif x == "RE":
        RE += 1
print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE))


Measured memory_bytes: 9152
using System;

public class Hello{
    public static void Main(){
        // Here your code !
        // your code goes here
		string line = System.Console.ReadLine();
		string[] ab = line.Split(' ');
		decimal r = Convert.ToDecimal(ab[0]);
		decimal pi = Convert.ToDecimal(Math.PI);
		decimal s = pi*r*r;
		decimal l = 2.0m*pi*r;
		Console.WriteLine("{0:F6} {1:F6}",s,l);
		
    }
}

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

using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(0); 
  cin.tie(0); 
  
  int a, b, c;
  cin >> a >> b >> c;

  if (a + b >= c) cout << "Yes" << "\n";
  else cout << "No" << "\n";
}


Measured memory_bytes: 3640
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<cstring>
using namespace std;
const int inf=1<<30;
int main(){
  string s;cin>>s;
  int ans=700;
  for(int i=0;i<3;i++)if(s[i]=='o')ans+=100;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <set>
 
using namespace std;
typedef long long ll;

ll ans,mx,mn=1e10,sum;
int main(){
	int a[3];

	for(int i=0;i<3; i++){
		cin>>a[i];
	}
	int k;
	cin>>k;
	sort(a,a+3);
	sum += a[0]+a[1]; 
	for(int i=1; i<=k; i++){
		a[2] =a[2]*2;
	}
	cout<<a[2]+sum;
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
int w[105],a[105],b[105],c[105];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%d",&w[i]);
    for(int i=1; i<n; i++)
        a[i]=0,b[i]=0;
    for(int i=1; i<n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if(j<=i)
                a[i]+=w[j];
            else
                b[i]+=w[j];
        }
    }
    for(int i=1; i<n; i++)
    {
        if(a[i]>b[i])
            c[i]=a[i]-b[i];
        else
            c[i]=b[i]-a[i];
    }
    sort(c+1,c+n);
    printf("%d\n",c[1]);
}


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

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

using ll = long long;

int main() {
  int S, W;
  cin >> S >> W;
  if(W>=S)cout << "unsafe"<< endl;
  if(W<S) cout << "safe" << endl;
}
          

Measured memory_bytes: 3640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

//const double PI = 3.1415926535897932384626433832795;

int main() {
  int a, b;
  cin >> a >> b;
  if(a >= 13) {
    cout << b << endl;
  }
  else if(a >= 6) {
    cout << b/2 << endl;
  }
  else {
    cout << 0 << endl;
  }

  return 0;
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m;
    vector<int> cnt(m);
    for (int i = 0; i < n; ++i) {
        cin >> k;
        while (k--) {
            int a;
            cin >> a;
            ++cnt[--a];
        }
    }
    int ans = 0;
    for (auto x: cnt) if (x == n) ++ans;
    cout << ans << endl;

    return 0;
}


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



int main() {
    int h, w, m;
    cin >> h >> w >> m;
    
    set<P> s;
    vector<int> all_h(h+1), all_w(w+1);
    rep(i,m) {
        int y, x;
        cin >> y >> x;
        s.insert(P(y,x));
        all_h[y]++;
        all_w[x]++;
    }
    
    int mh = 0, mw = 0;
    rep(i,h+1) {
        mh = max(mh,all_h[i]);
    }
    rep(i,w+1) {
        mw = max(mw,all_w[i]);
    }
    
    vector<int> all_mh, all_mw;
    rep(i,h+1) {
        if(mh == all_h[i])
            all_mh.push_back(i);
    }
    rep(i,w+1) {
        if(mw == all_w[i])
            all_mw.push_back(i);
    }
    
    rep(i,all_mh.size()) {
        rep(j,all_mw.size()) {
            if(s.count(P(all_mh[i],all_mw[j])))
                continue;
            else {
                cout << mh + mw << endl;
                return 0;
            }
        }
    }
    cout << mh + mw - 1 << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 23860
#include<cmath>
#include<iostream>

#define	EPS		1e-9

using namespace std;

class Point{
public:
	double x,y;
	Point(){}
	Point(double xx,double yy) : x(xx),y(yy){}
};

Point &operator -=(Point &a,const Point &b)
{
	a.x-=b.x;
	a.y-=b.y;
	return a;
}

double cross(const Point &a,const Point &b)
{
	return a.x*b.y-a.y*b.x;
}

int main()
{
	int n;	cin>>n;
	while(n--){
		Point p[4];
		for(int i=0;i<4;i++)	cin>>p[i].x>>p[i].y;
		p[1]-=p[0];
		p[3]-=p[2];
		if(abs(cross(p[1],p[3]))<EPS)	cout<<"YES"<<endl;
		else	cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
s=input()
k0=0
k1=0
g0=0
g1=0
for i in range(len(s)):
    if i%2==0:
        if s[i]=="0":
            k0+=1
        else:
            k1+=1
    else:
        if s[i]=="0":
            g0+=1
        else:
            g1+=1
print(min(k0+g1,k1+g0))


Measured memory_bytes: 3188
N = int(input())
N = N
s = "zabcdefghijklmnopqrstuvwxyz"
ans = []
while True:
    temp = N % 26
    ans.append(s[temp])
    if temp == 0:
        N = N - 1
    N = N // 26
    if N <= 0:
        break

ans.reverse()
print("".join(ans))


Measured memory_bytes: 9164
N=[list(map(int,input().split())) for j in range(3)]
M=int(input())
K=[int(input()) for v in range(M)]

for b in range(M):
  for t in range(3):
    for r in range(3):
      if N[t][r]==K[b]:
        N[t][r]=0
for i in range(3):
  if N[i][0]+N[i][1]+N[i][2]==0: #たて
    print("Yes")
    exit()
  elif N[0][i]+N[1][i]+N[2][i]==0:
    print("Yes")
    exit()
if N[0][0]+N[1][1]+N[2][2]==0:
  print("Yes")
  exit()
elif  N[0][2]+N[1][1]+N[2][0]==0:
  print("Yes")
  exit()
else:
  print("No")

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define Edge pair< int, i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second

//int dxy[5] = {0, 1, 0, -1, 0};
// assign avl ncm dij geo2

int fact(int a)
{
    int ret = 1;
    Rep(i, a+1) {
        ret *= i;
        ret %= MOD;
    }
    return ret;
}

signed main()
{
    int2(a, b);
    if (abs(a - b) > 1) {
        cout << 0 << endl;
        return 0;
    }

    if (a != b) {
        cout << (fact(a) * fact(b)) % MOD << endl;
    } else {
        cout << (2 * (fact(a) * fact(b))) % MOD << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////


int c[500],s[500],f[500],ans[500];
int n;

int solve( int p , int now ){
	
	int arr;
	

	if(now <= s[p] ){
		arr = s[p] + c[p];
	}
	else{
		int x = 0;
		while( !(s[p] + (f[p] * x ) >= now) ){
			x++;
		}
		arr = s[p] + (f[p] * x ) + c[p];
	}
	
	if( p+1 == n-1 ){
		ret arr;
	}
	else{
		if(s[p+1] >= arr){
			ret ans[p+1];
		}
		else{
			ret solve( p+1 , arr);
		}
	}

}

int main(){
	cin >> n;
	rep(i,0,n-1){
		cin >> c[i] >> s[i] >> f[i];
	}

	ans[n-1] = 0;
	ans[n-2] = c[n-2] + s[n-2];

	for(int i = n-3 ; i >= 0 ; i-- ){
		ans[i] = solve( i , 0 );				
	}
	
	rep(i,0,n)
		P(ans[i]);

	ret 0;
}

Measured memory_bytes: 256
N,M,X,Y=map(int,input().split())
x_array = list(map(int,input().split()))
y_array = list(map(int,input().split()))
x_array.sort()
y_array.sort()
if x_array[N-1] >= Y or y_array[0] <= X :print("War")
else :
    if y_array[0] - x_array[N-1] > 0 : print("No War")
    else : print("War")

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

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

struct UnionFind {
  vector<int> par;
  vector<int> rank;
  vector<int> size;
    
  UnionFind(int N) : par(N), rank(N), size(N) {
    for (int i = 0; i < N; i++) {
      par[i]  = i;
      rank[i] = 0;
      size[i] = 1;
    }
  }
  
  int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  
  void unite(int x, int y) {
    int rx = find(x);
    int ry = find(y);
    if (rx == ry) return;
    
    if (rank[rx] < rank[ry]) {
      par[rx] = ry;
      size[ry] = size[ry] + size[rx];
    }
    else if (rank[rx] > rank[ry]) {
      par[ry] = rx;
      size[rx] = size[rx] + size[ry];
    }
    else {
      par[ry] = rx;
      size[rx] = size[rx] + size[ry];
      rank[rx]++;
    }
  }
  
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  
  int get_size(int x) {
    int rx = find(x);
    return size[rx];
  }
  
};

int main() {

  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N, K, L;
  cin >> N >> K >> L;

  UnionFind uf_road = UnionFind(N); // road
  UnionFind uf_rail = UnionFind(N); // railway

  int p, q, r, s;
  for (int i = 0; i < K; i++) {
    cin >> p >> q;
    p--; q--;
    uf_road.unite(p, q);
  }

  for (int i = 0; i < L; i++) {
    cin >> r >> s;
    r--; s--;
    uf_rail.unite(r, s);
  }

  map<P, int> mp;
  vector<P> v(N);
  
  for (int i = 0; i < N; i++) {
    int r1 = uf_road.find(i);
    int r2 = uf_rail.find(i);
    P p = P(r1, r2);
    v[i] = p;
    
    if(mp.find(p) != mp.end()) mp[p]++;
    else mp[p] = 1;
  }
  
  for (int i = 0; i < N; i++) {
    auto itr = mp.find(v[i]);
    cout << itr->second << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 15232
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
            int h = sc.nextInt();
            int w = sc.nextInt();
            if (h==0 && w == 0) break;
            for(int i = 1; i <= h; i++){
                for(int j = 1; j <= w; j++){
                    if((i+j) % 2 == 0){
                        System.out.print("#");
                    } else {
                        System.out.print(".");
                    }
                    if (j == w) {
                        System.out.println("");
                    }
                }
            }
            System.out.println("");
        }
    }
}



Measured memory_bytes: 35116
package main

import (
	"fmt"
	"strings"
)

func main() {
	var N string
	fmt.Scanf("%s", &N)

	if strings.HasSuffix(N, "2") || strings.HasSuffix(N, "4") || strings.HasSuffix(N, "5") || strings.HasSuffix(N, "7") || strings.HasSuffix(N, "9") {
		fmt.Println("hon")
		return
	}

	if strings.HasSuffix(N, "0") || strings.HasSuffix(N, "1") || strings.HasSuffix(N, "6") || strings.HasSuffix(N, "8") {
		fmt.Println("pon")
		return
	}
	fmt.Println("bon")
}


Measured memory_bytes: 1820
// AOJ 1142

#include <iostream>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int main(void)
{
	int m;
	cin >> m;
	while (m--){
		string str;
		map <string, int> mydata;
		cin >> str;
		for (int i = 1; i < (int)str.length(); i++){
			string first = str.substr(0, i);
			string second = str.substr(i, (int)str.length() - i);
			string frev = first; reverse(frev.begin(), frev.end());
			string srev = second; reverse(srev.begin(), srev.end());
			// cout << first << " " << second << endl;

			// そのまま＋そのまま
			mydata[first + second]++;
			// はんてん＋そのまま
			mydata[frev + second]++;
			// そのまま＋はんてん
			mydata[first + srev]++;
			// はんてん＋はんてん
			mydata[frev + srev]++;

			// いれかえする
			// そのまま＋そのまま
			mydata[second + first]++;
			// そのまま＋はんてん
			mydata[second + frev]++;
			// はんてん＋そのまま
			mydata[srev + first]++;
			// はんてん＋はんてん
			mydata[srev + frev]++;
		}

		cout << mydata.size() << endl;
	}

	return 0;
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

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

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


int main(){
    int n;
    cin >> n;
    map<ll, int> cnt;
    rep(i, n) {
        ll a;
        cin >> a;
        cnt[a]++;
    }
    int ans = 0;
    for (auto e: cnt) {
        if (e.second % 2 != 0) {
            ans++;
        } 
    }

    cout << ans << endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i, n) cin >> x[i];
    sort(all(x), greater<>());
    int mx = x[0];
    int ans = INF;
    rep(i, mx) {
        int tmp = 0;
        rep(j, n) {
            tmp += abs(i+1-x[j]) * abs(i+1-x[j]);
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

s = input()
t = input()
lenS = len(s)
lenT = len(t)
for i in range(lenS-lenT,-1,-1):
  sub = s[i:i+lenT]
  for j in range(lenT):
    if sub[j]!="?" and sub[j]!=t[j]:
      break
  else:
    s=s.replace("?","a")
    print(s[:i]+t+s[i+lenT:])
    sys.exit()
  continue
  
print('UNRESTORABLE')

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

int main() {
    long long int X; cin >> X;
    long long int yokin = 100;
    long long int year = 1;
    
    while(true){
        yokin += yokin / 100;
        if(yokin >= X){
            break;
        }
        year ++;
    }

    cout << year << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main(void){
   int N;
   int Y;
   scanf("%d%d", &N,&Y);
   int x,y,z;
   for (x = 0; x < N+1; x++) {
      for ( y = 0; y < N + 1; y++) {
         z = N - x - y;
         if (z < 0) {
            break;
         }else{
            if (x*10000 + y*5000 + z*1000==Y) {
               printf("%d %d %d\n",x,y,z);
               return 0;
            }
         }
      }
   }
   printf("-1 -1 -1\n");
   return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define int         int64_t

using namespace std;

const int N = int(3e5) + 7;
const int mod = 998244353;

int fac[N], rev[N], n, a, b, k, res, cur, t;

int Pow(int x, int y) {
    int res = 1;
    while(y) {
        if(y & 1) res = res * x % mod;
        x = x * x % mod; y >>= 1;
    }
    return res;
}
int nCk(int n, int k) {return fac[n] * rev[k] % mod * rev[n - k] % mod;}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> a >> b >> k;
    fac[0] = rev[0] = 1;
    for(int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % mod;
    rev[n] = Pow(fac[n], mod - 2);
    for(int i = n - 1; i > 0; --i) rev[i] = rev[i + 1] * (i + 1) % mod;
    for(int i = 0; i <= n; ++i) {
        if(a * i > k) break;
        cur = k - a * i;
        if(cur % b != 0 || cur / b > n) continue;
        res += nCk(n, i) * nCk(n, cur / b) % mod;
    }
    cout << res % mod;
}


Measured memory_bytes: 4992
import math
N = int(input())
A = list(map(int,input().split()))
C = [0]*(N+1)
s=0
ds = [0]*N
def c(n,r):
    if(n<r): return 0
    return math.factorial(n)//(r*math.factorial(n-r))

for i in range(N):
    C[A[i]-1] += 1
for i in range(N):
    s +=c(C[i],2)
for i in range(N):
   print(s-C[A[i]-1]+1)


Measured memory_bytes: 26140
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
#define rep(n) for( int i = 0 ; i < n ; i++ )
#define REP(n) for( int i = 1 ; i <= n ; i++ )
#define repll(n) for( ll i = 0 ; i < n ; i++ )
#define REPll(n) for( ll i = 1 ; i <= n ; i++ )
#define rep2(n) for( int j = 0 ; j < n ; j++ )
#define REP2(n) for( int j = 1 ; j <= n ; j++ )
#define repll2(n) for( ll j = 0 ; j < n ; j++ )
#define REPll2(n) for( ll j = 1 ; j <= n ; j++ )
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n , m , b[102] = {} , c[102] = {};
    cin >> n >> m;
    string s[n] = {};
    for( int i = 0 ; i < n ; i++ ) cin >> s[i];
    for( int i = 0; i < n ; i++ ) {
      	for ( int j = 0 ; j < m ; j++ ) {
            if( s[i][j] == '#' ) {
              	b[i] = 1;
                c[j] = 1;
            }
        }
    }
    for( int i = 0 ; i < n ; i++ ) {
      	if( b[i] ) {
        	for( int j = 0 ; j < m ; j++ ) if( c[j] ) cout << s[i][j];
        	cout << endl;
   		}
	}
}


Measured memory_bytes: 3620
n = int(input())
city = list(map(int, input().split()))
hero = list(map(int, input().split()))
get = 0

if city[0] <= hero[0]:
    get = get + city[0]
    hero[0] = hero[0] - city[0]
else:
    get = get + hero[0]
    hero[0] = 0


for i in range(1,n):
    if city[i] <= hero[i-1]:
        get = get + city[i]
    elif (city[i] > hero[i-1]) & (city[i] <= hero[i] + hero[i-1]):
        get = get + city[i]
        hero[i] = hero[i] - (city[i] - hero[i-1])
    else:
        get = get + (hero[i-1] + hero[i])
        hero[i] = 0

if city[n] <= hero[n-1]:
    get = get + city[n]
else:
    get = get + hero[n-1]

print(get)

Measured memory_bytes: 19236
n = int(input())

a = list(map(int,input().split()))
b = []
add = 0
for i in a:
    add += i
    b.append(add)

for i in range(len(b)):
    if b[i]> add / 2:
        x = abs(add - 2 * b[i])
        y = add - 2 * b[i-1]
        ans = min(x,y)
        break
print(ans)

    
    
    




Measured memory_bytes: 26220
#include<bits/stdc++.h>
const int mod=1e9+7;
typedef long long ll;
using namespace std;

ll dp[2005];
int main()
{
    for(int i=0;i<=2004;i++) dp[i]=1;
    dp[0]=0;
    dp[1]=0;
    dp[2]=0;
    dp[3]=1;
    int n;cin>>n;
    for(int i=4;i<=n;i++)
    {
        for(int j=3;j<=i-3;j++)
            dp[i]=(dp[i]+dp[j])%mod;
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)










int main(){
    ll n, k;
    cin >> n >> k;
    vector<vector<ll>> g(n);
    REP(i, n - 1){
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    
    cout << (k * 
        [dfs = [&k, &g](auto f, ll now, ll par) -> ll {
            if(k < g[now].size()) return 0;
        
            ll res = 1;
            ll tmp = ((par == -1)? k - 1 : k - 2);
            for(auto &child : g[now]){
                if(child == par) continue;
                res *= tmp;
                res %= MOD;
                tmp--;
            }
            for(auto &child : g[now]){
                if(child == par) continue;
                res *= f(f, child, now);
                res %= MOD;
            }
            return res;
        }](ll now, ll par){ return dfs(dfs, now, par); }(0, -1) ) % MOD
    << endl;
}


Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
#define int long long   // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << "(" << pair_var.first << ", " << pair_var.second << ")";return os;}
// head

template<int T>
struct Node{
	char c;
	vector<int> nxt,idxs;
	int idx;
	Node(char c):c(c),nxt(T,-1),idx(-1){}
};




int q,m,n,k,res,tmp,tmp2;
int a[200010] = {};
int b[200010] = {};
VVI g(100010);
queue<int> que2;
double dp[301][301][301]={};
int c[4] = {};
string s;

double dfs(int i,int j,int k){
	if (dp[i][j][k] != -1) return dp[i][j][k];
	double t = 0;
	if (i) t += (double)i/(i+j+k)*dfs(i-1,j,k);
	if (j) t += (double)j/(i+j+k)*dfs(i+1,j-1,k);
	if (k) t += (double)k/(i+j+k)*dfs(i,j+1,k-1);
	t += (double)n/(i+j+k);
	dp[i][j][k] = t;
	return t;
}

signed main() {
	cin.tie(0);
    ios::sync_with_stdio(false);
	std::cin >>n;
	rep(i,0,n){
		cin>>tmp;
		c[tmp] += 1;
	}
	rep(i,0,n+1){
		rep(j,0,n+1){
			rep(k,0,n+1){
				dp[i][j][k] = -1;
			}
		}
	}	
	dp[0][0][0] = 0;

	cout<< fixed << setprecision(12) <<dfs(c[1],c[2],c[3])<<endl;
}

Measured memory_bytes: 217728
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;

typedef long long s64;

const int L = 86;
const int M = 1000000007;

int nQ;

s64 f[L + 2];

struct object
{
	s64 x, y;
	object() {}
	object(const s64 &_x, const s64 &_y)
		: x(_x), y(_y) {}
};
vector<object> ex[L + 1];

int main()
{
	ios::sync_with_stdio(false);

	f[0] = f[1] = 1;
	for (int i = 2; i <= L + 1; ++i)
		f[i] = f[i - 1] + f[i - 2];

	ex[1].emplace_back(1, 2);
	ex[1].emplace_back(1, 3);
	ex[1].emplace_back(1, 4);
	for (int i = 1; i <= L - 3; ++i)
	{
		s64 lim = f[i] + f[i + 3];

		for (object k : ex[i])
		{
			s64 x = k.x, y = k.y;
			while ((x += y) <= lim)
				ex[i + 1].emplace_back(y, x);
		}
	}

	cin >> nQ;
	while (nQ--)
	{
		s64 n, m;
		cin >> n >> m;

		if (n > m)
			swap(n, m);

		int l = 1;
		while (f[l + 1] <= n && f[l + 2] <= m)
			++l;
		cout << l << ' ';

		if (l == 1)
			cout << (s64)n * m % M << endl;
		else
		{
			int res = 0;
			for (object k : ex[l - 1])
			{
				s64 x = k.x, y = k.y;
				if (y <= n)
					res = (res + (m - x) / y) % M;
				if (y <= m)
					res = (res + (n - x) / y) % M;
			}

			cout << res << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 4096
class BinaryIndexedTree:
    def __init__(self, size):
        size = 1 << (size-1).bit_length()
        self.data = [0] * (size+1)
        self.size = size
    
    def add(self, i, w):
        i += 1
        while i <= self.size:
            self.data[i] += w
            i += i & -i

    def sum(self, i):
        """
        [0,i)
        """
        result = 0
        while i > 0:
            result += self.data[i]
            i -= i & -i
        return result

    __getitem__ = sum

    def lower_bound(self, v):
        """
        return smallest i such that v < sum(data[:i])
        """

        s,pos = 0,0
        N = self.size
        k = N
        while k > 0:
            i = pos+k
            if i <= N:
                x = s+self.data[i]
                if x < v:
                    s = x
                    pos = i
            k >>= 1
        return pos

N = int(input())
S = input()
S = list(ord(c)-ord('a') for c in S)
bits = tuple(BinaryIndexedTree(N) for _ in range(26))

for i,c in enumerate(S):
    bit = bits[c]
    bit.add(i, 1)


def q1(i, c):
    i = int(i)-1
    bit = bits[S[i]]
    bit.add(i,-1)
    c = ord(c)-ord('a')
    bit = bits[c]
    bit.add(i,1)
    S[i] = c
def q2(l,r):
    l,r = int(l)-1,int(r)
    print(sum(bit.sum(r) > bit.sum(l) for bit in bits))


Q = int(input())
for _ in range(Q):
    q,x,y = input().split()

    if q == '1':
        q1(x,y)
    else:
        q2(x,y)


Measured memory_bytes: 154448
#include <stdio.h>

int solve(int,int);
int n,A[20];
int main(){
  int i,q,m;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(solve(0,m))printf("yes\n");
    else printf("no\n");
  }
  return 0;
}
int solve(int i,int m){
  int res;
  if(m==0)return 1;
  if(i>=n)return 0;
  res = solve(i+1,m)||solve(i+1,m-A[i]);
  return res;
}



Measured memory_bytes: 2108
#include<stdio.h>
int main(void)
{
    long int N,i,a=0,b=0,c=0;
    scanf("%ld",&N);
    scanf("%ld",&b);
    for(i=0;i<N-1;i++)
    {
        scanf("%ld",&a);
        if(b>a)
        {
            c+=b-a;
        }
        else b=a;
    }
    printf("%ld",c);
    return 0;
}

Measured memory_bytes: 1728
H, W, N = map(int, input().split())
S = set()
toCheck = set()
rs = [0] * 10
for _ in range(N):
    a, b = map(int, input().split())
    S.add((a, b))
    for i in range(3):
        for j in range(3):
            toCheck.add((a - i, b - j))

for a, b in toCheck:
    if a + 2 > H or b + 2 > W or b < 1 or a < 1:
        continue
    cnt = 0
    for i in range(3):
        for j in range(3):
            na, nb = a + i, b + j
            if (na, nb) in S:
                cnt += 1
    rs[cnt] += 1

total = max(0, H - 2) * max(0, W - 2)
rs[0] = total - sum(rs[1:])
for it in rs:
    print(it)




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

int main() {
	int n,x,y;
	cin>>n;
	bool f=false,s=false;
	while(n--){
	    cin>>x>>y;
	    if(x==y){
	        if(s){ cout<<"Yes";break;}
	        else if(f)s=true;
	        else f=true;
	    }
	    else{
	        f=false;
	        s=false;
	    }
	}
	if(n==-1)
	cout<<"No";
	else{
	    while(n--){cin>>x>>y;}
	}
	return 0;
}

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

class UFDS {
public:
	vector<int> ufds, rank;
	UFDS(int n) {
		ufds = vector<int>(n+1, 0);
		rank = vector<int>(n+1, 0);
		for(int i = 0; i <= n; i++)
			ufds[i] = i;
	}

	int find(int a) {
		while(ufds[a] != a) {
			int pa = ufds[a];
			if(pa != ufds[pa]) {
				ufds[a] = ufds[pa];
			}
			a = ufds[pa];
		}
		return a;
	}

	void join(int a, int b) {
		a = find(a);
		b = find(b);
		if(rank[b] > rank[a]) {
			rank[b] += rank[a];
			ufds[a] = b;
		} else {
			rank[a] += rank[b];
			ufds[b] = a;
		}
	}
};

int main () {
	ios::sync_with_stdio(false);

	int n, m;
	cin >> n >> m;
	UFDS ufds(n);

	vector<int> p(n+1,0);
	for(int i = 1; i <= n; i++)
		cin >> p[i];

	while(m--) {
		int a, b;
		cin >> a >> b;
		ufds.join(a, b);
	}

	int total = 0;
	for(int i = 1; i <= n; i++) {
		if(ufds.find(i) == ufds.find(p[i]))
			total++;
	}

	cout << total << endl;

	return 0;
}


Measured memory_bytes: 1408
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N), elements(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i]--;
    elements[A[i]]++;
  }
  ll base_comb_num = 0, e_n, e_k;
  for (int n = 0; n < N; n++) {
    e_n = elements[n];
    if (e_n != 0) base_comb_num += e_n * (e_n - 1) / 2;
  }
  for (int k = 0; k < N; k++) {
    e_k = elements[A[k]];
    ll new_e_k = e_k - 1;
    ll ans = base_comb_num;
    if (new_e_k > 0) {
      ans -= (e_k * (e_k - 1) / 2);
      ans += (new_e_k * (new_e_k - 1) / 2);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 5760
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//



int main(void) {

    ld r; cin >> r;
    ld ans = r * 6.283185;
    out(ans);
    


    


    return 0;
}











Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define SORT(i) sort((i).begin(),(i).end())
#define INF 2000000000
constexpr ll mod = 1000000007;

int coudp[100001];

int main() {
	string s;
	cin >> s;
	if (s == "Sunny") {
		cout << "Cloudy" << "\n";
	}
	else if (s == "Cloudy") {
		cout << "Rainy" << "\n";
	}
	else {
		cout << "Sunny" << "\n";
	}

	return 0;
}

Measured memory_bytes: 256
using System;

namespace C
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var ss = new string[n];
			for (var i = 0; i < n; i++) { ss[i] = Console.ReadLine(); }

			var alphabetNums = new int[26];
			for (var i = 0; i < 26; i++) { alphabetNums[i] = 100; }

			foreach (var s in ss)
			{
				var tmpAlphabetNums = new int[26];
				for (var i = 0; i < 26; i++) { tmpAlphabetNums[i] = 0; }

				foreach (var c in s) { tmpAlphabetNums[c - 'a']++; }

				for (var i = 0; i < 26; i++)
				{
					if (alphabetNums[i] > tmpAlphabetNums[i]) { alphabetNums[i] = tmpAlphabetNums[i]; }
				}
			}

			for (var i = 0; i < 26; i++)
			{
				for (var j = 0; j < alphabetNums[i]; j++) { Console.Write((char) ('a' + i)); }
			}

			Console.WriteLine();
		}
	}
}

Measured memory_bytes: 13140
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int k = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        long num = 1;
        if (a < k && a + 1 < b) {
            num += a - 1;
            long remainK = k - (a - 1);

            long add = b - a;
            num += remainK / 2 * add;
            num += remainK % 2 == 0 ? 0 : 1;

        } else {
            num += k;
        }

        long result = num;

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 23380
const input = require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);
const nin=()=>{const r = input[0];input.shift();return Number(r)};
const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};
const sin=()=>{const r = input[0];input.shift();return String(r)}
const out = (...a) => {console.log(...a)}
const floor = (a) => {return Math.floor(a)}
const min = (...a) => {return Math.min(...a)}
const rep = (n, callback) => {for(let i = 0;i < n; i++){callback()}}

const main = () => {
  let [a,b] = [...nrin(2)];
  out(floor(((a*3+b)/2)));
}
main();

Measured memory_bytes: 7372
#include<stdio.h>
main(){
  double weight;
  while(scanf("%lf",&weight) != EOF){
    if(weight<=48)printf("light fly\n");
    else if(weight>48 && weight<=51)printf("fly\n");
    else if(weight>51 && weight<=54)printf("bantam\n");
    else if(weight>54 && weight<=57)printf("feather\n");
    else if(weight>57 && weight<=60)printf("light\n");
    else if(weight>60 && weight<=64)printf("light welter\n");
    else if(weight>64 && weight<=69)printf("welter\n");
    else if(weight>69 && weight<=75)printf("light middle\n");
    else if(weight>75 && weight<=81)printf("middle\n");
    else if(weight>81 && weight<=91)printf("light heavy\n");
    else if(weight>91)printf("heavy\n");
	    }
    return 0;
  }

Measured memory_bytes: 608