akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;


int main(){
    fast_io

    int n;
    cin>>n;
    int wa = 0;
    int ac = 0;
    int tle = 0;
    int re = 0;
    rep(i,n){
        string s;
        cin>>s;
        if(s=="WA") wa++;
        else if(s=="AC") ac++;
        else if(s=="TLE") tle++;
        else if(s=="RE") re++;
    }

    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout << "RE x "<<re<<endl;
    return 0;
}


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

class UnionFind{
private:
    vector<int> p,s;
	int cnt;
public:
	UnionFind(){}
	UnionFind(int N){
		cnt = N;
		p = s = vector<int>(N+1,0);
		for(int i=1;i<=N;i++){
			p[i] = i; s[i] = 1;
		}
	}
	int find(int x){
		if(p[x]==x) return x;
		else return p[x] = find(p[x]);
	}
	void unite(int x,int y){
		x = find(x); y = find(y);
		if(x==y) return;
		if(s[x]>s[y]){
			p[y] = x;
			s[x] += s[y];
		}else{
			p[x] = y;
			s[y] += s[x];
		}
		cnt--;
	}
	bool is_same_set(int x,int y) {return find(x)==find(y);}
	int size(int x) {return s[find(x)];}
	int compnents_number(){return cnt;}
};

int N,R,p;
int cnt[500010] = {};
int checked[500010] = {};
int a[1010] = {},m[1010] = {};
int dp[500010];
int main(){
    cin >> N >> R;
    UnionFind uf(N);
    for(int i=1;i<=N;i++){
        cin >> p;
        uf.unite(i,p);
    }
    int ma = 0;
    for(int i=1;i<=N;i++) if(!checked[uf.find(i)]){
        ma = max(ma,uf.size(i));
        cnt[uf.size(i)]++;
        checked[uf.find(i)] = 1;
    }
    int num = 0;
    for(int i=1;i<=ma;i++){
        if(cnt[i]==0) continue;
        num++;
        a[num] = i; m[num] = cnt[i];
    }
    for(int i=1;i<=R;i++) dp[i] = -1;
    for(int i=1;i<=num;i++){
        for(int j=0;j<=R;j++){
            if(dp[j]>=0) dp[j] = m[i];
            else if(j<a[i] || dp[j-a[i]]<=0) dp[j] = -1;
            else dp[j] = dp[j-a[i]]-1;
        }
    }
    cout << (dp[R]>=0? "Yes":"No") << endl;
}


Measured memory_bytes: 7364
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, T := sc.nextInt(), sc.nextInt()
	ans := 0
	total := 0
	for i := 0; i < N; i++ {
		t := sc.nextInt()
		if total <= t {
			total = t + T
			ans += T
		} else {
			diff := total - t
			total += T - diff
			ans += T - diff
		}
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


Measured memory_bytes: 3840
import heapq as hq
n = input()
arr = map(int,raw_input().split())
h = []
for i in range(n):
	hq.heappush(h,arr[i])
s = sum(h)
z = [s]
for i in range(n,2*n):
	sm = hq.heappop(h)
	hq.heappush(h,max(arr[i],sm))
	s = s-sm+max(sm,arr[i])
	z.append(s)
arr1 = arr[::-1]
h = []
for i in range(n):
	hq.heappush(h,-arr1[i])
s = sum(h)
s = -s
z1 = [s]
for i in range(n,2*n):
	sm = hq.heappop(h)
	hq.heappush(h,max(sm,-arr1[i]))
	s = s+sm+min(-sm,arr1[i])
	z1.append(s)
z1 = z1[::-1]
ans = -10**20
for i in range(len(z)):
	ans = max(ans,z[i]-z1[i])
print ans



Measured memory_bytes: 74520
#include <iostream>
#include <stack>
#include <cstdio>
using namespace std;

int main(){
  stack<int> st;
  int a;
  while(cin>>a){
    if(a)st.push(a);
    else {printf("%d\n",st.top());
      st.pop();
    }
}

   
  return 0;
}

Measured memory_bytes: 1180
d,g=map(int,input().split())
pc=[list(map(int,input().split())) for i in range(d)]
ans=10**18
for i in range(2**d):
  cnt=0
  res=[]
  x=0
  for j in range(d):
    if i>>j&1:
      cnt+=pc[j][1]+pc[j][0]*(j+1)*100
      x+=pc[j][0]
    else:
      res.append((100*(j+1),pc[j][0]))
  res.sort(reverse=True)
  if cnt>=g:
    ans=min(ans,x)
  elif len(res)>0:
    y=res[0]
    z=0
    while z<y[1] and cnt<g:
      cnt+=y[0]
      z+=1
    if cnt>=g:
      ans=min(ans,x+z)
print(ans)

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

int fact(int n)
{
	return (n <= 1)?1:n*fact(n-1);
}

int perm(char *str, int n)
{
	int l, p, i;
	char buff;
	l = strlen(str);
//	printf("## n:%d l:%d\n", n, l);
	if(l <= 1) {
		return 0;
	}
	p = (n / fact(l-1))%l;
	buff = str[p];
	for(i = p; i > 0; i--) {
		str[i] = str[i-1];
	}
	str[0] = buff;
//	printf("## p:%d l:%d %s\n", p, l, str);
	perm(str+1, n);
	return 0;
}


int main(void)
{
	char s[10];
	int x[10], y[10];
	int n;
	char buff[256];
	int i, j;
	int f, t;
	double dis[10][10];
	double total = 0;
	int fl;
	scanf("%d", &n);
	for(i = 0; i < n; i++) {
		scanf("%d %d", &x[i], &y[i]);
	}
	for(i = 0; i < n; i++) {
		s[i] = '0' + i;
	}
	s[n] = '\0';
	for(i = 0; i < n; i++) {
		for(j = 0; j < n; j++) {
			dis[i][j] = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
		}
	}
   	fl = fact(strlen(s));
	for(i = 0; i < fl; i++) {
		strcpy(buff, s);
		perm(buff, i);
//		printf("%d %s\n",i, buff);
		for(j = 0; j < n - 1; j++) {
			f = buff[j] - '0';
			t = buff[j+1] - '0';
			total += dis[f][t];
		}
	}
	printf("%.10f\n", total / fl);
	return 0;
}


Measured memory_bytes: 128
s = input()
n = 4
i = 0
d = {}
while(i<n):
    if s[i] in d.keys():
        d[s[i]] +=1
    else:
        d.setdefault(s[i], 1)
    i += 1
print("Yes" if len(d)==2 and max(d.values())==2 else "No")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define forn(i,b) for(int i=0 ; i< b ;i++)
#define for1(i,b) for(int i=1 ; i<=b ;i++)
#define reps(i,a,b) for(int i=a ; i< b.length() ;i++)
typedef long long ll;
#define MOD 1000000007



using namespace std;

int main()
{

string s,t;
cin>>s>>t;
cout<<t+s;

  return 0 ;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <utility>
#include <map>
#include <functional>
#include <initializer_list>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
using namespace std;
typedef long long ll;

int main(){
    ll N;
    cin >> N;
    if(N%2 == 1){
        cout << "No";
        }
    else{
        vector<char> S1(N/2), S2(N/2);
        for(ll i=0; i<N/2; i++){
            cin >> S1[i];
            }
        for(ll i=0; i<N/2; i++){
            cin >> S2[i];
            }
        if(S1 == S2) cout << "Yes";
        else cout << "No";
    }
}

Measured memory_bytes: 256
import scala.io.StdIn.readLine

object Main extends App {
  val Array(n, a, b) = readLine.split(" ").map(_.toInt)
  val xs = readLine.split(" ").map(_.toInt)

  val ds = for(Array(a, b) <- xs.sliding(2)) yield (b - a).toLong
  val mincs = ds.map(_ * a min b)

  println(mincs.sum)
}


Measured memory_bytes: 67936
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n;
	cin >> n;
	
	vector<ll> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	a.push_back(0LL);
	ll ans = 1000LL, money = 1000LL, stock = 0LL;
	
	for(int i = 0; i < n; ++i) {		
		if( i > 0 && a[i - 1] < a[i] && stock > 0 ) {
			money += a[i] * stock;
			stock = 0;
			ans = max(ans, money);
		}
		
		if( i < n && a[i] < a[i + 1] && money > a[i] ) {
			stock = money / a[i];
			money %= a[i];
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<map>
#include<queue>
using namespace std;
int main() {
	long long n, a[10], reigai = 1;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] % 2 == 0)reigai *= 2;
	}
	cout << pow(3, n) - reigai << endl;
	return 0;
}


Measured memory_bytes: 256
/*input
3
*/

#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>

using namespace std;

ll go(ll h) {
	if(h == 0) return 0;
	if(h == 1) return 1;
	return 1 + 2*go((h/2));
}

void run() {
	ll h;
	cin >> h;
	cout << go(h) << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);		
	int t = 1;
	while(t--) {
		run();
	}
}


Measured memory_bytes: 256
N,M=map(int,input().split())
H=list(map(int,input().split()))
A=[i for i in range(N)]
B=[]
for i in range(M):
    a,b=map(int,input().split())
    if H[a-1]>H[b-1]:
        B.append(b)
    elif H[b-1]>H[a-1]:
        B.append(a) 
    else:
        B.append(a)
        B.append(b)

B=list(set(B))
print(len(A)-len(B))

Measured memory_bytes: 23696
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def conb(n,r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n,k = inpl()
s = input()
cnt = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        cnt += 1
print(min(cnt+2*k, n-1))

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

// Euclid's algorithm for calculating gcd(a,b) in O(log(min(a,b)))
int64_t gcd(int64_t a, int64_t b){
	return b ? gcd(b, a % b) : a;
}

// get the prime factorization of n in O(sqrt(n))
vector<int64_t> prime_factors(int64_t n){
	vector<int64_t> res;
	for(int64_t i = 2; i*i <= n; i++){
		if(n % i == 0) res.push_back(i);
		while(n % i == 0){
			n /= i;
		}
	}
	if(n > 1) res.push_back(n); // n has a prime factor > sqrt(n)
	// Note: for any n > 1, it has at most 1 prime factor > sqrt(n)
	// 		 Why? Assume it has 2 prime factors p,q that are > sqrt(n)
	// 		 so p|n and q|n, => pq|n, but pq>n ==> contradiction.
	return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int64_t n ; cin >> n;
	vector<int64_t> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	int64_t g = a[0];
	for(int i = 1; i < n; i++) g = gcd(g, a[i]);
	if(g != 1) cout << "not coprime";
	else{
		bool found_common = false;
		unordered_map<int, int> div;
		for(int k : a){
			vector<int64_t> f = prime_factors(k);
			// for(int b : f) cout << b << ' ';
			// cout << '\n';
			for(int j : f){
				if(div[j] != 0){
					found_common = true;
					goto done;
				}
				div[j] = 1;
			}
		}

		done: if(found_common) cout << "setwise coprime";
		else{
			cout << "pairwise coprime";
		}
	}
	return 0;
}

Measured memory_bytes: 11116
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <climits>
#define ll   long long int 
#define mod 1000000007
#define inf  200000000000000
#define eps  0.0000000000001
using namespace std ;  
int main()
{
   ios::sync_with_stdio(false);cin.tie(0) ;cout.tie(0) ; 
   ll n , k ;cin>>n>>k  ; 
   ll arr[n + 1];
   ll mina =  inf ; 
   ll minindex ; 
   for(ll i  = 1 ; i <= n  ;++i)
   {
     cin>>arr[i] ; 
     if(arr[i] < mina) 
      {
         mina  =arr[i] ;  
         minindex  =  i ;  
      } 
   }
  ll i  = minindex ;
  if(i - k  <= 0)
  {
    ll cur = i + (k - i)  ; 
    ll ans = 1 ; 
     while(cur < n)
     {
       ans++ ; 
       cur += (k-1) ;
     
     }
     cout<<ans ;
  }
  else if(i + k - 1 >= n  )
  {

    ll cur =  i -  ( (i + k - 1 ) - n)  ; 
    ll ans = 1 ; 
     while(cur > 1 )
     {
       ans++ ; 
       cur -= (k-1) ;
      
     }
     cout<<ans ; 

  }
  else
  {
    ll x =  (n - i - ( k  - 2))/(k-1) ; 
    ll cur = n  -  (k-1)*x ; 
    ll ans  = x ; 
     while(cur > 1 )
     {
       ans++ ; 
       cur -= (k-1) ;
      
     }
     cout<<ans ; 
  }

  
return   0 ; }


Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int N=1005;
int n,m,q,x,y;
vector<int> e[N];
int main() {
    scanf("%d%d%d",&n,&m,&q);
    for (int i=1;i<=m;i++) {
        scanf("%d%d",&x,&y);
        e[x].push_back(y);
    }
    for (int i=1;i<=n;i++) {
        sort(e[i].begin(),e[i].end());
    }
    for (int i=1;i<=q;i++) {
        scanf("%d%d",&x,&y);
        int now=0;
        for (int j=x;j<=y;j++) {
            now+=upper_bound(e[j].begin(),e[j].end(),y)-e[j].begin();
        }
        printf("%d\n",now);
    }
    return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  ll sum = 0;
  rep(i, m) {
    int a;
    cin >> a;
    sum += a;
  }
  if (n - sum < 0) puts("-1");
  else cout << n-sum << endl;
  return 0;
}

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

const int N = 100 * 1000 + 10;

int n;
int A[N], B[N];
vector <int> extra;
long long need;

void input() {
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> A[i];
    for (int i = 0; i < n; i++)
        cin >> B[i];
    return;
}

void solve() {
    int cnt = 0;
    for (int i = 0; i < n; i++)
        if (A[i] - B[i] > 0)
            extra.push_back(A[i] - B[i]) ;
        else if (A[i] - B[i] < 0) {
            need += B[i] - A[i];
            cnt++;
        }

    sort(extra.begin(), extra.end(), greater <int> ()) ;

    int pnt = 0;
    while (need > 0 && pnt < extra.size())
        need -= extra[pnt++];

    if (need > 0)
        cout << -1 << endl;
    else
        cout << pnt + cnt << endl;
    return;
}

int main() {
    input() ;
    solve() ;
    return 0;
}


Measured memory_bytes: 1408
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		if(A == B) System.out.println(C);
		if(A == C) System.out.println(B);
		if(C == B) System.out.println(A);
	}
}


Measured memory_bytes: 23892
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n,t = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)

maxes = Array.new(n)
maxes[-1] = a[-1]
(n-2).downto(0) do |i|
  maxes[i] = [maxes[i+1], a[i]].max
end

min = INF
maxdiff = 0
(n-1).times do |i|
  min = [min, a[i]].min
  diff = maxes[i+1] - min
  maxdiff = [maxdiff, diff].max
end

ans = 0
(n-1).times do |i|
  diff = maxes[i+1] - a[i]
  if diff == maxdiff
    ans += 1
  end
end

puts ans






Measured memory_bytes: 23068
fn main() {
    let (n,k) = {
        let s = rv::<usize>();
        (s[0],s[1])
    };
    let mut g = vec![vec![];n];
    for _ in 1..n {
        let (a,b) = {
            let s = rv::<usize>();
            (s[0]-1,s[1]-1)
        };
        g[a].push(b);
        g[b].push(a);
    }
    println!("{}",f(0,0,k,0,0,&g));
}
fn f(v:usize, p:usize, k:usize, k1:usize, k2:usize, g:&Vec<Vec<usize>>) -> usize {
    let mut t=k;
    let k=k+k2;
    let mut i=0;
    for &u in &g[v] { if u!=p {
        i = std::cmp::min(k,i+1);
        t = t*f(u,v,k-i,1,k1+i-1,g)%MOD;
    }}
    t
}
const MOD: usize=1000000007;
fn rl() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s
}
fn rv<T>() -> Vec<T> where T: std::str::FromStr, T::Err: std::fmt::Debug, {
    rl().split_whitespace().map(|x|x.parse::<T>().unwrap()).collect()
}

Measured memory_bytes: 16252
#include <stdio.h>
#include <string.h>

int main(void){
    int N;
    scanf("%d",&N);
    char blue[N][10];
    for(int i = 0;i < N;i++){
        scanf("%s",blue[i]);
    }

    int M;
    scanf("%d",&M);
    char red[M][10];
    for(int i = 0;i < M;i++){
        scanf("%s",red[i]);
    }

    int X = 0;
        for(int i = 0;i < N;i++){
            int count = 0;
            for(int j = i;j < N;j++){
                if(strcmp(blue[i],blue[j]) == 0){
                    count++;
                }
            }
            for(int j = 0;j < M;j++){
                if(strcmp(blue[i],red[j]) == 0){
                    count--;
                }
            }
            if(count > X){
                X = count;
            }
        }
        printf("%d\n",X);
}

Measured memory_bytes: 128
INF = 1 << 60

n, m ,p = gets.split.map(&:to_i)
g = []
to = Array.new(n + 1) {[]}
ot = Array.new(n + 1) {[]}
m.times do
  a, b, c = gets.split.map(&:to_i)
  g << [a, b, -(c - p)]
  to[a] << b
  ot[b] << a
end

toflag = [0] * (n + 1)
toflag[1] = 1
iki = ->(v) {
  to[v].each do |u|
    if toflag[u].zero?
      toflag[u] = 1
      iki.(u)
    end
  end
}
iki.(1)

otflag = [0] * (n + 1)
otflag[n] = 1
kaeri = ->(v) {
  ot[v].each do |u|
    if otflag[u].zero?
      otflag[u] = 1
      kaeri.(u)
    end
  end
}
kaeri.(n)

cand = toflag.zip(otflag).map {|a, b| a * b}
max_count = cand.count(1)
g.select! {|a, b, _| cand[a] == 1 && cand[b] == 1}

bf = ->{
  inf = INF
  d = Array.new(n + 1, inf)
  d[1] = 0
  update = true
  max_count = cand.count(1).times do |i|
    update = false
    g.each do |v, u, cost|
      if d[v] != inf && d[u] > (a = d[v] + cost)
        d[u] = a
        update = true
      end
    end
    return -d[n] unless update
  end
  inf
}
ans = bf.()

ans = (ans == INF) ? -1 : [ans, 0].max
puts ans

Measured memory_bytes: 14588
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

ll score(vector<ll> &vec, ll b) {
  ll tmp = 0;
  for (auto &v : vec)
    tmp += abs(v - b);
  return tmp;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> vec(n);
  for (int i = 0; i < n; ++i) {
    ll tmp;
    cin >> tmp;
    vec[i] = tmp - (i + 1);
  }

  ll b0 = -1e9;
  ll b1 = -1e9 + 2e9 / 3;
  ll b2 = -1e9 + 2e9 / 3 * 2;
  ll b3 = 1e9;
  ll f0 = score(vec, b0);
  ll f1 = score(vec, b1);
  ll f2 = score(vec, b2);
  ll f3 = score(vec, b3);

  while (3 <= b3 - b0) {
    if (f0 > f1 && f1 > f2) {
      b0 = b1;
      f0 = f1;
      if (b3 - b2 < b2 - b1) {
        b1 = (b1 + b2) / 2;
        f1 = score(vec, b1);
      } else {
        b1 = b2;
        b2 = (b2 + b3) / 2;
        f1 = f2;
        f2 = score(vec, b2);
      }
    } else {
      b3 = b2;
      f3 = f2;
      if (b2 - b1 < b1 - b0) {
        b2 = b1;
        f2 = f1;
        b1 = (b0 + b1) / 2;
        f1 = score(vec, b1);
      } else {
        b2 = (b1 + b2) / 2;
        f2 = score(vec, b2);
      }
    }
  }

  vector<ll> ans = {f0, f1, f2, f3};
  cout << *min_element(ans.begin(), ans.end()) << endl;
}

Measured memory_bytes: 4852
def burger_size(N):
    if N == 0:
        return 1
    return 3 + 2 * burger_size(N - 1)

def burger_patty_num(N):
    if N == 0:
        return 1
    return 1+ 2 * burger_patty_num(N - 1)

def patty_num(N, X):
    if X == 0:
        return 0
    if N == 0:
        return 1
    if X <= 1 + burger_size(N - 1):
        return patty_num(N - 1, X - 1)
    elif X == 2 + burger_size(N - 1):
        return 1 + burger_patty_num(N - 1)
    elif X <= 2 + 2 * burger_size(N - 1):
        return 1 + burger_patty_num(N - 1) + patty_num(N - 1, X - (2 + burger_size(N - 1)))
    else:
        return 1 + 2 * burger_patty_num(N - 1)
        
    
N, X = map(int, input().split())
print(patty_num(N, X))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9 + 5;
constexpr long long INFLL = 1LL << 62;
constexpr double eps = (1e-9);

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

  ll k;
  cin >> k;

  vector<ll> lu;
  queue<ll> q;

  for (int i = 1; i <= 9; i++) {
    lu.push_back(i);
    q.push(i);
  }

  while (lu.size() < k && !q.empty()) {
    ll n = q.front(); q.pop();
    ll b = n % 10;
    ll ne = n * 10;
    if (b != 0) {
      lu.push_back(ne + b - 1LL);
      q.push(ne + b - 1LL);
    }
    lu.push_back(ne + b);
    q.push(ne + b);
    if (b != 9) {
      lu.push_back(ne + b + 1LL);
      q.push(ne + b + 1LL);
    }
  }

  cout << lu[k-1] << endl;

  return 0;
}


Measured memory_bytes: 4620
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    ll n,m;cin>>n>>m;
    ll ki[n+2];
    fill(ki,ki+n+2,0);
    ll a[n];
    rep(i,0,m){
        cin>>a[i];
        ki[a[i]]=1;
    }
    ll dp[n+2];
    fill(dp,dp+n+2,0);
    dp[0]=1;
    rep(i,0,n){
        if(ki[i+1]==0){
            dp[i+1]+=dp[i];
            dp[i+1]%=mod;
        }
        if(ki[i+2]==0){
            dp[i+2]+=dp[i];
            dp[i+2]%=mod;
        }
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 2560
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma") 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define ll long long
#define lld long long double
#define MP make_pair
// #define int long long
// #define MAX LONG_LONG_MAX
// #define MIN LONG_LONG_MIN
#ifdef LOCAL // setting up print debugging (yes lol)
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.x<<','<<p.y<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
#endif
using namespace std;
// const lld pi = 3.14159265358979323846;
const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;
 
namespace modop {
	ll madd(ll a, ll b) {
	  return (a + b) % mod;
	}
	ll msub(ll a, ll b) {
	  return (((a - b) % mod) + mod) % mod;
	}
	ll mmul(ll a, ll b) {
	  return ((a % mod) * (b % mod)) % mod;
	}
	ll mpow(ll base, ll exp) {
	  ll res = 1;
	  while (exp) {
		if (exp % 2 == 1){
			res = (res * base) % mod;
		}
		exp >>= 1;
		base = (base * base) % mod;
	  }
	  return res;
	}
	ll minv(ll base) {
	  return mpow(base, mod - 2);
	}
	ll mdiv(ll a, ll b) {
	  return mmul(a, minv(b));
	}
}
 
using namespace modop;
 
ll n, m, k, q, l, r, x, y, z;
const ll template_array_size = 1e6 + 1389;
ll a[template_array_size];
ll b[template_array_size];
ll c[template_array_size];
string s, t;
ll ans = 0;
 
ll fact[1000005], ifact[1000005];
 
ll nck(ll n, ll k) {
	ll dem = (ifact[n - k] * ifact[k]) % mod;
	return (fact[n] * dem) % mod;
}
 
void check(int tc = 0) {
	cin >> n;
	
	fact[0] = fact[1] = ifact[0] = ifact[1] = 1;
	for (ll i = 2; i <= n; i++) {
		fact[i] = (i * fact[i - 1]) % mod;
		ifact[i] = minv(fact[i]);
	}
	
	ll ans = 0;
	
	for (ll n9 = 1; n9 <= n; n9++) {
		ll pos9 = nck(n, n9);
		ll tot = mpow(9, n - n9);
		ll invalid = mpow(8, n - n9);
		ans = (ans + pos9 * (tot - invalid)) % mod;
		ans = (ans + mod) % mod;
	}
	
	cout << ans << '\n';
}
 
int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); 
	cin.exceptions(cin.failbit);
	int t = 1;	
	// cin >> t;
	for(int i = 1 ; i <= t ;i++){
		// cout << "Case "<< i << ":\n";
		check();
	}
	return 0;
}


Measured memory_bytes: 19212
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>

//using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

using ll =  long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T& a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}


}


int main() {

	ll n, m;
	std::cin >> n >> m;
	std::vector<ll> a(n);
	rep(i, n) std::cin >> a[i];
	rep(i, n) a[i] /= 2;

	ll ans = 0;

	// aの中で2の因数がすべて同じ数
	ll g = a[0];
	rep(i, n - 1) {
		g = gcd(g, a[i + 1]);
	}

	// lcm
	ll min_x = a[0];
	rep(i, n - 1) {
		min_x = lcm(min_x, a[i + 1]);
		if (min_x > m) {
			std::cout << 0 << std::endl;
			return 0;
		}
	}

	if ((min_x / g) % 2LL == 0) {
		std::cout << 0 << std::endl;
		return 0;
	}

	// min_xは3,5,7,9など奇数倍してもよい
	for (ll rate = 1; ; rate += 2LL) {
		if (min_x * rate > m) break;
		++ans;
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 1000009
#define mod 1000000007
ll n,m,i,j,k,tt,a,l,b[sz],d[sz],arr[sz];
int main()
{
scanf("%lld",&a);
l=a+(a*a)+(a*a*a);
printf("%lld\n",l);
}


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

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

using namespace std;

int main(){
  string a,b,c;
  cin>>a>>b>>c;
  
  if(a.back()==b.at(0) && b.back()==c.at(0)){
    cout<<"YES";
  }else{
    cout<<"NO";
  }
  return 0;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    if(n % 2 == 0) {
        for(int i=0; i<n/2; i++) {
            if(s.at(i) != s.at(i+n/2)) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    } else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int mod=1e9+7;
int main() {
string s;
cin>>s;
int n=0;
int N=0;
for(int i=0;i<s.size();i++){
   N=N*10+(s.at(i)-'0');
   n+=s.at(i)-'0';
}
if(N%n==0)cout<<"Yes"<<endl;
else cout<<"No"<<endl;

}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    println(if (a+b==c || a+c==b || b+c==a) "Yes" else "No")
}

Measured memory_bytes: 31264
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int N;
vector<int> G[200000];
bool used[200000];
int cnt[200000];
int idx1[200001];
int idx2[200001];
vector<int> vs;

void dfs(int v){
    used[v] = true;
    vs.push_back(v);
    for(int to : G[v]){
        if(used[to]) continue;
        if(cnt[to] == 0) continue;
        dfs(to);
    }
}

void print(vector<int> ans){
    for(int i : ans) cout << i << ' ';
    cout << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N-1; i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
        cnt[u]++; cnt[v]++;
    }
    for(int i = 0; i < N; i++){
        if(G[i].size() == 1){
            int to = G[i][0];
            cnt[to]--;
            cnt[i]--;
        }
    }
    int v;
    for(int i = 0; i < N; i++){
        if(cnt[i] >= 3){
            cout << -1 << endl;
            return 0;
        }
        if(cnt[i] == 1) v = i;
    }
    bool f = false;
    for(int i = 0; i < N; i++){
        if(cnt[i] == 1) {
            dfs(i);
            f = true;
            break;
        }
    }
    if(!f){
        cout << 1 << ' ';
        for(int i = 3; i <= N-1; i++) cout << i << ' ';
        cout << 2 << ' ' << N << endl;
        return 0;
    }
    int cur = 1;
    vector<int> ans1, ans2;
    ans1.push_back(1);
    for(int i = 0; i < vs.size(); i++){
        int v = vs[i];
        int sz = G[v].size()-2;
        for(int i = 1; i <= sz; i++) ans1.push_back(cur+i+1);
        ans1.push_back(cur+1);
        cur += (sz+1);
    }
    ans1.push_back(N);
    cur = 1;
    ans2.push_back(1);
    for(int i = vs.size()-1; i >= 0; i--){
        int v = vs[i];
        int sz = G[v].size()-2;
        for(int i = 1; i <= sz; i++) ans2.push_back(cur+i+1);
        ans2.push_back(cur+1);
        cur += (sz+1);
    }
    ans2.push_back(N);
    
    for(int i = 0; i < N; i++){
        if(ans1[i] < ans2[i]) {
            print(ans1);
            return 0;
        }
        if(ans2[i] < ans1[i]) {
            print(ans2);
            return 0;
        }
    }
    print(ans1);
}

Measured memory_bytes: 15992
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<cstdio>
using namespace std;
int main()

{
    int a,b,c;
    while(scanf("%d%d%d",&a,&b,&c)!=EOF)
    {
        printf("%d\n",b/a>c?c:b/a);
    }

}


Measured memory_bytes: 256
input = require('fs').readFileSync('/dev/stdin', 'utf8');
L = input.split('\n')[1].split(' ').map(Number).sort((x, y) => x - y).reverse();

M = L[0];
L.shift();
S = L.reduce((x, y) => x + y);
console.log(M < S ? 'Yes' : 'No');

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x,y;
    scanf("%d %d",&x,&y);
    int e=x*4;
    for(int i=0;i<x+1;i++){
        if(e==y){
            printf("Yes");
            return 0;
        }
        e-=2;
    }
    printf("No");
    return 0;
}

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

//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long double db;

#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

template<typename T> void print(const T& a, ostream& out){	
	for(auto i: a) out << i << ' ';
	out << endl;
}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	int h, w, m;
	cin >> h >> w >> m;
	set<PII> S;
	vector<int> A(h, 0);
	vector<int> B(w, 0);
	while(m--){
		int x, y;
		cin >> x >> y;
		--x; --y;
		A[x]++;
		B[y]++;
		S.insert({x, y});
	}
	
	int ans = 0;
	int mxa = *max_element(ALL(A));
	int mxb = *max_element(ALL(B));
	ans = mxa + mxb;
	VI cnta, cntb;
	FOR(i, 0, h) if (A[i] == mxa) cnta.PB(i);
	FOR(i, 0, w) if (B[i] == mxb) cntb.PB(i);
	
	if (SZ(cnta) * (LL) SZ(cntb) <= SZ(S)){
		bool ok = 0;
		for(auto i: cnta) if (!ok) for(auto j: cntb){
			if (!S.count({i, j})){
				ok = 1;
				break;
			}
		}
		
		ans -= !ok;
	}
	
	cout << ans << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
    return 0;
}


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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i=(a);i>=(b);i--)
#define FORR(i,a,b) for (int i=(a);i>(b);i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

    ll k,a,b;
    cin >> k >> a >> b;

    if(b-a<=2){
        cout << k+1 << endl;
    }else{
        ll m=(k-(a-1))/2;
        ll res=a;
        res+=(b-a)*m;
        if((k-(a-1))&1)
            res++;

        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  while (true) {
    lint n; cin >> n;
    if (!n) break;
    string b; cin >> b;
    b = '1' + b;
    lint a = stoll(b, nullptr, 2);
    int e = 0;
    lint s = a;
    while (n and a) {
      lint ok = 0, ng = (1LL << 60) / a;
      assert(__lg(s + ng * a) > __lg(s));
      while (ng - ok > 1) {
        lint m = ok + ng >> 1;
        (__lg(s + m * a) == __lg(s) ? ok : ng) = m;
      }
      lint c = min(n, ng);
      s += c * a;
      if (__lg(s) > 52) {
        ++e;
        s >>= 1;
      }
      a >>= 1;
      n -= c;
    }
    cout << bitset<12>(e) << bitset<52>(s) << '\n';
  }
}


Measured memory_bytes: 3128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;

#define bil ((ll)1e9)
#define mod ((ll)1e9+7)

int main(int argc,char* argv[]){
    int w,h,n;
    cin >> w >> h >> n;

    vector<pii> xy(n);
    vector<int> a(n);
    for(int i=0;i<n;i++)
        cin >> xy[i].first >> xy[i].second >> a[i];

    vector<bool> wbh(w,true),hbh(h,true);
    for(int i=0;i<n;i++){
        if(a[i]==1){
            for(int count=0;count<xy[i].first;count++)
                wbh[count]=false;
        }else if(a[i]==2){
            for(int count=w-1;count>xy[i].first-1;count--)
                wbh[count]=false;
        }else if(a[i]==3){
            for(int count=0;count<xy[i].second;count++)
                hbh[count]=false;
        }else if(a[i]==4){
            for(int count=h-1;count>xy[i].second-1;count--)
                hbh[count]=false;
        }
    }

    int wh=0,hh=0;
    for(int wide=0;wide<w;wide++){
        if(wbh[wide]==true)
            wh++;
    }
    for(int high=0;high<h;high++){
        if(hbh[high]==true)
            hh++;
    }

    cout << wh*hh << endl;

    return 0;
}


Measured memory_bytes: 256
M, K = map(int, input().split())
if K>(1<<M)-1:
    print(-1)
elif M == 1 and K == 1:
    print(-1)
elif M == 1 and K == 0:
    print(0, 0, 1, 1)
elif M == 0 and K == 0:
    print(0, 0)
elif M == 0:
    print(-1)
else:
    N = 1<<M
    ans = list(range(K))+list(range(K+1, N))+[K]+list(range(K+1, N))[::-1]+list(range(K))[::-1]+[K]
    print(*ans)

Measured memory_bytes: 67568
n = gets.chomp.to_i
b_arr = [10**5+1] + gets.chomp.split(" ").map(&:to_i) + [10**5+1]

a_arr = []
b_arr.each_cons(2) do |b1, b2|
  if b1 > b2 then
    a_arr << b2
  else
    a_arr << b1
  end
end

puts a_arr.inject(&:+)


Measured memory_bytes: 1788
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
long long n, d, ans = 0, a[15][15];
int main(int argc, char const *argv[])
{
	scanf("%lld%lld", &n, &d);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= d; ++j)
			scanf("%lld", &a[i][j]);
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j < i; ++j)
		{
			long long sum = 0;
			bool pd = false;
			for (int k = 1; k <= d; ++k) sum += (a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			for (int k = 1; k <= 1000; ++k)
			{
				if ((long long)k*k == sum)
				{
					pd = true;break;
				}
			}
			if (pd) ans++;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        String answer = a < b && b < c ? "Yes" : "No";
        System.out.println(answer);
    }
}


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

int main(){
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    if(a == 0)cout << 1 << endl;
    if(b == 0)cout << 2 << endl;
    if(c == 0)cout << 3 << endl;
    if(d == 0)cout << 4 << endl;
    if(e == 0)cout << 5 << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(LL)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat 
using namespace std;
typedef long long LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef pair<ut,bool> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
const int INF=1<<30;
const int BITSIZE=1<<17;
const LL p=7+1e9;
const int SIZE=5+1e5;
LL x[SIZE];
int main(){
	int N;
	cin >> N;
	LL ans=0;
	FOR(i,1,N+1){
		cin >> x[i];
		LL useful=min(x[i],x[i-1]);

		ans+=useful;
		x[i]-=useful;
		useful=x[i]/2;
		ans+=useful;
		x[i]-=useful*2;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

int gcd(int x, int y){
	return x? gcd(y%x, x) : y;
}
void Main()
{
	int N, a;
  	cin >> N;
	int ans = 0;
  	rep(i,N) {
      	cin >> a;
  		ans = gcd(ans,a);
    }  	
	cout << ans << endl;  	
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 12345678;
int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    int ans = INF;
    rep(i,n){
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }
    rep(is, 1 << n){
        // cout << bitset<3>(is) << " ";
        int sum = 0;
        vector<int> skill(n);
        bool can = false;
        int cnt = 0;
        rep(i,n){
            if(is >> i & 1){
                sum += c[i];
                rep(j,m){
                    skill[j] += a[i][j];
                    // cout << skill[j] << " ";
                }
            }
        }
        rep(i,m){
            if(skill[i] >= x){
                cnt++;
            }
        }
        // cout << sum << endl;
        // if(is == 0) ans = sum;
        if(cnt == m && ans > sum) ans = sum;
    }
    // rep(i,m) cin >> a[0][i];
    // rep(i,m) cout << a[0][i] << endl;
    // rep(i,n){
    //     cout << c[i] << " ";
    //     rep(j,m) cout << a[i][j] << " ";
    //     cout << endl;
    // }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        
        if(s.equals("Sunny")){
            System.out.println("Cloudy");
        }else if(s.equals("Cloudy")){
            System.out.println("Rainy");
        }else{
            System.out.println("Sunny");
        }
    }
}

Measured memory_bytes: 21972
#include <queue>
#include <string>
#include <iostream>
using namespace std;
main(){
	priority_queue<int>q;
	string s;
	int k;
	for(;cin>>s&&s!="end";){
		if(s=="insert"){
			cin>>k;
			q.push(k);
		}else
			cout<<q.top()<<endl,q.pop();
	}
}

Measured memory_bytes: 6504
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        int cnt = 1;
        for(int i = 0; i < N; i++){
          a[i] = sc.nextInt();
        }
        int[] c = Arrays.stream(a).distinct().toArray();
        Arrays.sort(c);
        int min = c[0];
        for(int i = 0; i < c.length; i++){
          if(min < c[i]){
            cnt++;
          }
        }
        
        System.out.println(cnt);
    }
}


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

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

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

using namespace std;

#define ll long long 
#define ld long double

signed main() {
	int n, k; cin >> n >> k;
	string s; cin >> s;
	s[k - 1] = 'a' + (s[k - 1] - 'A');
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, 0, n) cin >> v[i];
  sort(v.begin(), v.end());
  int bs = 0, as = 0;
  rep(i, 0, n) {
    if(i % 2 == 0) {
      as += v[n-i-1];
    } else {
      bs += v[n-i-1];
    }
  }
  cout << as - bs;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	vector<int> a(n);
	vector<int> b(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a.at(i);

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

	sort(b.begin(), b.end());
	int b0 = b.at(n / 2);

	ll ans = inf;
	ll s = 0;
	for (int i = 0; i < n; i++)
	{
		s += abs(a.at(i) - (b0 + (i + 1)));
	}

	cout << s << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <cmath>
using namespace std;

const double PI = acos(-1);

int main(){
  int n;
  long long a = 1;
  long long m;
  cin >> n;
  vector<long long> arr;
  for(int i=0;i<n;i++){
    cin >> m;
    if(m == 0){
      cout << "0\n";
      return 0;
    }
    arr.push_back(m);
  }
  for(auto v: arr){
    if(v > sqrt(1000000000000000000)){
      cout << "-1\n"; 
      return 0;
    }
    a *= v;
    if(a > 1000000000000000000){
      cout << "-1\n"; 
      return 0;
    }
  }
  if(a > 1000000000000000000){
    cout << "-1\n"; 
    return 0;
  }
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int gcd(int a, int b){
  if(a % b == 0) return b;
  return gcd(b, a%b);
}
int main(){
  int n; cin >> n;

  int b; cin >> b;
  for(int i = 1; i < n; i++){
    int a; cin >> a;
    b = gcd(a,b);
  }
  cout << b << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> p;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9



int main() {
	int N;
	cin >> N;
	ll a, b;
	cin >> a >> b;

	for (int i = 1; i < N; i++) {
		ll tmpa, tmpb;
		cin >> tmpa >> tmpb;
		// na は a <= tmpa * na を満たす最小値
		ll na = a / tmpa; if (a != tmpa * na) na++;
		ll nb = b / tmpb; if (b != tmpb * nb) nb++;
		
		ll n = max(na, nb);
		a = n * tmpa;
		b = n * tmpb;
	}
	cout << a + b << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int X = sc.nextInt();
		int L[] = new int[N];
		int D[] = new int[N+1];
		for(int i=0;i<N;i++) {
			L[i] = sc.nextInt();
		}
		D[0]=0;
		int c=0;
		for(int i=1;i<N+1;i++) {
			D[i] = D[i-1]+L[i-1];
			if(D[i]<=X)c++;
		}
		System.out.println(c+1);
	}
}

Measured memory_bytes: 21972