akhauriyash/Code-Regression huggingface dataset:
use proconio::{fastout, input, marker::Usize1};
use std::collections::HashMap;

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        d: usize,
        a: [[Usize1; w]; h],
        q: usize,
        lr: [(Usize1, Usize1); q],
    }

    let mut hm = HashMap::new();
    for i in 0..h {
        for j in 0..w {
            hm.insert(a[i][j], (i, j));
        }
    }
    let mut modulo = vec![vec![0i64]; d];
    for i in d..h * w {
        let pn = hm.get(&i).unwrap();
        let pb = hm.get(&(i - d)).unwrap();
        let dist = i64::abs(pb.0 as i64 - pn.0 as i64) + i64::abs(pb.1 as i64 - pn.1 as i64);
        let last = modulo[i % d][modulo[i % d].len() - 1];
        modulo[i % d].push(last + dist);
    }

    for i in 0..q {
        let l = lr[i].0;
        let r = lr[i].1;
        println!("{}", modulo[r % d][r / d] - modulo[l % d][l / d]);
    }
}


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

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

  vector<int> P(N);
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }

  int answer = 1;
  int current = P[0];
  for (int i = 1; i < N; i++) {
    if (P[i] < current) {
      answer++;
      current = P[i];
    }
  }

  cout << answer << endl;

}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    ll n,m;
    cin >> n >> m;
    ll k[n];
    ll a[30][30]={0};
    rep(i,n){
        cin >> k[i];
        rep(j,k[i]) cin >> a[i][j];
    }
    ll btn[31]={0};
    rep(i,n){
        rep(j,m) btn[a[i][j]]++;
    }
    ll ans=0;
    for(ll i=1;i<m+1;i++){
        if(btn[i]==n) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n,k = map(int , input().split())
a = []
from collections import defaultdict as dd
dc = dd(lambda : 0)
for i in range(k):
  d = int(input())
  a = list(map(int , input().split()))
  for i in a:
    dc[i] += 1
cnt = 0
for i in range(1 , n + 1):
  if dc[i] == 0:
    cnt += 1
print(cnt)

Measured memory_bytes: 9504
// Brutal
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 10;

int n, m, targets[3], l[maxn];

int min4(int a, int b, int c, int d) {
	if (a > b) a = b;
	if (a > c) a = c;
	if (a > d) a = d;
	return a;
}

int dfs(int idx, int a, int b, int c) {
	if (idx == n) {
		if (a == 0 || b == 0 || c == 0)
			return INT_MAX / 2;
		else
			return abs(a - targets[0]) + abs(b - targets[1])
					+ abs(c - targets[2]) - 30;
	}

	int r1 = dfs(idx+1, a, b, c);
	int r2 = dfs(idx+1, a + l[idx], b, c) + 10;
	int r3 = dfs(idx+1, a, b + l[idx], c) + 10;
	int r4 = dfs(idx+1, a, b, c + l[idx]) + 10;
	return min4(r1, r2, r3, r4);
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	for (int i = 0; i < 3; ++i)
		cin >> targets[i];

	for (int i = 0; i < n; ++i)
		cin >> l[i];

	cout << dfs(0, 0, 0, 0) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <algorithm>
#include <cmath>

using namespace std;

namespace {

}

int main()
{
	std::string s;

	int a = 0, b = 0, c = 0, d = 0;

	cin >> a >> b >> c >> d;

	if ((abs(c - a) <= d) || 
		(abs(b -a) <= d && abs(c -b) <=d)){
		cout << "Yes";
	}
	else {
		cout << "No";
	}


	return 0;
}


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

const int N = 100010;
int n;
vector<int> g[N];
int color[N];

bool dfs(int v) {
    for (int u : g[v]) {
        if (color[u] != -1) {
            if (color[v] == color[u]) {
                return false;
            }
        }
        else {
            color[u] = color[v] ^ 1;
            if (!dfs(u)) return false;
        }
    }
    return true;
}

int main() {
    int m;
    cin >> n >> m;
    rep(i, m) {
        int v, u;
        cin >> v >> u;
        v--; u--;
        g[v].push_back(u);
        g[u].push_back(v);
    }
    fill(color, color + n, -1);
    color[0] = 0;
    if (!dfs(0)) {
        cout << (ll)n * (n - 1) / 2 - m << endl;
    }
    else {
        ll t = 0;
        rep(i, n) {
            t += color[i];
        }
        cout << t * (n-t) - m << endl;
    }
    return 0;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
 
int main(){
  int n;
  cin >>n;
  vector<vector<char>> s(n,vector<char>(10));
  rep(i,n){
    rep(j,10){
      cin >>s.at(i).at(j);
    }
    sort(s.at(i).begin(),s.at(i).end());
  }
  vector<string> w(n,"");
  rep(i,n){
    rep(j,10){
      w.at(i).push_back(s.at(i).at(j));
    }
  }
  map<string,ll> cnt;
  for(string x: w){
    if(cnt.count(x)){
      cnt.at(x)++;
    }
    else{
      cnt[x]=1;
    }
  }
  ll sum=0;
  for(auto y: cnt){
    ll v=y.second;
    sum+=v*(v-1)/2;
  }
  cout << sum << endl;
}
  

Measured memory_bytes: 18944
main(){int w,n,i,t[32],y,z,a;scanf("%d %d",&w,&n);for(i=1;i<=w;i++)t[i]=i;for(i=0;i<n;i++){scanf("%d,%d",&y,&z);a=t[y];t[y]=t[z];t[z]=a;}for(i=1;i<=w;i++)printf("%d\n",t[i]);return 0;}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<set>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define MAX 1000000007
typedef long long ll;

ll power(ll m,ll n){
	if(n==0) return 1;
	if(n%2==0) return power((m*m)%MAX,n/2);
	else return (m*power((m*m)%MAX,(n-1)/2))%MAX;
}
	
int main(){
	ll m,n;
	cin >> m>>n;
	cout << power(m,n) << endl;
	return 0;
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int maxn = 1000000;
int fizzbuzz[1000007];

int main(){
	for(int i=3; i<=maxn; i+=3) fizzbuzz[i] = 1;
	for(int i=5; i<=maxn; i+=5){
		if(fizzbuzz[i]) fizzbuzz[i] = 3;
		else fizzbuzz[i] = 2;
	}	
	int n;
	cin>>n;
	long long ret = 0;
	for(int i=1; i<=n; i++){
		if(!fizzbuzz[i]) ret+=i;
	}
	cout<<ret;
}

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

int main(void){
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    for(int i=0; i<s.size(); i++){
        if(!((i == a && s[i] == '-') || (i != a && s[i] != '-'))){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
A=int(input())
B=int(input())
C=int(input())
X=int(input())
pattern=0
cnt=0
for i in range(C+1):
    cnt=cnt+50*i
    for j in range(B+1):
        cnt=cnt+100*j
        for k in range(A+1):
            cnt=cnt+500*k
            if cnt==X:
                pattern=pattern+1
            cnt=cnt-500*k
        cnt=cnt-100*j
    cnt=cnt-50*i
print(pattern)


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void insert(int);
struct node{
  int key;
  struct node *p;
  struct node *right;
  struct node *left;
};
struct node *Node,*NIL;


void insert(int a){
   struct node *y=NIL;
   struct node *x=Node;
   struct node *z;
   z = malloc(sizeof(struct node));
    z->key=a;
    z->left=NIL;
    z->right=NIL;
    while(x!=NIL){
        y=x;
        if(z->key<x->key){
            x=x->left;
        }else{
            x=x->right;
        }
    }
    z->p=y;
    if(y == NIL){
        Node=z;
    }else{
        if(z->key < y->key){
            y->left=z;
        }else{
            y->right=z;
        }
    }
}
void pre(struct node *a){
  if(a==NIL)return;
  printf(" %d",a->key);
  pre(a->left);
  pre(a->right);
}
void in(struct node *a){
  if(a==NIL)return;
  in(a->left);
  printf(" %d",a->key);
  in(a->right);
}
int main(){
  int i,j,n;
  char M[10];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",M);
    if(strcmp(M,"insert")==0){
    scanf("%d",&j);
    insert(j);
    }else if(strcmp(M,"print")==0){
      in(Node);
      printf("\n");
      pre(Node);
      printf("\n");
    }
  }
  return 0;
  
}



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

int n, k, h[100010], ans = 1e9+7;

int main(){
	cin >> n >> k;
  for(int i=0; i<n; ++i) cin >> h[i];
  sort(h, h+n);
  for(int i=0; i+k-1<n; ++i)
    ans = min(ans, h[i+k-1]-h[i]);
  cout << ans << "\n";
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define M 1101
#define MOD 1000000007
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define all(v) v.begin(),v.end()
#define repl(i,l,r) for(long long i=l;i<=r;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define ins insert
#define inf INT_MAX
#define vp vector< pair<int,int> >
char a[M][M];
int h,w;
int dp[M][M];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>h>>w;
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
            cin>>a[i][j];

    for(int i=0;i<=max(h,w)+1;i++)
    {
        dp[i][0]=0;
        dp[0][i]=0;
    }
    dp[1][1]=1;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(i==1 && j==1) continue;
            if(a[i][j]=='.')
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
            else
                dp[i][j]=0;
        }
    }
    cout<<dp[h][w]<<"\n";

    return 0;
}






Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define myPair pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define qmax priority_queue<int>
#define qmin priority_queue<int,vector<int>,greater<int>>
#define all(x) x.begin(),x.end()
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define FORR(i,a,b) for(int i = a; i >= b; i--)

const int mxn = 1e5 + 10;
int dp[110][mxn];
int n, W;
int w[mxn], v[mxn];

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> W;
	int aux = 0;

	FOR(i,1,n)
	{
		cin >> w[i] >> v[i];
		aux += v[i];
	}

	FOR(i,0,n)
		dp[i][0] = 0;
	FOR(v,1,aux)
		dp[0][v] = 2e18;

	FOR(i,1,n)
	{
		FOR(j,1,aux)
		{
			dp[i][j] = dp[i - 1][j];
			if(j >= v[i])
				dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
		}
	}

	int ans = 0;
	FORR(j,aux,0)
	{
		bool flag = 0;
		FORR(i,n,1)
		{
			if(dp[i][j] <= W)
			{
				flag = 1;
				ans = j;
			}
		}
		if(flag)
			break;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 82496
defmodule Main do
  def solve(prev, x, num, n) when x <= n and x != 1 do
  	solve(prev * num, x * num, num, n)
  end
  def solve(prev, x, num, n) do
  	if prev == num and prev != 1 do
      0
    else
      prev
    end
  end
  
  
  def main do
    n = IO.gets("") |> String.trim |> String.to_integer
    numbers = 1..n
    numbers = Enum.to_list(numbers)
	IO.puts(Enum.map(numbers, fn x -> solve(1, x, x, n) end) |> Enum.filter(fn(x) -> x <= n end) |> Enum.max)
  end
end


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

using namespace std;

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

ll gcd(ll a, ll b){
    if(a<b){
      ll x;
      x = a;
    }
    if(b == 0){
        return a;
    }
    return gcd(b, a % b);
}
template <typename T>
T lcm(T x, T y) {
    return x / gcd(max(x,y), min(x,y)) * y;
}

int main() {
    ll n, m, i, j, k;
    cin >> n >> m;
    vector<ll> a(n);
    ll l = 1;
    for(auto &x : a) {
        cin >> x;
        l=lcm(l,x/2);
    }
    ll ret = 0;
    //cout << l << endl;
    for(auto &x:a){
        if(l%x==0){
            cout << 0 << endl;
            return 0;
        }
    }
    cout << (m/l+1)/2 << endl;
    return 0;
}


Measured memory_bytes: 1024
use std::io;

fn main() {
    let cards = input();

    let mut checked: Vec<Vec<bool>> = vec![];
    for _ in 0..4 {
        let mut v = vec![];
        for _ in 0..13 {
            v.push(false);
        }
        checked.push(v);
    }

    for card in cards {
        match card {
            ('S', n) => checked[0][n - 1] = true,
            ('H', n) => checked[1][n - 1] = true,
            ('C', n) => checked[2][n - 1] = true,
            (_, n) => checked[3][n - 1] = true,
        }
    }

    for (k, cards) in checked.iter().enumerate() {
        for (n, is_check) in cards.iter().enumerate() {
            if !is_check {
                let kind = match k {
                    0 => 'S',
                    1 => 'H',
                    2 => 'C',
                    _ => 'D'
                };
                println!("{} {}", kind, n+1);
            }
        }
    }
}

fn input() -> Vec<(char, usize)> {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    
    let n: i32 = s.trim().parse().unwrap();

    let mut cards: Vec<(char, usize)> = vec![];
    for _ in 0..n {
        let mut s = String::new();
        io::stdin().read_line(&mut s).expect("");
        let mut iter = s.trim().split_whitespace();

        let kind: char = iter.next().unwrap().chars().nth(0).unwrap();
        let num: usize = iter.next().unwrap().parse().unwrap();

        cards.push((kind, num));
    }

    cards
}


Measured memory_bytes: 5040
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define pb push_back
bool isPrime(ll n) 
{ 
    
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
   
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
ll minthis(ll a, ll b){
if(a < b){
return a;
}
return b;
}
ll maxthis(ll a, ll b){
if(a > b){
return a;
}
return b;
}
int gcd(int a, int b){
    if( a<0 ) a = -a;
    if( b<0 ) b = -b;
    while( b!=0 ){
        a %= b;
        if( a==0 ) return b;
        b %= a;
    }
    return a;
}
 
int findLargestDivisor(int n) 
{ 
	int max = 1;
    for (int i = 2; i < n; i++) {        
        if(n %(i) == 0) { 
            max = i;
        } 
    }
    return max;     
} 
	 
 
ll power(ll x, ll y)  
{  
    ll temp;  
    if(y == 0)  
        return 1;  
    temp = power(x, y / 2);  
    if (y % 2 == 0)  
        return (temp * temp)%1000000007;  
    else
    {  
        if(y > 0)  
            return (x * temp * temp)%1000000007;  
        else
            return (temp * temp)%1000000007 / x;  
    }  
} 
bool sortbysec(const pair<int, int>& a, 
               const pair<int, int>& b) 
{ 
    return (a.second < b.second); 

} 


void solve(){
    ll n, m;
    cin >> n >> m;
    m = m*m;
    int ans = 0;
    for(ll i = 0 ; i < n ; i++){
        ll x, y;
        cin >> x >> y;
        if((abs(x*x) + abs(y*y)) <= m) ans++;
    }
    cout << ans << "\n";
}
int main(){ 
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
	solve();
    }
    return 0; 
}





Measured memory_bytes: 3624
#include<stdio.h>

int main(){
  int i,j,n,q,s[10000],t[500],sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&t[i]);
  }
  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(t[i]==s[j]){
	t[i]=-1;
	sum++;
      }
    }
  }
  printf("%d\n",sum);
}
	



Measured memory_bytes: 2108
package main

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

type Int2DList [][]int
type IntList []int

func (a Int2DList) ChMin(i, j int, value int) bool {
	curV := a[i][j]
	if curV > value {
		a[i][j] = value
		return true
	}
	return false
}
func lib_NewInt2DList(length1, length2 int, initialValue int) Int2DList {
	ret := make([][]int, length1, length1)
	for i := 0; i < length1; i++ {
		ret[i] = lib_NewIntList(length2, initialValue)
	}
	return ret
}
func lib_NewIntList(length int, initialValue int) IntList {
	ret := make([]int, length, length)
	for i := 0; i < length; i++ {
		ret[i] = initialValue
	}
	return ret
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var N int
	scanner.Scan()
	N, _ = strconv.Atoi(scanner.Text())
	var W int
	scanner.Scan()
	W, _ = strconv.Atoi(scanner.Text())
	w := make([]int, N)
	v := make([]int, N)
	for i := 0; i < N; i++ {
		scanner.Scan()
		w[i], _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		v[i], _ = strconv.Atoi(scanner.Text())
	}
	fmt.Println(solve(N, W, w, v))
}
func solve(N int, W int, w []int, v []int) int {
	maxV := N * 1000
	list := lib_NewInt2DList(N+10, maxV+10, math.MaxInt64/2)
	list[0][0] = 0
	for i := 0; i < N; i++ {
		for curV := 0; curV <= maxV; curV++ {
			list.ChMin(i+1, curV, list[i][curV])
			if newW := list[i][curV] + w[i]; newW <= W {
				list.ChMin(i+1, curV+v[i], newW)
			}
		}
	}
	retV := 0
	for curV, w := range list[N] {
		if curV > retV && w <= W {
			retV = curV
		}
	}
	return retV
}


Measured memory_bytes: 89728
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>
#include <type_traits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//constexpr long long MOD = 1e9 + 7;
//constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;
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; }

ll h, w;
vector<ll> dx = { -1, 0, 1, 0 };
vector<ll> dy = { 0, -1, 0, 1 };


bool isInField(ll x, ll y) {
    bool f = x >= 0 && x < w && y >= 0 && y < h;
    return f;
}

bool compare_first(pair<ll, ll> x, pair<ll, ll> y)
{
    if (x.first != y.first) {
        return x.first < y.first;
    }
    else {
        return x.second < y.second;
    }
}

bool compare_second(pair<ll, ll> x, pair<ll, ll> y)
{
    if (x.second != y.second) {
        return x.second < y.second;
    }
    else {
        return x.first < y.first;
    }
}

struct {
    bool operator()(pair<string, int> x, pair<string, int> y) const
    {
        return x.second <= y.second && x.first < y.first;
    }
} compare_map;

const ll MAX = 500000000;
const ll MOD = 1000000007;


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

    ll l;
    cin >> l;

    double x = l / 3.0;
    double y = l / 3.0;
    double z = l - x - y;
    cout << setprecision(10) << x * y * z << "\n";

    //ll max = -1;
    //for (ll x = 1; x < l; x++)
    //{
    //    for (ll y = 1; y < l; y++)
    //    {
    //        ll z = l - x - y;
    //        max = max < x * y * z ? x * y * z : max;
    //    }
    //}

    //cout << max << "\n";
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

int main()
{
    int n, s = 0;
    while (std::cin >> n && n > 0) {
        int max, min, sum = 0;
        std::cin >> s;
        max = s;
        min = s;
        sum += s;

        for (int i = 0; i < n - 1; i++) {
            std::cin >> s;
            if (s > max)
                max = s;
            if (s < min)
                min = s;
            sum += s;
        }
        std::cout << (sum - max - min) / (n - 2) << '\n';
    }

    return 0;
}


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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const double PI = 3.141592653589793238462643383279;
const int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
    };
} init;

string S;
signed main() {
    cin >> S;
    int a = 0;
    for (int i = 0; i < S.length(); i++) { a += (S[i] - '0') ^ (i & 1); }
    cout << min(a, (int)S.length() - a) << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>

int main(void)
{
    int n;
    double Px,Py,r;
    double a,b,c,d,e,f;
    int i;

    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%lf %lf %lf %lf %lf %lf",&a, &b, &c, &d, &e, &f);
        double aa = a * a;
        double bb = b * b;
        double cc = c * c;
        double dd = d * d;
        double ee = e * e;
        double ff = f * f;
        Py = ((e - a) * (aa + bb - cc - dd) - (c - a) * (aa + bb - ee - ff) ) 
        / ((2 * (e - a) * (b - d)) - (2 * (c - a) * (b - f)));
        Px = (2 * (b - f) * Py - aa - bb + ee + ff) / (2 * (e - a));
        
        
        r = hypot(Px - a, Py - b);
        printf("%.3lf %.3lf %.3lf\n", Px, Py, r);
    }
    return (0);
}



Measured memory_bytes: 2044
//Fence
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1;
#define ll long long
//#define d double
//#define int long long
#define F first
#define S second
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(10)
#define M 100000000
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)

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

int main()
{
    int n;
    cin>>n;
    int arr[n+1];
    rep(i,1,n)cin>>arr[i];
    long dp[n+1];
    dp[0]=0;
    if(n>=1)
    dp[1]=0;
    if(n>=2)
    dp[2]=abs(arr[2]-arr[1]);
    for(int i=3;i<=n;i++)
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    cout<<dp[n];
}



Measured memory_bytes: 1408
NK = [int(x) for x in input().split()]
d=[]
A=[]
x=[]
n=0
for i in range(NK[1]):
  d.append(int(input()))
  A.append([int(x) for x in input().split()])
for i in A:
  for j in i:
    for k in range(NK[0]):
      if j==k+1:
        x.append(j)
        
for i in range(NK[0]):
  if i+1 in x:
    n+=1
print(NK[0]-n)


Measured memory_bytes: 9368
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,ww;
vector<ll>v(1000);
vector<ll>w(1000);
vector<vector<ll> > dp(105, vector<ll>(100005, -1));
ll f(ll pos,ll rem)
{
    if(rem<0) return -1e17+2;
    if(rem==0) return 0;
    if(pos>=n) return 0;
       if(dp[pos][rem]!= -1) return dp[pos][rem];

    ll lefttree=f(pos+1,rem-w[pos])+v[pos];
    ll righttree=f(pos+1,rem);
    return dp[pos][rem]=max(lefttree,righttree);
}
main()
{

    cin>>n>>ww;
   for(int i=0;i<n;i++)
   {
       cin>>w[i]>>v[i];
   }

    cout<<f(0,ww)<<"\n";
}


Measured memory_bytes: 83456
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    long long sum = 0;
    for( auto x : s)
    {
        sum += (x-48);
    }
    if(sum%9==0) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i = x; i < n; i++)
#define MAX 100
#define INF 1000000001
typedef long long ll;
int n, m;

// char X[100][100];
// int dp[1000000001];
int a[114514];
int acc[114514];
int xr[114514];

int bit[114514][20];

int p[214514];
int x[214514];
bool checked[214514];

vector<int> ps;
vector<int> ans;

int main(void){
    cin >> n;
    // int count = 0;
    REP(i,0,n) {
        cin >> p[i];
        // cout << a[i] << endl;
    }
  
    if (p[0] > 0) {cout << -1 << endl; return 0;}
    REP(i,1,n) {
        if (p[i] - p[i-1] > 1) {
            cout << -1 << endl;
            return 0;
        }
    }
    
    REP(i,0,n) {
        int temp = i - p[i];
        x[i] = temp;
        checked[i] = false;
    }
    
    // REP(i,0,n) {
    //     cout << x[i] << endl;
    //     checked[i] = false;
    // }
    
    ll ans = 0;
    
    for (int i = n - 1; i >= 0; i--) {
        if (checked[x[i]]) continue;
        ans += i - x[i];
        checked[x[i]] = true;
        // cout << ans << endl;
    }
    
    cout << ans << endl;


}

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

ikeru = [[] for _ in range(n)]
for i in range(n-1):
	a, b, c = map(int, input().split())
	ikeru[a-1].append((b-1, c))
	ikeru[b-1].append((a-1, c))

#fukasa = [0 for _ in range(n)]
#fukasamoto = [0 for _ in range(n)]
kaisuu = 0
settansaku = set([])
setmada = {0}
kouho = 1
guuki = [0 for _ in range(n)]

while kouho != 0:
	kaisuu += 1
	for i in list(setmada):
		settansaku.add(i)
		setmada.remove(i)
		kouho -= 1
		for k, leng in ikeru[i]:
			if not k in setmada:
				if not k in settansaku:
					setmada.add(k)
					guuki[k] = (guuki[i] + leng) % 2
					kouho += 1
					#fukasa[k] = kaisuu
					#fukasamoto[k] = i+1

print("\n".join([str(guuki[i]) for i in range(n)]))

Measured memory_bytes: 53564
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char s[100005];
	int i,j,h[100005]={0};
	scanf(" %s",s);
	char s1[]="dream";
	char s2[]="dreamer";
	char s3[]="erase";
	char s4[]="eraser";
	for(i=0;s[i];i++)
	{
		//printf("%d\n",i);
		if(s[i]=='d')
		{
			j=0;
			int c=0;
			while(s1[j]==s[i] && s1[j] && s[i])
			j++,c++,i++;
		//	printf("%d\n",c);
			if(c<5)
			{
				printf("NO");
				return 0;
			}
			i--;
			h[i]=1;
		}
		else if(s[i]=='e')
		{
			j=0;
			int c=0;
			if(s[i+1] && s[i+1]=='r')
			if(s[i+2] && s[i+2]!='a' && i>0 && h[i-1]==1)
			{
				i+=1;
			//	printf("yo");
				continue;
			}
			else if(!s[i+2] && i>0 && h[i-1]==1)
			{
				printf("YES");
				return 0;
			}
			while(s4[j]==s[i] && s4[j] && s[i])
			{
				j++,c++,i++;
			}
			if(c<5)
			{
				printf("NO");
				return 0;
			}
			i--;
		}
		else
		{
			printf("NO");
			return 0;
		}
	}
	printf("YES");
}

Measured memory_bytes: 896
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


class Program {

	static long mod = 1000000007;
	//static long mod =998244353;
	static int[] ans;
	static void Main(string[] args) {

		char[] cs = new char[] { ' ' };
		//char[] cs = new char[] { ' ', ',' };

		//int n = int.Parse(Console.ReadLine());
		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		//string res = "";
		long res=0;
		int max=2000;

		int[] vals = parseAry(Console.ReadLine().Split(cs));
		int n = vals[0];
		long kk = vals[1];
		int[] nums = parseAry(Console.ReadLine().Split(cs));


		long plusL = ( ( 1 + kk ) * ( kk ) / 2 ) % mod;
		long plusR = ( ( 1 + kk-1 ) * ( kk-1 ) / 2 ) % mod;


			for ( int i = 0; i < n; i++ ) {

				long cnt = 0;
				long left = 0;
				long right=0;
				for ( int k = 0; k < n; k++ ) {
					if ( k < i ) { if ( nums[i] < nums[k] ) { left++; } }
					if ( k > i ) { if ( nums[i] < nums[k] ) { right++; } }
				}

				long temp = left * plusL % mod;
				long temp2 = right * plusR % mod;

					res += temp+temp2;
				res %= mod;
			}






			Console.WriteLine(res);

			return;

	}



	//	int配列をスペース区切りの文字列に変換
	static string stringBuilderArrayInt(int[] a) {
		StringBuilder sb = new StringBuilder();

		for ( int i = 0; i < a.Length; i++ ) {
			if ( a[i] == 1 ) { sb.Append(i + " "); }
		}
		if ( sb.Length > 1 ) {
			sb = sb.Remove(sb.Length - 1, 1);
		}
		return sb.ToString(); ;
	}


	//	文字列strをindex番目からdで上書き
	static string strOverWrite(string str, int i, string s) {
		return str.Remove(i, s.Length).Insert(i, s);
	}

	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryL(string[] str) {
		long[] nums = new long[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { nums[i] = long.Parse(str[i]); }
		return nums;
	}

	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for ( int i = 0; i < str.Length; i++ ) { re[i] = str[i].ToString(); }
		return re;
	}


	
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, m, q;
  cin >> n >> m >> q;
  vector<vector<int>> imos(n, vector<int>(n, 0));
  vector<vector<int>> sums(n, vector<int>(n+1, 0));
  rep(i, m){
    int l, r;
    cin >> l >> r;
    l--; r--;
    imos.at(l).at(r)++;
  }
  rep(i, n){
    rep(j, n){
      sums.at(i).at(j+1) = sums.at(i).at(j) + imos.at(i).at(j);
    }
  }

  rep(_q, q){
    int a, b;
    cin >> a >> b;
    int ans = 0;
    rep2(i, a-1, b){
      ans += sums.at(i).at(b) - sums.at(i).at(a-1);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 5576
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,m,x,ans=2e9+7;
int c[15],a[15][15],pos[15];
int main()
{
   cin>>n>>m>>x;
   for(int i=1;i<=n;i++)
   {
   	   cin>>c[i];
   	   for(int j=1;j<=m;j++)
   	    cin>>a[i][j];
   }
   while(pos[0]==0)
   {
   	   int in[15]={0},money=0;
		for(int i=1;i<=n;i++)
		{
			if(pos[i]==1)
			{
				money+=c[i];
				for(int j=1;j<=m;j++)in[j]+=a[i][j];
			}
		 } 
		 int flag=1;
		 for(int i=1;i<=m;i++)
		   {
		   	  if(in[i]<x) {
		   	  	flag=0;break;
				 }
		   }
		if(flag==1)  ans=min(ans,money);
		for(int i=n;i>=0;i--)
		{
			if(pos[i]==1) pos[i]=0;
			else
			   {
			   	  pos[i]=1;break;
			   }
		}
   } 
   if(ans!=2e9+7) cout<<ans;
   else 
      cout<<-1;
return 0;
}


Measured memory_bytes: 3580
if __name__ == "__main__":
    N, M = map(int, input().split())
    As = list(map(int, input().split()))
    As.sort(reverse=True)

    yes = True
    threshold = sum(As) / (4*M)
    for idx in range(M):
        if As[idx] < threshold:
            yes = False
            break
    
    if yes:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 9176
n= int(input())
nyuuryok = input().split()
nyuuryoku = [0]*n
for i in range(n):
    nyuuryoku[i] = int(nyuuryok[i])
count = 0
count2 = 0
while count2 == 0:
    if(all([x % 2 == 0 for x in nyuuryoku])):
        for i in range(n):
            nyuuryoku[i] = nyuuryoku[i]/2
        count += 1
        
    else:
        count2 += 1
print(count)
    

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;
using ll=long long;
using pp=pair<int,pair<int,int>>;

int main(){
  string S;
  cin>>S;
  int k=S.size();
  int ans=0;
  for(int i=0;i<k;i++){
    if(S.at(i)=='x'){
      ans++;
    }
  }
  if(ans<8){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}


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

zorome_max=0
zorome=0

for i in range(n):
    one,two=[int(i) for i in input().split()]
    if one==two:
        zorome+=1
        zorome_max=max(zorome_max,zorome)
    else:
        zorome=0

if zorome_max>=3:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 62380
#include <iostream>
using namespace std;
int main (void) {
    int n;
    int nx = 0;
    int ny = 0;
    int nt = 0;

    cin >> n;
    for (int i = 0; i < n; i++) {
        int t;
        int x;
        int y;
        cin >> t >> x >> y;
        int diff = (t - nt) - (abs(x - nx) + abs(y - ny));
        if (diff < 0 || diff % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
        nt = t;
        nx = x;
        ny = y;
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

int n;
vector<int> l;

void solve() {
    sort(l.begin(), l.end(), greater<>());
    int ans = 0;
    rep(i, 2 * n) if (i % 2 != 0) ans += l[i];
    cout << ans << endl;
}

int main() {
    cin >> n;
    l.resize(2 * n);
    rep(i, 2 * n) cin >> l[i];
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

char judge(int m ,int t,int r)
{
	int sum;
	
	sum = m + t;
	
	if(m == -1 || t ==-1){
		return 'F';
	}
	else if(sum>=80){
		return 'A';
	}
	else if(sum<80&&sum>=65){
		return 'B';
	}
	else if(sum<65&&sum>=50){
		return 'C';
	}
	else if(sum<50&&sum>=30){
		if(r>=50){
			return 'C';
		}
	else
		return 'D';
	}
	else if(sum<30){
		return 'F';
	}
}
int main(void)
{
	int m,t,r;
	
	while(1){
		scanf("%d %d %d", &m, &t, &r);
		if(m == -1 && t == -1 && r == -1){
			break;
		}
		printf("%c\n",judge(m,t,r));
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
//#define int ll

signed main(){
    int w,a,b;
    scanf("%d%d%d",&w,&a,&b);
    if(a<=b&&b<=a+w || a<=b+w&&b+w<=a+w) puts("0");
    else printf("%d\n",min(abs(b-(a+w)),abs((b+w)-a)));
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	_ = iScan()
	s := Scan()
	k := iScan()
	for _, v := range s {
		if string(v) == string(s[k-1]) {
			fmt.Print(string(v))
		} else {
			fmt.Print("*")
		}
	}
	fmt.Println("")
}


Measured memory_bytes: 1772
#include<iostream>
#define N 100
using namespace std;

int main(){
  int n,a[N],cnt=0;
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=1;i<n;i++)
    for(int j=n-1;j>=i;j--){
      if(a[j-1]>a[j]){
	int t=a[j];
	a[j]=a[j-1];
	a[j-1]=t;
	cnt++;
      }
    }
  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<a[i];
  }
  cout<<endl<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    int N; cin >> N;
    vector<int> A(100001,0);
    int i,j;
    ll ans;
    rep(i,N){
        cin >> j;
        A[j]++;
        ans += j;
    }
    int Q; cin >> Q;
    ll k,l;
    rep(i,Q){
        cin >> k >> l;
        ans += (l-k) * A[k];
        A[l] += A[k];
        A[k] = 0;
        AA(ans);
    }
    return 0;
}

Measured memory_bytes: 3732
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
    a,b = map(int,input().split())
    
    s = str(a) + str(b)
    i = int(s)
    
    tmp = math.sqrt(i)
    
    if tmp.is_integer():
        print("Yes")
    else:
        print("No")
	
if __name__ == "__main__":
	main()


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

int main(){
  ll n;
  cin >> n;
  ll num = 1;
   for(ll i =1; i*i<=n;i++){
         if(n%i==0)num=i;
   }
   ll ans = num + n/num  -2 ;
   cout << ans  << endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)

const int INF = 1e9;
int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef long long ll;

int main() {
  ll ans, n, m;
  cin >> n >> m;

  ans = abs(n - 2) * abs(m - 2);
  cout << ans << endl;
}


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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;

int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

int mx[16] = {-2, -2, -2, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 2, 2, 2};
int my[16] = {-2, -1, 0, 1, 2, -2, 2, -2, 2, -2, 2, -2, -1, 0, 1, 2};

int main() {

	IOS

	int h, w, sx, sy, dex, dey;
	cin >> h >> w >> sx >> sy >> dex >> dey;

	char g[h+1][w+1];
	bool vis[h+1][w+1] = {0};

	for (int i = 1; i <= h; i++)
		for (int j = 1; j <= w; j++)
			cin >> g[i][j];

	queue<pair<int, int>> q;
	q.push({sx, sy});
	vis[sx][sy] = true;

	int magic_moves = 0;
	bool found = false;
	
	while (!q.empty()) {
		set<pair<int, int>> border;

		while (!q.empty()) {
			auto popped = q.front();
			q.pop();

			if (popped.first == dex && popped.second == dey) {
				found = true;
				break;
			}

			for (int di = 0; di < 4; di++) {
				int nx = popped.first + dx[di];
				int ny = popped.second + dy[di];

				if (!(nx >= 1 && nx <= h && ny >= 1 && ny <= w))
					continue;

				if (vis[nx][ny])
					continue;

				if (g[nx][ny] == '#')
					border.insert({popped.first, popped.second});

				else {
					q.push({nx, ny});
					vis[nx][ny] = true;
				}

				if (nx == dex && ny == dey) {
					found = true;
					break;
				}
			}

			if (found)
				break;
		}

		if (found)
			break;

		magic_moves++;

		// magic
		for (auto popped: border) {

			for (int dxi = -2; dxi <= 2; dxi++) {
				for (int dyi = -2; dyi <= 2; dyi++) {
					int nx = popped.first + dxi;
					int ny = popped.second + dyi;

					if (!(nx >= 1 && nx <= h && ny >= 1 && ny <= w))
						continue;

					if (vis[nx][ny])
						continue;

					if (g[nx][ny] == '.') {
						q.push({nx, ny});
						vis[nx][ny] = true;

						if (nx == dex && ny == dey) {
							found = true;
							break;
						}
					}
				}
			}

			// for (int di = 0; di < 16; di++) {


			// 	int nx = popped.first + mx[di];
			// 	int ny = popped.second + my[di];

			// 	if (!(nx >= 1 && nx <= h && ny >= 1 && ny <= w))
			// 		continue;

			// 	if (vis[nx][ny])
			// 		continue;

			// 	if (g[nx][ny] == '.') {
			// 		q.push({nx, ny});
			// 		vis[nx][ny] = true;

			// 		if (nx == dex && ny == dey) {
			// 			found = true;
			// 			break;
			// 		}
			// 	}
			// }
		}

		if (found)
			break;
	}


	cout << (found ? magic_moves : -1);

	return 0;
}

Measured memory_bytes: 5956
# print('input >>')
T = input()

ans = ''

"""
i = 0
while i < len(T)-1:
    # print(i)
    if T[i] == 'P':
        ans += 'P'
    elif T[i] == 'D':
        ans += 'D'
    elif T[i] == '?':
        if T[i:i+2] == '??':
            ans += 'PD'
            i += 1
        elif T[i:i+2] == '?P':
            ans += 'DP'
            i += 1
        elif T[i:i+2] == '?D':
            ans += 'PD'
            i += 1
    i += 1
    # print(ans)

# print(i)
if not i == len(T):
    if T[-1] == '?':
        ans += 'D'
    else:
        ans += T[-1]
"""

for t in T:
    if t == '?':
        ans += 'D'
    else:
        ans += t


# print('-----output-----')
print(ans)

Measured memory_bytes: 9476
#include<cstdio>
#include<iostream>
#include<iomanip>

using namespace std;

int main(){
  double a,b,c,d,e,f,x,y;
  while( cin >>a>>b>>c>>d>>e>>f){
    x = (c*e - b*f)/(a*e - b*d) + 1e-10;
    y = (a*f - c*d)/(a*e - b*d) + 1e-10;
    cout <<fixed<<setprecision(3)<<x<<" "<<y<<endl;
  }
  return 0;
}

Measured memory_bytes: 1284
#include <stdio.h>

int main(){
   long a,b,m,aa,bb;
 
   scanf("%ld %ld",&a,&b);
   aa=a;bb=b;
   m=a%b;
   while (m>0) {
      a=b;b=m;
      m=a%b;
   }
   printf("%ld\n",(aa/b)*bb);
   return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;


int main(void) {
    int n, i, t, c, dp[200003] = {};
    const int mod = 1e9 + 7;
    vector<int> cv;
    map<int, int> m;

    cv.push_back(0);
    t = 1;

    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> c;
        if (c != cv[t - 1]) {
            cv.push_back(c);
            t++;
        }
    }

    dp[0] = 1;
    m[0] = 1;
    for (i = 0; i < t; i++) {
        dp[i] = m[cv[i]];
        m[cv[i + 1]] = (m[cv[i + 1]] + dp[i]) % mod;
    }

    cout << dp[t - 1] << endl;

    return 0;
}

Measured memory_bytes: 11124
//  amiD
#include <bits/stdc++.h>
#define ld long double
#define ll long long int
#define mod 1000000007
#define ll_inf 1000000000000000
#define int_inf 1000000000
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define eps 1e-9
#define PI acos(-1.0)
#define ii pair<int,int>
#define se second
#define fi first
using namespace std;
int a, b;
int main(){
    cin>>a>>b;
    if(b>=a)cout<<min(a, 12)<<endl;
    else{
        if(a>=12){
            if(b>=12)cout<<12<<endl;
            else cout<<11<<endl;
            return 0;
        }
        cout<<a-1<<endl;
    }
}


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

using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define all(v) v.begin(),v.end()
#define v vector
#define vi vector<int>
#define vi2 vector<vi>
#define vl vector<long long>
#define vl2 vector<vl>

template <class T> T maxAny(T a, T b){
    if(a > b) return a;
    else return b;
}

template <class T> T minAny(T a, T b){
    if(a > b) return b;
    else return a;
}

int main(){
    long long n, ans = 0;
    cin >> n;
    map<long long,int> sosuu;
    if(n == 1){
        cout << 0 << endl;
        return 0;
    }
    int p = (int)sqrt((double)n);
    for(long long i = 2; i <= p; i++){
        while(n % i == 0){
            n /= i;
            if(!sosuu.count(i)) sosuu[i] = 1;
            else sosuu[i]++;
        }
        if(n == 1) break;
        if(i == p){
            sosuu[n] = 1;
        }
    }
    for(auto s : sosuu){
        int value = s.second;
        for(long long i = 1;true; i++){
            if(value >= i){
                ans += 1;
                value -= i;
            }
            else break;
        }
    }
    cout << ans << endl;
}

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

typedef long long lint;
typedef long double ldouble;
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = 1e18;
const lint MOD = 1e9 + 7;
const lint inv = 1e9 + 5;

int main(){
    vector<int> x(3);
    cin >> x[0] >> x[1] >> x[2];
    int ans = 0;
    SORT(x);
    ans += x[2] * 10 + x[1] + x[0];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>

using namespace std;

int main(){
  int N, A, B, ans=0;

  cin >> N >> A >> B;

  for(int x = 1; x <= N; x++){
    int s = 0, t = x;
    while(t != 0){
      s += t % 10;
      t = t / 10;
    }
    if(A <= s && s <= B) ans += x;
  }

  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
typedef struct{
    int k;
    int l;
    int r;
} Tree;
 
void insert(int, int);
void chu(int);
void sen(int);
Tree t[500001];
int main()
{
    char s[8];
    int m;
    int num;
    int i;
 
    scanf("%d", &m);
 
    int count=0;
    for(i=0; i<m; i++){
        scanf("%s", &s);
        if(s[0]=='i'){ 
          scanf("%d", &num); 
          insert(count, num); 
          count++; 
        }
        if(s[0]=='p'){
          if(count>0) chu(0);
            printf("\n");
            if(count>0) sen(0);
            printf("\n");
        }
    }
     
    return 0;
 
}
 
void chu(int p){
    if(t[p].l>=0) chu( t[p].l);
    printf(" %d", t[p].k);
    if(t[p].r>=0) chu( t[p].r);
}
 
void sen(int p){
    printf(" %d", t[p].k);
    if(t[p].l>=0) sen(t[p].l);
    if(t[p].r>=0) sen(t[p].r);
}
 
void insert(int count, int z){
    int x=0, y;
    if(count<1) x=-1;
 
    t[count].k = z;
    t[count].l = -1;
    t[count].r = -1;
 
    while(x>=0){
        y = x; 
        if(z < t[x].k)x = t[x].l; 
        else x = t[x].r; 
    }
 
    if(count<1){}
    else if(z < t[y].k)t[y].l = count; 
    else t[y].r = count; 
    
}

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

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

int main(void){
    double r;
    scanf("%lf",&r);
    printf("%lf",3.1415*2.0*r);
    return 0; 
}


Measured memory_bytes: 1748
while True:
    N = int(input())
    if N == 0: break
    def to_seconds(s):
        d = 3600
        ret = 0
        for i in s.split(":"):
            ret += d * int(i)
            d //= 60
        return ret

    d = [0] * 90000
    for i in range(N):
        a, b = input().split()
        a, b = to_seconds(a), to_seconds(b)
        d[a] += 1
        d[b] -= 1

    for i in range(1, 90000):
        d[i] += d[i-1]

    print(max(d))



Measured memory_bytes: 9604