akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <tuple>
#include <algorithm>
//#include <cmath>
using namespace std;


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

    if(N==0){
        cout << X << endl;
        return 0;
    }

    vector< int > exist(102, 0);

    int pi;
    for(int i=0;i<N;i++){
        cin >> pi;
        exist[pi]++;
    }

    if(exist[X]==0){
        cout << X << endl;
        return 0;
    }

    for(int i=X-1,j=X+1;i>=0||j<=101;i--,j++){
        if(i>=0){
            if(exist[i]==0){
                cout << i << endl;
                break;
            }
        }
        if(j<=101){
            if(exist[j]==0){
                cout << j << endl;
                break;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'a' = 97

int main()
{
    while (1) {
        int a, b;
        char op;
        cin >> a >> op >> b;
        int ans = 0;
        if (op == '?') break;
        else if (op == '+') ans = a + b;
        else if (op == '-') ans = a - b;
        else if (op == '*') ans = a * b;
        else ans = a / b;
        cout << ans << endl;
    }
}



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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) cin >> vec.at(i);

  int ans = 0;

  for (int i = 1; i < N - 1; i++) {
    if (vec.at(i - 1) < vec.at(i) && vec.at(i) > vec.at(i + 1)) continue;
    else if (vec.at(i - 1) > vec.at(i) && vec.at(i) < vec.at(i + 1)) continue;
    else ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import math
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	N, H = MAP()
	A = [0]*(2*N)

	# Aを平たいリストで持っておく
	for i in range(N):
		a, b = MAP()
		A[2*i] = a
		A[2*i+1] = b
	
	# 偶数番目の攻撃方法は1度限りなのでメモしておく
	B = [0 if not i%2 else 1 for i in range(2*N)]
	# print(A,B)

	# 順序を保ってソートするため、二つのリストを1回マージ
	C = list(zip(A,B))
	# print(C)

	# Aの降順でソート
	C.sort(reverse=True)

	# 再度マージしたリストを分割
	A, B = zip(*C)
	# print(A, B)

	ans = 0
	for i, a in enumerate(A):
		if B[i]:
			H -= a
			ans += 1
			if H <= 0:
				break
		else:
			ans += math.ceil(H/a)
			break
	
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 44256
def daydream():
	S = input()
	flag = False
	while True:
		if len(S) == 0:
			flag = True
			break
		elif S.endswith('dreamer'):
			S = S[:-7]
		elif S.endswith('dream'):
			S = S[:-5]
		elif S.endswith('eraser'):
			S = S[:-6]
		elif S.endswith('erase'):
			S = S[:-5]
		else:
			break
	if flag:
		print('YES')
	else:
		print('NO')

daydream()

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

int main() {
    int k , a, b;
    cin >> k >> a >> b;
    for (int i=a; i<=b; i++) {
        if (i%k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD ((ll)1e9+7)
ll N,M;
ll amk[101010];
ll dp[101010];
ll i,j,ans;
int main(){
    scanf("%lld%lld", &N,&M);
    fornum(i,0,M){
        ll a;
        scanf("%lld", &a);
        amk[a] = 1;
    }
    dp[0] = 1;
    j = 0;
    fornum(i,0,N){
        if(amk[i+1]==0){
            dp[i + 1] += dp[i];
            dp[i + 1] %= MOD;
        }
        if(amk[i+2]==0){
            dp[i + 2] += dp[i];
            dp[i + 2] %= MOD;
        }
    }
    printf("%lld\n", dp[N]);

    return 0;
}

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

using namespace std;

struct UnionFind {  // The range of node number is u 0 v n-1
	vector<int> rank, parents;
	UnionFind() {}
	UnionFind(int n) {  // make n trees.
		rank.resize(n, 0);
		parents.resize(n, 0);
		for (int i = 0; i < n; i++) {
			makeTree(i);
		}
	}
	void makeTree(int x) {
		parents[x] = x;  // the parent of x is x
		rank[x] = 0;
	}
	bool isSame(int x, int y) { return findRoot(x) == findRoot(y); }
	void unite(int x, int y) {
		x = findRoot(x);
		y = findRoot(y);
		if (rank[x] > rank[y]) {
			parents[y] = x;
		}
		else {
			parents[x] = y;
			if (rank[x] == rank[y]) {
				rank[y]++;
			}
		}
	}
	int findRoot(int x) {
		if (x != parents[x]) parents[x] = findRoot(parents[x]);
		return parents[x];
	}
};

// 辺の定義
struct Edge {
	int u;
	int v;
	int cost;
};

struct posi {
	int x;
	int y;
	int num;
};

bool comp_e(const Edge &e1, const Edge &e2) { return e1.cost < e2.cost; } // 辺を直接比較するための関数

bool comp_x(const posi &l, const posi &r) { return l.x < r.x; }
bool comp_y(const posi &l, const posi &r) { return l.y < r.y; }

long long Kruskal(vector<Edge> &edges, int v) {

	long long sum = 0;  // 最小全域木の重みの総和

	sort(edges.begin(), edges.end(), comp_e); // 辺の重みでソート

	UnionFind uft = UnionFind(v);

	for (unsigned int i = 0; i < edges.size(); i++) {
		if (!uft.isSame(edges[i].u, edges[i].v)) { // 閉路にならなければ加える
			uft.unite(edges[i].u, edges[i].v);
			sum += edges[i].cost;
		}
	}

	return sum;
};

int main() {

	int n;
	cin >> n;
	vector <posi> xy(n);
	for (int i = 0; i < n; i++) {
		cin >> xy[i].x >> xy[i].y;
		xy[i].num = i;
	}

	vector <posi> xy_x(n);
	vector <posi> xy_y(n);

	xy_x = xy;
	sort(xy_x.begin(), xy_x.end(), comp_x);
	xy_y = xy;
	sort(xy_y.begin(), xy_y.end(), comp_y);

	vector<Edge> edges(n*2-2);

	for (int i = 0; i < n - 1; i++) {
		edges[i] = { xy_x[i].num,xy_x[i + 1].num,abs(xy_x[i].x - xy_x[i + 1].x) };
	}
	for (int i =0; i < n-1; i++) {
		edges[i+n-1] = { xy_y[i].num,xy_y[i + 1].num,abs(xy_y[i].y - xy_y[i + 1].y) };
	}

	long long krs = Kruskal(edges, n);
	cout << krs << endl;
	return 0;
}

Measured memory_bytes: 9880
#include <stdio.h>
int main(void){
        int i,x=0,c;
        int val[] = {1,5,10,50,100,500};

        for(i=0; i<6; i++){
                scanf("%d",&c);

                x+= val[i]*c;
        }
        if(x>=1000)
                printf("1\n");
        else
                printf("0\n");
        return 0;
}

Measured memory_bytes: 1808
#include <stdio.h>

int main(void) {
	char s[4];
	int i,j,c;
	c=0;
	scanf("%s",&s);
	for(i=0;i<4;i++){
		for(j=0;j<4;j++){
		if(s[i]==s[j]){
			c++;
		}	
		}
		
	}
	if(c==8){
		printf("Yes");
	}else{
		printf("No");
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;


#define REP(i, n) for(ll i = 0; i < n; i++)


























int main(){
    ll n;
    string s;
    cin >> n >> s;
    vector<ll> c1(n + 1), c2(n + 1);
    REP(i, n){
        c1[i + 1] = c1[i];
        if(s[i] == 'W') c1[i + 1]++;
    }
    for(ll i = n - 1; i >= 0; i--){
        c2[i] = c2[i + 1];
        if(s[i] == 'R') c2[i]++;
    }
    ll ans = INF;
    REP(i, n + 1){
        ll t = min(c1[i], c2[i]);
        ans = min(ans, t + max(c1[i], c2[i]) - t);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6836
#include<stdio.h>
int main(){
  int c[100010]={};
  int n,m,a,b,i;
  scanf("%d %d",&n,&m);
  for(i=0;i<m;i++){
    scanf("%d %d",&a,&b);
    c[a]++;
    c[b]++;
  }
  for(i=0;i<n;i++){
    if(c[i+1]%2)break;
  }
  printf("%s\n",i==n?"YES":"NO");
  return 0;
}


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

int main() {
  	int a, b;
	string ans = "No";
 	cin >> a >> b ;
  
	if(2*a<= b && b <=4*a)
    {if(b%2 == 0)
      {ans = "Yes";} 
    }
	cout << ans << endl;
}



Measured memory_bytes: 3624
#include<iostream>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<bitset>
#include<functional>
#include<iterator>
#include<complex>
#include<fstream>
#include<random>
#include<ctype.h>
#include<stdio.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using PII = pair<ll, ll>;
using piii = pair<pii, pii>;
using Pi = pair<int, pii>;
using Graph = vector<vector<int>>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
bool check(int x, int y) {
	if (0 <= x && x<55 && 0 <= y && y<55)return true;
	else return false;
}
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;

//iの逆元mod inf
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const double PI = 3.14159265358979323846;
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
double Euclidean_distance(double x1, double y1, double x2, double y2) {
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

//素因数分解
map<int, int>prime_factor(int n) {
	map<int, int>res;
	for (int i = 2; i*i <= n; ++i) {
		while (n%i == 0) {
			++res[i];
			n /= i;
		}
	}
	if (n != 1)res[n] = 1;
	return res;
}


ll powmod(ll a, ll k, ll mod) {
	ll ap = a, ans = 1;
	while (k) {
		if (k & 1) {
			ans *= ap;
			ans %= mod;
		}
		ap = ap * ap;
		ap %= mod;
		k >>= 1;
	}
	return ans;
}
ll invi(ll a, ll mod) {
	return powmod(a, mod - 2, mod);
}
#define PI 3.14159265358979323846  // 円周率
//逆元Aを足したときのmodで割った余りは
//+=invi(A)
//Yで割ることはY^(10^9+7)-2を掛けることは同値
///////////////////////////////////////
bool is_prime(int n) {
	for (int i = 2; i*i <= n; ++i) {
		if (n%i == 0)return false;
	}
	return n != 1;
}

ll cnt[10000010] = {};
int main() {
	int n; cin >> n;
	for (int i = 2; i<=n/2; ++i) {
		int k = i;
		int x = n / k;
		for (int j = 2; j <= x; ++j) {
			cnt[k*j]++;
		}
	}
	ll ans = 1;
	for (int i = 2; i <= n; ++i) {
		ans += i*(cnt[i]+2);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 81736
h, w = map(int, input().split())
SS = [input() for _ in range(h)]
ret = ''
for i in range(h):
    for j in range(w):
        if SS[i][j] == '#':
            ret += '#'
            continue
        count = 0
        for dx, dy in ((1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)):
            ny = i + dy
            nx = j + dx
            if 0 <= nx < w and 0 <= ny < h and SS[ny][nx] == '#':
                count += 1
        ret += str(count)
    ret += '\n'
print(ret)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
using namespace std;

#define M 1046527
#define L 14

char H[M][L];

int getNum(char c)
{
	if(c=='A')return 0;
	else if(c=='T')return 1;
	else if(c=='G')return 2;
	else return 3;
}
int getKey(char str[])
{
	int sum=0,p=1;
	for(int i=0;i<strlen(str);i++)
	{
		sum+=p*getNum(str[i]);
		p*=4;
	}
	return sum;
}

int h1(int key){return key%M;}
int h2(int key){return 1+key%(M-1);}
int h(int key,int i){return (h1(key)+i*h2(key))%M;}

int find(char str[])
{
	int key=getKey(str);
	long long i,h;
	for(i=0;;i++)
	{
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)return 1;
		else if(strlen(H[h])==0)return 0;
	}
}

int insert(char str[])
{
	int key=getKey(str);
	long long i,h;
	for(i=0;;i++)
	{
		h=(h1(key)+i*h2(key))%M;
		if(strcmp(H[h],str)==0)return 1;
		else if(strlen(H[h])==0)
		{
			strcpy(H[h],str);
			return 0;
		}
	}
}

int main()
{
	int n;scanf("%d",&n);
	char str[L],com[8];
	for(int i=0;i<M;i++)
	{
		H[i][0]=0;
	}
	for(int i=0;i<n;i++)
	{
		scanf("%s %s",com,str);
		if(com[0]=='i')insert(str);
		else
		{
			if(find(str)==1)printf("yes\n");
			else printf("no\n");
		}
	}
	return 0;
}

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

int main(){
	while(1){
	double x,h;
	cin>>x>>h;
		if(x==0&&h==0)break;
	double s=2*x*sqrt((x/2)*(x/2)+h*h);
	cout<<fixed<<setprecision(6)<<x*x+s<<endl;
	}
	return 0;
}

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

const int MAXN = 200010;
typedef long long LL;
LL A[MAXN], li[MAXN];
int n, K;
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> K;
	LL ans = 0;
	for (int i = 1; i <= n; ++i)
		std::cin >> A[i], A[i] -= K, A[i] += A[i - 1], ans += A[i] >= 0;
	memcpy(li, A, n + 1 << 3);
	std::sort(li + 1, li + 1 + n);
	for (int i = 0; i <= n; ++i)
		A[i] = std::lower_bound(li + 1, li + 1 + n, A[i]) - li;
	memset(li, 0, sizeof li);
	for (int i = 1; i <= n; ++i) {
		for (int x = A[i]; x; x &= x - 1) ans += li[x];
		for (int x = A[i]; x <= n; x += x & -x) ++li[x];
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    FOR(i, 1, b){
        if((a * i) % b == c){
            cout << "YES" << "\n";
            return 0;
        }
    }
    cout << "NO" << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MX = 2e5+2;
vector<int> adj[MX];
bool seen[MX];
int dfs(int i) {
	if(seen[i])
		return 0;
	seen[i] = 1;
	int cnt = 1;
	for(int a: adj[i]) {
		cnt += dfs(a);
	}
	return cnt;
}
int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n, m;
	cin >> n >> m;
	while(m--) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	int mx = 0;
	for(int i=1; i<=n; i++) {
		if(!seen[i]) {
			mx = max(mx, dfs(i));
		}
	}
	cout << mx;
}

Measured memory_bytes: 20916
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<long long> x(n, 0), y(n, 0), z(n, 0);
  for (int i = 0; i < n; ++i) {
    cin >> a.at(i);
    ++x.at(a.at(i) - 1);
  }
  long long all = 0;
  for (int i = 0; i < n; ++i) {
    if (x.at(i) <= 1) {
      continue;
    } else if (x.at(i) == 2) {
      y.at(i) = 1;
      z.at(i) = 1;
    } else if (x.at(i) == 3) {
      y.at(i) = 3;
      z.at(i) = 2;
    } else {
      y.at(i) = x.at(i) * (x.at(i) - 1) / 2;
      z.at(i) = y.at(i) - (x.at(i) - 1) * (x.at(i) - 2) / 2;
    }
    all += y.at(i);
  }
  for (int i = 0; i < n; ++i) {
    cout << all - z.at(a.at(i) - 1) << endl;
  }
  return 0;
}


Measured memory_bytes: 8064
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

struct Point{
	double x,y;
};

int main(){

	double c1x,c1y,c1r,c2x,c2y,c2r,dist;

	scanf("%lf %lf %lf",&c1x,&c1y,&c1r);
	scanf("%lf %lf %lf",&c2x,&c2y,&c2r);

	dist = sqrt((c1x-c2x)*(c1x-c2x)+(c1y-c2y)*(c1y-c2y));

	if(dist > c1r + c2r){
		printf("4\n");
	}else if(fabs(dist - (c1r+c2r)) < 0.00000001){
		printf("3\n");
	}else{
		if(c1r > c2r){
			if(dist < c1r){
				if(fabs(c1r-(dist+c2r)) < 0.00000001){
					printf("1\n");
				}else{
					if(dist < (c1r-c2r)){
						printf("0\n");
					}else{
						printf("2\n");
					}
				}

			}else{
				printf("2\n");
			}

		}else{
			if(dist < c2r){
				if(fabs(c2r-(dist+c1r)) < 0.00000001){
					printf("1\n");
				}else{
					if(dist < (c2r-c1r)){
						printf("0\n");
					}else{
						printf("2\n");
					}
				}
			}else{
				printf("2\n");
			}
		}

	}

    return 0;
}

Measured memory_bytes: 2744
// TO KAISE HAI AAP LOG!! //

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

#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define F first
#define S second
#define all(v) v.begin(),v.end()
ll mod=1e9+7;
 
/*/----------------------------- Code begins -----------------------------/*/
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll t=1,tc;
    //cin>>t;
    for(tc=1;tc<=t;tc++){
      ll n,k,i,j,s=0;
      cin>>n>>k;
      ll a[n+5];
      for(i=0;i<n;i++)cin>>a[i];
      for(i=0;i<k;i++){
          s+=a[i];
      }
      for(i=k;i<n;i++){
          if((s-a[i-k]+a[i])>s)
           cout<<"Yes\n";
          else cout<<"No\n";
          s=s-a[i-k]+a[i];
      }
    }
	return 0;
}

Measured memory_bytes: 5232
#include <iostream>
#include <utility>
#include <queue>

int main(int argc, char *argv[]){
    int K;
    int X, Y;
    std::cin >> K >> X >> Y;
    int signX=1;
    if(X < 0){
        X = -X;
        signX = -1;
    }
    int signY=1;
    if(Y < 0){
        Y = -Y;
        signY = -1;
    }
    bool isSwapped = false;
    if(X<Y){
        using std::swap;
        swap(X,Y);
        isSwapped = true;
    }

    std::queue<std::pair<int,int> > pos;
    int r = (X+Y)%K;
    int n = (X+Y)/K;
    int tmpX=0, tmpY=0;
    if(X+Y<K){
        if(r==0){
            //do nothing         
        }else if((r&1)==0){
            if((K&1)==0){
                tmpX = r>>1;
                tmpY = tmpX-K;
                pos.emplace(tmpX,tmpY);
            }else{
                tmpX = r>>1;
                tmpY = tmpX-K;
                pos.emplace(tmpX,tmpY);
            }
        }else{
            if((K&1)==0){
                std::cout << -1 << std::endl;
                return 0;
            }else{
                tmpX = -((K+r)>>1);
                tmpY = -((K-r)>>1);
                pos.emplace(tmpX,tmpY);
                tmpX = 0;
                tmpY = -K+r;
                pos.emplace(tmpX,tmpY);
            }
        }
    }else{
        if(r==0){
            //do nothing
        }else if((r&1)==0){
            if((K&1)==0){
                tmpX = (K+r)>>1;
                tmpY = tmpX-K;
                pos.emplace(tmpX,tmpY);
            }else{
                tmpX = r>>1;
                tmpY = tmpX-K;
                pos.emplace(tmpX,tmpY);
            }
        }else{
            if((K&1)==0){
                std::cout << -1 << std::endl;
                return 0;
            }else{
                tmpX = (K+r)>>1;
                tmpY = tmpX-K;
                pos.emplace(tmpX,tmpY);
            }
        }

    }
    while(tmpX != X || tmpY != Y){
        tmpX += K;
        if(tmpX > X){
            tmpY += tmpX - X;
            tmpX = X;
        }
        pos.emplace(tmpX,tmpY);
    }

    std::cout << pos.size() << std::endl;
    while(!pos.empty()){
        auto &front = pos.front();
        if(isSwapped){
            std::cout << signX*front.second << " " << signY*front.first << std::endl;
        }else{
            std::cout << signX*front.first << " " << signY*front.second << std::endl;
        }
        pos.pop();
    }

    return 0;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < n; ++i)
#define REPR(i,n) for(int i = n; i >= 0; --i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = b-1;i >= a;--i)
#define p(s) cout << (s) << endl
#define p2(s,t) cout << (s) << " " << (t) << endl 
#define ALL(v) (v).begin(), (v).end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

static const ll MOD  = 1e9 + 7;
static const ll INF  = 1e18;
static const ll MAX_N = 100000;
static const ll MAX_M = 100000;

static const int White = 0;
static const int Gray = 1;
static const int Black = 2;

void pvector(vector<int> A){
    cout << "[vector]";
    for(int i = 0; i < A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    ll N, M;
    cin >> N >> M;
    int A[MAX_N+1] = {0};
    REP(i, M){
        int a; cin >> a;
        A[a]++;
    }
    ll dp[MAX_N+1] = {0};//i段目での場合の数
    dp[0] = 1;
    dp[1] = 1;
    for(int i = 2; i <= N; i++){
        if(A[i] == 0){
            if(A[i-1] == 0 && A[i-2] == 0)dp[i] = (dp[i-1] + dp[i-2])%MOD;
            else if(A[i-1] == 0 && A[i-2] != 0) dp[i] = dp[i-1]%MOD;
            else if(A[i-1] != 0 && A[i-2] == 0) dp[i] = dp[i-2]%MOD;
            else dp[i] = 0;
        }
    }
    p(dp[N]);
}

Measured memory_bytes: 1408
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
)

func main() {
	n, w := readInt(), readInt()
	dp := make([]int, w+1)

	for i := 0; i < n; i++ {
		ww, v := readInt(), readInt()
		for j := w - ww; j >= 0; j-- {
			dp[j+ww] = max(dp[j+ww], dp[j]+v)
		}
	}

	fmt.Println(dp[w])
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=305;
long double p[305][305][305],ev[305][305][305];
ll n,cnt[4];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    for(ll i=1,x;i<=n;i++)cin>>x,cnt[x]++;
    p[cnt[1]][cnt[2]][cnt[3]]=1;
    for(ll c=n;c>=0;c--){
        for(ll b=n;b>=0;b--){
            for(ll a=n;a>=0;a--){
                if(a==0&&b==0&&c==0)continue;
                if(a+b+c>n)continue;

                long double tmp_p = (n*1.0-(a+b+c+0.0))/(n*1.0);
                long double tmp_ev = tmp_p/(1-tmp_p) + 1;

                ev[a][b][c]+=tmp_ev*p[a][b][c];

                if(a){
                    tmp_p = (a*1.0)/(a*1.0 + b + c);
                    p[a-1][b][c]+=p[a][b][c]*tmp_p;
                    ev[a-1][b][c]+=ev[a][b][c]*tmp_p;
                }
                if(b){
                    tmp_p = (b*1.0)/(a*1.0 + b + c);
                    p[a+1][b-1][c]+=p[a][b][c]*tmp_p;
                    ev[a+1][b-1][c]+=ev[a][b][c]*tmp_p;
                }
                if(c){
                    tmp_p = (c*1.0)/(a*1.0 + b + c);
                    p[a][b+1][c-1]+=p[a][b][c]*tmp_p;
                    ev[a][b+1][c-1]+=ev[a][b][c]*tmp_p;
                }
            }
        }
    }
    cout<<fixed<<setprecision(18)<<ev[0][0][0];
}

Measured memory_bytes: 874752
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

ll pow_mod(ll n, ll p, ll mod) {
    if (p == 0) {
        return 1;
    } else if (p % 2 == 1) {
        return pow_mod(n, p - 1, mod) * n % mod;
    } else {
        ll s = pow_mod(n, p / 2, mod);
        return s * s % mod;
    }
}

void solve() {
    int n;
    cin >> n;
    vector<vector<pair<int, bool>>> c(n, vector<pair<int, bool>>());
    int a, x, y;
    REP(i, n) {
        cin >> a;
        REP(j, a) {
            cin >> x >> y;
            x--;
            c[i].emplace_back(x, y == 1);
        }
    }

    int ans = 0;
    REP(i, 1 << n) {
        bool ok = true;
        int z = 0;
        REP(j, n) {
            if ((1 & i >> j) == 1) {
                z++;
                for (auto d : c[j]) {
                    if (d.second) {
                        if ((1 & i >> d.first) == 0) {
                            ok = false;
                            break;
                        }
                    } else {
                        if ((1 & i >> d.first) == 1) {
                            ok = false;
                            break;
                        }
                    }

                }
                if (!ok) break;
            }
        }
        if (ok) chmax(ans, z);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3684
#include <stdio.h>
#include <stdlib.h>

#define N (10*3*4)

int main(){
	int n,V[4+1][3+1][10+1];
	int b,f,r,v;

	scanf("%d",&n);

	for(int i=1;i<=4;i++){
		for(int j=1;j<=3;j++){
			for(int k=1;k<=10;k++){
				V[i][j][k]=0;
			}
		}
	}

	for(int i=0;i<n;i++){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		V[b][f][r]+=v;
		if(V[b][f][r] < 0){
			V[b][f][r]=0;
		}
	}

	for(int i=1;i<=4;i++){
		for(int j=1;j<=3;j++){
			for(int k=1;k<=10;k++){
				printf(" %d",V[i][j][k]);
			}
			printf("\n");
		}
		if(i!=4){
			for(int j=0;j<20;j++){
				printf("#");
			}
			printf("\n");
		}
	}	

	return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6;
const ll LINF = 1e18;
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl

ll n, cnt, ans, a, b, c, d, tmp, tmpp, m, h, w, x, y, sum, pos, k;
ld doua;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
bool fl;
struct edge
{
    int to, cost;
};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin >> n >> k;
    ll kae;
    kae = n - 1;
    ans = kae / (k - 1);
    if (kae % (k - 1) != 0)
        ans++;
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    // ABC152D
    static final long MOD = 1_000_000_007;
    // 10^9+7
    static final int MAX = 2_147_483_646;
    // intの最大値
    static final int INF = 1_000_000_000;

    // 10^9
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long ans = 0;
        long num = 1;
        while(n > 0){
            n/=2;
            ans += num;
            num *= 2;
        }
        System.out.println(ans);
    }
   
}


Measured memory_bytes: 22608
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define x_ real()
#define y_ imag()
#define cross(a, b) (conj(a)*(b)).imag()
#define dot(a, b) (conj(a)*(b)).real()
#define PI acos(-1)
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define ordered_set tree<pair<int, int>, null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<ld> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
typedef pair<double, double> pd;
pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };
const ld eps = 1e-6;
const int N = 2e5 + 7;
string s;

int dp[N][27][27];

int solve(int idx, char prev1, char prev2) {
	if (idx == s.size())
		return 0;

	string p;
	if (prev1 >= 'a' && prev1 <= 'z')
		p += prev1;
	if (prev2 >= 'a' && prev2 <= 'z')
		p += prev2;

	int& ans = dp[idx][prev1-'a'][prev2-'a'];
	if (~ans)
		return ans;
	ans = -N - 15;
	if (idx != s.size() - 1) {
		if (s.substr(idx, 2) != p) {
			ans = max(ans, 1+solve(idx+2, s.substr(idx, 2)[0], s.substr(idx, 2)[1]));
		}
		if (s.substr(idx, 1) != p)
			ans = max(ans, 1+solve(idx+1, 'z'+1, s.substr(idx, 1)[0]));
	}
	else {
		if (s.substr(idx, 1) != p)
			ans = max(ans, 1+solve(idx+1, 'z'+1, s.substr(idx, 1)[0]));
	}
	return ans;
}



int main() {
	fastIO;
	cin >> s;
	memset(dp, -1, sizeof dp);
	cout << solve(0, 'z'+1, 'z'+1);

}


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

using namespace std;

int main(){
    int n, k;
    string s;
    cin >> n >> k >> s;
    int ans = 0, cnt = 0;
    char last = 'w';
    for (int i = 0; i < n; i++){
        if (s[i] != last){
            cnt ++;
            last = s[i];
        }
        if (s[i] == 'L' && i > 0 && s[i - 1] == 'L') ans++;
        else if (s[i] == 'R' && i < n - 1 && s[i + 1] == 'R') ans++;
    }
    if (k > (cnt - 1) / 2) ans = n - 1;
    else ans += k * 2;

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
vector<ll> v(10000005,1);
void  solve(){
  int n;
  cin>>n;
  rep(i,2,n+1){
    for(int j=i;j<=n;j+=i){
      v[j]++;
    }
  }
  ll ans=1;
  rep(i,2,n+1){
    ans+= 1LL*i*v[i];
  }
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


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

int main() {

 int A,B,C,K;
  
  cin >> A >> B >> C >> K;
  
  if(K <= A){
  cout << K << endl;  
  }
  
  else if(K <= A+B){
  cout << A << endl;  
  }
  
  else{
  cout << A*2-K+B << endl;
  }
    
 
}

Measured memory_bytes: 3616
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;

int n;
int n0;
long long a[111];

set<long long>st;
set<long long>::iterator it;
int h[111];
int g[111];

long long ans,ss;
int main()
{
    int i,j,k;
    
    cin>>n;
    n0=n;
    ss=0;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        ss+=a[i];
    }
    
    ans=ss;
    
    n=n0/4;
    /*
    for(i=1;i<=n;i++)
    {
         st.insert(1<<(i-1));
    }
    */
    st.insert(0);
    
    
    int c=0;
    it=st.begin();
    while(it!=st.end())
    {
        long long now=*it;
        long long now0=now;
        i=1;
        
        //cout<<now<<endl;
        memset(h,0,sizeof(h));
        while(now>0)
        {
            h[i]=(now&1);
            now>>=1;
            i++;
        }
        /*
        for(j=1;j<=n;j++)
        {
            cout<<h[j]<<' ';
        }
        cout<<"hhh"<<endl;
        */
        for(j=i;j<=n;j++)
        {
             
             for(k=1;k<=j/k;k++)
             {
                 if(j%k==0)
                 {
                     if(h[k]==1 || h[j/k]==1)break;
                 }
             }
             if(k<=j/k)
             {
                 continue;
             }
             
             st.insert(now0|(1<<(j-1)));
        }
        
        
        
        //////////////////////////
        long long tmp=0;
        memset(g,0,sizeof(g));
        for(i=1;i<=n;i++)
        {
            //cout<<h[i]<<"  ss"<<endl;
            if(h[i]==1)
            {
                for(j=i;j<=n0;j+=i)
                {
                    if(g[j]==0)tmp+=a[j];
                    //cout<<j<<' '<<a[j]<<"   uuu"<<endl;
                    g[j]=1;
                }
            }
        }
        
        //cout<<tmp<<" tmp"<<endl;
        
        for(i=n0/2+1;i<=n0;i++)
        {
            if(g[i]==0 && a[i]<0)
            {
                tmp+=a[i];
                g[i]=1;
            }
        }
        
        //cout<<tmp<<" tmp2"<<endl;
        for(i=n0/4+1;i<=n0/2;i++)
        {
            long long w=0;
            if(g[i]==0)w+=a[i];
            if(i*2<=n0 && g[i*2]==0)w+=a[i*2];
            if(i*3<=n0 && g[i*3]==0)w+=a[i*3];
            if(w<0)
            {
                tmp+=w;
                g[i]=g[i*2]=g[i*3]=1;
            }
        }
        //cout<<ss<<' '<<tmp<<' '<<ss-tmp<<"  ---"<<endl;
        ans=max(ans,ss-tmp);
        
        
        ///////////////////////////////
        c++;
        it++;
    }
    
    //cout<<c<<endl;
    
    cout<<ans<<endl;
    return 0;
} 


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

int main() {
    int N;
    cin >> N;
    int A[N];
    for(int i=0;i<N;i++) cin >> A[i];
    sort(A,A+N);
    long tate =0, yoko = 0;
    for(int i=N-1;i>=0;i--){
        if(A[i]==A[i-1]){
            tate = A[i];
            for(int j=i-2;j>=0;j--){
                if(A[j]==A[j-1]){
                    yoko=A[j];
                    break;
                }
            }
            break;
        }
    }
    long x = tate * yoko;
    cout << x << "\n";
}

Measured memory_bytes: 640
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>

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

int main(void)
{
	int N;
	string S;

	cin >> N;
	cin >> S;

	int ans = 0;
	for (int i = 1; i < N; i++){
		int cnt = 0;
		int max_cnt = 0;
		bool isContinue = true;
		for (int j = 0; j < N - i; j++){
			//cout << S[j] << " " << S[i + j] << endl;
			if (S[j] == S[i + j]){
				if (isContinue){
					cnt++;
				}
				else{
					cnt = 1;
					isContinue = true;
				}
			}
			else{
				isContinue = false;
			}
			max_cnt = max(cnt, max_cnt);
			//cout << cnt << endl;
		}
		cnt = min(max_cnt, i);
		ans = max(cnt, ans);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
#define llMAX 9223372036854775807LL
#define llMIN -9223372036854775808LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
 
ll n,k,x,y;
 
int main(){
  ll ans=0;
  cin >> n ;
  vi a(n+1),b(n+1),c(n+1),d(n+1);
  REP(i,n+1) cin>>a[i];



  if (n==0){
    if (a[0]==1){
      cout<<1<<endl;
      return 0;
    }else{
      cout<<-1<<endl;
      return 0;
    }
  }
  


  if (a[0]!=0){
    cout<<-1<<endl;
    return 0;
  }

 
 

  d[n]=a[n];
  for(ll i=n-1;i>=0;i--){
    d[i]=d[i+1]+a[i];
  }

  ll nown=1;
  b[0]=1;
  c[0]=1;
  for(ll i=1;i<n+1;i++){
    nown=min(nown*2,d[i]);
    b[i]=nown;
    nown-=a[i];
    if (nown<0){
      cout<<-1<<endl;
      return 0;
    }


    c[i]=nown;
  }

  

 
 
 
  int flag=0;
  for(ll i=0;i<n+1;i++){
    ans+=b[i];
    flag+=(b[i]<=0);
    //flag+=(c[i]<0);
  }

  /*
  if (flag!=0){
    cout<<-1<<endl;
    return 0;
  }
  */
 
 
 
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 6432
// ~/SolverToBe/Developers/Corvus
// ~/sudo apt-get verdict Accpeted

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>
#include <assert.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 105, M = 1000005;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;

int n,k,a[N],dp[2][100005];

int calc(int i, int rem) {
    if(rem==0)
        return i^1;
    int &r = dp[i][rem];
    if(r!=-1)
        return r;
    r = i^1;
    for(int j=0; j<n; j++)
        if(rem >= a[j] && calc(i^1, rem-a[j])==i) {
            r = i;
            break;
        }
    return r;
}

int main() {
    scanf("%d%d",&n,&k);
    for(int i=0; i<n; i++)
        scanf("%d",a+i);
    memset(dp,-1,sizeof dp);
    printf("%s\n", calc(0,k)==0 ? "First" : "Second");
    return 0;
}

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

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String chr[] = in.split(" ");
			System.out.println(chr[2]+" "+chr[0]+" "+chr[1]);
		}
	}
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll dig = 1;
  char response = ' ';
  while (response!='N'&&dig<powl(10,10)) {
    dig *= 10;
    cout << "? " << dig << endl;
    cin >> response;
  }

  ll result = 0;
  if (dig!=powl(10,10)) {
    ll l = dig/100, r = dig/10-1;
    while (l!=r) {
      ll mid = (l+r+1)/2;
      cout << "? " << mid << endl;
      cin >> response;
      if (response=='Y') l = mid;
      else r = mid-1;
    }
    ll d10 = l*10, d1 = 10;
    response = ' ';
    while (response!='N'&&d1>0) {
      d1--;
      cout <<  "? " << (d10+(d1-1))*10 << endl;
      cin >> response;
    }
    result = d10+d1;
  }
  else {
    ll now = 1;
    response = ' ';
    while (response!='Y') {
      now *= 10;
      cout << "? " << now-1 << endl;
      cin >> response;
    }
    result = now/10;
  }

  cout << "! " << result << endl;
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#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<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()


int main() {
    bool flag = true;
    int x, y;
    cin >> x >> y;
    int a2 = 4 * x - y;
    int b2 = y - 2 * x;
    if (a2 < 0 || a2 % 2) {
        flag = false;
    }
    if (b2 < 0 || b2 % 2) {
        flag = false;
    }
    cout << (flag ? "Yes" : "No") << endl;
}




Measured memory_bytes: 3636
n,m = list(map(int,input().split()))
a = list()
for i in range(0,n):
    a.append(list(map(int,input().split())))
a.sort()
count = 0
rest = 0
cost = 0
for i in range(0,n):
    count += a[i][1]
    if count >= m:
        rest = a[i][1]-(count - m)
        cost += a[i][0]*rest
        break
    else:
        cost += a[i][0]*a[i][1]
print(cost)

Measured memory_bytes: 27760
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
#include <math.h>
using namespace std ;
//using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	int n ; cin >> n ;
	int even = 0,odd = 0 ;
	for(int i=0;i<n;i++){
		int a ; cin >> a ;
		if(a&1) odd++ ;
		else even++ ;
	}
	cout << pow(3,n)-pow(2,even) << endl ;

}


Measured memory_bytes: 512
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        StringTokenizer st=new StringTokenizer(br.readLine());
        int[] a=new int[2*n];
        for(int i=0;i<2*n;i++){ a[i]=Integer.parseInt(st.nextToken()); }
        Arrays.sort(a);
        int sum=0;
        for(int i=0;i<2*n;i+=2){ sum+=Math.min(a[i],a[i+1]); }
        System.out.println(sum);
    }
}

Measured memory_bytes: 8404
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (int)(s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
constexpr long long INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}

int A,B,C,D,E,F,G,X,Y,Z,N,M,W;
string s,t;

signed main(){
	int N,M;
	cin>>N>>M;
	vector<int>a(N);
	REP(i,N)cin>>a[i];
	priority_queue<int>que;
	REP(i,N)que.push(a[i]);
	int ans = 0;
	REP(i,M){
		int t = que.top();
		que.pop();
		que.push(t/2);
	}
	REP(i,N){
		ans += que.top();
		que.pop();
	}
	cout << ans << endl;
}

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

using i64 = int64_t;

constexpr i64 MOD = 998244353;

i64 dp[302][90005]={0}, dp2[302][90005]={0};

i64 repeated_squaring(i64 x, i64 n) {
    i64 res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

int main(){
    int n;
    cin >> n;
    vector<i64> v;
    i64 sum = 0;
    for(int i=0;i<n;++i){
        i64 tmp;
        cin >> tmp;
        v.push_back(tmp);
        sum += tmp;
    }

    for(int i=0;i<=n;++i){
        for(int j=0;j<=sum;++j){
            dp[i][j] = 0;
            dp2[i][j] = 0;
        }
    }
    dp[0][0] = 1;
    for(int i=0;i<n;++i){
        for(int j=0;j<=sum;++j){
            if(dp[i][j] == 0)continue;
            dp[i+1][j+v[i]] += dp[i][j];
            dp[i+1][j+v[i]] %= MOD;
            dp[i+1][j] += 2*dp[i][j];
            dp[i+1][j] %= MOD;
        }
    }

    dp2[0][0] = 1;
    for(int i=0;i<n;++i){
        for(int j=0;j<=sum;++j){
            if(dp2[i][j] == 0)continue;
            dp2[i+1][j+v[i]] += dp2[i][j];
            dp2[i+1][j+v[i]] %= MOD;
            dp2[i+1][j] += dp2[i][j];
            dp2[i+1][j] %= MOD;
        }
    }

    i64 ans = repeated_squaring(3, n);
    i64 tmp = 0;
    for(int i=(sum+1)/2;i<=sum;++i){
        tmp += dp[n][i]*3 % MOD;
        tmp %= MOD;
    }
    ans -= tmp;
    ans = (ans + MOD) % MOD;
    if(sum%2 == 0){
        ans += dp2[n][sum/2]*3 % MOD;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 424320
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int h[n];
    for (int i=0;i<n;i++){
        cin>>h[i];
    }
    int mx = 0;
    int ans = 0;
    for (int i=0;i<n;i++){
        if (mx<=h[i]){
            ans++;mx=h[i];
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256