akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush,heappop,heapify
INF=10**30
def dijkstra(G,s,n):
    que=[(0,s)]
    dist=[INF]*n
    dist[s]=0
    while que:
        mincost,u=heappop(que)
        if(mincost>dist[u]):
            continue
        for v,c in G[u]:
            if(dist[u]+c<dist[v]):
                dist[v]=dist[u]+c
                heappush(que,(dist[v],v))
    return dist
N=int(input())
G=[[] for i in range(N)]
for i in range(N-1):
    a,b,c=map(int,input().split())
    G[a-1].append([b-1,c])
    G[b-1].append([a-1,c])
Q,K=map(int,input().split())
dist=dijkstra(G,K-1,N)
for i in range(Q):
    x,y=map(lambda x:int(x)-1,input().split())
    print(dist[x]+dist[y])

Measured memory_bytes: 103968
def main():
    N = int( input())
    D = [ tuple( map( int, input().split())) for _ in range(N)]
    cnt = 0
    for i in range(N):
        if D[i][0] == D[i][1]:
            cnt += 1
        else:
            cnt = 0
        if cnt >= 3:
            print("Yes")
            return
    print("No")
        
if __name__ == '__main__':
    main()


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

int main(){
	int e;
	while(cin >> e && e){
		int min_count = 1000000;
		for(int z = 0; z*z*z <= e; z++){
			for(int y = 0; y*y <= e - z*z*z; y++){
				min_count = min(min_count, z+y+e-y*y-z*z*z);
			}
		}
		cout << min_count << endl;
	}
	return 0;
}

Measured memory_bytes: 868
//============================================================================
// Author       : Sun YaoFeng
//============================================================================

//#pragma 	comment(linker, "/STACK:100240000,100240000")
//#include	<cstdio>
//#include	<cstdlib>
//#include	<cstring>
//#include	<algorithm>

#include	<bits/stdc++.h>

using	namespace	std;

#define DB		double
#define	lf		else if
#define I64		long long
#define	Rd()	(rand()<<15|rand())
#define For(i,a,b)	for(int i=a,lim=b;i<=lim;i++)
#define Rep(i,a,b)	for(int i=a,lim=b;i>=lim;i--)

#define	fi	first
#define se	second
#define MK	make_pair
#define PA	pair<int, int>

//#define	min(a,b)	((a)<(b)?(a):(b))
//#define	max(a,b)	((a)<(b)?(b):(a))

#define	CH	(ch=getchar())
int		IN()	{
		int x= 0, f= 0, ch;
		for	(; CH < '0' || ch > '9';)	f= (ch == '-');
		for	(; ch >= '0' && ch <= '9'; CH)	x= x*10 + ch -'0';
		return	f? -x : x;
}

#define n	100005

int		N, E, st[n], Q[n];

I64		T, X[n], F[n];

I64		Cost(int j, int i){
		return	X[j+1] - X[j] + max(T, (X[i] - X[j+1])*2) + (X[i] - X[j+1]);
}

int		main(int argc, char* argv[]){
		N= IN();
		E= IN();
		T= IN();
		For(i, 1, N)	X[i]= IN();
		
		int h= 1, t= 1;
		st[1]= 1;	Q[1]= 0;
		
		For(i, 1, N)	{
			for	(; h < t && st[h+1] == i; h++);
			F[i]= F[Q[h]] + Cost(Q[h], i);
			
			for	(; st[t] > i && F[i] + Cost(i, st[t]) < F[Q[t]] + Cost(Q[t], st[t]); )	t--;
			
			int l= max(st[t], i), r= N+1;
			for	(; l+1 < r;)	{
				int Mid= (l+r) >> 1;
				if	(F[i] + Cost(i, Mid) < F[Q[t]] + Cost(Q[t], Mid))	r= Mid;
					else	l= Mid;
			}
			
			if	(r != N+1)	t++, Q[t]= i, st[t]= r;
		}
		
		cout << F[N] + E - X[N] << endl;
		
		return	0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;   
string s[4];
int p[4];
int main(){
	fastIO;
	for(int i=1;i<=3;i++){
		cin>>s[i];
	}
	int ps=1;
	while(p[ps] < (int)s[ps].size()){
		if(s[ps][p[ps]]	== 'a'){
			p[ps]++;
			ps=1;
		}	
		else{
			if(s[ps][p[ps]]	== 'b'){
				p[ps]++;
				ps=2;
			}
			else {
				p[ps]++;
				ps=3;
			}
		}
	}                 
	if(ps == 1)cout<<"A\n";
	else{
		if(ps == 2)cout<<"B\n";
		else cout<<"C\n";
	}
	return 0;
}

Measured memory_bytes: 256
// import std = require('tstl')

{
  type Print = void | string | number | string[] | number[]
  let outs: Print[] = []

  const main = (): Print => {
    const r = _io()
    const [N] = r.nn()
    let a = r.nn()

    a.sort((x, y) => x - y)
    const hash = {}
    const dups = {}

    a.forEach((v) => {
      if (hash[v]) dups[v] = true
      hash[v] = true
    })
    a = Object.keys(hash).map(Number)
    const hit = {}
    let pc = 0

    a.forEach((v) => {
      if (!hit[v] && !dups[v]) {
        pc++
      }
      if (hit[v]) {
        return
      }
      for (var i = v; i <= 1000000; i += v) {
        hit[i] = true
      }
    })
    // console.log(a)

    // for (var i = 3; i < 1000000; i += 2) {
    //   if (primes.every((p) => i % p !== 0)) {
    //     primes.push(i)
    //   }
    // }

    // const primes: number[] = []

    // for (let i = 0; i < a.length; i++) {
    //   if (primes.every((p) => a[i] % p !== 0)) {
    //     if (!dups[a[i]]) pc++
    //     primes.push(a[i])
    //   }
    // }
    return pc
  }

  const _io = (i = 0) => {
    const str = require('fs').readFileSync('/dev/stdin', 'utf8')
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')

    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map((v) => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  outs.push(main())

  console.log(
    outs
      .map((line) => (typeof line === 'object' ? line.join(' ') : String(line)))
      .join('\n')
  )
}


Measured memory_bytes: 117604
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
ll inf = 1e10;
ll w[105], v[105];
ll dp[300005] = {};
ll t[200005];
vector<ll> b[100005];
int rec(int x) {
	if (dp[x] > 0) {
		return dp[x];
	}
	int mx = 0;
	for (int i = 0; i < b[x].size(); i++) {
		mx = max(mx, rec(b[x][i]) + 1);
	}
	dp[x] = mx;
	return mx;
}
int main() {
	ll n, m;
	cin >> n >> m;
	ll x, y;
	for (int i = 0; i < m; i++) {
		cin >> x >> y;
		x--;
		y--;
		b[x].push_back(y);
	}
	for(int i = 0; i < n; i++) {
		dp[i] = 0;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (dp[i] == 0) {
			ans = max(ans, rec(i));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11520
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == 1)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> void SORT_(vector<int>& v,bool GREATER = 0){if(GREATER == 0)sort(v.begin(),v.end());else{sort(v.begin(),v.end(),std::greater<T>());}}


int heap[1000], sz = 0;


void solve(void)
{
  int N;
  cin>>N;
  vector< vector<pair<int,int> > > data;
  for (int i = 0; i < N; i++)
  {
    int A;
    cin>>A;
    vector<pair<int,int> >  data_inst(A);
    for (int i = 0; i < A; i++)
    {
      cin>>data_inst[i].first>>data_inst[i].second;
      data_inst[i].first--;
    }
    // DEBUG(data_inst.size());
    
    data.push_back(data_inst);
  }

  int ANS = 0;
  for (int bit = 0; bit < (1<<N); bit++)
  {
    vector<int> info(N,0);
    int A = bit;
    int NUM = 0;
    for (int i = 0; i < N; i++)
    {
      // DEBUG(bit);
      info[i] = A%2;
      NUM += A%2;
      A /= 2;

    }
    // DEBUG(NUM);
    // DEBUG("X",bit);

    // DEBUG(info);
    bool OK = true;
    for (int i = 0; i < N; i++)
    {
      if(info[i] == 1)
      {
        // DEBUG(data[i].size());
        for (int j = 0; j < data[i].size(); j++)
        {

          int P = data[i][j].first;
          int Q = data[i][j].second;

          if(info[P] != Q) OK = false;
        }
      }
    }

    if(OK == true)
    {
      chmax(ANS,NUM);
    }
    
  }
  cout<<ANS<<endl;
  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

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

int main(void) {
	uint64_t A, B, C;
	if (scanf("%" SCNu64 "%" SCNu64 "%" SCNu64, &A, &B, &C) != 3) return 1;
	if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) {
		puts("0");
	} else {
		uint64_t asumikana, kitamuraeri, kugimiyarie;
		uint64_t haradahitomi;
		asumikana = A * B;
		kitamuraeri = B * C;
		kugimiyarie = C * A;

		haradahitomi = asumikana;
		if(kitamuraeri < haradahitomi) haradahitomi = kitamuraeri;
		if (kugimiyarie < haradahitomi) haradahitomi = kugimiyarie;
		printf("%" PRIu64 "\n", haradahitomi);
	}
	return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector<string> s(n);
	rep(i,n){
		cin >> s[i];
	}
	
	int a = 0;
	int b = 0;
	int ba = 0;
	int ans = 0;
	rep(i,n){
		rep(j,s[i].size()-1){
			if(s[i][j] == 'A' && s[i][j+1] == 'B') ans++;
		}
		if(s[i][0] == 'B') b++;
		if(s[i][s[i].size()-1] == 'A') a++;
		if(s[i][0] == 'B' && s[i][s[i].size()-1] == 'A') ba++;
	}
	
	if(ba == a && ba == b && b > 0){
		cout << ans + min(a,b) - 1 << endl;
	}else{
		cout << ans + min(a,b) << endl;
	}
    return 0;
}



Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;

struct Point {
  long long x, y;
  bool operator<(const Point& another) const {
    if (another.x == x) {
      return y < another.y;
    } else {
      return x < another.x;
    }
  }
};

struct Node {
  Point p;
  vector<Node*> edges;
  bool visited;
};

bool y_order(const Point &a, const Point &b) {
  if (a.y == b.y) {
    return a.x < b.x;
  } else {
    return a.y < b.y;
  }
}

void dfs(Node *n, long long &n_points, set<long long> &xlines, set<long long> &ylines) {
  if (!n->visited) {
    n->visited = true;
    ++n_points;
    xlines.insert(n->p.x);
    ylines.insert(n->p.y);
    for (Node* next : n->edges) {
      dfs(next, n_points, xlines, ylines);
    }
  }
  return;
}

void solve(long long N, std::vector<long long> x, std::vector<long long> y){
  vector<Point> points(N);
  map<Point, int> pmap;
  for (int i = 0; i < N; i++) {
    points[i] = {x[i], y[i]};
  }
  for (int i = 0; i < N; i++) {
    pmap[points[i]] = i;
  }

  vector<Node> G;
  for (int i = 0; i < N; i++) {
    G.push_back((Node){points[i], vector<Node*>(), false});
  }

  int u, v;
  sort(points.begin(), points.end());
  for (int i = 1; i < N; i++) {
    if (points[i-1].x == points[i].x) {
      u = pmap[points[i-1]];
      v = pmap[points[i]];
      G[u].edges.push_back(&G[v]);
      G[v].edges.push_back(&G[u]);
    }
  }

  sort(points.begin(), points.end(), y_order);
  for (int i = 1; i < N; i++) {
    if (points[i-1].y == points[i].y) {
      u = pmap[points[i-1]];
      v = pmap[points[i]];
      G[u].edges.push_back(&G[v]);
      G[v].edges.push_back(&G[u]);
    }
  }

  long long n_points, ans;
  set<long long> xlines, ylines;

  ans = 0;

  for (int i = 0; i < N; i++) {
    if (!G[i].visited) {
      n_points = 0;
      xlines.clear();
      ylines.clear();
      dfs(&G[i], n_points, xlines, ylines);
      ans += xlines.size() * ylines.size() - n_points;
    }
  }

  std::cout << ans << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> x(N);
  std::vector<long long> y(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&x[i]);
    scanf("%lld",&y[i]);
  }
  solve(N, std::move(x), std::move(y));
  return 0;
}


Measured memory_bytes: 26732
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;
typedef mp::cpp_int BigInt;
typedef long long ll;

BigInt gcdBigInt(BigInt a, BigInt b)
{
    if (a < b) {
        std::swap(a, b);
    }
    
    return b ? gcdBigInt(b, a % b) : a;
}

BigInt lcmBigInt(BigInt a, BigInt b)
{
    return a * b / gcdBigInt(a, b);
}

const ll MOD = 1000000007; // 1e9 + 7

ll modinv(ll a, ll modVal) {
    ll b = modVal, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; std::swap(a, b);
        u -= t * v; std::swap(u, v);
    }
    u %= modVal; 
    if (u < 0) u += modVal;
    return u;
}

ll solve(const std::vector<ll> a)
{
    const ll n = a.size();
    ll m = a[0];
    std::vector<ll> lcmArray;

    BigInt mBigInt = a[0];
    for (int i = 1; i < n; i++) {
        mBigInt = lcmBigInt(mBigInt, a[i]);
    }

    m = static_cast<ll>(mBigInt % MOD);

    ll sum = 0;
    for (int i = 0; i < n; i++) {
        sum += m * modinv(a[i], MOD);
        sum %= MOD;
    }

    return sum;
}

int main(int argc, char *argv[])
{
    ll n;
    std::vector<ll> a;

    std::cin >> n;

    a.resize(n);

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

    ll ans = solve(a);

    std::cout << ans << std::endl;

    return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, k;
  cin >> n >> k;
  
  if (1 + (k - 1) * 2 <= n) cout << "YES\n";
  else cout << "NO\n";
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;

void rec(pair<double, double> p1, pair<double, double> p2, int depth, vector<pair<double, double> >& v)
{
  if (depth <= 0) {
    v.push_back(p2);
    return;
  }
  pair<double, double> s, t, u;
  s.first = p1.first + (p2.first - p1.first) / 3;
  s.second = p1.second + (p2.second - p1.second) / 3;
  t.first = p1.first + (p2.first - p1.first) * 2 / 3;
  t.second = p1.second + (p2.second - p1.second) * 2 / 3;
  double x = t.first - s.first, y = t.second - s.second;
  u.first = x / 2 - sqrt(3) * y / 2 + s.first;
  u.second = sqrt(3) * x / 2 + y / 2 + s.second;
  //fprintf(stderr, "DEBUG: u=(%lf, %lf)\n", u.first, u.second);
  rec(p1, s, depth - 1, v);
  rec(s, u, depth - 1, v);
  rec(u, t, depth - 1, v);
  rec(t, p2, depth - 1, v);
}

int main()
{
  int n = 0;
  fscanf(stdin, "%d", &n);
  pair<double, double> p1 = make_pair(0, 0);
  pair<double, double> p2 = make_pair(100, 0);
  vector<pair<double, double> > v;
  v.push_back(p1);
  rec(p1, p2, n, v);
  for (int i = 0; i < v.size(); ++i) {
    fprintf(stdout, "%.6lf %.6lf\n", v[i].first, v[i].second);
  }
  return 0;
}

Measured memory_bytes: 1356
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

template <typename T>
void deb1(T x) {
  cout << "debug: " << x << "\n";
}

template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  int n, m;
  cin >> n >> m;
  vi a(m), b(m);
  rep(i, m) cin >> a[i] >> b[i], --a[i], --b[i];
  int ans = 0;
  rep(i, m) {
    vvi g(n);
    rep(j, m) {
      if (j == i) continue;
      g[a[j]].pb(b[j]);
      g[b[j]].pb(a[j]);
    }
    vector<bool> f(n, true);
    f[0] = false;
    queue<int> pq;
    pq.push(0);
    while (!pq.empty()) {
      for (auto j : g[pq.front()])
        if (f[j]) f[j] = false, pq.push(j);
      pq.pop();
    }
    bool flag = false;
    rep(j, n) if (f[j]) flag = true;
    if (flag) ans++;
  }
  out(ans);
}
int main(void) { solve(); }

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#define int long long int
using namespace std;

const int maxN = 2e5, maxVal = 1e6, MOD = 998244353;
int N, cnt[maxVal + 10], W[maxVal], inv[maxVal], x;

inline void initW(){
    inv[1] = 1;
    for(int i = 2; i <= maxVal; i++){
        inv[i] = (MOD - MOD/i) * inv[(MOD % i)] % MOD;
    }
    W[1] = 1;
    for(int i = 2; i <= maxVal; i++) W[i] = inv[i];
    for(int i = 1; i <= maxVal; i++) {
        for(int j = 2 * i; j <= maxVal; j += i) W[j] = (W[j] + MOD - W[i]) % MOD;
    }
}

signed main(){
    cin >> N;
    int su = 0;
    for(int i = 0; i < N; i++){
        cin >> x;
        su = (su + x) % MOD;
        cnt[x]++;
    }
    initW();
    /*
    for(int i = 1; i <= 10; i++){
        cout << inv[i] << " ";
    }
    cout << endl;
    for(int i = 1; i <= 10; i++){
        cout << W[i] << " ";
    }

    cout << endl;
    */
    int ans = 0, tw;
    for(int d = 1; d <= maxVal; d++){
        tw = 0;
        for(int j = d; j <= maxVal; j += d){
            tw = (tw + cnt[j] * j) % MOD;
        }
        ans = (ans + ((tw * tw % MOD) * W[d]) % MOD) % MOD;
    }
    ans = (ans - su + MOD) % MOD;
    ans = ( ans * inv[2] ) % MOD;
    cout << ans << endl;
}


Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

    int a, b;
    cin >> a >> b;

    if(b == 1){
        cout << 0 << endl;
        return 0;
    }

    int res = a;
    int ans = 1;
    while(res < b){
        res += (a-1);
        ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 28;
int a[maxn], t0[maxn], t1[maxn];
int main(){
	int n, max0 = 0, max1 = 1, i0 = 0, i1 = 0, max00 = 0, max11 = 0;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		//t[a[i]] ++;
		if(i % 2 == 0){
			t0[a[i]] ++;
			max0 = max(max0, t0[a[i]]);
			if(t0[a[i]] == max0)
				i0 = a[i];
		}
		else{
			t1[a[i]] ++;
			max1 = max(max1, t1[a[i]]);
			if(t1[a[i]] == max1)
				i1 = a[i];
		}
	}
	//cout << max1 << "   " << max0 << "\n\n";
	if(i0 != i1)
		return cout << n - (max0 + max1), 0;
	for(int i = 0; i < n; i++)
		if(i % 2 == 0 && a[i] != i0)
			max00 = max(t0[a[i]], max00);
		else
			if(a[i] != i1)
				max11 = max(t1[a[i]], max11);
	//cout << n - (max1 + max00) << "  " << n - (max0 + max11) << "\n\n";
	cout << min(n - (max1 + max00) , n - (max0 + max11));
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define fi first
#define se second
#define mod 1000000007
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
vector<ll> vec;
ll calc(ll x)
{
	ll i,f=1;
	for(i=2;i*i<=x;i++)
	{
		if(x%i==0)
		{
			f++;
			if(x/i!=i)
				f++;
		}
	}
	return f;
}
vector<ll> func(ll x)
{
	ll i;
	vec.push_back(x);
	for(i=2;i*i<=x;i++)
	{
		if(x%i==0)
			vec.push_back(i);
	}
	return vec;
}
int main()
{
	ios;
	ll n,sum=0,i,m,d;
	cin>>n;
	if(n==2)
	{
		cout<<1<<endl;
		exit(0);
	}
	sum+=calc(n-1);
	func(n);
	for(i=0;i<vec.size();i++)
	{
		d=vec[i];m=n;
		while(m%d==0)
			m=m/d;
		if(m%d==1)
			sum++;
	}
	cout<<sum<<endl;
}


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

int main() {
  string s;
  cin >> s;
  int f, b;
  istringstream(s.substr(0, 2)) >> f;
  istringstream(s.substr(2, 4)) >> b;
  int month[2];
  if (f == 0 || f > 12) {
    month[0] = 0;
  } else {
    month[0] = 1;
  }
  if (b == 0 || b > 12) {
    month[1] = 0;
  } else {
    month[1] = 1;
  }
  if (month[0] == 1 && month[1] == 1) {
    cout << "AMBIGUOUS" << endl;
  }
  if (month[0] == 1 && month[1] == 0) {
    cout << "MMYY" << endl;
  }
  if (month[0] == 0 && month[1] == 1) {
    cout << "YYMM" << endl;
  }
  if (month[0] == 0 && month[1] == 0) {
    cout << "NA" << endl;
  }
}

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

using namespace std;

inline bool cmp(const string &a, const string &b) {
  if(a.size() == b.size()) return a<b;
  return a.size()<b.size();
}

int main() {
  
  int N;
  while(cin >> N && N) {
    vector<string> vec(N);
    for(int i=0; i<N; i++) {
      cin >> vec[i];
    }

    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    N = vec.size();
    
    vector<bool> check(N, true);
    for(int i=0; i<N; i++)
      for(int j=0; j<N; j++) {
        if(i == j) continue;
        if(vec[i].find(vec[j]) != string::npos)
          check[j] = false;
      }
    
    vector<string> strs;
    for(int i=0; i<N; i++) {
      if(check[i]) strs.push_back(vec[i]);
    }
    
    N = strs.size();
    string next[12][12];
    for(int k=0; k<N; k++) {
      for(int l=0; l<N; l++) {
        if(k == l) continue;
        const string &s = strs[k], &t = strs[l];
        int const ssize = s.size(), tsize = t.size();
        next[k][l] = t;
        for(int i=0; i<ssize; i++) {
          bool ok = true;
          for(int j=0; j<ssize-i; j++) {
            if(j == tsize) { ok = false; break; }
            if(s[i+j] != t[j]) { ok = false; break; }
          }
          if(ok) {
            next[k][l] = t.substr(ssize-i);
            break;
          }
        }
      }
    }
    
    string dp[1<<11][11];
    
    for(int i=0; i<N; i++)
      dp[1<<i][i] = strs[i];
    
    for(int S=0; S<(1<<N); S++) {
      for(int i=0; i<N; i++) {
        if(!(S >> i & 1)) continue;
        if(dp[S][i].empty()) continue;
        for(int j=0; j<N; j++) {
          if(S >> j & 1) continue;
          if(dp[S|(1<<j)][j].empty()) dp[S|(1<<j)][j] = dp[S][i] + next[i][j];
          else dp[S|(1<<j)][j] = min(dp[S|(1<<j)][j], dp[S][i] + next[i][j], cmp);
        }
      }
    }
    
    string ans = dp[(1<<N)-1][0];
    for(int i=0; i<N; i++) {
      ans = min(ans, dp[(1<<N)-1][i], cmp);
    }
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1816
use whiteread::parse_line;

fn main() {
    let _n: u64 = parse_line().unwrap();
    let xs: Vec<u64> = parse_line().unwrap();
    let res = xs
        .iter()
        .enumerate()
        .filter(|&(i, val)| (i + 1) % 2 != 0 && val % 2 != 0)
        .count();
    println!("{}", res);
}


Measured memory_bytes: 2140
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)

string s;

int cnt[26];
bool good(int x, int y)
{
    for(int i = 0; i < 26; i++)
    {
        cnt[i] = 0;
    }
    
    int l = y - x + 1;
    for(int i = x; i <= y; i++)
    {
        cnt[s[i] - 'a']++;
        if(cnt[s[i] - 'a'] > l / 2)
        {
            return true;
        }
    }
    return false;
}


void solve()
{
    cin >> s;
    int n = (int) s.length();
    for(int l = 2; l <= min(100, n); l++)
    {
        for(int i = 0; i + l - 1 < n; i++)
        {
            int j = i + l - 1;
            if(good(i, j))
            {
                cout << i + 1 << " " << j + 1;
                return;
            }
        }
    }
    cout << -1 << " " << -1;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0);
    //freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
    solve();
    cout << "\n";
    return 0;
}

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

using namespace std;

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

#define X first
#define Y second

const int N=2e5+10;
const ll inf=1e16;

struct segtree{
    ll b[N<<2];
    void build(){
        fill(b,b+(N<<2),inf);
    }
    ll get(int node,int L,int R,int l,int r){
        if (L>r||R<l) return inf;
        if (l<=L&&R<=r) return b[node];
        return min(get(node*2,L,(L+R)/2,l,r),get(node*2+1,(L+R)/2+1,R,l,r));
    }
    void update(int node,int L,int R,int pos,ll val){
        if (L>pos||R<pos) return;
        if (L==R){
            b[node]=min(b[node],val);
            return;
        }
        update(node*2,L,(L+R)/2,pos,val);
        update(node*2+1,(L+R)/2+1,R,pos,val);
        b[node]=min(b[node*2],b[node*2+1]);
    }
}msegL,msegR;




ll ssum[N];
int n,m,st[2];
int qu[N];


void prepare(){
    scanf("%d%d%d%d",&n,&m,st,st+1);
    ///stone 0 and stone 1
    for(int i=1;i<=m;i++) scanf("%d",qu+i);
    ///ssum[i]== time needed to go from qu[i]->qu[i+1]->...->qu[m]
    for(int i=m-1;i>=1;i--) ssum[i]=ssum[i+1]+abs(qu[i]-qu[i+1]);
}
ll solve(){
    ///special case
    if (m==1) return min(abs(st[0]-qu[1]),abs(st[1]-qu[1]));
    msegL.build();
    msegR.build();

    ll scale=0;
    for(int i=2;i<=m;i++){
        ///first move of stone 1 is to x[i]
        ll cost=ssum[1]-ssum[i-1]+abs(qu[1]-st[0])+abs(qu[i]-st[1]);
        ///first move of stone 0 is to x[i]
        cost=min(cost,ssum[1]-ssum[i-1]+abs(qu[1]-st[1])+abs(qu[i]-st[0]));
        ///other case
        ll bestL=msegL.get(1,1,n,1,qu[i])+qu[i]+scale;
        ll bestR=msegR.get(1,1,n,qu[i],n)+(n-qu[i])+scale;
        ///cost == a stone at x[i] and a stone at pos x[i-1]
        cost=min(cost,min(bestL,bestR));
        ///scaling other position as a stone move from x[i-1] to x[i]
        ///note that in this case , both stone have moved at least once
        scale+=abs(qu[i]-qu[i-1]);
        ///update two side
        ///because there are two cases of absolute value
        msegL.update(1,1,n,qu[i-1],cost-qu[i-1]-scale);
        msegR.update(1,1,n,qu[i-1],cost-(n-qu[i-1])-scale);
    }
    ///initial ans is when stone 1 or stone 2 didn't move
    ll ans=ssum[1]+min(abs(st[0]-qu[1]),abs(st[1]-qu[1]));
    for(int i=1;i<=n;i++) ans=min(ans,msegL.get(1,1,n,i,i)+i);
    return ans+scale;
}
int main(){
    prepare();
    cout<<solve();
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(6) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;

signed main(){
    double pi = 3.14159265358979323846264338327950288419716939937510582097494459;
    double x;
    cin >> x;
    printf("%.16f %.16f\n",x*x*pi,x*2*pi);
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}



Measured memory_bytes: 3200
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define X first
#define Y second
#define clr(u,v); memset(u,v,sizeof(u));
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e5+10;
const int INF=0x3f3f3f3f;
char str[maxn];

int main()
{
    int g=0,p=0;
    scanf("%s",str);
    int len=strlen(str);
    for (int i=0;i<len;i++)
    if (str[i]=='g') g++;
    else p++;
    int P=len/2;
    int G=len-P;
//     printf("%d %d\n",P,p);
//    printf("%d %d\n",G,g);
    if (p>=P) {
        p-=P;
        P=0;
    }
    else {
        P-=p;
        p=0;
    }
    if (g>=G) {
        g-=G;
        G=0;
    }
    else {
        G-=g;
        g=0;
    }
//    printf("%d %d\n",P,p);
//    printf("%d %d\n",G,g);
    printf("%d\n",P-p);
    return 0;
}


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

bool solve(vector<int> A, long long N) {
    for (long long i = 0; i < 3; i++) {
        long long check = A[i * (N / 3)];
        for (long long j = 0; j < (N / 3); j++) {
            if (A[i * (N / 3) + j] != check) return false;
        }
    }
    if ((A[1 * (N / 3)] ^ A[2 * (N / 3)]) == A[0])
        return true;
    else
        return false;
}

bool newSolve(vector<int> A, long long N) {
    long long idx = 0;
    long long check = 0;
    for (long long i = 0; i < A.size(); i++) {
        if (A[i] != 0 && check == 0) {
            check = A[i];
            idx = i;
            break;
        }
    }
    if (!check) return true;
    if (idx * 3 != N) return false;
    for (long long i = idx; i < A.size(); i++) {
        if (A[i] != check) return false;
    }
    return true;
}

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

    long long N;
    cin >> N;
    vector<int> A(N);
    for (long long i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    if (A[0] == 0) {
        cout << (newSolve(A, N) ? "Yes" : "No") << endl;
    } else if (N % 3 != 0)
        cout << "No" << endl;
    else {
        cout << (solve(A, N) ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;
int x[100001];
int w[100001];
int ans[100001];

int main(int argc, char const* argv[])
{
	int n, l, t;
	cin >> n >> l >> t;
	for(int i = 0; i < n; i++)cin >> x[i] >> w[i];
	for(int i = 0; i < n; i++){
			ll tmp;
			if(w[i] == 1)tmp = x[i] + (ll)t;
			else tmp = x[i] - (ll)t;
			ans[i] = tmp % l;
			if(ans[i] < 0)ans[i] += l;
	}
	int index = 0;
	for(int i = 1; i < n; i++){
			int tmp;
			if(w[i] != w[0] && w[0] == 1){
					if(2 * t >= x[i] - x[0]){
							tmp = 1 + int((2 * t - x[i] + x[0])/l);
							index += tmp;
							index %= n;
					}
			}else if(w[i] != w[0] && w[0] == 2){
					if(2 * t >= l - x[i] + x[0]){
							tmp = 1 + int((2 * t - l + x[i] - x[0])/l);
							index -= tmp;
							index %= n;
							if(index < 0)index += n;
					}
			}
	}
	int cood;
	cood = ans[0];
	sort(ans, ans + n);
	int at = lower_bound(ans, ans+n, cood) - ans;
	if(w[0] == 1){
			if(at < n - 1 && ans[at] == ans[at+1])at++;
	}
	for(int i = 0; i < n; i++){
			if(at - index + i < 0)cout << ans[n + at - index + i] << endl;
			else if(at - index + i >= n)cout << ans[at - index + i - n] << endl;
			else cout << ans[at - index + i] << endl;
	}
	return 0;
}


Measured memory_bytes: 2432
unittest
{
	assert( [ "3", "7 12 8" ].parse.expand.solve == 4 );
	assert( [ "2", "11 11" ].parse.expand.solve == 2 );
	assert( [ "1", "0" ].parse.expand.solve == 0 );
	
	assert( [ "2", "1 11" ].parse.expand.solve == 1 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto ds = input.front.split.to!( long[] );
	return tuple( ds );
}

auto solve( long[] ds )
{
	// 現地時間を復元
	ds.sort();
	for( auto i = 0L; i < ds.length; i += 2 )
	{
		if( 0 < ds[ i ] ) ds[ i ] = 24 - ds[ i ];
	}
	
	// 高橋君の都市を含めて並び替え
	ds ~= 0;
	ds ~= 24;
	ds.sort();
	
	// 時差の最小値を計算
	auto ans = long.max;
	for( auto i = 1L; i < ds.length; i++ )
	{
		auto d = ds[ i ] - ds[ i - 1 ];
		ans = min( ans, min( d, 24 - d ) );
	}
	return ans;
}


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

int  A, B, H, M;

double PI = 3.1415926535897932384;

int main(void)
{
	cin >> A >> B >> H >> M;
	H = H % 12;

	double ra, rb;

	ra = PI / 2 - (2*PI * (60 * H + M) / (60 * 12));
	rb = PI / 2 - (2*PI * M / 60);

	double a_x, a_y, b_x, b_y;

	a_x = A * cos(ra);
	a_y = A * sin(ra);
	b_x = B * cos(rb);
	b_y = B * sin(rb);

	double ans = sqrt((a_x - b_x) * (a_x - b_x) + (a_y - b_y) * (a_y - b_y));
	cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 4160
N = int(input())
result = []
for i in range(0,(N)):
    A = input()
    if A:
        result.append(A)
AC = result.count("AC")
WA = result.count("WA")
TLE = result.count("TLE")
RE = result.count("RE")
print(f"AC x {AC}\nWA x {WA}\nTLE x {TLE}\nRE x {RE}\n")

Measured memory_bytes: 16284
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int D, G; std::cin >> D >> G; G/=100;
  std::vector<int> p(D), c(D);
  for(int i = 0; i < D; ++i) {
    std::cin >> p[i] >> c[i];
    c[i] /= 100;
  }
  int ans = 1001;
  for(int s = 0; s < (1<<D); ++s) {
    int cur = 0, g = 0;
    for(int i = 0; i < D; ++i) if((1<<i)&s) {
      cur += p[i];
      g += c[i] + p[i]*(i+1);
    }
    if(g < G) for(int i = D-1; i >= 0; --i) if(((1<<i)&s)==0) {
      int ma = (p[i]-1)*(i+1);
      if(g+ma >= G) {
        cur += (G-g+i)/(i+1);
        g = G;
        break;
      }
      cur += p[i]-1;
      g += ma;
    }
    if(g >= G) ans = std::min(ans, cur);
  }
  fin(ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
	int a;
	cin >> a;
	cout << pow(a, 3) + pow(a, 2) + a << endl;
	return 0;
}


Measured memory_bytes: 4224
#include <cstdio>

typedef long long ll;
ll n,l;
int len;
int k[100],pl[100];

ll abs(ll a){
	if(a<0)return -a;
	return a;
}

int main(void){
	while(1){
		scanf("%lld",&n);
		if(n==0)break;

		int i=0;
		while(n!=0){
			if(i%2==0){
				if(n>0)k[i]=abs(n)%10;
				else{
					k[i]=10-abs(n)%10;
					if(abs(n)%10==0)k[i]=0;
				}
				n-=k[i];
			}else{
				if(n<0)k[i]=abs(n)%10;
				else{
					k[i]=10-abs(n%10);
					if(abs(n)%10==0)k[i]=0;
				}
				n+=k[i];
			}
			i++;
			n/=10;
			//printf("%lld\n",n);
		}
		for(int j=i-1;j>=0;j--){
			printf("%d",k[j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1032
N,M,X,Y = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x.sort(key=lambda x: -x)
y.sort()
left = x[0]
right = y[0]

if left < right:
    flag = False
    while left != right:
        left = left + 1
        if X < left and left < Y and left <= right:
            flag = True
            break
    print('No War') if flag else print('War')
else:
    print('War')

Measured memory_bytes: 3064
/* SmartCoder Apr 7, 2019 */
#include <bits/stdc++.h>
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end();i++)
#define present(c,x)  ( (c).find(x) !=(c).end())
#define cpresent(c,x) (find(all(c),x)!= (c).end() )
#define minei(x)  min_element(x.begin(),x.end())-(x).begin()
#define maxei(x)  max_element(x.begin(),x.end())-(x).begin()

#define uns(v)     sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define acusum(x)  accumulate(x.begin(),x.end(),0)
#define acumul(x)  accumulate(x.begin(),x.end(),1, multiplies<int>());
#define bits(x)     __builtin_popcount( x )
#define oo INT_MAX
#define inf 1000000000

const double pi = acos(-1.0);
const double eps = 1e-11;
#define MAXN 100007
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
void fastIO() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
ll W[MAXN], V[MAXN];
ll dp[2][MAXN];
void copyOver(int r) {
	for (int i = 0; i < MAXN; i++) {
		dp[r % 2][i] = dp[1 - (r % 2)][i];
	}
}
void printDP(int r, int w) {
	for (int i = 0; i <= w; i++) {
		cout << dp[r % 2][i] << " ";
	}
	cout << endl;
}
int main() {
	fastIO();
	int n, w;
	cin >> n >> w;
	for (int i = 0; i < n; i++) {
		cin >> W[i] >> V[i];
	}
	for (int i = 0; i <= w; i++) {
		dp[0][i] = dp[1][i] = -1;
	}
	dp[1][0] = 0;
	for (int i = 0; i < n; i++) {
		copyOver(i);

		for (int j = w; j >= 0; j--) {
			if (dp[i % 2][j] == -1 || W[i] + j > w)
				continue;
			if (dp[i % 2][j + W[i]] == -1)
				dp[i % 2][j + W[i]] = V[i] + dp[i % 2][j];
			else
				dp[i % 2][j + W[i]] = max(dp[i % 2][j + W[i]], V[i] + dp[i % 2][j]);
		}
	}
	ll res = -1;

	for (int i = 0; i <= w; i++) {
		res = max(res, dp[1 - (n % 2)][i]);
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1792
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize("SEX_ON_THE_BEACH")	
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/STACK:36777216")

#define _CRT_SECURE_NO_WARNINGS

#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
#include <iomanip>
#include <numeric>
#include <time.h>//////////////
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define queuel queue<long long>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(), v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for (auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for (int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for (int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for (int i = 0; i < n; ++i){int a; cin >> a; s.insert(a); }
#define fastio() ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); srand(time(NULL))
#define sp system("pause")
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;//СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚
					//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define int ll
const int MAXN = 2e5 + 1;
const ll inf = 1e9;
const ld EPS = 1e-4;
const ld PI = acos(-1);
int mod = (int)998244353;
//const int MOD = 1000000007;
const int MOD9 = 1000000009;
const int a228 = 18;
const ll MOD = 1000000007;
const int maxelem = 12000000;
const int fsconst = 12000;
signed main()
{
	fastio();
	int k, x;
	cin >> k >> x;
	for (int i = x - k + 1; i < x + k; ++i)
	{
		cout << i << ' ';
	}
	//ssp;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define ll long long int
#define pb push_back
void solve(){
    int n;
    cin>>n;
    int cnt[4]={0};
    string ans[4]={"AC","WA","TLE","RE"};
    for(int i=0;i<n;i++){
        string h;
        cin>>h;
        if(h=="AC"){
            cnt[0]++;
        }
        else if(h=="WA"){
            cnt[1]++;
        }
        else if(h=="TLE"){
            cnt[2]++;
        }
        else if(h=="RE"){
            cnt[3]++;
        }
    }
    for(int i=0;i<4;i++){
        cout<<ans[i]<<" x "<<cnt[i]<<"\n";
        
    }
}
int main() {
	int t=1;
	//cin>>t;
	while(t--){
	    solve();
	}
	return 0;
}


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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
#define endl '\n'
#define space ' '
#define elif else if
#define def inline auto
#define func inline constexpr ll
#define run __attribute__((constructor)) def _
#define all(v) begin(v), end(v)

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define rep(i, n) inc(i, 0, n - 1)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

// Math
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }

#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;

ll N, M, S = 2;
vector<ll> A;
cpp_int comb[31];
def nHr() {
    comb[0] = 1;
    inc(i, 1, 30) comb[i] = comb[i - 1] * (N + i - 1) / i;
    inc(i, 1, 30) comb[i] %= MOD;
}

signed main() {
    ll M;
    cin >> N >> M;
    nHr();
    while (M != 1) {
        A.push_back(0);
        while (M % S == 0) {
            M /= S;
            *(A.end() - 1) += 1;
        }
        S++;
    }
    cpp_int ANS = 1;
    rep(i, A.size()) {
        ANS *= comb[A[i]];
        ANS %= MOD;
    }
    cout << ANS << endl;
}

// for compilation: g++ -O3 -o _ _.cpp -std=c++17


Measured memory_bytes: 524756
n,k = map(int,input().split())
s = input()
cnt = 1
arr0 = []
if s[0]=="1":
  arr = [0]
else:
  arr = [0,0]
for i in range(n-1):
  if s[i] == s[i+1]:
    cnt += 1
  else:
    arr0.append(cnt)
    cnt = 1
arr0.append(cnt)
arr += arr0
if s[n-1] == "0":
  arr.append(0)
lsum = [0]*(len(arr)//2)
lsum[0] = arr[0]+arr[1]
for i in range(1,len(arr)//2):
  lsum[i] = lsum[i-1]+arr[2*i]+arr[2*i+1]
arr = [0,0]+[0]*(s[0]=="0")+arr0+[0]*(s[n-1]=="1")
rsum = [0]*(len(arr)//2)
for i in range(1,len(arr)//2):
  rsum[i] = rsum[i-1]+arr[2*i]+arr[2*i+1]
ans = 0
if k >= len(lsum)-1:
  print(n)
  quit()
for i in range(k,len(lsum)):
  ans = max(ans,lsum[i]-rsum[i-k])
print(ans)

Measured memory_bytes: 8820
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=200005;
int x,d,n;
typedef pair<ll,ll> P;
inline ll sum(int a,int b){
    return 1ll*(a+a+b-1)*b/2;
}
int main(){
    scanf("%d%d%d",&n,&x,&d);
    if(d<0)d=-d,x=-x;
    if(d==0){
        if(x==0)printf("1\n");
        else printf("%d\n",n+1);
    }
    else{
        int g=__gcd(d,x);
        g=abs(g);
        d/=g,x/=g;
        set<P> s;
        ll ans=0;
        for(int i=0;i<d;i++){
            s.clear();
            for(int j=i;j<=n;j+=d){
                s.insert({1ll*j/d*x+sum(0,j),1ll*j/d*x+sum(n-j,j)+1});
            }
            ll r=-1e18;
            for(auto p:s){
                ans+=max(0ll,p.second-max(p.first,r));
                r=max(r,p.second);
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 12800