akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int counter(int a) {
	if (a == 0) return 0;
	return counter(a >> 1) + (a & 1);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];

	ll ans = 100000000000;
	for (int bit = 0; bit < (1 << n); ++bit) {
		//bit番目が見えるように調節する
		//一番目は必ず見える
		ll res = 0;
		ll tmp = a[0];
		int cnt = 1;
		rrep(i, n) {
			if (tmp >= a[i] && bit & (1 << i)) {
				res += tmp - a[i] + 1;
				tmp++;
				cnt++;
			}
			else if (tmp < a[i]) {
				tmp = a[i];
				cnt++;
			}
			if (cnt >= k) ans = min(ans, res);
		}
	}

	dunk(ans);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,pii> pr;
const ll inf = 1e12L;
int main(int argc,char const* argv[]){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	ll n,w;
	cin>>n>>w;
	vector<ll> weights(n);
	vector<ll> vals(n);
	ll sum_of_val = 0;
	for(int i=0;i<n;i++){
		cin>>weights[i]>>vals[i];
		sum_of_val+=vals[i];
	}
	vector<vector<ll>> dp(n+1,vector<ll>(sum_of_val+1,inf));
	for(int i=0;i<=n;i++){
		dp[i][0] = 0;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=sum_of_val;j++){
			if(vals[i-1]<=j){
				dp[i][j] = min(dp[i-1][j],dp[i-1][j-vals[i-1]] + weights[i-1]);
			}else{
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	ll ans = 0;
	for(int j=sum_of_val;j>=0;j--){
		if(dp[n][j] <= w){
			ans = j;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 83000
#include<bits/stdc++.h>
#define ll long long
#define P pair<ll, ll>
using namespace std;

const int inf = 1e9;

vector<vector<int>> G (2005);
vector<vector<int>> dis (2005, vector<int>(2005, inf));

void dfs(int p, int num, int d){
    for(auto to: G[num]){
        if(dis[p][to] >= d && dis[to][p] >= d){
            dis[p][to] = d;
            dis[to][p] = d;
            dfs(p, to, d+1);
        }
    }
}

int main(){
    int n, x, y;
    cin >> n >> x >> y;

    for(int i=0;i<n-1;i++){
        G[i].push_back(i+1);
        G[i+1].push_back(i);
    }
    G[x-1].push_back(y-1);
    G[y-1].push_back(x-1);

    for(int i=0;i<n;i++) dis[i][i] = 0;
    for(int i=0;i<n-1;i++) dfs(i, i, 1);

    vector<int> ans(n, 0);
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans[dis[i][j]]++;
        }
    }

    for(int i=1;i<n;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 19676
H, W = map(int, input().split())
A = [["#"]+list(input())+["#"] for _ in range(H)]

print("#"*(W+2))
for h in range(H):
    for w in range(len(A[h])):
        print(A[h][w], end="")
    print()
print("#"*(W+2))

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

#define ll long long
#define N 100010
const ll p = 1e9 + 7;
int n, k;
ll res;
vector <vector<int>> G;

void DFS(int u, int fa) {
	int sze = 1 + (u != 1);
	for (auto v : G[u]) if (v != fa) {
		res = res * max(0, k - sze) % p;
	    ++sze;	
		DFS(v, u);	
	}
}

int main() {
	while (scanf("%d%d", &n, &k) != EOF) {
		G.clear(); G.resize(n + 1);
		for (int i = 1, u, v; i < n; ++i) {
			scanf("%d%d", &u, &v);
			G[u].push_back(v);
			G[v].push_back(u);
		}
		res = k;
		DFS(1, 1);
		printf("%lld\n", res);
	}
	return 0;
}


Measured memory_bytes: 10368
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
void solve()
{
    int n,i,t,cnt=0;cin>>n;
    fo(i,0,n)
    {
        cin>>t;
        if(i%2==0&&t&1)cnt++;
    }
    cout<<cnt<<"\n";
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
//for modinverse use modularexponention(x,M-2,M);
//for "each" subtraction from ans(ans-k) if(ans<0) do ans+=MOD,ans%=MOD
//vector<vector<int>>dp(201,vector<int>(n+1)); A way to initialize vector of vector
//If wrong on pretest 2 means logically wrong


/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


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

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

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

int N;
int A[15];
int x[15][15];
int y[15][15];

int counter(int x) {
    if (x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        for (int j = 0; j < A[i]; ++j) {
            cin >> x[i][j] >> y[i][j];
        }
    }
    int ans = 0;
    for (int bits = 1; bits < (1 << N); bits++) {
        bool ok = true;
        for (int i = 0; i < N; ++i) {
            if (!(bits & (1 << i))) continue;
            for (int j = 0; j < A[i]; ++j) {
                if (y[i][j] ^ ((bits >> (x[i][j] - 1) & 1))) ok = false;
            }
        }
        if (ok) ans = max(ans, counter(bits));
    }
    cout << ans << endl;
    return 0;
}

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

int main(){ 
  int x,y; cin >> x >> y;
  int ans = 0;
  if( x == 3){ ans += 1e5;}
  if( y == 3){ ans += 1e5;}
  if( x == 2){ ans += 2e5;}
  if( y == 2){ ans += 2e5;}
  if( x == 1){ ans += 3e5;}
  if( y == 1){ ans += 3e5;}
  
  if( x == 1 && y == 1){ ans += 4e5;}
  
  cout << ans << endl; return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
mat = [input() for i in range(H)]
mat_t = [''.join(x) for x in zip(*mat)]
def check(mat, t):
    stack = set()
    for i, string in enumerate(mat):
        string = '.' + string + '.'
        for j in range(len(string)):
            if j+3<=len(string):
                if string[j:j+3] == '.#.':
                    if t==False:
                        stack.add((i, j))
                    else:
                        stack.add((j, i))
    return stack

stack1 = check(mat, False)
stack2 = check(mat_t, True)
if stack1 & stack2:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
import sys
from itertools import product
input = lambda:sys.stdin.buffer.readline().rstrip()

m, n, k = map(int, input().split())
grid = [[0] * n for _ in range(m)]
for _ in range(k):
    i, j, v = map(int, input().split())
    i -= 1; j -= 1
    grid[i][j] = v

dp = [[0] * 4 for _ in range(n)]
for i in range(m):
    ndp = [[0] * 4 for _ in range(n)]
    for j, k in product(range(n), range(4)):
        # from top
        ndp[j][0] = max(ndp[j][0], dp[j][k])
        ndp[j][1] = max(ndp[j][1], dp[j][k] + grid[i][j])
        # from left
        if j > 0:
            ndp[j][k] = max(ndp[j][k], ndp[j - 1][k])
            if k > 0:
                ndp[j][k] = max(ndp[j][k], ndp[j - 1][k - 1] + grid[i][j])
    dp = ndp

print(max(dp[-1]))

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


int main() {
    int N;
    cin >> N;
    vector<pair<ll,ll>> v(N);
    rep(i, N) {
        ll x,l;
        cin >> x >> l;
        v[i].first = x+l;
        v[i].second = x-l;
    }
    ll t = -1e9;
    sort(v.begin(), v.end());
    int ans = 0;
    rep(i, N) {
        if(t > v[i].second) continue;
        ans++;
        t = v[i].first;
    }
    cout << ans << endl;

}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 2000000000
typedef long long ll;
bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    ll N;
    
    cin >>N;
    
    cout << N *N<< endl;
    

}

Measured memory_bytes: 3640
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
#define MOD 100000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
using namespace std;
namespace Arithmetics {
    template<typename T>
    T original_pow(T a, T b) {
        T ans = 1;
        rep(i, b) {
            ans *= a;
        }

        return  ans;
    }
    template<typename T>
    T gcd(T a, T b) {
        if (a > b) {
            T c = a;
            a = b;
            b = c;
        }
        if (a == 0) {
            return b;
        }

        return gcd(b % a, a);
    }
    template<typename T>
    T gcd_of_all(vector<T> v) {
        T temp = v[0];
        for (T elem : v) {
            temp = gcd(temp, elem);
        }

        return temp;
    }
    template<typename T>
    T lcm(T a, T b) {
        T GCD = gcd(a, b);
        return a * b / GCD;
    }
    template<typename T>
    T lcm_of_all(vector<T> v) {
        T temp = v[0];
        for (T elem : v) {
            temp = lcm(temp, elem);
        }
        return temp;
    }
}
using namespace Arithmetics;

ll Oceil(ll X, ll K) {
    ll ret = X / K;
    if (X % K != 0) {
        ret++;
    }

    return ret;
}

ll Ofloor(ll X, ll K) {
    return X / K;
}
int main() {
    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll ans = b - a + 1;

    ans -= Ofloor(b, c) - Oceil(a, c) + 1;

    ans -= Ofloor(b, d) - Oceil(a, d) + 1;
    ll L = lcm(c, d);
    ans += Ofloor(b,L) - Oceil(a,L) + 1;

    cout << ans << endl;
}


Measured memory_bytes: 384
#pragma GCC optimize("O3", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int n; cin >> n;
	for (int i = 1; i < 10; ++i) {
		for (int j = 1; j < 10; ++j) {
			if (i * j == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

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

// 插入此處

LL a[100005];

vector<int> edges[100005];


bool vis[100005];

void dfs(int x, vector<LL> &s) {
    vis[x] = true;
    for (auto nxt: edges[x]) {
        if (!vis[nxt]) {
            dfs(nxt, s);
        }
    }
    s.push_back(a[x]);
}

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    vector<LL> remain;
    LL ans = 0;
    LL tree = 0;
    for (int i = 0; i < n; i++) {
        if (!vis[i]) {
            tree++;
            vector<LL> s;
            dfs(i, s);
            sort(s.begin(), s.end());
            ans += s[0];
            for (int j = 1; j < s.size(); j++) {
                remain.push_back(s[j]);
            }
        }
    }
    // printf("tree = %d\n", tree);
    if (tree == 1) {
        printf("0\n");
    } else if (remain.size() < 2 * (tree - 1) - tree) {
        printf("Impossible\n");
    } else {
        sort(remain.begin(), remain.end());
        for (int i = 0 ; i < 2 * (tree - 1) - tree; i++) {
            ans += remain[i];
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 12028
// AtCoder Regular Contest 061
// E - すぬけ君の地下鉄旅行 / Snuke's Subway Trip

#include <cstdio>
#include <unordered_map>
#include <queue>
#include <utility>
#include <functional>
#define MAX_N 100000
#define MAX_C 1000000
#define INF 100000000
#define S 0
#define T (N - 1)
#define ARR 0 // arrival 到着
#define DEP 1 // departure 出発
#define TRS 2 // transfer 乗換
using namespace std;


typedef long long int ll;
typedef pair<int, ll> PAIR;


class Graph {
public:
  void add_edge(ll from, ll to, int cost); // 有向辺を追加
  void dijkstra(ll s);
  ll count_at(ll s);
  unordered_map<ll, int> dist;
private:
  unordered_map<ll, vector<PAIR> > g; // cost, to
};

void Graph::add_edge(ll from, ll to, int cost) {
  g[from].push_back(PAIR(cost, to));
  return;
}

void Graph::dijkstra(ll s) {
  priority_queue<PAIR, vector<PAIR>, greater<PAIR> > q;
  PAIR p, e;

  dist.clear();
  dist[s] = 0;
  q.push(PAIR(dist[s], s));
  while(!q.empty()){
    p = q.top();
    q.pop();
    if (dist[p.second] == 0 && p.second != s) {
      dist[p.second] = INF;
    }
    if (dist[p.second] < p.first) {
      continue;
    }
    for (ll i = 0; i < (ll)g[p.second].size(); i++) {
      e = g[p.second][i];
      if (dist[e.second] == 0 && e.second != s) {
        dist[e.second] = INF;
      }
      if (dist[e.second] > dist[p.second] + e.first) {
        dist[e.second] = dist[p.second] + e.first;
        q.push(PAIR(dist[e.second], e.second));
      }
    }
  }
  return;
}

ll Graph::count_at(ll s) {
  return g[s].size();
}



int N, M;
Graph G;
int ans;

ll to_index(int n, int c, int type) {
  return (ll)n * (MAX_C * 2 + 1) + type * MAX_C + (type == TRS ? 0 : c);
}

void create_inner_edges(int n, int c) {
  G.add_edge(to_index(n, c, ARR), to_index(n, c, TRS), 0);
  G.add_edge(to_index(n, c, ARR), to_index(n, c, DEP), 0);
  G.add_edge(to_index(n, c, TRS), to_index(n, c, DEP), 1);
  return;
}

void one_way_connect(int from, int to, int c) {
  ll s_dep, t_arr;
  s_dep = to_index(from, c, DEP);
  t_arr = to_index(to, c, ARR);

  // 駅 n における鉄道会社 c の最初の路線を作成するとき
  // 駅内の edge を新設
  if (G.count_at(s_dep) == 0) {
    G.add_edge(to_index(from, c, TRS), s_dep, 1);
  }
  if (G.count_at(t_arr) == 0) {
    G.add_edge(t_arr, to_index(to, c, TRS), 0);
    G.add_edge(t_arr, to_index(to, c, DEP), 0);
  }

  G.add_edge(s_dep, t_arr, 0);
}

int main() {

  int p, q, c;

  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; i++) {
    scanf("%d%d%d", &p, &q, &c);
    p--; q--; c--;
    one_way_connect(p, q, c);
    one_way_connect(q, p, c);
  }

  G.dijkstra(to_index(S, -1, TRS));

  ans = G.dist[to_index(T, -1, TRS)];
  if (ans == INF || (ans == 0 && S != T)) {
    ans = -1;
  }
  printf("%d\n", ans);

  return 0;

}




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

int main(){
    int n, c, max, min;
    long long int sum;
    max = -1000000;
    min = 1000000;
    sum = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> c;
        if(c > max) max = c;
        if(c < min) min = c;
        sum += c;
    }
    cout << min << " " << max << " " << sum << endl;
    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
    int a,b,i,c;
    cin >> a >> b >> c;
    
    if(a>b){
        i = a;
        a = b;
        b = i;
    }
    if(b>c){
        i = b;
        b = c;
        c = i;
    }
    if(a>b){
        i = a;
        a = b;
        b = i;
        
    }
    cout << a <<" "<< b <<" "<< c <<endl;

    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long x,n;cin >> x >> n;
  if (n==0) {cout << x << endl;}
  else {
  
    vector<long long> a(n),aa;
	for (int i=0;i<n;i++) cin >> a[i];
	//sort(a.begin(),a.end());
	for (int i=1;i<101;i++) {
	  long long r=1;
	  for (int j=0;j<n;j++)	{
	    if (a[j]==i) r=0;
	  }
	  if (r) aa.push_back(i);
	}
    aa.push_back(0);
    aa.push_back(101);
    sort(aa.begin(),aa.end());
	long long ans=0;
    long long aasize=aa.size()-1;
	for (long long i=0;i<aasize;i++) {
	  if (aa[i]<=x && aa[i+1]>=x) {
        if (x-aa[i]<=aa[i+1]-x) ans=aa[i];
        else ans=aa[i+1];
      }
      
	}
    
    cout << ans << endl;
	
  }
}


Measured memory_bytes: 3636
// problem: "https://atcoder.jp/contests/abc159/tasks/abc159_f"

#include<bits/stdc++.h>
#define ll long long
#define p (ll)(998244353)

using namespace std;

ll totSeg(ll i,ll s,vector<ll>&A,vector<vector<ll>>&V)
{
    if(i < 0 || s < 0)
        return 0;
    else if(s == A[i] && i > 0)
        return i+1+totSeg(i-1,s,A,V);
    else if(s == A[i])
        return i+1;


    if(V[i][s] == -1)
        V[i][s] = (totSeg(i-1,s-A[i],A,V) + totSeg(i-1,s,A,V))%p;


    return V[i][s];
}

int main()
{
    ll n,s;
    cin>>n>>s;

    vector<ll>A(n);
    ll i;
    for(i=0;i!=n;i++)
        cin>>A[i];

    vector<vector<ll>>V(n,vector<ll>(s+1,-1));

    //totSeg(n-1,s,A,V);      // define
    ll m = (totSeg(0,s,A,V) * n)%p;
    for(i=1;i!=n;i++)
        m = (m + ((p+totSeg(i,s,A,V)-totSeg(i-1,s,A,V)) * (n-i))%p)%p;

    cout<<m;

    return 0;
}


Measured memory_bytes: 72832
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> b(n);
    for (int i=0;i<n-1;i++){
        cin >> b.at(i);
    }
    vector<int> a(n);
    a.at(0) = b.at(0);
    for (int i=1;i<n-1;i++){
        a.at(i) = min(b.at(i-1),b.at(i));
    }
    a.at(n-1) = b.at(n-2);
    int sum = 0;
    for(int i=0;i<n;i++){
        sum+=a.at(i);
    }
    cout << sum << endl;
    return 0;
}

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

using std::cin;
using std::cout;
using std::endl;
using std::string;

int main() {
	string a;
	while (1) {
		cin >> a;
		if (a == "0") break;	// ???????????¶
		else {
			int sum = 0;
			for (size_t i = 0; i < a.size(); i++)
			{
				sum += a[i]-'0';
			}
			cout << sum << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3132
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cassert>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < int(n); ++(i))
using namespace std;
template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void setmin(T & a, T const & b) { a = min(a, b); }

int main() {
    while (true) {
        int r, n; scanf("%d%d", &r, &n);
        if (r == 0 and n == 0) break;
        vector<int> hl(2*r);
        vector<int> hr(2*r);
        repeat (i, n) {
            int xl, xr, hi; scanf("%d%d%d", &xl, &xr, &hi);
            repeat_from (x, max(-r, xl), min(+r, xr)-1+1) setmax(hr[r  +x], hi);
            repeat_from (x, max(-r, xl)+1, min(+r, xr)+1) setmax(hl[r-1+x], hi);
        }
        double t = INFINITY;
        repeat_from (x, -r, +r+1) {
            double y = sqrt(r*r - x*x);
            if (x < +r) setmin(t, r - y + hr[r  +x]);
            if (-r < x) setmin(t, r - y + hl[r-1+x]);
        }
        printf("%.8lf\n", t);
    }
    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
    ll a, b, c, k;
    ll ans = 0;
    cin >> a >> b >> c >> k;
    if ((a + b) >= k && a != 0) {
        if (a <= k ) {
        ans = a;
        } else {
            ans = k;
        }
        cout << ans << endl;
    }else if((a + b) >= k && a == 0) {
        ans = 0;
        cout << ans << endl;
    }
    else {
        ans = a - (k-a-b);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
//	cut here before submit 
//	freopen ("testcase.search_i", "r", stdin );
	int n;
	scanf ("%d", &n );
	set<int> S;
	rep (i, n ){
		int in;
		cin >> in;
		S.insert (in );
	} // end rep
	int q;
	scanf ("%d", &q );
	vector<int> T (q, 0 );
	rep (i, q ){
		cin >> T[i];
	} // end rep

	int res = 0;
	rep (i, q ){
		if (S.count (T[i] ) ){
			++res;
		} // end if
	} // end rep
	printf ("%d\n", res );
		
	return 0;
}

Measured memory_bytes: 2116
n1 = [0 for i in range(10) for j in range(3)]
n2 = [0 for i in range(10) for j in range(3)]
n3 = [0 for i in range(10) for j in range(3)]
n4 = [0 for i in range(10) for j in range(3)]
for _ in range(int(input())):
	b,f,r,v = map(int, tuple(input().split(' ')))
	if b == 1:
		n1[10*(f-1)+r-1] += v
	elif b == 2:
		n2[10*(f-1)+r-1] += v
	elif b == 3:
		n3[10*(f-1)+r-1] += v
	elif b == 4:
		n4[10*(f-1)+r-1] += v
for j in range(3): 
	s = ''
	for i in range(10): s += ' ' + str(n1[10*j+i])
	print(s)
print('####################')
for j in range(3): 
	s = ''
	for i in range(10): s += ' ' + str(n2[10*j+i])
	print(s)
print('####################')
for j in range(3): 
	s = ''
	for i in range(10): s += ' ' + str(n3[10*j+i])
	print(s)
print('####################')
for j in range(3): 
	s = ''
	for i in range(10): s += ' ' + str(n4[10*j+i])
	print(s)


Measured memory_bytes: 7768
def wall(grid,x,y,d):
	#(0,1,2,3) => (R,D,L,U)
    if d == 0: return x < 4 and grid[y*2][x] == '1'
    if d == 1: return y < 4 and grid[y*2+1][x] == '1'
    if d == 2: return x > 0 and grid[y*2][x-1] == '1'
    if d == 3: return y > 0 and grid[y*2-1][x] == '1'
 
def move(x,y,d):
    if d == 0: return x+1,y,'R'
    if d == 1: return x,y+1,'D'
    if d == 2: return x-1,y,'L'
    if d == 3: return x,y-1,'U'
 
ans = ""
x=y=d=0
grid=[raw_input() for i in range(9)]
while x or y or d < 2:
    d = (d+3)%4
    while not wall(grid,x,y,d):
        d = (d+1)%4
    x,y,c = move(x,y,d)
    ans += c
print ans

Measured memory_bytes: 4260
#!/usr/bin/python2
# -*- coding: utf-8 -*-

import sys

def rl(proc=None):
    if proc is not None:
        return proc(sys.stdin.readline())
    else:
        return sys.stdin.readline().rstrip()

def srl(proc=None):
    if proc is not None:
        return map(proc, rl().split())
    else:
        return rl().split()

def solve(A, x):
    p = min(A[0], x)
    r = A[0] - p
    for i in xrange(1, len(A)):
        c = A[i]
        eat = max(0, c + p - x)
        p = c - eat
        r += eat
    return r

def main():
    N, x = srl(int)
    A = srl(int)
    print min(solve(A, x), solve(list(reversed(A)), x))

if __name__ == '__main__':
    main()

Measured memory_bytes: 11304
#include "bits/stdc++.h"

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

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

bool flag[56000] = {false};

int main(){

  int n; cin >> n;
  flag[0] = flag[1] = true;

  for(int i = 2;i < sqrt(55560);i++){
      if(!flag[i]){
        int j = 2;
        while(i * j < 55560){
          flag[ i * j ] = true;
          j++;
        }
      }
  }

  rep(i,55560){
    if( !flag[i] and  n > 0 and i % 5 == 1){
      if(n == 1)cout << i << endl;
      else cout << i << ' ';
      n--;
    }
  }

  return 0;
}


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

int main()
{
    int n;
    int dp[100005][5];
    memset(dp,0,sizeof(dp));
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=3;j++)
            cin>>dp[i][j];
    }
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=3;j++)
        {
            if(j==1)
                dp[i][j]+=max(dp[i-1][j+1],dp[i-1][j+2]);
            if(j==2)
                dp[i][j]+=max(dp[i-1][j-1],dp[i-1][j+1]);
            if(j==3)
                dp[i][j]+=max(dp[i-1][j-1],dp[i-1][j-2]);
        }
    }
    cout<<max(dp[n][1],max(dp[n][2],dp[n][3]))<<endl;
}


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

int main(){
  int n;
  cin >>n;
  int cnt = 1;
  vector<string> s(n);
  rep(i,n) cin >>s[i];
  sort(s.begin(), s.end());
  for(int i = 1; i<n; i++){
    if(s[i-1]!=s[i]) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 9600
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
h = 0
w = 0
for i in range(n-1):
  if a[i] == a[i+1]:
    h = a[i]
    break
for j in range(i+2, n-1):
  if a[j] == a[j+1]:
    w = a[j]
    break
print(h*w)

Measured memory_bytes: 14252
package main

import (
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func main() {
	var A, B int
	fmt.Scanf("%d %d\n", &A, &B)

	max := A * B
	if A+B > max {
		max = A + B
	}
	if A-B > max {
		max = A - B
	}
	fmt.Println(max)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}
const int N=3e5+5;
vector<int> g[N];
int x[N];
const int M=998244353;
const int P=((ll)(1e18))%M;
int p[N];
vector<int> c[3];

int32_t main(){
    p[0]=1;
    for(int i=1;i<N;++i)p[i]=(p[i-1]*P)%M;
    int n;
    cin>>n;
    forn(t,3){
        int m;
        cin>>m;
        for(int i=1;i<=n;++i)g[i].clear();
        forn(i,m){
            int a,b;
            cin>>a>>b;
            if(a>b)swap(a,b);
            g[a].pb(b);
        }
        for(int i=n;i>=1;--i){
            vector<int> go;
            for(int to:g[i])go.pb(x[to]);
            sort(go.begin(), go.end());
            go.resize(unique(go.begin(), go.end())-go.begin());
            x[i]=go.size();
            forn(j,go.size()){
                if(go[j]!=j){
                    x[i]=j;
                    break;
                }
            }
            if(x[i]>=c[t].size())c[t].resize(x[i]+1,0);
            (c[t][x[i]]+=p[i])%=M;
        }
    }
    int ans=0;
    forn(i,c[0].size()){
        forn(j,c[1].size()){
            int k=i^j;
            if(k<c[2].size()){
                int cur=c[0][i]*c[1][j]%M;
                (cur*=c[2][k])%=M;
                if((ans+=cur)>=M)ans-=M;
            }
        }
    }
    cout<<ans<<'\n';


    return 0;
}


Measured memory_bytes: 15360
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007
const long long INF = 1LL<<60;


int main(){	
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	vector<int> ans(N);
	ans = A;
	sort(A.begin(),A.end());
	for(int i = 0; i < N; i++){
		if(ans[i] == A[N-1]){
			cout << A[N-2] << endl;
		}else{
			cout << A[N-1] << endl;
		}

	}
}

Measured memory_bytes: 3200
import bisect
n=int(input())
x=[]
d=[]
mod=998244353
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
l.sort(key=lambda x:x[0])
for i in range(n):
    a,b=l[i][0],l[i][1]
    x.append(a)
    d.append(b)

r=[0]*n
r[-1]=n-1
for i in range(n-2,-1,-1):
    xi=bisect.bisect_left(x,x[i]+d[i])
    xi-=1
    r[i]=xi
    #if xi==i:
        #r[i]=i
    #else:
        #r[i]=r[xi]

#####segfunc######                                                              
def segfunc(x,y):
    return max(x,y)

def init(init_val):
    #set_val                                                                    
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built                                                                      
    for i in range(num-2,-1,-1):
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])
    
def update(k,x):
    k+=num-1
    seg[k]=x
    while k+1:
        k=(k-1)//2
        seg[k]=segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p+=num-1
    q+=num-2
    res=ide_ele
    while q-p>1:
        if p&1==0:
            res=segfunc(res,seg[p])
        if q&1==1:
            res=segfunc(res,seg[q])
            q-=1
        p=p//2
        q=(q-1)//2
    if p==q:
        res=segfunc(res,seg[p])
    else:
        res=segfunc(segfunc(res,seg[p]),seg[q])
    return res

ide_ele=-10
num=2**(n-1).bit_length()
seg=[ide_ele]*2*num
init(r)
rr=[0]*n
rr[-1]=n-1
for i in range(n-2,-1,-1):
    rr[i]=query(i,r[i]+1)
    update(i,rr[i])

dp=[0]*(n+1)
dp[-2]=2
dp[-1]=1
for i in range(n-2,-1,-1):    
    dp[i]=(dp[i+1]+dp[rr[i]+1])%mod
print((dp[0])%mod)

Measured memory_bytes: 124016
#include "bits/stdc++.h"
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define nl '\n'
typedef long double ld;
typedef long long ll;

const int N = 1007;
bool bpGraph[N][N];

bool findBPM(int u, bool seen[], int matchR[], int n) {
    for (int v = 0; v < n; v++) {
        if (bpGraph[u][v] && !seen[v]) {
            seen[v] = true;
            
            if (matchR[v] < 0 || findBPM(matchR[v], seen, matchR, n)) {
                matchR[v] = u;
                return true;
            }
        }
    }
    return false;
}

int main() { _
    int n; cin >> n;
    vector<pair<int, int>> red;
    vector<pair<int, int>> black;
    forn(i, 0, n) {
        int x, y; cin >> x >> y;
        red.push_back({x, y});
    }
    forn(i, 0, n) {
        int x, y; cin >> x >> y;
        black.push_back({x, y});
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (red[i].first < black[j].first && red[i].second < black[j].second) {
                bpGraph[i][j] = true;
            }
        }
    }
    
    int match[n];
    memset(match, -1, sizeof(match));
    int result = 0;
    for (int i = 0; i < n; i++) {
        bool seen[n];
        memset(seen, 0, sizeof(seen));
        if (findBPM(i, seen, match, n)) {
            result++;
        }
    }
    
    cout << result << nl;
}


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

long tri_n(long a)
{
	a--;
	return ((a * (a+1)) / 2);
}


int  main()
{

	long n ; cin >> n;
	vector<long> a(n);
	unordered_map<long, long> mp;
	rep(i, n)
	{
		cin >> a[i];
		mp[a[i]]++;
	}
	long sum = 0;
	set<long> st;
	rep(i, n)
	{
		if (!st.count(a[i]))
		{
			st.insert(a[i]);
			sum += tri_n(mp[a[i]]);
		}
	}
	rep(i, n)
	{
		cout << sum - ( tri_n(mp[a[i]]) - tri_n(mp[a[i]] - 1) ) << endl;
	}
	return 0;
}

Measured memory_bytes: 15048
#include <cstdio>
#include <iostream>
using namespace std;
int N, K;
long long result,  Count[200005];

int main()
{
    scanf("%d %d", &N, &K);
    if(K == 1)
    {
        result = (long long)N * N * N;
        printf("%lld", result);
        return 0;
    }
    for(int i = 1; i <= K; i++)
    {
        if((K - i) * 2 % K == 0)
        {
            long long temp;
            temp = N / K;
            if(N % K >= i)
            {
                temp++;
            }
            Count[i] = temp * temp;
            result += Count[i];
        }
    }
    result = result * (N / K);
    for(int i = 1; i <= N % K; i++)
    {
        result += Count[i];
    }
    printf("%lld",result);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int N,X;
	int D;
	int L;
	int i,count=0;

	scanf("%d %d",&N,&X);
	D=0;
	for(i=0; i<N; i++){
		scanf("%d",&L);
		if(D<=X) count++;
		D = D+L;
		if(D>X)break;
	}
	if(D<=X) count++;
	printf("%d\n",count );
}

Measured memory_bytes: 128
N = int(raw_input())
a = map(int, raw_input().split())
a.sort()

rank = [False] * 8

count = 0
for i in range(N):
  if 3200 <= a[i]:
    count += 1
  else:
    rank[int(a[i]/400)] = True

minimum = rank.count(True)
maximum = minimum + count
if minimum == 0:
  minimum = 1
print minimum, maximum

Measured memory_bytes: 2568
/*
 * Author : Sadi
 * Wed 01/07/2020
 * 19:17:30.14
 */
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int n, m, X, Y;
    cin >> n >> m >> X >> Y;
    vector<int> x(n + 1), y(m + 1);
    x[0] = X;
    y[0] = Y;
    for(int i = 1; i <= n; ++i) cin >> x[i];
    for(int i = 1; i <= m; ++i) cin >> y[i];
    sort(all(x));
    sort(all(y));
    if(x[n] < y[0] or y[m] < x[0]) {
        cout << "No War" << endl;
    }
    else {
        cout << "War" << endl;
    }
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int b[N];
    for(int i=0;i<N-1;i++){
        cin >> b[i];
    }
    int a[N],sum;
    sum = a[0] = b[0];
    for(int i=1;i<N-1;i++){
        if(b[i]<b[i-1]){
            a[i] = b[i];
        } else {
            a[i] = b[i-1];
        }
        sum = sum + a[i];
    }
    sum = sum + b[N-2];
    cout << sum << endl;
}

Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    int n,m;cin>>n>>m;
    vector<int> vec(n);
    for(int i=0;i<n;i++)cin>>vec[i];
    sort(all(vec));
    vector<pair<int,int>> com(m,pair<int,int> {0,0});
    for(int i=0;i<m;i++){
        cin>>com[i].second;
        cin>>com[i].first;
    }
    sort(all(com),greater<pair<int,int>>());
    int i=0;
    lint ans=0;
    bool end=false;
    for(auto p:com){
        int v=p.first;
        int num=p.second;
        while(num>0){
            num--;
            if(i>=n){end=true;break;}
            if(vec[i]<v){
                ans+=v;i++;
            }
            else {end=true;break;}
        }
        if(end)break;
    }
    if(i<n){
        for(i;i<n;i++){
            ans+=vec[i];
        }
    }
    cout<<ans<<endl;
}


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

namespace abc134_d
{
    static class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine().ToInteger();
            var a = Console.ReadLine().ToIntArray();

            // 偶数か奇数かなので、ボールを1つ入れるか入れないかだけを考えればいい。

            var boxes = new int[n];
            for (int i = 0; i < a.Length; i++)
            {
                // 逆さから考える。
                var number = a.Length - i;
                var index = number - 1;

                // 倍数がいくつあるか
                var div = n / number - 1;
                // 倍数の総和
                var sum = 0;
                for (int j = 0; j < div; j++)
                {
                    sum += boxes[number * (j + 2) - 1];
                }
                if (sum % 2 != a[index])
                {
                    // 総和が条件に一致しないときだけ1を足す
                    boxes[index] = 1;
                }
            }
            Console.WriteLine($"{boxes.Where(m => m > 0).Count()}");
            Console.WriteLine($"{string.Join(" ", boxes.Select((m, i) => m > 0 ? (i + 1).ToString() : ""))}");
        }

        static int ToInteger(this string s)
        {
            return int.Parse(s);
        }

        static int[] ToIntArray(this string s, char separator = ' ')
        {
            return s.Split(separator).Select(m => m.ToInteger()).ToArray();
        }
    }
}


Measured memory_bytes: 31704
// Words are flowing out like endless rain into a paper cup
// They slither while they pass they slip away across the universe
// Pools of sorrow, waves of joy are drifting through my open mind
// Possessing and caressing me

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

using LL = long long;

namespace _buff {

const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
    if (ib == ie) {
        ib = ibuf;
        ie = ibuf + fread(ibuf, 1, BUFF, stdin);
    }
    return ib == ie ? -1 : *ib++;
}

}

LL read() {
    using namespace _buff;
    LL ret = 0;
    bool pos = true;
    char c = getc();
    for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
        assert(~c);
    }
    if (c == '-') {
        pos = false;
        c = getc();
    }
    for (; c >= '0' && c <= '9'; c = getc()) {
        ret = (ret << 3) + (ret << 1) + (c ^ 48);
    }
    return pos ? ret : -ret;
}

const size_t N = 5e3 + 5;

int n, f[N], mod;

void iadd(int &dp, const int &val) {
    dp += val;
    if (dp >= mod) {
        dp -= mod;
    }
}

void ladd(int &dp, const LL &val) {
    dp = (dp + val) % mod;
}

int main() {
    n = read(); mod = read();
    f[0] = 1;
    for (int i = 2; i <= n; ++i) {
        int coeff = min(i - 1, n + 2 - i);
        for (int j = coeff; j <= n; ++j) {
            iadd(f[j], f[j - coeff]);
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ladd(ans, (LL) f[i] * (n - i));
    }
    cout << ans;
    return 0;
}


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


int hoge(int x, int y)
{
	int r = 1;
	for(int i = 0; i < y; ++i)
		r *= x;
	return r;
}

int calc(int state, int m, vector<int> &a, vector<int> &memo)
{
	if(memo[state] != -1)
		return memo[state];

	int n = a.size();
	int ans = 0, filter = 0, s = state;
	
	for(int i = 0; i < m; ++i) {
		int x = s % 3;
		if(x != 0) filter |= 1 << i;
		if(x == 2) ans |= 1 << i;
		s = s / 3;
	}

	int count = 0;

	for(int i = 0; i < n; ++i) {

		if((a[i] ^ ans) & filter)
			continue;
		count += 1;
	}

	if(count <= 1)
		return memo[state] = 0;

	int ret = 1000;

	for(int i = 0; i < m; ++i) {

		if((filter >> i) & 1)
			continue;
		int p3i = hoge(3, i);
		int lv = calc(state + p3i * 1, m, a, memo) + 1;
		int rv = calc(state + p3i * 2, m, a, memo) + 1;
		ret = min(ret, max(lv, rv));
	}

	return memo[state] = ret;
}

int main()
{
	while(true) {

		int m, n;
		vector<int> a;
		vector<int> memo;

		scanf("%d%d", &m, &n);
		if(m == 0)
			break;
		a.resize(n);
		for(int i = 0; i < n; ++i) {
			char temp[64];
			scanf("%s", temp);
			int &v = a[i];
			for(int j = 0; j < m; ++j)
				v |= (temp[j] == '1') << j;
		}

		memo.resize(hoge(3, m), -1);
		int ans = calc(0, m, a, memo);

		printf("%d\n", ans);
	}

	return 0;
}

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

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		int a[20];
//		int allsum=0;
		for(int i=0; i < n; i++){
			cin >> a[i];
//			allsum+=a[i];
		}
		sort(a,a+n);

		int ret=10000000;
		for(int s = 0; s < (1 << n); s++){
			int sum=0;
			int left=0;
			for(int i = 0; i < n; i++){
				if(1 & (s>>i)){
					sum+=a[i];
				}
				else
					left+=a[i];
			}
			ret=min(ret,abs(sum-left));
			if(ret==0){
				break;
			}
		}
		cout<<ret<<endl;

		//int Asum=0;
		//vector<int>A,B;
		//int minSum;
		//for(int i = 0; i < n; i++){
		//	minSum = abs(Asum-sum);
		//	if(Asum < sum){
		//		A.push_back(a[i]);
		//		Asum+=a[i];
		//		sum-=a[i];
		//	}
		//	else{
		//		for(int j = i; j < n; j++){
		//			B.push_back(a[j]);
		//		}
		//		break;
		//	}
		//}
		//minSum = abs(Asum-sum);
		//for(int i = 0; i < A.size(); i++){
		//	if(Asum <= sum)
		//		break;
		//	Asum-=A[i];
		//	sum+=A[i];
		//	minSum = min(minSum,abs(Asum-sum));
		//}
		//cout << minSum << endl;
	}

	return 0;
}

Measured memory_bytes: 868
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef double db;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int main(){
    int n;scanf("%d",&n);
    ll ans=0;
    for(int i=1;i<=n;i++){
        if(i%3&&i%5)ans+=i;
    }
    printf("%lld\n",ans);
    return 0;
}

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

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,c;
    cin>>n>>m>>c;
    int b[m];
    for(int i=0;i<m;i++)
    {
        cin>>b[i];
    }
    int ans=0;
    while(n--)
    {
        int temp=0;
        for(int i=0;i<m;i++)
        {
            int a;
            cin>>a;
            temp+=a*b[i];
        }
        temp+=c;
        if(temp>0)
        ans++;
        
    }
    cout<<ans<<"\n";

    
}

Measured memory_bytes: 3652
#include <iostream>
using namespace std;
int x, mx=1, a;
int main() {
	cin>>x;
	for(int i=2; i*i<=x; i++) {
		for(a=i*i; a<=x; a*=i) mx = max(mx, a);
	}
	cout<<mx;
	return 0;
}

Measured memory_bytes: 256