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

class PriorityQueue {
public:
    PriorityQueue() : size(0) {}
    
    void insert(int k)
    {
        if ( size == data.size() ) {
            data.push_back(k);
            size++;
        } else {
            data[size++] = k;
        }
        int pos = size - 1;
        while ( pos > 0 && data[(pos - 1) / 2] < data[pos] ) {
            swap(data[(pos - 1) / 2], data[pos]);
            pos = (pos - 1) / 2;
        }
    }
    
    int extract()
    {
        int ret = data[0];
        data[0] = data[--size];
        maxHeapify(0);
        return (ret);
    }

private:
    vector < int > data;
    int size;
    
    void maxHeapify(int node)
    {
        int l = node * 2 + 1, r = node * 2 + 2;
        int largest = node;
        if ( l < size && data[l] > data[node] ) largest = l;
        if ( r < size && data[r] > data[largest] ) largest = r;
        if ( largest != node ) {
            swap(data[largest], data[node]);
            maxHeapify(largest);
        }
    }
};

int main()
{
    string query;
    PriorityQueue tree;

    while ( cin >> query, query != "end" ) {
        if ( query == "insert" ) {
            int value;
            cin >> value;
            tree.insert(value);
        } else if ( query == "extract" ) {
            cout << tree.extract() << endl;
        }
    }

    return (0);
}



Measured memory_bytes: 7052
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int str1,str2,i,flag=1;
    char a[110],b[110];
    gets(a);
    gets(b);
    str1=strlen(a);
    str2=strlen(b);
    sort(a,a+str1);
    sort(b,b+str2);
    if(str1<str2)
    {
        for(i=0;i<str1;i++)
        {
            if(a[i]<b[str2-i-1])
            {
                cout<<"Yes"<<endl;
                flag=0;
                break;
            }
            else if(a[i]>b[str2-i-1])
            {
                cout<<"No"<<endl;
                flag=0;
                break;
            }
        }
        if(flag==1)
        {
            cout<<"Yes"<<endl;
        }
    }
    else
    {
        for(i=0;i<str2;i++)
        {
            if(a[i]<b[str2-i-1])
            {
                cout<<"Yes"<<endl;
                flag=0;
                break;
            }
            else if(a[i]>b[str2-i-1])
            {
                cout<<"No"<<endl;
                flag=0;
                break;
            }
        }
        if(flag==1)
        {
            cout<<"No"<<endl;
        }   
    }
}

Measured memory_bytes: 256
N, X = map(int, input().split())
x = list(map(int, input().split()))
for i in range(N):
    x[i] -= X


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


g = x[0]
for i in range(1, N):
    g = gcd(g, x[i])


print(abs(g))




Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

int main() {
	int A, B, K;
	cin >> A >> B >> K;

	int m = min(A, B);
	vector<int> v;

	for (int i = 1; i <= m; i++) {
		if ((A % i == 0) && (B % i == 0)) {
			v.push_back(i);
		}
	}
	reverse(v.begin(), v.end());

	cout << v[K - 1] << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

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

  vector<vector<mint>> dp(n + 1, vector<mint>(s + 1, 0));

  dp[0][0] = 1;
  for (int i = 1; i < n + 1; i++)
  {
    vector<mint> dp_new(s + 1, 0);

    for (int j = 0; j < s + 1; j++)
    {
      if (j + a[i - 1] <= s)
      {
        dp_new[j + a[i - 1]] += dp[i - 1][j];
      }
    }

    for (int j = 0; j < s + 1; j++)
    {
      dp[i][j] = dp[i - 1][j] * 2 + dp_new[j];
    }
  }

  cout << dp[n][s] << endl;
}


Measured memory_bytes: 73748
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    double A, B, H, M; cin >> A >> B >> H >> M;
    double md = M * 6;
    double hd = H * 30 + M * 0.5;
    double diff = abs(md - hd);
    if (diff > 180) diff = 360 - diff;
    double ans = sqrt(pow(A, 2) + pow(B, 2) - 2 * A * B * cos(diff * M_PI / 180.0));
    printf("%.12lf\n", ans);
    return 0;
}

Measured memory_bytes: 4256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int n,ans=0;
    cin>>n;
    string s,t;
    cin>>s>>t;
    for(int i=0;i<n;i++){
        int cnt=0,j=0;
        for(int pos=i;pos<n;pos++){
            if(s[pos]==t[j]) cnt++;
            j++;
        }
        if(n-i==cnt){
            ans=(cnt+i*2);
            break;
        }else if(i==n-1) ans=2*n;
    }
    cout<<ans<<endl;
    return 0;
}


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

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

    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n), c(m), d(m);
    rep(i, n) cin >> a[i] >> b[i];
    rep(i, m) cin >> c[i] >> d[i];

    rep(i, n){
        int res = -1;
        int mn = 1001001001;
        rep(j, m){
            int di = abs(a[i]-c[j]) + abs(b[i]-d[j]);
            if(di < mn){
                mn = di;
                res = j+1;
            }
        }
        cout << res << endl;
    }   

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define MAX_N 100000
typedef long long ll;
using namespace std;

int n;
ll activities[MAX_N + 1][3], dp_arr[MAX_N + 1][3] = {{-1, -1, -1}};

ll dp(int day, int last) {
    if (day == n + 1) {
        // cout << day << ' ' << last << " JINKIES!\n";
        return 0;
    } else if (dp_arr[day][last] != -1) {
        // cout << dp_arr[day][last] << " ZOOP!\n";
        return dp_arr[day][last];
    } else {
        // cout << day << ' ' << last << " REE!\n";
        switch (last) {
            case 0:
                return dp_arr[day][last] =
                           max(dp(day + 1, 1) + activities[day][1],
                               dp(day + 1, 2) + activities[day][2]);
            case 1:
                return dp_arr[day][last] =
                           max(dp(day + 1, 0) + activities[day][0],
                               dp(day + 1, 2) + activities[day][2]);
            case 2:
                return dp_arr[day][last] =
                           max(dp(day + 1, 0) + activities[day][0],
                               dp(day + 1, 1) + activities[day][1]);
            default:
                return dp_arr[day][0] = max(max(dp(day + 1, 0) + activities[day][0],
                               dp(day + 1, 1) + activities[day][1]),
                           dp(day + 1, 2) + activities[day][2]);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    FOR(i, 1, n + 1) {
        cin >> activities[i][0] >> activities[i][1] >> activities[i][2];
        dp_arr[i][0] = -1;
        dp_arr[i][1] = -1;
        dp_arr[i][2] = -1;
    }
    cout << dp(1, -1) << '\n';
    // FOR(i, 1, n + 1) {
    //     cout << dp_arr[i][0] << ' ' << dp_arr[i][1] << ' ' << dp_arr[i][2] << '\n';
    // }
    return 0;
}

Measured memory_bytes: 9600
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

/*

10 3
1 2 3

10 3
1 2 9

*/

fn main() {
    let (K, N) = read!(i64, usize);
    let A = read![[i64]];

    let mut d = vec![0; N];
    for i in 0..N - 1 {
        d[i] = A[i + 1] - A[i];
    }
    d[N - 1] = (A[0] + K) - A[N - 1];

    let x = K - d.iter().max().unwrap();

    println!("{}", x)
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
typedef signed long long lint;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  lint n;
  cin >> n;
  n--;
  string s = "";
  while (n >= 0) {
    s += ('a'+n%26);
    n /= 26;
    n--;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main(void) {
	int n, q, a, b, c;
	char ch;
	string s;
	cin >> n >> s >> q;
	vector<set<int>> pos(26);
	rep(i, 0, n) {
		pos[s[i] - 'a'].insert(i + 1);
	}
	rep(i, 0, q) {
		cin >> a >> b;
		if (a == 1) {
			cin >> ch;
			rep(i2, 0, 26) {
				if (pos[i2].find(b) != pos[i2].end()) {
					pos[i2].erase(b);
					pos[ch - 'a'].insert(b);
					break;
				}
			}
		}
		else {
			int cnt = 0;
			cin >> c;
			rep(i2, 0, 26) {
				auto it = pos[i2].lower_bound(b);
				if (it != pos[i2].end() && *it <= c)cnt++;
			}
			printf("%d\n", cnt);
		}
	}
	return 0;
}


Measured memory_bytes: 27096
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_set>
# include <unordered_map>
using namespace std;


long long ans, x;
pair<long long, long long> a[10005];
int n;

int main(int argc, const char * argv[]) {
#ifdef __APPLE__
    freopen("/Users/danya.smelskiy/Documents/Danya/Resources/input.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i].first;
    }
    for (int i = 1; i <= n; ++i) {
        cin >> x;
        ans += max(0ll, a[i].first - x);
    }
    cout << ans << '\n';
}



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

int main(){
	ll n,m;
	cin>>n>>m;
	ll ans=n;
	ll h[n]={};
	bool c[n]={};
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		if(h[a]>h[b]){
			if(!c[b]){
				ans--;
			}
			c[b]=true;
		}else if(h[a]<h[b]){
			if(!c[a]){
				ans--;
			}
			c[a]=true;
		}else{
			if(!c[a]){
				ans--;
			}
			if(!c[b]){
				ans--;
			}
			c[a]=true;
			c[b]=true;
		}
		//cout<<ans<<endl;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4472
from collections import Counter
N, M = map(int, input().split())
countab = Counter()
for i in range(M):
    a, b = map(int, input().split())
    countab[a] += 1
    countab[b] += 1
ans = True
for k, v in countab.items():
    if v % 2 == 0:
        continue
    ans = False
    break
if ans:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 51672
a,b=map(int,input().split())
Mod=10**9+7

if abs(a-b)>1:
  print(0)
elif abs(a-b)==1:
  ans=max(a,b)
  for i in range(2,max(a,b)):
    ans*=(i*i)
    ans%=Mod
  print(ans)
else:
  ans=2
  for i in range(2,a+1):
    ans*=(i*i)
    ans%=Mod
  print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main() 
{ 
	SPEED
    int a, b;
    cin >> a >> b;
    if ((a&1 && !(b&1)) || (b&1 && !(a&1)))
    {
        cout << "IMPOSSIBLE" << '\n';
    }
    else
    {
        cout << (a+b)/2 << '\n';
    }
    return 0;      
} 

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL h, w;
int n, a[100000], b[100000];
LL ans[10];

int main() {
	cin >> h >> w >> n;
	inc(i, n) { cin >> a[i] >> b[i]; }
	
	ans[0] = (h - 2) * (w - 2);
	
	map<pair<int, int>, int> m;
	inc(i, n) { m[ MP(a[i], b[i]) ] = 1; }
	
	vector<pair<int, int>> v;
	inc(i, n) {
		incII(j, a[i] - 1, a[i] + 1) {
		incII(k, b[i] - 1, b[i] + 1) {
			if(! inID(j, 2, h)) { continue; }
			if(! inID(k, 2, w)) { continue; }
			v.EB(j, k);
		}
		}
	}
	sort(ALL(v));
	inc(i, v.size()) {
		if(i != 0 && v[i] == v[i - 1]) { continue; }
		
		int x = 0;
		incII(j, v[i].FI - 1, v[i].FI + 1) {
		incII(k, v[i].SE - 1, v[i].SE + 1) {
			x += m[ MP(j, k) ];
		}
		}
		ans[x]++;
		ans[0]--;
	}
	
	inc(i, 10) {
		cout << ans[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 164588
/* kadai3_4
   nabe9393 */
 
#include<stdio.h>
 
int main(void){
  int number, divisor, answer=0; //answerの値で判断。
  scanf("%d", &number ); //入力
  for(divisor=1; divisor < 10; divisor++){ //初期化　条件判定　更新
    if(number % divisor == 0 && number / divisor < 10){ //割り切れて尚且つ商が１０未満
      answer++; //answerに１を足す
    }
  }
  if(answer != 0){ //answerが０ではない時がYes
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
} 

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

string cast(int n){
  string ans;
  int flag = 0;
  if(n/10000){
    ans.push_back(n/10000+'0');
    n -= (n/10000)*10000;
    flag = 1;
  }
  if(n/1000 || flag == 1){
    ans.push_back(n/1000+'0');
    n -= (n/1000)*1000;
    flag = 1;
  }
  if(n/100 || flag == 1){
    ans.push_back(n/100+'0');
    n -= (n/100)*100;
    flag = 1;
  }
  if(n/10 || flag == 1){
    ans.push_back(n/10+'0');
    n -= (n/10)*10;
  }
  ans.push_back(n+'0');
  return ans;
}

int main(){
  int i,j,k;
  int m,n,r;
  char a[1000];
  string s,tmp;

  while(1){
    cin >> m >> n;
    if(!m && !n)break;

    for(i=0;i<m;i++)a[i] = '1';

    r = m;
    j = 0;
    k = 0;
    for(i=0;i<n;i++){
      cin >> s;
      if(r!=1){	
	while(a[k]!='1'){
	  k++;
	  if(k==m)k=0;
	}
	j++;
	if(j%3){
	  if(j%5){
	    tmp = cast(j);
	    if(s!=tmp){
	      a[k] = '0';
	      r--;
	    }
	  }else{
	    if(s!="Buzz"){
	      a[k] = '0';
	      r--;
	    } 
	  }
	}else{
	  if(j%5){
	    if(s!="Fizz"){
	      a[k] = '0';
	      r--;
	    } 
	  }else{
	    if(s!="FizzBuzz"){
	      a[k] = '0';
	      r--;
	    }
	  } 
	}
      }
      k++;
      if(k==m)k=0;
    }

    for(i=0;i<m;i++){
      if(a[i]=='1'){
	cout << i+1;
	r--;
	if(r!=0)cout << " ";
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 932
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll

int n, m, k, a[300010], q, l, r;
string s, t;
int32_t main(){
INIT
cin>>s>>t;
int mn=10e9;
for(int i=0; (i+t.length()-1)<s.length(); i++){
    int cr=0;
    for(int j=0; j<t.length(); j++){
        if(s[i+j]!=t[j]){cr++;}
    }
    mn=min(mn, cr);
}
cout<<mn;
return 0;
}





Measured memory_bytes: 3648
//naveen mall
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto i: a)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        fl(i,0,n){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";cout<<"\n";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define PB                pop_back
#define endl              "\n"
#define what(x) cerr <<  #x << " is " << x << endl;
int sum() { return 0; }template<typename T,typename... Args>T sum(T a, Args... args) { return a + sum(args...); }

vec<int> v[200000+5];
 
void solve()
{  int n;
	cin>>n;
	rep(i,2,n+1)
	  {
	  	int a;
	  	cin>>a;
	  	v[a].pb(i);
	  }
	  rep(i,1,n+1)
	    cout<<sz(v[i])<<endl;
 
 
}
signed main()
{fast
    int t;
 t=1;
  //cin>>t;
  while(t--)
     {
      solve();
     }
 
 
 
}


Measured memory_bytes: 14480
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,p,q;
    cin >> N;
    vector<int> students(N);
    for(int i = 0; i < N; i++){
        cin >> students[i];
    }
    vector<int> ans(N);
    for(int i = 0; i < N; i++){
      p = students[i];
      ans[p- 1] = i + 1;
    }
    for(int i = 0; i < N; i++){
    if(i < N - 1)
   cout << ans[i] << " ";
   if(i == N - 1)
   cout << ans[i] << endl;
    }
} 

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    int l,r,d;
    cin>>l>>r>>d;
    int count=0;
    for(int i=l; i<=r; i++){
        if(i%d==0)
        count++;
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3632
import bisect
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = list(map(int, input().split()))


ans = 0
for b in B:
    r = bisect.bisect_right(A, b)
    l = bisect.bisect_left(A, b)
    if r != l:
        ans += 1
print(ans)


Measured memory_bytes: 16736
def lis(A: list):
    # https://ikatakos.com/pot/programming_algorithm/dynamic_programming/longest_common_subsequence
    from bisect import bisect_left
    L = [A[0]]
    for a in A[1:]:
        if a > L[-1]:
            # Lの末尾よりaが大きければ増加部分列を延長できる
            L.append(a)
        else:
            # そうでなければ、「aより小さい最大要素の次」をaにする
            # 該当位置は、二分探索で特定できる
            L[bisect_left(L, a)] = a
    return len(L)

from math import pi
from operator import itemgetter
x1, y1, x2, y2 = map(int, input().split())
if x1 > x2:
    x1, x2 = x2, x1
    y1, y2 = y2, y1
xmin, xmax = sorted([x1, x2])
ymin, ymax = sorted([y1, y2])
N = int(input())
XY = []
for _ in range(N):
    X, Y = map(int, input().split())
    if xmin <= X <= xmax and ymin <= Y <= ymax:
        XY.append([X, Y])
if len(XY)==0:
    print(100*(xmax-xmin + ymax-ymin))
#elif x1==x2 or y1==y2:
#    print(100*(xmax-xmin + ymax-ymin) + (10*pi-20))
else:
    XY.sort()
    Y = list(map(itemgetter(1), XY))
    if y1 > y2:
        Y = Y[::-1]
    lis_ = lis(Y)
    if lis_==ymax-ymin+1 or lis_==xmax-xmin+1:
        lis_ -= 1
        print(100*(xmax-xmin + ymax-ymin) + (5*pi-20)*lis_ + (10*pi-20))
    else:
        print(100*(xmax-xmin + ymax-ymin) + (5*pi-20)*lis_)


Measured memory_bytes: 41884
#include <stdio.h>
#include <math.h>
int main (void)
{
  double r, c_m, c_r;
  scanf("%lf", &r);
  c_m = r * r * M_PI;
  c_r = 2 * r * M_PI;
  printf("%f %f\n", c_m, c_r);
  return 0;
}

Measured memory_bytes: 1804
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;

class UnionFind {
public:
	vector<int> par;

	UnionFind(int n) {
		par = vector<int>(n, -1);
	}

	int root(int a) {
		if (par[a] < 0) {
			return a;
		}
		else {
			return par[a] = root(par[a]);
		}
	}

	int size(int a) {
		return -par[root(a)];
	}

	bool connect(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b) {
			return false;
		}
		if (size(a) < size(b)) {
			swap(a, b);
		}
		par[a] += par[b];
		par[b] = a;
		return true;
	}

};

int main() {
	int n, m;
	cin >> n >> m;
	vector<p> bri(m);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		bri[i].first = a - 1;
		bri[i].second = b - 1;
	}
	vector<ll> ans(m);
	ans[m - 1] = (ll)n * (n - 1) / 2;
	UnionFind Uni(n);
	repd(i, m-1) {
		ans[i - 1] = ans[i];
		if (Uni.root(bri[i].first) != Uni.root(bri[i].second)) {
			ans[i - 1] -= (ll)Uni.size(bri[i].first)*Uni.size(bri[i].second);
			Uni.connect(bri[i].first, bri[i].second);
		}
	}
	rep(i, m){
		cout << ans[i] << endl;
	}
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
	int n,q;
	cin >> n >> q;
	vector<lli> a(n);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	vector<lli> x(q);
	for(int i=0; i<q; i++){
		cin >> x[i];
	}
	vector<lli> sumall(n+1, 0), sumeven(n+1, 0), sumodd(n+1, 0);
	for(int i=0; i<n; i++){
		sumall[i+1] = sumall[i]+a[i];
		if(i%2==0){
			if(i==0){
				sumeven[i+1] = a[i];
			}else{
				sumeven[i+1] = sumeven[i-1]+a[i];
			}
		}else{
			sumodd[i+1] = sumodd[i-1]+a[i];
		}
	}

	for(int i=0; i<q; i++){
		int lb=1, ub=n; //高橋君が取れる枚数(lb:ok, ub:ng)
		//cout << "i=" << i << endl;
		while(ub-lb > 1){
			int mid = (lb +ub)/2;
			//a[n-mid] まで高橋君が取れる 
			//== 青木君はmid-1手でa[n-mid]が取れない
			//== a[n-mid]よりも距離が近いものをすべて取るとmid-1より大きくなる
			lli dist = abs(x[i] -a[n-mid]);
			lli minimum = x[i]-dist;
			auto itr = lower_bound(a.begin(), a.end(), minimum);
			lli num = n-mid -(itr -a.begin()) +1;
			if(num > mid-1){
				//ok
				lb = mid;
			}else{
				//ng
				ub = mid;
			}
			//cout << lb << " " << ub << endl;
			//cout << dist << " " << minimum << " " << num << endl;
		}
		//cout << lb << endl;
		lli ans = 0;
		ans += sumall[n] -sumall[n-lb];
		int rem = n- 2*lb;
		if(rem > 0){
			if(rem %2 == 0){
				ans += sumodd[rem];
			}else{
				ans += sumeven[rem];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 5632
#include<iostream>
using namespace std;
int main()
{
  int k,x;
  cin>>k>>x;
  if(k==1)
    cout<<x;
  else
  {
    if(k==0)
    {
      for(int i=x-1;i<=x+1;i++)
        cout<<i<<" ";
    }
    else
    {
    for(int i=x-k+1;i<=k+x-1;i++)
      cout<<i<<" ";
    }
    
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstring>

using namespace std;

void east_change(int dice[]){
	int copy_dice[6];
	memcpy(copy_dice, dice, 6*sizeof(*dice));
	for(int i = 0; i < 6; i++){
		if(i + 1 == 1){
			dice[i] = copy_dice[3];
		}else if(i + 1 == 3){
			dice[i] = copy_dice[0];
		}else if(i + 1 == 4){
			dice[i] = copy_dice[5];
		}else if(i + 1 == 6){
			dice[i] = copy_dice[2];
		}
	}
}

void south_change(int dice[]){
	int copy_dice[6];
	memcpy(copy_dice, dice, 6*sizeof(*dice));
	for(int i = 0; i < 6; i++){
		if(i + 1 == 1){
			dice[i] = copy_dice[4];
		}else if(i + 1 == 2){
			dice[i] = copy_dice[0];
		}else if(i + 1 == 5){
			dice[i] = copy_dice[5];
		}else if(i + 1 == 6){
			dice[i] = copy_dice[1];
		}
	}
}

void west_change(int dice[]){
	int copy_dice[6];
	memcpy(copy_dice, dice, 6*sizeof(*dice));
	for(int i = 0; i < 6; i++){
		if(i + 1 == 1){
			dice[i] = copy_dice[2];
		}else if(i + 1 == 3){
			dice[i] = copy_dice[5];
		}else if(i + 1 == 4){
			dice[i] = copy_dice[0];
		}else if(i + 1 == 6){
			dice[i] = copy_dice[3];
		}
	}
}

void north_change(int dice[]){
	int copy_dice[6];
	memcpy(copy_dice, dice, 6*sizeof(*dice));
	for(int i = 0; i < 6; i++){
		if(i + 1 == 1){
			dice[i] = copy_dice[1];
		}else if(i + 1 == 2){
			dice[i] = copy_dice[5];
		}else if(i + 1 == 5){
			dice[i] = copy_dice[0];
		}else if(i + 1 == 6){
			dice[i] = copy_dice[4];
		}
	}
}

int main(){
	int dice[6];
	char direction[100];
	for(int i = 0; i < 6; i++) scanf("%d",&dice[i]);
	scanf("%s", direction);
	int i = 0;
	while(true){
		if(std::strncmp(&direction[i], "E", 1) == 0 ){
			east_change(dice);
		}else if(std::strncmp(&direction[i], "S", 1) == 0 ){
			south_change(dice);
		}else if(std::strncmp(&direction[i], "W", 1) == 0 ){
			west_change(dice);
		}else if(std::strncmp(&direction[i], "N", 1) == 0 ){
			north_change(dice);
		}else{
			break;
		}
		//for(int j = 0; j < 6; j++) printf("%d ",dice[j]);
		//printf("\n");
		i++;
	}
	printf("%d\n", dice[0]);

}

/*

1 2 4 8 16 32
SE

1 2 4 8 16 32
EESWN

*/


Measured memory_bytes: 2760
#include <stdio.h>

#define MAX 100000
#define SENTINEL 2000000000

typedef struct{
  char suit;
  int value;
}Card;

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

void merge(Card A[], int n, int left, int mid, int right){
  int i, j, k;
  int n1 = mid - left;
  int 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].value = R[n2].value = SENTINEL;

  i=j=0;

  for(k=left; k<right; k++){
    if(L[i].value<=R[j].value){
      A[k]=L[i++];
    }
    else{
      A[k]=R[j++];
    }
  }
}

void mergeSort(Card A[], int n, int left, int right){
  int mid;

  if(left+1 < right){
    mid=(left+right)/2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int partition(Card A[], int n, int p, int r){
  int i, j;
  Card t, x;
  x=A[r];
  i=p-1;
  for(j=p; j<r; j++){
    if(A[j].value <= x.value){
      i++;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;

  return i+1;
}

void quickSort(Card A[], int n, int p, int r){
  int q;

  if(p<r){
    q=partition(A, n, p, r);
    quickSort(A, n, p, q-1);
    quickSort(A, n, q+1, r);
  }
}

int main(){
  int n, i, v;
  Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    scanf("%s %d", S, &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A, n, 0, n);
  quickSort(B, n, 0, n-1);

  for(i=0; i<n; i++){
    if(A[i].suit != B[i].suit) stable=0;
  }

  if(stable ==1) printf("Stable\n");
  else printf("Not stable\n");

  for(i=0; i<n; i++){
    printf("%c %d\n",B[i].suit, B[i].value);
  }

  return 0;
}

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

#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define FORN(i, m, n) for(int (i) = (m); (i) <= (n); (i)++)
#define FORR(i, m, n) for(int (i) = (m); (i) >= (n); (i)--)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
typedef long long ll;
typedef pair<ll, ll> P;

struct Edge{
	int to;
	int cost;
};

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;
const int MAX_N = 1e5;
vector<vector<Edge> > tree;
ll dist[MAX_N] = {};

int main(void){
	int n, m;
	cin >> n >> m;
	tree.resize(n);
	fill_n(dist, n, LINF);
	repn(i, n-1){
		Edge e = {i-1, 0};
		tree[i].pb(e);
	}

	rep(i, m){
		int l, r, c;
		cin >> l >> r >> c;
		l--; r--;
		Edge e = {r, c};
		tree[l].pb(e);
	}

	priority_queue<P, vector<P>, greater<P> > q;
	q.push(mp(0, 0));
	while(!q.empty()){
		P p = q.top(); q.pop();
		if(p.fs >= dist[p.sc]) continue;
		dist[p.sc] = p.fs;
		rep(i, tree[p.sc].size()){
			Edge e = tree[p.sc][i];
			q.push(mp(p.fs+e.cost, e.to));
		}
	}

	if(dist[n-1] == LINF) co(-1);
	else co(dist[n-1]);

	return 0;
}


Measured memory_bytes: 9332
import * as fs from 'fs';

export function Main(input: string) {
    const lines = input.split('\n');    // ?
    const k = parseInt(lines[0]);   // ?
    const s = lines[1];

    let result = '';

    if(s.length <= k) {
        result = s;
    } else {
        result = `${s.substr(0, k)}...`;
    }

    //output

    console.log(result);
}

// Don't edit this line!
Main(fs.readFileSync("/dev/stdin", "utf8"));


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

using namespace std;

typedef long long ll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> a(3 * n);
	for (int i = 0; i < 3 * n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	vector<ll> b(n);
	for (int i = 3 * n - 2, j = 0; j < n; i -= 2, j++) {
		b[j] = a[i];
	}
	cout << accumulate(b.begin(), b.end(), 0LL) << endl;
	return 0;
}

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

namespace TYC
{
	typedef long long ll;
	typedef pair<ll, int> pa;
	const int N = 2010, INF = 0x3f3f3f3f;
	const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;

	int n, S, T, Head[N], Pre[N], Vis[N];
	ll H[N], Dis[N];
	struct edge { int to, next, w, c; } E[N * 20];

	inline int read()
	{
		int x = 0, f = 0, ch = getchar();
		while (!isdigit(ch))
			f |= (ch == '-'), ch = getchar();
		while (isdigit(ch))
			x = x * 10 + ch - '0', ch = getchar();
		return f ? -x : x;
	}

	void add(const int u, const int v, const int w, const int c)
	{
		static int ecnt = 1;
		E[++ecnt] = (edge){v, Head[u], w, c};
		Head[u] = ecnt;
		E[++ecnt] = (edge){u, Head[v], 0, -c};
		Head[v] = ecnt;
	}

	void spfa()
	{
		static queue<int> Q;
		Q.push(S);
		fill(H + 1, H + T + 1, -INFLL);
		H[S] = 0;
		while (!Q.empty())
		{
			int u = Q.front();
			Q.pop();
			Vis[u] = 0;
			for (int i = Head[u]; i; i = E[i].next)
			{
				int v = E[i].to;
				if (E[i].w && H[v] < H[u] + E[i].c)
				{
					H[v] = H[u] + E[i].c;
					if (!Vis[v])
						Q.push(v), Vis[v] = 1;
				}
			}
		}
	}

	bool Dijkstra()
	{
		static priority_queue<pa> Q;
		memset(Vis, 0, sizeof(int[T + 1]));
		fill(Dis + 1, Dis + T + 1, -INFLL);
		Q.push(pa(Dis[S] = 0, S));
		while (!Q.empty())
		{
			int u = Q.top().second; 
			Q.pop();
			if (Vis[u])
				continue;
			Vis[u] = 1;
			for (int i = Head[u]; i; i = E[i].next)
			{
				int v = E[i].to;
				ll w = E[i].c + H[u] - H[v];
				if (E[i].w && Dis[v] < Dis[u] + w)
				{
					Pre[v] = i;
					Dis[v] = Dis[u] + w;
					Q.push(pa(Dis[v], v));
				}
			}
		}
		return Dis[T] != -INFLL;
	}

	ll mcmf()
	{
		spfa();
		ll ans = 0;
		while (Dijkstra())
		{
			int flow = INF;
			for (int i = Pre[T]; i; i = Pre[E[i ^ 1].to])
				flow = min(flow, E[i].w);
			for (int i = Pre[T]; i; i = Pre[E[i ^ 1].to])
				E[i].w -= flow, E[i ^ 1].w += flow;
			ans += (ll)flow * (Dis[T] - H[S] + H[T]);
			for (int i = 1; i <= T; i++)
				H[i] += Dis[i];
		}
		return ans;
	}

	void work()
	{
		n = read();
		S = (n << 1) + 1, T = S + 5;
		for (int i = 1; i <= n; i++)
		{
			int x = read(), y = read();
			add(S, i, read(), 0);
			add(i, S + 1, INF, +x + y);
			add(i, S + 2, INF, +x - y);
			add(i, S + 3, INF, -x + y);
			add(i, S + 4, INF, -x - y);
		}
		for (int i = n + 1; i <= (n << 1); i++)
		{
			int x = read(), y = read();
			add(i, T, read(), 0);
			add(S + 1, i, INF, -x - y);
			add(S + 2, i, INF, -x + y);
			add(S + 3, i, INF, +x - y);
			add(S + 4, i, INF, +x + y);
		}
		printf("%lld\n", mcmf());
	}
}

int main()
{
	TYC::work();
	return 0;
}

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

using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<long> A(N+1);
    vector<long> B(N);

    for(int i=0;i<=N;i++)
        cin>>A[i]; 
    for(int i=0;i<N;i++)
        cin>>B[i]; 

    long sum = 0; 
    long t=0; 
    for(int i=0;i<N;i++)
    {
        //cout<<" min " <<min(A[i],B[i])<<endl; 
        t = min(A[i],B[i]); 
        sum += t; 
        A[i] -=t; 
        B[i] -=t; 

        //cout<<" min " <<min(A[i+1],B[i])<<endl; 
        t = min(A[i+1],B[i]);
        sum += t;
        A[i+1] -=t;
        B[i] -=t;

    }
    cout<< sum<<endl; 
    return 0; 
}


Measured memory_bytes: 1792
s=input()
sento1 = 0
sento0 = 0
for i in range(len(s)):

  if i % 2 == 0:
    
    if s[i] == '1':
      sento1 += 1
      
    elif s[i] == '0':
      sento0 += 1
      
  else:
    if s[i] == '0':
      sento1 += 1
    elif s[i] == '1':
      sento0 += 1
      
print(min(sento1,sento0))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
signed main(void) {
    string s;cin>>s;
    int n=s.size();
    if(n%2==1){
        cout<<"No"<<endl;
        return 0;
    }
    for(int i=0;i<n;i+=2){
        if(s[i]!='h'||s[i+1]!='i'){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
int a[N], b[N];
int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vector<int> ans;
    for(int i = n; i >= 1; i--) {
        int c = 0;
        for(ll j = i*2; j <= n; j += i) {
            c += b[j];
        }
        b[i] = (c&1) != a[i];
        if(b[i]) ans.push_back(i);
    }
    cout << ans.size() << '\n';
    for(int i = 0; i < ans.size(); i++) {
        cout << ans[i] << '\n';
    }
    return 0;
}

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

int main() {
 long long n;
  cin>>n;
  long long a[n];
  map<int,long long> freq;
  for(long long i=0;i<n;i++)
  {
    cin>>a[i];
    freq[a[i]]++;
    
  }

  long long answer=0;
  for(auto i=freq.begin();i!=freq.end();++i)
  {
    long long count = i->second;
      answer+=(count*(count-1))/2;
  }
  for(long long i=0;i<n;i++)
  {

      cout<<answer-freq[a[i]]+1<<endl;
  
  }
  
	return 0;
}


Measured memory_bytes: 11008
import { readFileSync } from 'fs'

const RED_STONE = 'R'

function main(input: string) {
  const [[n], stones] = input.split('\n').map(v => v.split(''))

  const border = stones.filter(s => s === RED_STONE).length
  const res = stones.slice(border).filter(s => s === RED_STONE).length

  console.log(res)
}

main(readFileSync('/dev/stdin', 'utf8').trim())


Measured memory_bytes: 39792
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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

	int N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;

	FOR(i, 1, N) {
		if (i*C - (N - 1 - i)*D <= B - A && B - A <= i * D - (N - 1 - i)*C) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(time(NULL));

const int maxN = 2e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

const int MAGIC = 3;
int dp[maxN][MAGIC], n;
string st;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	cin >> st;
	n = st.size();
	st += string(MAGIC, '@');

	for(int i = n - 1; i >= 0; i--)
		for(int a = 1; i + a <= n && a < MAGIC; a++)
			for(int b = 1; b < MAGIC; b++)
				if(st.substr(i, a) != st.substr(i + a, b))
					dp[i][a] = max(dp[i][a], dp[i + a][b] + 1);

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


Measured memory_bytes: 2964
"""

https://atcoder.jp/contests/caddi2018/tasks/caddi2018_d

インラインdpを習得したから再挑戦
2*2→3*3…と塗っていくと、毎回2個を決めることとなる

新たに塗る2箇所をどう決められるかを考える
→偶奇を反転させる場合、01 or 10で塗り、させない場合は11 or 00で塗る
→1箇所までなら塗られていても自由度が下がるだけ？
→両方塗られていたらまずい場合がある

基本的に4列目以降は00 01の対以外不可能になる
→すでに片側置かれていたら1択、両側でダメだったら0になる
→つまり、考えるべきは3列目までである

3列目までは、片側は問題ないが、両側は制約として作動する
1列目(i=j)は文字を確定させる
2列目(abs(i-j)!=1)は隣り合う文字が同じ or 異なるを確定させる
3列目は、1列目の文字を確定させる

"""

from sys import stdin
import sys
mod = 998244353

N,M = map(int,stdin.readline().split())

neq = {}
eq = [None] * N
lock = [None] * (N-1)

for loop in range(M):

    a,b,c = map(int,stdin.readline().split())
    a -= 1
    b -= 1
    if a < b:
        a,b = b,a
    
    if a == b:
        if eq[a] == None or eq[a] == c:
            eq[a] = c
        else:
            print (0)
            sys.exit()
    
    elif a-b == 1:
        if (a,b) in neq:
            lock[b] = (neq[(a,b)] ^ c)
        else:
            neq[(a,b)] = c

    elif a-b == 2:
        if (a,b) in neq:
            if eq[a-1] == None or eq[a-1] == neq[(a,b)]^c:
                eq[a-1] = neq[(a,b)]^c
            else:
                print (0)
                sys.exit()
        else:
            neq[(a,b)] = c

    else:
        if (a,b) in neq:
            if neq[(a,b)] ^ c == 1:
                print (0)
                sys.exit()
        else:
            neq[(a,b)] = c

ableout = (N**2-N)//2 - len(neq)
outans = pow(2,ableout,mod)

dp = [[0,0] for i in range(N)]
dp[0] = [1,1]

for i in range(N):

    if eq[i] == 0:
        dp[i][1] = 0
    if eq[i] == 1:
        dp[i][0] = 0

    if i == N-1:
        break

    if lock[i] == 0:
        dp[i+1][0] = dp[i][0]
        dp[i+1][1] = dp[i][1]
    elif lock[i] == 1:
        dp[i+1][0] = dp[i][1]
        dp[i+1][1] = dp[i][0]
    else:
        dp[i+1][0] = sum(dp[i]) % mod
        dp[i+1][1] = sum(dp[i]) % mod

#print (dp , ableout)
print (sum(dp[-1]) * outans % mod)

                


Measured memory_bytes: 96712
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

ll fanc(vector<int> &now){
  ll ret = now.front();
  ll sum = ret;
  int bf = now.front();
  rep2(k, 1, now.size()){
    // cerr << i << " " << ret << " " << sum << endl;
    if(bf == now.at(k)){
      ret += sum;
    }else{
      sum++;
      ret++;
    }
    bf = now.at(k);
  }
    // cerr << i << " " << ret << " " << sum << endl;
  return ret;
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n){
    int in;
    cin >> in;
    a.at(i) = in;
    bool flag = true;
    if(i == 0){
      if(in != 0) flag = false;
    }else{
      if(in - a.at(i-1) > 1) flag = false;
    }
    if(flag == false){
      cout << -1 << endl;
      return 0;
    }
  }
  int bf = 0;
  vector<int> now;
  now.push_back(a.front());
  ll ans = 0;
  rep2(i, 1, n){
    if(bf > a.at(i)){
      ll ret = fanc(now);
      if(ret == -1){
        cout << -1 << endl;
        return 0;
      }
      ans += ret;
      now.clear();
    }
    now.push_back(a.at(i));
    bf = a.at(i);
  }
  ll ret = fanc(now);
  if(ret == -1){
    cout << -1 << endl;
    return 0;
  }
  ans += ret;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2168
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

inline void down(int &x,const int &y){if(x>y)x=y;}
const int maxn = 210000;

int n;
char str[maxn];
int nex[maxn][26],las[26];
int f[maxn];

int main()
{
	scanf("%s",str+1); n=strlen(str+1);
	for(int i=0;i<26;i++) las[i]=n+1;
	for(int i=n;i>=0;i--)
	{
		for(int j=0;j<26;j++) nex[i][j]=las[j];
		las[str[i]-'a']=i;
	}
	memset(f,63,sizeof f); f[n+1]=0;
	for(int i=n;i>=0;i--)
	{
		for(int j=0;j<26;j++) down(f[i],f[nex[i][j]]+1);
	}
	int pos=0;
	while(pos!=n+1)
	{
		for(int i=0;i<26;i++)if(f[nex[pos][i]]+1==f[pos])
			{ putchar(i+'a');pos=nex[pos][i];break; }
	}
	puts("");
	
	return 0;
}


Measured memory_bytes: 21632
import java.util.*;
import java.io.*;
import java.math.*;

public class Main{

  public static boolean check(char[] arr, int len){
    for(int i=0;i<len; i++){
      if(arr[0] != arr[i]){
        return false;
      }
    }
    return true;
  }

  public static void main(String[] args) throws IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    int[] c = new int[26];

    String str = in.readLine();

    int min = 100;
    for(int i=str.length()-1;i>=0;i--){
      char[] s = str.toCharArray();
      char a = s[i];
      for(int j=0;j<=(s.length+1)/2;j++){
        if(check(s, s.length-j) && min > j){
          min = j;
        }
        for(int k=0;k<s.length-j-1;k++){
          if(s[k+1]==a){
            s[k]=a;
          }
        }
      }
    }
    System.out.println(min);
  }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
string a;
int la;
int st,b;
int ans;
int main()
{
	cin>>a;
	la=a.size();
	for(int i=0;i<la;i++)
	{
		if((a[i]=='g' || a[i]=='p') && b<st)
		{
			b++;
			if(a[i]=='g')
			{	
				ans++;
			}
		}
		else if((a[i]=='g' || a[i]=='p') && b==st)
		{
			st++;
			if(a[i]=='p')
			ans--;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 512