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

// ただの辺
struct edge {
    int to;
    long long cost;
    // 引数一つの時は距離1
    edge(int t, long long c = 1) : to(t), cost(c) {}
};

// Bellman-Ford
// depend:edge
// 到達不可能:LLONG_MAX、負閉路を経由可能:LLONG_MIN
vector<lint> bellman_ford(vector<vector<edge>>& g, int s) {
    int n = g.size();
    vector<long long int> res(n, LLONG_MAX);
    res[s] = 0;
    for (int i = 0; i < 2 * n; i++) {
        for (int j = 0; j < n; j++) {
            if (res[j] == LLONG_MAX) continue;
            for (int k = 0; k < (int)g[j].size(); k++) {
                int c = g[j][k].cost, dest = g[j][k].to;
                if (i < n - 1) {
                    res[dest] = min(res[dest], res[j] + c);
                } else {
                    if (res[j] == LLONG_MIN || res[dest] > res[j] + c) res[dest] = LLONG_MIN;
                }
            }
        }
    }
    return res;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<edge>> g(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        lint c;
        cin >> a >> b >> c;
        a--, b--;
        c = -c;
        g[a].push_back(edge(b, c));
    }
    auto dist = bellman_ford(g, 0);
    lint res = dist[n - 1];
    if (res == LLONG_MIN) {
        cout << "inf" << endl;
    } else {
        cout << -res << endl;
    }
}

Measured memory_bytes: 3612
use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let s: String = parse_line().unwrap();

    let mut count = 0;
    for c in s.chars() {
        match c {
            'g' => count += 1,
            'p' => count -= 1,
            _ => unreachable!(),
        }
    }
    println!("{}", count / 2);
}


Measured memory_bytes: 2348
import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int N;
    string[] A, B;
    string S, T;
    bool input() {
        scanf("%d\n", &N);
        if (N == 0) return false;
        A = new string[N];
        B = new string[N];
        foreach (i; 0 .. N) {
            auto _ = readln.chomp.split(" ").array;
            A[i] = _[0];
            B[i] = _[1];
        }
        S = readln.chomp;
        T = readln.chomp;
        return true;
    }
    struct P {
        string s;
        int t;
    }
    void solve() {
        DList!P Q;
        Q.insert(P(S, 0));
        int Ans = -1;
        bool[string] used;
        while (!Q.empty) {
            P p = Q.front; Q.removeFront;
            if (p.s == T) {
                Ans = p.t;
                break;
            }
            foreach (i; 0 .. N) {
                string ns = p.s.replace(A[i], B[i]);
                if (ns.length > 10) continue;
                if (ns in used) continue;
                used[ns] = true;
                Q.insert(P(ns, p.t + 1));
            }
        }
        writeln(Ans);
    }
    while (input) solve;
}

Measured memory_bytes: 2172
using System;
using System.Linq;

class Problem
{
  public static void Main()
  {
    var inputs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    int N = inputs[0], K = inputs[1];
    var lengths = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    var ans = lengths.OrderBy(l => l).Reverse().Take(K).ToArray().Sum();
    Console.WriteLine($"{ans}");
  }
}


Measured memory_bytes: 13652
import java.util.Random;
import java.util.Scanner;
        
        public class Main {
        	public static void main(String[] args) {
        		Scanner in = new Scanner(System.in);
        		String name = in.next();
        		int a = name.length();
        		Random rand = new Random();
        	    int num = rand.nextInt(a-2);
        		
        	    for(int i = 0;i<3;i++) {
        	    	char c = name.charAt(num+i);
        	    	System.out.print(c);
        	    }
        		
        	}
        }

Measured memory_bytes: 27020
#include<iostream>
#include<stdio.h>
#include<math.h>

#define angle M_PI/3

using namespace std;

void func(pair<double,double> p1, pair<double,double> p2, int n){

	if(n==0) return;

	pair<double,double> s,t,u;

	s.first=(2*p1.first+p2.first)/3;
	s.second=(2*p1.second+p2.second)/3;

	t.first=(p1.first+2*p2.first)/3;
	t.second=(p1.second+2*p2.second)/3;

	u.first=(t.first-s.first)*cos(angle)-(t.second-s.second)*sin(angle)+s.first;
	u.second=(t.first-s.first)*sin(angle)+(t.second-s.second)*cos(angle)+s.second;

	n--;
	func(p1,s,n);
	printf("%.8f %.8f\n", s.first, s.second);
	func(s,u,n);
	printf("%.8f %.8f\n", u.first, u.second);
	func(u,t,n);
	printf("%.8f %.8f\n", t.first, t.second);
	func(t,p2,n);

}


int main(){
	
	int n;
	cin>>n;
	pair<double,double> p1,p2;

	p1.first=0.0;
	p1.second=0.0;

	p2.first=100;
	p2.second=0;

	printf("%.8f %.8f\n", p1.first, p1.second);
	func(p1,p2,n);
	printf("%.8f %.8f\n", p2.first, p2.second);

	return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#include <cstdio>
#include <string.h>
#include <vector>
#include <limits>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <deque>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <sstream>
#include <type_traits>
#define SET(x,y) x |= (1 << y)
#define CLEAR(x,y) x &= ~(1<< y)
#define READ(x,y) ((0u == (x & (1<<y)))?0u:1u)
#define TOGGLE(x,y) (x ^= (1<<y))
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define si(n) scanf("%d",&n)
#define sf(n) scanf("%f",&n)
#define sl(n) scanf("%lld",&n)
#define slu(n) scanf("%llu",&n)
#define sd(n) scanf("%lf",&n)
#define ss(n) scanf("%s",n)
#define pnl printf("\n")
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pF first
#define pS second
#define CL(a,b) memset(a,b,sizeof(a))
#define sqr(x) ((x)*(x))
#define intLIMIT numeric_limits<int>
#define longLIMIT numeric_limits<long long>
#define GCD(a,b) __gcd((a),(b))
#define dbl(x) (double)(x)
#define vi vector <int>
#define vii vector < pair <int, int> >
#define vll vector <long long>
#define allof(x) (x).begin(), (x).end()
#define fastCin cin.sync_with_stdio(0);cin.tie(0)
#define scanUnsigned(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
#define printArr(a,l) cout<<#a<<": ";for(int i=0;i<(l);i++){cout<<a[i]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(int i=0;i<(r);i++){for(int j=0;j<(c);j++){cout<<a[i][j]<<" ";}cout<<endl;}
char _;
using namespace std;
void PRINT (int x, int y) { for (int i = y-1; i >= 0; i--) { cout << READ(x,i); } cout << endl; }

vector<string>vec_splitter(string s){s+=',';vector<string>res;while(!s.empty()){res.push_back(s.substr(0,s.find(',')));s=s.substr(s.find(',')+1);}
return res;}
void debug_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,__attribute__((unused))int LINE_NUM){cerr<<endl;}
template<typename Head,typename...Tail>void debug_out(vector<string>args,int idx,int LINE_NUM,Head H,Tail...T){if(idx>0)cerr<<", ";else cerr<<"Line("<<LINE_NUM<<") ";stringstream ss;ss<<H;cerr<<args[idx]<<" = "<<ss.str();debug_out(args,idx+1,LINE_NUM,T...);}
#ifdef LOCAL_DBG
#define dbg(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define dbg(...) 42
#endif

int main () {
	fastCin;
	int t, n;
	cin >> t >> n;
	int ans = -1;
	vi p(n);
	for (int x = 0; x < n; x++) {
		cin >> p[x];
	}
	sort (allof(p));
	int ptr = 0;
	for (int x = 0; x <= 200; x++) {
		while (ptr < p.size() && p[ptr] < x) {
			ptr++;
		}
		if (ptr >= p.size() || p[ptr] != x) {
			if (ans==-1) {
				ans = x;
			} else if (abs(t-x) < abs(t-ans)) {
				ans = x;
			}
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main() {
  int n,m;
  cin >> n >> m;
  vector<lli> a(n);

  rep(i,n)cin >> a[i];
  using p = lli;
  priority_queue<lli> que;
  rep(i,n)que.push(a[i]);
  rep(i,m){
    lli fuga = que.top();
    que.pop();
    que.push(fuga/2);
  }
  lli ans =0;
  rep(i,n){
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
}


Measured memory_bytes: 2168
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
auto construct(ll n){
    vector<int>res;
    int x;
    for(x = 50; x >= 1; x--){
        if(n >= (1LL<< x)-1){
            break;
        }
    }
    n-=(1LL<<x)-1;
    rep(i,x)res.push_back(i+1);
    int a = x+1;
    for(int i = x-1; i>=0; i--){
        if((1LL<<i)<=n){
            res.insert(res.begin()+i,a);
            a++;
            n-=(1LL<<i);
        }
    }
    assert(res.size()<=100);
    return res;
}
int main(){
    ll n;
    cin >> n;
    auto a = construct(n);
    cout << a.size()*2 << endl;
    for(int x:a){
        cout << x << " ";
    }
    rep(i,a.size()){
        cout << i + 1 << " ";
    }
    cout << endl;
}

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

int main() {
  int a;
  cin>>a;
  vector<string> bl(a);
  multiset<string> se;
  for (int i=0;i<a;i++){
    cin>>bl.at(i);
    se.insert(bl.at(i));
  }
  int b;
  cin>>b;
  multiset<string> re;
  string ree;
  for(int i=0;i<b;i++){
    cin>>ree;
    re.insert(ree);
  }
  int ans=0;
  int c=0;
  for(int i =0;i<bl.size();i++) {
    c=se.count(bl.at(i))-re.count(bl.at(i));
    ans=max(ans,c);
  }
  cout << ans << endl;
}

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

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


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int n;
int a[105];
int main(){
    int sum = 0,d1,d2,s1,s2;
scanf("%d",&n);
    for(int i = 1;i <= n;++i)
    {scanf("%d",&a[i]);
          sum += a[i];
          }
    d1 = sum/n;
     d2 = d1 + 1;
     s1 = 0,s2 = 0;
    for(int i = 1;i <= n;++i)
        {
        s1 += (d1 - a[i])*(d1 - a[i]);
        s2 += (d2 - a[i]) * (d2 - a[i]);
    }
    if(s1>s2)
  printf("%d",s2);
  else
     printf("%d",s1);
}


Measured memory_bytes: 128
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

struct Score{
  int c, s, p, t;
  
  Score(): c(0), s(0), p(0), t(0){}
  bool operator>(const Score& rhs) const{
	return c > rhs.c || (c == rhs.c &&
						 (s < rhs.s || (s == rhs.s && t > rhs.t)));
  }
};

bool eq(Score& s1, Score& s2){
  return s1.c == s2.c && s1.s == s2.s;
}

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

  while(true){
	int M, T, P, R; cin >> M >> T >> P >> R; if(T == 0) break;
	int wrong[51][11];
	fill((int*)wrong, (int*)wrong+51*11, 0);
	vector<Score> sc(T);
	REP(i,T) sc[i].t = i+1;
	REP(r,R){
	  int m, tid, pid, res;
	  cin >> m >> tid >> pid >> res;
	  if(!res){
		sc[tid-1].s += m + 20 * wrong[tid-1][pid];
		++sc[tid-1].c;
	  }
	  else
		++wrong[tid-1][pid];
	}

	sort(ALL(sc), greater<Score>());
	cout << sc[0].t;
	for(int i=1;i<T;++i){
	  if(eq(sc[i-1], sc[i])) cout << "=";
	  else cout << ",";
	  cout << sc[i].t;
	}
	cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define ll long long
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define DUMP(x) cout << #x << " = " << (x) << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;

int main() {
  int n, a, b; cin >> n >> a >> b;
  cout << (n * a > b ? b : n * a) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main()
{
  int N;
  cin >> N;
  for(int i=0; i<N; ++i){
    int hoge;
    cin >> hoge;
    if(hoge%2==0){
      if(hoge%3!=0&&hoge%5!=0){
        cout << "DENIED" << endl;
        exit(0);
      }
    }
  }
  cout << "APPROVED" << endl;
}

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

const int MOD = 1000000007;

long long solve(const vector<int>& a)
{
    int n = a.size();
    vector<int> b(n);
    b[0] = a[0];
    for(int i=1; i<n; ++i)
        b[i] = a[i] ^ b[i-1];

    long long ans = 1;
    if(b.back() == 0){
        for(int i=0; i<n-1; ++i){
            if(b[i] == 0){
                ans *= 2;
                ans %= MOD;
            }
        }
    }

    int cnt = 0;
    map<long long, long long> dp1, dp2, prev;
    for(int i=0; i<n; ++i){
        if(b[i] == 0){
            ++ cnt;
        }
        else{
            dp1[b[i]] += dp2[b[i]] * (cnt - prev[b[i]]);
            dp1[b[i]] %= MOD;
            prev[b[i]] = cnt;
            dp2[b[i]] += dp1[b[i]] + 1;
            dp2[b[i]] %= MOD;
        }
    }
    if(b.back() == 0){
        for(const auto& p : dp2){
            ans += p.second;
            ans %= MOD;
        }
    }
    else{
        ans += dp1[b.back()];
        ans %= MOD;
    }
    return ans;
}

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

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];

    cout << solve(a) << endl;

    return 0;
}


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

using lint = long long;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
template <typename T> using VVV = vector<vector<vector<T>>>;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repu(i, a, b, s) for(int i = int(a); i < int(b); i += int(s))
#define repd(i, a, b, s) for(int i = int(a); i > int(b); i += int(s))
#define endl "\n"
constexpr lint INF = 2e18;
constexpr lint MOD = 1e9 + 7;

void solve() {
    lint R, C, K;
    cin >> R >> C >> K;

    VV<lint> grid(R, V<lint>(C, -1));

    rep(i, K) {
        lint r, c, v;
        cin >> r >> c >> v;
        r--;
        c--;
        grid[r][c] = v;
    }

    VVV<lint> dp(R, VV<lint>(C, V<lint>(4, 0)));

    if(grid[0][0] != -1)
        dp[0][0][1] = grid[0][0];

    rep(y, R) {
        rep(x, C) {

            // 選ばない
            if(0 <= y - 1) {
                rep(i, 4) { dp[y][x][0] = max(dp[y][x][0], dp[y - 1][x][i]); }
            }
            if(0 <= x - 1) {
                rep(i, 4) { dp[y][x][i] = max(dp[y][x][i], dp[y][x - 1][i]); }
            }

            // 選ぶ
            if(grid[y][x] != -1) {
                if(0 <= y - 1) {
                    rep(i, 4) {
                        dp[y][x][1] =
                            max(dp[y][x][1], dp[y - 1][x][i] + grid[y][x]);
                    }
                }
            }
            if(0 <= x - 1) {
                repu(i, 1, 4, 1) {
                    dp[y][x][i] =
                        max(dp[y][x][i], dp[y][x - 1][i - 1] + grid[y][x]);
                }
            }
        }
    }

    lint ans = -INF;
    rep(i, 4) { ans = max(ans, dp[R - 1][C - 1][i]); }
    cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
    return 0;
}


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

/* clang-format off */
#define int long long
// #define double long double
struct Fast {Fast() {cin.tie(0); ios::sync_with_stdio(false);}} fast;

template <typename T> inline size_t maxElement(T beginIt, T endIt) { return max_element(beginIt, endIt); }
template <typename T> inline size_t minElement(T beginIt, T endIt) { return min_element(beginIt, endIt); }
template <typename T> inline size_t maxIndex(T beginIt, T endIt) { return distance(beginIt, *max_element(beginIt, endIt)); }
template <typename T> inline size_t minIndex(T beginIt, T endIt) { return distance(beginIt, *min_element(beginIt, endIt)); }
template <typename T> inline int sum(T beginIt, T endIt) { return accumulate(beginIt, endIt, 0); }
template <typename T> inline int mean(T beginIt, T endIt) { return sum(beginIt, endIt) / distance(beginIt, endIt); }
template <typename T> inline void debug(T x) { cerr << x << " " << "(L:" << __LINE__ << ")" << endl; }
/* clang-format on */

signed main(void) {
  /* */
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  // double num; // num
  // num = 0; // count, result
  // num = numeric_limits<double>::min(); // max
  // num = numeric_limits<double>::max(); // min
  int N;
  array<int, 3000> A;
  string S;
  /* */

  // array<int, 3000> B;
  int tmpMax = 1;
  
  
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

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

  // for (int m = 0; m < tmpMax; ++m) {
  //   int tmp = 0;
  //   for (int i = 0; i < N; ++i){
  //     tmp += m % A[i];
  //   }
  //   num = max(tmp, num);
  // }
  
  cout << num << endl;
  // cout << fixed << setprecision(10) << num << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define U [1<<17]={}
#define G(a)((c=A[a]+A[P[a]]+C[a])%k?c:0)
typedef long long L;using namespace std;
map<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p;char s U;
L D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)
	d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;}
L M(L i){return i?B[i]+M(i^i&-i):0;}
L S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;}
L K(L f){p=X[f];n=X[b];return p-n?M(O[E[p]<E[n]?p=n,a=b,b=f,a:f])-M(O[p])+G(p)+K(P[p]):abs(M(O[f])-M(O[b]));}
main(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
	for(D(b=p=0);p<*Z;p++)if(!p|H[P[a=p]]-p)for(;!b|a;S(a=H[a],O[a]=b++))X[a]=p;
	for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}

Measured memory_bytes: 33468
n, m = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)
n += 1
c.sort!
inf = n * 2
dp = Array.new(m) { Array.new(n, inf) }

0.step(n, c[0]).each_with_index do |x, i|
  dp[0][x] = i
end

(1...m).each do |i|
  n.times do |j|
    if (j - c[i] < 0)
      dp[i][j] = [dp[i - 1][j], dp[i][j]].min
    else
      dp[i][j] = [
        dp[i - 1][j - c[i]] + 1,
        dp[i - 1][j],
        dp[i][j - c[i]] + 1,
      ].min
    end
  end
end

puts dp[m - 1][n - 1]



Measured memory_bytes: 14720
n = int(input())

l = []
ans = 1
z = False
l = input().split(' ')
for x in l:
  x = int(x)
  if x == 0:
    print(0)
    exit(0)
for i in range(n):
  x = int(l[i])
  ans *= x
  if ans > 1e18:
    ans = -1
    break

print(ans)

Measured memory_bytes: 19492
#include<stdio.h>
int main(void){
    int H,W;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0 && W==0){
            break;
        }
        int i,j;
        for(i=1;i<=H;i++){
            for(j=1;j<=W;j++){
                if((i+j)%2==0){
                    printf("#");
                }
                else{
                    printf(".");
                }
            }
        printf("\n");
        }
    printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 1992
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int N;
int P[201010];
int mi[201010];

int main()
{
    cin >> N;
    mi[0] = inf;
    ll ans = 0;
    repe(i, 1, N)
    {
        cin >> P[i];
        if (P[i] <= mi[i - 1])
        {
            ans++;
        }
        mi[i] = min(mi[i - 1], P[i]);
    }

    cout << ans << endl;
}


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

string S, T;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int N;
    cin >> N >> S >> T;

    for(int i=0; i<N; i++)
        cout << S[i] << T[i];
    cout << "\n";

    return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    K = gete(int)
    S = gete()

    if len(S) <= K:
        print(S)
    else:
        print(S[:K] + "...")


if __name__ == "__main__":
    main()

Measured memory_bytes: 64888
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
LL a[303030];

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    rep(i, 3 * N) scanf("%lld", &a[i]);
    
    // 2. sort.
    sort(a, a + 3 * N);
    
    // 3. N組のチームの強さの和としてありうる値の最大値.
    LL ans = 0;
    repex(i, N, 3 * N, 2) ans += a[i];
    
    // 4. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

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

typedef long long int ll;
using ii= pair<ll,ll>;
#define F first
#define S second
#define MP make_pair
#define PB push_back
//using min_of_3=min({ll a,ll b,ll c});

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
    ll n,m,k;
    cin>>n>>m>>k;
    
    vector<ll> a(n+1,0);
    vector<ll> b(m+1,0);
    
    for(ll i=1;i<=n;i++)
    {
        ll y;
        cin>>y;
        a[i]=y+a[i-1];
    }
    
    for(ll i=1;i<=m;i++)
    {
        ll x;
        cin>>x;
        b[i]=x+b[i-1];
    }
    
    
    ll count=0;
    
    
    for(ll i=0;i<=n;i++)
    {
        ll sum=k-a[i];
        
        if(sum<0)
        {
            break;
        }
        
        else
        {
            
            ll j = upper_bound(b.begin(),b.end(),k-a[i])-b.begin();
            if(b[j-1]<=k-a[i])
            {
                count=max(count,i+j-1);
                //k = k-a[i]-b[j-1];
            }
        }
        
        
    }
    
    
    cout<<count<<"\n";
	
}


Measured memory_bytes: 6340
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
ll cnt =0;

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

    for(int i=1;i<n-1;i++){
        if( (a[i-1]<a[i] && a[i]<a[i+1]) || (a[i-1]>a[i] && a[i]>a[i+1]) ){
            cnt ++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.*;
 

public class Main {
    public static void main(String[] args) {   
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        System.out.println(Math.min(A*N,B));

		
    }
}



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

#define For(k,i) for(int i=0;i<k;i++)

using namespace std;
using ll = long long;
int E9 = 1000000000;

int main() {
    int ans = 0;
    int n,k,s,p;
    int l,r = 0;
    cin >> n >> k >> s;

    p = E9;
    if (s== E9) p = 1;

    for(int i=0 ; i < k;i++){
        cout << s << " ";
    }

    for(int i=k; i < n;i++){
        cout << p << " ";
    }
}


Measured memory_bytes: 1280
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		BigInteger myBI = new BigInteger(sc.next());
		double a = sc.nextDouble();
		BigDecimal bd = new BigDecimal(myBI);
		BigInteger doubleWithStringValue = bd.multiply(BigDecimal.valueOf(a)).toBigInteger();
		long result=doubleWithStringValue.longValue();
		System.out.println(result);
	}
}


Measured memory_bytes: 37676
package main

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

type Op struct {
	cy int
	cx int
	ny int
	nx int
}

func solve(io *io) {
	h := io.NextInt()
	w := io.NextInt()
	a := make([][]int, h)
	for i := range a {
		a[i] = make([]int, w)
		for j := range a[i] {
			a[i][j] = io.NextInt()
		}
	}
	answers := make([]Op, 0)
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if i == h-1 && j == w-1 {
				break
			}
			var cy, cx, ny, nx, dx int
			cy = i
			if i%2 == 0 {
				cx = j
				dx = 1
			} else {
				cx = w - 1 - j
				dx = -1
			}
			if j == w-1 {
				ny = i + 1
				nx = cx
			} else {
				ny = i
				nx = cx + dx
			}
			if a[cy][cx]%2 != 0 {
				a[cy][cx]--
				a[ny][nx]++
				answers = append(answers, Op{cy, cx, ny, nx})
			}
		}
	}
	io.Println(len(answers))
	for _, a := range answers {
		io.Println(a.cy+1, a.cx+1, a.ny+1, a.nx+1)
	}
}

func main() {
	io := newIo()
	defer io.Flush()
	solve(io)
}

type io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func intMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func intMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 24960
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

vector<pair<ll,ll> > ans;
ll K;
ll X,Y;
ll dx,dy;
pair<ll,ll> modify;

pair<ll,ll> strategy(ll x,ll y,ll K){
  //x,yは残りの距離、Kは移動可能距離
  // cout<<"remain "<<x<<" "<<y<<endl;
  if(x<0){
    modify = strategy(-x,y,K);
    return mp(-modify.first,modify.second);
  }
  if(y<0){
    modify = strategy(x,-y,K);
    return mp(modify.first,-modify.second);
  }
  if(x>y){
    modify = strategy(y,x,K);
    return mp(modify.second,modify.first);
  }
  //ここでは0<=x<=yであるはず
  ll L = x+y;
  //まだまだだからとりあえず近ずく
  if(L>2*K){
    dx = min(x,K);
    dy = K - dx;
    return mp(dx,dy);
  }
  //lastの移動
  if(L==K){
    return mp(x,y);
  }
  if((x+y)%2==0){
    //2回でいける
    ll t = (y-x)/2;
    dx = K-t;
    dy = t;
    return mp(dx,dy);
  }
  //3回でいける
  dx = min(K,x);
  dy = K-dx;
  return mp(dx,dy);
}

int main(){
  cin>>K;
  cin>>X>>Y;
  ll x=0,y=0;

  if(K%2==0 and (X+Y)%2!=0){
    cout<<-1<<endl;
    return 0;
  }

  else{
    while(x!=X or y!=Y){
      pair<ll,ll> move = strategy(X-x,Y-y,K);
      x += move.first;
      y += move.second;
      ans.pb(mp(x,y));
    }
    cout<<ans.size()<<endl;
    rep(i,ans.size()) cout<<ans[i].first<<" "<<ans[i].second<<endl;
  }

}


Measured memory_bytes: 5484
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

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

    int s[15],sum=0;
    for(int i=0;i<10;i++){
      cin>>s[i];
      sum+=s[i];
    }
    cout<<sum<<"\n";

    
    return 0;
}



Measured memory_bytes: 3180
l1=[]
l2=[]
for _ in range(5):
  a=int(input())
  if a%10==0:
    l1.append(a//10)
    l2.append(10)
  else:
    l1.append(1+a//10)
    l2.append(a%10)
print(10*sum(l1)+min(l2)-10)

Measured memory_bytes: 3060
n = int(input())
ps = list(map(int, input().split()))

ans = 0

i = 0
while i < n:
  if i == 0:
    min_n = ps[0]
    ans += 1
  else:
    if min_n >= ps[i]:
      min_n = ps[i]
      ans += 1
  i += 1

print(ans)


Measured memory_bytes: 24744
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void){
    int n, t, e; cin >> n >> t >> e;
    int res = -1;

    rep(i, n){
        int x; cin >> x;
        for(int d = -e; d <= e; d ++)
            if(!((t - d) % x)){ res = i + 1; break; }
    }

    cout << res << endl;

    return 0;
}

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

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int32 N;
	cin >> N;
	vector<int32> t(N), v(N);
	vector<vector<double>> dp(40010, vector<double>(2*110, -INF));

	REP(i, N) cin >> t[i];
	REP(i, N) cin >> v[i];
	int32 now = 0;
	dp[0][0] = 0;
	REP(i, N){
		FOR(j, now, now+2*t[i]){
			REP(k, 2*v[i]+1){
				chmax(dp[j+1][k], dp[j][k]+k);
				if(k < 2*v[i])
					chmax(dp[j+1][k+1], dp[j][k]+k+1.0/2.0);
				if(k > 0)
					chmax(dp[j+1][k-1], dp[j][k]+k-1+1.0/2.0);
			}
		}
		now += t[i]*2;
	}
	cout << fixed << setprecision(10) << dp[now][0]/4 << endl;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> o(n), p(n), q(n);
    for (int i = 0; i < n; i++)
        cin >> p[i];
    for (int i = 0; i < n; i++)
        cin >> q[i];
    for (int i = 0; i < n; i++)
        o[i] = i + 1;

    int a = 0, b = 0;
    while (1)
    {
        if (p == o)
        {
            break;
        }
        a++;
        next_permutation(o.begin(), o.end());
    }
    for (int i = 0; i < n; i++)
        o[i] = i + 1;
    while (1)
    {
        if (o == q)
        {
            break;
        }
        b++;
        next_permutation(o.begin(), o.end());
    }
    cout << abs(a - b);
    return 0;
}

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

using namespace std;
typedef long long ll;

int a,b[105];

int main()
{
	int n,m,c,ans=0;
	scanf("%d%d%d",&n,&m,&c);
	for(int i=0;i<m;i++)scanf("%d",&b[i]);
	for(int i=0;i<n;i++){
		int t=0;
		for(int j=0;j<m;j++){
			scanf("%d",&a);
			t+=a*b[j];
		}
		if(t+c>0)ans++;
	}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 256
#ALDS1_3-A Elementary data structures - Stack
A=input().split()
while(len(A)>1):
    for i in range(len(A)):
        if(A[i]=="+"):
            A[i]=int(A[i-2])+int(A[i-1])
            A=A[:i-2]+A[i:]
            break
        elif(A[i]=="-"):
            A[i]=int(A[i-2])-int(A[i-1])
            A=A[:i-2]+A[i:]
            break
        elif(A[i]=="*"):
            A[i]=int(A[i-2])*int(A[i-1])
            A=A[:i-2]+A[i:]
            break
print(A[0])

Measured memory_bytes: 7664
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;


struct edge {
	int to;
	long long cost;
	edge(int to_, long long cost_) :
		to(to_), cost(cost_) {}
};

int N, M;
vector<edge>graph[123456];

int color[123456];
void dfs(int i, int col) {
	if (color[i] >= 0) {
		return;
	}
	color[i] = col;
	for (auto e : graph[i]) {
		dfs(e.to, col);
	}
}

vector<int>L, R, D;
LL dist[123456];
bool flag[123456];

void dfs2(int v, int dis) {
	if (flag[v])return;
	flag[v] = true;
	dist[v] = dis;
	for (auto e : graph[v]) {
		dfs2(e.to, dis + e.cost);
	}
}

int main(void)
{
	cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		int l, r, d;
		cin >> l >> r >> d;
		--r; --l;
		graph[l].push_back({ r,d });
		graph[r].push_back({ l,-d });
		L.push_back(l);
		R.push_back(r);
		D.push_back(d);
	}
	fill(color, color + N, -1);
	for (int i = 0; i < N; ++i) {
		dfs(i, i);
	}
	set<int>cs;
	vector<int>tsuna;
	for (int i = 0; i < N; ++i) {
		if (!cs.count(color[i])) {
			tsuna.push_back(i);
		}
		cs.insert(color[i]);
	}
	for (int i = 1; i < tsuna.size(); ++i) {
		int l = tsuna[i - 1], r = tsuna[i];
		graph[l].push_back({ r,0 });
		graph[r].push_back({ l,0 });
		L.push_back(l);
		R.push_back(r);
		D.push_back(0);
	}
	dfs2(0, 0);
	for (int i = 0; i < M; ++i) {
		if (dist[L[i]] + D[i] != dist[R[i]]) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	return 0;
}


Measured memory_bytes: 20828
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
  int n = readln.chomp.to!int;
  auto a = new long[][](n);
  foreach (i; 0 .. n)
  {
    a[i] = readln.chomp.split.map!(to!long).array;
  }
  long sum = 0;
  bool yes = true;
  foreach (i; 0 .. n)
  {
    foreach (j; i + 1 .. n)
    {
      bool ok = true;
      foreach (k; 0 .. n)
      {
        if (k == i || k == j)
        {
          continue;
        }
        yes &= a[i][j] <= a[i][k] + a[k][j];
        ok &= a[i][j] < a[i][k] + a[k][j];
      }
      if (ok) {
        sum += a[i][j];
      }
    }
  }
  if (yes)
    sum.writeln;
  else
    writeln = -1;
}


Measured memory_bytes: 5372
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;

int mod;
const int N = 1e5 + 10;
int dp[N], ex[N];
vector<int> a[N];

void DFS(int u, int parent) {
  vector<int> child;
  dp[u] = 1;
  for (auto& v : a[u]) {
    if (v == parent) continue;
    DFS(v, u);
    child.push_back(v);
    dp[u] = (int64)dp[u] * (1 + dp[v]) % mod;
  }
  int m = child.size();
  if (m) {
    vector<int> L(m), R(m);
    L[0] = dp[child[0]] + 1;
    for (int i = 1; i < m; ++i) {
      L[i] = (int64)L[i - 1] * (dp[child[i]] + 1) % mod;
    }
    R[m - 1] = dp[child[m - 1]] + 1;
    for (int i = m - 2; i >= 0; --i) {
      R[i] = (int64)R[i + 1] * (dp[child[i]] + 1) % mod;
    }
    for (int i = 0; i < m; ++i) {
      int64 cur = 1;
      if (i - 1 >= 0) cur = cur * L[i - 1] % mod;
      if (i + 1 < m) cur = cur * R[i + 1] % mod;
      ex[child[i]] = cur;
    }
  }
}

int ret[N];
void DFS2(int u, int parent, int prod) {
  ret[u] = (int64)dp[u] * prod % mod;
  for (auto& v : a[u]) {
    if (v == parent) continue;
    DFS2(v, u, ((int64)prod * ex[v] + 1) % mod);
  }
}

int main() {
  int n;
  scanf("%d%d", &n, &mod);
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  DFS(0, -1);
  // for (int i = 0; i < n; ++i) {
  //   trace(i, dp[i], ex[i]);
  // }
  DFS2(0, -1, 1);
  for (int i = 0; i < n; ++i) {
    printf("%d\n", ret[i]);
  }
  return 0;
}


Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  int n;
  cin>>n;
  vector<string>head(n);
  vector<vector<int>>vis;
  for(int i=0;i<n;i++){
  	vector<int>fill;
  	vis.push_back(fill);
  	cin>>head[i];
  }
  int s = head[0].length();
  string h = head[0];
  vector<char>ans;
  for(int i=0;i<s;i++){
  	bool found = true;
  	for(int j=0;j<n;j++){
  		string s = head[j];
  		bool key = false;
  		for(int q=0;q<s.length();q++){
  			sort(vis[j].begin(),vis[j].end());
  			if(s[q]==h[i]&&!binary_search(vis[j].begin(),vis[j].end(),q)){
  				key=true;
  				vis[j].push_back(q);
  				break;
  			}
  		}
  		if(!key){
  			found=false;
  		}
  	}
  	if(found){
  		ans.push_back(h[i]);
  	}
  }
  sort(ans.begin(),ans.end());
  for(int i=0;i<ans.size();i++){
  	cout<<ans[i];
  }
  cout<<endl;
}


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

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

    ll t = a - b;

    if(abs(t) > 10e17){
        cout << "Unfair" << endl;
    }else{
        if(k % 2 == 0){
            cout << t << endl;
        }else{
            cout << 0 - t << endl;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n,x;
  cin >> n >>x;
  while(n!=0||x!=0){
    int i,j,k;
    int l=0;
    for(i=1;i<=n;i++){
      for(j=i+1;j<=n;j++){
	    for(k=j+1;k<=n;k++){
	    if(i+j+k==x) l++;
	    }
      }
    }
    cout << l << endl;
    cin >> n >> x;
  }


}



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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pow107 int(pow(10,9) + 7)

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

void warfl(vector<vector<int> > &dist, int n){
  for(int k=0; k<n; k++){
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }
  return;
}
#define long long long

const int MAX = 1000000;
const int MOD = 1e9+7;

long mpow(long x, long n){
    long ans = 1;
    while(n != 0){
        if(n%2==1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n/2;
    }
    return ans;
}

long mfact(long n){
  long ans = 1;
  for(long i=2; i<=n; i++){
    ans = ans*i % MOD;
  }
  return ans;
}

long mcomb(long n, long m){ //aCbをmod計算
    if(n == 0 && m == 0) return 1;
    if(n < m || n < 0) return 0;
    long ans = mfact(n)*mpow(mfact(m), MOD-2) %MOD;
    ans = ans*mpow(mfact(n-m), MOD-2) %MOD;
    return ans;
}

int main(){
    int x[6] = {100,101,102,103,104,105};
    int n;
    cin >> n;
    if(n/105.0 >= 1000000)cout << 0 << endl;
    else if(n%100 <= (n/100) * 5)cout << 1 << endl;
    else cout << 0 << endl;


}

Measured memory_bytes: 256
s_x, s_y, t_x, t_y = gets.split(" ").map(&:to_i)
a_x = t_x - s_x
a_y = t_y - s_y

s = ""
a_y.times{|i| s += "U"}
a_x.times{|i| s += "R"}
a_y.times{|i| s += "D"}
a_x.times{|i| s += "L"}
s += "L"
(a_y + 1).times{|i| s += "U"}
(a_x + 1).times{|i| s += "R"}
s += "D"
s += "R"
(a_y + 1).times{|i| s += "D"}
(a_x + 1).times{|i| s += "L"}
s += "U"

puts s

Measured memory_bytes: 31612
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
int main() {
	fast;
	lli r;
	cin>>r;
	cout<<fixed<<setprecision(6)<<2*pi*r;
	
	return 0;
}

Measured memory_bytes: 3800
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 2e5 + 10;

int a[N], nxt[N];

int main() {
	fast_cin();
	int n; cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	nxt[n] = 1;
	for (int i = n - 1; i >= 1; --i) {
		nxt[i] = 1;
		if (a[i + 1] == 0) {
			nxt[i] += nxt[i + 1];
		}
	}
	ll ans = 0;
	for (int l = 1; l <= n; ++l) {
		int sum = 0, xr = 0;
		for (int r = l; r <= n;) {
			sum += a[r];
			xr ^= a[r];
			if (sum == xr) {
				ans += nxt[r];
				r += nxt[r];
			} else {
				break;
			}
		}
	}
	cout << ans;
}

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

a = list(map(int,input().split()))

"""
for i in range(N):

    cnt = 1
    summ = 0
    flag = True

    while (i + 1) * cnt <= N:

        summ += a[(i + 1) * cnt -1]
        cnt += 1

    if summ % 2 != a[i]:
        flag = False
        print (i+1,"はみたさない")
        break

    else:
        pass
        print (summ,a[i],"でおｋ")

if flag :
    

    #print (lis)

    print (sum(a))

    ans = ""

    for i in range(len(a)):
        if a[i] == 1:
            ans += str(i+1) + " "

    print (ans[:-1])

else:
    print (-1)

"""

lis = [-1] * N



for i in range(N):

    i = N-i
    cnt = 2
    summ = 0
    flag = True

    while i * cnt <= N:

        summ += lis[i * cnt -1]
        cnt += 1

    #print (a[i-1],summ)

    if a[i-1] == 0 and summ % 2 == 0:
        lis[i-1] = 0
        #print ("a")

    elif a[i-1] == 0 and summ % 2 == 1:
        lis[i-1] = 1

    elif a[i-1] == 1 and summ % 2 == 0:
        lis[i-1] = 1

    elif a[i-1] == 1 and summ % 2 == 1:
        lis[i-1] = 0

    if not flag:
        break

if flag:

    #print (lis)

    print (sum(lis))

    ans = ""

    for i in range(len(lis)):
        if lis[i] == 1:
            ans += str(i+1) + " "

    print (ans)

else:
    print (-1)


    


Measured memory_bytes: 9200