akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000007;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int dp[100001];

int main() {

	int n;
	int h[100001];

	cin>>n;
	rep(i,n){
		cin>>h[i];
	}
	dp[1]=abs(h[1]-h[0]);

	for(int i=2; i<n; i++){
		dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
	}
	cout<<dp[n-1]<<endl;

	return 0;
}


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

using namespace std;

#define Vi vector<int>
#define FOR(i,s,e) for (int i=s; i<e; i++)
#define ITER(v) v.begin(), v.end()

constexpr int N_MAX = 44;

int dp[N_MAX+1] = {};

int fib(int n) {
    if (n == 0 || n == 1) { return 1; }
    if (dp[n]) { return dp[n]; }
    int res = fib(n-1) + fib(n-2);
    dp[n] = res;
    return res;
}

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

    int n;
    cin >> n;
    cout << fib(n) << endl;

    return 0;
}

Measured memory_bytes: 3188
N,K=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N-1)]
mod=10**9+7
fac=[1,1]
for i in range(2,K+1):
    fac.append(fac[i-1]*i%mod)
ifac=[pow(i,mod-2,mod) for i in fac]
def perm(a,b):
    if b==0:
        return(1)
    if a<b:
        return(0)
    return(fac[a]*ifac[a-b]%mod)



data=[[] for i in range(N+1)]
for a,b in AB:
    data[a].append(b)
    data[b].append(a)

"""
for i in range(1,N):
    if len(data[i])==1:
        stack=[[i,0]]
        break"""
stack=[[1,0]]
visited=set([stack[0][0]])
count=K
while stack:
    a,m=stack.pop()
    c=0
    for p in data[a]:
        if not p in visited:
            visited.add(p)
            c+=1
            stack.append([p,1])
    if c:
        count=count*perm((K-2) if m else (K-1),c)%mod

print(count)


Measured memory_bytes: 58304
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 3e5 + 5;
const int logn = 19;
const lli inf = 1e18;

int n;
int a[maxn], b[maxn];
pii v[maxn];

lli f[maxn];

struct fenwick
{
    lli val[maxn];

    void init()
    {
        fill(begin(val), end(val), 0);
    }

    void update(int x, int k)
    {
        for(; x < maxn; x += x & -x)
            val[x] += k;
    }

    lli get(int x)
    {
        lli res = 0;
        for(; x > 0; x -= x & -x)
            res += val[x];
        return res;
    }

    lli get(int l, int r)
    {
        return get(r) - get(l - 1);
    }
};

fenwick cnt, sum;
fenwick rev_cnt, rev_sum;

void read_input()
{
    cin >> n;
    n *= 3;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
}

void init()
{
    f[0] = 0;
    for(int i = 1; i <= n; ++i) f[i] = f[i - 1] + a[i];
    for(int i = 1; i <= n; ++i)
        v[i] = pii(a[i], i);
    sort(v + 1, v + n + 1);
    for(int i = 1; i <= n; ++i)
        b[v[i].se] = i;
    cnt.init(); sum.init();
    rev_cnt.init(); rev_sum.init();
    for(int i = 1; i <= n; ++i)
    {
        rev_cnt.update(n - b[i] + 1, 1);
        rev_sum.update(n - b[i] + 1, a[i]);
    }

}

void solve()
{
    lli ans = -inf;
    for(int i = 1; i <= n; ++i)
    {
        cnt.update(b[i], 1);
        sum.update(b[i], a[i]);
        rev_cnt.update(n - b[i] + 1, -1);
        rev_sum.update(n - b[i] + 1, -a[i]);
        if(i < n / 3 || i > 2 * n / 3) continue;
        lli cur = f[i] - (f[n] - f[i]);
        int pre = 0, tmp1 = 0, tmp2 = 0;
        for(int k = logn - 1; k >= 0; --k)
            if(pre + (1 << k) <= n && cnt.get(pre + (1 << k)) <= i - n / 3)
            {
                cur -= sum.get(pre + 1, pre + (1 << k));
                tmp1 += sum.get(pre + 1, pre + (1 << k));
                pre += (1 << k);
            }
        pre = 0;
        for(int k = logn - 1; k >= 0; --k)
            if(pre + (1 << k) <= n && rev_cnt.get(pre + (1 << k)) <= n - i - n / 3)
            {
                cur += rev_sum.get(pre + 1, pre + (1 << k));
                tmp2 += rev_sum.get(pre + 1, pre + (1 << k));
                pre += (1 << k);
            }
        ans = max(ans, cur);
    }
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    init();
    solve();
}



Measured memory_bytes: 16640
#include  <iostream>

using namespace std;

int gcd(int a, int b){
  int temp;
  
  while( a % b != 0){
    temp = b;
    b = a % b;
    a = temp;
  }
  return b;
}

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

int main(void){
  int n;
  cin >> n;
  
  int ans = lcm(n,2);
  
  cout << ans << endl;
  return 0;
}
    

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

plus = []
minus = []
for i in a:
    if i >= 0: plus.append(i)
    if i < 0: minus.append(-i)
plus.sort(reverse=True)
minus.sort(reverse=True)

ans = 1
i, j = 0, 0
if n == k:
    if len(plus) % 2 == 1:
        ans *= plus[0]
        i += 1
    if len(minus) % 2 == 1:
        ans *= -minus[0]
        j += 1
if n != k and k % 2 == 1:
    if len(plus) != 0:
        ans = plus[0]
        i += 1
    else:
        minus.sort()
        ans = -minus[0]
        j += 1
while i + j != k:
    x_p = plus[i] * plus[i + 1] if i < len(plus) - 1 else 0
    x_m = minus[j] * minus[j + 1] if j < len(minus) - 1 else 0
    if x_p >= x_m and i != len(plus):
        ans = (ans * x_p) % mod
        i += 2
    else:
        ans = (ans * x_m) % mod
        j += 2
print(ans)


Measured memory_bytes: 31648
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>

using std::string;
using std::vector;
using std::map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << ' '; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  ui N{}, W{}; std::cin >> N >> W;
  vector<pair<ui, ui>> vp(N);
  for(auto& p : vp) cin >> p.first >> p.second;
  auto sum = boost::accumulate(vp, (ui)0, [](auto r, auto p){ return r + p.second; });

  vector<vector<ull>> dp(N + 1, vector<ull>(sum + 1, std::numeric_limits<ull>::max() / 3));
  dp[0][0] = 0;
  for(ui row = 1; row < dp.size(); ++row)
  {
    for(ui column = 0; column < dp[row].size(); ++column)
    {
      if(column >= vp[row - 1].second)
      {
        chmin(dp[row][column], dp[row - 1][column - vp[row - 1].second] + vp[row - 1].first);
      }

      chmin(dp[row][column], dp[row - 1][column]);
    }
  }

  ui ans{};
  for(ui column = 0; column < dp[N].size(); ++column)
  {
    if(dp[N][column] <= W) ans = column;
  }
  cout << ans << '\n';
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 80256
#include<stdio.h>

int main(void){
  int i,j,n,table[11][11],w;

  while(1){
    scanf("%d",&n);
    if(n==0)break;
    w=0;
    for(i=0;i<11;i++)
      table[n][i]=0;
    
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	scanf("%d",&table[i][j]);
	w+=table[i][j];
	if(j==n-1){
	  table[i][j+1]=w;
	  w=0;
	}
	table[n][j]+=table[i][j];
      }
    }

    for(i=0;i<n;i++){
      table[n][n]+=table[n][i];
}

    for(i=0;i<=n;i++){
      for(j=0;j<=n;j++){
	printf("%5d",table[i][j]);
	if(j==n)printf("\n");
      }
    }
  }

  return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int n, m; cin >> n >> m;
    priority_queue<int> que;
    rep(i, n) {
        int a; cin >> a;
        que.push(a);
    }
    rep(i, m) {
        int a = que.top();
        que.pop();
        que.push(a/2);
    }
    ll ans = 0;
    while(que.size()) {
        ans += que.top();
        que.pop();
    }
    cout << ans << '\n';
    return 0;
}

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

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

using namespace std;
const int INF = 1 << 30;
const long long MOD = 1000000000 + 7;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if (a.second != b.second) {
        return a.second < b.second;
    }
    else {
        return a.first < b.first;
    }
}

int main() {
	int N; cin >> N;
	vector<pair<long long, long long>> AB(N);
	rep(i, N) cin >> AB[i].first >> AB[i].second;
    sort(AB.begin(), AB.end(), compare_by_b);
    long long total = 0;
    rep(i, N) {
        total += AB[i].first;
        if (total > AB[i].second) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define N 1000003
#define LL long long
#define mod 998244353
#define P 31

int n,m;
int Hash[N],Pow[N];
char s[N];

inline int read(){
	int X=0,w=0;
	char ch=0;
	while (ch<'0' || ch>'9')
	  w|=ch=='-',ch=getchar();
	while (ch>='0' && ch<='9')
	  X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
	return w ? -X : X;
}

inline int query(int l,int r){
	int res=(Hash[r]-1ll*Pow[r-l+1]*Hash[l-1]%mod+mod)%mod;
	return res;
}

inline bool check(int len){
	for (int i=1;i+2*len-1<=n;i++){
		int l1=i,r1=i+len-1;
		for (int j=r1+1;j+len-1<=n;j++){
			int l2=j,r2=j+len-1;
			if (query(l1,r1)==query(l2,r2)) return 1; 
		}
	}
	return 0;
}

int main(){
	n=read();
	scanf("%s",s+1);
	Pow[0]=1;
	for (int i=1;i<=n;i++){
		Pow[i]=1ll*Pow[i-1]*P%mod;
		Hash[i]=(1ll*Hash[i-1]*P%mod+s[i]-'a')%mod;
	}
	int l=1,r=n,ans=0;
	while (l<=r){
		int mid=(l+r)/2;
		if (check(mid)){
			ans=mid;
			l=mid+1;
		}
		else r=mid-1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2304
#include<iostream>
using namespace std;
int main(){
    int n,k;
    int number = 1;
    cin >> n >> k;
    for(int i=0;i<n;i++){
        if(number * 2 < number + k){
            number = number * 2;
        }else{
            number = number + k;
        }
    }
    cout << number << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
N=[]
for i in range(n):
  N.append(list(map(int,input().split())))

for x,y,z in N:
  if x**2+y**2==z**2 or x**2+z**2==y**2 or z**2+y**2==x**2:
    print('YES')
  else:
    print('NO')


Measured memory_bytes: 5752
#include <stdio.h>

int main() {
    double x1, y1, x2, y2, xq, yq, m;

    while ((scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &xq, &yq)) != EOF) {
        x2 -= x1;
        y2 -= y1;
        xq -= x1;
        yq -= y1;
        m = (x2 * xq + y2 * yq) / (x2 * x2 + y2 * y2);
        printf("%.6lf %.6lf\n", x1 + 2*m*x2 - xq, y1 + 2*m*y2 - yq);
    }

    return 0;
}

Measured memory_bytes: 656
#include <bits/stdc++.h>
#define INF 1e+9
using namespace std;

int field[1005][1005],dp[1005][1005][16];

int get(int x,int k){
	return ((x >> k) & 1);
}

int num(int a,int b,int c,int d){
	return a + b * 2 + c * 4 + d * 8;
}

signed main(){
	int h,w;
	cin >> h >> w;
	for(int i = 0;i < h;i++){
		string s;
		cin >> s;
		for(int j = 0;j < w;j++){
			if(s[j] != '.') field[i + 1][j + 1] = s[j] - '0';
		}
	}
	for(int i = 0;i <= h;i++){
		for(int j = 0;j <= w;j++){
			for(int k = 0;k < 16;k++) dp[i][j][k] = INF;
		}
	}
	dp[1][1][0] = 0;
	for(int i = 1;i <= h;i++){
		for(int j = 1;j <= w;j++){
			for(int k = 0;k < 16;k++){
				int add = field[i + 1][j + 1] + field[i + 2][j];
				if(!get(k,1)) add += field[i + 1][j];
				if(!get(k,0)) add += field[i + 1][j - 1];
				dp[i + 1][j][num(0,0,1,get(k,2))] = min(dp[i + 1][j][num(0,0,1,get(k,2))],dp[i][j][k] + add - field[i + 2][j]);
				dp[i + 1][j][num(0,1,0,get(k,2))] = min(dp[i + 1][j][num(0,1,0,get(k,2))],dp[i][j][k] + add - field[i + 1][j + 1]);
				if(!get(k,0)) dp[i + 1][j][num(0,1,1,get(k,2))] = min(dp[i + 1][j][num(0,1,1,get(k,2))],dp[i][j][k] + add - field[i + 1][j - 1]);
				add = field[i + 1][j + 1] + field[i][j + 2];
				if(!get(k,2)) add += field[i][j + 1];
				if(!get(k,3)) add += field[i - 1][j + 1];
				dp[i][j + 1][num(get(k,1),1,0,0)] = min(dp[i][j + 1][num(get(k,1),1,0,0)],dp[i][j][k] + add - field[i][j + 2]);
				dp[i][j + 1][num(get(k,1),0,1,0)] = min(dp[i][j + 1][num(get(k,1),0,1,0)],dp[i][j][k] + add - field[i + 1][j + 1]);
				if(!get(k,3)) dp[i][j + 1][num(get(k,1),1,1,0)] = min(dp[i][j + 1][num(get(k,1),1,1,0)],dp[i][j][k] + add - field[i - 1][j + 1]);
			}
		}
	}
	int mi = INF;
	for(int i = 0;i < 16;i++) mi = min(mi,dp[h][w][i]);
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 70068
N = int(input())
A = list(map(int, input().split()))

rng = [[A[N], A[N]]]

for i in range(N - 1, -1, -1):
    merged = (rng[-1][0] + 1) // 2 + A[i]
    nonmerged = rng[-1][1] + A[i]
    rng.append([merged, nonmerged])
if rng[-1][0] > 1:
    print(-1)
    exit()
rng.reverse()
prev_non_leaf = 1
ans = 1
for i in range(1, N + 1):
    _, u = rng[i]
    ans += min(prev_non_leaf * 2, u)
    prev_non_leaf = prev_non_leaf * 2 - A[i]
print(ans)


Measured memory_bytes: 30144
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef vector<int> vi;
const int MX = 2e5 + 5;
#define f(i, x, n) for (int i = x; i < n; i++)
#define int long long
#define w(t) int t;cin>>t;while(t--)
#define pb push_back
#define endl "\n"
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    // online submission
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n,s{0};
    cin>>n;
    int a[n];
    f(i,0,n)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    f(i,0,n)
    {
        s+=(pow(-1,i)*a[i]);
    }
    cout<<s<<endl;

    return 0;
}


Measured memory_bytes: 3904
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
b[n//2] = a[0]
count = n//2
if n%2 == 0:
    for i in range(1,n):
        if i%2 == 1:
            count = count-i
        else:
            count = count+i
        b[count] = a[i]
else:
    for i in range(1,n):
        if i%2 == 1:
            count = count+i
        else:
            count = count-i
        b[count] = a[i]
print(*b)

Measured memory_bytes: 26180
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int M,N;
char c[555][555];
int y[33][2],x[33][2],num[33];
int del[33];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>M>>N;
	rep(i,M)cin>>c[i];
	vi ys,xs;
	memset(y,-1,sizeof(y));
	rep(i,M)rep(j,N){
		if(isupper(c[i][j])){
			int col = c[i][j] - 'A';
			y[col][num[col]] = i;
			x[col][num[col]] = j;
			num[col]++;
			rep2(d,-1,2){
				ys.pb(i+d);
				xs.pb(j+d);
			}
		}
	}
	int ans = 0;
	while(1){
		int flag = 0;
		//rep(yi,sz(ys))rep(xi,sz(xs)){
		rep(Y,M)rep(X,N){
			//int Y = ys[yi], X = xs[xi];
			if(Y<0 || M<=Y || X<0 || N<=X)continue;
			int ok = 1;
			rep(i,26)if(!del[i] && (Y == y[i][0] && X == x[i][0]
				|| Y == y[i][1] && X == x[i][1]))ok=0;
			if(!ok)continue;

			int left = -INF, right = INF, up = -INF, down = INF;
			int l=-1,r=-2,u=-3,d=-4;
			rep(i,26)if(y[i][0] != -1 && !del[i])rep(j,2){
				if(y[i][j] == Y){
					if(x[i][j] < X && x[i][j] > left){
						left = x[i][j];
						l = i;
					}
					if(x[i][j] > X && x[i][j] < right){
						right = x[i][j];
						r = i;
					}
				}
				if(x[i][j] == X){
					if(y[i][j] < Y && y[i][j] > up){
						up = y[i][j];
						u = i;
					}
					if(y[i][j] > Y && y[i][j] < down){
						down = y[i][j];
						d = i;
					}
				}
			}
			int focus[4] = {l,r,u,d};
			rep(i,4)rep2(j,i+1,4)if(focus[i] == focus[j]){
				ans += 2;
				del[focus[i]] = 1;
				flag = 1;
				//cout<<(char)(focus[i]+'A')<<endl;
			}
		}
		if(!flag)break;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1512
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

#define errp(...) fprintf(stderr, __VA_ARGS__)

int main () { 
	int k,s,ans=0;
	scanf("%d%d",&k,&s);
	for(int a=0;a<=k;a++) {
		for(int b=0;b<=k;b++){
			int c=s-(a+b);
			if(c<=k && c>=0)
				ans++;

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

}

Measured memory_bytes: 128
n=int(input())
a=list(map(int,input().split()))
b=[0]*n
e=0
for i in range(n):
    c=n-i
    d=0
    while c<=n:
        d+=b[c-1]
        c+=(n-i)
    if d%2!=a[n-i-1]:
        b[-i-1]+=1
        e+=1
print(e)
for i in range(n):
    if b[i]!=0:
        print(i+1,end=' ')


Measured memory_bytes: 8128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N;
  ll K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  vector<vector<int> > memo(N);
  vector<pair<int, int> > memo3(N);
  unordered_map<int, int> mp;
  vector<int> tmp;
  int tmpTop;
  int next;
  for(int i=N-1; i>=0; i--) {
    unordered_map<int, int>::iterator itr = mp.find(A[i]);
    if(itr == mp.end()) {
      if(i == N-1)
        next = -1;
      else
        next = i+1;
      tmpTop = A[i];
    } else {
      if(itr->second == N-1) {
        next = -1;
        tmpTop = -1;
      } else {
        next = memo3[itr->second+1].second;
        tmpTop = memo3[itr->second+1].first;
      }
    }
    memo3[i].first = tmpTop;
    memo3[i].second = next;
    mp[A[i]] = i;
  }
  vector<int> memo2;
  set<int> s;
  int tmp2 = 0;
  while(s.find(tmp2) == s.end()) {
    memo2.push_back(tmp2);
    s.insert(tmp2);
    if(tmp2 == N || memo3[tmp2] == make_pair(-1, -1)) {
      tmp2 = 0;
    } else {
      tmp2 = mp[memo3[tmp2].first]+1;
    }
  }
  int k = memo2.size();
  K--;
  K %= k;
  if(memo2[K] == N)
    cout << endl;
  else {
    tmp2 = memo2[K];
    while(memo3[tmp2].second != -1) {
      cout << memo3[tmp2].first << ' ';
      tmp2 = memo3[tmp2].second;
    }
    if(memo3[tmp2].first != -1)
      cout << memo3[tmp2].first << ' ';
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 26952
#include<unordered_map>
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<chrono>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long ll;
int main(){
	int a=0,b=0,c;
	for(int i=0;i<4;i++){
		cin>>c;
		a+=c;
	}
	for(int i=0;i<4;i++){
		cin>>c;
		b+=c;
	}
	cout<<max(a,b)<<endl;
}

Measured memory_bytes: 3080
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define rSort(a) 		sort(a.rbegin(),a.rend())
#define Sort(a) 		sort(a.begin(),a.end())
#define Reverse(a) 		reverse(a.begin(),a.end())
#define Sum(a)  		accumulate(a.begin(), a.end(), 0)
#define REP(i, n) 		for(UI i = 0;i < n;i++)
#define REPR(i, n) 		for(UI i = n;i >= 0;i--)
#define FOR(i, m, n) 	for(UI i = m;i < n;i++)
#define pb(i) 			push_back(i)

#define MOD  			(LL)1e9 + 7;
#define INF  			(LL)1 << 62;

int main(int argc, const char * argv[]) {

	cin.tie(0);
	ios::sync_with_stdio(false);

	LL A,B,T;

	cin >> A >> B >> T;

    cout << (T / A) * B << endl;

	return 0;

}




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

int main()
{

#ifdef _d
    freopen("input.txt", "r", stdin);
#endif

    int a;
    cin >> a;
    int sum = a;
    sum += a*a;
    sum += a*a*a;
    cout << sum << "\n";

    return 0;
}


Measured memory_bytes: 3592
#include <stdio.h>

int main(void) {
	long long ans = 0;
	int a[100000];
	int n, x;
	int i, sum;
	
	scanf("%d %d", &n, &x);
	
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		if (a[i] > x) {
			ans += a[i] - x;
			a[i] = x;
		}
	}
	
	for (i = 1; i < n; i++) {
		sum = a[i] + a[i - 1];
		if (sum > x) {
			ans += sum - x;
			
			if (a[i] < sum - x) a[i] = 0;
			else a[i] -= sum - x;
		}
	}
	
	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 512
S = input()

n = len(S)
x = [1] * n
for i in range(n):
    if S[i] == "R" and S[i + 1] == "R":
        x[i + 2] += x[i]
        x[i] = 0

for i in reversed(range(n)):
    if S[i] == "L" and S[i - 1] == "L":
        x[i - 2] += x[i]
        x[i] = 0
            
print(*x)


Measured memory_bytes: 73304
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
int cntDiv(int n){
	int ans = 0;
	for (int i= 1;i*i<=n;i+=2){
		if(n%i==0){
			if(i*i==n)ans++;
			else ans +=2;
		}
	}
	return ans;
}
string makeStr(char c,int num){
	string ans = "";
	REP(i,num){
		ans += c;
	}
	return ans;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int sx,sy,tx,ty,w,h;
	string ans = "";
	scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
	w = tx - sx;
	h = ty - sy;
	ans += string(h,'U');
	ans += string(w,'R');
	ans += string(h,'D');
	ans += string(w,'L');
	ans += 'L';
	ans += string(h+1,'U');
	ans += string(w+1,'R');
	ans += "DR";
	ans += string(h+1,'D');
	ans += string(w+1,'L');
	ans += 'U';

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


Measured memory_bytes: 256
#!/usr/bin/env python3
from itertools import product
MOD = 10**9 + 7
N = int(input())

A, G, C, T = range(4)
dp = [[[[0 for _ in range(4)] for _ in range(4)] for _ in range(4)]
      for _ in range(N + 1)]
dp[0][T][T][T] = 1
for k in range(N):
    for c0, c1, c2, c3 in product(range(4), repeat=4):
        if c1 == A and c2 == G and c3 == C: continue
        if c1 == G and c2 == A and c3 == C: continue
        if c1 == A and c2 == C and c3 == G: continue
        if c0 == A and c2 == G and c3 == C: continue
        if c0 == A and c1 == G and c3 == C: continue
        dp[k + 1][c1][c2][c3] += dp[k][c0][c1][c2]
        dp[k + 1][c1][c2][c3] %= MOD

ans = 0
for c0, c1, c2 in product(range(4), repeat=3):
    ans += dp[N][c0][c1][c2]
    ans %= MOD
print(ans)


Measured memory_bytes: 3444
n,a,b = map(int,input().split())

def sumketa(x):
  ctr = 0
  y = str(x)
  for j in range(len(y)):
    ctr = ctr + x % 10
    x = x // 10
  return ctr

def sumspe(n,a,b):
  ctr = 0
  for i in range(1,n+1):
    if(a<=sumketa(i)<=b):
      ctr+=i
  return ctr

print(sumspe(n,a,b))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define f(a,b,c,d) for(a=b; a<=c; a+=d)
#define fd(a,b,c,d) for(a=b; a>=c; a-=d)
#define readD(n) scanf("%d", &n)
#define readC(n) scanf("%c", &c)
#define readLLD(n) scanf("%lld", &n)
#define NMAX 100050
#define INF 999999999

using namespace std;

struct obiecte{
    int wei;
    int val;
};
obiecte O[NMAX];
long long int n, w, i, j, dp[105][NMAX];

int main(){
   readLLD(n); readLLD(w);
   f(i,1,n,1){
        readLLD(O[i].wei);
        readLLD(O[i].val);
        }
    f(i,1,n,1){
        f(j,1,w,1){
            dp[i][j] = dp[i-1][j];
            if(j - O[i].wei>=0)
                if(dp[i][j] < dp[i-1][j-O[i].wei] + O[i].val)
                    dp[i][j] =dp[i-1][j-O[i].wei] + O[i].val;
            }
        }
    printf("%lld", dp[n][w]);
   return 0;
   }


Measured memory_bytes: 79232
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
using LL = long long;

class Solution {
public:
	LL league(const vector<vector<int>>& A) {
		const int n = A.size();
		vector<vector<int>> adjLists(n * n);
		for (int i = 1; i <= n; ++i) {
			int prev = -1;
			for (int j : A[i - 1]) {
				const int playerX = i - 1, playerY = j - 1;
				int curr = min(playerX, playerY) * n + max(playerX, playerY);
				if (prev != -1) {
					adjLists[prev].push_back(curr);
#if 0
					cout << "depedency: " << prev / n << "," << prev % n << "->";
					cout << curr / n << "," << curr % n << endl;
#endif
				}
				prev = curr;
			}
		}

		vector<int> nIndegree(n * n);
		for (const auto& adjList : adjLists) {
			for (int u : adjList)
				++nIndegree[u];
		}

		queue<int> Q;
		for (int i = 0; i < n * n; ++i) {
			if (!nIndegree[i])
				Q.push(i);
		}

		int ans = 0, nMatched = 0;
		for (int depth = 1; !Q.empty(); ++depth) {
			for (int i = Q.size(); i > 0; --i) {
				const int u = Q.front();
				Q.pop();
				++nMatched;
				for (int v : adjLists[u]) {
					if (!--nIndegree[v])
						Q.push(v);
				}
			}
			ans = max(ans, depth);
		}
		if (nMatched < n * n)
			return -1; /* failed */
		return ans;
	}
};

int main() {
	int n;
	cin >> n;
	vector<vector<int>> A(n, vector<int>(n - 1));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n - 1; ++j)
			cin >> A[i][j];
	}

	Solution sol;
	LL ans = sol.league(A);
	cout << fixed << ans << endl;
	return 0;
}


Measured memory_bytes: 49152
N, A, B, C, D = gets.split.map(&:to_i)

n = N - 2
a, b = [A, B].minmax

n.times do |i|
  max = a - (i * C) + (n - i + 1) * D
  min = a - (i * D) + (n - i + 1) * C
  
  if min <= b && b <= max
    puts 'YES'
    exit
  end
end

puts 'NO'


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int k;
  cin >> k;
  vector<bool> used(k);
  int ans = 0;
  int cur = 7;

  while (true) {
    ans++;
    cur %= k;
    if (cur == 0) break;
    if (used[cur]) {
      cout << -1 << endl;
      return 0;
    }
    used[cur] = true;
    cur *= 10;
    cur += 7;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3724
#include<stdio.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
	int i,j,k,a,b,c,x,ans=0;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	for(i=0;i<=a;i++){
		for(j=0;j<=b;j++){
			for(k=0;k<=c;k++){
				if(i*500+j*100+k*50==x)
					ans++;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
MOD = int(1e9 + 7)

sizeI, sizeJ, targetJ = map(int, input().split())

validRows = [row for row in range(1 << (sizeJ - 1)) if '11' not in bin(row)]
# dp[i][j] - number of ways to come to position (i, j)
dp = [[0 for _ in range(sizeJ)] for _ in range(sizeI + 1)]
dp[0][0] = 1
for i in range(1, sizeI + 1):
    for j in range(sizeJ):
        for prevRow in validRows:
            if j - 1 >= 0 and (prevRow >> (j - 1)) & 1:
                dp[i][j] += dp[i - 1][j - 1]
            elif (prevRow >> j) & 1:
                dp[i][j] += dp[i - 1][j + 1]
            else:
                dp[i][j] += dp[i - 1][j]
            dp[i][j] %= MOD
print(dp[sizeI][targetJ - 1])

Measured memory_bytes: 3064
def min_cost(u, v, d)
  (0..1/0.0).each do |i|
    if (q = d - u * i) % v == 0
      return [i, (q / v).abs]
    end
  end
end

loop do
  a, b, d = gets.split.map(&:to_i)
  break if a == 0
  x1, y1 = min_cost(a, b, d)
  y2, x2 = min_cost(b, a, d)
  s1 = [x1, y1].join(' ')
  s2 = [x2, y2].join(' ')
  if x1 + y1 < x2 + y2
    puts s1
  elsif x1 + y1 > x2 + y2
    puts s2
  else
    puts x1 * a + y1 * b < x2 * a + y2 * b ? s1 : s2
  end
end

Measured memory_bytes: 8772
N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

score = 0
prev = -100
for i in A:
    score += B[i-1]
    if i == prev+1:
        score += C[prev-1]
    prev = i
print(score)

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

int main() {
	int n, a[100000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	int64_t s[100000];
	s[0] = a[0];
	for (int i = 1; i < n; i++) {
		s[i] = s[i - 1] + a[i];
	}
	int m = 1;
	for (int i = n - 2; i >= 0; i--) {
		if (2 * s[i] >= a[i + 1]) {
			m++;
		} else {
			break;
		}
	}
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <queue>
using namespace std;

#define pii pair<int, int>
#define mp make_pair
#define pb push_back

vector<vector<int> > to_edge;
const int mod = 1e9+7;
vector<vector<int> > dp;

void add_self(int& x, int y){
	x += y;
	if(x >= mod)
		x -= mod;
	return;
}
long long mul_self(long long x, long long y){
	if(y == 1)
		return x;
	long long temp = mul_self(x, y/2);
	if(temp >= mod)
		temp %= mod;
	temp = temp+temp;
	if(temp >= mod)
		temp %= mod;
	if(y%2 == 1)
		temp += x;
	if(temp >= mod)
		temp %= mod;
	return temp;
}

int func(int root, bool white);

int main(void){
	int n;
	cin >> n;
	to_edge.resize(n);
	for(int i = 0;i < n;i++){
		vector<int> temp(2, -1);
		dp.pb(temp);
	}
	vector<vector<int> > edges(n);
	for(int i = 0;i < n-1;i++){
		int x, y;
		cin >> x >> y;
		edges[x-1].pb(y-1);
		edges[y-1].pb(x-1);
	}
	int root = 0;
	queue<int> q;
	q.push(0);
	vector<bool> visited(n);
	while(!q.empty()){
		int temp = q.front();
		q.pop();
		visited[temp] = true;
		int size = edges[temp].size();
		for(int i = 0;i < size;i++){
			if(visited[edges[temp][i]] == true)
				continue;
			to_edge[temp].pb(edges[temp][i]);
			q.push(edges[temp][i]);
		}
	}
	int black = func(0, false);
	int white = func(0, true);
	add_self(white, black);
	cout << white << endl;
	return 0;
}

int func(int root, bool white){
	if(white){
		if(dp[root][0] != -1)
			return dp[root][0];
	}
	else
		if(dp[root][1] != -1)
			return dp[root][1];
	int child_size = to_edge[root].size();
	if(child_size == 0){
		if(white)
			dp[root][0] = 1;
		else
			dp[root][1] = 1;
		return 1;
	}
	long long ans = 1;
	for(int i = 0;i < child_size;i++){
		int child = to_edge[root][i];
		int temp = 0;
		if(white)
			temp = func(child, true) + func(child, false);
		else
			temp = func(child, true);
		add_self(temp, 0);
		ans = mul_self(ans, (long long)temp);
	}
	if(white)
		dp[root][0] = (int) ans;
	else
		dp[root][1] = (int) ans;
	return (int) ans;
}


Measured memory_bytes: 24112
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>

using namespace std;

int main()
{
	int pasta[3];
	int juice[2];

	cin >> pasta[0];
	cin >> pasta[1];
	cin >> pasta[2];
	cin >> juice[0];
	cin >> juice[1];

	sort(pasta, pasta + 3);
	sort(juice, juice + 2);

	cout << pasta[0] + juice[0] - 50 << endl;
	return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
 #define ll  long long int
 int ans=INT_MAX,x=INT_MAX,y=INT_MAX;
 int n;
 int dp[100001];
 int fn(int i,int a[])
 {
     if(i<=0)
    {dp[0]=0;
        return 0;
    }
     if(i==1)
    {  dp[1]=abs(a[1]-a[0]);
        return abs(a[1]-a[0]);
   
    }
   /* if(i==2)
    {
        dp[2]=min(abs(a[2]-a[0]),abs(a[1]-a[0])+abs(a[2]-a[1]));
        return dp[2];
    }*/
     if(dp[i]!=-1)
     return dp[i];
     
    x=min(fn(i-1,a)+abs(a[i]-a[i-1]),fn(i-2,a)+abs(a[i]-a[i-2]));
  /* x=fn(i-1,a)+abs(a[i]-a[i-1]);
   y=fn(i-2,a)+abs(a[i]-a[i-2]);
   ans=min(x,y);
   */
     dp[i]=x;
    // cout<<dp[i]<<" ";
   return x;
 }
int main(){

//int n;
cin>>n; 
int a[n];
for(int i=0; i<n; i++)
cin>>a[i];
for(int i=0; i<=n; i++)
dp[i]=-1;
 int ans=fn(n-1,a);
cout<<ans;
}

Measured memory_bytes: 4096
"use strict"

const main = (args) => {
    const { a, b, n } = parser(args);
    console.log(maxFloor(a, b, n));
}
const getInput = (isDebug) => {
    if (isDebug) {
    } else {
    }
}

const parser = (inputStr) => {
    const [aStr, bStr, nStr] = inputStr.split(' ');
    return {
        a: Number(aStr),
        b: Number(bStr),
        n: Number(nStr),
    };
}

const maxFloor = (a, b, n) => {
    if ( b - 1 < n ) {
        return Math.floor((a * (b - 1)) / b) - (a * Math.floor((b - 1) / b));
    } else {
        return Math.floor((a * n) / b) - (a * Math.floor(n / b));
    }
}
if (process.argv[2] === 'debug') {
    const Q1 = '5 7 4'
    const Q2 = '11 10 2000';
    main(Q1);
    main(Q2);
} else {
    main(require('fs').readFileSync('/dev/stdin', 'utf8'));
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e5;
const int MOD = 1e9+7;

int n, A[MAXN+10];
vector<int> V;

vector<int> pos[MAXN+10];
vector<pii> seg;

int dp[MAXN+10];

int main()
{
    int i, j;
    scanf("%d", &n);
    for(i=1; i<=n; i++) scanf("%d", &A[i]);

    V.push_back(0);
    for(i=1; i<=n; i++) if(A[i]!=A[i-1]) V.push_back(A[i]);
    n=V.size()-1;

    for(i=1; i<=n; i++) pos[V[i]].push_back(i);
    for(i=1; i<=MAXN; i++)
    {
        if(pos[i].size()<2) continue;
        for(j=1; j<pos[i].size(); j++) seg.push_back({pos[i][j], pos[i][j-1]});
    }
    sort(seg.begin(), seg.end());
    //for(i=0; i<seg.size(); i++) printf("%d %d\n", seg[i].second, seg[i].first);

    int p=0;

    dp[1]=1;
    for(i=2; i<=n; i++)
    {
        dp[i]=dp[i-1];
        for(; p<seg.size() && seg[p].first==i; p++)
        {
            dp[i]+=dp[seg[p].second];
            dp[i]%=MOD;
        }
        //printf("%d : %d\n", i, dp[i]);
    }
    printf("%d", dp[n]);
}


Measured memory_bytes: 13556
n,k,q = map(int,input().split())
a_list=[input() for i in range(q)]
a_list_int = [int(s) for s in a_list]
score_list = [k-q] * n
for i in range(len(a_list_int)):
    score_list[a_list_int[i]-1] += 1
for j in range(len(score_list)):
    if score_list[j] >= 1:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 16744
#include<bits/stdc++.h>
using namespace std;
 #define SPEED ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(0)
int main() 
{
	SPEED; 
	long long n,count=1;
    cin>>n;
    while(n>1)
    {
        n=n/2;
        count=count*2;
    }
    cout<<count+count-1;
      return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,d,s=0;
	cin>>a>>b>>c>>d;
	if(a>=b)
		s=s+b;
	else
		s=s+a;
	if(c>=d)
		s=s+d;
	else
		s=s+c;
	cout<<s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define MOD 1000000007
#define pb push_back
#define loop(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define loope(i, b) for (int i = 1; i <= (int)b; i++)
#define loopl(i, a, b) for (ll i = ll(a); i < (ll)b; i++)

int main()
{
    int n;
    cin >> n;
    int hei[n];
    loop(i, 0, n)
    {
        cin >> hei[i];
    }

    ll ans = 0;
    loop(i, 0, n - 1)
    {
        if (hei[i] > hei[i + 1])
        {
            ans += hei[i] - hei[i + 1];
            hei[i + 1] = hei[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4396
#include <iostream>
 
using namespace std;
 
int main()
{
    int n, m;
    cin >> n >> m;
    
    int s, c, ans = -1;
    int v[3] = {-1, -1, -1};
    for (int i = 0; i < m; i++) {
        cin >> s >> c;
        s--;
        if (v[s] != -1 && v[s] != c) goto fin;
        v[s] = c;
    }
 
    if (n == 1) {
        if (v[0] == -1) v[0] = 0;
        ans = v[0];
    } else {
        if (v[0] == 0) goto fin;
        if (v[0] == -1) v[0] = 1;
        ans = v[0];
        for (int i = 1; i < n; i++) {
            ans = 10 * ans + ((v[i] == -1) ? 0 : v[i]);
        }
    }

 fin: 
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

ll a, b, c, d, n;
ll ans;

int main()
{
  //  freopen("test.in","r",stdin);

    cin >> a >> b >> c >> d >> n;
    c = min(c, 2LL * b);
    c = min(c, 4LL * a);
    d = min(d, 2LL * c);

    ans = (n / 2) * d + (n % 2) * c;
    cout << ans;



    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;

ll s;
ll a[1000002];
ll ret;

void input(){
    cin >> s;
}

void solve(){
    a[1] = s;
    for(ll i=2;i<1000001;i++){
        if(a[i-1]%2 == 0){
            a[i] = a[i-1]/2;
        }else{
            a[i] = 3 * a[i-1] + 1;
        }
        for(ll j=1;j<i;j++){
            if(a[i] == a[j]){
                ret = i;
                return;
            }
        }
    }
}

int main(void){
    // Your code here!
    input();
    solve();
    cout << ret << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var NK = ReadSplitInt();
            var A = ReadSplitInt();
            var N = NK[0];
            var K = NK[1];

            var ans = 0;
            for (int i = 1; i < N; i+=K-1)
            {
                ans++;
            }
            Println(ans);
        }


        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 17632
import sys
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
l=[]
par=[-1]*n
def root(x):
    if par[x]<0:
        return x
    else:
        par[x]=root(par[x])
        return par[x]

def unite(x,y):
    x=root(x)
    y=root(y)
    if x==y:
        return
    if par[x]>par[y]:
        temp=x
        x=y
        y=temp
    par[x]+=par[y]
    par[y]=x
def size(x):
    x=root(x)
    return -par[x]
for a,b in l:
    unite(a,b)

for i in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    unite(x,y)
ans=max(map(size,range(n)))
print(ans)


Measured memory_bytes: 14676
#include <stdio.h>

int main(void)
{
	int l;
	int m[12];
	int n[12];
	int okane;
	int flag;
	int i;
	int tassei;
	
	while (1){
		
		scanf("%d", &l);
		
		if (l == 0){
			break;
		}
		
		okane = 0;
		flag = 0;
		
		for (i = 0; i < 12; i++){
			scanf("%d%d", &m[i], &n[i]);
			
			okane = okane + m[i] - n[i];
			
			if (okane >= l){
				if(flag == 0){
				tassei = i + 1;
				flag++;
				}
			}
		}
		
		if (flag == 0){
			printf("NA\n");
		}
		
		else{
			printf("%d\n", tassei);
		}
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {

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

    int res = max(a+b, a-b);
    res = max(res, a*b);

    cout << res << endl;

    return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace   std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define ull       unsigned long long
#define mod       1000000007
#define vi        vector<ll>
#define ppi       pair<ll,pair<ll,ll>>
#define pb        push_back
#define mp        make_pair
#define str       string
#define pi        2*acos(0.0)
#define pr(a,x,n) for(int i=x;i<n;i++){cout<<a[i]<<" ";}
#define p(a)      cout<<a;
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define e         cout<<'\n';
#define all(v)    v.begin(), v.end()
#define test      cout<<"BECOME_EXPERT_FAST"<<endl;
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
int32_t main() {
	kehsihba();
	str s;cin>>s;
	cout<<((s=="ABC")?"ARC":"ABC");
}







Measured memory_bytes: 3644
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
dp = [0]*(K+1)
for i in range(K+1):
    for a in [x for x in A if x <= i]:
        if dp[i-a] == 0:
            dp[i] = 1
            break
    
print('First' if dp[K] else 'Second')

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

const int INF = 100000000;

int binpow(int n, int k) {
    if (k == 0) return 1;
    if (k == 1) return n;
    if (k % 2 == 0) {
        int nn = binpow(n, k / 2);
        return nn*nn;
    }
    if (k % 2 == 1) {
        return n * binpow(n, k - 1);
    }
}

vector<int> d;

void solve() {
    int x, y, rr, gg, cc;
    cin >> x >> y >> rr >> gg >> cc;
    vector<int> r(rr), g(gg), c(cc);
    for (int i = 0; i < rr; ++i) {
        cin >> r[i];
    }
    for (int i = 0; i < gg; i++) {
        cin >> g[i];
    }
    for (int i = 0; i < cc; i++) {
        cin >> c[i];
    }
    sort(r.begin(), r.end(), greater<int>());
    sort(g.begin(), g.end(), greater<int>());
    sort(c.begin(), c.end(), greater<int>());
    vector<int> v;
    long long res = 0;
    for (int i = 0; i < x; i++) {
        v.push_back(r[i]);
        res += r[i];
    }
    for (int i = 0; i < y; i++) {
        v.push_back(g[i]);
        res += g[i];
    }
    sort(v.begin(), v.end());
    int cnt = 0;
    for (int i = 0; i < x + y && cnt < cc; i++) {
        if (c[cnt] > v[i]) {
            res += c[cnt] - v[i];
            cnt++;
        }
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 2552
#include<cstdio>
#include<map>
using namespace std;
map<int ,int >mp;
bool err;
int x,n,m;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		mp[x]++;
	}
	scanf("%d",&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&x);
		if(mp[x])
		{
			mp[x]--;
		}
		else
		{
			printf("NO\n");err=1;break;
		}
	}
	if(!err) printf("YES\n");
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  vector<int> S(2*M);
  for(int i=0;i<2*M;i++){
    cin>>S.at(i);
  }
  for(int i=0;i<N;i++){
    int count=0;
    for(int j=0;j<2*M;j++){
      if(i+1==S.at(j)) count++;
    }
    cout<<count<<endl;
  }
}

Measured memory_bytes: 256
#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);
  } 
    sort(vec.begin(), vec.end()); 
 
    for (int i = 0; i < N; i++) {
      for (int ii = i+1; ii < (N); ii++) {
       if (vec.at(i)==vec.at(ii)){
         vec.at(ii)= 0;
       }  
    }
    }
  int count =0;
   for (int i = 0; i < N; i++) {
      if (vec.at(i)!=0){
       count++;
       }  
   }
  cout << count << endl;
  
}

Measured memory_bytes: 3636