akhauriyash/Code-Regression huggingface dataset:
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n;
  cin >> n;
  vector<int> d(n);
  for(auto &e : d) cin >> e;
  sort(begin(d), end(d));
  if(d[n/2] != d[n/2-1]) {
    cout << d[n/2] - d[n/2-1] << endl;
  } else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 640
r,c=map(int,input().split())
mat = [ list(map(int,input().split())) for _ in range(0,r) ]
for xs in mat: xs.append(sum(xs))
ll = [ sum([ xs[i] for xs in mat ]) for i in range (0,c+1) ]
for xs in mat: print(' '.join(map(str,xs)))
print(' '.join(map(str,ll)))

Measured memory_bytes: 7792
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for (long long& ai : a) cin >> ai;
  long long ret = 0;
  int mod = 1e9 + 7;

  // for (int i = 0; i < n - 1; ++i) {
  //   for (int j = i + 1; j < n; ++j) {
  //     long long aiaj = a[i] * a[j];
  //     aiaj %= mod;
  //     ret += aiaj;
  //     ret %= mod;
  //   }
  // }

  vector<long long> postfix(n);
  postfix[n - 2] = a[n - 1];
  for (int i = n - 2; i > 0; --i) {
    postfix[i - 1] = a[i] + postfix[i];
    postfix[i - 1] %= mod;
  }

  // for (auto el : postfix) {
  //   cout << el << endl;
  // }
  // cout << endl;

  ret = 0;
  for (int i = 0; i < n; ++i) {
    //
    ret += a[i] * postfix[i];
    ret %= mod;
  }
  cout << ret << endl;
  return 0;
}


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

int main() {
    int n, k; cin >> n >> k;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int h; cin >> h;
        cnt += h >= k;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;


int main(){
	ll a, b, v, w, t;
	cin >> a >> v >> b >> w >> t;
	if(w >= v){
		cout << "NO" << endl;
		return 0;
	}
	ll dis = abs(a-b);
	ll sp = v - w;
	ll time = dis/sp;
	if(dis%sp != 0) time += 1;
	if(time <= t){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}

}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define numrep(i,n) for(int i=1;i<=n;i++)
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)
#define ll int64_t
#define all(v) v.begin(), v.end()

const int MOD = 1000000007;

int main() {

int A,B; cin >> A >> B;

cout << (A-1)*(B-1) << endl;

return 0;

}

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

const int N = 105;
int cnt[N];
int n , a[N];
int main() {
    cin >> n;
    for (int i = 0 ; i < n ; ++ i) {
        cin >> a[i];
        ++ cnt[a[i]];
    }
    int mx = *max_element(a , a + n);
    if (mx == 1 && n > 2) {
        puts("Impossible");
        return 0;
    }
    int L = mx;
    for (int i = 1 , j = mx + 1 , k = mx ; i <= j ; ++ i , -- j , -- k) {
        if (-- cnt[k] < 0) {
            puts("Impossible");
            return 0;
        }
        if (i < j) {
            if (-- cnt[k] < 0) {
                puts("Impossible");
                return 0;
            }
        }
    }
    for (int i = 0 ; i <= n ; ++ i) {
        if (cnt[i]) {
            if (i < (mx + 1) / 2 + 1) {
                puts("Impossible");
                return 0;
            }
        }
    }
    puts("Possible");
    return 0;
}


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

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pint;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr int MOD = 998244353;

vector<int> to[200005];

ll dfs(int v) {
    ll res = 1;
    for (int u: to[v]) {
        res *= dfs(u);
        res %= MOD;
    }
    return res + 1;
}

int main() {
    int n; cin >> n;
    vector<pint> p(n); rep(i, n) cin >> p[i].first >> p[i].second;
    sort(p.begin(), p.end());

    set<pint> s;
    for (int i = n-1; i >= 0; --i) {
        int x = p[i].first, d = p[i].second;
        while (s.size() && s.begin()->first < x+d) {
            to[i].push_back(s.begin()->second);
            s.erase(s.begin());
        }
        s.emplace(x, i);
    }

    ll ans = 1;
    for (auto x: s) {
        int v = x.second;
        ans *= dfs(v);
        ans %= MOD;
    }
    cout << ans << endl;


    return 0;
}


    


Measured memory_bytes: 22144
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

n = int(input())
s,t = input().split()

ans=""
for _ in range(n):
    ans+=s[_]+t[_]
print(ans)

Measured memory_bytes: 3064
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

const int MAX = 1 << 18;
ll dp[MAX][51];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  vll a(n);
  rep(i, n){
    cin >> a[i];
  }
  vll b(n);
  rep(i, n){
    cin >> b[i];
  }
  for(int i = 1; i < n; i+=2){
    swap(a[i], b[i]);
  }
  
  repr(i, 1, MAX){
    rep(j, 51){
      dp[i][j] = INF;
    }
  }
  
  ll m = 1 << n;
  rep(cc, n){
    rep(i, m){
      if(__builtin_popcountll(i) == cc){
        ll cnt = 0;
        rep(j, n){
          if((i>>j)&1){
            
          }else{
            ll x = ((cc)&1)?b[j]:a[j];
            rep(k, x+1){
              chmin(dp[i+(1<<j)][x], dp[i][k]+cnt);
            }
            cnt++;
          }
        }
      }
    }
  }
  ll ans = INF;
  rep(x, 51){
    chmin(ans, dp[m-1][x]);
  }
  print(ans < INF ? ans : -1);
}


Measured memory_bytes: 104704
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=3.14159265359;

int main() {
    int N, M, X, Y;
    cin>>N>>M>>X>>Y;
    vector<int> x(N), y(M);
    for(int i=0;i<N;++i){
        cin>>x[i];
    }
    for(int i=0;i<M;++i){
        cin>>y[i];
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    bool ans = false;
    for(int i=X+1;i<=Y;++i){
        if((x[N-1]<i) & (i<=y[0])) ans = true;
    }
    if(ans) cout<<"No War"<<endl;
    else cout<<"War"<<endl;
}



Measured memory_bytes: 256
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

const ll MOD = 1e9 + 7;

map<ll, ll> dp;

ll rec(ll n){
    if(n == 0){
        return 1;
    }
    if(n < 3){
        return 0;
    }
    if(dp.find(n) != dp.end()){
        return dp[n];
    }
    ll res = 0;
    for(ll i = 3; i <= n; i++){
        res = (res + rec(n - i)) % MOD;
    }
    return dp[n] = res;
}

void solve(){
    ll n;
    cin >> n;
    ll res = rec(n);
    cout << res << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

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

int N;
int num2 = 0;
int num4 = 0;

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

    cin >> N;

    for(int i = 0; i < N; ++i){
        int a;
        cin >> a;
        if(a % 4 == 0)
            ++num4;
        else if(a % 2 == 0)
            ++num2;
    }

    int num1 = N - num2 - num4;
    cout << ((num1 <= num4 || (num1 == num4 + 1 && num2 == 0)) ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


struct stick{
	int left;
	int right;
	int lnode;
	int rnode;
};

typedef long long ll;
vector<stick> sticks;

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

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

ll isBalanced(int idx){
	
	ll lw,rw;
	if(sticks[idx].lnode==-1){
		lw=1;
	}
	else{
		lw=isBalanced(sticks[idx].lnode);
	}

	if(sticks[idx].rnode==-1){
		rw=1;
	}
	else{
		rw=isBalanced(sticks[idx].rnode);
	}

	ll l=lcm(lw*sticks[idx].left,rw*sticks[idx].right);
	return (l/(sticks[idx].left))+(l/(sticks[idx].right));
}

int main(){

	int n;
	bool ff[200];
	while(cin>>n&&n!=0){
		stick s;
		fill(ff,ff+200,false);
		for(int i = 0; i < n; i++){
			cin>>s.left>>s.right>>s.lnode>>s.rnode;
			s.lnode--;
			s.rnode--;
			sticks.push_back(s);
			if(s.lnode!=-1)
				ff[s.lnode]=true;
			if(s.rnode!=-1)
				ff[s.rnode]=true;
		}
		int start;
		for(int i = 0; i < n; i++){
			if(!ff[i]){
				start=i;
				break;
			}
		}
		cout<<isBalanced(start)<<endl;
		sticks.clear();
	}

	return 0;
}

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

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

    int n;
    cin >> n;
    vector<int> as(n);
    for (int i = 0; i < n; i++) cin >> as[i];
    vector<int> bs(n);
    for (int i = 0; i < n; i++) cin >> bs[i];
    auto A = as, B = bs;
    {
        sort(as.begin(), as.end());
        sort(bs.begin(), bs.end());
        for (int i = 0; i < n; i++) {
            if (as[i] > bs[i]) {
                cout << "No" << endl;
                return 0;
            }
        }
        for (int i = 0; i < n - 1; i++) {
            if (as[i + 1] <= bs[i]) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    as = A, bs = B;
    vector<pair<int, int>> ab;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        ab.emplace_back(as[i], bs[i]);
        mp[as[i]];
    }
    sort(ab.begin(), ab.end(), [](auto &a, auto &b) { return a.second < b.second; });
    int N = 0;
    for (auto &p : mp) {
        p.second = N++;
    }
    assert(n == N);
    vector<int> perm(n), pos(n);
    for (int i = 0; i < n; i++) {
        perm[i] = mp[ab[i].first];
        pos[perm[i]] = i;
    }

    int swp = 0;
    for (int i = 0; i < n; i++) {
        if (perm[i] != i) {
            swap(perm[i], perm[pos[i]]);
            swap(pos[perm[i]], pos[perm[pos[i]]]);
            swp++;
        }
    }
    cout << (swp < n - 1 ? "Yes" : "No") << endl;
}


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

int i;
int m, n;
char table[256];

int main() {
    while (1) {
        scanf("%d", &n);
        if (n == 0) return 0;

        memset(table, 0, sizeof(table));

        for (i=0; i<n; i++) {
            char a, b;
            scanf(" %c %c", &a, &b);
            table[a] = b;
        }
    
        scanf("%d", &m);
        for (i=0; i<m; i++) {
            char c;
            scanf(" %c", &c);
            if (table[c]) printf("%c", table[c]);
            else printf("%c", c);
        }
        puts("");
    }
}

Measured memory_bytes: 1016
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Calc calc = new Calc();

            List<int> input = new List<int>();
            List<List<double>> ans = new List<List<double>>();
            string str;

            while (!((str = Console.ReadLine()) == null))
            {
                input = str.Split(' ').Select(int.Parse).ToList();

                ans.Add(calc.Solve(input));
            }

            for (int i = 0; i < ans.Count(); i++)
            {
                Console.WriteLine("{0:F3} {1:F3}", ans[i][0], ans[i][1]);
            }
        }
    }

    class Calc
    {
        internal List<double> Solve(List<int> input)
        {
            int a, b, c, d, e, f;
            List<List<int>> mat_A;
            List<List<double>> mat_A_1;
            List<int> vector;
            List<double> x_y;
            double num;
            int det;

            a = input[0];    b = input[1];    c = input[2];
            d = input[3];    e = input[4];    f = input[5];

            vector = new List<int>() {
                {c}, {f}
            };

            mat_A = new List<List<int>>() {
                new List<int>{ a, b },
                new List<int>{ d, e }
            };

            det = mat_A[0][0] * mat_A[1][1] - mat_A[0][1] * mat_A[1][0];

            mat_A_1 = new List<List<double>>() {
                new List<double>(){ mat_A[1][1], (-1.0) * mat_A[0][1]},
                new List<double>(){ (-1.0) * mat_A[1][0], mat_A[0][0]}
            };

            x_y = new List<double>();
            
            for (int i = 0; i < mat_A_1.Count(); i++)
            {
                num = 0;
                for (int j = 0; j < vector.Count(); j++)
                {
                    num += mat_A_1[i][j] * (double)vector[j]; 
                }
                x_y.Add(num / (double)det);
            }

            return x_y;
        }
        
    }
}



Measured memory_bytes: 14460
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  double c;
  int d;
  int e;
  cin >> A >> B;
 if(A >= 500){
  for(d = A; d >= 500; d -= 500)
    //d = d - 500;
    e = d;
    e = e - 500;
    if(e == 0){
      cout << "Yes" << endl;
    }
    else{
      if(e <= B){
        cout << "Yes" << endl;
      }
      else{
      cout << "No" << endl;
      }
    }
 }
   else{
      if(e < B){
        cout << "Yes" << endl;
      }
      else{
      cout << "No" << endl;
      }
       }
 //cout << d << endl;
 // cout << e << endl;
  }

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(a: int, b: int, c: int, d: int, e: int, k: int):
    X = (a, b, c, d, e)
    for i, x in enumerate(X):
        for xx in X[i+1:]:
            if abs(x - xx) > k:
                return ':('
    return 'Yay!'

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    d = int(next(tokens))  # type: int
    e = int(next(tokens))  # type: int
    k = int(next(tokens))  # type: int
    print(solve(a, b, c, d, e, k))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
	if (y == 0) 
		return 1; 
	ll p = power(x, y/2) % MOD; 
	p = (p * p) % MOD; 
  
	return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
	#ifndef ONLINE_JUDGE
	if (fopen("INPUT.txt", "r"))
	{
		freopen ("INPUT.txt" , "r" , stdin);
		//freopen ("OUTPUT.txt" , "w" , stdout);
	}
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	clock_t clk;
	clk = clock();
//-----------------------------------------------------------------------------------------------------------//

	ll ans=0;
	READV(K);
	FORI(i,1,K+1)
	{
		FORI(j,1,K+1)
		{
			FORI(k,1,K+1)
			{
				ans+=__gcd(i,__gcd(j,k));
			}
		}
	}
	cout<<ans<<endl;

//-----------------------------------------------------------------------------------------------------------//


	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

	return 0;
}

Measured memory_bytes: 3808
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

o=[0 for _ in range(5)]
o1=[0 for _ in range(5)]
o[0]=a
o[1]=b
o[2]=c
o[3]=d
o[4]=e

m=max(o)
if not(m%10==0):
    while(m%10!=0):
        m+=1
for i in range(5):
    o1[i]=(m-o[i])%10
m1=max(o1)%10

for i in range(5):
    if not(o[i]%10==0):
        while(o[i]%10!=0):
            o[i]+=1
s=sum(o)

print(s-m1)

Measured memory_bytes: 3064
N = input()
lN = len(N)
n0 = int(N[0])
K = int(input())

# dp[i][k][is_tight] : 
# 上からi桁目まで確定させたときに、0でない桁がk個あり、
# is_tight = 0 -> N未満になることが確定している (=> 次の桁からは自由に選べる)
# is_tight = 0 -> Nと等しくなる可能性がある (=> 次の桁でNを超えないように注意する必要がある)
dp = [[[0, 0] for k in range(K+1)] for i in range(lN)]
# 始めの桁で、'0'を選択するとN未満が確定するため、[1, 0]
dp[0][0] = [1, 0]
# 始めの桁で、'0'以外を選択する場合、Nの最高位の数との関係で下記のように決まる
dp[0][1] = [n0-1, 1]

for i, n in enumerate(N[1:], 1):
  dp[i][0] = [1, 0] # その桁まで全ての桁で'0'を選び続けた場合は、[1, 0]
  if n == '0': # その桁が'0'の場合の遷移
    for k in range(1, K+1):
      dp[i][k][0] = dp[i-1][k][0] + dp[i-1][k-1][0]*9
      dp[i][k][1] = dp[i-1][k][1]
  
  else: # その桁が'0'以外の場合の遷移
    for k in range(1, K+1):
      dp[i][k][0] = sum(dp[i-1][k]) + dp[i-1][k-1][0]*9 + dp[i-1][k-1][1]*(int(n)-1)
      dp[i][k][1] = dp[i-1][k-1][1]


print(sum(dp[-1][K]))

Measured memory_bytes: 3064
#include <bits/stdc++.h> 
using namespace std; 
typedef long long ll;
int main()
{
    ll x,y,n,p,q,i,j;
    cin>>n>>x>>y;
    ll a[n-1];
    for(i=0;i<n-1;i++)
    {
        a[i]=0;
    }
    for(i=0;i<n-1;i++)
    {
        if(i+1<n-(y-x-1))
        {
            a[i]=a[i]+(n-i-1-(y-x-1));
        }
      if(i+1==(y-x+1-i-1))
      {
          a[i]=a[i]+(y-x+1-i-1);
      }
      else if(i+1<(y-x+1-i-1))
      {
          a[i]=a[i]+(y-x+1);
      }
     
      for(j=x-i-1;j<x-1;j++)
      {
         if(j>=0)
         {
          p=i+1-(x-1-j+1);
          if(j+i+1<y-1-p&&y-1-p!=y-1)
          {
              a[i]=a[i]+2;
          }
          else if(j+i+1<y-1-p&&y-1-p==y-1)
          {
              a[i]=a[i]+1;
          }
        else if(j+i+1==y-1-p)
          
          {
              a[i]++;
          }
         }
      }
     
      for(j=y;j<y+i;j++)
      {
         if(j<n)
         {
          p=i+1-(j-(y-1)+1);
          if(j-(i+1)>(x-1+p)&&p!=0)
          {
              a[i]=a[i]+2;
          }
         
          else if(j-(i+1)>(x-1+p)&&p==0)
          {
              a[i]++;
          }
          
          else if(j-(i+1)==(x-1+p))
          {
              a[i]++;
          }
         }
      }
    }
    a[0]=a[0]-1;
    for(i=0;i<n-1;i++)
    {
        cout<<a[i]<<endl;
    }
}
//=x-j+(y-1-(j+i+1))&&(y-1-(j+i+1))>x-1&&j+i+1<y-1

Measured memory_bytes: 256
N = input()
a = map(int, raw_input().split())

ans = 0

T = [0]*(N+1)
for x in a:
  if x<=N:
    T[x] += 1
  else:
    ans += 1
for i in range(N+1):
  if T[i]>0:
    if T[i]>=i:
      ans += T[i]-i
    else:
      ans += T[i]
print ans


Measured memory_bytes: 11348
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;

#define pb push_back
#define fi first
#define se second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int inf = 1e9;

template <class T>
istream& operator>>(istream& ss, vector<T>& v) {
    for (int i = 0; i < v.size(); i++) ss >> v[i];
    return ss;
}

template <class T> 
ostream& operator<<(ostream& ss, const vector<T>& v) {
    for (int i = 0; i < v.size(); i++) ss << v[i] << ' ';
    return ss;
}

ll binpow(ll a, ll n, ll m) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res *= a;
            res %= m;
        }
        a *= (a % m);
        a %= m;
        n >>= 1;
    }
    return res % m;
}

ll gcd(ll a, ll b) {
    return b ? gcd (b, a % b) : a;
}

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

void solve() {
    string s;
    cin >> s;
    int l = -1, r;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'A' && l == -1) l = i;
        if (s[i] == 'Z') r = i; 
    }
    cout << r - l + 1;
}

int main() {
    speed;
    int t = 1;
    //cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
}

Measured memory_bytes: 720
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

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

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

    vector<ll> sum(N + 1, 0);
    for (ll i = 1; i <= N; i++)
    {
        ll ni;
        cin >> ni;
        sum[i] = sum[i-1] + ni;
    }

    ll ans = INT_MAX;
    for (ll i = 1; i <= N; i++)
    {
        ll s1 = sum[i] - sum[0];
        ll s2 = sum[N] - sum[i];
        ans = min(ans, abs(s1 - s2));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/******************************************
*    AUTHOR:         julianferres         *
******************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define show(v,n) cerr << #v << " = "; forn(i,n) cerr << v[i] << " "; cerr << endl;
#define esta(x,c) ((c).find(x) != (c).end())
#define RAYA cerr << "===============================" << endl
const int inf = 1<<30; // const ll inf = 1LL<<62;
const int mod = 1e9+7; // 998244353
const int N  = 3005;

int D; string k;

void add( ll &a, ll b){
	a+=b;
	while(a>=mod) a-=mod;
	while(a<0) a+=mod;
}

int main(){
    FIN;
    cin >> k >> D;
    ll len = k.size();
	vector<vi> dp(105, vi(2, 0));
	dp[0][0] = 1;
	forn(where, len)
	{
		vector<vi> new_dp(105, vi(2,0));
    	forn(sum, D){
    		for(auto sm_already: {false, true}){
    			forn(digit, 10){
    				if(k[where]-'0'<digit && !sm_already) break;
    				add(new_dp[(sum+digit)%D][sm_already || (digit<k[where]-'0')],
					dp[sum][sm_already]);
    			}
    		}
    	}
    	dp = new_dp;
	}
	ll ans = (dp[0][false] + dp[0][true]) % mod;
	add(ans, -1);
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0) {
				sc.close();
				break;
			}

			int[][] bal = new int[n + 1][2];
			bal[0][0] = 0;
			bal[0][1] = 0;
			for (int i = 1; i < bal.length; i++) {
				bal[i][0] = sc.nextInt();// ポジション
				bal[i][1] = sc.nextInt();// 時間
			}

			// int[] = {position, time, baloons, distance}

			int drop = 0;
			int[][] dp = new int[n + 1][4];// dp[i番目の風船をゲットした時][積んでいる風船の個数]
			for (int i = 0; i < dp.length; i++) {
				Arrays.fill(dp[i], 40000);
			}
			dp[0][0] = 0;

			for (int i = 0; i < dp.length - 1; i++) {
				for (int j = 0; j < dp[i].length; j++) {
					if (dp[i][j] == 40000) {
						continue;
					}
					int dist = Math.abs(bal[i + 1][0] - bal[i][0]);
					boolean catchable = false;
					if (j < 3 && dist * (j + 1) <= bal[i + 1][1] - bal[i][1]) {
						// 取りに行ける時
						dp[i + 1][j + 1] = Math.min(dp[i][j] + dist,
								dp[i + 1][j + 1]);
						catchable = true;
					}
					if (bal[i + 1][0] + bal[i][0] * (j + 1) <= bal[i + 1][1]
							- bal[i][1]) {
						// 家に帰る時
						dp[i + 1][1] = Math.min(dp[i][j] + bal[i + 1][0]
								+ bal[i][0], dp[i + 1][1]);
						catchable = true;
					}
					if (!catchable) {
						// 取れない時
						drop = Math.max(drop, i + 1);
					}
				}
			}

			int score = Integer.MAX_VALUE;
			for (int i = 0; i < dp[n].length; i++) {
				score = Math.min(score, dp[n][i] + bal[n][0]);
			}
			if (score >= 40000) {
				System.out.println("NG " + drop);
			} else {
				System.out.println("OK " + score);
			}
		}
	}
}

Measured memory_bytes: 25464
import sys
import numpy as np
def Ii():return int(sys.stdin.buffer.read())
def Mi():return map(int,sys.stdin.buffer.readline().split())
def Li():return list(map(int,sys.stdin.buffer.readline().split()))
  
n,m,x = Mi()
a = []
b=[0]*m
b = np.array(b)
for i in range(n):
  a.append(Li())
  
ans = 10**7
def DFS(cost,start,skill):
  global ans
  if min(skill) >= x:
    ans = min(ans,cost)
    return ans
  for i in range(start,n):
    DFS(cost+a[i][0],i+1,skill+np.array(a[i][1:]))
  return ans

a = DFS(0,0,b)
if a == 10**7:
  a = -1
print(a)

Measured memory_bytes: 27088
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
  int a,b;

  cin >> a >> b;
  if(a < 10 && b < 10){
    cout <<a * b << endl;
  }else{
    cout << -1 << endl;
  } 
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll INF = 1e18L + 5;

vector<ll> pre; // preprocessing
// pre[mask] - score of group 'mask'
vector<ll> dp;

void rec(int i, const vector<int>& not_taken, ll score_so_far, int mask, int group) {
    if(i == (int) not_taken.size()) {
        dp[mask] = max(dp[mask], score_so_far + pre[group]);
        return;
    }
    rec(i + 1, not_taken, score_so_far, mask, group);
    rec(i + 1, not_taken, score_so_far, mask ^ (1 << not_taken[i]),
        group ^ (1 << not_taken[i]));
}

// O(2^n * n^2 + 3^n)

int main() {
    int n;
    scanf("%d", &n);
    vector<vector<ll>> in(n, vector<ll>(n));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            scanf("%lld", &in[i][j]);
        }
    }
    pre.resize(1 << n);
    // O(2^n * n^2)
    for(int mask = 0; mask < (1 << n); ++mask) {
        for(int i = 0; i < n; ++i) {
            if(mask & (1 << i)) {
                for(int j = i + 1; j < n; ++j) {
                    if(mask & (1 << j)) {
                        pre[mask] += in[i][j];
                    }
                }
            }
        }
    }
    // dp[mask] - best total score if we grouped rabbits from 'mask' already
    dp.resize(1 << n, -INF);
    dp[0] = 0;
    // O(2^n * n + 3^n)
    for(int mask = 0; mask < (1 << n); ++mask) {
        vector<int> not_taken;
        for(int i = 0; i < n; ++i) {
            if(!(mask & (1 << i))) {
                not_taken.push_back(i);
            }
        }
        rec(0, not_taken, dp[mask], mask, 0);
    }
    printf("%lld\n", dp[(1<<n)-1]);
}


Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

static const int INF = 1e9;
static const int MAX = 100;

int n;
struct edge{int to, cost;};
typedef pair<int, int> P;

int mincost[MAX];
bool used[MAX];
vector< vector<edge> > A(MAX);

int prim(){
    int to, cost, res = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    fill(mincost, mincost + n, INF);
    fill(used, used + n, false);
    mincost[0] = 0;
    que.push(P(0, 0));

    while(!que.empty()){
        P p = que.top(); que.pop();
        if (used[p.second]) continue;
        used[p.second] = true;

        for (int i = 0; i < A[p.second].size(); i++){
            to = A[p.second][i].to;
            cost = A[p.second][i].cost;
            if (used[to]) continue;
            if (mincost[to] > cost){
                mincost[to] = cost;
                que.push(P(mincost[to], to));
            }
        }
    }
    for (int i = 0; i < n; i++) res += mincost[i];
    return res;
}

int main(){
    cin >> n;
    edge x;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            scanf("%d", &x.cost);
            x.to = j;
            if (x.cost != -1) A[i].push_back(x);
        }
    }
    cout << prim() << endl;
    return 0;
}


Measured memory_bytes: 3344
#include<iostream>
using namespace std;
int main(){
	int n;
	double a[1024];
	int r[6]={0};
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]<165)r[0]++;
		else if(a[i]<170)r[1]++;
		else if(a[i]<175)r[2]++;
		else if(a[i]<180)r[3]++;
		else if(a[i]<185)r[4]++;
		else r[5]++;
		}
	
	for(int i=0;i<6;i++){
		cout<<i+1<<':';
		for(int j=0;j<r[i];j++)cout<<'*';
		cout<<endl;
		}
		}

Measured memory_bytes: 1240
n,m = map(int,input().split())
lr = [[0]*2]*m
for i in range(m):
  lr[i] = list(map(int,input().split()))
maxl = 0
minr = 10**5
for i in range(m):
  maxl = max(maxl,lr[i][0])
  minr = min(minr,lr[i][1])
if maxl>minr:
  print(0)
else:
  print(minr-maxl+1)

Measured memory_bytes: 27344
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

const int MAX_N = 100005;

int main(){
    int n; cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    vector<int> odd(MAX_N, 0);
    vector<int> even(MAX_N, 0);
    for(int i = 0; i < n; i++){
        if(i % 2 == 0) even[v[i]]++;
        else odd[v[i]]++;
    }
    vector<P> sort_odd, sort_even;
    for(int i = 0; i < MAX_N; ++i){
        sort_odd.push_back(P(odd[i], i));
        sort_even.push_back(P(even[i], i));
    }
    sort(RALL(sort_odd));
    sort(RALL(sort_even));
    int ans = 0;
    if(sort_odd[0].second != sort_even[0].second){//最頻値で考える
        ans =  n - sort_odd[0].first - sort_even[0].first;
    }else{
        ans = min(n - sort_odd[0].first - sort_even[1].first, n - sort_odd[1].first - sort_even[0].first);
    }
    cout << ans << endl;
}

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

int main() {
    int N, X, T;
    cin >> N >> X >> T;

    if (N % X != 0) {
        cout << (N / X + 1) * T << endl;
    }
    else {
        cout << N / X * T << endl;
    }
}

Measured memory_bytes: 3620
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)

int main(){
    string S;
    cin >> S;
    string res = "Yes";
    for(int i=1; i < S.size()+1; i++){
        if(i % 2 == 0){
            if(S[i-1] == 'R'){
                cout << "No"<<endl;
                return 0;
            }
        }else{
            if(S[i-1] == 'L'){
                cout << "No"<<endl;
                return 0;
            }
        }
    }

    cout << res << endl;

}


Measured memory_bytes: 256
package main

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

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	set := make(map[int]int, 0)
	for i := 0; i < N; i++ {
		sc.Scan()
		v, _ := strconv.Atoi(sc.Text())
		set[v]++
	}
	ans := 0
	if len(set) > K {
		vals := make([]int, 0)
		for _, v := range set {
			vals = append(vals, v)
		}
		sort.Ints(vals)
		dec := 0
		for i := 0; i < len(vals); i++ {
			ans += vals[i]
			dec++
			if len(set)-dec == K {
				break
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 16256
#include <iostream>
#include <cstring>
typedef long long ll;
using namespace std;
char g[1005][1005];
int h,w;
ll dp[1005][1005];
const ll mod = 1e9 + 7;
int main() {
  cin >> h >> w;

  for(int i = 0; i < h; i++) {
    string s;
    cin >> s;
    for(int j = 0; j < s.size(); j++) {
      g[i][j] = s[j];
    }
  }
  bool flag = true;
  for(int i = 0; i < w; i++) {
    if(g[0][i] == '#') flag = false;
    if(flag) dp[0][i] = 1;
  }

  flag = true;

  for(int i = 0; i < h; i++) {
    if(g[i][0] == '#') flag = false;
    if(flag) dp[i][0] = 1;
  }
  
  for(int i = 1; i < h; i++) {
    for(int j = 1; j < w; j++) {
      if(g[i][j] == '#') continue;
      dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
    }
  }

  cout << dp[h-1][w-1] << endl;
  
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define ll long long int 
#define endl '\n'
#define INF 1000000000
#define MOD 1000000007
#define MAX 100000000 
#define mp make_pair
#define pb push_back
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll d,t,x;
    cin>>d>>t>>x;
    if(x*t>=d)
    {
    	cout<<"Yes"<<endl;
    }
    else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>

using namespace std;

vector<int> blue,red,redpair,v;
vector<vector<int> >c;

int m=0,n=0;

int gcd(int x,int y){
    if(x%y==0){return y;}
    return gcd(y,x%y);
}

bool match(int x){
	if(x==-1)return 1;
	for(int i=0;i<n;i++){
		if(c[x][i]==1 && v[i]==0){
			v[i]=1;
			if(match(redpair[i])){
				redpair[i]=x;
				return 1;
			}
		}
	}
	return 0;
}


int main(){
    while(cin >> m >> n){
        if(m == 0 && n == 0){
            break;
        }
        blue.clear();
        red.clear();
        redpair.clear();
        v.clear();
        c.clear();
        for(int i = 0;i < m;i++){
            int tmp = 0;
            cin >> tmp;
            blue.push_back(tmp);
        }
        for(int i = 0;i < n;i++){
            int tmp = 0;
            cin >> tmp;
            red.push_back(tmp);
            redpair.push_back(-1);//-1??§?????¢??????????????¶????????¨???
            v.push_back(0);
        }
        for(int i = 0;i < m;i++){
            c.push_back(vector<int>());
            for(int j = 0;j < n;j++){
                c[i].push_back(gcd(blue[i],red[j]) != 1);
            }
        }
        int ans = 0;
        for(int i = 0;i < m;i++){
            for(int j = 0;j < n;j++){
                v[j] = 0;
            }
            if(match(i)){ans++;}
        }
        cout << ans << endl;
    }
    return 0;
}

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

int bm[12],bw[12];
int dp[1<<12][12];
int n,m;
int f(int a,int b){
    return abs(a-b) * (abs(a-b)-30)*(abs(a-b)-30);
}
int dfs(int x,int bit){
    if( x == n ) return 0;
    if( dp[bit][x] != -1 ) return dp[bit][x];

    int ans = dfs(x+1,bit);
    for(int i = 0 ; i < m ; i++){
        if( bit >> i & 1 ){
            ans = max(ans,dfs(x+1,bit^(1<<i)) + f(bm[x],bw[i]));
        }
    }
    return dp[bit][x] = ans;
}
int main(){

    while(cin >> n >> m && n){
        for(int i = 0 ; i < n ; i++) cin >> bm[i];
        for(int i = 0 ; i < m ; i++) cin >> bw[i];
        memset(dp,-1,sizeof(dp));
        cout << dfs(0,(1<<m)-1) << endl;
    }

}

Measured memory_bytes: 1360
import sys
from heapq import heappush
from heapq import heappop
from collections import deque


n_V, n_E, r = map(int, input().split())

E = [[] for _ in range(n_V)]
for i in range(n_E):
    v, e, c = map(int, input().split())
    E[v].append((e, c))


D = [sys.maxsize for _ in range(n_V)]
D[r] = 0

h = []
heappush(h, (D[r], r))


while len(h) != 0:
    _, index = heappop(h)

    for e, c in E[index]:
        d = D[index] + c
        if D[e] > d:
            D[e] = d
            heappush(h, (d, e))


for d in D:
    if d == sys.maxsize:
        print('INF')
    else:
        print(d)



Measured memory_bytes: 89608
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

main()
{
  bool is_prime[1300000];
  vector<int> prime;
  
  Rep(i, 1300000) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for(int i=2; i<1300000; i++) {
    if( is_prime[i] ) {
      prime.pb( i );
      for(int j=2*i; j<1300000; j+=i) is_prime[j] = false;
    }
  }

  //for(int i=0; i<prime.size(); i++) cout << prime[i] << endl;
  
  int k;
  while( cin >> k, k ) {
    if( is_prime[k] ) cout << 0 << endl;
    else cout << *upper_bound( All(prime), k ) - *(lower_bound( All(prime), k ) -1) << endl; 
  }
  
}

Measured memory_bytes: 4888
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

int n;
int a[200001];
int b[200001];
vector<int> ans;

int main() {
    cin >> n;
    rep(i,n) cin >> a[i+1];
    for (int i = n; i >= 1; i--) {
        int x = 0;
        for (int j = 2*i; j <= n; j += i) {
            x ^= b[j];
        }
        if (x != a[i]) b[i] = 1;
    }
    for (int i = 1; i <= n; i++) if (b[i]) ans.push_back(i);
    cout << ans.size() << endl;
    rep(i,ans.size()) {
        cout << ans[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 2936
var
  s:string;
  i,min,max:longint;
begin
  readln(s);
  min:=length(s);
  max:=1;
  for i:=1 to length(s) do
  begin
   if s[i]='C' then if i<min then min:=i;
   if s[i]='F' then if i>max then max:=i;
   end;
  if max>min then writeln('Yes') else writeln('No');
end.


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[10],n,sum=0,re=10,i,b=0;
    for(i=0; i<5; i++)
    {
        cin>>a[i];
        n=a[i]%10;
        if(n<re&&n!=0)
        {
            re=n;
            b=a[i];
        }
    }
    int cunt=0;
    for(i=0; i<5; i++)
    {
        if(a[i]==b&&cunt==0)
        {
            cunt++;
        }
        else
        {   if(a[i]%10==0)
        sum+=a[i];
            else
            sum+=a[i]+(10-a[i]%10);
        }
    }
    cout<<sum+b<<endl;
    return 0;
}


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

typedef long long ll;

ll N;
vector<ll> A[2];
ll R;

int main() {
  cin >> N;
  for (ll i : {0, 1}) A[i].resize(N);
  for (ll i : {0, 1})
    for (ll j = 0; j < N; ++j) cin >> A[i][j];
  for (ll j = 1; j < N; ++j) A[0][j] += A[0][j - 1];
  for (ll j = N - 2; j >= 0; --j) A[1][j] += A[1][j + 1];
  for (ll j = 0; j < N; ++j) R = max(R, A[0][j] + A[1][j]);
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
} 
int main(){
    ll n;cin >> n;
    cout << (1000-n%1000)%1000 <<endl;
}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int count = 0;
      	String strArr[] = br.readLine().split(" ");
        int a = Integer.parseInt(strArr[0]);
        int b = Integer.parseInt(strArr[1]);
        int c = Integer.parseInt(strArr[2]);
      
      	for (int i = a; i <= b; i++) {
        	if (c % i == 0) {
            count ++;
          } 
        }
      	System.out.println(count);
    }
}


Measured memory_bytes: 24436
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#define ll long long
#define out(a) printf("%lld",a)
#define ln printf("\n")
const int N=1e5+50;
const int MOD=1e9+7;
const int inf=0x7f7f7f7f;
using namespace std;
int n,m;
int now=0;
ll ans=0;
struct node
{
	int x,t,h;
}a[N];
priority_queue<int>q;
bool cmp(node a,node b)
{
	return a.h<b.h;
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	  scanf("%d%d",&a[i].t,&a[i].x),a[i].h=m-a[i].t+1;
	sort(a+1,a+n+1,cmp);
	for (int i=1;i<=n;i++){
	  ans+=a[i].x; now++; q.push(-a[i].x);
	  if (now>a[i].h){
	    now--;
	    ans+=q.top();
	    q.pop();
	  }
	}
	out(ans);
	return 0;
}

Measured memory_bytes: 2044
n,x = map(int, input().split())
list = list(map(int, input().split()))
list.sort()
count = 0
ans = 0

while count < n:
  if x >= list[count]:
    x -= list[count]
    ans += 1
    count += 1
  else:
    print(ans)
    break
else:
  if x == 0:
    print(ans)
  else:
    print(ans-1)


Measured memory_bytes: 2940
#include<stdio.h>

int main(){
	int n[29];
	int i = 0;
	int j;
	int a[2];
	int m;
	a[0] = 0;
	a[1];
	for(i = 0; i < 28; i++){
		scanf("%d", &n[i]);
	}
	for(i = 0; i < 27; i++){
		for(j = 1; j < 28; j++){
			if(n[i] > n[j]){
				m = n[i];
				n[i] = n[j];
				n[j] = m;
			}
		}
	}
	for(j = 1; j < 31; j++){
		if(a[0] != 0){
			if(n[i - 1] != j){
				a[1] = j;
			}
		}else if(n[i] != j){
			a[0] = j;
		}		
		i++;
	}
	
	printf("%d\n", a[0]);
	printf("%d\n", a[1]);

	return 0;
}

Measured memory_bytes: 596
import numpy as np

N, M  = map(int, input().split())

network = [[] for _ in range(N+1)]
res = [0 for _ in range(N+1)]
distance = [N+1 for _ in range(N+1)]
distance[1] = 0


for _ in range(M):
    i, j = map(int, input().split())
    network[i].append(j)
    network[j].append(i)


from collections import deque


n = 0
s = []
queue = deque([1])
while n < N:
    top = queue.popleft()
    for i in network[top]:
        if distance[i] > distance[top]+1:
            distance[i] = distance[top]+1
            res[i] = top
            queue.append(i)
    n += 1


print("Yes")  
for r in res[2:]:
    print(r)

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)
#define Rep(i, n) for(i = 1; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };



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

	cout << min(a, b) + min(c, d) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100010, mod = 1000000007;
int n, m;
ll a[N];
ll power(ll x, ll t)
{
	ll ret = 1;
	for(; t; t >>= 1, x = x * x % mod) 
		if(t & 1) 
			ret = ret * x % mod;
	return ret;
}
int main()
{
	scanf("%d%d", &n, &m);
	if(n < m) swap(n, m);
	if(n - m != 1 && n - m != 0)
	{
		puts("0");
		return 0;
	}
	a[0] = 1;
	for(int i = 1; i <= n + 1; ++i)
		a[i] = a[i - 1] * (ll)i % mod;
	if(n == m)
		printf("%lld\n", 2ll * a[n] % mod * a[m] % mod);
	else
		printf("%lld\n", a[n] % mod * a[m] % mod);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int seq[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    
    cout << seq[K-1] << endl;
}


Measured memory_bytes: 256