akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;
typedef std::pair<LL, LL> P;
struct edge { LL to, cost; };

int H, W, N;
std::string field[1123];
int Sx, Sy, x[11], y[11], ans;

int d[1123][1123];
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 };
void bfs(LL sx, LL sy, LL gx, LL gy)
{
	std::queue<P>que;
	memset(d, -1, sizeof(d));
	que.push({ sx,sy });
	d[sx][sy] = 0;
	while (que.size() > 0)
	{
		auto pos = que.front(); que.pop();
		if (pos.first == gx && pos.second == gy) { break; }
		rep(i, 4)
		{
			auto toX = pos.first + dx[i], toY = pos.second + dy[i];
			if (0 <= toX && toX < H && 0 <= toY && toY < W)
			{
				if (field[toX][toY] != 'X' && d[toX][toY] == -1)
				{
					que.push({ toX,toY });
					d[toX][toY] = d[pos.first][pos.second] + 1;
				}
			}
		}
	}
}

int main()
{
	in >> H >> W >> N;
	rep(i, H) { in >> field[i]; }

	rep(i, H)
	{
		rep(j, W)
		{
			if (field[i][j] == 'X') { continue; }
			if (field[i][j] == 'S') { Sx = i; Sy = j; }
			else if (field[i][j] != '.') { x[field[i][j] - '0'] = i; y[field[i][j] - '0'] = j; }
		}
	}
	x[0] = Sx; y[0] = Sy;
	rep(i, N)
	{
		bfs(x[i], y[i], x[i + 1], y[i + 1]);
		ans += d[x[i + 1]][y[i + 1]];
	}
	out << ans << std::endl;
	return 0;
}

Measured memory_bytes: 9020
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	xlist := IntSlice(n)
	total := SumSlice(xlist)
	avg := total / n
	p1, p2 := avg, avg+1
	dsum1, dsum2 := 0, 0

	for i := 0; i < n; i++ {
		dsum1 += IntPow(p1-xlist[i], 2)
		dsum2 += IntPow(p2-xlist[i], 2)
	}
	fmt.Println(Min(dsum1, dsum2))
}

func IntSlice(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&slice[i])
	}
	return slice
}

func SumSlice(slice []int) int {
	total := 0
	for i := 0; i < len(slice); i++ {
		total += slice[i]
	}
	return total
}

func Min(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func IntPow(x, pow int) int {
	return int(math.Pow(float64(x), float64(pow)))
}


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

int main(void){
	int A[3];
	long long sum = 0;
	for(int i=0;i<3;i++){
		cin >> A[i];
		sum += A[i];
	}
	if(sum==17){
		for(int i=0;i<3;i++){
			if(A[i]!=5 && A[i]!=7){
				cout << "NO";
				return 0;
			}
		}
		cout <<"YES";
		return 0;
	}
	cout << "NO";
	return 0;
}
	

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <numeric>

using namespace std;

typedef long long int ll;
typedef long int li;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}



ll find_all(const string str, const string subStr) {
    vector<ll> result;
    ll k=0;
    ll subStrSize = subStr.size();
    ll pos = str.find(subStr);
    
    while (pos != string::npos) {
        k++;
        result.push_back(pos);
        pos = str.find(subStr, pos + subStrSize);
    }
    
    return k;
}

int main() {
    ll ans = 0;
    ll a,b,k,n;
    string s;
    cin >> n >> k ;
    cin >> s;
    if(s.at(k-1)=='A'){s.at(k-1)='a';}
    if(s.at(k-1)=='B'){s.at(k-1)='b';}
    if(s.at(k-1)=='C'){s.at(k-1)='c';}
    cout << s << endl;
    return 0;
}



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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;
const int mxn=2e5+5;
int a[mxn];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n; cin >> n;
	int look=1;
	for(int i=0; i<n; i++){
		cin >> a[i];
		if(a[i]==look){
			look++;
		}
	}
	if(look==1){
		cout << -1 << endl;
	}else{
		cout << n-look+1 << endl;
	}
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 4400
class Twelvefold(): #n <= 1000程度
    def __init__(self, n, mod):
        self.mod = mod
        self.fct = [0 for _ in range(n + 1)]
        self.inv = [0 for _ in range(n + 1)]
        self.stl = [[0 for j in range(n + 1)] for i in range(n + 1)]
        self.bel = [[0 for j in range(n + 1)] for i in range(n + 1)]
        self.prt = [[0 for j in range(n + 1)] for i in range(n + 1)]
        self.fct[0] = 1
        self.inv[0] = 1
        self.stl[0][0] = 1
        self.bel[0][0] = 1
        for i in range(n):
            self.fct[i + 1] = self.fct[i] * (i + 1) % mod
        self.inv[n] = pow(self.fct[n], mod - 2, mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i + 1] * (i + 1) % mod
        for i in range(n):
            for j in range(n):
                self.stl[i + 1][j + 1] = self.stl[i][j] + (j + 1) * self.stl[i][j + 1]
                self.stl[i + 1][j + 1] %= mod
        for i in range(n):
            for j in range(n):
                self.bel[i + 1][j + 1] = self.bel[i + 1][j] + self.stl[i + 1][j + 1] % mod
                self.bel[i + 1][j + 1] %= mod
        for j in range(n):
            self.prt[0][j] = 1
        for i in range(n):
            for j in range(n):
                if i - j >= 0:
                    self.prt[i + 1][j + 1] = self.prt[i + 1][j] + self.prt[i - j][j + 1]
                else:
                    self.prt[i + 1][j + 1] = self.prt[i + 1][j]
                self.prt[i + 1][j + 1] %= mod

    def solve(self, element, subset, equate_element=False, equate_subset=False, less_than_1=False, more_than_1=False):
        assert not less_than_1 or not more_than_1
        n = element
        k = subset
        a = equate_element
        b = equate_subset
        c = less_than_1
        d = more_than_1
        id = a * 3 + b * 6 + c + d * 2
        tw = [self.tw1, self.tw2, self.tw3, self.tw4, self.tw5, self.tw6, self.tw7, self.tw8, self.tw9, self.tw10, self.tw11, self.tw12]
        return tw[id](n, k)

    def tw1(self, n, k):
        return pow(k, n, self.mod)

    def tw2(self, n, k):
        if k - n < 0: return 0
        return self.fct[k] * self.inv[k - n] % self.mod

    def tw3(self, n, k):
        return self.stl[n][k] * self.fct[k] % self.mod

    def tw4(self, n, k):
        if k == 0: return 0
        return self.fct[n + k - 1] * self.inv[n] * self.inv[k - 1] % self.mod

    def tw5(self, n, k):
        if k - n < 0: return 0
        return self.fct[k] * self.inv[n] * self.inv[k - n] % self.mod

    def tw6(self, n, k):
        if n - k < 0 or k == 0: return 0
        return self.fct[n - 1] * self.inv[k - 1] * self.inv[n - k]

    def tw7(self, n, k):
        return self.bel[n][k]

    def tw8(self, n, k):
        if k - n < 0: return 0
        return 1

    def tw9(self, n, k):
        return self.stl[n][k]

    def tw10(self, n, k):
        return self.prt[n][k]

    def tw11(self, n, k):
        if k - n < 0: return 0
        return 1

    def tw12(self, n, k):
        if n - k < 0: return 0
        return self.prt[n - k][k]

n, k = map(int, input().split())
t = Twelvefold(1000, 10**9 + 7)
print(t.solve(n, k, 0, 0, 0, 0))


Measured memory_bytes: 110660
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <tuple>
#include <functional>
#include <map>
#include <unordered_map>
#include <queue>
#include <tuple>
#include <random>
#include <stack>

using namespace std;

#define endl '\n'

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

using lld = long double;
using ull = unsigned long int;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  const int precision = 13;
  cout.precision(precision);
  cout.setf(ios_base::fixed);

  int n; cin >> n;
  vector<ll> a(n);
  for (auto& it : a) cin >> it;
  for (int i = 1; i < n; ++i) a[i] += a[i-1];

  vector<vector<ll>> dp(n, vector<ll>(n+1, 0));

  for (int i = 0; i < n; ++i) {
    dp[i][i] = a[i];
    if (i > 0) dp[i][i] -= a[i-1];
    for (int j = i-1; j >= 0; --j) {
      ll acc = a[i] - (j > 0 ? a[j-1] : 0);
      dp[i][j] = max(acc - dp[i-1][j], acc - dp[i][j+1]);
    }
  }

  cout << 2 * dp[n-1][0] -  a[n-1] << endl;

  return 0;
}


Measured memory_bytes: 70784
n = gets.chomp.to_i
s = gets.chomp.split("")
count = 0
s.each do |i|
    if i == "E"
        count += 1
    end
end
min = Float::INFINITY
migi = 0
tmp = count
s.each do |i|
    if i == "E"
        tmp -= 1
    end
    min = [min,tmp].min
    if i == "W"
        tmp += 1
    end        
end
puts min

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  string s; std::cin >> s;
  s = ' ' + s;
  int n = s.size();
  vector<ll> vec(n, -1);
  srep(i, 1, n) {
    int ni = i;
    while (ni+1 < n && s[i] == s[ni+1]) ni++;
    ll l = i-1, r = ni, cur = 0;
    if (s[i] == '<') {
      srep(j, l, r+1) {
        chmax(vec[j], cur++);
      }
    } else {
      cur = ni - i + 1;
      srep(j, l, r+1) {
        chmax(vec[j], cur--);
      }
    }
    i = ni;
  }
  std::cout << accumulate(rng(vec), 0ll) << "\n";
}


Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,i,sum=0,k;
	cin>>a>>b>>c>>k;
	if(a<k)
	{
		k=k-a;
		sum+=a;
	}
	else
	{
		cout<<k<<endl;
		return 0;
	}
	if(b<k) 
		k=k-b;
	else
	{
	cout<<sum<<endl; 
	return 0;
}
    sum=sum-k;
    cout<<sum<<endl;
    return 0;
	 
}


Measured memory_bytes: 3580
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define MAX 2010
#define MOD 1000000007
void add(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,k,mx,f[MAX][MAX];
int jc[MAX*MAX],jv[MAX*MAX],inv[MAX*MAX];
int C(int n,int m){return 1ll*jc[n]*jv[m]%MOD*jv[n-m]%MOD;}
int main()
{
	n=read();k=read();mx=n*k;
	if(k==1){puts("1");return 0;}
	jc[0]=jv[0]=inv[0]=inv[1]=1;
	for(int i=1;i<=mx;++i)jc[i]=1ll*jc[i-1]*i%MOD;
	for(int i=2;i<=mx;++i)inv[i]=1ll*inv[MOD%i]*(MOD-MOD/i)%MOD;
	for(int i=1;i<=mx;++i)jv[i]=1ll*jv[i-1]*inv[i]%MOD;
	f[0][0]=1;
	for(int i=1;i<=n;++i)
		for(int j=0;j<=i;++j)
		{
			add(f[i][j],f[i-1][j]);
			if(j)add(f[i][j],1ll*f[i][j-1]*(n-j+1)%MOD*C((n-i)+(n-j+1)*(k-1)-1,k-2)%MOD);
		}
	printf("%d\n",f[n][n]);
	return 0;
}

Measured memory_bytes: 63360
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main() {
  int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;
  int s = h1 * 60 + m1;
  int e = h2 * 60 + m2;
  cout << max(e - s - k, 0) << endl;

  return 0;
}

// EOF

Measured memory_bytes: 3636
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//V,P(大文字)使用不可
//乗算の際にオーバーフローに注意せよ！！（適切にmodをとれ）
//制約をよく読め！

const ll INF=1e18;
set<string> que;
int n;
void f(string s,int k){
    if(k==n){
        que.insert(s);
        return;
    }
    set<char> st;
    rep(i,k) st.insert(s[i]);
    int c=*rbegin(st)-'a';
    rep(i,26){
        if(i<=c+1){
            string u=s;
            u+=i+'a';
            f(u,k+1);
        }
    }
}

void solve(){
    
    string s="a";
    
    f(s,1);
}

signed main(){
    cin>>n;
    
    // que.push(s);
    // rep(i,n-1){
    //     string t;
    //     rep(j,i) t+='a';
    //     rep(j,n-i) t+='b';
    //     que.push(t);
    // }
    
    solve();
    while(!que.empty()){
        string t=*begin(que);
        cout<<t<<endl;
        que.erase(t);
    }
}

Measured memory_bytes: 14208
#include <stdio.h>
int main()
{
  int i,w;
  long long debt=100000;
  scanf("%d",&w);
  for(i=0;i<w;i++){
    debt*=1.05;
    if(debt%1000!=0)debt=debt+1000-debt%1000;
  }
  printf("%lld\n",debt);
  return 0;
}

Measured memory_bytes: 1020
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int k;
    string s;
    cin >> k >> s;
    if (s.length() > k){
        s = s.substr(0, k) + "...";
    }
    cout << s << endl;
    return 0;
}


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

int main() {
	int N;
	char c;
	bool t;

	t = false;
	cin >> N;
	for (int i = 0; i < N; i++)
	{	
		cin >> c;
		if(c == 'Y') t = true;
	}
	if(t) cout << "Four" << endl;
	else cout << "Three" << endl;

}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int x1 = line[0], y1 = line[1], x2 = line[2], y2 = line[3];
            int x3 = 0, y3 = 0, x4 = 0, y4 = 0;

            var demX = Math.Abs(x2 - x1);
            var demY = Math.Abs(y2 - y1);

            if (x1 <= x2 && y1 >= y2)
            {
                x3 = x2 + demY;
                y3 = y2 + demX;
                x4 = x1 + demY;
                y4 = y1 + demX;
            }
            else if (x1 <= x2 && y1 <= y2)
            {
                x3 = x2 - demY;
                y3 = y2 + demX;
                x4 = x1 - demY;
                y4 = y1 + demX;
            }
            else if (x1 >= x2 && y1 >= y2)
            {
                x3 = x2 + demY;
                y3 = y2 - demX;
                x4 = x1 + demY;
                y4 = y1 - demX;
            }
            else if (x1 >= x2 && y1 <= y2)
            {
                x3 = x2 - demY;
                y3 = y2 - demX;
                x4 = x1 - demY;
                y4 = y1 - demX;
            }

            Console.WriteLine($"{x3} {y3} {x4} {y4}");
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n;
  cin >> n;
  
  cout << n * (n + 1) / 2 << endl;


  
  return 0;
}

Measured memory_bytes: 256
number,type = gets.chomp!.split(" ").map(&:to_i)
array = []
roop =  type*2
roop.times do |i|
  if i%2 == 0
    num = gets
  end

  if i%2 == 1
    array << gets.chomp!.split(" ").map(&:to_i)
  end
end
p number - array.flatten.uniq.length

Measured memory_bytes: 14484
#include <stdio.h>

int main() {
	int Snuck, RstA, RstB, JrkA, JrkB;
	scanf("%d %d %d", &Snuck, &RstA, &RstB);
	
	JrkA = RstA - Snuck;
	JrkB = RstB - Snuck;
	if (JrkA < 0) {
		JrkA *= -1;
	}if (JrkB < 0) {
		JrkB *= -1;
	}
	if (JrkA < JrkB) {
		printf("A\n");
	} else {
		printf("B\n");
	}
	
	
	return 0;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;
long double A, B, H, M;

int main(){
  cin >> A >> B >> H >> M;
  double pi = acos(-1);
  double Mtheta = (2*pi/60)*M;
  double Htheta = ((double)(2*pi/12)/(double)60)*(H*60+M);
  double Hx = A*cos(Htheta), Hy = A*sin(Htheta), Mx = B*cos(Mtheta), My=B*sin(Mtheta);
  double ans = (Hx-Mx)*(Hx-Mx)+(Hy-My)*(Hy-My);
  printf("%.10Lf\n", sqrtl(ans));
  return 0;
}


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

int main() {
  string S;
  cin >> S;

  S = S.substr(0, S.size() - 8);
  cout << S << endl;
  return 0;
}

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

int f(int n){
  int div = 1;
  for(int i=1;i<n/2+1;++i){
    if(n%i == 0)div += 1;
  }
  return div;
}

int main(){
  int n;cin >> n;
  int ans = 0;
  for(int i = 11;i <= n;i += 2){
    if(f(i) == 8){
      ans += 1;
    }
  }
  cout << ans << endl;
}

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

int main(){
    int q; cin >> q;
    while(q--){
        ll a, b; cin >> a >> b; if(a < b) swap(a,b); // a >= b
        if(a-b == 0) cout << 2*(b-1) << endl;
        else if(a-b == 1) cout << 2*(b-1) << endl;
        else{
            ll k = (ll)sqrt(a*b);
            if(k*k == a*b) cout << 2*k-3 << endl;
            else if(k*(k+1) < a*b) cout << 2*k-1 << endl;
            else cout << 2*k-2 << endl;
        }
    }
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

int gettop(int a)
{
    while( a >= 10 ) a /= 10;
    return a;
}

int main()
{
    int n;
    cin >> n;
    int c[10][10];
    rep(k, 10)
        rep(l, 10) c[k][l] = 0;
        
    for(int i = 1; i <= n; i++)
    {
        c[gettop(i)][i % 10]++;
    }
    _LL ans = 0;
    rep(k, 10)
        rep(l, 10) 
        {
            ans += c[k][l] * c[l][k];
        }

    cout << ans;
    return 0;    
}


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

using namespace std;

#define pb push_back

typedef long long ll;

const int N = 1066;
const ll inf = 1e18;
#define fo(i, n) for(int i = 1; i <= n;++i)

char s[N][N];
int n;
int dp[N][N];

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

    cin >> n;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            cin >> s[i][j];
    for(int i = 0; i < n; ++i)
        for(int j =0 ; j < n; ++j)
            s[i+n][j] = s[i+n][j+n] = s[i][j+n] = s[i][j];
    int ans = 0;
    for(int X = 0; X < n + n; ++X) {
        int x = X;
        int y = 0;
        for(int i = 0; i < n + n; ++i)
            for(int j = 0; j < n + n; ++j)
                dp[i][j] = 0;
        for(; x < n + n && y < n + n; x++, y++) {
            int cy = y;
            int cx = x;
            for(; cx < n + n && cy < n + n; ++cx, ++cy) {
                if(s[x][cy] == s[cx][y])
                    dp[x][cy] = dp[cx][y] = 1;
            }
        }
        for(int i = 0; i < n + n; ++i)
            for(int j = 0; j < n + n; ++j) {
                if(i) dp[i][j] += dp[i-1][j];
                if(j) dp[i][j] += dp[i][j-1];
                if(i && j) dp[i][j] -= dp[i-1][j-1];
            }
        x = X;
        y = 0;
        for(; x + 1 < n + n && y + 1 < n + n; ++y, ++x) {
            int i = x, j = y;
            int cur = dp[i][j];
            if (i >= n) cur -= dp[i - n][j];
            if (j >= n) cur -= dp[i][j - n];
            if (i >= n && j >= n) cur += dp[i - n][j - n];
            if (cur == n * n) ++ans;
        }
    }
    for(int Y = 1; Y < n + n; ++Y) {
        int x = 0;
        int y = Y;
        for(int i = 0; i < n + n; ++i)
            for(int j = 0; j < n + n; ++j)
                dp[i][j] = 0;
        for(; x < n + n && y < n + n; x++, y++) {
            int cy = y;
            int cx = x;
            for(; cx < n + n && cy < n + n; ++cx, ++cy) {

                if(s[x][cy] == s[cx][y])
                    dp[x][cy] = dp[cx][y] = 1;
            }
        }
        for(int i = 0; i < n + n; ++i)
            for(int j = 0; j < n + n; ++j) {
                if(i) dp[i][j] += dp[i-1][j];
                if(j) dp[i][j] += dp[i][j-1];
                if(i && j) dp[i][j] -= dp[i-1][j-1];
            }
        x = 0;
        y = Y;
        for(; x + 1 < n + n && y + 1 < n + n; ++y, ++x) {
            int i = x, j = y;
            int cur = dp[i][j];
            if (i >= n) cur -= dp[i - n][j];
            if (j >= n) cur -= dp[i][j - n];
            if (i >= n && j >= n) cur += dp[i - n][j - n];
            if (cur == n * n) ++ans;
        }
    }

    cout << ans;
    return 0;
}













Measured memory_bytes: 4992
#include <cstdio>
int max(int a,int b){
	return a>b?a:b;
}
const int Maxn=200000;
int fa[Maxn+5];
int find(int x){
	if(fa[x]==x){
		return x;
	}
	return fa[x]=find(fa[x]);
}
void merge(int x,int y){
	int fa_x=find(x),fa_y=find(y);
	if(fa_x==fa_y){
		return;
	}
	fa[fa_y]=fa_x;
}
int sz[Maxn+5];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		fa[i]=i;
	}
	for(int i=1;i<=m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		merge(a,b);
	}
	for(int i=1;i<=n;i++){
		sz[find(i)]++;
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ans=max(ans,sz[i]);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 4808
function main(input) {
  const N = parseInt(input.split(" ")[0] , 10);
  const M = parseInt(input.split(" ")[1] , 10);
  var arr=[];
  //1からMまでの配列作る
  for(var i=0; i<M; i++){
    arr.push(i+1)
  }

  var ans=0;
  //1からMの数字それぞれについて、全ての配列にそれが存在してたらansに1を足す
  for(var i=0; i<M; i++){
    var temp=0;
    for(var j=0; j<N; j++){
      var tempArr=input.split('\n')[j+1].split(' ').map((n) => parseInt(n, 10));
      tempArr.shift()
      if(tempArr.indexOf(i+1)>=0){
        temp++
      }
    }
    if(temp==N){
      //console.log("すべての配列に"+(i+1)+"は存在");
      ans++
    }
  }
  console.log(ans);

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 9348
N=int(input())
X=input()

data=[0]*N
for i in range(1,N):
    temp=0
    for j in range(20):
        temp+=(i>>j &1)
    next=i%temp
    data[i]=data[next]+1

base=sum(int(X[i]) for i in range(N))

if base==0:
    baseup=0
    for i in range(N):
        baseup=(baseup*2)%(base+1)
        baseup=(baseup+int(X[i]))%(base+1)

    for i in range(N):
        if X[i]=="1":
            temp=(basedown-pow(2,N-1-i,base-1))%(base-1)
            print(1+data[temp])
        else:
            temp=(baseup+pow(2,N-1-i,base+1))%(base+1)
            print(1+data[temp])
elif base==1:
    baseup=0
    for i in range(N):
        baseup=(baseup*2)%(base+1)
        baseup=(baseup+int(X[i]))%(base+1)

    for i in range(N):
        if X[i]=="1":
            print(0)
        else:
            temp=(baseup+pow(2,N-1-i,base+1))%(base+1)
            print(1+data[temp])
else:
    basedown=0
    baseup=0
    for i in range(N):
        basedown=(basedown*2)%(base-1)
        baseup=(baseup*2)%(base+1)
        basedown=(basedown+int(X[i]))%(base-1)
        baseup=(baseup+int(X[i]))%(base+1)

    for i in range(N):
        if X[i]=="1":
            temp=(basedown-pow(2,N-1-i,base-1))%(base-1)
            print(1+data[temp])
        else:
            temp=(baseup+pow(2,N-1-i,base+1))%(base+1)
            print(1+data[temp])


Measured memory_bytes: 75808
a=input()
b=input()

if len(a)>len(b):
    print('GREATER')
elif len(a)<len(b):
    print('LESS')
else:
    for i in range(len(a)):
        if a[i]>b[i]:
            print('GREATER')
            exit()
        elif a[i]<b[i]:
            print('LESS')
            exit()
    print('EQUAL')

Measured memory_bytes: 3064
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>

using namespace std;

unsigned long long mod = 1000000007;

unsigned long long kai(int q) {
	long long res = 1;
	for (int i = 1; i <= q; i++) {
		res = (res*i)%mod;
	}
	return res;
}

int main() {
	int n, m;
	
	cin >> n >> m;
	if (abs(n - m) > 1) {
		cout << 0 << endl;
		return 0;
	}
	else if (abs(n - m) == 1) {
		int l = max(n, m), f = min(n, m);
		cout << (kai(l)*kai(f)) % mod << endl;
	}
	else {
		cout << (kai(n) * kai(n) * 2)%mod << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	static int N;
	static int bfs(int sum,int n){
		if(n==4&&sum==N)return 1;
		else if(n==4&&sum!=N)return 0;
		int cnt = 0;
		for(int i=0;i<=9;i++)if(sum+i<=N)cnt+=bfs(sum+i,n+1);
		return cnt;
	}
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(in.hasNext()){
			N = in.nextInt();
			System.out.println(bfs(0,0));
		}
	}
}

Measured memory_bytes: 18840
import java.util.*

fun main(args: Array<String>) {
    readLine()!!.toInt()
    val A = readLine()!!.split(" ").map(String::toInt)
    val lcm = Sieve.lcm(A)
    val ans = A.map { i -> lcm / MInt(i) }.reduce { acc, i -> acc + i }
    println(ans)
}

object Sieve {
    private val N = Math.sqrt(1000000.0).toInt()
    private val primes: Array<Int>

    init {
        val que = ArrayDeque<Int>()
        val sieve = BooleanArray(N+1) { true }
        sieve[0] = false
        sieve[1] = false
        for (i in 2..N) {
            if (!sieve[i]) continue
            que.push(i)
            for (j in (i*2)..N step i) {
                sieve[j] = false
            }
        }
        primes = que.toTypedArray()
    }

    fun lcm(array: List<Int>): MInt {
        val map = HashMap<Int, Int>()
        for (n in array) {
            fact(n).forEach { e ->
                val ex = map[e.key] ?: 0
                map[e.key] = Math.max(ex, e.value)
            }
        }
        var mint = MInt(1)
        map.forEach { e ->
            mint = mint * MInt(e.key).pow(e.value)
        }
        return mint
    }

    fun fact(n: Int): HashMap<Int, Int> {
        val map = HashMap<Int, Int>()
        var tmp = n
        for (prime in primes) {
            if (tmp % prime == 0) {
                var cnt = 0
                while (tmp % prime == 0) {
                    tmp /= prime
                    cnt++
                }
                map[prime] = cnt
            }
        }
        if (tmp != 1) {
            map[tmp] = 1
        }
        return map
    }
}

class MInt {
    private val MOD = 1000000007L
    var v: Long

    constructor(v: Long) {
        this.v = v % MOD
    }

    constructor(v: Int) {
        this.v = v.toLong() % MOD
    }

    operator fun plus(b: MInt): MInt {
        val a = MInt(v)
        a += b
        return a
    }

    operator fun minus(b: MInt): MInt {
        val a = MInt(v)
        a -= b
        return a
    }

    operator fun times(b: MInt): MInt {
        val a = MInt(v)
        a *= b
        return a
    }

    operator fun div(b: MInt): MInt {
        val a = MInt(v)
        a /= b
        return a
    }

    operator fun plusAssign(b: MInt) {
        v += b.v
        if (v >= MOD) v -= MOD
    }

    operator fun minusAssign(b: MInt) {
        v -= b.v
        if (v < 0) v += MOD
    }

    operator fun timesAssign(b: MInt) {
        v *= b.v
        v %= MOD
    }

    operator fun divAssign(b: MInt) {
        this *= b.inv()
    }

    fun inv(): MInt {
        var a = v
        var b = MOD
        var u = 1L
        var w = 0L
        while (b != 0L) {
            val t = a / b
            a -= t * b
            u -= t * w
            var tmp = a
            a = b
            b = tmp
            tmp = u
            u = w
            w = tmp
        }
        u %= MOD
        if (u < 0) u += MOD
        return MInt(u)
    }

    fun pow(n: Int): MInt {
        var a = MInt(1)
        for (i in 1..n) a = a * this
        return a
    }

    override fun toString(): String {
        return v.toString()
    }
}

Measured memory_bytes: 41524
#include<stdio.h>
int main()
{
int m,n,r;
while(1){

scanf("%d",&m);scanf("%d",&n);scanf("%d",&r);
if(m==-1&&n==-1&&r==-1)break;
if(m==-1||n==-1)printf("F\n");
else if(m+n>=80)printf("A\n");
else if(m+n>=65)printf("B\n"); 
else if(m+n>=50)printf("C\n");
else if(m+n>=30){if(r>=50)printf("C\n");else if(r<50)printf("D\n");}
else if(m+n<30)printf("F\n");
}
return 0;
}

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

using i64 = int64_t;

int main(){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a > k)cout << ":(";
    else cout << "Yay!";
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/abc143/tasks/abc143_d
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    ll N; cin>>N;
    vector<ll> ln(N);
    for(auto&& l:ln){
        cin>>l;
    }
    sort(ln.begin(),ln.end());
    ll ans=0;
    REP(i,N){
        ll a=ln.at(i);
        FOR(j,i+1,N){
            ll b=ln.at(j);
            FOR(k,j+1,N){
                ll c=ln.at(k);
                if(a+b>c){
                    ++ans;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    int x;
    cin >> x;
    int ans = 1;
    for(int i = 2; i*i <= x; i++){
        int tmp = i*i;
        while(tmp <= x){
            ans = max(ans, tmp);
            tmp *= i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>

int main () {
    int n;
    std::cin >> n;

    int ans = 1;
    int num;
    while (ans <= n)
    {
        num = ans;
        ans *= 2;
    }


    std::cout << num << "\n";
}

Measured memory_bytes: 3616
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  cout << a[2]-a[0] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 21;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<double> x(n),y(n);
    double sum = 0;
    rep(i,n){
        cin >> x[i] >> y[i];
    }
    rep(i,n-1){
        rep(j,i+1,n){
            sum += sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
        }
    }
    printf("%0.10f\n",2*sum/(double)n);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<cmath>
#include<cstdio>

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

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

int N;
int N_array[10001];

int main(int argc, const char * argv[]) {
    
    
    cin >> N;
    
    for(int x=1; x*x<=N; x++){
        for(int y=1; x*x+y*y+x*y<=N; y++){
            for(int z=1; z<=N; z++){
                ll ans = x*x + y*y + z*z + x*y + y*z + z*x;
                if(ans <= N){
                    N_array[ans]++;
                }
            }
        }
    }
    
    for(int i=1; i<=N; i++){
        cout << N_array[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3656
import collections

x,y = map(int, input().split())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
    
print(len(list(set(prime_factorize(x)) & set(prime_factorize(y)))) + 1)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll h, w; cin >> h >> w;
    vector<string> s(h);
    for(long long i=0; i<h; i++) cin >> s[i];
    // w->bに移動する際にコスト1かかるものとしてdp
    vvi dp(h, vi(w, 10001));
    dp[0][0] = (s[0][0] == '.' ? 0 : 1);
    for(long long i=0; i<h; i++){
        for(long long j=0; j<w; j++){
            // 現在見ているマスが黒の場合
            if(s[i][j] == '#'){
                // 一つ前が白か黒かで場合分け
                if(i > 0) chmin(dp[i][j], dp[i-1][j] + (s[i-1][j] == '.' ? 1 : 0));
                if(j > 0) chmin(dp[i][j], dp[i][j-1] + (s[i][j-1] == '.' ? 1 : 0));
            }
            else{
                if(i > 0) chmin(dp[i][j], dp[i-1][j]);
                if(j > 0) chmin(dp[i][j], dp[i][j-1]);
            }
        }
    }
    cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 3756
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k,s;
	cin>>k>>s;
	int ans=0;
	for(int i=0;i<=k;i++){
		for(int j=0;j<=k;j++){
			int z=s-i-j;
			if(0<=z and z<=k){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			while (true)
			{
				int[] hms = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
				int h = hms[0];
				int m = hms[1];
				int s = hms[2];
				if (h == -1 && m == -1 && s == -1) break;

				TimeSpan vt = new TimeSpan(2, 0, 0);
				TimeSpan nt = new TimeSpan(h, m, s);
				TimeSpan r1 = vt - nt;
				TimeSpan r2 = new TimeSpan(0, 0, (int)r1.TotalSeconds * 3);
				Console.WriteLine(r1.ToString());
				Console.WriteLine(r2.ToString());
			}
		}
	}
}

Measured memory_bytes: 5964
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<stack>
using namespace std;
#define ll long long
#define ull unsigned long long
#define up(i,a,b) for(register int i=(a);i<=(b);i++)
#define down(i,a,b) for(register int i=(a);i>=(b);i--)
#define mem(x,y) memset(x,(y),sizeof x)
#define ff first
#define ss second
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define sc(a) scanf("%d",&a)
#define scl(a) scanf("%lld",&a)
#define scs(a) scanf("%s",a)
#define pr(a,b) printf("%d%c",a,b)
#define prl(a,b) printf("%lld%c",a,b)
#define PQ priority_queue
#define ld long double
#define all(v) v.begin(),v.end()
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

typedef pair<ll,ll> pii;
typedef map<int,int> mii;
typedef vector<int> V;

template<typename T>
T gcd(T a,T b) {
	return !b?a:gcd(b,a%b);
}

inline int read() {
	int input=0,v=1;
	char c=getchar();
	while((c<'0'||c>'9')&&c!='-')c=getchar();
	if(c=='-')v=-1,c=getchar();
	while(c>='0'&&c<='9')input=input*10+c-'0',c=getchar();
	return v*input;
}

int ans=1e9;
int vis[10],val[10];
void dfs(int x,int a){
	if(x==6){
		ans=min(ans,a);return;
	}
	up(i,1,5)
	if(!vis[i]){
		vis[i]++;
		if(a%10)a=(a/10+1)*10;
		a+=val[i];
		
		dfs(x+1,a);
		
		a-=val[i];
		vis[i]--;
	}
}

int main() {
	up(i,1,5)sc(val[i]);
	dfs(1,0);
	pr(ans,'\n');
}

Measured memory_bytes: 384
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,C;
LL D[31][31];
LL c[501][501];
 
LL ans = INF;

void solve(){
	//(x+y)%3 = i%3が0,1,2の各場合について
	//j色(1<=j<=C)で塗られている数を
	//color[i%3][j]とする
	vector<vector<LL>> color(3,vector<LL>(C+1,0));
	for(int y=1;y<=N;y++){
		for(int x=1;x<=N;x++){
			color[(y+x)%3][c[y][x]]++;
		}
	}
	//余りが0,1,2それぞれのマスについてそれぞれ
	//色i,j,kを割り当てる場合を考える
	for(int i=1;i<=C;i++){
		for(int j=1;j<=C;j++){
			for(int k=1;k<=C;k++){
				//3つ選定する色はそれぞれ異なっている必要がある
				if(i==k || j==k || i==j) continue;
				LL sum = 0;
				//余りが0,1,2それぞれのマスの、色cであるものを色iに塗り替えるコスト
				for(int c=1;c<=C;c++) sum += (D[c][i])*color[0][c];
				for(int c=1;c<=C;c++) sum += (D[c][j])*color[1][c];
				for(int c=1;c<=C;c++) sum += (D[c][k])*color[2][c];
				ans = min(ans,sum);
			}
		}
	}
}

int main(){
    cin >> N >> C;
    for(int i=1;i<=C;i++){
		for(int j=1;j<=C;j++) cin >> D[i][j];
	}
	for(int y=1;y<=N;y++){
		for(int x=1;x<=N;x++) cin >> c[y][x];
	}
 
    solve();
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2176
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc089.contest.atcoder.jp/tasks/arc089_a>
問題文============================================================
 シカのAtCoDeerくんは二次元平面上で旅行をしようとしています。
 AtCoDeerくんの旅行プランでは、時刻 0 に 点 (0,0) を出発し、
 1 以上 N 以下の各 i に対し、時刻 ti に 点 (xi,yi) を訪れる予定です。
 
 AtCoDeerくんが時刻 t に 点 (x,y) にいる時、
 時刻 t+1 には 点 (x+1,y), (x−1,y), (x,y+1), (x,y−1) のうちいずれかに存在することができます。
 その場にとどまることは出来ないことに注意してください。
 AtCoDeerくんの旅行プランが実行可能かどうか判定してください。

=================================================================

解説=============================================================

 次地点に時間が間に合わない時はいうまでもなく no
 時間が間に合う時、
     シカは同一地点に留まることができないので、
     次地点に到達した時の残り時間が偶数のとき、時間ぴったしに到達できる
 
================================================================
*/
struct plan{
    int t,x,y;
    plan():t(0),x(0),y(0){}
};
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<plan> P(N+1);
    for(int i = 1; i <= N;i++) cin >> P[i].t >> P[i].x >> P[i].y;
    for(int i = 1; i <= N;i++){
        int diff = abs(P[i].x - P[i-1].x) + abs(P[i].y - P[i-1].y);
        if(diff > P[i].t - P[i-1].t){
            cout << "No" << endl;
            return 0;
        }else{
            if((P[i].t - P[i-1].t - diff )% 2 != 0){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    while(~scanf("%d",&n)){
        int ans=0;
        int a[100007];
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        for(int i=1;i<=n;i++){
            if(a[i]==i && a[i+1]==i+1){
                ans++;
                a[i+1]=-1;
            }
            else if(a[i]==i) ans++; 
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n, a, b, c, d, e;
	cin >> n >> a >> b >> c >> d >> e;

	ll x = min({a, b, c, d, e});
	cout << 5 + (n + x - 1) / x - 1 << endl;
}


Measured memory_bytes: 256
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }


int main() {
	
	vll a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(all(a));

	ll ans = 0;
	ans += (a[2] - a[0]) / 2;
	a[0] += ((a[2] - a[0]) / 2) * 2;
	ans += (a[2] - a[1]) / 2;
	a[1] += ((a[2] - a[1]) / 2) * 2;
	sort(all(a));
	if (a[0] == a[1] && a[1] == a[2] && a[2] == a[0]) cout << ans << endl;
	if (a[0] != a[1]) cout << ans + 2 << endl;
	if (a[1] != a[2]) cout << ans + 1 << endl;
}

Measured memory_bytes: 256
#coding: utf-8
N = int(input())
P = list(map(int, input().split()))
l = list(range(1, N+1))
ans = 0
for i in range(N-1):
    if P[i] == l[i]:
        ans += 1
        P[i], P[i+1] = P[i+1], P[i]
if P[-1] == l[-1]:
    ans += 1
print(ans)

Measured memory_bytes: 14008
#include<stdio.h>
int main()
{
	double a,b;
	while(scanf("%lf%lf",&a,&b)!=EOF){
		if(a<35.5&&b<71.0){
			printf("AAA\n");
		}else if(a<37.5&&b<77.0){
			printf("AA\n");
		}else if(a<40.0&&b<83.0){
			printf("A\n");
		}else if(a<43.0&&b<89.0){
			printf("B\n");
		}else if(a<50.0&&b<105.0){
			printf("C\n");
		}else if(a<55.0&&b<116.0){
			printf("D\n");
		}else if(a<70.0&&b<148.0){
			printf("E\n");
		}else{
			printf("NA\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2540
N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = float("inf")

dp = [INF] * N
dp[0] = 0
for i in range(1, N):
    for j in range(K):
        if i - j-1 < 0:
            break # スタート地点より手前になる場合は飛ばす
        dp[i] = min(dp[i], dp[i-j-1] + abs(h[i] - h[i-j-1]))

print(dp[-1])

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


int main(){
    long long n, m;
    cin >> n >> m;
   
   vector<vector<long long> > v(n+1);
    

    for(long long i = 0; i < m; i++){
        long long a, b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);

    }

    
    vector<long long> distance(n+1, -1);
    vector<long long> front(n+1);
    distance[1] = 0;

    queue<long long> q;
    long long top;
    q.push(1);

    while(!q.empty()){
        top = q.front();
        q.pop();
        
        for(long long i = 0; i < v[top].size(); i++){
            if(distance[v[top][i]] != -1){
                continue;
            }
            q.push(v[top][i]);
            distance[v[top][i]] = distance[top] + 1;
            front[v[top][i]] = top;
        }
    }

    printf("Yes\n");
    for(long long i = 2; i <= n; i++){
       printf("%lld\n", front[i]);
    }
    
    return 0;
}

Measured memory_bytes: 13672
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    N = next(it)
    A = [next(it) for i in range(N)]

    if N == 1:
        print(1)
        return

    ax = max(A)+1
    dp = [0]*ax
    for ai in A:
        da = dp[ai]
        if da > 1:
            continue
        dp[ai] += 1
        if da == 0:
            for aj in range(2*ai, ax, ai):
                dp[aj] = 2
        #print(dp)
    print(dp.count(1))


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 105292