akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <algorithm>

std::vector<int> edges[100005];

int vs[100005];
int ds[100005];
int cs[100005];

int vis[100005];
int color[100005];

void paint(int V,int D,int C){
  if(vis[V]>=D) return;
  vis[V]=D;
  if(!color[V]) color[V]=C;
  for(int W:edges[V]){
    paint(W,D-1,C);
  }
}

int main(){
  int N,M,Q;
  scanf("%d %d",&N,&M);
  for(int i=0;i<M;i++){
    int A,B;
    scanf("%d %d",&A,&B);
    A--,B--;
    edges[A].push_back(B);
    edges[B].push_back(A);
  }
  std::fill(vis,vis+N,-1);

  scanf("%d",&Q);
  for(int i=0;i<Q;i++){
    scanf("%d %d %d",&vs[i],&ds[i],&cs[i]);
    vs[i]--;
  }
  for(int i=Q-1;i>=0;i--){
    paint(vs[i],ds[i],cs[i]);
  }
  for(int i=0;i<N;i++){
    printf("%d\n",color[i]);
  }
  return 0;
}


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

int main() {
	int i, n, b, num = 0;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> b;
		while(true) {
			 if (b % 2 == 1) {
			 	break;
			 }
			 b = b / 2;
			 num++;
		}
	}
	cout << num << endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        h: usize,
        w: usize,
        m: usize,
        bombs: [(usize1, usize1); m],
    }
    let mut hs = vec![0; h];
    let mut ws = vec![0; w];

    for (h_, w_) in bombs.iter() {
        hs[*h_] += 1;
        ws[*w_] += 1;
    }

    let mut dh = 0;
    let mut dw = 0;
    let h_max = hs.iter().max().unwrap();
    let w_max = ws.iter().max().unwrap();

    let h_cnt = hs.iter().filter(|&x| x == h_max).count();
    let w_cnt = ws.iter().filter(|&x| x == w_max).count();

    let mut cnt = h_cnt * w_cnt;
    for (h_, w_) in bombs.iter() {
        if (&hs[*h_] == h_max) && (&ws[*w_] == w_max) {
            cnt -= 1;
        }
    }
    if cnt > 0 {
        println!("{}", h_max + w_max);
    } else {
        println!("{}", h_max + w_max - 1);
    }
}


Measured memory_bytes: 9092
#include <iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define LL long long
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define sz(v) ((int)sizeof(v))
#define N 200005
char str[N];

int main()
{
    int n;
    while(~scanf("%s",str)){
        n=strlen(str);
        rep(i,0,n){
            if(str[i]==','){
                cout<<' ';
            }
            else{
                cout<<str[i];
            }
        }
        cout<<'\n';
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, a, b, d) for (int i = a; i <= b; i += d)
#define brep(i, a, b, d) for (int i = a; i >= b; i -= d)
#define pb push_back
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define endl '\n'
const int MAX = 1e5 + 5;
const int MOD = 1e9 + 7;
////////////////////////////////

int dp[105][MAX];

int32_t main(){
    fastio
    int N, W; cin >> N >> W;
    int v[N+1], w[N+1];
    rep(i,1,N,1) cin >> w[i] >> v[i];
    rep(i,1,N,1){
        rep(j,0,W,1){
            if(w[i] <= j) dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
            else dp[i][j] = dp[i-1][j];
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}

Measured memory_bytes: 79360
import java.util.Scanner;

public class Main {

	static int[][][]dp;
	static int n,ans;
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		for(;;){
			n=cin.nextInt();
			if(n==0)break;
			dp=new int[26][25][24];
			ans=1<<30;
//			for(int i=0;i<n/100;i++)
			dp(0,0,0);
			System.out.println(ans);
		}
	}
	static int dp(int a,int b,int c){
//		System.out.println(n+" "+calcG(a,b,c));
		int g=calcG(a,b,c);
		if(g>n)return 0;
		if(g==n){
			ans=Math.min(ans,calcM(a,b,c));	
			return 0;
		}
		if(dp[a][b][c]!=0)return 0;
		dp[a][b][c]=1;
		dp(a+1,b,c);
		dp(a,b+1,c);
		dp(a,b,c+1);
		return dp[a][b][c];
	}
	static int calcG(int a,int b,int c){
		return 200*a + 300*b + 500*c;
	}
	static int calcM(int a,int b,int c){
		int re=0;
//		System.out.println(380*5*0.8);
//		System.out.println();
		re+=((380*5)*0.8)*(a/5);
		re+=380*(a%5);
		
		re+=((550*4)*0.85)*(b/4);
		re+=550*(b%4);
		
		re+=((850*3)*0.88)*(c/3);
		re+=850*(c%3);
		
		return re;
	}
}

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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr ll mod = static_cast<ll>(1e9 + 7);
template<long long Mod = mod>
constexpr long long MOD(long long in) {
    return in % Mod;
}

int n, a[200005];
int main()
{
    std::cin >> n;
    for (int i = 1; i <= n; ++i)
        std::cin >> a[i];

    std::vector<int> num;
    for (int i = n; i >= 1; --i) {
        int res = 0;
        for (int j = 2; i * j <= n; ++j)
            if (a[i * j] == 1)
                ++res;
        if (a[i] != res % 2) {
            a[i] = 1;
            num.push_back(i);
        }
        else
            a[i] = 0;
    }

    int m = (int)num.size();
    std::cout << m << std::endl;
    for (int i = 0; i < m; ++i)
        if (i != m - 1)
            std::cout << num[i] << " ";
        else
            std::cout << num[i] << std::endl;
    return 0;
}


Measured memory_bytes: 2424
const lines = [];
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

reader.on("line", function (line) {
  lines.push(line);
});
reader.on("close", function () {
  const input = lines[0] as string;
  const numbers = (lines[1] as string).split(" ");

  console.log(countDivide(numbers, Number(input[0]), 0));
});

function countDivide(numbers: string[], inputNum: number, count: number) {
  let nextNumbers: string[] = [];
  let nextFlag = true;

  numbers.forEach((number) => {
    if (Number(number) % 2 !== 0) {
      nextFlag = false;
    }

    let halfNumber = Number(number) / 2;
    nextNumbers.push(String(halfNumber));
  });

  if (nextFlag) {
    count++;
    return countDivide(nextNumbers, inputNum, count);
  } else {
    return count;
  }
}


Measured memory_bytes: 8140
//In the name of God
#include<bits/stdc++.h>

using namespace std;

int n , a[150] , res = 2e9 ;

int main(){
        cin >> n;
        for(int i=0 ; i < n ; i++)
                cin >> a[i];
        for(int x= -100 ; x < 101 ; x++){
                int now = 0;
                for(int i=0 ; i < n ; i++)
                        now += (x - a[i]) * (x - a[i]);
                res = min(res , now);
        }
        cout << res;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

int main()
{
  int a[3];
  for(int i = 0 ; i < 3 ; i++)
    cin >> a[i];
  sort(a, a + 3);
  cout << a[0] + a[1] << endl;
  return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
h = sorted([int(input()) for _ in range(n)])
cnt = [h[n-1] - h[0]]
for i in range(n-k+1):
  if cnt[0] > (h[i+k-1] - h[i]):
    cnt[0] = h[i+k-1] - h[i]
print(cnt[0])

Measured memory_bytes: 8280
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int k, x;
  cin >> k >> x;
  for (int i = x - k + 1; i <= x + k - 1; i++) {
    cout << i << ' ';
  }
  cout << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3612
import java.util.Scanner;
public class Main {
	private static Scanner sc;
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		int V = sc.nextInt();
		int E [][] = new int [V+1][V+1];
		for (int i=1; i<=V; i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			for (int k=0; k<b; k++){
				int c = sc.nextInt();
				E [a][c] = 1;
			}
		}
		for (int m=1; m<=V; m++){
			for (int n=1; n<=V; n++){
				if (n!=V)
				System.out.print(E[m][n]+" ");
				else System.out.println(E[m][n]);
			}
		}
	}
}

Measured memory_bytes: 32024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int GCD(int m,int n){
	int remain;
	if((remain = m % n) == 0)return n;
	else return GCD(n,remain);
}

int main(){
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	ll ans = b - a + 1;
	ans -= ((b / c) * c - (a / c) * c - c) / c + 1;
	if(a % c == 0) ans--;
	ans -= ((b / d) * d - (a / d) * d - d) / d + 1;
	if(a % d == 0) ans--;
	ll e = c * d / GCD(c,d);
	ans += ((b / e) * e - (a / e) * e - e) / e + 1;
	if(a % e == 0) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		System.out.println(solve());
	}

	public static String solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String s = sc.next();
		String t = sc.next();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < N; i++) {
			sb.append(s.charAt(i));
			sb.append(t.charAt(i));
		}
		return sb.toString();
	}
}


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

#define loop(n) for(int i = 0;i < (int)(n);++i)
#define rep(i,n) for(int i = 0;i < (int)(n);++i)
#define all(vec) (vec).begin(),(vec).end()
#define Sort(vec) sort(all(vec))
#define Rev(vec) reverse(all(vec))

using Graph = vector<vector<int>>;

namespace Input
{
                
    void input(){return;}
    template<typename First,typename... Rest> void input(First &first,Rest&... rest){
    std::cin >> first;
    input(rest...);
}
    
    void inputVec(){return;}
    template<typename First,typename... Rest> void inputVec(vector<First> &first,Rest&... rest){
        int N = first.size();
        for(int i = 0;i < N;i++){
            cin >> first[i];
        }
        inputVec(rest...);
    }
    
    template<typename First,typename Second> void inputTwoVec(vector<First> &first,vector<Second>& second){
        int N = first.size();
        for(int i = 0;i < N;i++){
            cin >> first[i] >> second[i];
        }
    }

    void inputGraph(Graph &g,int path_num,bool isdirected){
        for(int i = 0;i < path_num;i++){
            int a,b;
            cin >> a >> b;
            a--;b--;
            if(isdirected){
                g[a].push_back(b);
            }
            else{
                g[a].push_back(b);
                g[b].push_back(a);
            }
        }
    }
}

void calculate(){
    int N,K;
    Input::input(N,K);
    map<int,int> m;
    int tmp;
    int kind = 0;
    rep(i,N){
        cin >> tmp;
        if(m.count(tmp) == 0){
            m.insert(make_pair(tmp,1));
            kind++;
        }
        else{
            m[tmp]++;
        }
    }
    if(kind <= K){
        cout << 0 << '\n';
        return;
    }
    vector<int> l;
    for(auto i : m){
        l.push_back(i.second);
    }
    Sort(l);
    int res = 0;
    rep(i,N){
        if(kind == K){
            cout << res << '\n';
            return;
        }
        else{
            res += l[i];
            kind--;
        }
    }
    cout << res << '\n';
}

int main(int,char**){
    calculate();    
}




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

#define REP(i,n) for(int i=0,_n=(int)(n); i < _n; i++)
typedef long long ll;

const ll MOD = 1e9+7;

int A[100000];
int B[100000];

void main2() {
  int N; cin >> N;
  REP(i, N) cin >> A[i];
  REP(i, N) B[A[i]]++;
  ll ans = 1;
  if (N % 2 == 0) {
    for (int i = 1; i < N; i += 2) {
      if (B[i] != 2) {
        cout << 0 << endl;
        return;
      }
      ans = (ans * 2) % MOD;
    }
    cout << ans << endl;
  }
  else
  {
    if (B[0] != 1) { cout << 0 << endl; return; }
    for (int i = 2; i < N; i += 2) {
      if (B[i] != 2) {
        cout << 0 << endl;
        return;
      }
      ans = (ans * 2) % MOD;
    }
    cout << ans << endl;
  }
  return;
}


int main() {
  while (!cin.eof()) {
    main2();
    cin >> ws;
  }
  return 0;
}




Measured memory_bytes: 1024
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7; 
long long a, dp[N][3];
int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < 3; j++){
            cin >> a;
            for(int k = 0; k < 3; k++){
                if(j != k){
                    dp[i][j] = max(dp[i][j], dp[i - 1][k] + a);
                }
            }
        }
    }
    cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
}  

Measured memory_bytes: 4352
import sys
def main():
    N = int(input())
    A_list = [int(_) for _ in input().split()]
    ans = 1
    
    if 0 in A_list:
        out = 0
        print(out)
        sys.exit()
    
    for i in range(N):
        ans = ans * A_list[i]
        
        if ans>1000000000000000000:
            ans = -1
            break
    out = ans
    print(out)

main()

Measured memory_bytes: 21648
while(1):
	H, W = map(int, input().split())
	if H == 0 and W == 0:
		break
	for i in range(H):
		for j in range(W):
			if i == 0 or i == H-1:
				print("#", end='')
			else:
				if j == 0 or j == W-1: 
					print("#", end='')
				else:
					print(".", end='')
		print("\n", end='')
	print("\n", end='')

Measured memory_bytes: 9028
#include<bits/stdc++.h>
#include<queue>
using namespace std;
int W,H;
char c[101][101];
bool visited [100][100];

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

void compute(){
  memset(visited,false,sizeof visited);


  queue<int> que;
int i,j;
 for(i=0;i<H;++i){
   for(j=0;j<W;++j){
     if(c[i][j]=='@'){
       que.push(j+i*W);
       visited[i][j]=true;
       break;}
       
	 }


   }
 int answer=1;
 
 while(!que.empty()){
   int cur = que.front();
   que.pop();
   int x = cur % W,y=cur/W;

   for(i=0;i<4;i++)
     {int nx = x + dx[i],ny= y+dy[i];
       if(!(0<=nx && nx< W && 0<=ny && ny < H))continue;
       if(c[ny][nx]=='#'||visited[ny][nx])continue;
       
       que.push(nx+ny*W);
       visited[ny][nx]=true;
       ++answer;
       
     }
 }
 cout<<answer<<endl;
 
}





int main(){
  while(cin>>W>>H,W|H) {
    for(int i=0;i<H;++i) {
      cin>>c[i];	    
    }
    compute();
  }
  return 0;
}

Measured memory_bytes: 1228
import operator as op
from itertools import groupby
from functools import reduce

NN = 10 ** 9 + 7


def prime_factors(n):
    i = 2
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            yield i
    if n > 1:
        yield n


def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom


N, M = map(int, input().split())
result = 1

for k, g in groupby(prime_factors(M)):
    result = result * ncr(len(list(g)) + N - 1, N - 1)
    if result > NN:
        result = result % NN

print(result)


Measured memory_bytes: 3568
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

dp = [[100100] * (1 << N) for _ in range(N)]
for i in range(N):
    dp[i][1 << i] = 0
for mask in range(1, 1 << N):
    mask_pop = format(mask, 'b').count('1')
    for j in range(N):
        if (1 << j) & mask:
            if (j - mask_pop) % 2 == 1:
                cur_elem = A[j]
            else: 
                cur_elem = B[j]
            prev_mask = mask & ~(1 << j)
            cost_delta = format(prev_mask & (-1 << j), 'b').count('1')
            for t in range(N):
                if (1 << t) & prev_mask:
                    prev_elem = A[t] if (t - mask_pop - 1) % 2 == 1 else B[t]
                    if prev_elem <= cur_elem:
                        if dp[j][mask] > dp[t][prev_mask] + cost_delta:
                            dp[j][mask] = dp[t][prev_mask] + cost_delta
            
# print(*dp, sep = '\n')

ans = min((dp[i][-1] for i in range(N)))
if ans == 100100:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 111316
#include <string>
#include <vector>
#include <iostream>

using namespace std;

int main()
{
	int N, M;

	bool locked = true;

	cin >> N;

	vector<string> U(N);

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

	cin >> M;

	vector<string> T(M);

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

	for (int i = 0; i < M; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if (T[i] == U[j])
			{
				goto Exit1;
			}
		}

		cout << "Unknown " << T[i] << endl;

		goto Exit2;

	Exit1:;

		if (locked == true)
		{
			locked = false;

			cout << "Opened by " << T[i] << endl;
		}
		else
		{
			locked = true;

			cout << "Closed by " << T[i] << endl;
		}

	Exit2:;
	}

	return 0;
}

Measured memory_bytes: 1236
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    // char ;
    ll h,w,ans=INF;
    scanf("%lld%lld",&h,&w);
    if(h%3==0 || w%3==0){
        printf("0\n");
        return 0;
    }
    if(h%2){
        rep(i,max2(1,w/3-2), min2(w,w/3+3) ){
            ll s[3]={h*i,(h/2+1)*(w-i),h/2*(w-i)};
            sortup(s,3);
            if( ans < s[2]-s[0] ) break;
            ans= s[2]-s[0] ;
            // printf("%lld ",ans);
        }
    }else{
        rep(i,max2(1,w/3-2), min2(w,w/3+3) ){
            if( ans < ABS(h*i-h/2*(w-i)) ) break;
            ans= ABS(h*i-h/2*(w-i)) ;
        }
    }
    if(w%2){
        rep(i,max2(1,h/3-2), min2(h,h/3+3) ){
            ll s[3]={w*i,(w/2+1)*(h-i),w/2*(h-i)};
            sortup(s,3);
            ans= min2( ans , s[2]-s[0] );
            // printf("%lld ",ans);
        }
    }else{
        rep(i,max2(1,h/3-2), min2(h,h/3+3) ){
            ans= min2( ans , ABS(w*i-w/2*(h-i)) );
        }
    }
    ans = min2(ans,h);
    ans=min2(ans,w);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
# -*- coding:utf-8 -*-
N = int(input())
A = []
B = []
ans = 0
for tmp in range(N):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)
for tmp in reversed(range(N)):
    factor = (A[tmp]+ans)
    if factor%B[tmp] != 0:
        ans += ((factor//B[tmp])+1)*B[tmp]-factor
print(ans)

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

int main()
{
int m,n,a[110][110],b[110],i,j,out[100]={};

cin>>n>>m;

for(i=0;i<n;i++){
    for(j=0;j<m;j++){
    cin>>a[i][j];
    }

}

 for(j=0;j<m;j++){
    cin>>b[j];
    }


   for(i=0;i<n;i++){
    for(j=0;j<m;j++){
        out[i]=a[i][j]*b[j]+out[i];

    }

}
for(j=0;j<n;j++){
    cout<<out[j]<<endl;
    }

}








Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int M;
  ll K;
  cin >> M >> K;
  if(K == 0) {
    rep(i, 1<<M) cout << i << ' ' << i << ' ';
    cout << "\n";
  } else {
    ll xorall = 0;
    rep(i, 1<<M) xorall ^= i;
    rep(j, 1<<M) {
      if(K == j && K == (xorall^j)) {
        rep(i, 1<<M) if(i!=j) cout << i << ' ';
        cout << j << ' ';
        rrep(i, (1<<M)) if(i!=j) cout << i << ' ';
        cout << j << ' ';
        cout << "\n";
        return 0;
      }
    }
    cout << -1 << "\n";
  }
  return 0;
}


Measured memory_bytes: 3636
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// マラソン用時間計測
clock_t start_clock;
constexpr double time_limit = 1.919114514; // 実行時間[s]より0.1ms程度余裕をあける
constexpr double CLOCKS_PER_SEC_INV = 1.0 / CLOCKS_PER_SEC;
inline double nowtime() { return CLOCKS_PER_SEC_INV * (clock() - start_clock); }
inline bool intime() { return nowtime() < time_limit; }

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (int i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (int i=(is), i##_end=(ie); i<=i##_end; i++)
#define FOREACH(i, arr) for (auto &i : arr)
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
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 (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using ll = long long;
using namespace std;

// 汎用クラス
struct union_find {
    vector<int> par;
    vector<int> num;
    union_find(int n) : par(n, 0), num(n, 1) { iota(ALL_OF(par), 0); }
    int root(int i) { return par[i] == i ? i : (par[i] = root(par[i])); }
    bool same(int i, int j) { return root(i) == root(j); }
    void unite(int i, int j) {
        int ri = root(i);
        int rj = root(j);
        if (ri != rj) {
            if (num[ri] > num[rj]) swap(ri, rj);
            par[ri] = rj;
            num[rj] += num[ri];
        }
    }
};

// main前実行のためのダミークラス
struct preexec_dummy {
    preexec_dummy() {
        start_clock = clock();
    }
} preexec_dummy_instance;

// Let's comp(u|e)te!
int main() {

    int n, m;
    cin >> n >> m;
    vector<int> a(m, 0), b(m, 0);
    union_find uf(n);
    REP(i, m) {
        cin >> a[i] >> b[i];
        // make them 0-indexed
        a[i]--;
        b[i]--;
    }

    vector<ll> ans(m, 0);
    ans[m-1] = (ll)n * ((ll)n - 1ll) / 2ll;
    for (int i = m-1; i--;) {

        if (!uf.same(a[i+1], b[i+1])) {
            int na = uf.num[uf.root(a[i+1])];
            int nb = uf.num[uf.root(b[i+1])];
            ans[i] = ans[i+1] - (ll)na * (ll)nb;
            uf.unite(a[i+1], b[i+1]);
        } else {
            ans[i] = ans[i+1];
        }

    }

    REP(i, m) cout << ans[i] << endl;
    
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define DEBUG2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << "\n"
#define DEBUG3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define ld long double
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vec<int> a(N);
  vec<int> b(N);
  REP(i, N) {
    cin >> a[i];
    a[i]--;
    b[a[i]] = i;
  }
  set<int> q0;
  set<int> q1;
  q0.insert(-1);
  q0.insert(N);
  q1.insert(1);
  q1.insert(-N);
  int ans = 0;
  REP(i, N) {
    int pos = b[i];
    int val0 = *q0.upper_bound(pos);
    int val1 = *q1.upper_bound(-pos);
    val1 = -val1;
    q0.insert(pos);
    q1.insert(-pos);
   // DEBUG3(val1, pos, val0);
    ans += (i + 1) * (val0 - pos) * (pos - val1);
  }
  print(ans);
}

Measured memory_bytes: 22144
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	fmt.Println(paintBall(n, k))
}

func paintBall(n, k int) int {
	pat := float64(k) * math.Pow(float64(k-1), float64(n-1))
	return int(pat)
}


Measured memory_bytes: 512
def main():
    n = int(input())
    h = list(map(int, input().split()))
    # dpテーブル作成,スタート地点のdpテーブルの値は0にする
    dp =[float("inf")] * n
    dp[0] = 0
    dp[1] = abs(h[0] - h[1])
    for i in range(2,n):
        dp[i] = min([dp[i], dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i])])
    print(dp[n-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 52296
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] box = sc.nextLine().split("");
        int ans=0;
        for(String num:box){
            if(Integer.parseInt(num)==1){
                ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
#define yn(f) cout<<(f?"yes":"no")<<endl
#define Yn(f) cout<<(f?"Yes":"No")<<endl
#define YN(f) cout<<(f?"YES":"NO")<<endl
#define COUT(x) cout<<(x)<<endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  string s1,s2,t1,t2; cin>>s1>>s2;
  t1=s1,t2=s2; reverse(all(s1)),reverse(all(s2));
  YN(s1==t2&&s2==t1);
}













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


using namespace std;


void atcoder_beginner_contest999()
{
  string n;
  cin >> n;

  for (int i = 0; i < n.size(); ++i)
  {
    if (n[i] == '1') n[i] = '9';
    else if (n[i] == '9') n[i] = '1';
  }
  cout << n << "\n";
}


void programming_education()
{
  int n;
  cin >> n;
  
  if (n == 1)
  {
    cout << "Hello World\n";
    return;
  }
  else
  {
    int a, b;
    cin >> a >> b;
    cout << a + b << "\n";
  }
}

void discount_fare()
{
  int x, y;
  cin >> x >> y;

  cout << x + y / 2 << "\n";
}


void A_114()
{
  int x;
  cin >> x;

  if (x == 3 || x == 5 || x == 7) cout << "YES\n";
  else cout << "NO\n";
}


void christmas_eve_eve_eve()
{
  int d;
  cin >> d;

  if (d == 25) cout << "Christmas\n";
  else if (d == 24) cout << "Christmas Eve\n";
  if (d == 23) cout << "Christmas Eve Eve\n";
  if (d == 22) cout << "Christmas Eve Eve Eve\n";
}


void right_triangle()
{
  int a, b, c;
  cin >> a >> b >> c;

  cout << a * b / 2 << "\n";
}


void entrance_examination()
{
  int t, x;
  cin >> t >> x;

  cout << (double)t / (double)x << "\n";
}


int main()
{
  //atcoder_beginner_contest999();
  //programming_education();
  //discount_fare();
  //A_114();
  //christmas_eve_eve_eve();
  //right_triangle();
  entrance_examination();
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println(String.format("%d %d", a * b, 2 * (a + b)));
        }
    }
}



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

using P = pair<int,int>;
using P3 = pair<P, int>;
using ll = long long int;
constexpr int INF = 1<<30;
constexpr ll MOD = (1e9)+7;

vector<ll> factrial, inverse;  //階乗と逆元を保持

ll mod_power(ll x, ll n) {  //繰り返し二乗法
    x %= MOD;
    ll res = 1;
    while (n > 0) {
        if (n & 1) {
            res = res * x % MOD;
        }
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

void init(ll n) {
    factrial.resize(n+1);
    inverse.resize(n+1);
    factrial[0] = 1;
    inverse[0] = 1;
    for (ll i = 1; i <= n; i++) {
        factrial[i] = (factrial[i - 1] * i) % MOD;
        inverse[i] = mod_power(factrial[i], MOD - 2);
    }
}

ll nCk(ll n, ll k) {
    if(n < 0 || k < 0 || n < k) return 0;
    return factrial[n] * inverse[k] % MOD * inverse[n - k] % MOD;
}

int main() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    init(n);
    vector<vector<ll> > dp(n+1, vector<ll>(b-a+2));
    dp[0][0] = 1;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=b-a;j++){
            dp[i][j+1] += dp[i][j];
            dp[i][j+1] %= MOD;
            int x = j+a;
            for(int k=c;k<=d;k++){
                if(i+x*k <= n){
                    dp[i+x*k][j+1] += dp[i][j]*nCk(n-i,x*k)%MOD*factrial[x*k]%MOD*inverse[k]%MOD*mod_power(inverse[x],k)%MOD;
                    dp[i+x*k][j+1] %= MOD;
                }
            }
        }
    }
    cout << dp[n][b-a+1] << endl;
    return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
 
int main() {
    fast();
    /*ll t;
    cin>>t;
    while(t--)
    {
       
    }*/
    ll n,k,q;
    cin>>n>>k>>q;
    ll a[q];
    ll cnt[n]={0};
    for(ll i=0;i<q;i++)
    {
        cin>>a[i];
        cnt[a[i]-1]++;
    }
    for(ll i=0;i<n;i++)
    {
        if((k-(q-cnt[i]))>0)
        cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl;
    }
}


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

bool IsPrime(long long int num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    int sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) return false;
    }
    return true;
}

std::vector<long long int> enum_div(long long int n) {
    std::vector<long long int> ret;
    for(long long int i=1 ; i*i<=n ; ++i) {
        if(n%i == 0) {
            ret.push_back(i);
            if(i!=1 && i*i!=n) {
                ret.push_back(n/i);
            }
        }
    }
    ret.push_back(n);
    return ret;
}

int main() {
    long long int a, b;
    int ans = 1;
    cin >> a >> b;
    vector<long long int> a_enum = enum_div(a);
    for(int i = 0; i < a_enum.size(); ++i) {
        if(IsPrime(a_enum[i]) && b%a_enum[i] == 0) ans++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main();
	}

	Main() {
		Scanner sc = new Scanner(System.in);
		int[] in = new int[10];
		for (int i = 0; i < 10; i++) {
			in[i] = sc.nextInt();
		}
		Arrays.sort(in);
		for (int i = 0; i < 3; i++)
			System.out.println(in[9-i]);
	}
}

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

int main(){
    string s;cin >> s;
    bool flag;
    if(s.length()%2==1) flag=false;
    else flag=true;
    bool hi=true;
    for(int i=0;i<s.length();i++){
        if(hi){
           if(s[i]!='h') flag=false;
        }else{
           if(s[i]!='i') flag=false;
        }
        hi=!hi;
    } 
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,X;
  int count = 0;
  cin >> A >> B >> C >> X;
  for (int i = 0; i <= A; ++i){
    for (int j = 0; j <= B; ++j){
      for (int k = 0; k <= C; ++k){
        if (X == 500 * i + 100 * j + 50 * k) count++;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
require 'set'

class Array
    def pop_q
        first = self[0]
        self.delete_at 0
        return first
    end
end

def main
    h = gets.to_i
    w = gets.to_i
    n = gets.to_i
    big = [h,w].max
    if n % big == 0
        puts n/big
    else
        puts n/big + 1
    end
end

main

## イディオムなど
# until s.empty? do
#
## 配列のインデックス
# s[0,6] # 0番目から6文字
# s[0..6] # 0番目から6番目まで
# s[5..-1] # 5番目から最後まで
#
## 全探索
# [0, 1].repeated_permutation(n) do |combination| # bit全探索
# array.combination(i) do |selected| # array から要素が i 個である部分列を全部抽出
#
## 無向グラフの幅優先探索(BFS)
# to = Array.new(n).map{Array.new()} # ある頂点と繋がる頂点のリスト
# m.times do
#     a,b = gets.chomp.split(" ").map(&:to_i)
#     to[a].push b
#     to[b].push a
# end
# q = Queue.new # BFS は queue
# ds = Array.new(n, -1)
# pre = Array.new(n, -1)
#
## その他
# a1 = Marshal.load(Marshal.dump(a2)) # 深いコピー
# matrix = Array.new(n).map{Array.new()} # 二次元配列の初期化
# 

Measured memory_bytes: 2300
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    string S; cin >> S;
    int len = S.length();
    int ans = 0;
    REP(i,len)
    {
        REP(j,len-i+1)
        {
            bool check = 1;
            string substr = S.substr(i,j);
            REP(k,substr.length())
            {
                if(substr[k] == 'A' || substr[k] == 'C' || substr[k] == 'G' || substr[k] == 'T') 
                {
                    ;
                }
                else
                {
                    check = 0;
                }
            }
            if(check) 
            {
                if(ans < substr.length()) ans = substr.length();
            }
        }
    }
    cout << ans << endl;


}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc133/tasks/abc133_b

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
using ll = long long;

bool is_square(ll x) {
    ll y = llround(sqrt((double)x));
    return y*y == x;
}
struct C {
    ll N_{};
    ll D_{};
    vector<vector<ll>> points_{};
    explicit C(vector<vector<ll>> points, ll D) : points_(move(points)), N_(points_.size()), D_(D) {}
    ll f() {
        ll count = 0;
        for (size_t i=0; i < points_.size(); i++) {
            auto& p1 = points_[i];
            for (size_t j=i+1; j < points_.size(); j++) {
                auto& p2 = points_[j];
                ll d_square = 0;
                for (size_t n=0; n < D_; ++n) {
                    d_square += (p1[n]-p2[n])*(p1[n]-p2[n]);
                }
                if (is_square(d_square)) {
                    ++count;
                }
            }
        }
        return count;
    }
};

int main() {
    ll N, D;
    vector<vector<ll>> points{};
    cin >> N >> D;
    points.resize(N);
    for (int i=0; i < N; ++i ) {
        points[i].resize(D);
        for (int j=0; j< D; ++j) {
            cin >> points[i][j];
        }
    }
    C c{points, D};
    cout << c.f() << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef vector<int>vi;
typedef pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vi>vvi;
#define double long double
#define pow powl
#define sqrt sqrtl
#define cbrt cbrtl
#define floor floorl
#define ceil ceill
#define pb push_back
#define ep emplace_back
#define PB pop_back
#define pf push_front
#define ef emplace_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)-a.begin()
#define lb(a,b) lower_bound(all(a),b)-a.begin()
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) FOR(i,0,n-1) cin>>a[i]
#define in1(a,n) FOR(i,1,n) cin>>a[i]
#define ff first
#define ss second
#define out(a,n) FOR(i,0,n-1) cout<<a[i]<<" ";cout<<endl;
#define out1(a,n) FOR(i,1,n) cout<<a[i]<<" ";cout<<endl;
#define clr(a) a.clear()
#define pow2(a) (1LL<<a)
#define all(a) a.begin(),a.end()
#define all1(a) a.begin()+1,a.end()
#define rall(a) a.rbegin(),a.rend()
#define rall1(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define FOR(i,a,b) for(auto i=a;i<=b;i++)
#define NFOR(i,a,b) for(auto i=a;i>=b;i--)
const int mod=1e9+7;

inline int add(int a,int b){return (a%mod + b%mod)%mod;}
inline int sub(int a ,int b){return (a%mod - b%mod + mod)%mod;}
inline int mul(int a,int b){a%=mod;b%=mod;return a*b%mod;}
inline int power(int a,int b,int MOD){a%=mod;int res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define trace(x) cout<<#x<<" :: "<<x<<endl;
#define trace2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define trace3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define trace4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}
signed main()
{
     SPEED;
     int n,k;
     cin>>n>>k;
     vector<int>a,f;
     for(int i=0;i<n;i++)
     {
     	  int x;
     	  cin>>x;
     	  a.push_back(x);
     }
     for(int i=0;i<n;i++)
     {
     	   int x;
     	   cin>>x;
     	   f.push_back(x);
     }
     sort(f.rbegin(),f.rend());
     sort(a.begin(),a.end());
     int low=0;
     int high=1e13;
     int ans=-1;
     while(low<=high)
     {
     	  int mid=low+(high-low)/2;
     	  bool okay=false;
     	  int count=0;
          for(int i=0;i<n;i++)
          {
          	  int x=a[i]-(mid/f[i]);
          	  if(x>=0)
          	  	count+=x;
          }
          if(count>k)
          {
          	   low=mid+1;
          }
          else
          {
          	    ans=mid;
          	    high=mid-1;
          }
     }
     cout<<ans<<endl;
     time();
     return 0;
}

Measured memory_bytes: 5616
#include<bits/stdc++.h>
#define int long long
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << x << "\n"
constexpr int mod = 1000000007;
using namespace std;
int d, c[30], l[30], s[400][30];
signed main() {
	cin >> d;
	for1(i, 26)cin >> c[i];
	for1(i, d)for1(j, 26)cin >> s[i][j];
	for1(i, d) {
		int p = 0, k = -mod;
		for1(j, 26) {
			int kj = s[i][j] + c[j] * (i - l[j]) * 2.73 + c[j] * 12.9;
			if (kj > k) { p = j; k = kj; }
			else if (kj == k && c[j] > c[p])p = j;
		}
		puts(p); l[p] = i;
	}
}

Measured memory_bytes: 3728
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))

d = defaultdict(int)

for i in a:
  d[i] += 1

a.sort()
if max(a) == 0 and min(a) == 0:
  print ('Yes')
  exit()
b = set(a)
if len(b) == 3:
  c = 0
  for i in b:
    c ^= i
  if c == 0:
    flg = 0
    for i in d:
      if d[i] != n/3:
        flg = 1
    if flg == 1:
      print ('No')
    else:
      print ('Yes')
  else:
    print ('No')
  exit()
else:
  if min(a) == 0 and d[min(a)] ==n/3 and d[max(a)] == (2*n)/3:
    print('Yes')
  else:
    print ('No')
  exit()
print ('No')



Measured memory_bytes: 20660
#include <iostream>

void DisableIOSync() {
	std::cin.tie(0);
	std::cout.tie(0);
	std::ios::sync_with_stdio(false);
}
int main() {
	DisableIOSync();
	std::string str;
	std::getline(std::cin, str);

	const int L = str.length();
	std::string res;
	res.resize(L);
	auto* ptr = const_cast<char*>(res.data());
	auto* src = str.c_str();
	bool flag = true;
	for(;;) {
		const auto c = *src++;
		if(c == 0)
			break;
		if(flag)
			*ptr++ = c;
		flag ^= 1;
	}
	res.resize(ptr - res.data());
	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 576
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct S{
  int x, y, a, b, fr;
  S(int x, int y, int a, int b, int fr) :
    x(x), y(y), a(a), b(b), fr(fr) {}
};
bool insert(queue<S>& que, bool used[100][100][11][11][4], int x, int y, int a, int b, int fr){
  if(used[y][x][a][b][fr]) return false;
  used[y][x][a][b][fr] = true;
  que.push(S(x, y, a, b, fr));
  return true;
}
int tb[4][4] = {{-1, 0, 2, 1},
                {0, -1, 1, 2},
                {2, 1, -1, 0},
                {1, 2, 0, -1}};

int main(){
  int H, W, A;
  while(cin>>H>>W>>A){
    bool used[100][100][11][11][4] = {};
    vector<string> grid(H);
    REP(y, H) cin>>grid[y];
    queue<S> que;
    REP(y, H)REP(x, W){
      if(grid[y][x] == 'S'){
        int r = 1;
        int nx = x + dx[r];
        int ny = y + dy[r];
        if(valid(nx, ny, W, H) && grid[ny][nx] != '#'){
          insert(que, used, nx, ny, 0, 0, r);
        }
      }
    }
    while(!que.empty()){
      S s = que.front(); que.pop();
      if(grid[s.y][s.x] == 'S' && s.fr == 3) continue;
      REP(r, 4){
        int nx = s.x + dx[r];
        int ny = s.y + dy[r];
        if(valid(nx, ny, W, H) && grid[ny][nx] != '#'){
          switch(tb[s.fr][r]){
            case -1:
              insert(que, used, nx, ny, s.a, s.b, r);
              break;
            case 0:
              if(s.a + 1 <= A && grid[s.y][s.x] == '.') insert(que, used, nx, ny, s.a + 1, s.b, r);
              break;
            case 1:
              if(s.b + 1 <= A && grid[s.y][s.x] == '.') insert(que, used, nx, ny, s.a, s.b + 1, r);
              break;
            case 2:
              break;
          }
        }
      }
    }
    int ans = INF;
    REP(y, H)REP(x, W)if(grid[y][x] == 'G')REP(r, 4)REP(a, A + 1)REP(b, A + 1)if(used[y][x][a][b][r]) ans = min(ans, a + b);
    if(ans == INF) ans = -1;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 6096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  int a,b,h;
  cin >> a >> b >> h;
  cout << (a+b)*h/2 << endl;
  return 0;

}


Measured memory_bytes: 256