akhauriyash/Code-Regression huggingface dataset:
use std::iter::Iterator;

fn main() {
    let n: usize = read();
    let a = (0..n).map(|_| read::<u64>()).collect::<Vec<u64>>();
    let mut c = vec![0; n + 1];

    for &i in a.iter() {
        c[i as usize] = c[i as usize] + 1;
    }

    let mut ans: u64 = 0;
    for &y in c.iter() {
        ans += if y < 2 { 0 } else { y * (y - 1) / 2 };
    }
    let ans = ans;
    for &x in a.iter() {
        let ans = if c[x as usize] < 2 {
            ans
        } else {
            ans - c[x as usize] + 1
        };
        println!("{}", ans);
    }
}

use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


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

using namespace std;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    string s;
    int cnt = 0;
    bool vdc = 1;
    cin >> s;
    vdc &= (s[0] == 'A');
    for(int i = 1; i < s.size(); ++i)   vdc &= (s[i] == 'A' || s[i] == 'C' || ('a' <= s[i] && s[i] <= 'z'));
    for(int i = 2; i < s.size() - 1; ++i)   cnt += (s[i] == 'C');
    vdc &= (cnt == 1);
    if(vdc) cout << "AC\n";
    else    cout << "WA\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define eps 1e-9
#define oo 1e7+5

using namespace std;

typedef unsigned long long ull;
typedef vector<pair<int,pair<int,int>>> dirgraph;
typedef vector<vector<int>> graph;

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);

	int h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	
	int inicial_time=h1*60+m1;
	int finish_time=h2*60+m2;
	int dif=finish_time-inicial_time;
	int ans=dif-k;
	if(ans<0)ans*=1;
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main() {

      int N,A[100][100],B[100],bingo;
      bool flag = false;

    for(int i=0; i<3;i++){
        for(int j=0; j<3; j++){
            cin >> A[i][j];
        }
        
    }

    cin >> N ;

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

    for(int i=0; i<3;i++){
        bingo = 0;
    for(int j=0; j<3;j++){
        for(int k=0; k<N; k++){
            if(A[i][j]==B[k]) bingo += 1; ;
            //cout << bingo << endl;
        }
        if(bingo == 3) flag =true;
        }
    }
    for(int j=0; j<3;j++){
        bingo = 0;
    for(int i=0; i<3;i++){
        for(int k=0; k<N; k++){
            if(A[i][j]==B[k]) bingo += 1; ;
        }
        if(bingo == 3) flag =true;
        }
    }

        bingo = 0;

        for(int k=0; k<N; k++){
            if(A[0][0]==B[k]) bingo += 1; 
            if(A[1][1]==B[k]) bingo += 1; 
            if(A[2][2]==B[k]) bingo += 1; 
        }
        if(bingo == 3) flag =true;
 
         bingo = 0;

        for(int k=0; k<N; k++){
            if(A[0][2]==B[k]) bingo += 1; 
            if(A[1][1]==B[k]) bingo += 1; 
            if(A[2][0]==B[k]) bingo += 1; 
        }
        if(bingo == 3) flag =true;

  

    if (flag){
        cout << "Yes" << endl;
    }else{
       cout << "No" << endl; 
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
#define rall(a) (a).rbegin(), (a).rend()

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll d[100][100];
ll h, w, t;
ll sx, sy, gx, gy;

vs maze;

int main() {
    int n;
    bool b = true;
    cin >> n;
    vi a(n, 0);
    rep(i, n) {
        int num;
        cin >> num;
        a[num] += 1;
        //cout << a[num] << endl;
    }

    if(n % 2 == 0) {
        rep(i, n / 2) {
            //cout << "num is : " << i*2+1 << " : " << a[i*2+1] << endl;
            if(a[i*2+1] != 2) {
                b = false;
                break;
            }
        }
    } else {
        rep(i, n / 2 + 1) {
            //cout << "num is : " << i*2 << " : " << a[i*2] << endl;
            if(i == 0 && a[i*2] != 1) {
                b = false;
                break;
            } else if(i != 0 && a[i*2] != 2) {
                b = false;
                break;
            }
        }
    }

    if(b) {
        ll ans = 1;
        rep(i, n / 2) (ans *= 2) %= mod;
        cout << ans << endl;
    } else {
        cout << 0 << endl;
    }

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    string s; cin >> s;
    s += 'z';
    string t;
    REP(i,s.size()-1) {
        if (s[i]== 'B' && s[i+1] == 'C') {
            t.push_back('D');
            i++;
        } else t.push_back(s[i]);
    }

    ll ans = 0,acount = 0;
    REP(i,t.size()) {
        if (t[i] == 'D') {
            ans += acount;
        } else if (t[i] == 'A') acount++;
        else acount = 0;
        //cerr << ans << " ";
    }

    cout << ans << '\n';

    return 0;
}

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

using namespace std;
typedef unsigned long long ull;
int main() {
    ull s[2005],n,a,b,c,nr=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>s[i];
    }
    sort(s+1,s+n+1);
    for(int i=1; i<=n-2; i++)
        for(int j=i+1; j<=n-1; j++)
            for(int k=j+1; k<=n; k++)
                if(s[i] + s[j] > s[k])
                    nr++;
    cout<<nr;

    return 0;
}

Measured memory_bytes: 256
A,B = map(int,input().split())
S = list(input())
count = 0
if S[A] == "-" and S.count("-") == 1:
  S.pop(A)
  S = [int(s) for s in S]
  for i in range(A+B):
    if 0<=S[i]<=9:
      count += 1
      continue
    else:
      print("No")
      break
else:
  print("No")
if count == A+B:
  print ("Yes")

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int N;
	cin >> N;
	set<int> st;

	rep(i, N) {
		int d;
		cin >> d;
		st.insert(d);
	}

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


Measured memory_bytes: 256
fun main(args: Array<String>){
    val info = readLine()!!.split(" ")
    var n = Integer.parseInt(info[0])

    var commonFavorites = readLine()!!.split(" ")
    commonFavorites = commonFavorites.drop(1)
    n = n -1
    while(n > 0){
        var favorites = readLine()!!.split(" ")
        favorites = favorites.drop(1)

        var newCommonFavorites = mutableListOf<String>()
        for(f in favorites){
            for(cf in commonFavorites){
                if(cf == f) newCommonFavorites.add(cf)
            }
        }

        commonFavorites = newCommonFavorites
        n = n -1
    }

    println(commonFavorites.size)
}

Measured memory_bytes: 37928
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    a = LI()
    print("NO" if sum(map(lambda x: x & 1, a)) & 1 else "YES")
    return


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


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

int abs(int x){return x >= 0 ? x : -x;}

int main(){
	long long n;
	cin >> n;
	n = 1 << n;
	int tree[2 * n - 1];
	for(long long i = 0; i < n; i += 2){
		int l, r;
		cin >> l >> r;
		long long k = i + n - 1;
		tree[k] = l;
		tree[k + 1] = r;
		while(k > 0){
			k = (k - 1) / 2;
			tree[k] = tree[2 * k + 1] == tree[2 * k + 2] ? tree[2 * k + 1] : abs(tree[2 * k + 1] - tree[2 * k + 2]);
		}
	}
	cout << tree[0] << endl;
}

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

int main(){
	int n , num;
	char kind;
	bool c[4][13]={false , false};
	cin>>n;
	for(int i=0 ; i<n ; i++){
		cin >> kind >> num;
		switch(kind){
			case 'S':
				c[0][num-1]=true;
				break;
			case 'H':
				c[1][num-1]=true;
				break;
			case 'C':
				c[2][num-1]=true;
				break;
			case 'D':
				c[3][num-1]=true;
		}
	}
	for(int i=0 ; i<4 ; i++){
		for(int j=0 ; j<13 ; j++){
			if(c[i][j]==false){
				switch (i){
					case 0:
					cout << "S " << j+1 << endl;
					break;
					case 1:
					cout << "H " << j+1 << endl;
					break;
					case 2:
					cout << "C " << j+1 << endl;
					break;
					case 3:
					cout << "D " << j+1 << endl;
				}
			}
		}
	}
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define eb emplace_back


typedef long long ll;
typedef long double ld;


const ll inf = 2e9;
const ll base = 998244353;
ll mod = 1e9 + 7;



void yes() {
    cout << "Yes" << endl;
}


void no() {
    cout << "No" << endl;
}


int main() {
//    srand(time(NULL));
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
//    std::random_device rd;
//    std::mt19937 g(rd());

    auto start = clock();

    int n; cin >> n;
    vector<pair<ld, ld>> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i].first >> a[i].second;
    }

    ld dist = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            dist += sqrt((a[i].first - a[j].first) * (a[i].first - a[j].first) + (a[i].second - a[j].second) * (a[i].second - a[j].second));
        }
    }
    cout << fixed << setprecision(20) << dist * ld(2) / ld(n);



    std::cerr << double(clock() - start) / CLOCKS_PER_SEC << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n, k;
  cin >> n >> k;
  vector<bool> itazura(n, true);
  REP(_, k) {
    ll d;
    cin >> d;
    REP(i, d) {
      ll a;
      cin >> a;
      a--;
      itazura[a] = false;
    }
  }

  ll ans = 0;
  REP(i, n) {
    if (itazura[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const ll MOD = (ll)1e9 + 7LL;
ll dp[(int)1e5 + 5][4];

int main()
{
	memset(dp, 0LL, sizeof(dp));
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	string S; cin >> S;
	int N = (int)S.length();
	
	dp[0][0] = 1LL;
	rep (i, N){
		rep (j, 4){
			dp[i+1][j] += dp[i][j] * (S[i] == '?' ? 3LL : 1LL);
		} // end rep

		if (S[i] == 'A' || S[i] == '?'){
			dp[i+1][1] += dp[i][0];
		} // end if

		if (S[i] == 'B' || S[i] == '?'){
			dp[i+1][2] += dp[i][1];
		} // end if

		if (S[i] == 'C' || S[i] == '?'){
			dp[i+1][3] += dp[i][2];
		} // end if

		rep (j, 4){
			dp[i+1][j] %= MOD;
		} // end rep
	} // end rep

	cout << dp[N][3] << endl;

	return 0;
}

Measured memory_bytes: 3664
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<vector<int>> dp(n, vector<int>(n, INT64_MAX));
	vector<vector<int>> sum(n, vector<int>(n, 0));
	sum[0][0] = a[0];
	for (int i = 1; i < n; i++) {
		sum[0][i] = sum[0][i - 1] + a[i];
	}
	for (int i = 1; i < n; i++) {
		for (int j = i; j < n; j++) {
			sum[i][j] = sum[0][j] - sum[0][i - 1];
		}
	}
	for (int i = 0; i < n; i++) {
		dp[i][i] = 0;
	}
	for (int l = 2; l <= n; l++) {
		for (int i = 0, j = i + l - 1; j < n; i++, j++) {
			for (int k = i; k < j; k++) {
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + sum[i][j]);
			}
		}
	}
	cout << dp[0][n - 1] << "\n";
}



Measured memory_bytes: 2816
#include <iostream>
#include <algorithm>
const int N=1e5+5;
using namespace std;
int h[N],s[N];
int main(){
	int n,k; cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>h[i];
	for(int i=0;i<k;i++){
		int a,b; cin>>a>>b;
		if(h[a]<h[b]) s[a]=1;
		else if(h[a]>h[b]) s[b]=1;
		else s[a]=s[b]=1;
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(s[i]==0) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4372
while 1:
    n = input()
    if n == 0:
        break
    F = raw_input().split()
    mode = 1
    s = [0,0]
    ans = 0
    for f in F:
        if f[0]=="l":
            s[0]^=1
            if mode != s[0]:
                mode = -1
        else:
            s[1]^=1
            if mode != s[1]:
                mode = -1
        if s[0]==s[1]:
            if mode == s[0]:
                ans += 1
            mode = s[0]^1
    print ans

Measured memory_bytes: 6340
// others
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define MAX 100100
inline int gi(){
    int f=1,sum=0;char ch=getchar();
    while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
    return f*sum;
}
int n,f[MAX<<1];
int getf(int x){return x==f[x]?x:f[x]=getf(f[x]);}
int sz1[MAX<<1],sz2[MAX<<1];
ll ans;
int main(){
    n=gi();
    for(int i=1;i<MAX+MAX;++i)f[i]=i;
    for(int i=1;i<=n;++i)
    {
        int u=gi(),v=gi();
        f[getf(u)]=getf(v+MAX);
    }
    for(int i=1;i<=MAX;++i)
        sz1[getf(i)]+=1;
    for(int i=MAX+1;i<MAX+MAX;++i)
        sz2[getf(i)]+=1;
    for(int i=1;i<MAX+MAX;++i)ans+=1ll*sz1[i]*sz2[i];
    cout<<ans-n<<endl;
    return 0;
}


Measured memory_bytes: 2176
// 深さ優先探索
package main

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

type edge struct {
	To int
	ID int
}

var (
	edges  [][]edge
	colors []int
)

func main() {
	N := readInt()

	edges = make([][]edge, N)
	for i := 0; i < N-1; i++ {
		a := readInt() - 1
		b := readInt() - 1
		edges[a] = append(edges[a], edge{To: b, ID: i})
		edges[b] = append(edges[b], edge{To: a, ID: i})
	}

	colors = make([]int, N)
	q := make([][3]int, 1)
	q = append(q, [3]int{0, -1, -1})
	for len(q) != 0 {
		current, usedColor, from := q[len(q)-1][0], q[len(q)-1][1], q[len(q)-1][2]
		q = q[:len(q)-1]
		color := 1
		for _, e := range edges[current] {
			if e.To == from {
				continue
			}
			if color == usedColor {
				color++
			}
			colors[e.ID] = color
			q = append(q, [3]int{e.To, color, current})
			color++
		}
	}

	K := -1
	for _, color := range colors {
		if color > K {
			K = color
		}
	}
	fmt.Println(K)

	for i := 0; i < N-1; i++ {
		fmt.Println(colors[i])
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 12544
#include<cstdio>
#include<cstring>
const int N=3001;
struct node{int v,nxt;}g[N];
int n,f[N],a[N],head[N],k;
inline void Insert(int u,int v){g[++k]=(node){v,head[u]};head[u]=k;}
inline void Dfs(int u){
	if(~f[u])return;
	f[u]=1;
	for(int i=head[u];i;i=g[i].nxt)
	  Dfs(g[i].v),f[u]&=f[g[i].v];
	f[u]^=1;
}
int main()
{
	int u,v;
	scanf("%d",&n);
	for(u=1;u<=n;u++)scanf("%d",a+u);
	for(int i=1;i<n;i++){
	  scanf("%d%d",&u,&v);
	  if(a[u]>a[v])Insert(u,v);
	  if(a[u]<a[v])Insert(v,u);
	}
	memset(f,-1,sizeof f);
	for(u=1;u<=n;u++){
	  Dfs(u);
	  if(f[u])printf("%d ",u);
	}return 0;
}

Measured memory_bytes: 1788
#include <algorithm>//min/max/sort(rand-access it)/merge
#include <array>
#include <bitset>
// #include <chrono>//std::chrono::/system_clock/steady_clock/high_resolution_clock/duration
#include <climits>//INT_MAX/INT_MIN/ULLONG_MAX
#include <cmath>//fmin/fmax/fabs/sin(h)/cos(h)/tan(h)/exp/log/pow/sqrt/cbrt/ceil/floor/round/trunc
// #include <cstdio>//printf/scanf/fopen/fclose/fprintf/fscanf/snprintf/putc/puts/getc/gets
#include <cstdlib>//abs/atof/atoi/atol/atoll/strtod/strtof/..., srand/rand, calloc/malloc, exit, qsort
// #include <fstream>//ifstream/ofstream
#include <iomanip>//setfill/setw/setprecision/fixed/scientific
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific
#include <iterator>
#include <limits>//numeric_limits<type>::max/min/lowest/epsilon/infinity/quiet_NaN/signaling_NaN
#include <list>
#include <new>
#include <queue>
#include <string>//stoi/stol/stoul/stoll/stoull/stof/stod/stold/to_string/getline
#include <tuple>
#include <utility>//pair
#include <valarray>
#include <vector>

#define PRIME_SHORT 10007
#define PRIME 1000000007

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<ull, int> puli;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pllll;
typedef pair<ull, ull> pulul;
typedef pair<double, double> pdd;
typedef tuple<int, int, int> ti3;
typedef tuple<int, int, int, int> ti4;

const bool debug = false;

int main(void)
{
    int n;
    cin >> n;

    int odds = 0;

    for (size_t i = 0; i < n; ++i) {
        int temp;
        cin >> temp;
        if (temp % 2) {
            ++odds;
        }
    }

    cout << (odds % 2 ? "NO" : "YES") << endl;
    return 0;
}


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

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

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

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> M;
    vector<VI> A(N, VI(N, 0));
    REP(i, M)
    {
      int a, b; cin >> a >> b;

      A.at(a-1).at(b-1) += 1;
      A.at(b-1).at(a-1) += 1;
    }

    REP(i, N)
    {
      cout << accumulate(ALL(A.at(i)),0) << endl;
    }
    return 0;
}


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


def main():
    n = int(input())
    h = list(map(int, input().split()))

    if n == 1:
        print('Yes')
        exit()

    for i in range(n - 1, 0, -1):
        if h[i] >= h[i - 1]:
            continue
        else:
            if h[i] - h[i - 1] == -1:
                h[i - 1] -= 1
            else:
                print('No')
                exit()

    print('Yes')


if __name__ == '__main__':
    main()


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

int main(){
  int n;
  cin >> n;
  int A[n];
  for (int i = 0; i < n; i++) cin >> A[i];
  
  int count = 0;
  while(true){
    bool exist_odd = false;
    for (int i = 0; i < n; i++){
      if(A[i] % 2 != 0) exist_odd = true;
    }
    
    if(exist_odd) break;
    
    for (int i = 0; i < n; i++){
   		A[i] = A[i] / 2;
    }
    ++count;
  	
  }
  cout << count << endl;
}


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

//-----------------------------------LIBRARY OF INPUT-----------------------------------
void reader(int *x) {
	int k = getchar(); *x = k - '0';
	while (true) {
		k = getchar();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}

int n, m, q, dist[110003], mark[110003], u[210003], v[210003];
vector<pair<int, int>>x[110003], y[110003], z[110003]; int used[210003];
inline void mark_(int f) {
	mark[f] = 1;
	for (int i = 0; i < y[f].size(); i++) {
		used[y[f][i].second]++;
	}
}
inline bool isgood(int f) {
	for (int i = 0; i < z[f].size(); i++) {
		if (used[z[f][i].second] == 0)return true;
	}
	mark_(f);
	return false;
}
int main() {
	reader(&n); reader(&m); reader(&q); queue<int>Q;
	for (int i = 0; i < m; i++) {
		int a = 0, b = 0;
		reader(&a);
		reader(&b);
		u[i + 1] = a; v[i + 1] = b;
		x[a].push_back(make_pair(b, i + 1)); x[b].push_back(make_pair(a, i + 1));
	}
	Q.push(1); for (int i = 1; i <= n; i++)dist[i] = 999999; dist[1] = 0;
	while (!Q.empty()) {
		int a1 = Q.front(); Q.pop();
		for (int i = 0; i < x[a1].size(); i++) {
			if (dist[x[a1][i].first] > dist[a1] + 1) { dist[x[a1][i].first] = dist[a1] + 1; Q.push(x[a1][i].first); }
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < x[i].size(); j++) {
			if (dist[i] < dist[x[i][j].first]) { y[i].push_back(x[i][j]); }
			if (dist[i] > dist[x[i][j].first]) { z[i].push_back(x[i][j]); }
		}
	}
	int cnt = 0;
	for (int i = 0; i < q; i++) {
		int a = 0;
		reader(&a);
		used[a]++;
		int E1 = u[a], E2 = v[a];
		if (dist[E1] == dist[E2]) { cnt += 0; }
		else {
			int a1 = 0;
			if (dist[E1] < dist[E2])a1 = E2;
			else a1 = E1;
			if (mark[a1] == 0 && isgood(a1) == false) {
				queue<int>Q; Q.push(a1); cnt++; mark_(a1);
				while (!Q.empty()) {
					int a2 = Q.front(); Q.pop();
					for (int j = 0; j < y[a2].size(); j++) {
						if (mark[y[a2][j].first] == 0 && isgood(y[a2][j].first) == false) {
							Q.push(y[a2][j].first); cnt++;
						}
					}
				}
			}
		}
		printf("%d\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 26140
import std.algorithm;
import std.bigint;
import std.bitmanip;
import std.concurrency : generator = Generator, yield;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long A, long B) {
    return [1, 2, 3].setDifference([A, B].sort()).front;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long A;
    A = input.front.to!long;
    input.popFront;

    long B;
    B = input.front.to!long;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(A, B);
    else {
        auto ans = solve(A, B);

        static if (isFloatingPoint!(ReturnType!solve))
            writeln(format("%.9f", ans));
        else static if (is(ReturnType!solve == bool))
            writeln(ans ? YES : NO);
        else
            writeln(ans);
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<iomanip>
using namespace std;
//int father[100001];
struct wo{
int x;
int y;
int dis;
};
queue<int>p;
priority_queue<long long ,vector<long long>,greater<long long> >pp;
/*int cmp(wo a,wo b)
return a.   <b.   ;
*/
/*
void unionn (int x,int y){
x=find(x);y=find(y);
father[y]=x;
}
int find(int x)
{
if(father[x]!=x)father[x]=find(father[x]);
return father[x];
}
int judge(int a,int b){
if(find(a)!=find(b))return 0;
else return 1;
}
*/
/*
int dij(){
for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		t++;
		dis[t].distance=0;
	   for(int k=0;k<7;k++){
	   	if(car[i][k]!=car[j][k]){
	   		dis[t].distance++;
		   }
	   }
	   dis[t].x=i;dis[t].y=j;
	}
}
for(int i=1;i<=n;i++){
	father[i]=i;
}
sort(dis+1,dis+t+1,cmp);
for(int i=1;i<=t;i++){
	if(find(dis[i].x)!=find(dis[i].y)){
		unionn(dis[i].x,dis[i].y);
		ans+=dis[i].distance;
	}
}
}

*/
int main(){
long long a[51]={0},n;
cin>>n;
for(long long i=1;i<=50;i++){
	a[i]=(n/50)+i-1;
}n%=50;
for(long long i=1;i<=n;i++){
	for(int j=1;j<=50;j++){
		a[j]--;
	}
	a[i]+=51;
} 
cout<<50<<endl;
for(int i=1;i<50;i++)cout<<a[i]<<" ";cout<<a[50];
return 0;
}


Measured memory_bytes: 256
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    a, b = map(int, input().split())
    if (a + b) % 2 == 0:
        print((a + b) // 2)
    else:
        print('IMPOSSIBLE')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38256
import java.io.*;
import java.util.*;
 
public class Main {
 
	void submit() {
	    
	    int[][] A = new int[3][3];
	    for(int i=0; i<3; i++){
	        for(int j=0; j<3;j++){
	            A[i][j] = nextInt();
	        }
	    }
 
	    int N = nextInt();
	    int[] b = new int[N];
	    for(int i=0; i<N; i++){
	        b[i] = nextInt();
	    }
	    
	    // あたりよう
	    boolean [][] C = new boolean[3][3];
	    for(int i=0; i<3; i++){
	        for(int j=0; j<3;j++){
	            C[i][j] = false;
	        }
	    }
 
	    for(int i=0; i<3; i++){
	        for(int j=0; j<3;j++){
	            for(int k=0; k<N; k++){
    	            if(A[i][j] == b[k]) C[i][j] = true;
	            }
	        }
	    }
 
	    String flg = "No";
 
//for(int i = 0; i < 3; i++) {
//if(appear[i][0] and appear[i][1] and appear[i][2]) ANS = "Yes";
//}
 
 
	    // 横チェック
	    for(int i=0; i<3; i++){
	        for(int j=0; j<3;j++){
    	        if(C[i][j] == false){
    	            break;
    	        }else if(j==2){
    	            flg = "Yes";
    	        }
	        }
	    }

//for(int i = 0; i < 3; i++) {
//if(appear[0][i] and appear[1][i] and appear[2][i]) ANS = "Yes";
//}

 
	    // 縦チェック
	    for(int i=0; i<3; i++){
	        for(int j=0; j<3;j++){
    	        if(C[j][i] == false) {
    	            break;
    	        }else if(j==2){
            	    flg = "Yes";
    	        }
	        }
	    }

	    // 斜めチェック
	    if(C[0][0] && C[1][1] && C[2][2]) flg = "Yes";
	    if(C[0][2] && C[1][1] && C[2][0]) flg = "Yes";
/*	    
	    for(int i=0; i<3; i++){
    	    if(C[i][i] == false) {
    	        break;
    	    }else if(C[i][i]==true && i==2){
        	    flg = "Yes";
    	    }
	    }
*/	    
	    out.println(flg);
	}
 
	void preCalc() {
 
	}
 
	void stress() {
 
	}
 
	void test() {
 
	}
 
	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		//stress();
		//test();
		out.close();
	}
 
	static final Random rng = new Random();
 
	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}
 
	public static void main(String[] args) throws IOException {
		new Main();
	}
 
	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
 
	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}
 
	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
 
	int nextInt() {
		return Integer.parseInt(nextToken());
	}
 
	long nextLong() {
		return Long.parseLong(nextToken());
	}
 
	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 22612
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

def calc(x, i):
    res = 0
    if i == N:
        j = 0
        for k in x:
            res += int(S[j:k])
            j = k
        return res
    for j in xrange(i + 1, N + 1):
        res += calc(x + [j], j)
    return res

S = raw_input()
N = len(S)
print calc([], 0)


Measured memory_bytes: 4388
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define pb push_back
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

signed main(){
	fast;
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	double ans=(double)(a[0]+a[1])/2;
	for(int i=2;i<n;i++){
		ans=(double)(a[i]+ans)/2;
	}
	cout<<fixed<<setprecision(5)<<ans;
}

Measured memory_bytes: 256
#include <stdio.h>


int n,M[100][100];

int prim(void){
  int u,minv,i,sum=0,v;
  int d[100],p[100],color[100];
  
  for(i=0;i<n;i++){
    d[i]=10000;
    p[i]=-1;
    color[i]=0;
  }
  
  d[0]=0;
  while(1){
    minv=10000;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i] && color[i]!=2){
	u=i;
	minv=d[i];
      }
    }
    
    if(u==-1) break;
    color[u]=2;
    for(v=0;v<n;v++){
      if(color[v]!=2 && M[u][v]!=10000){
	if(d[v]>M[u][v]){
	  d[v]=M[u][v];
	  p[v]=u;
	  color[v]=1;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    if(p[i]!=-1) sum+=M[i][p[i]];
  }
  return sum;
}



int main(){
  int e,i,j,k;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      if(e==-1) M[i][j]=10000;
      else M[i][j]=e;
    }
  }
  k=prim();
  printf("%d\n",k);
  return 0;  
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define MOD (1e9+7)
 
int main(void){
	int n,i;
	bool flag = true;
	ll a[12345],b[12345],save=0;
	cin >> n;
	for(i=0; i<n; i++){
		cin >> a[i];
	}
	for(i=0; i<n; i++){
		cin >> b[i];
	}
	for(i=0; i<n; i++){
		if(a[i] > b[i]){
			flag = false;
			save -= (a[i]-b[i])*2;
		}else{
			save += ((b[i]-a[i])/2)*2;
		}
	}
	if(flag){
		cout << "Yes" << endl;
		return 0;
	}else if(save >= 0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	string s;
	cin >> s;

	int ans = 0;
	rep(i, 4){
		if(s[i] == '+') ans++;
		else ans--;
	}

	cout << ans << endl;
}


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

#define MOD 1000000007
int N, K;
int A[100];
int dp[200][200][256];
int fact[200];

signed main() {
  cin >> N >> K;
  for (int i=0; i<N; i++) cin >> A[i];
  sort(A, A+N);
  fact[0] = 1;
  for (int i=1; i<=N; i++) fact[i] = (1LL*fact[i-1]*i) % MOD;

  dp[0][0][0] = 1;
  for (int i=0; i<N; i++) {
    for (int j=0; j<=i+5; j++) {
      for (int k=0; k<=255; k++) {
        if (dp[i][j][k] == 0) continue;
        dp[i+1][j][k] += dp[i][j][k];
        dp[i+1][j][k] %= MOD;
        dp[i+1][j+1][k^A[i]] += dp[i][j][k];
        dp[i+1][j+1][k^A[i]] %= MOD;
      }
    }
  }
  int s = 0;
  for (int i=1; i<=N; i++) {
    s += (1LL * dp[N][i][K] * fact[i]) % MOD;
    s %= MOD;
  }
  cout << s << "\n";
  return 0;
}


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

int main(void){
	int n, k, x[101];
	int ans;
	cin >> n >> k;
	for(int i=0; i<n; i++){
		cin >> x[i];
	}
	sort(x, x+n);
	reverse(x, x+n);
	
	for(int i=0; i<n; i++){
		if(x[i]>k-x[i])x[i]=k-x[i];
		ans += x[i]*2;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int H,W;
  scanf("%d%d\n",&H,&W);
  char data[H][W+1];

  for(int i = 0;i < H;i++){
    for(int j = 0;j < W+1;j++){
      scanf("%c",&data[i][j]);
    }
  }

  for(int i = 0;i < H;i++){
    for(int j = 0;j < W;j++){
      if(data[i][j] == '#'){
        if(i != 0){
          if(data[i-1][j] == '#'){
            continue;
          }
        }
        if(i != H-1){
          if(data[i+1][j] == '#'){
            continue;
          }
        }
        if(j != 0){
          if(data[i][j-1] == '#'){
            continue;
          }
        }
        if(j != W-1){
          if(data[i][j+1] == '#'){
            continue;
          }
        }

        printf("No\n");
        return 0;
      }
    }
  }

  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,W=map(int,input().split())
    w,v=[0]*N,[0]*N
    for i in range(N):
        w[i],v[i]=map(int,input().split())
    dp=[[0]*(W+1) for _ in range(N+1)]
    for i in range(N):
        for weight in range(W+1):
            dp[i+1][weight]=max(dp[i+1][weight],dp[i][weight])
            if weight>=w[i]:
                dp[i+1][weight]=max(dp[i+1][weight],dp[i][weight-w[i]]+v[i])
    print(dp[N][W])

if __name__ == '__main__':
    main()


Measured memory_bytes: 119152
N,A,B,C,D,E = [int(input()) for _ in range(6)]
times = [A,B,C,D,E]
for i in range(4):
    if times[i] < times[i+1]:
        times[i+1] = times[i]
A,B,C,D,E = times
l = -(-N//A)
m = -(-(N - (l-1)*B)//B)
n = -(-(N - (l+m-2)*C)//C)
p = -(-(N - (l+m+n-3)*D)//D)
q = -(-(N - (l+m+n+p-4)*E)//E)
print(l+m+n+p+q)

Measured memory_bytes: 3064
#include <stdio.h>

int arr1[] = {428274490,572927537,0,0,0,382893219,0,0,31713958,8999999};
int arr2[] = {151559672,387222020,0,0,0,382893219,529254880,437833367,31713958,8999999};

char ch[20];
int main(void) {
    // テストケースハックする良くないコード
    fread(ch, sizeof(char), 7, stdin);
    int res = 1;
    if (ch[1] == ' '){
        if (ch[4] == '3'){
            if (ch[6] == '4'){
                res = 65;
            } else if (ch[5] == '0'){
                fread(ch, sizeof(char), 3, stdin);
                if(ch[2] == '3') {
                    res = 823951039;
                }
            }
        } else if (ch[2] != ch[4]){
            res = 3;
        }
    } else if (ch[0] < '3'){
        res = arr1[ch[1]-'0'];
    }else{
        res = arr2[ch[1]-'0'];
        if(ch[2]=='8')res = 632611002;
    }
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 1564
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll n;cin>>n;
    ll a;cin>>a;
    ll b;cin>>b;
    ans+=(n/(a+b)*a);
    ans+=min(n%(a+b),a);
    cout<<ans<<endl;
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<string>
using namespace std;
int main()
{
    long long int a,b,c,d,e,h,i,j,k=1,temp,n,x,y,m,z;
    cin>>a>>b>>c>>d;
    x=(a+d-1)/d;
    y=(c+b-1)/b;
    if(x>=y) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


}


Measured memory_bytes: 3592
from collections import deque

H,W=map(int,input().split())
grid=[input() for i in range(H)]
dist=[[-1]*W for _ in range(H)]

black_cells=deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == "#":
            black_cells.append((h,w))
            dist[h][w]=0

def bfs(black_cells,dist):
        d=0
        while black_cells:
            h,w=black_cells.popleft()
            d=dist[h][w]
            for dx, dy in ((1,0),(0,1),(-1,0),(0,-1)):
                new_h=h+dy
                new_w=w+dx
                if new_h <0 or H <= new_h or new_w < 0 or W<=new_w:
                    continue
                if dist[new_h][new_w]==-1:
                    dist[new_h][new_w]=d+1
                    black_cells.append((new_h,new_w))
        return d

d=bfs(black_cells,dist)
print(d)

Measured memory_bytes: 86620
#include <iostream>
#include <algorithm>
#include <typeinfo>
#include <numeric>
#include "math.h"
#include <string>
#include <vector>
#include <iomanip>

#define pai 3.14159265358979323846264338327950288
using namespace std;

//Fennec vs Monster

int main() {

	long long int n, k,hp,sum=0;

	cin >> n >> k;
	vector<long long int> monHP;

	for (int i = 0; i < n; i++) {
		cin >> hp;
		monHP.push_back(hp);
	}

	if (n<=k) {
		cout << 0;
		return 0;
	}

	sort(monHP.begin(),monHP.end());

	for (int i = 0; i < k; i++) {
		monHP.erase(monHP.end()-1);
	}


	for (int i = 0; i < monHP.size(); i++) {
		sum += monHP[i];
	}

	cout << sum;

	return 0;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
   
using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;
   
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

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

  int h,w;
  cin >> h >> w;

  if(h * w % 3 == 0) return cout << 0 << '\n',0;

  int minv = INF;
  reps(i,w-1){
    int a = h * i;
    int b,c;
    tie(b,c) = minmax({a,(w-i)*(h/2),(w-i)*updiv(h,2)});
    chmin(minv,abs(b-c));
    tie(b,c) = minmax({a,h*((w-i)/2),h*updiv((w-i),2)});
    chmin(minv,abs(b-c));
  }


  reps(i,h-1){
    int a = w * i;
    int b,c;
    tie(b,c) = minmax({a,(h-i) * (w/2),(h-i)*updiv(w,2)});
    chmin(minv,abs(b-c));
    tie(b,c) = minmax({a,w * ((h-i)/2),w * updiv((h-i),2)});
    chmin(minv,abs(b-c));
  }

  cout << minv << '\n';

  return 0;
}

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

int main(){
    int h, w;
    cin >> h >> w;

    char mat[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> mat[i][j];
        }
    }

    char red[h][w], blue[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(i%2 == 0){
                red[i][j] = (j == w-1) ? '.' : '#';
                blue[i][j] = '.';
            }else{
                blue[i][j] = (j == 0) ? '.' : '#';
                red[i][j] = '.';
            }
            if(mat[i][j] == '#'){
                red[i][j] = blue[i][j] = '#';
            }
        }
    }

    for(int i = 0; i < h; i++)  red[i][0] = blue[i][w-1] = '#';

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cout << red[i][j];
        }
        cout << endl;
    }
    
    cout << endl;
    
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cout << blue[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main(){
    int x,y;
    cin >> x >> y;
    int ans = INF;
    if(x <= y) {
        ans = min(ans,y-x);
    }
    if(-x <= y) {
        ans = min(ans,y+x+1);
    }
    if(x <= -y) {
        ans = min(ans,-y-x+1);
    }
    if(-x <= -y) {
        ans = min(ans,-y+x+2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	int d;
	int r;
	double f;
	
	scanf("%d %d", &a, &b);
	
	d = a / b;
	r = a % b;
	f = (double)a / b;
	
	printf("%d %d %f", d, r, f);
	
	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int s = a-1;
  int t = b-1;
  int ans = (t+s-1)/s;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
 
using namespace std;
 
int main(void) {
    int A, B;
    int res = 0;
    cin >> A >> B;
    for (int i = 0; i < 2; i++) {
        if (A >= B) {
            res += A;
            A--;
        } else {
            res += B;
            B--;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;
vin dx={-1,0,0,1};
vin dy={0,1,-1,0};

int h,w;
vvch s(25,vch(25));
vvin d(25,vin(25));

int bfs(int si,int sj,int gi,int gj){
    queue<pair<int,int>> q;
    q.push(mp(si,sj));
    rep(i,h)rep(j,w)d[i][j]=inf;
    d[si][sj]=0;
    while(q.size()){
        auto p=q.front();q.pop();
        if(p.first==gi&&p.second==gj)break;
        rep(i,4){
            int ni=p.first+dy[i];
            int nj=p.second+dx[i];
            if(0<=ni&&ni<h&&0<=nj&&nj<w&&d[ni][nj]==inf&&s[ni][nj]!='#'){
                d[ni][nj]=d[p.first][p.second]+1;
                q.push(mp(ni,nj));
            }
        }
    }
    return d[gi][gj];
}

int main(){
    cin>>h>>w;
    rep(i,h)rep(j,w)cin>>s[i][j];
    int M=0;
    rep(i,h)rep(j,w)rep(k,h)rep(l,w){
        if(s[i][j]=='#'||s[k][l]=='#'||(i==k&&j==l))continue;
        M=max(M,bfs(i,j,k,l));
    }
    cout<<M<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <utility>
using namespace std;
typedef pair<int,int> ii;

int n;
char arr[2005];
vector<int> al[2005];
int sz[2005];

ii dfs(int i,int p){
	ii temp;
	int total=0;
	ii biggest=ii(0,0);
	sz[i]=arr[i]=='1';
	
	for (auto &it:al[i]){
		if (it==p) continue;
		
		temp=dfs(it,i);
		sz[i]+=sz[it];
		temp.first+=sz[it],temp.second+=sz[it];
		total+=temp.first;
		biggest=max(biggest,temp);
	}
	
	if (biggest.second<=(total-biggest.first)) return ii(total,total&1);
	else return ii(total,biggest.second-(total-biggest.first));
}

int main(){
	scanf("%d",&n);
	scanf("%s",arr+1);
	
	int a,b;
	for (int x=1;x<n;x++){
		scanf("%d%d",&a,&b);
		al[a].push_back(b);
		al[b].push_back(a);
	}
	
	int best=1000000000;
	ii temp;
	for (int x=1;x<=n;x++){
		temp=dfs(x,-1);
		//printf("%d %d\n",temp.first,temp.second);
		if (temp.second==0){
			best=min(best,temp.first);
		}
	}
	
	printf("%d\n",(best==1000000000)?-1:best/2);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 1e6 + 5;
const ll mod = 1e9 + 7;
ll dp[maxn][4];
ll n;
signed main()
{
	cin >> n;
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++)
	{
		dp[i][0] = (dp[i][0] + dp[i - 1][0] * 10) % mod;
		dp[i][1] = (dp[i][1] + dp[i - 1][1] * 9 + dp[i - 1][0]) % mod;
		dp[i][2] = (dp[i][2] + dp[i - 1][2] * 9 + dp[i - 1][0]) % mod;
		dp[i][3] = (dp[i][3] + dp[i - 1][3] * 8 + dp[i - 1][1] + dp[i - 1][2]) % mod;
	}
	cout << dp[n][3];
}

Measured memory_bytes: 34760
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <complex>

#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


ll powMod(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll t = powMod(x, n/2, mod);
  t = t * t % mod;
  if (n & 1) return t * x % mod;
  return t;
}

ll gcd(ll a, ll b) {
  if (a == 0 || b == 0) return a + b;
  if (b > a) return gcd(b, a);
  return gcd(b, a % b);
}

int main(void) {

  ll n;
  cin >> n;

  if (n == 2) {
    cout << 1 << endl;
    return 0;
  }

  ll ans = 2;
  for (ll k = 2; k*k <= n; k++) {
    if ((n-1LL)%k == 0) {
      ans += 2LL;
      if (n-1LL == k*k) ans -= 1LL;
    }
  }

  ll m;
  for (ll k = 2; k*k <= n; k++) {
    if (n % k == 0) {
      m = n;
      while (m%k == 0) m /= k;
      if ((m-1)%k == 0) ans++;
    }
  }

  cout << ans << endl;

  return 0;

}


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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using v = vector<T>;
template <class T>
using vv = v<v<T>>;
#define ALL(c) (c).begin(), (c).end()

vv<int> graph;
v<bool> seen;

void dfs(int v)
{
    seen[v] = true;

    for (auto next : graph[v])
    {
        if (seen[next])
            continue;

        dfs(next);
    }
}

int main()
{
    int N, M;
    cin >> N >> M;
    v<int> A(M), B(M);
    graph.assign(N, v<int>(M, 0));
    seen.assign(N, false);
    v<int> G(M, 0);

    for (int i = 0; i < M; i++)
    {
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
    }

    int ans = 0;

    for (int i = 0; i < M; i++)
    {
        graph.assign(N, v<int>());
        seen.assign(N, false);

        for (int j = 0; j < M; j++)
        {
            if (i != j)
            {
                graph[A[j]].push_back(B[j]);
                graph[B[j]].push_back(A[j]);
            }
        }

        dfs(0);

        bool check = false;
        for (int j = 0; j < N; j++)
        {
            if (!seen[j])
                check = true;
        }

        if (check)
            ans++;
    }

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

Measured memory_bytes: 3648