akhauriyash/Code-Regression huggingface dataset:
use std::io::{self, BufRead};

fn gcd(x: usize, y: usize) -> usize {
  let (mut a, mut b) = if x < y {
    (y, x)
  } else {
    (x, y)
  };
  while b != 0 {
    let r = a % b;
    a = b;
    b = r;
  }
  a
}

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let xs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let (n, k, s) = (xs[0], xs[1], xs[2]);
  let mut t = 2;
  while gcd(s, t) != 1 {
    t += 1;
  }
  for i in 0..k {
    if i > 0 {
      print!(" ");
    }
    print!("{}", s);
  }
  for i in 0..(n-k) {
    if k > 0 || i > 0 {
      print!(" ");
    }
    print!("{}", t);
  }
  println!();
}

Measured memory_bytes: 5372
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdlib.h>
int asc(const void* a, const void* b) { return *(int*)a - *(int*)b; }
int desc(const void* a, const void* b) { return *(int*)b - *(int*)a; }

//qsort(data,10,sizeof(int),compare_int);

int main(void)
{
	int a, b;
	int sum = 1;
	int i = 0;

	scanf("%d %d", &a, &b);
	while (sum < b) {
		i++;
		sum--;
		sum += a;
	}
	printf("%d\n", i);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define setbits(x)          __builtin_popcountll(x)
#define lp(a,n) for(ll i=a; i<n; i++)
#define lpi(a,n) for(int i=a; i<n; i++)
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int> 
#define vll vector<ll>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define inf 1e9
#define mod 1e9 + 7
using namespace std;
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a,b);
}
void FIO(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("inputPrayag.txt", "r", stdin);
    freopen("outputPrayag.txt", "w", stdout);
    #endif
}
ll power(ll x, ll y) 
{ 
    ll res = 1;     
    while (y > 0) 
    { 
        if (y & 1) 
            res = res*x; 
   
        y = y>>1;
        x = x*x;  
    } 
    return res; 
}

int main(){
 FIO();
   int n;
   cin>>n;
   string s;
   cin>>s;
   if(s.length()<=n){
   	cout<<s<<endl;
   }else {
   	cout<<s.substr(0,n)<<"..."<<endl;
   }
}


Measured memory_bytes: 3656
// Why am I so dumb? :c
#include<bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

ll cur, b, c, d;

void solve() {
    scanf("%lld %lld %lld %lld", &cur, &b, &c, &d);

    if (d < b) {
        printf("No\n");
        return;
    }

    {
        ll k = max(1ll, (cur - c + b - 1) / b);
        cur -= k * b;
    }

    if (cur < 0) {
        printf("No\n");
        return;
    }

    if (d == b) {
        printf("Yes\n");
        return;
    }

    // Now we have d > b

    if (b <= c + 1) {
        printf("Yes\n");
        return;
    }

    // Now we have b > c + 1

    ll g = __gcd(b, d);
    ll L = cur - (b - 1), R = cur - (c + 1);
    ll tmp = max(0ll, (-R + g - 1) / g);

    R += tmp * g;
    L += tmp * g;
    R = (R / g) * g;
    L -= tmp * g;
    R -= tmp * g;

    if (R >= L) {
        printf("No\n");
    }
    else {
        printf("Yes\n");
    }
}

int main() {
    int tt;
    scanf("%d", &tt);

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int N;
	string S;

	cin >> N >> S;

	string sub = S.substr(0, N / 2);

	sub += sub;

	yn(S == sub);

	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define PI 3.1415926535

int main(void)
{
   ll q, h, s, d, n;
   cin >> q >> h >> s >> d >> n;

   //全て4倍
   n *= 4;
   ll DP[9] = {};
   DP[0] = 0;
   DP[1] = q;

   for (int i = 2; i <= 8; i++){
      if (i < 4){
         DP[i] = min(DP[i - 1] + q, DP[i - 2] + h);
         continue;
      }
      if (i < 8)
      {
         DP[i] = min(DP[i - 1] + q, DP[i - 2] + h);
         DP[i] = min(DP[i], DP[i - 4] + s);
         continue;
      }
      DP[i] = min(DP[i - 1] + q, DP[i - 2] + h);
      DP[i] = min(DP[i], DP[i - 4] + s);
      DP[i] = min(DP[i], DP[i - 8] + d);
   }
   ll ans = DP[8] * (n / 8) + DP[n % 8];

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


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

#define INF (INT_MAX/2-1)
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

int main(){
  int N;
  cin>>N;
  vector<ll>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  int p=0;
  for(int i=0;i<N;i++){
    if(A[i]<0)p++;
  }

  ll ans=0;
  for(int i=0;i<N;i++){
    ans+=abs(A[i]);
  }

  if(p%2==0){
    cout<<ans<<endl;
    return 0;
  }
  else{
    ll Min = 10000000000;
    for(int i=0;i<N;i++){
      ll ABS;
      Min=min(Min,abs(A[i]));
    }
    ans-=2*Min;
    cout<<ans<<endl;
    return 0;
  }
  return 0;
}



Measured memory_bytes: 1024
x = []
y = []
while(True):
    a,b = map(int,input().split())
    if(a==0 and b==0):
        break
    x.append(a)
    y.append(b)
for i in range(len(x)):
    if(x[i] > y[i]):
        print(str(y[i])+" "+str(x[i]))
    else:
        print(str(x[i]) + " " + str(y[i]))


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

const long double PI = (acos(-1));

int main(){
    double a, b, x, theata;
    cin>> a >> b >> x;

    if(x > a*a*b/2){
        theata = atan(2*(a*a*b - x)/(a*a*a));
    }else{
        theata = atan((a*b*b)/(2*x));
    }
    theata = theata*180/PI;
    cout<<setprecision(10)<< theata <<endl;
    return 0; 
}

Measured memory_bytes: 4000
from math import sqrt

def func(a, b):
	if a == b:
		return (a - 1) * 2
	else:
		sq = int(sqrt(a * b))
		if a * b == sq ** 2:
			return (sq - 1) * 2 - 1
		elif sq * (sq + 1) > a * b:
			return (sq - 1) * 2
		elif sq * (sq + 1) == a * b:
			if abs(a - b) == 1:
				return (sq - 1) * 2
			else:
				return (sq - 1) * 2
		else:
			return sq * 2 - 1

q = int(input())
for _ in range(q):
	a, b = map(int, input().split())
	print(func(a, b))

Measured memory_bytes: 3064
/*input
46 4 40 5
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b, c, d, i = 0; cin >> a >> b >> c >> d;
    while(a > 0 && c > 0)
    {
    	if(i & 1) a -= d;
    	else c -= b;
    	i++;
    }
    cout << ((i & 1) ? "Yes" : "No");

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int ans = 0;
    rep(i, n - 2) {
        if ((p[i] < p[i + 1] && p[i + 1] < p[i + 2]) || (p[i] > p[i + 1] && p[i + 1] > p[i + 2])) {
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

A = sorted(A, reverse=True)

result = A[0]
cnt =1
position = 1
flag = 0
while cnt<N-1:
    result += A[position]
    cnt += 1
    if cnt == N-1:
        break
    result += A[position]
    cnt +=1
    position += 1

print(result)


Measured memory_bytes: 31428
import java.util.Scanner;


public class Main {
	static Scanner sc = new Scanner(System.in);
	static int cnt=0;

	public static void main(String[] args) {

		while(sc.hasNext()){
			String str = sc.next();

			if(str.contains("apple")){
				str = str.replace("apple", "peach");
			} else if(str.contains("peach")){
				str = str.replace("peach", "apple");
			}

			if(cnt != 0) System.out.print(" ");
			System.out.print(str);
			cnt++;
		}
		System.out.println();

	}

}

Measured memory_bytes: 12000
#include "bits/stdc++.h"
using namespace std;

int main(){
  int N;
  cin >> N;
  if(N == 1){
    cout << "Hello World" << endl;
  }else if(N == 2){
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;

int main(){
  int N;
  while(cin >> N){
    int ans = 0;

    FORE(i,1,N){
      if(N-i > 0 and N-i < i){
        ++ans;
      }
      
    }


    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)


const int MAX = 10000000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void){
    // Your code here!
    COMinit();
    int x,y; cin >> x >> y;
    if ((x+y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    if ((2*y - x) % 3 != 0 || (2*x-y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    int a = (2*y-x)/3;
    int b = (2*x-y)/3;
    long long ans = COM(a+b,b);
    cout << ans << endl;
}


Measured memory_bytes: 237960
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#define full(c) c.begin() c.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1);
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int max_digit = 0;
string make(string t)
{
    string ret = "";
    bool flag = true;
    for(int i = 0; i < t.size(); i++)
    {
        if(t[i] >= '0' && t[i] <= '9')
        {
            int j = i;
            int cnt = 0;
            string str = "";
            while(t[j] >= '0' && t[j] <= '9')
            {
                cnt++;
                j++;
                str += t[i];
                i++;
            }
            int tmp = max_digit - cnt;
            //cout << t << " " << cnt << endl;
            while(tmp--) ret += '0';
            ret += str;
            //flag = false;
        }
        //else flag = true;
        ret += t[i];
    }
    return ret;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<string> vec;
    for(int i = 0; i <= n; i++)
    {
        string s;
        cin >> s;
        vec.push_back(s);
    }
    int cnt = 0;
    for(int i = 0; i < vec.size(); i++)
    {
        int tmp = 0;
        for(int j = 0; j < vec[i].size(); j++)
        {
            if(vec[i][j] >= '0' && vec[i][j] <= '9') cnt++;
            else cnt = 0;
            tmp = max(cnt, tmp);
        }
        max_digit = max(tmp, max_digit);
    }
    for(int i = 0; i < vec.size(); i++) vec[i] = make(vec[i]);
    for(int i = 1; i < vec.size(); i++)
    {
        bool ok = true; //vec[j] > vec[i]
        bool flag = false;
        for(int j = 0; j < min(vec[0].size(), vec[i].size()); j++)
        {
            if(vec[0][j] == vec[i][j]) continue;
            flag = true;
            if(vec[0][j] < vec[i][j]) break;
            else ok = false;
        }
        if(flag == false && vec[0].size() > vec[i].size()) ok = false;
        //cout << vec[0] << " " << vec[i] << endl;
        cout << (ok ? '+' : '-') << "\n";
    }
    return 0;
}



Measured memory_bytes: 10820
#include <stdio.h>
#include <algorithm>

using namespace std;

void set_prime_number(bool* array, int num) {

  fill(array, array + num, true);
  array[0] = array[1] = false;
  for (int i = 2; i < num; i++) {
    if (!array[i]) continue;
    for (int j = i * 2; j < num; j += i) {
      array[j] = false;
    }
  }

}

int main() {
  bool prime_number[1000000];
  int num;
  int nump=0;
  int cnt=0;

  set_prime_number(prime_number,1000000);
	while(scanf("%d",&num)!=EOF){
	 for (int i = 0; i <= num; i++) {
		 if (prime_number[i]){cnt++;}
	 }
	 printf("%d\n",cnt);
	 cnt=0;
	}


  return 0;
}

Measured memory_bytes: 2000
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

#define mod 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N,K,sum=0;

int main(){
    cin>>N>>K;
    int l[N];
    rep(i,N){
        cin>>l[i];
    }
    sort(l,l+N,greater<int>());
    rep(i,K){
        sum+=l[i];
    }
    out(sum);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,a,b;
  cin>>N;
  a = (N-N/1000*1000)%111;
  b = ((N-N%10)/10)%111;
  if(a == 0 || b == 0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
n, t = map(int, input().split())
tn = list(map(int, input().split()))
x = 0

for i in range(n-1):
    if tn[i+1] - tn[i] >= t:
        x += t
    else:
        x += tn[i+1] - tn[i]
print(x + t)


Measured memory_bytes: 26708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int a[2000005], b[2000005];

void CountingSort (int n, int k) {
    int c[k + 1] = {};
    rep (i, 0, n) c[a[i]]++;
    // rep (i, 0, k + 1) cout << c[i] << " ";
    // cout << "\n";
    rep (i, 1, k + 1) c[i] += c[i - 1];
    // rep (i, 0, k + 1) cout << c[i] << " ";
    // cout << "\n";
    rep (i, 0, n) { b[--c[a[i]]] = a[i]; }
    rep (i, 0, n) {
        if (i) cout << " ";
        cout << b[i];
    }
    cout << "\n";
}

int main() {
    int n, k = 0;
    cin >> n;
    rep (i, 0, n) {
        cin >> a[i];
        k = max (k, a[i]);
    }
    CountingSort (n, k);
}


Measured memory_bytes: 18716
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <fstream>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
typedef long long ll;

#define INF 1000000000

#define MX 300000

vector<int> msp; //monday saturday primes

bool prime[MX+10];

void make_list(){
    fill(prime, prime+MX+5, false);
    for(int i=1; i*7< MX+5; i++){
        prime[i*7-1] = prime[i*7+1] = true;
    }

    for(int i=6; i<=MX; i++){
        if(prime[i]){
            for(int j=i*2; j<=MX; j+=i) prime[j]=false;
            msp.pb(i);
        }
    }
}

int main(){
    make_list();

    int n;
    while(cin>>n, n!=1){
        printf("%d:", n);
        rep(i,msp.size()){
            if(n<msp[i]) break;
            if(n%msp[i]==0) printf(" %d", msp[i]);
        }
        printf("\n");
    }

    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<bool> ok(N, false);
  vector<int> cnt(N, 0);
  for (int i = 0; i < M; i++) {
    int p;
    string s;
    cin >> p >> s;
    p--;
    if (!ok[p] && s == "WA") {
      cnt[p]++;
    }
    if (!ok[p] && s == "AC") {
      ok[p] = true;
    }
  }
  vector<int> res(2, 0);
  for (int i = 0; i < N; i++) {
    if (ok[i]) {
      res[0]++;
      res[1] += cnt[i];
    }
  }
  cout << res[0] << ' ' << res[1] << '\n';
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n;
	cin >> n;
	ll arr[n]; ll mx = 0; ll ans = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		if (arr[i] < mx)
		{
			ans += mx - arr[i];
		}
		else
			mx = arr[i];

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



Measured memory_bytes: 5160
N = int(input())
As = list(map(int,input().split()))

#0～NのN+1個のindexを持っていてこのうち1～Nを使う
#iの倍数を使うので0indexは都合が悪い
#Asの先頭はダミー,Bsは正解の列(ボール有:1、ボール無:0)
As = [-1] + As
Bs = [0 for _ in range(N+1)]

#N,N-1,N-2,...,3,2,1
for i in reversed(range(1,N+1)):
	tmpS = 0
	#iの倍数の箱があれば積み上げる
	for j in range(2*i,N+1,i):
		tmpS += Bs[j]
		
	#合計とAs[i]が異なると、補正するためにBsに1を
	#それ以外は0なのでデフォルトのまま何もしない
	if tmpS % 2 != As[i]:
		Bs[i] = 1

anss = []
#1のindexを抽出とjoinを使うため文字列化
for i in range(N+1):
	if Bs[i] == 1:
		anss.append(str(i))
		
print(len(anss))
print(" ".join(anss))

Measured memory_bytes: 73564
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

using Graph = vector<vector<pair<int, int>>>;

int main(){
    fastcin();

    int l;
    cin >> l;
    vector<int> a;
    int l2 = l;
    while(l2 > 0){
        a.push_back(l2%3);
        l2 /= 3;
    }
    reverse(all(a));
    // repe(i, a) cout << i; cout << endl;
    int n = a.size()+1, m = 0;
    Graph G(n);
    int now = 1, border = 0;
    rep(i, n-2) now *= 3;
    rep(i, n-1){
        if(i > 0)rep(j, 3){
            G[i].emplace_back(i+1, now*j);
            m++;
            // cout << now*j << " ";
        }
        // cout << endl;
        rep(j, a[i]){
            G[0].emplace_back(i+1, border+now*j);
            m++;
            // cout << border+now*j << " ";
        }
        // cout << endl;
        border += now*a[i];
        // cout << "border:" << border << endl;
        now /= 3;
    }
    cout << n << " " << m << endl;
    rep(i, n)repe(j, G[i]){
        cout << i+1 << " " << j.first+1 << " " << j.second << endl;
    }


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int main()
{
	int n,x,ans=INT_MAX,i;
	scanf("%d %d",&n,&x);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	for(i=0;i<=n-x;i++)
		if(a[i+x-1]-a[i]<ans)
			ans=a[i+x-1]-a[i];
	printf("%d",ans);
	return 0;
}

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

vector<int> a(15);
vector<vector<int>> x(15,vector<int>(15));
vector<vector<int>> y(15,vector<int>(15));

int main() {
	int n;
	cin >> n;
	rep(i,n) {
		cin >> a[i];
		rep(j,a[i]) {
			cin >> x[i][j] >> y[i][j];
			x[i][j]--;
		}
	}
	int ans = 0;
	rep(div,1<<n) {
		int g = 0;
		vector<bool> honest(n);
		int num_honest = 0;
		rep(i,n) {
			if (div>>i&1) {
				num_honest++;
				honest[i] = true;
			}
			else honest[i] = false;
		}
		bool ok = true;
		rep(i,n) rep(j,a[i]) {
			if (honest[i] == 1 && (int(honest[x[i][j]]) != y[i][j])) ok = false;
		}
		if (ok) ans = max(ans, num_honest);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)n; i++)
#define REPR(i, n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define FORR(i, m, n) for(int i=(int)m-1; i>=(int)n; i--)
#define ASC(v) sort(v.begin(), v.end());
#define DESC(v) sort(v.begin(), v.end(), greater<int>());
#define REVERSE(v) reverse(v.begin(), v.end());
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
typedef long long ll;
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main() {
	ll N, A, B;
	cin >> N >> A >> B;
	string s;

	if (A==0) {
		cout << 0 << "\n";
		return 0;
	}

	ll res = N / (A+B) * A;
	ll rem = N % (A+B);
	res += min(rem, A);
	cout << res << "\n";
}


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

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  int N;
  cin >> N;
  for (int i = 0; i <= N / 4; i++) {
    for (int y = 0; y <= N / 7; y++) {
      if (4 * i + 7 * y == N) {
	cout << "Yes" << endl;
	return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
ans = 0

if(N>1):
    Q = factorization(N)
    A = [ b for [a,b] in Q]
    for a in A:
        i = 1
        while(a >= i):
            a -= i
            i += 1
            ans += 1
    print(ans)

else:
    print(0)

Measured memory_bytes: 9496
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}





///////////////////////////


int main() {
	ll H, W, D;
	cin >> H >> W >> D;

	vector<ll> h(H*W + 1), w(H*W + 1);

	repn(i, H) {
		repn(j, W) {
			ll A;
			cin >> A;
			h[A] = i;
			w[A] = j;
		}
	}

	vector<ll> pow(H*W + 1);

	repn(i, H*W) {
		if (i <= D) { pow[i] = 0; }
		else {
			pow[i] = pow[i - D] + abs(h[i] - h[i - D]) + abs(w[i] - w[i - D]);
		}
	}

	ll Q;
	cin >> Q;
	repn(i, Q) {
		ll L, R;
		cin >> L >> R;
		cout << pow[R] - pow[L] << endl;
	}

	system("PAUSE");

}


Measured memory_bytes: 3448
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.out



int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	int n;
    cin>>n;
    vi a(n),b(n);
    rep(i,n){
        cin>>a[i];
        b[i]=a[i];
    }
    Sort(b);
    int omax=b[n-1],tmax=b[n-2];
    for(int i=0;i<n;i++){
        if(a[i]==omax)cout<<tmax<<endl;
        else cout<<omax<<endl;
    }

//////////////////////////////////////////////////////
return 0;}

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

int main () {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  
  int n, m;
  double total = 0.0;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    total += a[i];
  }
  sort(a.rbegin(), a.rend());
  total /= (4*m);
  bool ok = true;
  for (int i = 0; i < m; ++i) {
    if (a[i] < total) ok = false;
  }
  cout << (ok?"Yes":"No") << "\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
#include<map>
#include<vector>

using namespace std;

int main(){
  
  int n,anum,bnum;
  int as, bs;
  
  as = bs = 0;
  
  while(1){
    scanf("%d",&n);
    
    if(n == 0) break;  
    
    for(int i = 0 ; i < n ; i++){
      scanf("%d%d",&anum,&bnum);
      
      if(anum == bnum){
	as += anum;
	bs += bnum;
      }
      
      else if(anum > bnum){
	as += anum;
	as += bnum; 
      }
      
      else if(anum < bnum){
	bs += anum;
	bs += bnum; 
      }  
    }
    
    printf("%d %d\n",as,bs);

    as = bs = 0;

  }
  return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define loop for(;;)
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;
#define sort_all(v) sort(begin(v), end(v))
#define inf (1e9)
#define eps (1e-9)
using Integer = long long;
using Real = long double;
const Real PI = acosl(-1);
using P = pair<int, int>;

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

template<class T, class U> inline
ostream& operator<<(ostream&os, tuple<T,U> t) {
    return os << '(' << get<0>(t) << ", " << get<1>(t) << ')';
}

template<class S, class T, class U> inline
ostream& operator<<(ostream&os, tuple<S,T,U> t) {
    return os << '(' << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << ')';
}

template<class T> inline
ostream& operator<<(ostream&os, set<T> v) {
    os << "(set"; for (T item: v) os << ' ' << item; os << ")"; return os;
}

template<class T> inline
ostream& operator<<(ostream&os, vector<T> v) {
    if (v.size() == 0) return os << "(empty)";
    os << v[0]; for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
    return os;
}

template<class T> inline
istream& operator>>(istream&is, vector<T>&v) {
    rep (i, v.size()) is >> v[i]; return is;
}

//           ^   >  v   <
int dx[] = { -1, 0, 1,  0 };
int dy[] = {  0, 1, 0, -1 };

using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);
    random_device dev;
    mt19937 rand(dev());

    int n; cin >> n;
    cout << n * n * 3 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long n; cin >> n;
    long total = 0;
    long ans = 0;
    vector<long> v(n);
    for(int i=0;i<n;i++){
        cin >> v[i];
        total += v[i];
        total %= 1000000007;
    }
    for(int i=0;i<n-1;i++){
        total -= v[i];
        total %= 1000000007;
        ans += total*v[i];
        ans %= 1000000007;
    }
    if(ans < 0)ans = 1000000007 + ans;
    cout << ans << endl;
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;

template <typename F>
struct FixPoint : F{
  explicit constexpr FixPoint(F &&f) noexcept : F(std::forward<F>(f)){}

  template <typename... Args>
  constexpr decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};

template <typename F>
static inline constexpr decltype(auto) make_fix_point(F &&f){
  return FixPoint<F>(std::forward<F>(f));
}

int main(){
  int N;
  while(cin >> N){
    vector<int> a(N);
    FOR(i,1,N){
      cin >> a[i];
      --a[i];
    }

    vector<vector<int>> b(N);
    FOR(i,1,N){
      b[a[i]].push_back(i);
    }

    auto f =
      make_fix_point([&](auto &&f, int i) -> int{
                       vector<int> temp;

                       for(auto j : b[i]){
                         temp.push_back(f(j));
                       }

                       sort(RALL(temp));

                       int ret = 0;

                       REP(k,temp.size()){
                         chmax(ret, k+1 + temp[k]);
                       }

                       return ret;
                     });
    
    auto ans = f(0);
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 12800
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			long[] ls = new long[N];
			for(int i = 0; i < N; i++) {
				ls[i] = sc.nextLong();
			}
			
			long answer = 0;
			for(int i = 0; i < N; i++) {
				for(int j = i + 1; j < N; j++) {
					if(ls[i] == ls[j]) { continue; }
					
					for(int k = j + 1; k < N; k++) {
						if(ls[i] == ls[k] || ls[j] == ls[k]) { continue; }
						
						final long max = Math.max(ls[i], Math.max(ls[j], ls[k]));
						final long rest = (ls[i] + ls[j] + ls[k]) - max;
						
						//System.out.println((i + 1) + " " + (j + 1) + " " + (k + 1));
						
						if(max < rest) {
							answer++;
						}
					}
				}
			}
			
			System.out.println(answer);
			
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 32988
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

int main(){
	int L,m,n;
	while(cin>>L,L){
		int sum = 0;
		bool flag =false;
		int ans =-1;
		for(int i =0; i <12;i++){
			cin>>m>>n;
			sum +=(m-n);
			if(sum >=L&&!flag){
				flag =true;
				ans = i+1;
			}
		}
		if(flag){
			cout <<ans<<endl;
		}else{
			cout <<"NA"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    k = int(input())
    keta = 1
    mod = 7%k
    if k % 7 == 0:
        max_k = 9*k//7
    else:
        max_k = 9*k
    if k %2 == 0 or k%5 == 0:
        print(-1)
    while keta < max_k:
        if mod == 0:
            print(keta)
            break
        mod = (mod*10 + 7)%k
        keta += 1


if __name__=='__main__':
    main()

Measured memory_bytes: 62900
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
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; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  int n, d;
  cin >> n >> d;
  vector<vector<int> > x(n, vector<int>(d));
  rep(i, n) rep(j, d) cin >> x[i][j];

  int ans = 0;
  rep(i, n) rep3(j, i + 1, n) {
    int sum = 0;
    rep(k, d) sum += pow(x[i][k] - x[j][k], 2);
    if ((int)sqrt(sum) * (int)sqrt(sum) == sum) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import numpy as np

N=int(input())
TA = list(map(int,input().split()))
T=TA[0]
A=TA[1]
H = list(map(int,input().split()))
temperature=[]
def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

for i in range(N):
    temperature.append(T-H[i]*0.006)
print(getNearestValue(temperature,A)+1)


Measured memory_bytes: 12496
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top = 0, S[1000];

void push(int x) {
  S[++top] = x;
}

int pop(void) {
  top--;
  return S[top+1];
}

int main(void) {
  int a, b;
  top = 0;
  char s[100];
  while(scanf("%s",s) != EOF) {
    if(s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if(s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if(s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }
  printf("%d\n",pop());

  return 0;
}


Measured memory_bytes: 2068
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,M;
  cin>>N>>M;
  Graph G(N);
  REP(i,M){
    ll A,B;
    cin>>A>>B;
    A--,B--;
    G[A].PB(B);
    G[B].PB(A);
  }
  
  ll ANS[N];
  REP(i,N) ANS[i]=INF;
  ANS[0]=0;
  queue<ll> Q;
  Q.push(0);
  
  while(!Q.empty()){
    ll v=Q.front();
    Q.pop();
    FORE(nv,G[v]){
      if(ANS[nv]!=INF) continue;
      ANS[nv]=v;
      Q.push(nv);
    }
  }
  
  cout<<"Yes"<<endl;
  RREP(i,N-1) co(ANS[i]+1);
  return 0;
}

Measured memory_bytes: 10792
# include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int a[maxn];
int main()
{
    int n, cnt = 0, ans = 0;
    scanf("%d",&n);
    for(int i=1; i<=n; ++i) scanf("%d",&a[i]);
    for(int i=1; i<=n; ++i)
    {
        if(i == a[i])
            ++cnt;
        else
        {
            ans += (cnt+1)/2;
            cnt = 0;
        }
    }
    if(cnt) ans += (cnt+1)/2;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**5)

N = int(input())
B = list(map(int, input().split()))
ans = []
while len(B) > 0:
  ok = False
  for i in reversed(range(len(B))):
    if B[i] == i+1:
      ok = True
      ans.append(B.pop(i))
      break
  if not ok:
    break
if len(B) > 0:
  print(-1)
else:
  for a in reversed(ans):
    print(a)



Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
	int A,B,C;
	string ans;
	cin >> A >> B >> C;
	if (A <= B && A <= C && C <= B) {
		ans = "Yes";
	}
	else if (A >= B && A >= C && C >= B)
		ans = "Yes";
	else
		ans = "No";
	cout << ans <<"\n";
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  vector<ll> H(n); rep(i, n) cin >> H[i];
  vector<bool> ans(n, true);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    if(H[a] > H[b]) {
      ans[b] = false;
    } else if(H[a] == H[b]) {
      ans[a] = ans[b] = false;
    } else {
      ans[a] = false;
    }
  }
  cout << accumulate(all(ans), 0) << "\n";
  return 0;
}


Measured memory_bytes: 3936
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <typeinfo>
    
using namespace std;
    
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    REP(i,n) cin >> s[i];
    // minimum size
    int p=0;
    REP(i,n) if(s[i].size() < s[p].size()) p = i;
    string mn_s, inp;
    mn_s = s[p];
    
    // find common chars
    for(int i=0; i<mn_s.size(); i++){
        int ok=1;
        for(int j=0; j<n; j++){
            if((int)s[j].find(mn_s[i]) == -1){
                ok = 0;
                break;
            }
        }
        if(ok){
            inp += mn_s[i];
            for(int j=0; j<n; j++){
                s[j].erase(s[j].begin() + (int)s[j].find(mn_s[i]));
            }  
        }
    }
    for(int i=0; i<inp.size(); i++){
        for(int j=0; j<inp.size()-1; j++){
            if(inp[j] > inp[j+1]) swap(inp[j], inp[j+1]);
        }
    }
    cout << inp << endl;
} 

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

int main() {
  string S;
  cin >> S;
  int N=S.size();
  string rS=S;
  reverse(rS.begin(),rS.end());
  string rlS,rrS,cplS,cprS;

  for(int i=0;i<(N-1)/2;i++) {
      cplS+=S.at(i);
      rlS+=S.at(i);
  }
  reverse(rlS.begin(),rlS.end());
  for(int i=0;i<(N-1)/2;i++) {
      cprS+=S.at(i+(N+1)/2);
      rrS+=S.at(i+(N+1)/2);
  }
  reverse(rrS.begin(),rrS.end());

  bool result=false;
  if(S==rS&&cplS==rlS&&cprS==rrS) result=true;

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

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

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

	int A, B, C, D;
	cin >> A >> B >> C >> D;
	A = max(A, C);
	B = min(B, D);
	if(A>B)cout<<0;
	else cout<<B-A;
}


Measured memory_bytes: 256