akhauriyash/Code-Regression huggingface dataset:
//by Sshwy
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/
const int N=5005,P=1e9+7;

int n;
vector<int> T[N];

int sz[N];
int f[N][N][2];//f[i,j,0/1]表示第i个点的子树，i所在的连通块大小为j，被割掉的边的奇偶性 的容斥贡献。
//转移的时侯在割边时才统计与i连通的部分的贡献。
int g[N];//g[i]表示有i个点的配对方案
int t[N][2];

void add(int &x,int y){x=(x+y)%P;}
void dfs(int u,int p){
    for(int v:T[u])if(v!=p)dfs(v,u);

    sz[u]=1;
    f[u][1][0]=1;//方案数为1

    for(int v:T[u])if(v!=p){
        memset(t,0,sizeof(t[0])*(sz[u]+sz[v]+1));
        //不割边
        FOR(i,1,sz[u]){
            FOR(j,1,sz[v]){
                add(t[i+j][0],1ll*f[u][i][0]*f[v][j][0]%P);
                add(t[i+j][0],1ll*f[u][i][1]*f[v][j][1]%P);
                add(t[i+j][1],1ll*f[u][i][0]*f[v][j][1]%P);
                add(t[i+j][1],1ll*f[u][i][1]*f[v][j][0]%P);
            }
        }
        //割边
        FOR(i,1,sz[u]){
            FOR(j,1,sz[v]){
                add(t[i][0],1ll*f[u][i][0]*f[v][j][1]%P*g[j]%P);
                add(t[i][0],1ll*f[u][i][1]*f[v][j][0]%P*g[j]%P);
                add(t[i][1],1ll*f[u][i][1]*f[v][j][1]%P*g[j]%P);
                add(t[i][1],1ll*f[u][i][0]*f[v][j][0]%P*g[j]%P);
            }
        }
        memcpy(f[u],t,sizeof(t[0])*(sz[u]+sz[v]+1));
        sz[u]+=sz[v];
    }
}
int main(){
    scanf("%d",&n);
    FOR(i,1,n-1){
        int u,v;
        scanf("%d%d",&u,&v);
        T[u].pb(v),T[v].pb(u);
    }

    g[2]=1;
    FOR(i,2,n/2)g[i*2]=g[i*2-2]*(i*2-1ll)%P;
    
    dfs(1,0);
    int ans=0;
    FOR(i,1,n){
        if(f[1][i][0])add(ans,f[1][i][0]*1ll*g[i]%P);
        if(f[1][i][1])add(ans,-f[1][i][1]*1ll*g[i]%P);
    }
    add(ans,P);
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 195456
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N, M;
  while (cin >> N >> M) {
    map<int, int> mp;
    for (int i = 0; i < N; i++) {
      int x;
      cin >> x;
      ++mp[x];
    }
    vector<int> g(M, 0), m(M, 0);
    for (auto e : mp) {
      int x = e.first % M, cnt = e.second;
      m[x] += cnt;
      g[x] += cnt / 2;
    }
    int res = 0;
    for (int i = 0; i <= M - i; i++) {
      int j = (M - i) % M;
      if (i == j) {
        res += m[i] / 2;
      } else {
        int best = 0;
        for (int lower = 0, upper = min(m[i], m[j]); lower <= upper; lower++) {
          int ai = min(g[i], (m[i] - lower) / 2);
          int aj = min(g[j], (m[j] - lower) / 2);
          best = max(best, ai + aj + lower);
        }
        res += best;
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 5760
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <utility>
#include <vector>

int main() {
  size_t N;
  intmax_t K;
  scanf("%zu %jd", &N, &K);

  std::vector<std::pair<int, int>> ab(N);
  for (size_t i=0; i<N; ++i)
    scanf("%d %d", &ab[i].first, &ab[i].second);

  std::sort(ab.begin(), ab.end());
  for (size_t i=0; i<N; ++i) {
    K -= ab[i].second;
    if (K <= 0)
      return !printf("%d\n", ab[i].first);
  }
}


Measured memory_bytes: 1024
#include <stdio.h>

int main()
{
	char a[6];
	scanf("%s", &a);
	
	if(a[2] == a[3] && a[4] == a[5])
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

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

P p[5000];
vector<int>dat[50000];
void init(int k, int l, int r) {
	if (r - l == 1) {
		dat[k].push_back(p[l].second); return;
	}
	int lb = k * 2 + 1, rb = k * 2 + 2;
	init(lb, l, (l + r) / 2);
	init(rb, (l + r) / 2, r);
	dat[k].resize(r - l);
	merge(dat[lb].begin(), dat[lb].end(), dat[rb].begin(), dat[rb].end(), dat[k].begin());
}
int query(int a, int b, int c, int d, int k, int l, int r) {
	if (b <= l || r <= a)return 0;
	if (a <= l&&r <= b) {
		int u = upper_bound(dat[k].begin(), dat[k].end(), d) - dat[k].begin();
		int v = upper_bound(dat[k].begin(), dat[k].end(), c - 1) - dat[k].begin();
		return u - v;
	}
	int lb = query(a, b, c, d, k * 2 + 1, l, (l + r) / 2);
	int rb = query(a, b, c, d, k * 2 + 2, (l + r) / 2, r);
	return lb + rb;
}
int main() {
	int n, q; scanf("%d%d", &n, &q);
	rep(i, n)scanf("%d%d", &p[i].first, &p[i].second);
	sort(p, p + n); init(0, 0, n);
	rep(i, q) {
		int sx, tx, sy, ty; scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
		int a = lower_bound(p, p + n, P(sx, INT_MIN)) - p;
		int b = lower_bound(p, p + n, P(tx, INT_MAX)) - p;
		printf("%d\n", query(a, b, sy, ty, 0, 0, n));
	}
}

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

int main(){
    
    long long int N,P;cin>>N>>P;
    if(N==1) cout<<P<<endl;
    else if(N<=50){
        long long int ans=1;
        for(long long int i=2;i<=P;i++){
            long long int Q=P;
            bool flag=true;
            for(int j=0;j<N;j++){
                if(Q%i!=0) flag=false;
                Q/=i;
            }
            if(flag) ans=i;
            if(Q==0) break;
        }
        cout<<ans<<endl;
    }
    else cout<<1<<endl;
}



Measured memory_bytes: 256
import sys

A, B = list(map(int, input().split()))

l = int(A / 0.08 + 1 - 1e-8)
r = int((A + 1) / 0.08 + 1 - 1e-8)

x = -1
for i in range(l, r):
    if int(i * 0.1) == B:
        x = i
        break

print(x)

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

int main() {
    vector<string> s(3);
    for (int i = 0; i < 3; i++) {
        cin >> s[i];
    }

    int b = 'A' - 'a';
    for (int i = 0; i < 3; i++) {
        cout << char(s[i][0] + b);
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())
if abs(a - b) % 2:
    te = [a - 1, b - 1]
    te.sort()
    rem = te[1] - te[0] + 1
    cand1 = te[0] + rem // 2

    te = [n - a, n - b]
    te.sort()
    rem = te[1] - te[0] + 1
    cand2 = te[0] + rem // 2
    print(min(cand1, cand2))
else:
    print(abs(a-b)//2)


Measured memory_bytes: 3064
card = [list(map(int,input().split())) for i in range(3)]
n = int(input())
for i in range(n):
    num = int(input())
    for i in range(3):
        for j in range(3):
            if card[i][j] == num:
                card[i][j] = 0
for i in range(3):
    if  (card[0][i] == 0 and card[1][i] == 0 and card[2][i] == 0) or\
        (card[i][0] == 0 and card[i][1] == 0 and card[i][2] == 0):
        print("Yes")
        exit()
if  (card[0][0] == 0 and card[1][1] == 0 and card[2][2] == 0) or\
    (card[0][2] == 0 and card[1][1] == 0 and card[2][0] == 0):
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 38256
fun main(args: Array<String>){
    val len = readLine()!!.toInt()
    val s = readLine()!!
    val lc = mutableListOf<Char>()
    for(i in 0..(len - 1)){
        lc.add(s[i])
    }
    lc.sort()
    var ret = 1L
    var i = 0
    while(i < len){
        val c = lc[i]
        var cnt = 1L
        while(++i < len){
            if(lc[i] != c) break
            cnt++
        }
        ret = (ret * (cnt + 1L)) % 1000000007L
    }
    println(ret - 1)
}


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

int main() {
    ll n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    vector<ll> sum;
    bool is0=s[0]=='0';
    ll point=0;
    sum.push_back(0);
    rep(i,n){
        if(s[i]=='0'){
            if(!is0){
                is0=true;
                point++;
                sum.push_back(0);
            }
        }else{
            if(is0){
                is0=false;
                point++;
                sum.push_back(0);
            }
        }
        sum[point]++;
    }
    vector<ll> zpos;
    if(s[0]=='0'){
        rep(i,sum.size()){
            if(i%2==0)zpos.push_back(i);
        }
    }else{
        rep(i,sum.size()){
            if(i%2==1)zpos.push_back(i);
        }
    }
    if(zpos.size()<=k){
        cout<<n<<endl;
        return 0;
    }
    ll ans=0;
    for(ll i=0;i+k<=zpos.size();i++){
        ll tmp=0;
        for(ll j=i;j<i+k;j++){
            if(zpos[j]!=0)tmp+=sum[zpos[j]-1];
            tmp+=sum[zpos[j]];
        }
        if(sum.size()-1>zpos[i+k-1])tmp+=sum[zpos[i+k-1]+1];
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2036
#include<iostream>
#include<iomanip>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<cmath>
using namespace std;
typedef vector<int> vi;
const int MAX_V=1e3+5;
const int INF=1e9;
bool cando[505][505];
int gcd(int a, int b)
{
  if(b==0) return a;
  return gcd(b,a%b);
}
struct edge
{
  int to,cap,rev;
};

bool used[MAX_V];

void add_edge(int from,int to,int cap,vector<edge> *G)
{
  edge F;
  edge T;
  F.to=to;
  F.cap=cap;
  F.rev=G[to].size();
  G[from].push_back(F);

  T.to=from;
  T.cap=0;
  T.rev=G[from].size()-1;
  G[to].push_back(T);
}

int dfs(int v,int t,int f,vector<edge> *G)
{
  if(v==t) return f;
  used[v]=true;
  for(int i=0;i<G[v].size();i++)
    {
      edge &e=G[v][i];
      if(!used[e.to] && e.cap>0)
	{
	  int d=dfs(e.to,t,min(f,e.cap),G);
	  if(d>0)
	    {
	      e.cap-=d;
	      G[e.to][e.rev].cap+=d;
	      return d;
	    }
	}
    }
  return 0;
}

int max_flow(int s,int t,vector<edge> *G)
{
  int flow=0;
  while(1)
    {
      memset(used,false,sizeof(used));
      int f=dfs(s,t,INF,G);
      if(f==0) return flow;
      flow+=f;
    }
}

int main(void)
{
  int m,n;
  while(cin >> m >> n && m)
    {
      memset(cando,false,sizeof(cando));
      memset(used,false,sizeof(used));
      vector<edge> G[1005];
      int s=n+m;
      int t=s+1;
      vector<int> blue;
      vector<int> red;
      for (int i = 0; i < m; ++i)
	{
	  int b;
	  cin >>b;
	  blue.push_back(b);
	  add_edge(s,i,1,G);
	}
      for (int i = 0; i < n; ++i)
	{
	  int r;
	  cin >> r;
	  red.push_back(r);
	  add_edge(m+i,t,1,G);
	}
      for (int i = 0; i < m; ++i)
	{
	  for(int j=0;j<n;j++)
	    {
	      if(gcd(blue[i],red[j])>1)
		{
		  add_edge(i,m+j,1,G);
		}
	    }
	}
      cout << max_flow(s,t,G) << endl;
    }
}



Measured memory_bytes: 7708
//### In The Name Of GOD ###

//%% Remember; (((He))) is The (((Accepter))) %%

// GOD IS GREATER ...

#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;

#define int ll
#define pb push_back
#define bp pop_back
#define X first
#define Y second
#define sz(a) (int)(a.size())

const int MAXN = 1e5 + 10; // ios_base :: sync_with_stdio(false);

signed main() {
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	int a[MAXN], sum = 0;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a, a + n, greater<int>());
	int dp[MAXN], ans = 0;
	dp[0] = true;
	for(int i = 1; i < n; i++) {
		sum -= a[i - 1];
		dp[i] = dp[i - 1] && (a[i - 1] <= 2 * sum);
		ans += dp[i];
	}
	cout << ans + 1;
}


Measured memory_bytes: 1792
def gcd(x, y):
    if x < y:
        x, y = y, x
    while x % y != 0:
        x, y = y, x % y
    return y
        
def lcm(x, y):
    return (x * y) // gcd(x, y)

A,B,C,D = map(int,input().split())
#A = list(map(int,input().split()))

c_b  = B//C
d_b  = B//D
cd_b = B//lcm(C,D)

c_a  = (A-1)//C
d_a  = (A-1)//D
cd_a = (A-1)//lcm(C,D)

ans = (B - c_b - d_b + cd_b) - (A - 1 - c_a - d_a + cd_a)



print(str(ans))

Measured memory_bytes: 38704
#!/usr/bin/python
# coding: utf-8
import os
from sys import stdin, stdout

if(os.getenv('__LOCAL__')):
    __dirname = os.path.dirname(__file__)
    __basename = os.path.splitext(os.path.basename(__file__))[0]
    __inputname = './input/' + __basename + '.txt'
    __outputname = './output/' + __basename + '.txt'
    __input_path = os.path.join(__dirname, __inputname)
    __output_path = os.path.join(__dirname, __outputname)
    stdin = open(__input_path)
    # stdout = open(__output_path, "w")

def main():
    A, B, Q = map(int, stdin.readline().rstrip().split(' '))
    s = list()
    t = list()
    s.append(-1e12)
    t.append(-1e12)
    s += [int(stdin.readline()) for _ in range(A)]
    t += [int(stdin.readline()) for _ in range(B)]
    X = [int(stdin.readline()) for _ in range(Q)]
    ansvec = list()
    s.append(1e12)
    t.append(1e12)
    # stdout.write("{}\n".format(s))
    # stdout.write("{}\n".format(t))
    # stdout.write("{}\n".format(X))
    for x in X:
        ls = 0
        rs = A+2
        lt = 0
        rt = B+2
        while(rs-ls>1):
            mids=(ls+rs)//2
            if(s[mids]<=x):
                ls = mids
            else:
                rs = mids

        while(rt-lt>1):
            midt=(lt+rt)//2
            if(t[midt]<=x):
                lt = midt
            else:
                rt = midt

        if(t[lt]<=s[ls] and s[rs]<=t[rt]):
            ans = min(abs(t[lt]-x),abs(t[rt]-x))
        elif(s[ls]<=t[lt] and t[rt]<=s[rs]):
            ans = min(abs(s[ls]-x),abs(s[rs]-x))
        elif(s[ls]<=t[lt] and s[rs]<=t[rt]):
            ans = min(abs(s[ls]-x),abs(t[rt]-x), 2*abs(s[rs]-x)+abs(t[lt]-x), 2*abs(t[lt]-x)+abs(s[rs]-x))
        elif(t[lt]<=s[ls] and t[rt]<=s[rs]):
            ans = min(abs(t[lt]-x),abs(s[rs]-x), 2*abs(s[ls]-x)+abs(t[rt]-x), 2*abs(t[rt]-x)+abs(s[ls]-x))
        ansvec.append(ans)

    for a in ansvec:
        stdout.write("{}\n".format(a))

if __name__ == "__main__":
    main()

Measured memory_bytes: 20224
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

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

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

int keta(int x) {
	int y = 0;
	while (x > 0) {
		y++;
		x /= 10;
	}
	return y;
}

ll dx[8] = { 0,0,-1,1 };
ll dy[8] = { -1,1,0,0 };
ll dp[101010];

//long longしか使わない
int main() {
	double a, b, h, m;
	cin >> a >> b >> h >> m;
	double hour = 30 * h + 0.5 * m;
	double mini = 6 * m;
	double angle = min(abs(hour - mini), 360 - abs(hour - mini));
	angle /= 180;
	angle *= M_PI;
	double ans = sqrt(a * a + b * b - 2 * a * b * cos(angle));
	printf("%.12f\n", ans);
	return 0;
}


Measured memory_bytes: 4236
package main

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

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func getFloat() float64 {
	sc.Scan()
	n, _ := strconv.ParseFloat(sc.Text(), 64)
	return n
}

func sum(n []int) int {
	a := 0
	for _, v := range n {
		a += v
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)
	x := getInt()

	if x == 3 || x == 5 || x == 7 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const long double Pi=acos(-1);
ll pow(ll a,ll b){
  if(b==0){
    return 1;
  }else if(b%2==0){
    return(pow(a*a,b/2));
  }else{
    return(a*pow(a,b-1));
  }
}
ll gcd(ll a,ll b) {
  if(a%b==0){
    return(b);
  }else{
    return(gcd(b,a%b));
  }
}
ll lcm(ll a,ll b){
  return a*b/gcd(a,b);
}
ll log2(ll a,ll count){
  if(a%2==0){a/=2;count++;log2(a,count);}
  else{return count;}
}
int main(){
  ll N,M,ans=1;
  cin>>N>>M;
  vector<ll> a(N);
  for(ll i=0;i<N;i++){
    ll d;
    cin>>d;
    a.at(i)=d/2;
    ll memo=ans;
    ans=lcm(ans,a.at(i));
    if(i>=1){if(log2(a.at(i),0)!=log2(a.at(i-1),0)){cout<<0<<endl;return 0;}}
    if(ans>M){cout<<0<<endl;return 0;}
    else{continue;}
  }
  cout<<(M-ans)/(2*ans)+1<<endl;
}

Measured memory_bytes: 1024
import Control.Monad

solve :: [String] -> [(Int, Int)] -> (Int, Int) -> [Bool]
solve _ [] _ = []
solve ss (xy:xys) hw = check ss xy hw : solve ss xys hw

check :: [String] -> (Int, Int) -> (Int, Int) -> Bool
check ss (x, y) (h, w) = dot || sharp
  where f (a, b) = a>=0 && a<w && b>=0 && b<h
        t = filter f [(x-1, y), (x, y-1), (x+1, y), (x, y+1)]
        dot = ss !! y !! x == '.'
        sharp = any (\(tx, ty) -> ss !! ty !! tx == '#') t

main :: IO ()
main = do
  [h, w] <- map read . words <$> getLine
  ss <- replicateM h getLine
  let t = [(x, y) | x <- [0..w-1], y <- [0..h-1]]
  putStrLn $ if and $ solve ss t (h, w) then "Yes" else "No"

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

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

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

    Unionfind(int n) : par(n) {
        for(int i = 0; i < n; ++i) par[i] = i;
    }

    int root(int x) {
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] =ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    int n;
    cin >> n;

    vector<int> a(n);
    vector<int> cnt(n+1, 0);

    rep(i, n) {
        cin >> a[i];
        ++cnt[a[i]];
    }

    ll total = 0;
    for(int i = 1; i <= n; ++i) {
        if(cnt[i] < 2) continue;
        total += ll(cnt[i]) * (cnt[i] - 1) / 2;
    }

    rep(i, n) {
        ll ans = 0;
        ans = total - (cnt[a[i]] - 1);
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 4788
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final char[] chs = sc.next().toCharArray();
			
			int answer = 0;
			
			int leftW = 0;
			int rightR = N - 1;
			while(true) {
				while(leftW < N && chs[leftW] == 'R') { leftW++; }
				while(rightR >= 0 && chs[rightR] == 'W') { rightR--; }
				
				if(leftW > rightR) { break; }
				
				if(leftW < N && rightR >= 0) {
					chs[leftW++] = 'R';
					chs[rightR--] = 'W';
					answer++;
				}else if(leftW < N){
					chs[leftW++] = 'R';
					answer++;
				}else if(rightR >= 0) {
					chs[rightR--] = 'W';
					answer++;
				}
			}
			
			//System.out.println(Arrays.toString(chs));
			System.out.println(answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


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


Measured memory_bytes: 3284
//1521159
//AOJ0006

#include<stdio.h>
#include<string.h>

#define MAX 1000

int main()
{
	int i,len;
	char str[MAX];
	while (1)
	{
		scanf("%s", &str);
		len = strlen(str);
		if (0 <= len && len <= 20){
			break;
		}
	}

	for (i=len-1; i >= 0; i--){
		printf("%c", str[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 524
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
	int N;
	vector<int> data;

	while (1){
		data.clear();
		scanf("%d", &N);
		if (N == 0)break;

		for (int i = 0; i < N; i++){
			int temp;
			scanf("%d", &temp);
			data.push_back(temp);
		}
		bool flag = false;
		for (int i = 0; i < N; i++){
			if (data[i] > 1){
				flag = true;
				break;
			}
		}
		if (!flag){
			printf("NA\n");
		}
		else{
			if(N == 1)
				printf("2\n");
			else{
				int ans = 1;
				for (int i = 0; i < N; i++){
					if (data[i] != 0 )ans++;
				}
				printf("%d\n", ans);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1168
import java.util.Scanner;
 
public class Main {
	
	public static void main(String[] args) throws Exception{	
		Scanner sc = new Scanner(System.in);

		int w = sc.nextInt();
		int h = sc.nextInt();
		int n = sc.nextInt();
		
		int x, y, a;
		
		int x1 = 0;
		int x2 = w;
		int y1 = 0;
		int y2 = h;
		
		for(int i=0; i<n; i++){
			x = sc.nextInt();
			y = sc.nextInt();
			a = sc.nextInt();
			
			if(a == 1){ if(x1 < x) x1 = x; }
			else if(a == 2){ if(x2 > x) x2 = x; }
			else if(a == 3){ if(y1 < y) y1 = y; }
			else if(y2 > y) y2 = y;
		}
		
		if(x2 - x1 < 0 || y2 - y1 < 0) System.out.println(0);
		else System.out.println((x2 - x1) * (y2 - y1));
		
		sc.close();
	}
}

Measured memory_bytes: 10324
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
  int N;
  cin >> N;
  map<string, int> blue{};
  rep(i, N) {
    string str;
    cin >> str;
    blue[str] += 1;
  }
  
  int M;
  cin >> M;
  map<string, int> red{};
  rep(i, M) {
    string str;
    cin >> str;
    red[str] += 1;
  }
  
  int ans = 0;
  for (auto itr : blue) {
    ans = max(ans, itr.second - red[itr.first]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>

#include <iostream>

template <typename T> struct edge {
  int to;
  T cost;
};

template <typename T>
std::vector<std::vector<T>>
warshallFloyd(const int size, const std::vector<std::vector<edge<T>>> &g,
              const T init) {

  std::vector<std::vector<T>> d(size);

  for (int i = 0; i < size; i++) {
    for (int j = 0; j < size; j++) {
      if (i == j) {
        d[i].push_back(0);
      } else {
        d[i].push_back(init);
      }
    }
  }

  for (int i = 0; i < size; i++) {
    for (const auto &e : g[i]) {
      d[i][e.to] = e.cost;
    }
  }

  for (int k = 0; k < size; k++) {
    for (int i = 0; i < size; i++) {
      for (int j = 0; j < size; j++) {
        if (d[i][k] != init && d[k][j] != init)
          d[i][j] = std::min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  return d;
}

// verify: https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/all/GRL_1_C
int main() {
  int v, e;
  std::cin >> v >> e;
  std::vector<std::vector<edge<long long int>>> g(v);

  for (int i = 0; i < e; i++) {
    int a, b;
    long long int c;
    std::cin >> a >> b >> c;
    g[a].push_back({b, c});
  }

  long long int MAX = 200000000001;
  auto d = warshallFloyd(v, g, MAX);

  bool negative_cycle = false;
  for (int i = 0; i < v; i++) {
    if (d[i][i] < 0LL) {
      negative_cycle = true;
      break;
    }
  }

  if (negative_cycle) {
    std::cout << "NEGATIVE CYCLE" << std::endl;
  } else {
    for (int i = 0; i < v; i++) {
      for (int j = 0; j < v; j++) {
        if (d[i][j] == MAX) {
          std::cout << "INF";
        } else {
          std::cout << d[i][j];
        }
        std::cout << (j != v - 1 ? " " : "\n");
      }
    }
  }
}



Measured memory_bytes: 3304
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n, k;
    cin >> n >> k;
    vint a(n);
    rep(i, n) cin >> a[i];

    ll total = accumulate(all(a), 0ll);
    vll b;
    ll num = 1;
    rep(i, 60) {
        b.push_back(num);
        num <<= 1;
    }
    sort(rall(b));
    vll ls;
    rep(i, n) {
        ll sum = 0;
        srep(j, i, n) {
            sum += a[j];
            ls.push_back(sum);
        }
    }
    
    ll ans = 0;
    for (ll x : b) {
        int count = 0;
        ll tmp = ans + x;
        for (ll y : ls) {
            if ((tmp & y) == tmp) count++;
            if (count >= k) {
                ans += x;
                break;
            }
        }
    }

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

Measured memory_bytes: 5496
/*input
4
10 80 90 30
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<int,int>
#define f first
#define s second
#define pb emplace_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
ll dp[3005][3005];
ll arr[maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	REP(i,n) cin>>arr[i];
	for(int i=n-1;i>=0;i--){
		for(int j=i;j<n;j++){
			if(i==j) dp[i][j]=arr[i];
			else dp[i][j]=max(arr[j]-dp[i][j-1],arr[i]-dp[i+1][j]);
		}
	}
	cout<<dp[0][n-1];
}

Measured memory_bytes: 69376
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define mod 1000000007
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes printf("Yes\n")
#define no printf("No\n")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using ull=unsigned long long;
using vi=vector<int>;
using pint=pair<int,int>;

const int INF = (1 << 30);

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    if(a>b){
        if(b==1){
            puts("Bob");
        }else{
            puts("Alice");
        }
    }else if(b>a){
        if(a==1){
            puts("Alice");
        }else{
            puts("Bob");
        }
    }else{
        puts("Draw");
    }

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#define inf 1000000000
using namespace std;

typedef pair<int, int> P;
struct edge{
	int to, cost;
	edge(int a, int b){
		to = a, cost = b;
	}
};

int K;
vector<edge> G[100005];
int dist[100005];

void dijkstra()
{
	for(int i = 0; i < K; i++) dist[i] = inf;
	dist[1] = 0;
	
	priority_queue< P, vector<P>, greater<P> > Q;
	Q.push( make_pair(0, 1) );
	
	int v; int d;
	while(Q.size()){
		d = Q.top().first;
		v = Q.top().second;
		Q.pop();
		if(dist[v] < d) continue;
		for(int i = 0; i < G[v].size(); i++){
			if(dist[G[v][i].to] > d + G[v][i].cost){
				dist[G[v][i].to] = d + G[v][i].cost;
				Q.push( make_pair(dist[G[v][i].to], G[v][i].to) );
			}
		}
	}
}

int main(void)
{
	cin >> K;
	for(int i = 0; i < K; i++){
		G[i].push_back(edge((i+1)%K, 1));
		G[i].push_back(edge((i*10)%K, 0));
	}
	
	dijkstra();
	cout << dist[0]+1 << endl;
	return 0;
}

Measured memory_bytes: 6780
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}

func Count(S [][]int, h1, w1, h2, w2 int) int {
  return S[h1 - 1][w1 - 1] + S[h2][w2] - S[h1 - 1][w2] - S[h2][w1 - 1]
}

func Solve() {
  var H, W, K int
  NextInt(&H, &W, &K)
  S := make([][]int, H + 1)
  for i := range S {
    S[i] = make([]int, W + 1)
  }
  for i := range S[1:] {
    for j, s := range NextLine() {
      if s == '1' { S[i + 1][j + 1]++ }
    }
  }
  for i := range S[1:] {
    for j := range S[i][1:] {
      S[i + 1][j + 1] += S[i + 1][j]
    }
  }
  for j := range S[0][1:] {
    for i := range S[1:] {
      S[i + 1][j + 1] += S[i][j + 1]
    }
  }
  ans := H + W
  top:
    for cut := 0; cut < 1 << uint(H - 1); cut++ {
      C := make([]int, 0)
      C = append(C, 0)
      for i, _c := 1, cut; 0 < _c; i, _c = i + 1, _c / 2 {
        if _c % 2 == 1 { C = append(C, i) }
      }
      C = append(C, H)
      w0 := 1
      cnt := len(C) - 2
      for w := 1; w <= W; w++ {
        for i, c := range C[1:] {
          if K < Count(S, C[i] + 1, w0, c, w) {
            if w == w0 { continue top }
            w0 = w
            cnt++
            if K < Count(S, C[i] + 1, w0, c, w) { continue top }
          }
        }
      }
      for i, c := range C[1:] {
        if K < Count(S, C[i] + 1, w0, c, W) {
          continue top
        }
      }
      ans = MinInt(cnt, ans)
  }
  Write(ans)
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 896
tformat = lambda num, time: '{} {:.2f}'.format(num, time)
runners = [[] for _ in range(3)]
thirds = []
for i in range(3):
    for _ in range(8):
        num, time = input().split()
        runners[i].append((float(time), int(num)))
    runners[i].sort()
    thirds += runners[i][2:]
thirds.sort()
for run in runners:
    for time, num in run[:2]:
        print(tformat(num, time))
for time, num in thirds[:2]:
    print(tformat(num, time))

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

int main() {
  int N, X[110];
  cin >> N;
  for (int i = 0; i < N; i++) cin >> X[i];
  int min_sum = 1e+8;
  for (int p = 1; p <= 100; p++) {
    int sum = 0;
    for (int i = 0; i < N; i++) sum += (X[i] - p) * (X[i] - p);
    min_sum = min(min_sum, sum);
  }
  cout << min_sum << endl;
}

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

using namespace std;
using ll = long long;
constexpr int mod = 1e9+7;
constexpr int md = mod;
int main(){
    int n;
    cin>>n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;++i){
        cin>>a[i];
        b[i] = a[i];
    }
    sort(b.begin(),b.end());
    int count = 0;
    for(int i=0;i<n;++i){
        a[i] = lower_bound(b.begin(),b.end(),a[i]) - b.begin();
        count += abs(a[i] - i)%2;
    }
    cout << count/2 << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

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

	if (n == 100)
	{
		n = 101;
	}

	switch (d)
	{
	case 0:
		cout << n << endl;
		break;

	case 1:
		cout << n * 100 << endl;
		break;

	case 2:
		cout << n * 10000 << endl;
		break;

	default:
		break;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
const int N = 1e5;  // limit for array size
ll n;  // array size

int main(){
    string s;cin>>s;
    if(s=="ABC"){
       cout<<"ARC"<<endl;}
    if(s=="ARC"){
       cout<<"ABC"<<endl;}
	return 0;
}



Measured memory_bytes: 3628
mod = 10**9 + 7
n = int(input())
s = input()
ret = [0]*27
for c in s:
    i = ord(c) - ord("a")
    ret[i] += 1

DP = [[0]*28 for i in range(28)]
DP[0][0] = 1
for i in range(1,28):
    DP[i][0] = 1
    for j in range(1,28):
        DP[i][j] = (DP[i-1][j] + DP[i-1][j-1]*ret[i-1]) % mod
ans = 0
for i in DP[-1]:
    ans = (ans + i) % mod
print(ans -1)

Measured memory_bytes: 3188
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

unsigned char D[252004];
bool E[252004];
int Q[252004];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint();
	int n = N + 2;
	rep1(i, N) {
		int ij = n * i + 1;
		unsigned char kari = min(i - 1, N - i);
		unsigned char kari2 = 3;

		rep(j, kari) {
			D[ij++] = kari2++;
		}
		rep(j, N - kari - kari) {
			D[ij++] = kari + 3;
		}
		rep(j, kari) {
			D[ij++] = --kari2;
		}
	}

	int kotae = 0;
	rep(k, N * N) {
		int ij = getint();
		ij += (ij - 1) / N * 2 + N + 2;

		kotae += D[ij];
		E[ij] = 1;

		int p = 0, q = 0;
		Q[p++] = ij;

		while (p > q) {
			int ij = Q[q++];
			int d =	D[ij] - E[ij] + 1;

			if (D[ij - n] > d) {
				D[ij - n] = d;
				Q[p++] = ij - n;
			}
			if (D[ij + n] > d) {
				D[ij + n] = d;
				Q[p++] = ij + n;
			}
			if (D[ij - 1] > d) {
				D[ij - 1] = d;
				Q[p++] = ij - 1;
			}
			if (D[ij + 1] > d) {
				D[ij + 1] = d;
				Q[p++] = ij + 1;
			}
		}
	}

	printf("%d\n", kotae - 3 * N * N);



	Would you please return 0;
}

Measured memory_bytes: 4488
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  string T;
  cin >> T;

  string ans;
  rep(i, T.size()) {
    char c = T[i];
    if (c == '?')
      ans += 'D';
    else
      ans += c;
  }
  out(ans);
}


Measured memory_bytes: 3892
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <random>
#include <set>
#include <map>
#include <queue>
#include <bitset>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)

int main(){
	int n,k,t,ans=0;
	cin >> n;
	cin >> k;
	FOR(i,0,n-1){
		cin >> t;
		ans += (k>=t);
		k = t;
	}
	cout << min(ans+1,n) << endl << n << endl;
}



Measured memory_bytes: 3108
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 100000;
int main() {
    int n,m;
    cin >> n >> m;
    int a[m + 1],b[m + 1];
    for (int i = 1; i <= m; i++) {
        cin >> a[i] >> b[i];
    }
    int ret = 0;
    for (int i = 1; i <= m; i++) {
        //辺 i は使わない時
        bool check = false; //橋かどうか
        for (int j = 1; j <= n; j++) {
            // 頂点 j から他のところに行けるか
            bool d[n + 1];
            for (int temp = 1; temp <= n; temp++) {
                d[temp] = false;
            }
            d[j] = true;
            bool update = true;
            while(update) {
                update = false;
                for (int s = 1; s <= m; s++) {
                    if ((d[a[s]])&&(s != i)&&(d[b[s]] == false)) {
                        d[b[s]] = true;
                        update = true;
                    }
                    else if(((d[b[s]])&&(s != i)&&(d[a[s]] == false))) {
                        d[a[s]] = true;
                        update = true;
                    }
                }
            }
            for (int p = 1; p <= n; p++) {
                if (!d[p]) {
                    check = true;
                }
            }
        }
        if (check) {
            ret++;
        }
    }
    cout << ret;
    return 0;
}

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

char A[1000] = {0},B[1000] = {0};

int main()
{
    scanf("%s%s",A,B);
    int lA = strlen(A),lB = strlen(B);
    if(lA > lB)printf("GREATER\n");
    else if(lA < lB)printf("LESS\n");
    else
    {
        for(int i = 0; i < lA + 1; i++)
        {
            if(i == lA){printf("EQUAL\n");break;}
            if(A[i] > B[i]){printf("GREATER\n");break;}
            else if(A[i] < B[i]){printf("LESS\n");break;}
        }
    }
    return 0;
}


Measured memory_bytes: 256
import math
a, b, h, m = map(int,input().split())
jikann = (h/12+m/720)*360
hun = (m/60)*360
kakudo = abs(jikann-hun)
if kakudo > 180:
    kakudo =  360- kakudo
kakudo = math.radians(kakudo)

ans = a**2+b**2-2*a*b*math.cos(kakudo)

print(ans**(1/2))

Measured memory_bytes: 9516
#include "iostream"
#include "vector"
#include "string"
#include <iomanip>

//const double PI = 3.14159265358979323846;

using namespace std;

int main() {
	double A, V, B, W, T;
	cin >> A >> V >> B >> W >> T;

	if (W >= V) {
		cout << "NO" << endl;
		return 0;
	}

	double t = abs(B - A) / abs(W - V);
	
	if (t <= T) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	
	return 0;
}

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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
ll LCM(int a, int b){
    return a*b/gcd(a,b);
}

int main(void)
{
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,0,n)cin>>a[i];

    ll cnt1=0,cnt2=0;
    rep(i,0,n){
        if(a[i]%4==0)cnt1++;
        else if(a[i]%2==0)cnt2++;
    }
    cnt1+=cnt2/2;
    if(n/2<=cnt1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 1024
N, M = map(int,input().split())
like = [0 for i in range(M+1)]

for i in range(N):
    KA = list(map(int,input().split()))

    for k in range(1,KA[0]+1):
        like[KA[k]] += 1
        
ans = 0
for i in range(M+1):
    if like[i] == N:
        ans += 1

print(ans)

Measured memory_bytes: 9184
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
using namespace std;

int main() 
{
    // freopen("./input.txt", 'r', stdin);
    // freopen("./output.txt", 'w', stdout);

	int N;
	string S;
	cin >> N >> S;
	int cnt[2][30];
	int len = S.length();
	
	int maxtot = 0;
	int ans = 0;
	
	for (int i = 0; i <= len - 2; i++) {
		memset(cnt, 0, sizeof(cnt));
		for (int j = 0; j <= i; j++) {
			cnt[0][(int)(S[j] - 'a')]++;
		}
		for (int j = i + 1; j < len; j++) {
			cnt[1][(int)(S[j] - 'a')]++;
		}
		int tot = 0;
		for (int j = 0; j < 26; j++) {
			if (cnt[0][j] >= 1 && cnt[1][j] >= 1) {
				tot++;
			}
		}
		// cout << i << " " << tot << "\n";
		if (tot > maxtot) {
			maxtot = tot;
			ans = i;
		}
	}

	cout << maxtot << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N,p[11],m=0,sum=0;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>p[i];
        m=max(m,p[i]);
        sum=sum+p[i];
    }
    cout<<sum-m/2<<endl;
    return 0;
}

Measured memory_bytes: 256