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

signed main()
{
  int N; cin>>N;
  vector<int> a(N+1);
  for(int i=1;i<=N;i++){
    cin>>a[i];
  }

  vector<int> cnt(N+1);
  for(int i=N;i>=1;i--){
    int c=0;
    for(int j=i*2;j<=N;j+=i){
      c+=cnt[j];
    }
    if(c%2!=a[i]){
      cnt[i]=1;
    }
  }

  vector<int> ans;
  for(int i=1;i<=N;i++){
    if(cnt[i]==1) ans.push_back(i);
  }

  cout<<ans.size()<<endl;
  for(int i=0;i<ans.size();i++){
    cout<<ans[i]<<' ';
  }
  cout<<endl;

  return 0;
}


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

int main(void){
  int n,m; cin>>n>>m;
  int l=1,r=n;
  for(int i=0; i<m; ++i){
    int l_tmp,r_tmp;
    cin >> l_tmp >> r_tmp;
    if ( l < l_tmp) l = l_tmp;
    if ( r > r_tmp) r = r_tmp;
  }
  if( (r - l) >= 0) cout << r-l+1 << endl;
  else cout << 0 << endl;
  return 0;
}


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

int main(){
    long long n, m;cin>>n>>m;
    vector<long long> observatories(n+1);for (int i=1;i<=n;i++){cin>>observatories[i];};
    map<long long, vector<long long>> heights;
    long long left, right;
    for (int i=0;i<m;i++){
        cin >> left >> right;
        if (heights.find(left) == heights.end()){
            heights[left] = {observatories[right]};
        } else {
            heights[left].push_back(observatories[right]);
        }
        if (heights.find(right) == heights.end()){
            heights[right] = {observatories[left]};
        } else {
            heights[right].push_back(observatories[left]);
        }
    }
    long long acc = 0;
    for (long long i=1;i<=n;i++){
        if (heights.find(i) == heights.end()){
            acc++;
        } else {
            if (observatories[i] > *max_element(heights[i].begin(), heights[i].end())){
                acc++;
            }
        }
    }
    cout << acc << endl;
    return 0;
}

Measured memory_bytes: 14316
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

int main(void){
	const int MOD = 1e9+7;
	ll ans=1;
	int N,h[100010]={},A[100010],T[100010];
	bool can=true;
	scanf("%d",&N);
	T[0]=-1;
	A[N+1]=-1;
	reg(i,1,N)scanf("%d",&T[i]);
	reg(i,1,N)scanf("%d",&A[i]);
	
	reg(i,1,N)if(T[i]>T[i-1]){//更新時は確定
		h[i]=T[i];
		if(A[i]<h[i])can=false;
	}
	ireg(i,1,N)if(A[i]>A[i+1]){//更新時は確定
		h[i]=A[i];
		if(T[i]<h[i])can=false;
	}
	reg(i,1,N){
		if(h[i]==0){
			ans*=min(A[i],T[i]);
			ans%=MOD;
		}
	}
	if(can){
		printf("%lld\n",ans);
	}else{
		printf("0\n");
	}
	return 0;
}

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

int main()
{
    int n;
    string s;
    while (cin >> n) {
        cin >> s;
        int cnt = 0;

        for (int i = 0; i + 2 < n; i++) {
            if ("ABC" == s.substr(i, 3)) {
                cnt++;
            }
        }
        cout << cnt << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 50005

int N,M;
ll table[2*NUM];


bool is_ok(ll value,int start_index){

	ll num_section,base,next_base;
	int L,R,mid;

	for(int start = start_index; start <= start_index; start++){

		num_section = 0;
		base = start;

		while(base < N+start){

			//2分探索で、総和がvalue以下となる最大のインデックスを求める
			L = 0,R = start+N-1-base,mid = (L+R)/2;

			while(L <= R){

				if(table[base+mid]-table[base-1] <= value){

					next_base = base+mid+1;
					L = mid+1; //より区間を長く

				}else{

					R = mid-1;
				}
				mid = (L+R)/2;
			}

			num_section++;

			base = next_base;

			//残りを最大化しても、総和が足りなければ不可
			if(value*(M-num_section) < table[start+N-1]-table[base-1]){
				return false;
			}
		}

		if(num_section <= M){
			return true;
		}
	}

	return false; //区間分割数がM以下か
}



int main(){

	scanf("%d %d",&N,&M);

	ll maximum = 0;

	table[0] = 0;
	for(int i = 1; i <= N; i++){

		scanf("%lld",&table[i]);
		table[i+N] = table[i];
		maximum = max(maximum,table[i]);
	}

	for(int i = 1; i <= 2*N; i++){

		table[i] += table[i-1];
	}

	ll L = maximum, R = table[N], mid = (L+R)/2;
	ll ans = BIG_NUM;

	while(L <= R){

		if(is_ok(mid,1)){

			ans = mid;
			R = mid-1;
		}else{

			L = mid+1;
		}

		mid = (L+R)/2;

	}

	L = maximum,R = ans,mid = (L+R)/2;
	int left,right,m,start_index,end_index;

	vector<int> V;

	while(L <= R){

		//2から数えて、合計がmidを超えない最大の右端を求める
		left = 2,right = N+1,m = (left+right)/2;
		end_index = 2;

		while(left <= right){

			if(table[m]-table[1] <= mid){

				end_index = m;
				left = m+1; //より右へ

			}else{

				right = m-1;
			}
			m = (left+right)/2;
		}

		V.clear();
		for(int i = 2; i <= end_index; i++){
			V.push_back(i);
		}

		//左端を求める
		ll tmp_sum = table[end_index]-table[1];

		if(end_index == N+1){

			//Do nothing
		}else{

			left = end_index+1,right = N+1,m = (left+right)/2;
			start_index = N+1;

			while(left <= right){

				if(table[N+1]-table[m-1]+tmp_sum <= mid){

					start_index = m;
					right = m-1; //より左へ

				}else{

					left = m+1;
				}
				m = (left+right)/2;
			}

			for(int i = start_index; i <= N+1; i++){

				V.push_back(i);
			}
		}

		bool FLG = false;

		for(int i = 0; i < V.size(); i++){

			if(is_ok(mid,V[i])){
				FLG = true;
				break;
			}
		}

		if(FLG){ //少なくとも一件成功すれば良し

			ans = mid;
			R = mid-1;

		}else{

			L = mid+1;
		}

		mid = (L+R)/2;
	}

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 4140
#include <iostream>

using namespace std;

int main(){
  int a=0,b=0;
  cin>>a>>b;
  int items[a+1][2]={0};
  int sum=0;
  for(int i=1;i<=a;i++){
    cin>>items[i][0]>>items[i][1];
    sum+=items[i][1];
  }
  
  long long int arr[sum+1]={0};
  for(int j=sum;j>0;j--){
    arr[j]=1e12;
  }
  
  for(int i=1;i<=a;i++)
    for(int j=sum;j>=items[i][1];j--)
      arr[j]=min(arr[j-items[i][1]]+items[i][0],arr[j]);
      
  while(arr[sum]>b) sum--;
  cout<<sum<<endl;
  cin>>sum;
  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,lengthof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	int n;
	cin >> n;
	while (n--){
		string s1, s2;
		cin >> s1 >> s2;
		string ans = "";
		int s1l = s1.length();
		int s2l = s2.length();
		bool up = false;
		REP(i, max(s1l, s2l)){
			int a = up ? 1 : 0;
			if (s1l - i - 1 >= 0)
				a += s1.c_str()[s1l - i - 1] - '0';
			if (s2l - i - 1 >= 0)
				a += s2.c_str()[s2l - i - 1] - '0';
			up = (a >= 10);
			ans = to_string(a % 10) + ans;
			if (max(s1l, s2l) - i-1 == 0 && up)ans = "1" + ans;
		}
		if (ans.length()<=80)
		cout<<ans<<endl;
		else
			cout << "overflow"<<endl;
	}
}

Measured memory_bytes: 3144
#include <iostream>
using namespace std;
int main()
{
  int H, W;
  cin >> H >> W;
  string a[H];
  for (int i = 0; i < H; i++)
    cin >> a[i];
  for (int i = 0; i < W + 2; i++)
    cout << '#';
  cout << '\n';
  for (int i = 0; i < H; i++)
    cout << '#' << a[i] << '#' << endl;
  for (int i = 0; i < W + 2; i++)
    cout << '#';
  cout << '\n';
  return 0;
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n;
    cin >> n;
    vector<ll> a(3), b(3);
    REP(i, 3) cin >> a[i];
    REP(i, 3) cin >> b[i];

    // a→bの変換
    vector<vector<ll>> dp(4, vector<ll>(n+1));
    REP(i, 3) REP(j, n+1) {
        chmax(dp[i+1][j], dp[i][j]);
        if(j+a[i] <= n) chmax(dp[i+1][j+a[i]], dp[i+1][j]+b[i]);
    }
    ll ma = n;
    REP(i, n+1) chmax(ma, dp[3][i] + n-i);

    // REP(i, 4) cout << dp[i] << endl;

    // b→aの変換
    n = ma;
    dp.assign(4, vector<ll>(n+1, 0));
    REP(i, 3) REP(j, n+1) {
        chmax(dp[i+1][j], dp[i][j]);
        if(j+b[i] <= n) chmax(dp[i+1][j+b[i]], dp[i+1][j]+a[i]);
    }
    REP(i, n+1) chmax(ma, dp[3][i] + n-i);

    cout << ma << endl;

    return 0;
}


Measured memory_bytes: 977024
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N, Q;
  while (cin >> N >> Q) {
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    vector<ll> S(N + 1, 0);
    for (int i = 0; i < N; i++) S[i + 1] = S[i] + A[i];
    vector<ll> S2(N + 1, 0);
    for (int i = 0; i < N; i++) {
      S2[i + 1] = A[i] + (i > 0 ? S2[i - 1] : 0);
    }
    for (int q = 0; q < Q; q++) {
      ll x;
      cin >> x;
      ll ok = 0, ng = 1ll << 35;
      while (ng - ok > 1) {
        ll d = (ok + ng) / 2;
        int a = distance(A.begin(), lower_bound(A.begin(), A.end(), x - d));
        int b = distance(A.begin(), upper_bound(A.begin(), A.end(), x + d));
        int cnt = b - a;
        int c = N - cnt;
        if (b <= c) {
          ok = d;
        } else {
          ng = d;
        }
      }
      ll d = ok;
      int a = distance(A.begin(), lower_bound(A.begin(), A.end(), x - d));
      int b = distance(A.begin(), upper_bound(A.begin(), A.end(), x + d));
      int cnt = b - a;
      int c = N - cnt;
      if (b > c) {
        cout << S2[N] << endl;
        continue;
      }
      ll res = S[N] - S[c];
      for (;;) {
        if (b < c) {
          --c;
          res += A[c];
        } else {
          res += S2[a];
          break;
        }
        if (a == 0 && b == c) break;
        if (a == 0) {
          ++b;
          continue;
        }
        if (b == c) {
          --a;
          continue;
        }
        if (x - A[a - 1] <= A[b] - x) {
          --a;
        } else {
          ++b;
        }
      }
      cout << res << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 4096
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
ans = sum(a)
b = [0 for i in range(41)]
for j in range(41):
    for i in range(len(a)):
        if a[i]%2==1 : b[j]+=1
        a[i]//=2
c = 40
if k==0 : c = -1
while c>=0:
    if 2**(c)>k :
        c-=1
        continue;
    if b[c] < n-b[c]:
        k-=2**c
        ans -=b[c]*2**c
        ans += (n-b[c])*2**c
    c-=1
print(ans)


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

#define IO                       \
    std::ios_base::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define LL long long
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;

const int INF = 0x3f3f3f3f;

int main(void) {
    IO;
    int N;
    cin >> N;

    int a[10][10] = {0};

    for (int i = 1; i <= N; ++i) {
        string s = to_string(i);
        ++a[s.front()-'0'][s.back()-'0'];
    }

    int ans = 0;
    for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= 9; ++j) {
            ans += a[i][j] * a[j][i];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
using System.Collections.Generic;
using System;

public class UnionFind
{
    private int[] data;
    public UnionFind(int size)
    {
        data = new int[size];
        for (int i = 0; i < size; i++) data[i] = -1;
    }
    public bool Unite(int x, int y)
    {
        x = Root(x);
        y = Root(y);
        if (x != y)
        {
            if (data[y] < data[x])
            {
                var tmp = y;
                y = x;
                x = tmp;
            }
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    public bool IsSameGroup(int x, int y) => Root(x) == Root(y);
    public int Root(int x) => data[x] < 0 ? x : data[x] = Root(data[x]);
    public int getMem(int x) => -data[Root(x)];
}


public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var k = int.Parse(line[2]);
        var dr = new int[n];
        var u = new UnionFind(n);
        var bL = new List<int>[n];
        for (int i = 0; i < n; i++) bL[i] = new List<int>();
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[0]) - 1;
            var b = int.Parse(line[1]) - 1;
            u.Unite(a, b);
            dr[a]++;
            dr[b]++;
        }
        for (int i = 0; i < k; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var c = int.Parse(line[0]) - 1;
            var d = int.Parse(line[1]) - 1;
            bL[c].Add(d);
            bL[d].Add(c);
        }
        getAns(n, u, dr, bL);
    }
    static void getAns(int n, UnionFind u, int[] dr, List<int>[] bL)
    {
        var ans = new int[n];
        for (int i = 0; i < n; i++)
        {
            var w = u.getMem(i) - dr[i] - 1;
            foreach (var x in bL[i])
                if (u.Root(i) == u.Root(x)) w--;
            ans[i] = w;
        }
        Console.WriteLine(string.Join(" ", ans));
    }
}


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

using namespace std;
typedef  long long int ll;
#define rep(i, n) for (int i = 0; i < (n); i++)



int main () {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << max(a+b, max(a-b, a*b)) << endl;

    return 0;
 }


Measured memory_bytes: 892
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	double l; cin >> l;
	printf("%.20f\n", pow(l / 3, 3));
	
	return 0;
}

Measured memory_bytes: 512
using System;


namespace ConsoleApplication13
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true) {
                String[] s = Console.ReadLine().Split(' ');
                int H = int.Parse(s[0]);
                int W = int.Parse(s[1]);

                if (H == 0 && W == 0) break;
            
                int i = 0;
                while (true)
                {
                    if (i == H) break;
                    if (i == 0 || i == H - 1)
                    {
                        for (int x = 0; x < W; x++)
                        {
                            Console.Write("#");

                        }
                    }
                    else
                    {
                        Console.Write("#");
                        for (int x = 1; x < W-1; x++)
                        {
                            Console.Write(".");

                        }
                        Console.Write("#");
                    }
                    
                    Console.WriteLine();

                    i++;
                }
                Console.WriteLine();


            }

        }
    }
}

Measured memory_bytes: 8840
import collections
import itertools
n = int(input())
l = list(map(int, input().split()))
c = collections.Counter(l)
ans = 0
p_list = list(itertools.combinations(c, 3))
for e in p_list:
  if e[0] + e[1] > e[2] and e[1] + e[2] > e[0] and e[2] + e[0] > e[1]:
    ans += c[e[0]] * c[e[1]] * c[e[2]]
print(ans)

Measured memory_bytes: 20816
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int Maxx = 300;
int a, b, c;
int p[Maxx];
int t[Maxx];

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int  main(){
 int a;
 cin >> a;
 string s;
 cin >> s;
 if(s.size()%2!=0){
    cout << "No" << endl;
    return 0;
 }
 string yon = s.substr(0,s.size()/2);
 string kun = s.substr(s.size()/2,s.size());
 for(int i= 0;i<a/2;i++){
    if(yon[i]!=kun[i]){
       cout << "No" << endl;
       return 0;
    }
 }
 cout << "Yes" << endl;
return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

struct C1 {
    vector<ll> v_{};
    explicit C1(vector<ll> v) : v_(move(v)){}

    double resolve() {
        double t = 0;
        for(ll d : v_) {
            double x = d;
            t += 1.0/x;
        }
        return (double)1.0/t;
    }
};

int main() {
    ll N;
    cin >> N ;
    vector<ll> v{};
    for (int i=0; i < N; ++i) {
        ll x;
        cin >> x;
        v.emplace_back(x);
    }
    C1 c{move(v)};
    cout.precision(12);
    cout << c.resolve() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    string s, t;
    cin >> n >> s >> t;

    for (int i = 0; i < n; i++) {
        cout << s[i] << t[i];
    }

    cout << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5, inf = 1e9;
int n, m;
int d[maxn], a[maxn], b[maxn], c[maxn];
map<pair<int, int>, int> mp;
vector<int> G[maxn];
int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) {
		scanf("%d", &d[i]);
	}
	for(int i = 1; i <= m; ++i) {
		scanf("%d%d", &a[i], &b[i]);
		G[a[i]].push_back(b[i]);
		G[b[i]].push_back(a[i]);
	}
	vector<pair<int, int> > v;
	for(int i = 1; i <= n; ++i) {
		v.emplace_back(d[i], i);
	}
	sort(v.begin(), v.end());
	for(int i = 0; i < v.size(); ++i) {
		int u = v[i].second;
		int p = 0;
		if(c[u]) {
			continue;
		}
		for(auto v : G[u]) {
			if(d[v] <= d[u]) {
				p = v;
				break;
			}
		}
		if(!p) {
			puts("-1");
			return 0;
		}
		if(!c[p]) {
			c[p] = 1;
		}	
		c[u] = -c[p];
		mp[minmax(u, p)] = d[u];
	}
	for(int i = 1; i <= n; ++i) {
		putchar(c[i] == 1 ? 'B' : 'W');
	}
	puts("");
	for(int i = 1; i <= m; ++i) {
		printf("%d\n", mp.count(minmax(a[i], b[i])) ? mp[minmax(a[i], b[i])] : inf);
	}
	return 0;
}

Measured memory_bytes: 20468
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MAX = 1e5 + 5, MOD = 1e9 + 7;
constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }, dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

// 1 2 3 4 5 6 7 8 9
// 2 5 5 4 5 6 3 7 6
const int require[] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

int N, M;
vi A;
vi dp;

int main() {
    cin >> N >> M;
    A.resize(M);
    rep(i, M) cin >> A[i];
    sort(all(A));
    reverse(all(A));

    dp.resize(N + 1, -INF);
    dp[0] = 0;
    rep(i, 1, N + 1) {
        rep(j, M) {
            if (i - require[A[j]] >= 0) {
                chmax(dp[i], dp[i - require[A[j]]] + 1);
            }
        }
    }

    int Nrest = N;
    rep(i, dp[N]) {
        rep(j, M) {
            if (Nrest >= require[A[j]] && dp[Nrest - require[A[j]]] == dp[Nrest] - 1) {
                cout << A[j];
                Nrest -= require[A[j]];
                break;
            }
        }
    }
    puts("");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N;
 cin >> N;
 vector<int> a(N);
  
  for(int i = 0; i < N; i++) cin >> a.at(i);
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  int A = 0;
  int B = 0;
  
  for(int i = 0; i < N; i+= 2) A += a.at(i);
  for(int i = 1; i < N; i+= 2) B += a.at(i);
	
  cout << A - B << endl;
 }

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int ans = 0;
        List<List<Integer>> sl = new ArrayList<List<Integer>>();
        for(int i = 0; i < n; i++){
            sl.add(new ArrayList<Integer>());
        }
        int[] p = new int[m];
        for(int i = 0; i < m; i++){
            int k = sc.nextInt();
            for(int j = 0; j < k; j++){
                sl.get(sc.nextInt()-1).add(i);
            }
        }
        for(int i = 0; i < m; i++){
            p[i] = sc.nextInt();
        }
        int loops = (int)Math.pow(2,n);
        for(int i = 0; i < loops; i++){
            int[] tp = new int[m]; 
            for(int j = 0; j < n; j++){
                if(((i >> j) % 2) == 1){
                    List<Integer> tmp = sl.get(j);
                    for(int v:tmp){
                        tp[v]++;
                    }
                }
            }
            boolean bool = true;
            for(int j = 0; j < m; j++){
                if(tp[j]%2 != p[j]){
                    bool = false;
                    break;
                }
            }
            if(bool){
                ans++;
            }
        }
        System.out.println(ans);
    }
}

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

using namespace std;

int main()
{
    string s;
    int buc[30] = {};
    cin >> s;
    for (int i = 0; i < s.size(); i++)
        buc[s[i] - '0']++;
    int cnt = 0;
    for (int i = 0; i < 30; i++)
        if (buc[i])
            cnt++;
    if (cnt == 2)
        cout << "Second" << endl;
    else
    {
        if (s[0] == s[s.size() - 1])
            cout << (s.size() % 2 ? "Second" : "First") << endl;
        else
            cout << (s.size() % 2 ? "First" : "Second") << endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define EM 100000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;

int main(){
	int N;
	cin >> N;
	vector<double> p(N+1);
	for(int i = 1;i <= N;i++)	cin >> p[i];
	vector<vector<double>> dp(N+1, vector<double>(N+1, (double)0));
	dp[0][0] = 1;
	for(int i = 1;i <= N;i++){
		for(int j = 0;j <= i-1;j++)	dp[i-j-1][j+1] += p[i]*dp[i-j-1][j];
		for(int j = 0;j <= i-1;j++)	dp[j+1][i-j-1] += ((double)1-p[i])*dp[j][i-j-1];
	}
	double ans = 0;
	for(int i = 0;i <= N;i++)	if(i < N-i)	ans += dp[i][N-i];
	cout << setprecision(20) << ans << endl;
}

Measured memory_bytes: 70784
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let (n, m) = {
    let v: Vec<usize> = read_vec();
    (v[0], v[1])
  };

  println!("{}", (n - 1) * (m - 1));
}


Measured memory_bytes: 4352
#include<stdio.h>
int main() {
	long long  a, b;
	scanf("%lld%lld", &a, &b);
	if (a == 1&&b==1) {
		printf("1");
	}
	else if (a == 1 || b == 1) {
		printf("%lld", a*b - 2);
	}
	else {
		printf("%lld", (a - 2)*(b - 2));
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;
ll col[100005];
vector<ll> g[100005];
ll n,m;
ll p[100005];
void dfs(ll s, ll pr)
{
        assert(col[s]==0 && p[s]==0);
        p[s] = pr;
        col[s]=1;
        for(auto i : g[s]) {
                if(i==pr) assert(0);
                if(col[i] == 0) {
                        dfs(i,s);
                }else if(col[i] == 1) assert(0);
                else {
                        if(col[p[i]] == 1) p[i]=s;
                }
        }
        col[s]=2;
}
ll ins[100005];
int main()
{
        cin >> n >> m;
        m += n-1;
        for(ll i=1;i<=m;i++) {
                ll a , b;
                cin >> a >> b;
                ins[b]++;
                g[a].pb(b);
                //g[b].pb(a);
        }
        for(ll i=1;i<=n;i++) {
                if(ins[i]==0) {
                        dfs(i,0); break;
                }
        }
        for(ll i=1;i<=n;i++) cout << p[i] << "\n";
        return 0;
}


Measured memory_bytes: 13312
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pll pair<long long, long long>
#define f first
#define s second
#define debug cout<<"here\n" 
#define MOD 1000000007

const int MAXN = 2e5 +15;
using namespace std;

ll modexp(ll a, ll p, ll mod){
	if(p == 0) return 1;
	ll ans = modexp(a,p/2,mod);
	ans = (ans*ans)%mod;
	if(p%2) return (a*ans)%mod;
	else return ans;
}

void solve(){	
	int n; cin>>n;
	cout<<(2*MOD+modexp(10,n,MOD) - 2*modexp(9,n,MOD) + modexp(8,n,MOD))%MOD;
}
 
int main(){
	ios_base::sync_with_stdio(false);
	cout.tie(0); cin.tie(0);	
	cout<<fixed<<setprecision(12);

	int t =1; //cin>>t;
	for(int i=1; i<= t; i++){
		solve();
		cout<<"\n";
	}
	
	return 0;
}

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

using namespace std;

int main(){
  
  int n, k, d, a;
  
  cin >> n >> k;
  vector<int> visited(n, false);
  while(cin >> d){
  	
    for(int i = 0; i < d; i++){
    	cin >> a;
      if(!visited[a - 1]){
        visited[a - 1] = true;
        n--;
      }
    }
  }
    cout << n << endl;
  
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int n, k, q;
	cin >> n >> k >> q;
	int co[100010] = { 0 };
	for (int i = 0; i < q; i++) {
		int a;
		cin >> a;
		co[a - 1]++;
	}
	for (int i = 0; i < n; i++) {
		if (k - q + co[i] > 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

/**
 *
 * @author k16075kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */       
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[n];
        for(int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
        }
        System.out.print(x[n-1]);
        for(int i = n-2; i >= 0; i--) {
            System.out.print(" " + x[i]);
        }
        System.out.println();
    }
}
    


Measured memory_bytes: 26140
n,x,y = map(int,input().split())
dic = {}
for i in range(1,n):
    dic[i] = 0
for i in range(n):
    for j in range(i+1,n):
        kyori = min(j-i,abs(x-1-i) + 1 + abs(y-1-j), abs(y-1-i) + 1 + abs(x-1-j))
        dic[kyori] +=1
for i in dic.values():
    print(i)

Measured memory_bytes: 48220
N = int(input())
LUT = [[0] * 10 for _ in range(10)]
for n in range(1, N + 1):
    LUT[int(str(n)[0])][int(str(n)[-1])] += 1
ans = sum([sum([LUT[i][j] * LUT[j][i] for i in range(10)]) for j in range(10)])
print(ans)


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	
	public static int[][] eat_type = new int[][]{{0, 1, 2}, {0}, {1}, {2}};
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int K = sc.nextInt();
		
		int[] pasta = new int[N];
		
		for(int i = 0; i < K; i++){
			pasta[sc.nextInt() - 1] = sc.nextInt();
		}
		
		int[] cur = new int[27];
		int[] next = new int[27];
		
		for(int t_eat : eat_type[pasta[2]]){
			for(int p_eat : eat_type[pasta[1]]){
				for(int pp_eat : eat_type[pasta[0]]){
					final int number = pp_eat * 9 + p_eat * 3 + t_eat;
					
					cur[number]++;
				}
			}
		}
		
		for(int day = 3; day < N; day++){
			Arrays.fill(next, 0);
			
			for(int eat : eat_type[pasta[day]]){
				for(int number = 0; number < 27; number++){
					final int t_eat = number % 3;
					final int p_eat = number / 3 % 3;
					final int pp_eat = number / 9 % 3;
					
					if(t_eat == p_eat && p_eat == pp_eat){
						continue;
					}else if(eat == t_eat && eat == p_eat){
						continue;
					}
					
					next[p_eat * 9 + t_eat * 3 + eat] += cur[number];
					next[p_eat * 9 + t_eat * 3 + eat] %= 10000;
				}
			}
			
			{
				int[] tmp = cur;
				cur = next;
				next = tmp;
			}
		}
		
		int sum = 0;
		for(int number = 0; number < 27; number++){
			final int t_eat = number % 3;
			final int p_eat = number / 3 % 3;
			final int pp_eat = number / 9 % 3;
			
			if(t_eat == p_eat && p_eat == pp_eat){
				continue;
			}
			
			sum += cur[number];
			sum %= 10000;
		}
		
		System.out.println(sum);
	}

}

Measured memory_bytes: 20068
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define ll long long
//不要再爆long long了！！！！！！！！不要再爆long long了！！！！！！！ 

int main()
{
	int n;
	cin>>n;
	int b=n%1000;
	b=1000-b;
	b%=1000;
	cout<<b<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <iomanip>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
 

int main(){
    float L;
    cin >> L;
    double res;
    res = pow(double(L/3),3);
    cout << fixed << setprecision(6) << res << endl;
    
    return 0;
}

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

int main() {
  ll a, v, b, w, t; cin >> a >> v >> b >> w >> t;
  if (abs(a - b) <= (v - w) * t)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h> 
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define mc map<char, int>
#define ms map<string, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define mod 1000000007LL
//#define mod 998244353 
using namespace std;
int power(int x, int y) ;
int gcd(int a, int b) ;

signed main() {
    quickie
    int n ;
    cin >> n ;
    int a[n+11], b[n+11] ;
    b[n] = 10000000000000000 ;
    b[0] = 100000000000000000 ;
    rep1(i, 1, n-1) {
        cin >> b[i] ;
    }
    int s = 0 ;
    rep1(i, 1, n) {
        a[i] = min(b[i-1], b[i]) ;
        s += a[i] ;
    }
    cout << s << endl ;
}
 
int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}
 
int gcd(int a,int b){
    if(a==0) return b;
    return gcd(b%a,a);
}

Measured memory_bytes: 256
import math


class SegmentTree:
    __slots__ = ["elem_size", "tree_size", "tree"]

    def __init__(self, a: list, default: int):
        real_size = len(a)
        self.elem_size = 1 << math.ceil(math.log2(real_size))
        self.tree_size = 2 * self.elem_size
        self.tree = [default]*self.elem_size + a + [default]*(self.elem_size - real_size)
        self.init_tree()

    def init_tree(self):
        tree = self.tree
        for i in range(self.elem_size-1, 0, -1):
            left, right = tree[i << 1], tree[(i << 1)+1]
            # ===== ??????????????´???????????? =====
            tree[i] = left if left < right else right

    def get_range_indexes(self, x: int, y: int):
        '''[x, y), tree[k], [l_end, r_end)'''
        l, r = x+self.elem_size, y+self.elem_size
        indexes = []
        append = indexes.append
        while l < r:
            if l & 1:
                append(l)
                l += 1
            if r & 1:
                r -= 1
                append(r)
            l, r = l >> 1, r >> 1

        return indexes

    def get_value(self, x: int, y: int):
        tree = self.tree
        index_list = self.get_range_indexes(x, y)

        # ===== ??????????????´???????????? =====
        return min(tree[n] for n in index_list)

    def update_tree(self, k: int):
        tree = self.tree

        while k > 1:
            k >>= 1
            left, right = tree[k << 1], tree[(k << 1)+1]
            # ===== ??????????????´???????????? =====
            tree[k] = left if left < right else right

    def set_value(self, i: int, value: int, op: str):
        k = self.elem_size + i
        if op == "=":
            self.tree[k] = value
        elif op == "+":
            self.tree[k] += value
        self.update_tree(k)


n, q = map(int, input().split())
rmq = SegmentTree([2**31-1]*n, 2**31-1)
ans = []
for _ in [0]*q:
    c, x, y = map(int, input().split())
    if c == 0:
        rmq.set_value(x, y, "=")
    else:
        ans.append(rmq.get_value(x, y+1))
print("\n".join([str(n) for n in ans]))

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

int main(){
    int n;
    cin >> n;
    vector<long long> A;
    vector<long long> B;
    for (auto i = 0; i < n; i++)
    {
        long long A_i;
        cin >> A_i;
        A.push_back(A_i);
    }

    long long sum = 0, sum1=0,sum2=0;

    for (auto i = 0; i < n; i++)
    {
        sum += A[i];
    }

    for (auto i = 0; i < n; i++)
    {
        if(i % 2 == 1){
            sum1 += A[i] * 2;
        }

        if(i != 0 && i%2 == 0){
            sum2 += A[i] * 2;
        }
    }
    



    for (auto i = 0; i < n; i++)
    {
        if(i % 2 == 0){
            if(i == 0){
                cout << sum - sum1 << " ";
            }else{
                sum1 = sum1 + 2 * A[i - 2] - 2 * A[i - 1];
                cout << sum - sum1 << " ";
            }
        }else{
            if(i == 1){
                cout << sum - sum2 << " ";
            }else{
                sum2 = sum2 + 2 * A[i - 2] - 2 * A[i - 1];
                cout << sum - sum2 << " ";
            }
        }
    }
    cout << endl;
}

Measured memory_bytes: 2292
#include<bits/stdc++.h>
using namespace std; 
typedef long long int ll;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    if(n % 2 != 0 || n < 2)
    {
        cout << 0 << endl;
    }
    else
    {
        ll x = 10;
        ll ans = 0;
        while(n / x > 0)
        {
            // cout << n / x << endl;
            ans = ans + (n / x);
            x = x * 5;
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[100005];
bool f[100005];
main () {
	int n,w;
	cin>>n>>w;
	
	f[0]=1;
	for (int i=1; i<=n; i++) {
		int W,V;
		cin>>W>>V;
		for (int j=w; j-W>=0; j--) 
			if (f[j-W]) 
				dp[j]=max(dp[j],dp[j-W]+V),f[j]=1;
	}
	
	ll ans=0;
	for (int i=1; i<=w; i++)
		ans=max(ans,dp[i]);
	cout<<ans<<endl;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    if (k > (n - 1) * (n - 2) / 2) {
        puts("-1");
        return 0;
    }
    vector<pair<int, int>> edges;
    rep(i, n - 1) {
        edges.push_back(make_pair(1, i + 2));
    }
    int rest = (n - 1) * (n - 2) / 2 - k;
    int node = 2, next = 3;
    while (rest--) {
        if (next == n+1) {
            node++;
            next = node + 1;
        }
        edges.push_back(make_pair(node, next++));
    }
    cout << edges.size() << endl;
    for (auto p : edges) {
        printf("%d %d\n", p.first, p.second);
    }
}

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

const int mod = 1000000007;
struct mint {
    ll x; //typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        //tが0なら1を返す
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    //for prime mod
    //逆元を求める、mod-2乗
    mint inv() const {
        return pow(mod-2);
    }
    //逆元をかける
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

mint f(int n) {
    if (n == 0)  return 1;
    mint x = f(n/2);
    x *= x;
    if (n%2 == 1) x *= 2;
    return x;
}

mint choose(int n, int a) {
    mint x = 1, y = 1;
    rep(i,a) {
        x *= n-i;
        y *= i+1;
    }
    return x / y;
}

mint g(int n) {
    mint z = 1;
    for(int i = 1; i <= n; i++) {
        z *= i;
    }
    return z;
}

int main(){
    int n;
    cin >> n;
    mint ans = g(n);
    cout << ans.x << "\n";
    return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  string S;
  cin >> S;

  int answer {};
  int S_size = S.size();
  rep(i, S_size) {
    if (S[i] == '+') {
      ++answer;
    } else if (S[i] == '-') {
      --answer;
    }
  }
  cout << answer << '\n';
}


Measured memory_bytes: 256
input = raw_input
n = int(input())
s = input()

r_is = []
r_dic = {}
g_is = []
g_dic = {}
b_is = []
b_dic = {}

r_num = 0
g_num = 0
b_num = 0
for i, c in enumerate(s):
    if c=="R":
        r_is.append(i)
        #r_dic[i] = None
        r_num += 1
    elif c == "G":
        g_is.append(i)
        #g_dic[i] = None
        g_num += 1
    else:
        #b_is.append(i)
        b_dic[i] = None
        b_num += 1

out = 0
for ri in r_is:
    for gi in g_is:
        small_i = min(ri, gi) 
        big_i = max(ri, gi) 
        diff = big_i - small_i
        cur_b_num = b_num

        cand_i = small_i - diff
        if cand_i >= 0:
            try:
                b_dic[cand_i]
                cur_b_num -= 1
            except:
                pass

        cand_i = big_i + diff
        if cand_i <= n-1:
            try:
                b_dic[cand_i]
                cur_b_num -= 1
            except:
                pass

        # center
        wa = small_i + big_i
        if wa % 2 == 0:
            cand_i = wa // 2
            try:
                b_dic[cand_i]
                cur_b_num -= 1
            except:
                pass


        out += cur_b_num

print(out)

Measured memory_bytes: 75608
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

int main(){
  int X, N;
  cin >> X >> N;
  vector<int> P(N);
  for(int i = 0; i < N; i++){
    cin >> P.at(i);
  }
  
  bool loop = true;
  int diff = 0;
  while(loop){
    bool judgep = false;
    bool judgem = false;
    for(int i = 0; i < N; i++){
      if(X + diff == P.at(i)) judgep = true;
      if(X - diff == P.at(i)) judgem = true;
    }
    if(judgep && judgem) diff++;
    else{
      if(judgep == false && judgem == false){
        cout << min(X + diff, X - diff) << endl;
        return 0;
      }
      else{
        if(judgep == false){
          cout << X + diff << endl;
          return 0;
        }
        else{
          cout << X - diff << endl;
          return 0;          
        }
      }
    }
  }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int64_t N;
  cin >> N;

  int64_t a, b;
  for (int i=1; i<sqrt(N)+1; i++){
    if(N % i == 0){
      a = i; b = N/i;
    }
  }

  cout << a+b-2 << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  if (N % 2 == 1) {
   cout << (N - 1) / 2 << endl; 
  } else if (N % 2 == 0) {
   cout << (N - 2) / 2 << endl; 
  }
}


Measured memory_bytes: 256
#include<iostream>
//STL,Vector使用
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    vector<vector<char>> vec(2,vector<char>(3));
    for(int i=0;i<2;i++){
        for(int j=0;j<3;j++){
        cin >> vec.at(i).at(j);
        }
    }
    //vec.at(上から何番目).at(左から何番目)
    if(vec.at(0).at(0)!=vec.at(1).at(2)){
        cout << "NO"<<endl;
        return 0;
    }
    else if(vec.at(0).at(1)!=vec.at(1).at(1)){
        cout << "NO"<<endl;
        return 0;
    }
    else if(vec.at(0).at(2)!=vec.at(1).at(0)){
        cout << "NO"<<endl;
        return 0;
    }
    
    cout << "YES"<<endl;
}

Measured memory_bytes: 3492