akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define INF 10000000

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

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

    sort(X.begin(),X.end());

    int ans = INF;
    
    for(int i = X[0];i<=X[N-1];i++)
    {
        int check = 0;
        for(int j = 0;j<N;j++)
        {
            check += pow(X[j] - i,2);
        }
        if(check < ans)ans = check;
    }


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

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <utility>
#include <random>
#include <chrono>

using namespace std;

#define ll long long

int s, w;

int main()
{
    scanf("%d%d", &s, &w);
    if (w >= s) {
        printf("unsafe");
    } else {
        printf("safe");
    }
    return 0;
}


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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(A==B){
    cout << C << endl;
  }
  else if(B==C){
    cout << A << endl;
  }
  else{
    cout << B << endl;
  }
}

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



int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int N, x; cin >> N >> x;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    int res = 0;
    for (int i = 0; i < N; i++) {
        if ((i != N - 1 && a[i] <= x) || (i == N - 1 && a[i] == x)) {
            res++;
            x -= a[i];
        }
    }
    cout << res << '\n';

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    set<string> s;
    int n;
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        string a;
        cin >> a;
        s.insert(a);
    }

    cout << s.size();
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) cin >> b[i];
  vector<int> orig;
  for(int i = 1; i <= n; i++) orig.push_back(i);
  int cnt = 1;
  int apos = 0, bpos = 0;
  do{
  	if(orig == a) apos = cnt;
    if(orig == b) bpos = cnt;
    cnt++;
  }while(next_permutation(orig.begin(), orig.end()));
  
  cout << abs(apos - bpos);
         
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int x;
    cin >> x;
    if (x < 1200) cout << "ABC" << endl;
    else cout << "ARC" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

a, b, c, d = list(map(int, input().rstrip()))

li = ["+", "-"]

for x in li:
    for y in li:
        for z in li:
            tmp = a
            if x == "+":
                tmp += b
            else:
                tmp -= b
            if y == "+":
                tmp += c
            else:
                tmp -= c
            if z == "+":
                tmp += d
            else:
                tmp -= d
            if tmp == 7:
                print("{}{}{}{}{}{}{}=7".format(a, x, b, y, c, z, d))
                sys.exit()

Measured memory_bytes: 9120
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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 ll INF=1e9+7;


int main(){
    ll n;
    cin >> n;
    ll a=0,b=0,c=0;
    ll ans=0;
    rep(i,n){
        string s;
        cin >> s;
        ll m=s.length();
        rep(i,m-1){
            if(s[i]=='A' && s[i+1]=='B') ans++;
        }
        if(s[0]=='B' && s[m-1]=='A') a++;
        if(s[0]!='B' && s[m-1]=='A') b++;
        if(s[0]=='B' && s[m-1]!='A') c++;
    }
    if(a){
        ans+=a-1;
    }
    if(a && b){
        ans++;
        b--;
    }
    if(a && c){
        ans++;
        c--;
    }
    cout << ans+min(b,c) << endl;
}

Measured memory_bytes: 3608
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int getsum(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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

  cout << (n % getsum(n) == 0 ? "Yes" : "No") << endl;


  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;
//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

void solve() {
    int n;
    cin >> n;
    vector<int> a;
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        a.pb(k);
    }
    sort(a.begin(),a.end());
    cout << a[n-1] - a[0] << endl;
}

int main(int argc, char *argv[]){
    // /* Regular */
    // int case_num = 1;
    // if (argc > 1 && stoi(argv[1])) cin >> case_num;
    // REP(case_no, case_num) {
    //   cerr << endl << "case " << case_no + 1 << endl;
    //   solve();
    // }
    /* AOJ */
    solve();
    return 0;
}

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

int main() {
	int a, b, c, tr = 0;
	cin >> a >> b >> c;
	for (int i = 0; i < 150; i++) {
	    if ((a * i) % b == c) tr++;
	}
	if (tr > 0) cout << "YES";
	else cout << "NO";
	return 0;
}


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

const int mod = 1e9 + 7;

int main() {
	int n, b; long long ans; string s1, s2;
	cin >> n >> s1 >> s2;
	if (s1[0] == s2[0])ans = 3; else ans = 6;
	for (int i = 0; i < n - 1; i++) {
		if (s1[i] == s1[i + 1])continue;
		if (s1[i] == s2[i]) {
			if (s1[i + 1] == s2[i + 1])b = 2;
			else if (s1[i + 1] != s2[i + 1])b = 2;
		}
		else if (s1[i] != s2[i]) {
			if (s1[i + 1] == s2[i + 1])b = 1;
			else if (s1[i + 1] != s2[i + 1])b = 3;
		}
		ans = (ans * b) % mod;
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
  int a,b,s;
  bool flag=false;
  vector<int> data(100100);
  cin>>a>>b;
  rep(i,100100){data[i]=(i+1)*(i+1);}
  if(b<10){s=a*10+b;}
  else if(b<100){s=a*100+b;}
  else {s=a*1000+b;}

  rep(i,100100){if(s==data[i]){ flag=true; break;}}
  if(flag){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}

Measured memory_bytes: 640
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    n = int(input())
    a = list(map(int, input().split()))
    hoge = 0
    ans = 0
    for i in range(n):
        if a[i] < 0:
            hoge += 1
    if 0 in a or hoge % 2 == 0:
        for i in range(n):
            ans += abs(a[i])
    else:
        huga = []
        for i in range(n):
            a[i] = abs(a[i])
            ans += abs(a[i])
            if a[i] > 0:
                huga.append(a[i])
        ans -= min(huga)*2
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 25296
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

char maze[1000][1000];
int H;
int W;

int score[1000][1000];
const int dh[] = {1, -1, 0, 0,1,1,-1,-1,2,2,2,1,0,-1,-2,-2,-2,-2,-2,-1,0,1,2,2};
const int dw[] = {0, 0, 1, -1,1,-1,1,-1,0,1,2,2,2,2,2,1,0,-1,-2,-2,-2,-2,-2,-1};
  
void bfs(int i, int j) {
  deque<pair<int,int> > Q;
  score[i][j] = 0;
  Q.push_back(make_pair(i, j));
  while(!Q.empty()) {
    pair<int,int> q = Q.front();
    Q.pop_front();
    int h = q.first;
    int w = q.second;
    for (int k = 0; k < 24; k++) {
      int nh = h + dh[k];
      int nw = w + dw[k];
      if (nh < 0 || nh >= H || nw < 0 || nw >= W) {
        continue;
      }
      if(maze[nh][nw]=='#') continue;
      if (k<4 && score[nh][nw]>score[h][w]){
        Q.push_front(make_pair(nh, nw));
        score[nh][nw] = score[h][w];
      }
      if(k>=4 && score[nh][nw]>score[h][w]+1){
        Q.push_back(make_pair(nh, nw));
        score[nh][nw] = score[h][w]+1;
      }
    }
  }
}
  
int main() {
  cin >> H >> W;
  
  ll ch,dh,cw,dw;
  cin>>ch>>dh>>cw>>dw;
  ch--,dh--,cw--,dw--;
  
  rep(i,1000){
    rep(j,1000) score[i][j]=1e9;
  }
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) cin >> maze[i][j];
  }
  
  bfs(ch, dh);
  
  if(score[cw][dw]==1e9) cout<<-1<<endl;
  else cout<<score[cw][dw]<<endl;

  return 0;
}

Measured memory_bytes: 8520
n = int(input())
j = []
b = []
for i in range(n):
  x, u = map(str, input().split())
  x = float(x)
  if u == "JPY":
    j.append(x)
  else:
    b.append(x)
print(sum(j) + 380000.0 * sum(b))

Measured memory_bytes: 3060
from collections import Counter
N=int(input())
S=[0]*N
for i in range(N):
  S[i]=input()[0]
  
d=dict(Counter(S))
#print(d)
e=list()
for i in d:
  if i=="M" or i=="A" or i=="R" or i=="C" or i=="H":
    e.append(d[i])
#print(e)

n=len(e)
ans=0
for i in range(0,n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      #print(i,j,k,e[i]*e[j]*e[k])
      ans += e[i]*e[j]*e[k]
print(ans)

Measured memory_bytes: 4084
# after listening explanation
n, m = gets.split.map(&:to_i)
key = []
m.times{
  a,b = gets.split.map(&:to_i)
  c = gets.split.map(&:to_i)
  state = c.map{|ci| 1<<(ci-1)}.inject(:+)
  key << [state, a]
}
dp = Array.new(1<<n)
dp[0] = 0
(1<<n).times{|state_s|
  next if dp[state_s] == nil
  m.times{|i|
    state_t = state_s | key[i][0]
    cost = dp[state_s] + key[i][1]
    dp[state_t] = dp[state_t]==nil ? cost : [dp[state_t], cost].min
  }
}
ans = dp.last
p ans==nil ? -1 : ans

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

int main() {
    int n;
    cin>>n;
    unordered_map<string,int>unmp;
    for(int i=0;i<n;i++)
    {
    	string s;
    	cin>>s;
    	sort(s.begin(),s.end());
    	unmp[s]++;
    }
    long long ans=0;
    for (auto& it: unmp) {
    	 long long x=it.second;
         ans+= (x*(x-1))/2;
    }
    cout<<ans;
	return 0;
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    int sum = 0;

    vector<vector<int> > A(365,vector<int>(26));
    vector<int> c(26);
    for (size_t i = 0; i < 26; i++)
    {
        cin >> c.at(i);
        sum += c.at(i);
    }
    
    for (size_t i = 0; i < N; i++)
    {
        for (size_t j = 0; j < 26; j++)
        {
            cin >> A.at(i).at(j);
        }
        
    }
    vector<int> fuman(26,0);;
    int t;
    int f = 0;
    int ans = 0;
    for (size_t i = 0; i < N; i++)
    {
        for (size_t j = 0; j < 26; j++)
        {
            fuman.at(j)++;
        }
        

        cin >> t;
        fuman.at(t-1) = 0;
        for (size_t j = 0; j < 26; j++)
        {
            f += c.at(j)*fuman.at(j);
        }
        ans += A.at(i).at(t-1) - f;
        cout << ans << endl;
        f = 0;
    }
    
    //cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100009][4];
int dp[100009][4];
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	for(int i=1;i<n;i++){
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
		dp[i][2]=max(dp[i-1][0],dp[i-1][1])+a[i][2];
	}
/*	for(int i=0;i<n;i++){
		cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
	}*/
	cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2])<<endl;
}



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

int main() {
  char S[210];
  int i;
  
  scanf("%s", S);
  for(i = strlen(S) - 2; i >= 0; i -= 2) {
    int l = 0, r = i/2;
    int flag = 0;
    
    while(l < i/2 && r < i) {
      if(S[l] != S[r]) {
        flag = 1;
        break;
      }
      l++;
      r++;
    }
    if(flag == 0) {
      break;
    }
  }
  
  printf("%d\n", i);
  
  return 0;
}

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

#define mod 1000000007

vector<vector<char>> mp;
vector<vector<int>> dp;
int W,H;
int ans;

int main(){

  cin >> H >> W;

  mp=vector<vector<char>>(W,vector<char>(H));
  dp=vector<vector<int>>(W,vector<int>(H,0));
  for(int y=0;y<H;y++){
    for(int x=0;x<W;x++){
      cin >> mp[x][y];
    }
  }

  dp[0][0]=1;
  for(int y=0;y<H;y++){
    for(int x=0;x<W;x++){
      if(x+1<W && mp[x+1][y]=='.'){
        dp[x+1][y]=(dp[x+1][y]+dp[x][y])%mod;
      }
      if(y+1<H && mp[x][y+1]=='.'){
        dp[x][y+1]=(dp[x][y+1]+dp[x][y])%mod;
      }
    }
  }

  cout << (mod+dp[W-1][H-1])%mod << endl;
}

Measured memory_bytes: 5248
using System;

class C
{
	static void Main()
	{
		var h = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
		long k = h[0], a = h[1], b = h[2];

		if (a + 2 < b && k >= a)
		{
			var c = a;
			k -= a - 1;

			c += k / 2 * (b - a);
			k %= 2;
			Console.WriteLine(c + k);
		}
		else
		{
			Console.WriteLine(k + 1);
		}
	}
}


Measured memory_bytes: 27568
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for(int i=0;i<N;i++) cin >> A[i];
    map<ll,ll> mp;
    for(int i=0;i<N;i++){
        if(i==0){
            mp[-A[i]]++;
        }
        else{
            auto itr=mp.upper_bound(-A[i]);
            if(itr==mp.end()){
                mp[-A[i]]++;
            }
            else{
                itr->second=itr->second-1;
                if(itr->second==0){
                    mp.erase(itr);
                }
                mp[-A[i]]++;
            }
        }
    }
    ll ans=0;
    for(auto e : mp){
        //cout << e.first << " " << e.second << endl;
        ans+=e.second;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7168
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string s;

int main(void){
	int a;
	scanf("%d",&a);
	cin >> s;
	if(a<3200){
		printf("red\n");
	}else{
		cout << s << endl;
	}
	return 0;
}


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

using namespace std;

int main(void){
    int weigh;
    int w[1001],v[1001];
    int dp[1001][1001];
    int n;
    int c=0;
    
    while(cin>>weigh,weigh!=0){
        for(int i=0;i<1001;i++){
            memset(dp[i],0,1001);
        }
    
        cin>>n;
        for(int i=0;i<n;i++){
            scanf("%d,%d",&v[i],&w[i]);
        }
    
        for(int i=0;i<n;i++){
            for(int j=0;j<=weigh;j++){
                if(j<w[i]){
                    dp[i+1][j]=dp[i][j];
                }
                else{
                    dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
                }
            }
        }
        printf("Case %d:\n",++c);
        printf("%d\n",dp[n][weigh]);
        for(int i=0;i<=weigh;i++){
            if(dp[n][weigh]==dp[n][i]){
                printf("%d\n",i);
                break;
            }
        }
    }
    return(0);
}

Measured memory_bytes: 5148
#include <iostream>
#include <vector>
#include <climits>
#include <unordered_map>

#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive

//short hand for usual tokens
#define pb push_back
#define fi first
#define se second

#define mod 10000009

using namespace std;

// Shorthand for commonly used types
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long long ll;
typedef double ld;

void solution() {
    int n;
    cin>>n;

    int arr[n];

    for0(i, n) {
        cin>>arr[i];
    }

    // <val, freq>
    unordered_map<int,int> mp;
    for0(i, n) {
        mp[arr[i]]++;
    }
    int ans = 0;
    for(auto m: mp) {
        if(m.first < m.second) {
            ans += (m.second - m.first);
        } else if(m.first > m.second) {
            ans += m.second;
        }
    }

    cout<<ans<<endl;
}

int main() {
    int t(1);
    // cin>>t;
    while (t--) {solution();}
    return 0 ;
}



Measured memory_bytes: 7048
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < int(n); ++(i))
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using ll = long long;
using namespace std;
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }

ll solve(ll n, ll m, ll a, ll b, ll p, ll q) {
    if (a == 1 and b == 1) {
        ll delta = p + q;
        ll result = m;
        setmin(result, abs(m - min(n,  m              / delta) * delta));
        setmin(result, abs(m - min(n, (m + delta - 1) / delta) * delta));
        return result;
    }
    vector<ll> tickets;
    for (ll k = 0; k < n; ++ k) {
        double ticket = p * pow(a, k) + q * pow(b, k);
        if (2 * m + 3 < ticket) break;
        tickets.push_back(ticket);
    }
    if (tickets.empty()) {
        return m;
    } else if (tickets.size() == 1) {
        return min(m, abs(m - tickets[0]));
    }
    auto generate = [&](int l, int r) {
        vector<ll> acc;
        acc.push_back(0);
        repeat_from (k, l, r) {
            ll ticket = tickets[k];
            int prev_size = acc.size();
            repeat (i, prev_size) {
                acc.push_back(acc[i] + ticket);
            }
            whole(sort, acc);
            acc.erase(whole(unique, acc), acc.end());
        }
        return acc;
    };
    vector<ll> lower = generate(0, tickets.size() / 2);
    vector<ll> upper = generate(tickets.size() / 2, tickets.size());
    ll result = m;
    for (ll x : lower) {
        int i = whole(lower_bound, upper, m - x) - upper.begin();
        repeat_from (j, max(0, i - 3), min<int>(upper.size(), i + 3)) {
            ll y = upper[j];
            setmin(result, abs(m - (x + y)));
        }
    }
    return result;
}

int main() {
    ll n, m, a, b, p, q; scanf("%lld%lld%lld%lld%lld%lld", &n, &m, &a, &b, &p, &q);
    ll result = solve(n, m, a, b, p, q);
    printf("%lld\n", result);
    return 0;
}

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

int main() {
    int n, m;
    string a[100], b[100];
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    for (int i = 0; i < m; ++i)
    {
        cin >> b[i];
    }
    for (int i = 0; i < n - m + 1; ++i)
    {
        for (int j = 0; j < n - m + 1; ++j)
        {
            int f = 1;
            for (int k = 0; k < m && f; ++k)
            {
                for (int l = 0; l < m && f; ++l)
                {
                    if (a[i + k][j + l] != b[k][l])
                    {
                        f = 0;
                    }
                }
            }
            if (f)
            {
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
    return 0;
}


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

// 宣言
string maze[50]; // 迷路データ
int H; // 高さ
int W; // 幅
int scount = 0; // '#'の数
int ans = 0;

vector< vector<int> > score(50, vector<int> (50, 0)); // 手数
bool visited[50][50]; // 訪問履歴
const int dh[] = {1, -1, 0, 0};
const int dw[] = {0, 0, 1, -1};

// 幅優先探索
void bfs(int i, int j) {
  // キューを準備
  queue<pair<int,int> > Q;
  // スタート地点のスコアを0にセット
  score[i][j] = 0;
  // スタート地点の座標をキューにプッシュ
  Q.push(make_pair(i, j));
  // キューが空になるまで処理を実行
  while(!Q.empty()) {
    // 探索の起点となる座標を記憶してからポップ
    pair<int,int> q = Q.front();
    Q.pop();
    int h = q.first;
    int w = q.second;
    // 起点を元に座標を移動
    for (int k = 0; k < 4; k++) {
      int nh = h + dh[k];
      int nw = w + dw[k];
      // 移動先が迷路の範囲外なら処理をスキップ
      if (nh < 0 || nh >= H || nw < 0 || nw >= W) {
        continue;
      }
      // 移動先が壁か訪問済みなら処理をスキップ
      if (maze[nh][nw] == '#' || visited[nh][nw]) {
        continue;
      }
      // 移動先のスコアを起点のスコア+1にする
      score[nh][nw] = score[h][w] + 1;
      // 移動先の座標を訪問済みにする
      visited[nh][nw] = true;
      // 訪問先の座標をキューにプッシュ(順番が来たら探索の起点になる)
      Q.push(make_pair(nh, nw));
    }
  }
}

int main() {
  // 入力
  cin >> H >> W;
  // 迷路データ
  for (int i = 0; i < H; i++ ) {
    cin >> maze[i]; 
  }

  // 幅優先探索
  bfs(0, 0);

  // '#'の数をカウント
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (maze[i][j] == '#') {
        scount++;
      }
    }
  }
  // ゴールにたどり着けなかった場合
  if (score[H - 1][W - 1] == 0) {
    ans = -1;
  }
  // ゴールにたどり着けた場合
  else {
    ans = H * W - scount -(score[H - 1][W - 1] + 1);
  }

  // 出力
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
///1<<3シフト演算子 とは　0001の1を三つずらして1000にする, これは8を表しておりつまりbitは0から7まで
#define all(x) (x).begin(),(x).end()
#define ll long long
#define ld long double
#define cyes cout<<"Yes"<<endl
#define cno cout<<"No"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
using namespace std;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vi> Graph;

//条件式 ? 真の場合の文 : 偽の場合の文
//abs(x) = (x の絶対値)
//string S  S,at(i),S += T,S += c,S.size(),S.substr(l)l文字目から最後まで,
///S.substr(l, r)l文字目からl+r-1文字目 n文字目から0個で空列を返せる
//*min_element(all(x)) *max_element(all(x))
//vi x; x.back(),x.front(),x.push_back(),x.pop_back()
//swap(a, b)
//gcd(a, b)最大公約数
//sort(all(x)),reverse(all(x)),sort(x.begin()+l,a.begin()+r)lからrまで
//stack<int> a; a.push(x),a.pop(),a.top(),a.empty()bool
//queue<int> b; b.push(x),b.pop(),b.front(),b.empty()bool,b.size() 要素が小さい順
//priority_queue<int, vector<int>, greater<int>> c,c.top()
//map<int, int> M1; 変数[key] = value; 変数.erase(key); 変数.at(key); 変数.count(key)所属判定　変数.size()
//find(all(x), key)boolソート済みのベクトル
//*lower_bound(all(x),k)以上の最小の要素,*uppper_bound(all(x),k)より大きい最小の要素
//char('0'+cnt) 数字cntからcharへの変換
//int(char-'0') charからintへの変換

int a[12][12];
const int INF = 1001001001;
int main(){

    int n,m,x;
    cin >> n >> m >> x;
    vi c(n);
    rep(i,n){
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }
    int ans = INF;
    rep(s,1<<n){
        int cost = 0;
        vector<int> skill(m,0);
        rep(i,n){
            if(s&(1<<i)){
                cost += c.at(i);
                rep(j,m) skill.at(j) += a[i][j];
            }
        }
        bool ok = true;
        rep(j,m) if(skill.at(j) < x) ok = false;
        if(ok) ans = min(ans,cost);
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;

}


Measured memory_bytes: 3640
using System;
using System.Collections.Generic;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();

            var R = new List<int>();
            var G = new List<int>();
            var B = new List<int>();
            for (int i = 0; i < N; i++)
            {
                if (S[i] == 'R')
                {
                    R.Add(i);
                }
                else if (S[i] == 'G')
                {
                    G.Add(i);
                }
                else
                {
                    B.Add(i);
                }
            }

            var result = 0L;
            for (int i = 0; i < R.Count; i++)
            {
                var ix = R[i];
                for (int j = 0; j < G.Count; j++)
                {
                    var jx = G[j];
                    //for (int k = 0; k < B.Count; k++)
                    //{
                    //    var kx = B[k];

                    //    var max = Math.Max(Math.Max(ix, jx), kx);
                    //    var min = Math.Min(Math.Min(ix, jx), kx);
                    //    var mid = 0;
                    //    if (max != ix && min != ix)
                    //    {
                    //        mid = ix;
                    //    }
                    //    else if (max != jx && min != jx)
                    //    {
                    //        mid = jx;
                    //    }
                    //    else
                    //    {
                    //        mid = kx;
                    //    }

                    //    if (max - mid != mid - min)
                    //    {
                    //        result++;
                    //    }
                    //}

                    result += B.Count;

                    var d = Math.Abs(ix - jx);
                    if (B.Contains(Math.Max(ix, jx) + d))
                    {
                        result--;
                    }
                    if (B.Contains(Math.Min(ix, jx) - d))
                    {
                        result--;
                    }
                    if ((ix + jx) % 2 == 0 && B.Contains((ix + jx) / 2))
                    {
                        result--;
                    }
                }
            }

            Console.WriteLine(result);
        }
    }
}

Measured memory_bytes: 27768
n,q = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n-1)]
px = [list(map(int,input().split())) for i in range(q)]

pea  = [[] for i in range(n)]
for a,b in ab:
	a,b = a-1,b-1
	pea[a].append(b)
	pea[b].append(a)

point = [0]*n
for p,x in px:
	point[p-1] += x

ans = [0]*n
ans[0] = point[0]
visited = [False]*n
visited[0] = True
stock = [0]

while stock:
	# print('while')
	# print(stock)
	# print(ans)
	s = stock.pop()
	for p in pea[s]:
		# print('for')
		if visited[p]:
			continue
		# print(s,p)
		# print()
		visited[p] = True
		stock.append(p)
		ans[p] = ans[s]+point[p]
print(*ans)

Measured memory_bytes: 125572
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	int x;
	cin >> x;
	if (x == 7 || x == 5 || x == 3)
	{
		cout << "YES" << endl;
	}
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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


int main() {
    int n;
    float m;
    cin >> n >> m;
    vector<int> a(n);
    REP(i, n){
        cin >> a[i];
    }
    sort(a.rbegin(),a.rend());
    float sum = 0;
    REP(i, n) {
        sum += a[i];
    }
    int pop = 0;
    REP(i,n){
        if(a[i] >= sum/(4*m)){
            pop += 1;
        }
    }
    if(pop >= m){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
d = defaultdict(int)
for x in a:
  d[x] += 1
  
s = 0
for k,v in d.items():
  s += v * (v-1) // 2
for x in a:
  c = d[x] - 1
  print(s - c)

Measured memory_bytes: 26780
#include <bits/stdc++.h>
using namespace std;
struct rest{
  int num;
  string name;
  int point;
};
bool operator<(const rest& x, const rest& y){
  if(x.name<y.name){
    return true;
  } else if(x.name>y.name){
    return false;
  } else{
    return (x.point>y.point);
  }
}
int main(){
  size_t n; cin>>n;
  vector<rest> rests{n};
  {
    int i=1;
    for(auto&& r:rests){
      r.num=i; ++i;
      cin>>r.name>>r.point;
    }
  }
  sort(begin(rests),end(rests));
  for(const auto& r:rests){
    cout<<r.num<<'\n';
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
int K,N,max=0;
scanf("%d%d",&K,&N);

int A[N],dist[N];

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

dist[N-1] = K - A[N-1] + A[0];
max = dist[N-1];

for (int i = 0; i < N-1; i++)
{
  dist[i] = A[i+1] - A[i];
  if (max<dist[i])
  {
    max = dist[i];
  }
}

printf("%d",K-max);
return 0;

}

Measured memory_bytes: 3256
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

class Node {
public:
  int location;
  int p, l, r;
  Node() {}
};

class Point {
public:
  int id, x, y;
  Point() {}
  Point(int id, int x, int y): id(id), x(x), y(y) {}
  bool operator < (const Point &p) const {
    return id < p.id;
  }

  void print() {
    printf("%d\n", id);
  }
};

static const int MAX = 1000000;
static const int NIL = -1;

int N;
Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point &p1, const Point &p2) { return p1.x < p2.x; }
bool lessY(const Point &p1, const Point &p2) { return p1.y < p2.y; }

int makeKDTree(int l, int r, int depth) {
  if ( !(l < r) ) return NIL;
  int mid = (l + r) / 2;
  int t = np++;
  if ( depth % 2 == 0 ) {
    sort(P + l, P + r, lessX);
  } else {
    sort(P + l, P + r, lessY);
  }
  T[t].location = mid;
  T[t].l = makeKDTree(l, mid, depth + 1);
  T[t].r = makeKDTree(mid + 1, r, depth + 1);

  return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth,
          vector<Point> &ans) {
  int x = P[T[v].location].x;
  int y = P[T[v].location].y;

  if ( sx <= x && x <= tx && sy <= y && y <= ty ) {
    ans.push_back(P[T[v].location]);
  }

  if ( depth % 2 == 0 ) {
    if ( T[v].l != NIL ) {
      if ( sx <= x ) find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
    }
    if ( T[v].r != NIL ) {
      if ( x <= tx ) find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
    }
  } else {
    if ( T[v].l != NIL ) {
      if ( sy <= y ) find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
    }
    if ( T[v].r != NIL ) {
      if ( y <= ty ) find(T[v].r, sx, tx, sy, ty, depth  +1, ans);
    }
  }
}

int main() {
  int x, y;
  scanf("%d", &N);
  for ( int i = 0; i < N; i++ ) {
    scanf("%d %d", &x, &y);
    P[i] = Point(i, x, y);
    T[i].l = T[i].r = T[i].p = NIL;
  }

  np = 0;

  int root = makeKDTree(0, N, 0);

  int q;
  scanf("%d", &q);
  int sx, tx, sy, ty;
  vector<Point> ans;
  for ( int i = 0; i < q; i++ ) {
    scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
    ans.clear();
    find(root, sx, tx, sy, ty, 0, ans);
    sort(ans.begin(), ans.end());
    for ( int j = 0; j < ans.size(); j++ ) {
      ans[j].print();
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 15840
T = {
  ?A => '00000',
  ?B => '00001',
  ?C => '00010',
  ?D => '00011',
  ?E => '00100',
  ?F => '00101',
  ?G => '00110',
  ?H => '00111',
  ?I => '01000',
  ?J => '01001',
  ?K => '01010',
  ?L => '01011',
  ?M => '01100',
  ?N => '01101',
  ?O => '01110',
  ?P => '01111',
  ?Q => '10000',
  ?R => '10001',
  ?S => '10010',
  ?T => '10011',
  ?U => '10100',
  ?V => '10101',
  ?W => '10110',
  ?X => '10111',
  ?Y => '11000',
  ?Z => '11001',
  ?\  => '11010',
  ?. => '11011',
  ?, => '11100',
  ?- => '11101',
  ?' => '11110',
  ?? => '11111',
}.freeze
S = {
  '101' => ?\ ,
  '000000' => ?',
  '000011' => ?,,
  '10010001' => ?-,
  '010001' => ?.,
  '000001' => ??,
  '100101' => ?A,
  '10011010' => ?B,
  '0101' => ?C,
  '0001' => ?D,
  '110' => ?E,
  '01001' => ?F,
  '10011011' => ?G,
  '010000' => ?H,
  '0111' => ?I,
  '10011000' => ?J,
  '0110' => ?K,
  '00100' => ?L,
  '10011001' => ?M,
  '10011110' => ?N,
  '00101' => ?O,
  '111' => ?P,
  '10011111' => ?Q,
  '1000' => ?R,
  '00110' => ?S,
  '00111' => ?T,
  '10011100' => ?U,
  '10011101' => ?V,
  '000010' => ?W,
  '10010010' => ?X,
  '10010011' => ?Y,
  '10010000' => ?Z,
}.freeze
$<.each do |l|
  s = l.chomp.each_char.map {|c| T[c] }.join
  rs = []
  loop do
    key = S.each_key.find {|k| /^#{k}/ =~ s }
    break unless key
    rs << S[key]
    s = $'
  end
  puts rs.join
end

Measured memory_bytes: 11632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    int aa=abs(b-a),bb=abs(c-b),cc=abs(c-a);
    if((aa<=d&&bb<=d)||cc<=d) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
let () =
    let split s =
        let rec loop i cur flag acc =
            if i = String.length s then ( if flag then cur :: acc else acc) else (
                match flag, s.[i] with
                | true,  ' ' -> loop (i + 1) "" false (cur :: acc)
                | false, ' ' -> loop (i + 1) "" false acc
                | true,  v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
                | false, v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
            )
        in
        List.map int_of_string (List.rev (loop 0 "" false []))
    in
    let main () =
        let n, k = Scanf.sscanf (read_line ()) "%d %d" (fun n k -> n, k) in
        let a = Array.of_list (split (read_line ())) in
        let f = Array.of_list (split (read_line ())) in
        let () = Array.sort compare a in
        let () = Array.sort compare f in
        let init =
            let rec loop i acc =
                if i = n then acc else loop (i + 1) (max acc (a.(i) * f.(i)))
            in
            loop 0 0
        in
        let calc m =
            let rec loop i acc =
                if i = n then acc else
                    loop (i + 1) (acc + max 0 (a.(n - 1 - i) - m / f.(i)))
            in
            loop 0 0
        in
        let rec bin left right =
            if left = right then left else
                let m = (left + right) / 2 in
                let cost = calc m in
                if cost <= k then bin left m else bin (m + 1) right
        in
        let r = bin 0 init in
        Printf.printf "%d\n" r
    in
    main ()

Measured memory_bytes: 31456
N, T = map(int, input().split())
A = map(int, input().split())
mxx, mnx = 0, 10**18
for a in A:
    if a-mnx > mxx:
        c, mxx = 1, a-mnx
    elif a-mnx == mxx:
        c += 1
    mnx = min(mnx, a)
print(c)


Measured memory_bytes: 63088
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N,X;
    cin>>N>>X;
    vi v(N);
    rep(i,N) {
        cin>>v[i];
    }
    vi x(N+1);
    x[0]=0;
    int sum=0;
    rep(i,N) {
        sum+=v[i];
        x[i+1]=sum;
    }
    int counter=0;
    rep(i,N+1) {
        if(x[i]<=X) counter++;
    }
    cout<<counter<<endl;
}

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



long long A[1000],B[1000],C[1000];

int main(){
	long long n;
	cin >> n;
	for(long long i=0;i<n;i++){
		cin >> A[i] >> B[i] >> C[i];
	}
	
	long long sum;
	for(long long i=0;i<n;i++){
		sum=B[i]+A[i];
		for(long long j=i+1;j<n-1;j++){
			if(sum<=B[j]) sum=B[j]+A[j];
			else{
				long long x=sum-B[j],y=0;
				if(x%C[j]) y=1;
				x/=C[j];
				x+=y;
				sum=B[j]+A[j]+C[j]*x;
			}
		}
		cout << sum << endl;
	}
	return 0;
}

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

int main() {
  int N, M;
  scanf("%d %d", &N, &M);
  int A[N];
  int sum = 0;
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
    sum += A[i];
  }
  sort(A, A + N, [](int a, int b) {return a > b;});

  bool ans = true;
  for (int i = 0; i < M; i++) {
    if (sum > A[i] * 4 * M) {
      ans = false;
      break;
    }
  }

  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


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

int main() {
    using namespace std;
    unsigned long A, B;
    cin >> A >> B;
    for(unsigned long i{0}; i < 1000000; ++i){
        auto t = i * 2 / 25, s = i / 10;
        if(A == t && B == s){
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}

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

const int max_N = 1e5 + 21;

int n,ans;

std::pair<int,int>A[max_N];

int main(){
	scanf("%d",&n);
	for(int i=1,a;i<=n;++i){
		scanf("%d",&a);
		A[i]={a,i};
	}
	std::sort(A+1,A+1+n);
	for(int i=1;i<=n;++i)
		if((i^A[i].second)&1)++ans;
	printf("%d\n",ans>>1);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
int dist(int x1,int x2,int y1,int y2){
  return abs(x1-x2)+abs(y1-y2);
}

int main() {
  int n;
  cin>>n;
  VEC<tuple<int,int,int>>po(n);
  REP(i,0,n){
    int a,b,c;
    cin>>a>>b>>c;
    po[i]=make_tuple(a,b,c);
  }
  auto cmp = [](tuple<int,int,int> a, tuple<int,int,int> b){return get<2>(a) > get<2>(b);};
  sort(ALL(po),cmp);
  int H = 101;int W=101;
  
  REP(i,0,n){
    int a,b,c;
    tie(a,b,c)=po[i];
    cerr<<a<< " "<<b<<" "<<c<<endl;
  }

  REP(h,0,H){
    REP(w,0,W){
      int rx,ry,rh;
      tie(rx,ry,rh) = po[0];
      int ch = rh+dist(h,ry,w,rx);
      bool ok  =1;
      REP(i,1,n){
        int tx,ty,th;
        tie(tx,ty,th)=po[i];
        int th2 = max(ch-dist(h,ty,w,tx), 0);
        if(th!=th2){
          ok = 0;
          break;
        }
      }
      if(ok){
        cout<<w<<" "<<h<<" "<<ch;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
fun main(arr: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toLong() }
    val rain = LongArray(n)
    for(i in 2 until n step 2) {
        val diff = a[i] - a[i-1]
        rain[i] = rain[i-2] + diff * 2
    }
    rain[1] = rain.last() + (a[1] - a[0]) * 2
    for(i in 3 until n step 2) {
        val diff = a[i] - a[i-1]
        rain[i] = rain[i-2] + diff * 2
    }
    val ans = rain.dropLast(1).toMutableList()
    ans.add(0, rain.last())
    val adj = a[0] - (ans[1] + ans[0])/2
    println(ans.map { it+adj }.joinToString(" "))
}


Measured memory_bytes: 65944
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left, bisect_right
from functools import lru_cache
MOD = int(1e9)+7
INF = float('inf')


def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    xd = [0] * n
    ans = []
    for i in range(n-1,-1,-1):
        cnt = 0
        for j in range(i, n, i + 1):
            cnt += xd[j]
        cnt %= 2
        if cnt != a[i]:
            ans.append(i + 1)
            xd[i] = 1
    ans.reverse()
    print(len(ans))
    if ans:
        print(*ans)
        

    
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""


"""


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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	int mx=*max_element(a.begin(),a.end());
	int mn=*min_element(a.begin(),a.end());

	if(mx-mn>=2){
		puts("No");
	}
	else if(mx-mn==0){
		if(mx==n-1 || mx<=n/2) puts("Yes");
		else                   puts("No");
	}
	else{
		int c1=count(a.begin(),a.end(),mn);
		int c2=n-c1;
		if(1<=mn-c1+1 && mn-c1+1<=c2/2) puts("Yes");
		else                            puts("No");
	}

	return 0;
}


Measured memory_bytes: 640
#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<int,int>
#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:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};
//スタート点,頂点数、辺を渡して、最短経路の配列を返す
std::vector<int> dijkstra(int s,int N,vector<Edge> E){
    std::vector<int> ans(N,INF);
    std::vector<std::vector<Edge>> Edges(N);
    FOREACH(e,E){
        Edges.at(e.from).push_back(e);
    }
    priority_queue<P, std::vector<P>, greater<P>> que;
    ans.at(s)= 0;
    que.push(make_pair(0,s));
    while(!que.empty()){
        P p = que.top();que.pop();
        if(ans.at(p.second) < p.first)continue;
        for(int i = 0;i < Edges.at(p.second).size();i++){
            if(ans.at(p.second) + Edges.at(p.second).at(i).value < ans.at(Edges.at(p.second).at(i).to)){
                ans.at(Edges.at(p.second).at(i).to) = ans.at(p.second) + Edges.at(p.second).at(i).value;
                que.push(make_pair(ans.at(Edges.at(p.second).at(i).to),Edges.at(p.second).at(i).to));
            }
        }
    }
    return ans;
}
int main(){
    string str;cin >> str;
    CIN(w);
    int s = 0;
    w--;
    cout<<str.at(0);
   for(int a = 1;a < str.size();a++){
       if(s==w){
           s=0;
           cout<<str.at(a);
       }else{
           s++;
       }
   }
   cout<<endl;
    return 0;
}


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

int n;
string s;
bool dp[30009][4][1009];

int main() {
    cin >> n >> s;
    dp[0][0][0] = true;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= 3; ++j) {
            for (int k = 0; k <= 999; ++k) {
                if (dp[i][j][k] == false) continue;
                dp[i + 1][j][k] = true;
                if (j <= 2) {
                    dp[i + 1][j + 1][10 * k + s[i] - '0'] = true;
                }
            }
        }
    }
    int ans = 0;
    for (int k = 0; k <= 999; ++k) {
        if (dp[n][3][k]) ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 118528
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef vector<int> vi;
    typedef vector<long long> vll;
    typedef vector<pair<int , int>> vpii;
    typedef pair<int , int> pii;
    typedef pair<long long  , long long> pll;
    typedef pair<double , double> pdd;
    #define eb emplace_back;
    #define mp make_pair;
     
    int main(){
        string s;
        cin>>s;
        if(s[0] == '7' || s[1] == '7' || s[2] == '7'){
            cout<<"Yes";
        }
        else{
            cout<<"No";
        }
        return 0;
    }

Measured memory_bytes: 3628