akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))

m=min(A)
M=max(A)


ans=10**18
for i in range(m,M+1):
    ans=min(ans,sum(list(map(lambda x:(i-x)**2,A))))

print(ans)

Measured memory_bytes: 3060
import sys
import numpy as np

read = sys.stdin.read
readline = sys.stdin.readline

N, *S = map(str, read().split())
S = np.array(list(map(list, S)), np.str)
S = np.hstack((S, S))
S = np.vstack((S, S))
N = int(N)
answer = 0
for y in range(N):
    a = S[:N, y:y + N]
    if np.all(a == a.T):
        answer += N

print(answer)


Measured memory_bytes: 20672
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;
 
int main(){
  string n;
  cin >> n;

  if(n[0]==n[2]){ cout << "Yes" << endl; } else { cout << "No" << endl; }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define rep2(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) ll i=(n);ll now=-1;while(i--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)
#define vll vector<ll>
#define pb push_back
using namespace std;
using ll = long long;

static inline void ignore_ret(int x) {x++;}
template<class T> inline bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> inline T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> inline T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm(r,v.at(i));return r;}
template<class T> inline T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> inline T nCr(T n,T k){if(n<k||n<0||k<0)return 0;T r=1;k=min(k,n-k);for(T i=n-k+1;i<=n;i++)r*=i;return r/factorial(k);}
template<class T> inline T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> inline T sum(vector<T>v){return reduce(all(v),0LL);}

// Template ends here

void solve(string S){
  vector<string> dayOfTheWeek = { "SUN","MON","TUE","WED","THU","FRI","SAT" };
  rep(i, 7) if (S == dayOfTheWeek.at(i)) cout << 7 - i << endl;
}

int main() {
  string S;
    cin >> S;
  solve(S);
  return 0;
}


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

int main(void) {
	int N, ans = 0;
	cin >> N;
	int size = N - 1;
	vector<int> B(size);

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

	ans += B[0] + B[size-1];
	//cout << ans << endl;

	for (int i = 1; i < size; i++) {
		ans += min(B[i - 1], B[i]);
		//cout << ans << endl;
	}

	cout << ans;

	//system("pause");
	return 0;
}

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

int main() {
  int32_t n;
  cin >> n;
  int32_t a[n];
  int32_t total = 0;
  for (int32_t i = 0; i < n; i++) {
    cin >> a[i];
    total += a[i];
  }

  int32_t a1 = total / n;
  int32_t a2 = a1 + 1;
  int32_t c1 = 0, c2 = 0;
  for (int32_t i = 0; i < n; i++) {
    c1 += (a[i] - a1) * (a[i] - a1);
    c2 += (a[i] - a2) * (a[i] - a2);
  }

  cout << min(c1, c2) << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
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;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S; cin >> S;
    int N = S.size();

    int ans = 0;
    int k = 0;
    rep(i,N) {
        if (S[i] != '0') chmax(ans,k+(S[i]- '1')+9*(N-1-i));
        k += S[i]-'0';
    }
    chmax(ans,k);
    cout << ans << endl;   
} 


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] days = new int[m];
        int sum = 0;
        for (int i = 0; i < m; i++) {
            days[i] = sc.nextInt();
            sum += days[i];
        }
        if (n < sum) System.out.println("-1");
        else System.out.println(n - sum);
        
    }
}

Measured memory_bytes: 46492
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
using namespace std;

int main(){
  string s;
  cin >> s;
  map<char,int> cnt;
  for(int i = 0; i < s.size(); i++){
    if(cnt[s[i]] == 1) {
      cout << "no" << endl;
      return 0;
    } else {
      cnt[s[i]]++;
    }
  }
  cout << "yes" << endl;
  return 0;
}


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

int main(){
  vector<int> v(5);
  for(int i=0;i<5;i++){
    cin >> v.at(i);
  }
  int ans=0;
  while(1){
    auto itr=find_if(v.begin(),v.end(),[](int a){
      return (a%10==0);
    });
    if(itr==v.end()){
      break;
    }
    ans+=(*itr);
    v.erase(itr);
  }
  if(!v.empty()){
    sort(v.begin(),v.end(),[](int a,int b){
      return (a%10)>(b%10);
    });
    for(int i=0;i<v.size()-1;i++){
      ans+=(v.at(i)+9)/10*10;
    }
    ans+=v.back();
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main(){
  int l[3];

  cin >> l[0] >> l[1] >> l[2];

  sort(l, l+3);

  if(l[0] == 5 && l[1] == 5 && l[2] == 7){
    cout << "YES";
  } else{
    cout << "NO";
  }

  cout << endl;

  return 0;  
}


Measured memory_bytes: 256
eval'N,M,K,*X='+`dd`.split*?,
s=X[0,z=i=j=N].sum
X<<K
((s+=X[j];j+=1)until s+X[j]>K
s>K||z=[z,i+j].max
s-=X[i-=1])until i<0
p z-N

Measured memory_bytes: 94016
#include<iostream>
#include<string>

using namespace std;

int main(){
  string str,O,p,x;//O:order
  int q,a,b;
  cin>>str>>q;
  for(int i=0;i<q;i++){
    x=str;
    cin>>O;
    if(O=="print"){
      cin>>a>>b;
      for(int v=a;v<=b;v++){
        cout<<str[v];
        if(v==b)cout<<endl;
      }
    }
    if(O=="reverse"){
      cin>>a>>b;
      for(int v=a;v<=b;v++){
        str[v]=x[b-(v-a)];
      }
    }
    if(O=="replace"){
      cin>>a>>b>>p;
      for(int v=a;v<=b;v++){
        str[v]=p[v-a];
      }
    }
  }
}

//print a b:の a 文字目から b 文字目までを出力する。
//reverse a b:strの a 文字目から b 文字目までを逆順にする。
//replace a b p: strの a 文字目から b 文字目までを p に置き換える。



Measured memory_bytes: 3216
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
int main() {
	int i,j,k,l,n,m;
	string s,r,re;
	cin>>s>>r;
     n=s.length();
	 m=r.length();
	 int dp[n+1][m+1];
	 memset(dp,0,sizeof(dp));
	 for(i=1;i<=n;i++)
	 {
		 for(j=1;j<=m;j++)
		 {
			 if(s[i-1]==r[j-1])
			 dp[i][j]=dp[i-1][j-1]+1;
                
				else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		 }
	 }
	 l=dp[n][m];
	 i=n,j=m;
	 while(l){
		 if(s[i-1]==r[j-1]){
		 re+=s[i-1];
         l--;
		 i--,j--;
		 }
		 else{
          if(dp[i-1][j]>dp[i][j-1])
		     i--;
			 else
          j--;
		 }
	 }
	 reverse(re.begin(),re.end());
	 cout<<re;
	return 0;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> g(h, vector<char>(w));
  vector<vector<int>> d(h, vector<int>(w, -1));
  queue<pair<int, int>> Q;
  for (int i = 0; i < h; i ++) {
    for (int j = 0; j < w; j ++) {
      cin >> g[i][j];
      if (g[i][j] == '#') {
        d[i][j] = 0;
        Q.push(make_pair(i, j));
      }
    }
  }

  int ans = 0;
  int dx[4] = {1, -1, 0, 0};
  int dy[4] = {0, 0, 1, -1};
  pair<int, int> p;
  while (!Q.empty()) {
    p = Q.front(); Q.pop();
    int x = p.first;
    int y = p.second;
    ans = d[x][y];
    for (int i = 0; i < 4; i ++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx >= 0 && nx < h && ny >= 0 && ny < w && d[nx][ny] == -1) {
        d[nx][ny] = d[x][y] + 1;
        Q.push(make_pair(nx, ny));
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 13456
#include<iostream>
using namespace std;
int main()
{

    long long int n,flag=0,inp;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>inp;
        if(inp%2==0)
        {
            if(!(inp%3==0||inp%5==0))
            {
                flag=1;
            }
        }
    }
    if(flag==1)
        cout<<"DENIED";
    else
        cout<<"APPROVED";
    return 0;
}


Measured memory_bytes: 256
N,M=[int(s) for s in input().split()]
dic={}
ls=[int(s) for s in input().split()]
for i in range(N):
  if(ls[i] in dic):
    dic[ls[i]]+=1
  else:
    dic[ls[i]]=1
for i in range(M):
  a,b=[int(s) for s in input().split()]
  if(b in dic):
    dic[b]+=a
  else:
    dic[b]=a
x=list(dic)
x=sorted(x, key=lambda e : -e)
count=0
ans=0
for i in x:
  count+=dic[i]
  ans+=i*dic[i]
  if count>=N:
    ans-=i*(count-N)
    break
print(ans)

Measured memory_bytes: 38304
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int number_read=0,if_ok_read=1;
	char ch_read=getchar();
	while(ch_read<'0'||ch_read>'9')
	{
		if(ch_read=='-')
			if_ok_read=-1;
		ch_read=getchar();
	}
	while(ch_read>='0'&&ch_read<='9')
	{
		number_read=number_read*10+ch_read-'0';
		ch_read=getchar();
	}
	return number_read*if_ok_read;
}
inline void write(int x_write)
{
    if(x_write<0)
	{
    	putchar('-');
		x_write=-x_write;
	}
    if(x_write>9)
		write(x_write/10);
    putchar(x_write%10+'0');
    return ;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	string s;
    cin>>s;
    printf("%s",((s[0]==s[s.length()-1])^(s.length()%2))?"First":"Second");
	putchar('\n');
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
	int n;
	int flag=1;
	int breakflag=0;
	char s[110][11];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s",s[i]);
	}
	for(int i=0;i<n-1;i++){
		if(s[i][strlen(s[i])-1]!=s[i+1][0]){
			flag=0;
			break;
		}
	}
	if(flag==1){
		for(int i=0;i<n;i++){
			for(int a=0;a<i;a++){
				if(strcmp(s[i],s[a])==0){
					flag=0;
					breakflag=1;
					break;
				}
			}
			if(breakflag==1){
				break;
			}
		}
	}
	if(flag==0){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[][] lists = new String[h][w];
		for(int i=0;i<h;i++) {
			String[] list = new String[w];
			String line = sc.next();
			for(int y=0;y<line.length();y++) {
				list[y] = String.valueOf(line.charAt(y));
			}
			lists[i] = list;
		}
		sc.close();
		boolean isNo = false;
		for(int i=0;i<h;i++) {
			for(int y=0;y<w;y++) {
				if(lists[i][y].equals("#")) {
					isNo = Main.isNo(lists, i, y);
				}
				if(isNo) break;
			}
			if(isNo) break;
		}
		System.out.println((isNo)?"No":"Yes");
	}

	private static boolean isNo(String[][] lists,int i,int y) {
		int targetW = y-1;
		int targetY = i-1;
		if(targetW>=0 ) {
			if(lists[i][targetW].equals("#")) {
				return false;
			}
		}
		targetW = y+1;
		if(targetW<lists[i].length) {
			if(lists[i][targetW].equals("#")) {
				return false;
			}
		}
		if(targetY>=0) {
			if(lists[targetY][y].equals("#")) {
				return false;
			}
		}
		targetY = i+1;
		if(targetY<lists.length) {
			if(lists[targetY][y].equals("#")) {
				return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define fs first
#define sc second
#define pb push_back
#define sz size() 
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
 
const static int INF = 1e8;
const static D EPS = 1e-8;
 
int main(){
  int n;
  cin >> n;
  int cnt = 0;
  bool ok = true;
 
  rep(i,n){
    string s; cin >> s;
    if(s == "A"){
      cnt++;
    }else{
      cnt--;
      if(cnt<0) ok = false;
    }
  }
  if(cnt) ok = false;
 
  cout << (ok ? "YES" : "NO") << endl;
}

Measured memory_bytes: 3156
// VSCF.cpp : Defines the entry point for the console application.
//
#include <cassert>
#include <functional>
#include <cmath>
#include <list>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <set>
#include <deque>
#include <map>
#include <iomanip>
#include <sstream>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define FOR(v,p,k) for(int v=p;v<=k;++v)
#define FORD(v,p,k) for(int v=p;v>=k;--v)
#define REP(i,n) for(int i=0;i<(n);++i)
#define VAR(v,i) __typeof(i) v=(i)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define PB push_back
#define ST first
#define ND second
#define SIZE(x) (int)x.size()
#define ALL(c) c.begin(),c.end()
#define int long long
#define MAXN 1000010
typedef long double LD;

#undef int
int main() {
#define int long long
	string s;
	cin >> s;
	int idx = s.find("C");
	if (idx == string::npos) {
		cout << "No";
		return 0;
	}
	s = s.substr(idx);
	if (s.find("F") == string::npos) {
		cout << "No";
		return 0;
	}
	cout << "Yes";
	return 0;
	return 0;
}



Measured memory_bytes: 256
package main

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

// A - ABC Swap
// https://atcoder.jp/contests/abc161/tasks/abc161_a

func main() {
	scanner := NewBufScanner(os.Stdin)
	x,y,z :=  scanner.Int(), scanner.Int(), scanner.Int()
	B := x
	A := z
	C := y
	fmt.Println(A,B,C)
}

type BufScanner struct {
	*bufio.Scanner
}

func NewBufScanner(r io.Reader) *BufScanner {
	s := bufio.NewScanner(r)
	//s.Split(bufio.ScanWords)
	s.Split(scanWords)
	return &BufScanner{s}
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	start := 0
	for isSpace(data[start]) {
		start++
	}
	for i := start; i < len(data); i++ {
		if isSpace(data[i]) {
			return i+1, data[start:i], nil
		}
	}
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	return start, nil, nil
}
func isSpace(b byte) bool {
	return b == ' ' || b == '\n' || b == '\r' || b == '\t'
}

func (s *BufScanner) Int() int {
	return int(s.UInt())
}

func (s *BufScanner) UInt() uint64 {
	s.Scan()
	i, e := strconv.ParseUint(s.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}



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

int main() {
	ll N, W;
	cin >> N >> W;

	ll V = N*1000;
	vector<ll> dp(V+1, INT_MAX);
	dp[0] = 0;
	
	for (int i = 0; i < N; ++i) {
		ll wi, vi;
		cin >> wi >> vi;
		for (ll v = V-vi; v >= 0; --v) {
			dp[v+vi] = min(dp[v+vi], dp[v] + wi);
		}
	}

	ll best = 0;
	for (ll v = 0; v <= V; ++v) {
		if (dp[v] <= W)
			best = max(best, v);
	}
	
	cout << best << endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

class item {
public:
  i64 weight;
  i64 value;
};

namespace std {
  std::istream& operator>>(std::istream& is, item& self) {
    return is >> self.weight >> self.value;
  }
}

int main() {
  i64 N, W;
  std::cin >> N >> W;
  std::vector<item> items;
  tools::read(items, N);

  std::vector<std::vector<i64>> dp(N + 1, std::vector<i64>(W + 1, -1));
  dp[0][0] = 0;
  for (i64 i = 0; i < N; ++i) {
    const item& item = items[i];
    for (i64 w = 0; w <= W; ++w) {
      if (dp[i][w] >= 0) {
        dp[i + 1][w] = std::max(dp[i + 1][w], dp[i][w]);
        if (w + item.weight <= W) {
          dp[i + 1][w + item.weight] = std::max(dp[i + 1][w + item.weight], dp[i][w] + item.value);
        }
      }
    }
  }

  std::cout << *std::max_element(dp.back().begin(), dp.back().end()) << std::endl;
  return 0;
}

Measured memory_bytes: 80256
# シミュレーションぽい？iとi+1をみて増加か減少か判断して変わったら終了
n = int(input())
arr = list(map(int, input().split()))
ans = 1
state = 0  # 1..増加 -1..減少 0..未確定 みたいな
for i in range(n - 1):
    if state == 0:
        if arr[i] > arr[i + 1]:
            state = -1
        elif arr[i] < arr[i + 1]:
            state = 1
    elif state == 1:
        if arr[i] < arr[i + 1]:
            continue
        elif arr[i] > arr[i + 1]:
            # リセット
            state = 0
            ans += 1
        else:
            continue
    elif state == -1:
        if arr[i] > arr[i + 1]:
            continue
        elif arr[i] < arr[i + 1]:
            # リセット
            state = 0
            ans += 1
        else:
            continue

print(ans)


Measured memory_bytes: 14436
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <list>
#include <unordered_map>
#include <string>
using namespace std;
#define ll long long
#define pb push_back
using vi = vector<int>;
using vvi = vector<vector<int>>;

constexpr int maxW = 1e5 + 13;
constexpr int N = 110;

long long knapsack[maxW][N];

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


	for (int i = 0; i < n; i++) {
		long long weight, val;
		cin >> weight >> val; 
		knapsack[weight][i] = val;
		if (i > 0) {
			for (int prevWeight = 0; prevWeight <= maxWeight; prevWeight++) {
				if (knapsack[prevWeight][i-1]) {
					knapsack[prevWeight][i] = max(knapsack[prevWeight][i], knapsack[prevWeight][i-1]);

					int totalWeight = prevWeight + weight;
					if (totalWeight <= maxWeight) {
						knapsack[totalWeight][i] = val + knapsack[prevWeight][i-1];
					} 
				}
			}
		}
	}

	long long maxVal = 0;
	for (int i = 0; i <= maxWeight; i++) {
		maxVal = max(maxVal, knapsack[i][n-1]);
	}

	cout << maxVal << endl;
	return 0;
}


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

namespace prime{
	const int mx = 10000001;
	bool f[mx];
	int p[777777],lp;
	void init(){
		for(int i=2; i<mx; i++){
			if(!f[i])p[lp++]=i;
			for(int j=0; j<lp; j++){
				int w = p[j] * i;
				if(w >= mx)break;
				f[w] = true;
				if(i%p[j]==0)break;
			}
		}
	}
	bool isprime(int x){
		if(x<2)return false;
		return !f[x];
	}
};

bool g[10000002];

int lk[333];
bool b[333];
int A[333],B[333],LA,LB;
bool fd(int x){
	for(int j=0; j<LB; j++)
		if(!b[j] && prime::isprime(labs(A[x]-B[j]))){
			b[j] = true;
			if(lk[j] == -1 || fd(lk[j])){
				lk[j] = x;
				return true;
			}
		}
	return false;
}
int main(){
	prime::init();
	int x,z;
	for(scanf("%d",&x); x--;){
		scanf("%d",&z);
		g[z] = true;
	}
	for(int i=0; i<=z; i++)if(g[i] != g[i+1]){
		if(i%2==0)A[LA++] = i;else
			B[LB++] = i;
	}
	memset(lk,-1,sizeof(lk));
	int R = 0;
	for(int i=0; i<LA; i++){
		memset(b,0,sizeof(b));
		if(fd(i))R++;
	}
	LA -= R;
	LB -= R;
	if(LA % 2 == 1)R += 3;
	R += LA / 2 * 2 + LB / 2 * 2;
	printf("%d\n",R);
	return 0;
}


Measured memory_bytes: 20864
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int a,b;cin>>a>>b;
  if(a<=8 && b<=8){
    P("Yay!");
  }else{
    P(":(");
  }
  return 0;
}


Measured memory_bytes: 256
/*
~Like a small boat
~On the ocean
~Sending big waves
~Into motion
!Like how a single word
!Can make a heart open
!I might only have one match
!But I can make an explosion
#And all those things I didn't say
#Wrecking balls inside my brain
#I will scream them loud tonight
#Can you hear my voice this time?
@This is my fight song
@Take back my life song
@Prove I'm alright song
@My power's turned on
$Starting right now I'll be strong
$I'll play my fight song
$And I don't really care if nobody else believes
$'Cause I've still got a lot of fight left in me!!!
*/

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

typedef long long int ll;
const int N = 1e5+5,mod = 1e9+7;

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

    ll n,x;cin>>n>>x;
    ll Res = n;
    ll a = x,b = n-x;
    swap(a,b);
    while(b!=0)
    {
        Res += 2*(a-a%b);
        a %= b;
        swap(a,b);
    }
    Res -= a;
    cout<<Res<< "\n";



    return 0;
}


Measured memory_bytes: 256
N, *AS = $stdin.read.split.map(&:to_i)
=begin
2 3 1
- 1番が来たとき2人
  2番が来たとき3人
  3番が来たとき1人
=end
puts AS.map.with_index(1){|a, idx| [a, idx]}
       .sort_by{|a, idx| a}
       .map{|a, idx| idx}
       .join(" ")

Measured memory_bytes: 20688
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;

const int MAX_N = 500005;

int n, q;
int c[MAX_N];
int posOfLast[MAX_N];
vector<pair<int, int>> reqByR[MAX_N];
int t[4 * MAX_N];
int result[MAX_N];

void change(int i, int l, int r, int pos, int val)
{
	if (l == r)
		t[i] += val;
	else
	{
		int mid = (l + r) / 2;
		if (pos <= mid)
			change(2 * i + 1, l, mid, pos, val);
		else
			change(2 * i + 2, mid + 1, r, pos, val);
		t[i] = t[2 * i + 1] + t[2 * i + 2];
	}
}

int rmq(int i, int l, int r, int lx, int rx)
{
	if (l == lx && r == rx)
		return t[i];
	else
	{
		int mid = (l + r) / 2;
		int result = 0;
		if (lx <= mid)
			result = rmq(2 * i + 1, l, mid, lx, min(rx, mid));
		if (rx > mid)
			result += rmq(2 * i + 2, mid + 1, r, max(lx, mid + 1), rx);
		return result;
	}
}

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

	cin >> n >> q;
	for (int i = 0; i < n; i++)
	{
		cin >> c[i];
		c[i]--;
	}

	for (int i = 0; i < q; i++)
	{
		int l, r;
		cin >> l >> r;
		l--; r--;
		reqByR[r].emplace_back(l, i);
	}
	
	for (int i = 0; i < MAX_N; i++)
		posOfLast[i] = -1;
	for (int i = 0; i < n; i++)
	{
		if (posOfLast[c[i]] != -1)
			change(0, 0, n - 1, posOfLast[c[i]], -1);
		posOfLast[c[i]] = i;
		change(0, 0, n - 1, posOfLast[c[i]], 1);

		for (const auto& pr : reqByR[i])
			result[pr.second] = rmq(0, 0, n - 1, pr.first, i);
	}

	for (int i = 0; i < q; i++)
		cout << result[i] << '\n';

	return 0;
}

Measured memory_bytes: 35340
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]
ans = float("inf")
for bit in range(1 << d):
    count = 0
    sum = 0
    nokori = set(range(1, d + 1))
    for i in range(d):
        if bit & (1 << i):
            sum += pc[i][0] * (i + 1) * 100 + pc[i][1]
            count += pc[i][0]
            nokori.discard(i + 1)
    if sum < g:
        use = max(nokori)
        n = min(pc[use - 1][0], -(-(g - sum) // (use * 100)))
        count += n
        sum += n * use * 100
    if sum >= g:
        ans = min(ans, count)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define f first
#define s second
#define pl pair < long long , long long >
#define ll long long

using namespace std;

const long long MOD = 2e19 ;
const long long BIG = 1e7 + 9 ;
int gcd(int a, int b)

{

    if (a == 0)

        return b;

    return gcd(b % a, a);

}
int main()
{
    int k ;
    cin >> k ;
    int ans = 0 ;
    for ( int i = 1 ; i <= k ; i++ )
        for ( int j = 1 ; j <= k ; j++ )
            for ( int n = 1 ; n <= k ; n++ )
                ans += gcd( gcd( i , j ) , n ) ;
    cout << ans ;
    return 0 ;


}


Measured memory_bytes: 3652
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rept(i,s,n) for (int i = (s); i < (n); ++i)

#include <iostream>
#include <cmath>
#include <bitset>
#include <algorithm>
using namespace std;

int main() {

  long a,b,c,k, result=0;
  cin >> a>>b>>c>>k;

  if(k>0){
    if(k>=a){
      result += a;
      k-=a;
    } else{
      result += k;
      k = 0;
    }
  }

    if(k>0){
      if(k>=b){
        k-=b;
      } else{
        k = 0;
      }
    }

    if(k>0){
      if(k>=c){
        result -= c;
        k-=c;
      } else{
        result -= k;
        k = 0;
      }
    }



    cout << result << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()



int main(void){
	ll A,B;
    cin >> A >> B;
    ll K;
    if((A+B)%2 == 0){
        K = (A+B)/2;
        cout << K << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
    
    return 0;
}


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

int main() {
    
    int n,m;
    vector <int> H,A,B,ans;
    int count = 0;
    
    cin >> n >> m;
    
    H.assign(n+1,0);
    ans.assign(n+1,1);
    A.assign(m+1,0);
    B.assign(m+1,0);
    
    for (int i = 1; i <= n ; i++){
        cin >> H.at(i);
    }
    
    for (int i = 1; i <= m ; i++){
        cin >> A.at(i);
        cin >> B.at(i);
        
        if(H.at(A.at(i)) >= H.at(B.at(i))){
            ans.at(B.at(i)) = 0;
        }
        if(H.at(A.at(i)) <= H.at(B.at(i))){
            ans.at(A.at(i)) = 0;
        }
        
    }
    
    for (int i = 1; i <= n ; i++){
        count += ans.at(i);
    }
    
    cout << count << endl;
}


Measured memory_bytes: 4820
#include<stdio.h>

int main(void)
{
    int x, h, m, s;
	
	scanf("%d", &x);
	
	h = x/60/60;
	m = (x-(h*60*60))/60;
	s = x-(m*60)-(h*60*60);
	
	printf("%d:%d:%d\n", h, m, s);
	
	return 0;
    
    
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    ll tmp = 1;
    while(tmp < N) tmp *= 2;
    if(tmp == N){
    	cout << "No" << endl;
    	return 0;
    }else{
    	cout << "Yes" << endl;
     	ll M = (N-1)/2;
    	REP(i, M){
    		cout << 1 << " " << 2*(i+1) << endl;
    		cout << 1 << " " << 2*(i+1)+1 << endl;
    		cout << 2*(i+1)+1+N << " " << 2*(i+1) << endl;
    		cout << 2*(i+1)+N << " " << 2*(i+1)+1 << endl;
    	}
    	cout << N+3 << " " << N+1 << endl;
    	if(N%2 == 0){
    		ll idx = 1;
    		while(((N+1>>idx) & 1) == 0) idx++;
    		ll p = 1ll << idx;
    		ll q = N+1 - p;
    		cout << p << " " << N+N << endl;
    		cout << q << " " << N <<endl;
    	}
    }

    return 0;
}

Measured memory_bytes: 2304
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int a,b;
int main()
{
	scanf("%d%d",&a,&b);
	if (a<=b) printf("%d",a);
	    else printf("%d",a-1);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    
    vector<ll> f(N+1);
    for(ll x = 1; x <= N; x++){
        for(int m = 1; x*m <= N; m++){
            f[x*m]++;
        }
        
        res += x*f[x];
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

using namespace std;

int main(){
  int n;
  string s, t;
  std::cin >> n >> s >> t;
  for(int i=0; i<n; i++){
    std::cout << s[i] << t[i];
  }
  std::cout << '\n';
  return 0;
}


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

#define pb push_back
#define INF 1e9
#define mod 998244353
#define mod2 1000000007
#define dbg(x) cout << (#x) << " --> " << x << "\n";
#define dbgarr(y)                                                                                            \
  cout << (#y) << " --> " << '\n';                                                                           \
  for(auto& x : y) cout << x << '\n';
using namespace std;

typedef priority_queue<int, vector<int>, greater<int>> minPq;
typedef priority_queue<int> maxPq;
typedef long long ll;

void goodLuckHaveFun() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
/* clang-format off */
  #ifdef _DEBUG
  freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
  #endif
  /* clang-format on */
}

vector<int> adList[100001];

int maxEl[100001];
int vis[100001];

int dfs(int n) {
  int maxTemp = 0;
  for(auto x : adList[n]) {
    if(vis[x]) {
      maxTemp = max(maxTemp, maxEl[x] + 1);
      continue;
    }
    maxTemp = max(maxTemp, dfs(x)+1);
  }
  maxEl[n] = maxTemp;
  vis[n]   = 1;
  return maxTemp;
}

int main() {
  goodLuckHaveFun();
  int n, m;
  cin >> n >> m;
  pair<int, int> p;

  for(int i = 0; i < m; ++i) {
    cin >> p.first >> p.second;
    adList[p.first].pb(p.second);
  }

  for(int i = 1; i <= n; ++i) {
    dfs(i);
  }

  cout << *max_element(maxEl, maxEl + 100001) << '\n';
}

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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        string s = sc.Next();

        string answer = s.First().ToString() + (s.Length - 2) + s.Last().ToString();

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<long long>v(n + 3);
    for(int i = 1; i <= n; i++){
        cin >> v[i];
    }
    if(n % 2 == 0){
        long long dp[n + 3][2];
        dp[1][0] = v[1];
        for(int i = 3; i <= n; i += 2){
            dp[i][0] = dp[i - 2][0] + v[i];
        }
        dp[2][1] = v[2];
        for(int i = 4; i <= n; i += 2){
            dp[i][1] = max(dp[i - 2][1], dp[i - 3][0]) + v[i];
        }
        cout << max(dp[n][1], dp[n - 1][0]);
    }
    else{
        long long dp[n + 3][3];
        dp[1][0] = v[1];
        for(int i = 3; i <= n; i = i + 2){
            dp[i][0] = dp[i - 2][0] + v[i];
        }
        dp[2][1] = v[2];
        for(int i = 4; i <= n; i = i + 2){
            dp[i][1] = max(dp[i - 2][1], dp[i - 3][0]) + v[i];
        }
        dp[3][2] = v[3];
        for(int i = 5; i <= n; i = i + 2){
            long long val = max(dp[i - 2][2], dp[i - 3][1]);
            dp[i][2] = max(val, dp[i - 4][0]) + v[i];
        }
        long long ans = max(dp[n - 2][0], dp[n - 1][1]);
        ans = max(ans, dp[n][2]);
        cout << ans;
    }
    return 0;
}

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

int main() {
	char f, g, h;
	string Ans;

	cin >> f >> g >> h;

		if (f=='a' && g=='b' && h=='c')
			Ans = "Yes";
		else if (f == 'a' && g == 'c' && h == 'b')
			Ans = "Yes";
		else if (f == 'b' && g == 'a' && h == 'c')
			Ans = "Yes";
		else if (f == 'b' && g == 'c' && h == 'a')
			Ans = "Yes";
		else if (f == 'c' && g == 'a' && h == 'b')
			Ans = "Yes";
		else if (f == 'c' && g == 'b' && h == 'a')
			Ans = "Yes";
	    else
			Ans = "No";

	cout << Ans;

 return 0;
}


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

using namespace std;

int		main(void)
{
	int N;

	cin >> N;
	vector<int> W(N);
	int S1 = 0, S2 = 0;
	
	for (int i = 0; i < N; i++)
	{
		int w;

		cin >> w;
		W[i] = w;
		S2 += w;
	}
	int dif = 1e9;

	for (int i = 0; i < N; i++)
	{
		S2 -= W[i];
		S1 += W[i];
		if (abs(S1 - S2) < dif)
			dif = abs(S1 - S2);
	}
	cout << dif << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define r(i,a,n) for(int i=a;i<n;i++)
int main(){
	int a,b,c;
	string s;
	cin>>a>>b;
	if(a==1)a=14;
	if(b==1)b=14;
	if(a==b)cout<<"Draw"<<endl;
	else if(a>b)cout<<"Alice"<<endl;
	else cout<<"Bob"<<endl;
}

Measured memory_bytes: 764
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
#include <complex>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
static const double EPS = 1e-10;

int stage[101][101];
int dp[101][101];

P move(int x,int y){
  if(stage[y][x] == 0){
    return P(x,y);
  }

  else if(stage[y][x] == 1
	  && stage[y][x+1] == 1){
    return move(x+1,y);
  }
  else if(stage[y][x] == 1
	  && stage[y][x+1] != 1){
    return P(x,y);
  }
  else if(stage[y][x] == 2){
    return move(x-1,y);
  }

  else{
    return P(-1,-1);
  }
}

void dfs(int sx,int sy,int cost,int n){
  for(int tx=0; tx <= 2; tx++){
    int dx = sx + tx;
    int dy = (sy + 1) % 2;

    if(dx < 0 || dx >= n || dy < 0 || dy >= 2) continue;

    P p = move(dx,dy);

    if(p.first < 0 || p.first >= n) continue;
    if(p.second < 0 || p.second >= 2) continue;
    if(dp[p.first][p.second] <= cost + 1){
      continue;
    }
    dp[p.first][p.second] = cost + 1;
    dfs(p.first,p.second,cost + 1,n);
  }
}

int main(){
  int n;
  while(~scanf("%d",&n)){
    if(n == 0) break;

    memset(dp,0x3f,sizeof(dp));
    memset(stage,0,sizeof(stage));
    for(int y=0;y<2;y++){
      for(int x=0;x<n;x++){
	scanf("%d",&stage[y][x]);
      }
    }

    P init_lhs = move(0,0);
    P init_rhs = move(0,1);
    dp[init_lhs.first][init_lhs.second] = 0;
    dp[init_rhs.first][init_rhs.second] = 0;

    dfs(init_lhs.first,init_lhs.second,0,n);
    dfs(init_rhs.first,init_rhs.second,0,n);

    if((dp[n-1][0] != INF) || (dp[n-1][1] != INF)){
      printf("%d\n",min(dp[n-1][0],dp[n-1][1]));
    }
    else{
      printf("NA\n");
    }
  }
}

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

using namespace std;
typedef uint64_t u64;
typedef int64_t i64;
typedef double db;

int main() {
  i64 N, X, Y;
  cin >> N >> X >> Y;
  
  vector<i64> k_arr(N + 1);
  for (i64 i = 1; i <= N-1; i++) {
    for (i64 j = i+1; j <= N; j++) {
      i64 l = INT64_MAX;
      l = min(l, abs(i - j));
      l = min(l, abs(i - X) + 1 + abs(Y - j));
      l = min(l, abs(i - Y) + 1 + abs(X - j));
      k_arr[l]++;
    }
  }
  for (int i = 1; i <= N-1; i++) {
    cout << k_arr[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

struct edge{
  ll from,to,cost;
};

ll inf=1e18;
ll n,m;//頂点数, 辺数
edge es[2010];
vector<ll> d(1010,0);
vector<ll> d2(1010,inf);
bool negative[1010];

//負の閉路検出
void find_negative_loop(){
	//memset(D,0,sizeof(D));
	for(int i=1;i<=n;i++) negative[i] = false;
	for(int i=1;i<=n;i++){
		for(int j=0;j<m;j++){
			edge e = es[j];
			if(d2[e.to]!=inf && d2[e.to] > d2[e.from] + e.cost){
				d2[e.to] = d2[e.from] + e.cost;
				negative[e.to] = true;
			}
			if(negative[e.from]) negative[e.to] = true;
		}
	}
}

void shortest_path(ll s){
  d2[s]=0;
  rep(j,n-1){
    //bool update=false;
    rep(i,m){
      edge e=es[i];
      if(d2[e.from]!=inf && d2[e.to]>d2[e.from]+e.cost){
        d2[e.to]=d2[e.from]+e.cost;
        //update=true;
      }
    }
    //if(!update) break;
  }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>m;
    rep(i,m){
      ll a,b,c;
      cin>>a>>b>>c;
      es[i]={a,b,-c};
    }
    shortest_path(1);
    find_negative_loop();
    if(negative[n]){
      cout<<"inf"<<endl;
    }else{
    //shortest_path(1);
    ll ans=-d2[n];
    cout<<ans<<endl;
    }
}

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

int main() {
  int n = 0;
  cin >> n;
  if (n % 10 == n / 10 % 10 && n % 10 == n / 100 % 10)
    cout << "Yes" << endl;
  else if (n /10 % 10 == n / 100 % 10 && n / 10 % 10 == n / 1000 % 10)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#define INF 9999999
using namespace std;

int W;
int R[12];
int N;
double D[13][12];
double dp[(1 << 12)][13];

void calcCost() {
  for(int u = 0; u <= N; ++u) {
    for(int v = 0; v < N; ++v) {
      if(u == v) D[u][v] = 0;
      else if(u == N || R[u] == R[v]) D[u][v] = R[v] * 2;
      else {
	double d = sqrt((R[u]+R[v])*(R[u]+R[v]) - (R[u]-R[v])*(R[u]-R[v]));
	D[u][v] = d - R[u] + R[v];
      }
    }
  }
}

void solve() {
  calcCost();
  for(int s = 0; s < (1 << N); ++s) {
    if(s == (1 << N) - 1) fill(dp[s], dp[s] + N+1, 0);
    else                  fill(dp[s], dp[s] + N+1, INF);
  }

  for(int s = (1 << N)-2; s >= 0; --s) {
    for(int u = 0; u <= N; ++u) {
      for(int v = 0; v < N; ++v) {
	dp[s][u] = min(dp[s][u], dp[s | (1 << v)][v] + D[u][v]);
      }
    }
  }
  if(dp[0][N] <= W) cout << "OK" << endl;
  else              cout << "NA" << endl;
}

main() {
  string str;
  while(getline(cin, str) && !cin.eof()) {
    stringstream ss; ss << str;
    ss >> W;
    N = 0;
    while(!ss.eof()) {
      int tmp;
      ss >> tmp;
      R[N++] = tmp;
    }
    solve();
  }
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;


void no() {
	print(0); exit(0);
}
void solve() {
	int N; cin >> N;
	map<int, int>mp;
	vector<int>A(N);
	REP(i, N)cin >> A[i];
	REP(i, N) {
		mp[A[i]]++;
	}
	if (N & 1) {
		ll ans = 1;
		if (mp[0] != 1)no();
		for (int i = 2; i < N; i += 2) {
			if (mp[i] != 2)no();
			ans *= 2;
			ans %= MOD;
		}
		print(ans);
	}
	else {
		ll ans = 1;
		for (int i = 1; i < N; i += 2) {
			if (mp[i] != 2)no();
			ans *= 2;
			ans %= MOD;
		}
		print(ans);
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}


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

using namespace std;

const long long MOD = 1e9+7;
int main() {
    ios_base::sync_with_stdio(false);
    cout.precision(12);
    cout << fixed;
    cin.tie(0);

    long long a, b, c, k;
    cin >> a >> b >> c >> k;
    while (b <= a) {
        b *= 2;
        k--;
    }
    while (c <= b) {
        c *= 2;
        k--;
    }
    cout << (k >= 0 ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 3648
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N = sc.nextInt
  val numbers = Array.tabulate(N)(_ => sc.nextInt)
  val numbersSorted = numbers.sorted.reverse
  val highest = numbersSorted(0)
  val secondHighest = numbersSorted(1)

  for(i <- 0 until N) {
    if (numbers(i) == highest) println(secondHighest)
    else println(highest)
  }
}

Measured memory_bytes: 97568
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define maxn 200001
#define f(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rf(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);i--)
#define pb(x) push_back((ll)(x))
#define pf(x) push_front((ll)(x))
#define nl cout << "\n";
 
//void ini(){
//	#ifndef ONLINE_JUDGE
//		freopen("input.txt","r",stdin);
//		freopen("output.txt","w",stdout);
//	#endif
//}

ll a[100001],b[100001],c[100001],dp[100001][3];

void memo(ll n){
	dp[0][0]=dp[0][1]=dp[0][2]=0;
	f(i,1,n+1){
		dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
	}
}

int main(){
	//ini();
	
	ll n;
	cin >>n;
	f(i,1,n+1){
		cin >> a[i] >> b[i] >> c[i];
	}

	memo(n);

	cout << max(dp[n][0],max(dp[n][1],dp[n][2]));
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  REP(i, n) cin >> p[i];
  bool ok = true;
  REP(i, n) {
    if (p[i] != i + 1) ok = false;
  }
  if (ok) {
    cout << "YES" << endl;
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      swap(p[i], p[j]);
      ok = true;
      REP(i, n) {
        if (p[i] != i + 1) ok = false;
      }
      if (ok) {
        cout << "YES" << endl;
        return 0;
      }
      swap(p[i], p[j]);
    }
  }
  cout << "NO" << endl;
  return 0;
}


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int a1 = max(a, max(b, c)), c1 = min(a, min(b, c)), b1 = a+b+c-a1-c1;
	int ans = (a1 - c1) / 2 + (a1 - b1) / 2;
	if ((a1-c1)%2 && (a1-b1)%2) ans ++;
	else if ((a1-c1)%2 || (a1-b1)%2) ans += 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int N,S;
  cin >> N >> S;
  int x = -1, y = -1, z = -1;
  for(int i = 0; i < N+1;i++){
    for(int j = 0; j < N+1;j++){
      if(N-(i+j) >= 0 & S == ( 10000*i + 5000*j + 1000*(N-(i+j)) )){
        x = i;
        y = j;
        z = N - (i+j);
        break;
      }
    }
  }
  cout << x << " " << y << " " << z;
}

Measured memory_bytes: 3468