akhauriyash/Code-Regression huggingface dataset:
//by xiqiao
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
typedef long long ll;
int n,m,flag=1;
vector <int> v[maxn],g[maxn];
int fa[maxn],tag[maxn],is[maxn],vis[maxn];
void dfs(int x){
	vis[x]=1;//cout<<x<<" "<<fa[x]<<endl;
	for(int i=0;i<(int)v[x].size();i++){
		if(is[g[x][i]])continue;
		is[g[x][i]]=1;
		if(!vis[v[x][i]]){
			fa[v[x][i]]=x;dfs(v[x][i]);
			tag[x]+=tag[v[x][i]];
		}
		else{
			tag[x]++;tag[v[x][i]]--;
		}
	}
	if(fa[x]!=0 && tag[x]%2==0){
		flag=0;
	}
}
int main(){
	//freopen("1.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y;scanf("%d%d",&x,&y);
		v[x].push_back(y);v[y].push_back(x);
		g[x].push_back(i);g[y].push_back(i);
	}
	for(int i=1;i<=n;i++){
		if(!vis[i])dfs(i);
	}
	if(flag)puts("YES");
	else puts("NO");
	return 0;
}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    int sum = a + b + c + max(max(a, b), c) * (pow(2, k) - 1);
    cout << sum << endl;
    return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n,cnt=0,ans=0,a[10000000],b[10000000],c,cmp,data,m,h,w,x,y,xcmp,ycmp,sum=0;

string s;

vector<int> z;

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

       cin >> s;
       Yes(s[0]==s[2]);
return 0;
}


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

enum Mapchip{BLANK='.',BRICK='*',STEAL='#',WATER='-',UP='^',DOWN='v',LEFT='<',RIGHT='>'};
struct Tank{int x,y;char dir;};

int T,H,W,N;
string manip;
vector<string>field;
Tank me;

void move(char dir){
  Tank next;
  next.y = me.y + (dir==DOWN)-(dir==UP);
  next.x = me.x + (dir==RIGHT)-(dir==LEFT);
  next.dir = dir;
  if(next.x<0 || W<=next.x || next.y<0 || H<=next.y || field[next.y][next.x]!=BLANK){
    me.dir=dir;
    field[me.y][me.x]=dir;
    return;
  }else{
    field[me.y][me.x]=BLANK;
    field[next.y][next.x]=next.dir;
    me=next;
    return;
  }
  return;
}

void shoot(){
  Tank next;
  int dx,dy,x,y;
  dy = (me.dir==DOWN)-(me.dir==UP);
  dx = (me.dir==RIGHT)-(me.dir==LEFT);
  y = me.y + dy;
  x = me.x + dx;
  while(0<=x && x<W && 0<=y && y<H){
    if(field[y][x]==STEAL){
      break;
    }else if(field[y][x]==BRICK){
      field[y][x]=BLANK;
      break;
    }
    y+=dy;
    x+=dx;
  }
  return;
}

int main()
{
  int i,j;
  cin>>T;
  while(T-->0){
    cin>>H>>W;
    field.resize(H);
    for(i=0;i<H;i++){
      cin>>field[i];
      string tanks="^v<>";
      for(j=0;j<W;j++){
	if(tanks.find(field[i][j])!=string::npos){
	  me.x=j;
	  me.y=i;
	  me.dir=field[i][j];
	}
      }
    }
    cin>>N>>manip;

    for(i=0;i<N;i++){
      switch(manip[i]){
      case 'U':
	move(UP);
	break;
      case 'D':
	move(DOWN);
	break;
      case 'L':
	move(LEFT);
	break;
      case 'R':
	move(RIGHT);
	break;
      case 'S':
	shoot();
	break;
      default:
	cout<<"error"<<endl;
	break;
      }
      continue;
    }

    for(i=0;i<H;i++)cout<<field[i]<<endl;
    if(T!=0)puts("");
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline ostream& operator<<(ostream& is, vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "" : " "); return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
inline void print() { cout << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }

int main() {
    init();

    int n, m, k; cin >> n >> m >> k;
    VI r(k); cin >> r;
    each(i, r)--i;

    auto dis = defvec<int>(INF, n, n);
    FOR(i, 0, n)dis[i][i] = 0;
    FOR(i, 0, m) {
        int a, b, c; cin >> a >> b >> c;
        --a, --b;
        dis[a][b] = dis[b][a] = c;
    }

    FOR(l, 0, n)FOR(i, 0, n)FOR(j, 0, n) {
        chmin(dis[i][j], dis[i][l] + dis[l][j]);
    }

    int ans = INF;
    VI p(k);
    FOR(i, 0, k)p[i] = i;
    do {
        int res = 0;
        FOR(i, 1, k)res += dis[r[p[i - 1]]][r[p[i]]];
        chmin(ans, res);
    } while (next_permutation(all(p)));

    print(ans);
}

Measured memory_bytes: 384
import scala.io.StdIn._

object Main extends App {


  val n = readInt()
  val s = readLine()

  def solve() = {
    s.map { char =>
      val c = char.toLower
      val num = alpha2Num(c)
      num2Alpha((num+n)%26)
    }.toUpperCase()
  }

  // 0 index
  def num2Alpha(n: Int): Char =
    ('a' + n).toChar

  // 0 index
  def alpha2Num(c: Char): Int =
    c - 'a'

  println(solve())

}



Measured memory_bytes: 54668
#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(){
  LLI N, K, S;
  while(cin >> N >> K >> S){
    vector<LLI> ans(N, S-1);

    if(S <= 2) ans.assign(N, 100000);
    
    REP(i,K) ans[i] = S;

    join(cout, ALL(ans));
  }

  return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>
#include <math.h>

int main()
{
    while (1){
        int n;

        scanf(" %d", &n);
        if (n == 0){
            break;
        }

        int score[n];

        for (int i = 0; i < n; i++){
            scanf(" %d", &score[i]);
        }

        int sum = 0;
        double ave;
       
        for (int i = 0; i < n; i++){
            sum += score[i];
        }
        
        ave = (double)sum / n;

        double alpha = 0;

        for (int i = 0; i < n; i++){
            alpha += pow(score[i] - ave, 2);
        }

        printf("%lf\n", sqrt(alpha/n));
    }

    return 0;
}
    

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

int main(){
    int a, b, k;
    cin >> a >> b >> k;

    int cnt = 0;
    int ans;
    vector<int> tmp;
    for(int i = 1; i <= ((a > b) ? b : a); i++){
        if(a % i == 0 && b % i == 0){
            tmp.push_back(i);
        }
    }

    cout << tmp[tmp.size() - k] << endl;

    return 0;
}

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

int main()
{
	int n,m,x,a[100];
	cin>>n>>m>>x;
	for(int i=0;i<m;i++) cin>>a[i];
	
	int i;
	for(i=1;a[i-1]<x;i++);
	
	cout<<min(i-1,m-i+1)<<endl;
	
	return 0;
}


Measured memory_bytes: 256
function Main(input) {
    var X = parseInt(input.split('/n')[0].split(' '), 10);

    var list = [];
    
    for (var i = 2 ; i < 32 ; ++i) {
        for (var j = 2 ; ; ++j) {
            var pow = Math.pow(i, j);
            if (pow <= 1000) list.push(pow);
            else break;
        }
    }
    list.push(1);

    list = list.sort(function(a, b) { return a - b; });

    for (var i = 0 ; i < list.length ; ++i) {
        if (i === list.length - 1 || list[i+1] > X) {
            console.log(list[i]);
            break;
        }
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

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

    long long ans = 0, w = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'W') {
            ans += i - w;
            w++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
#define Senky_Bansal ios::sync_with_stdio(0); 
#define IIIT_ALLAHABAD cin.tie(0); cout.tie(0);
#define int long long
const int N=3e3+5;
int Dp[N][N];
string s,t;
int dp(int i,int j)
{
	if(i==s.size())
		return 0;
	if(j==t.size())
		return 0;
	int &ans=Dp[i][j];
	if(ans!=-1)
		return ans;
	if(s[i]==t[j])
		ans= 1+dp(i+1,j+1);
	else
		ans= max(dp(i+1,j),dp(i,j+1));
	return ans;
}
void path(int i,int j)
{
   if(i==s.size())
   	return;
   if(j==t.size())
   	return;
   int ans=dp(i,j);
   if(s[i]==t[j])
   {
   	cout<<t[j];
   	path(i+1,j+1);
   }
   else
   {
   	if(ans==dp(i+1,j))
   		path(i+1,j);
   	else
   	   path(i,j+1);
   }
}
signed main()
{
	Senky_Bansal
	IIIT_ALLAHABAD

   memset(Dp,-1,sizeof(Dp));
    cin>>s>>t;
    path(0,0);
	return 0;
}

Measured memory_bytes: 71168
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#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 rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define srep(i, from, to) for(int i = from; i < (int)(to); i++)

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

  int ans = 0;
  reps(i, n) {
    string s = to_string(i);
    if(s.length() % 2 == 1) ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, D, A;
    scan(N, D, A);
    auto X = new long[](N);
    auto H = new long[](N);
    foreach (i; 0 .. N)
        scan(X[i], H[i]);
    zip(X, H).sort();
    long R = 2 * D + 1;
    auto imos = new long[](N + 1);
    long j;
    long ans;
    foreach (i; 0 .. N)
    {
        imos[i] += imos[max(i - 1, 0)];
        // writefln("%s %s %s", i, H[i], imos);
        if (0 < H[i] - imos[i])
        {
            // writefln("%s %s", i, H[i] - imos[i]);
            long remain = H[i] - imos[i];
            long cnt = (remain + A - 1) / A;
            long damage = cnt * A;
            while (j <= N && X[j] < X[i] + R)
                j++;
            imos[i] += damage;
            imos[j] -= damage;
            ans += cnt;
        }
    }
    writeln(ans);
}


Measured memory_bytes: 8444
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
a = list(map(int, input().split()))
d = [0] * (N - 1)
imosa = [0] * (M * 2 + 2)
imosb = [0] * (M * 2 + 2)
for i in range(N - 1):
  if a[i + 1] >= a[i]:
    d[i] = a[i + 1] - a[i]
    imosa[a[i] + 1] += 1
    imosa[a[i + 1] + 1] -= 1
    imosb[a[i] + 1] -= a[i] + 1
    imosb[a[i + 1] + 1] += a[i] + 1
  else:
    d[i] = a[i + 1] + M - a[i]
    imosa[a[i] + 1] += 1
    imosa[a[i + 1] + M + 1] -= 1
    imosb[a[i] + 1] -= a[i] + 1
    imosb[a[i + 1] + M + 1] += a[i] + 1
  #print(imosb)
#print(d)

imos = [0] * (M + 2)
for i in range(2 * M + 1):
  imosa[i + 1] += imosa[i]
  imosb[i + 1] += imosb[i]
#print(imosa)
#print(imosb)
for i in range(M + 2):
  imos[i] = imosa[i] * i + imosa[i + M] * (i + M) + imosb[i] + imosb[i + M]
#print(imos)
print(sum(d) - max(imos[1: M + 1]))

Measured memory_bytes: 56720
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    string S;
    cin >> S;
    map<char,long long> mp;
    for(int i = 0; i < N; i++){
        mp[S[i]]++;
    }
    long long ans = mp['R']*mp['G']*mp['B'];
    long long Notans = 0;
    for(int k = 2; k < N; k++){
        for(int j = 1; j < k; j++){
            int i = 2*j - k;
            if(0 <= i && i < j && j-i == k-j){
                    if(S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) Notans++; 
            }
        }
    }
    cout << ans - Notans << endl;
}


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

long long dfs(string &S, long long n) {
    long long ret = 0;
    vector<char> list = {'3', '5', '7'};

    if ((int)S.size() > 0) {
        if (stoll(S) > n) {
            return ret;
        } else {
            bool flag = true;
            for (auto c : list) {
                if (S.find(c) == string::npos) {
                    flag = false;
                }
            }
            if (flag) {
                ret++;
            }
        }
    }
    
    for (auto c : list) {
        S.push_back(c);
        ret += dfs(S, n);
        S.pop_back();
    }
    return ret;
}


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

    string S = "";
    long long ans = 0;

    ans = dfs(S, n);
    cout << ans << endl;

}



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

int main() {
  int n; cin >> n;
  set<string> s;
  rep(i, n) {
    string a; cin >> a;
    s.insert(a);
  }
  cout << (int)s.size() << endl;
  return 0;
}

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

int main(){
  int H, W;  // H=高さ, W=幅
  cin >> H >> W;

  char Pic;  // 画像

  for ( int i=0; i<=W+1; i++){
    cout << '#' ;
  }
  cout << endl;

  for (int j=0; j<H; j++){
    cout << '#' ;
    for (int i=0; i<W; i++){
      cin >> Pic;
      cout << Pic;
    }
    cout << '#' << endl;
  }

  for ( int i=0; i<=W+1; i++){
    cout << '#' ;
  }
  cout << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e16
using namespace std;
typedef pair<ll, ll> P;

int main(void) {
	ll n, k;
	cin >> n >> k;
	if (k % 2 == 1) {
		ll x = n / k;
		cout << x * x*x << endl;
	}
	else {
		ll x = n / k;
		if (n%k >= k / 2) {
			cout << x * x*x + (x + 1)*(x + 1)*(x + 1) << endl;
		}
		else {
			cout << x * x*x + x * x*x << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
/* 
 * Project: AtCoder Beginners Contest 164 B - Battle
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/04/26
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cmath>
using namespace std;

int a, b, c, d;

void solve() {
    int takahashi = a;
    int aoki = c;
    while (1) {
        aoki -= b;
        if (aoki <= 0) {
            printf("Yes\n");
            return;
        }

        takahashi -= d;
        if (takahashi <= 0) {
            printf("No\n");
            return;
        }
    }


    if (aoki <= 0)
        printf("Yes\n");
    else
        printf("No\n");
    
}

int main() {

    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &d);

    solve();

}

Measured memory_bytes: 1648
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

template<typename T>
bool chmax(T &a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T &a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

int n;
vector<int> a;
vector<int> ans;

bool solve(void){
    cin >> n;

    a.emplace_back(0);

    reps(i, n){
        int t;
        cin >> t;
        a.emplace_back(t);
    }

    vector<int> b(n + 1, 0);

    rreps(i, n){
        int cnt = 0;
        for(int j = n / i * i ; j > 0 ; j -= i){
            cnt += b[j];
        }
        if(cnt % 2 != a[i]){
            b[i] = 1;
        }
    }

    reps(i, n){
        if(b[i] == 1){
            ans.emplace_back(i);
        }
    }

    return true;
}

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

    if(solve()){
        cout << ans.size() << endl;
        rep(i, ans.size()){
            if(i) cout << ' ';
            cout << ans[i];
        }
        cout << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}

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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = m - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>d(n);
  rep(i,0,n)cin>>d[i];
  rep(i,0,n)rep(j,i+1,n){
    res+=d[i]*d[j];
  }
  cout<<res<<endl;
  return 0;
}

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

int main() {
   int N, p;
   double T, A, H, c = 99999;
   std::cin >> N >> T >> A;
   for (size_t i = 0; i < N; i++) {
      std::cin >> H;
      if (c > fabs((T - (H * 0.006)) - A)) {
         c = fabs((T - (H * 0.006)) - A);
         p = i + 1;
      }
   }
   std::cout << p << '\n';
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    string str1, str2;
    cin >> str1 >> str2;
    bool flag=true;
    for(int i=0; i<3; i++) {
        if(str1[i]!=str2[2-i]) {
            flag=false;
            break;
        }
    }
    if(flag) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }


    return 0;
    
}

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();
		List<Integer> S = new ArrayList<>();
		if(n == 0)
			S.add(0);
		while(n != 0) {
			int a = Math.abs(n % 2);
			S.add(a);
			n = (n - a) / -2;
		}
		Collections.reverse(S);
		for(int i = 0; i < S.size(); i++) {
			System.out.print(S.get(i));
		}
		System.out.println();
	}

}

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

int main()
{
  int n, now = 0;
  long long cnt = 1;
  long long max = 100000;
  cin >> n;
  vector<int> V(n);
  for (int i = 0; i < n; i++)
  {
    cin >> V.at(i);
  }
  while (max)
  {
    if (V.at(now) == 2)
    {
      cout << cnt << endl;
      return 0;
    }
    cnt++;
    now = V.at(now) - 1;
    max--;
  }
  cout << -1 << endl;
}


Measured memory_bytes: 3788
import itertools

N = int(input())
P = []

for i in range(len(str(N))): 
     P+= list(itertools.product(["7", "5", "3"], repeat = i + 1))

ans = 0
for i in P:
    if "7" not in i or "5" not in i or "3" not in i:
        continue
    a = int("".join(i))
    if a <= N:
        ans += 1
print(ans)

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

#define ll long long
const int mod = 1e9 + 7;

int hgt[100005];
ll int dp[100005];

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, k;
  cin>>n>>k;

  for(int i=1;i<=n;i++)
    cin>>hgt[i];

  dp[0] = 1e17;

  for(int i=2;i<=n;i++)
  {
    dp[i] = 1e17;
    for(int j=1;j<=k;j++)
      if(i-j >= 0)
        dp[i] = min(dp[i], dp[i-j] + abs(hgt[i-j] - hgt[i]));
  }

  cout<<dp[n]<<endl;

  return 0;
}


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

int main(){
    int N,K,X,Y,ans=0;
    cin>>N>>K>>X>>Y;
    for (int i=1;i<=N;i++){
        if (i>K){
            ans +=Y;
        }else{
            ans +=X;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//223
	int n;
	cin>>n;
	ull gc;
	cin>>gc;
	while(--n) {
		ull val;
		cin>>val;
		ull ngc = __gcd(gc,val);
		if(val%ngc==0)gc=gc*(val/ngc);
		else if(gc%ngc==0)gc=val*(gc/ngc);
		else
		gc=gc*val/__gcd(gc,val);
	}
	cout<<gc;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
#define li long long int
#define pb push_back


int main() {
    li t,i,j,l=0;
    li N,M,K,Z;
    cin>>N>>Z; 
    while(N--)
    {
       cin>>i>>j;
       if(i*i + j*j <= Z*Z)
       l++;

    }
    cout<<l;
    return 0;
}


Measured memory_bytes: 3620
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

l=[[0]*10 for _ in range(10)]

while 1:
    try:
        x,y,s=map(int,raw_input().split(','))
        l[y][x]+=1
        syo=[[0,1],[0,-1],[1,0],[-1,0]]
        chu=[[1,1],[-1,-1],[1,-1],[-1,1]]
        dai=[[0,2],[0,-2],[2,0],[-2,0]]
        for i in syo:
            if 0<=y+i[0]<=9 and 0<=x+i[1]<=9:
                l[y+i[0]][x+i[1]]+=1
        if s>1:
            for i in chu:
                if 0<=y+i[0]<=9 and 0<=x+i[1]<=9:
                    l[y+i[0]][x+i[1]]+=1
        if s>2:
            for i in dai:
                if 0<=y+i[0]<=9 and 0<=x+i[1]<=9:
                    l[y+i[0]][x+i[1]]+=1


    except:
        break

a=b=0
for i in l:
    a+=i.count(0)
    b=max(b,max(i))
print a
print b

Measured memory_bytes: 6432
n,d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
count = 0
for i in range(0,n-1):
    for j in range (i+1,n):
        a = 0
        for k in range(d):
            a += (x[i][k]-x[j][k])**2
        if ((a**0.5)%1==0):
            count += 1
print(count)

Measured memory_bytes: 3188
import math


def solve():
    count = 0
    R, G, B, N = map(int, input().split())
    # print(math.floor(N / R))
    for r in range(math.floor(N / R) + 1):
        # print('G購入上限:', math.floor(((N - (R * r)) / G)))
        for g in range(math.floor(((N - (R * r)) / G)) + 1):
            if (N - (R * r) - (G * g)) % B == 0:
                # print('残数:', N - (R * r) - (G * g))
                # print(r, g, (N - (R * r) - (G * g)) / B)
                count += 1
    print(count)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
const int INF = (1LL<<30);
const ll LLINF = (1LL<<60);
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int a[100010];
signed main(void)
{
  int n;
  cin >> n;
  REP(i, n) cin >> a[i];

  int ret = 0;
  REP(i, n-1) {
    if(a[i] == i+1) {
      ret++;
      swap(a[i], a[i+1]);
    }
  }
  if(a[n-1] == n) swap(a[n-1], a[n-2]), ret++;
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 640
def print_ans(s):
  """
  Parameters
  --------------
  >>> print_ans("2276")
  Bad
  >>> print_ans("3776") 
  Bad
  >>> print_ans("8080")
  Good
  """
  if s[0] == s[1] or s[1] == s[2] or s[2] == s[3]:
    print("Bad")
  else:
    print("Good")
  

def main():
  s = input()
  print_ans(s)


if __name__ == '__main__':
  main()



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

ll nck(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

bool check(string s,int n,int m){
    string t=s.substr(n-1,m);
    string u=s.substr(n-1,m);
    reverse(u.begin(),u.end());
    //cout<<t<<endl;
    //cout<<u<<endl;
    if(u==t) return true;
    else return false;
}

int main(){
    //A
    /*
    int N,M;cin>>N>>M;
    if(N<=1&&M<=1) cout<<0<<endl;
    else cout<<nck(N,2)+nck(M,2)<<endl;
    */
   //B
   /*
   string s;cin>>s;
   int N=s.size();
   //string p="akasaka";
   //cout<<p.substr(5,7)<<endl;
   if(check(s,1,N)&&check(s,1,(N-1)/2)&&check(s,(N+3)/2,N-(N+3)/2+1))
        cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   */
  //C
  double L;cin>>L;
  cout<<fixed<<setprecision(10);
  cout<<L/3*L/3*L/3<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  vector<long> d(N);
  rep (i, N) cin >> d[i];
  sort(d.begin(), d.end());
  long a = d[N/2-1];
  long b = d[N/2];
  cout << b - a << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

const int limit=50;
int a[limit], b[limit];
int n,m;

bool graph[limit][limit];
bool visited[limit];

void dfs(int v){
    visited[v]=true;
    for(int v2=0; v2<n; v2++){
        if(graph[v][v2]==false) continue;
        if(visited[v2]==true) continue;
        dfs(v2); 
    }
}

int main(void){
    
    cin >> n >> m;
    for(int i=0; i<m; i++){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
    }

    int ans=0;

    for(int i=0; i<m; i++){
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;

        for(int j=0; j<n; j++) visited[j]=false;
        dfs(0);

        bool bridge=false;
        for(int j=0; j<n; j++){
            if(visited[j]==false) bridge=true;
        }
        if(bridge) ans++;

        graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
    }

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

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

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

int main(){
	int n;
	cin>>n;
	vi v(n);
	for (int i = 0; i < n; i++){
		cin>>v[i];
	}

	int ans=1,h=v[0];
	for (int i = 1; i < n; i++){
		if(h>=v[i]){
			ans++;
			h=v[i];
		}
	}

	cout<<ans<<endl;

	return 0;
}


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

using namespace std;

int main()
{
    int n,l;
    cin>>n>>l;
    
    vector<string> v;
    
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        v.push_back(s);
    }
    
    sort(v.begin(),v.end());
    
    for(int i=0;i<n;i++)
    {
        cout<<v[i];
    }

   
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  vector<ll> a(n), s(n+1),s2(n+1);
  ll sum = 0;
  s[0] = 0;
  REP(i,n){
    cin >> a[i];
    s[i+1] = s[i] + a[i];
    sum += a[i];
  }
  s2[0] = 0;
  REP(i,n){
    s2[i+1] = s2[i] + a[n-i-1];
  }
  ll ans = 1e18;
  REP(i,n/2+2){
    ans = min(ans, abs(sum-s[i]-s[i]));
    ans = min(ans, abs(sum-s2[i]-s2[i]));
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4992
// cities to vapori-
// corner cases // int vs ll // cin vs scanf // clear structures // statement // doublesz // math is your friend
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define REP(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){

	fastio;
	multiset<int> red,green;
	int x,y,a,b,c,num;
	cin >> x >> y >> a >> b >> c;
	REP(i,0,a){
		cin >> num;
		red.insert(num);
	}
	while(sz(red) > x) red.erase(red.begin());
	REP(i,0,b){
		cin >> num;
		green.insert(num);
	}
	while(sz(green) > y) green.erase(green.begin());
	REP(i,0,c){
		cin >> num;
		if(*red.begin() < *green.begin()){
			if(num > *red.begin()){
				red.erase(red.begin());
				red.insert(num);
			}
		}else{
			if(num > *green.begin()){
				green.erase(green.begin());
				green.insert(num);
			}
		}
	}

	ll ans = 0;
	for(int x : red) ans += x;
	for(int x : green) ans += x;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 9216
#include <stdio.h>
#include <string.h>
#include <math.h>
#define lop(i, n) for(i=1; i<=n; i++)

int sanjou(int x)
{
	return x*x*x;
}

int main()
{
	int N;
	scanf("%d", &N);
	
	printf("%d", sanjou(N));
	
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<limits.h>
#define MAX 500000

int n,S[MAX];
int cnt=0;

void Merge(int S[],int left,int mid, int right){
  int i,j,k;
  int n1,n2;
  int L[MAX],R[MAX];
  n1=mid-left;
  n2=right-mid;

  for(i=0;i<n1;i++) L[i]=S[left+i];
  for(i=0;i<n2;i++) R[i]=S[mid+i];

  L[n1]=INT_MAX;
  R[n2]=INT_MAX;
  i=0,j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      cnt++;
      S[k]=L[i];
      i++;
    }else{
      cnt++;
      S[k]=R[j];
      j++;
    }
  }      
}

void Merge_Sort(int S[],int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    Merge_Sort(S,left,mid);
    Merge_Sort(S,mid,right);
    Merge(S,left,mid,right);
  }
}

int main(){
  int i,n;
  int left,right;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&S[i]);
  left = 0;
  right = n;
  Merge_Sort(S,left,right);

  printf("%d ",S[0]);
  for(i=1;i<n-1;i++) printf("%d ",S[i]);
  printf("%d\n%d\n",S[n-1],cnt);
  return 0;
}
  

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

int main()
{
  int n, flag = 1 ;
  cin >> n ;
  for(int i = 1 ; i <= n ; i++)
  {
    if(n % i == 0 && i <= 9)
    {
      if(n / i <= 9)
      {
        flag = 0 ;
        cout << "Yes" ;
        break ;
      }
    }
  }
  if(flag)
    cout << "No" ;
  return 0 ;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

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

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

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

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

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

template <class T>
T Sq(const T &t) {
  return t * t;
}

signed main() {
  int N = read();
  if (N < 1000)
    cout << "ABC" << endl;
  else
    cout << "ABD" << endl;
  return 0;
}


Measured memory_bytes: 256
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def dump(*objects):
    print(*objects, file=sys.stderr)


N = int(input())
A = [0] + list(map(int, input().split())) + [0]
dump(N, A)
B = cp.deepcopy(A)
C = cp.deepcopy(A)
for i in range(1, len(A)):
    dump(i)
    B[i] = B[i-1] + abs(A[i]-A[i-1])
for i in range(len(A)-2, -1, -1):
    dump(i)
    C[i] = C[i+1] + abs(A[i]-A[i+1])
dump(A, B, C)
for i in range(1, N+1):
    dump(i, B[i-1] + B[N+1] - B[i+1] + abs(A[i-1]-A[i+1]))
    print(B[i-1] + C[i+1] + abs(A[i-1]-A[i+1]))

exit(0)


Measured memory_bytes: 118800
slime_sum = input()
slime_color = input()

slime_result_sum_list = []
tmp_color = ""

for color in slime_color:
    if not slime_result_sum_list:
        slime_result_sum_list.append(color)
        tmp_color = color
        continue
    
    if tmp_color != color:
        slime_result_sum_list.append(color)
        tmp_color = color

print(len(slime_result_sum_list))

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

using namespace std;


void solve() {
    long long X, Y; cin >> X >> Y;
    
    long long ans = 0;
    long long tmp = X;
    while (tmp <= Y) {
        ans++;
        tmp *= 2;
    }

    cout << ans << endl;
}


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;	cin >> s;
  int q;	cin >> q;
  
  string left="";
  string right="";
  
  int dir=1;
  for(int i=0;i<q;i++){
    int t;	cin >> t;
    if(t==1){
      dir*=(-1);
    }else if(t==2){
      int t;	cin >> t;
      char c;	cin >> c;
      if(t==1){
        if(dir>0)	left=c+left;
        if(dir<0)	right=right+c;
      }else if(t==2){
        if(dir>0)	right=right+c;
        if(dir<0)	left=c+left;
      }
    }
  }
  s=left+s+right;
  if(dir==-1)	reverse(s.begin(),s.end());
  cout << s;
}

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

using namespace std;

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

	int a = 0;
	int b = INT_MAX;

	for (int i = 0; i < m; i++)
	{
		int l, r;
		cin >> l >> r;
		a = max(a, l);
		b = min(b, r);
	}

	if (0 <= b - a + 1)
	{
		cout << b - a + 1 << endl;
	}
	else
	{
		cout << 0 << endl;
	}
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int n,p,a,b,x=0,y=0,z=0,i;
	cin >> n;
	cin >> a >> b;
	for(i=0; i<n; ++i){
		cin >> p;
		if(p<=a){
			++x;
		}else if(p<=b){
			++y;
		}else{
			++z;
		}
	}
	cout << (min(min(x,y),z)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 200000
#define SNT 2000000000
typedef long long int llong;

int L[MAX /2 +2],R[MAX / 2 + 2];

llong merge(int*,int,int,int,int);
llong mergeSort(int*, int,int,int);

int main(){
  int A[MAX],n,i;
  llong ans;
  scanf("%d",&n);
  for(i = 0; i<n ; i++){
    scanf("%d",&A[i]);
  }
  ans = mergeSort(A,n,0,n);
  printf("%lld\n",ans);
  return 0;
}

llong merge(int A[], int n, int left,int mid, int right){
  int i,j,k,n1,n2;
  llong count = 0;
  n1 = mid - left;
  n2 = right - mid;
  for(i = 0; i<n1 ;i++){
    L[i] = A[left +i];
  }
  for(i = 0 ; i < n2 ; i++){
    R[i] = A[mid +i];
  }
  L[n1] = SNT;
  R[n2] = SNT;
  i = 0;
  j = 0;
  for(k = left ; k<right ; k++){
    if(L[i] <=R[j]){
      A[k] = L[i++];
    }
    else{
      A[k] = R[j++];
      count += n1-i;
    }

  }
  return count;
}


llong mergeSort(int A[],int n,int left,int right){
  int mid;
  llong r1,r2,r3;
  if(left + 1 <right){
    mid = (left +right)/2;
    r1 = mergeSort(A,n,left,mid);
    r2 = mergeSort(A,n,mid,right);
    r3 = merge(A,n,left,mid,right);
    return r1+r2+r3;
  }
  else return 0;
}



Measured memory_bytes: 3272
#include <stdio.h>

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


Measured memory_bytes: 2112
#include <iostream>
#include <set>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[])
{
	int N,i;
	set<LL> mySet;
	set<LL>::iterator sit;
	LL A;
	cin>>N;
	for (i=0;i<N;i++){
		cin>>A;
		sit=mySet.find(A);
		if (sit!=mySet.end()){
			cout<<"NO"<<endl;
			return 0;
		}else{
			mySet.insert(A);
		}
	}
	cout<<"YES"<<endl;	
	return 0;
}

Measured memory_bytes: 9600
from bisect import *
H,W,D=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]
zahyou=[[0,0] for i in range(H*W+1)]
for h in range(H):
    for w in range(W):
        zahyou[A[h][w]][0]=h
        zahyou[A[h][w]][1]=w
dp=[0 for i in range(H*W+1)]
for i in range(len(dp)):
    if i>=D:
        dp[i]=dp[i-D]+int(abs(zahyou[i][0]-zahyou[i-D][0]))+int(abs(zahyou[i][1]-zahyou[i-D][1]))

for i in range(int(input())):
    l,r=map(int,input().split())
    print(dp[r]-dp[l])


Measured memory_bytes: 62300
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  ll a;
  cin>>a;
  vector<ll>vec(a);
  for(ll i=0;i<a;i++){
    cin>>vec.at(i);
  }
  vector<ll>veco(a);
  veco=vec;
  sort(vec.begin(),vec.end());
 
  for(ll i=0;i<a;i++){
    if(veco.at(i)==vec.at(a-1)){
      cout<<vec.at(a-2)<<endl;
      
    }
    else{
      cout<<vec.at(a-1)<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 6408
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <cassert>
 
using namespace std;
 
string str[2];
int s, n, t, m, lt, rt, t_w, t_t;
long double p;
 
int conv(string s){
  string data[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};  
  for(int i=0;i<7;i++) if(s == data[i]) return i;
  if(s == "All") return -1;
  assert(false);
}
 
bool check(int s_w, int s_t, int f_w, int f_t){
  if(!(t_w == -1 || (t_w == s_w && t_w == f_w))) return false;
    if(str[1] == "All"){
      if(0 <= s_t && s_t < 24 * 60 && 0 <= f_t && f_t < 24 * 60) return true;
    }else
    if(str[1] == "Day"){
      if(6 * 60 <= s_t && s_t < 18 * 60 && 6 * 60 <= f_t && f_t < 18 * 60) return true;
    }else
    if(str[1] == "Night"){
      if(((18 * 60 <= s_t && s_t < 24 * 60) || (0 <= s_t && s_t < 6 * 60))
         && ((18 * 60 <= f_t && f_t < 24 * 60) || (0 <= f_t && f_t < 6 * 60))) return true;
    }else assert(false);
    return false;
}
 
main(){
  while(cin >> s >> n >> t >> str[0] >> str[1] >> p >> m && (s|n|t|m) && str[0] != "None" && str[1] != "None"){
    t_w = conv(str[0]);
    if(str[1] == "All") t_t = 0;
    if(str[1] == "Day") t_t = 1;
    if(str[1] == "Night") t_t = 2;
    //int ans = 0;
    //for(int i=0;i<7;i++) for(int j=0;j<24*60;j++) ans = max(ans, calc(i, j, t_w, t_t));
    long double ans = 0.0;
    for(int i=0;i<7;i++){
      for(int j=0;j<24*60;j++){
        int s_w = i;
        int s_t = j;
        long double cnt = 0.0;
        for(int k=0;k<m;k++){
          int f_w = s_w;
          int f_t = s_t + s;
          if(f_t >= 24 * 60){
            f_t -= 24 * 60;
            f_w = (f_w + 1) % 7;
          }
          if(check(s_w, s_t, f_w, f_t)) cnt++;
          s_t += t;
          if(s_t >= 24 * 60){
            s_t -= 24 * 60;
            s_w = (s_w + 1) % 7;
          }
        }
        ans = max(ans, 1.0 - pow((p - 1.0) / p, n * cnt));
      }
    }
        //cout << setiosflags(ios::fixed) << setprecision(10) << (1.0 - my_pow(1.0 - 1.0 / (double)p, n * ans)) << endl;
    //printf("%.10f\n", (1.0 - pow(1.0 - 1.0 / p, n * ans)));
    cout << setiosflags(ios::fixed) << setprecision(10) << ans << endl;
  }
}

Measured memory_bytes: 1340
n, d = gets.chomp.split(' ').map(&:to_i)
points = readlines.map(&:chomp).map{|point| point.split(" ").map(&:to_i)}

cnt = 0
dest_sq = 0
n.times do |i|
    (i+1).upto(n-1) do |j|
        next if i == j
        d.times do |k|
            dest_sq += (points[j][k] - points[i][k])**2
        end
        cnt += 1 if Math.sqrt(dest_sq) % 1 == 0
        dest_sq = 0
    end
end

puts cnt

Measured memory_bytes: 3836
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
int main(){
    int mass[1000000];
    CIN(N);
    REP(a,N){
        CIN(b);
        mass[a]=b-1;
    }
    bool result = false;
    int co = 0;
    int ins = 0;
    REP(a,N){
        if(ins == 1){
            result = true;
            break;
        }
        co++;
        ins = mass[ins];

    }
    COUT(result?co:-1);
    return 0;
}


Measured memory_bytes: 2560