akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<utility>
#define rep(n) for(int i = 0;i < (n);i++)
int main(){
    int n,c=0,min;
    scanf("%d",&n);
    int a[n];
    rep(n) scanf("%d",&a[i]);
    for(int i = 0;i <= n-1;i++){
        min = i;
        for(int j = i; j <= n-1;j++)  if(a[min] > a[j]) min = j;
        if(i != min){
            std::swap(a[i],a[min]);
            c++;
        }
    }
    rep(n){
        if(i != n-1){
            printf("%d ",a[i]);
        } else{
            printf("%d\n",a[i]);
        }
    }
    printf("%d\n",c);
}



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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;

#define INF 		2000000007
#define MINF		-2000000007
#define MAX 		100005

const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//

vector<ll> fac(3001); //n!(mod M)
vector<ll> ifac(3001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

// agc132
int main(){
	int N,K;cin>>N>>K;

	fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<3000; i++){
        fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, MOD-2) % MOD; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }

	int REDNUM = N-K;
	REPS(i,1,K+1){
		ll RB = comb(REDNUM+1,i) % MOD;
		ll BSP = (((ll)fac[K-1]*ifac[K-i]%MOD)*ifac[i-1])%MOD;
		ll ans = ((ll)RB * BSP)%MOD;
		cout << ans << endl;
	}


	return 0;
}




Measured memory_bytes: 256
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(list(input()))
bomb = []
for i,h in enumerate(S):
    for j,r in enumerate(h):
        if r=="#":
            bomb.append((i, j))
        else:
            S[i][j]=0
for i,j in bomb:
    if 0<=i-1<=H-1 and 0<=j-1<=W-1 and S[i-1][j-1]!="#":
        S[i-1][j-1] += 1
    if 0<=i-1<=H-1 and 0<=j<=W-1 and S[i-1][j]!="#":
        S[i-1][j] += 1
    if 0<=i-1<=H-1 and 0<=j+1<=W-1 and S[i-1][j+1]!="#":
        S[i-1][j+1] += 1
    if 0<=i<=H-1 and 0<=j+1<=W-1 and S[i][j+1]!="#":
        S[i][j+1] += 1
    if 0<=i+1<=H-1 and 0<=j+1<=W-1 and S[i+1][j+1]!="#":
        S[i+1][j+1] += 1
    if 0<=i+1<=H-1 and 0<=j<=W-1 and S[i+1][j]!="#":
        S[i+1][j] += 1
    if 0<=i+1<=H-1 and 0<=j-1<=W-1 and S[i+1][j-1]!="#":
        S[i+1][j-1] += 1
    if 0<=i<=H-1 and 0<=j-1<=W-1 and S[i][j-1]!="#":
        S[i][j-1] += 1
for s in S:
    print("".join(list(map(str, s))))

Measured memory_bytes: 3188
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    long double a, b, x;
    cin >> a >> b >> x;
    double theta = atan2(a, b);
    long double up = M_PI / 2, low = 0;
    for(ll i = 0; i < 1e6; i++) {
        long double mid = (up + low) / 2;
        if(theta < mid) {
            long double area = a * (a * tan(M_PI / 2 - mid)) / 2 * a;
            if(a * a * b - area < x) low = mid;
            else up = mid;
        } else {
            long double mid = (up + low) / 2;
            long double area = b * (b * tan(mid)) / 2 * a;
            if(area < x) low = mid;
            else up = mid;
        }
    }
    cout << 90.0 - (low * 360 / (2 * M_PI)) << endl;
return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
//#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

int main() {
  vector<int> n;
  load(n, 4);
  sort(n);

  if (n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9) {
    p("YES");
  } else {
  	p("NO");
  }
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
mod=pow(10,9)+7
numbers=[]
num=0
for a in A:
    num+=a
    numbers.append(num)
ans=0
last=numbers[-1]
for n in range(N-1):
    number=numbers[n+1]-numbers[n]
    ans+=(number*(last-numbers[n+1]))
ans+=(A[0]*(last-A[0]))
ans=ans%mod
print(ans)


Measured memory_bytes: 101572
n = int(input())
a = list(map(int,input().split()))

start = 0
for i in range(0,n,2):
  if i == n-1:
    start += a[n-1]
    break
  start += a[i]-a[i+1]

ans = []
ans.append(start)
for i in range(1,n):
  ans.append(2*(a[i-1] - ans[i-1]//2))

l = [str(a) for a in ans]
l = " ".join(l)
print(l)


Measured memory_bytes: 19096
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3333;
bool is_ab[maxn];
int a[maxn], b[maxn];
bool active[maxn * 2];
int to[maxn];
int main(){
	int n; cin >> n;
	string s; cin >> s;
	vector<int> p[2];
	for(int i = 0; i < 2 * n; i++){
		p[s[i] - 'a'].push_back(i);
	}
	for(int i = 0; i < n; i++){
		a[i] = p[0][i];
		b[i] = p[1][i];
		is_ab[i] = a[i] < b[i];
	}
	vector<int> ab, ba;
	for(int i = n - 1; i >= -1; i--){
		if(i == -1 || !is_ab[i]){
			for(int j = 0; j <= i; j++) if(!is_ab[j]) ba.push_back(j);
			for(int j = i + 1; j < n; j++) if(is_ab[j]) ab.push_back(j);
			break;
		}
	}
	int len_ba = ba.size();
	vector<string> dp(len_ba + 1, "");
	for(int i = len_ba - 1; i >= 0; i--){
		dp[i] = dp[i + 1];
		to[i] = i;
		for(int j = i + 1; j < len_ba; j++){
			if(b[ba[i]] <= b[ba[j]] && b[ba[j]] <= a[ba[i]]) to[i] = max(to[i], to[j]);
		}
		string ival;
		vector<pair<int, char> > now;
		for(int j = i; j <= to[i]; j++){
			now.push_back({a[ba[j]], 'a'});
			now.push_back({b[ba[j]], 'b'});
		}
		sort(now.begin(), now.end());
		for(auto e : now) ival.push_back(e.second);
		ival += dp[to[i] + 1];
		dp[i] = max(dp[i], ival);
	}
	int len_ab = ab.size();
	vector<string> f(len_ab + 1, "");
	for(int i = len_ab - 1; i >= 0; i--){
		int nxt = len_ab;
		for(int j = i + 1; j < len_ab; j++) if(a[ab[j]] > b[ab[i]]){
			nxt = j;
			break;
		}
		f[i] = max(f[i + 1], "ab" + f[nxt]);
	}
	cout << dp[0] + f[0] << endl;
	return 0;
}


Measured memory_bytes: 15744
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
static const int MAX_N = 100000;

ll N, A, B;
ll X[MAX_N];

int main(void){
	cin >> N >> A >> B;
	for(int i = 0; i < N; i++){
		cin >> X[i];
	}
	ll sum = 0;
	for(int i = 0; i < N - 1; i++){
		sum += min((X[i + 1] - X[i]) * A, B);
	}
	cout << sum << endl;
	return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
//typedef unsigned long long uint;
typedef pair<long long, long long> pint;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;
typedef vector<long long> vint;
typedef vector<vint> vvint;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpint;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define mod 1000000007
#define M 1000006
# define N 100006
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, int m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
# define inf (ll)1e18
# define A 1000006

set<int>s;
bool ch(int x)
{
    while(x>0)
    {
        if(s.find(x%10)!=s.end())
            return false;
        x/=10;
    }
    return true;
}

int main()
{ 
    IOS;
   int k;
   cin >> k;
   int n;
   cin >> n;
   int a[n];
   for(int i=0;i<n;i++)
   {
      cin >> a[i];
      s.insert(a[i]);
   }

  int p=k;
   while(1)
   {
      if(ch(p))
      {
        cout << p;
        return 0;
      }
      p++;


   }


}

Measured memory_bytes: 256
#include <cstdio>

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

	int result[200001];
	for(int i = n; i > 0; i--) {
		result[i] = 0;
		for(int j = 2; i * j <= n; j++) {
			result[i] += result[i * j];
		}
		result[i] = result[i] % 2 == a[i] ? 0 : 1;
	}

	int m = 0;
	for(int i = 1; i <= n; i++) {
		m += result[i];
	}

	printf("%d\n", m);
	for(int i = 1; i <= n; i++) {
		if(result[i]) {
			printf("%d ", i);
		}
	}
	putchar('\n');

	return 0;
}

Measured memory_bytes: 2432
import java.math.*;
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigDecimal A = new BigDecimal(sc.next());
		BigDecimal B = new BigDecimal(sc.next());
		System.out.println(A.multiply(B).toBigInteger());
	}
}


Measured memory_bytes: 36028
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <tuple>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

using T = tuple<ll,ll>;
using Graph = vector<vector<T>>;

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

    ll a, b, c;
    cin >> a >> b >> c;

    if ((c-a-b > 0) && (4*a*b < (c-a-b)*(c-a-b)))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


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

using namespace std;

int min_cost(array<array<int, 10>, 10> &c, int n, int st,
             vector<vector<int>> &memo) {
  if (n == 1) {
    return 0;
  }

  if (memo[n][st] < 0) {
    int ans = -1;
    for (int i = 0; i <= 9; ++i) {
      if (st & (1 << i)) {
        continue;
      }

      int cost = min_cost(c, i, st | (1 << i), memo) + c[n][i];
      if (ans < 0 || cost < ans) {
        ans = cost;
      }
    }

    memo[n][st] = ans;
  }

  return memo[n][st];
}

int main(int argc, const char *argv[]) {
  int h, w;
  cin >> h >> w;

  array<array<int, 10>, 10> c;
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      cin >> c[i][j];
    }
  }

  vector<vector<int>> va(h, vector<int>(w)), memo(10, vector<int>(2048, -1));
  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> va[i][j];
      if (va[i][j] == -1) {
        continue;
      }

      ans += min_cost(c, va[i][j], 0, memo);
    }
  }

  cout << ans << '\n';
}

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

int main() {
  int N, x;
  cin >> N;
  x=0;
  vector<int> vec(N);
  for (int i=0;i<N;i++) {
    cin >> vec.at(i);
  }
  for (int i=1;i;i++) {
    for (int j=0;j<N;j++) {
      if (vec.at(j)%2==0) {
        vec.at(j)/=2;
        continue;
      }
      i=-1;
      break;
    }
  x++;
  }
  cout << x-1 << endl;
}

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

using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const int inf = 1e9+7;
const int mod = 1e9+7;

int main(){
    string s,t;
    cin>>s>>t;

    ll ans=0;

    rep(i,s.size()){
        if(s[i]!=t[i])ans++;
    }

    cout<<ans<<endl;
}




Measured memory_bytes: 3912
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
#define ll long long

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


Measured memory_bytes: 3592
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c for j in range(b)] for i in range(a)]
def list3d(a, b, c, d): return [[[d for k in range(c)] for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e for l in range(d)] for k in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10**9)
INF = 10**19
MOD = 10**9 + 7
EPS = 10**-10

K = INT()
ans = 'ACL' * K
print(ans)


Measured memory_bytes: 9536
lis_1=[]
lis_2=[]
for i in range(4):
    a=int(input())
    lis_1.append(a)
lis_1.sort()
for i in range(4,6):
    a=int(input())
    lis_2.append(a)
lis_2.sort()
x=lis_1[-1]
y=lis_1[-2]
z=lis_1[-3]
s=lis_2[-1]
print(x+y+z+s)


Measured memory_bytes: 5596
#include<iostream>
using namespace std;
int main(void){
  int X,Y;
  cin>>X;
  cin>>Y;
  //1種類
  if(X*2==Y){
    cout<<"Yes";
    return 0;
  }else if(X*4==Y){
    cout<<"Yes";
    return 0;
  }
  int j=X-1;
  for(int i=1;i<X;i++){
    
      int sum=2*i+4*j;
      if(sum==Y){
	cout<<"Yes";
	return 0;
      }
      j--;
  }
  


  cout<<"No";
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
const double EPS=1E-8;
////////////////////////////////////////

ll f(ll a,ll b){
    if(a==b)return a;
    if(a>b)swap(a,b);
    if(a==0)return 0;
    ll k=(b-1)/a;
    return 2*k*a+f(b-k*a,a);
}

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    
    ll n,x;cin>>n>>x;
    ll ans=n+f(n-x,x);
    cout<<ans<<endl;
    
    return 0;
}

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

typedef long long ll;

int main(int argc, char* argv[])
{
  ll n,m;
  ll ans;
  
  std::cin >> n;
  std::cin >> m;

  if (n > m) {
    std::swap(n, m);
  }

  if (n == 1) {
    if (m == 1) {
      ans = 1;
    } else {
      ans = m - 2;
    }
  } else {
    ans = (n - 2) * (m - 2);
  }
  
  std::cout << ans << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

typedef struct { int parent; int sibling; int depth, height; int k; int c[2]; } TREE;
TREE tree[30];

void calc_depth(int node, int d)
{
	int i;
	tree[node].depth = d;
	for (i = 0; i < tree[node].k; i++) calc_depth(tree[node].c[i], d+1);
}

int calc_height(int node)
{
	int i, h, t;

	h = 0;
	for (i = 0; i < tree[node].k; i++) {
		if ((t = calc_height(tree[node].c[i])+1) > h) h = t;
	}
	tree[node].height = h;
	return h;
}

int main()
{
	int n, i, id;
	int root, left, right;

	n = in();
	for (i = 0; i < n; i++) {
		id = in(), left = in(), right = in();
		if (left < 0 && right < 0) tree[id].k = 0;
		else if (left >= 0 && right >= 0) {
			tree[id].k = 2;
			tree[id].c[0] = left, tree[id].c[1] = right;
			tree[left].parent = id+1;
			tree[left].sibling = right+1;
			tree[right].parent = id+1;
			tree[right].sibling = left+1;
		} else {
			if (left < 0) left = right;
			tree[id].k = 1;
			tree[id].c[0] = left;
			tree[left].parent = id+1;

		}
	}
	for (root = 0; root < n; root++) {
		if (tree[root].parent == 0) break;
	}
	calc_depth(root, 0);
	calc_height(root);

	for (i = 0; i < n; i++) {
		printf("node %d:", i);
		printf(" parent = %d,", tree[i].parent-1);
		printf(" sibling = %d,", tree[i].sibling-1);
		printf(" degree = %d,", tree[i].k);
		printf(" depth = %d,", tree[i].depth);
		printf(" height = %d,", tree[i].height);
		if (i == root)          printf(" root");
		else if (tree[i].k == 0) printf(" leaf");
		else                    printf(" internal node");
		putchar('\n');
	}
	return 0;
}



Measured memory_bytes: 2144
#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>

using namespace std;

vector<int>a;

bool dp[2][5005][5005];

int main() {

	int N, K;

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

	int i,j;

	for (i = 0; i < N; i++) {
		int b;
		scanf(" %d", &b);
		if (b < K) {
			a.push_back(b);
		}
	}

	sort(a.begin(),a.end());

	int left = 0; 
	int right = a.size();

	int cnt = 0;

	while (left<right) {

		int mid = (left + right) / 2;

		fill(dp[0][0], dp[2][0], false);

		for (i = 0; i <= a.size(); i++) {
			dp[0][i][0] = true;
			dp[1][i][0] = true;
		}
		for (i = 0; i < mid; i++) {
			for (j = 0; j < K; j++) {
				if (j - a[i] >= 0) {
					dp[0][i + 1][j] = (dp[0][i][j] | dp[0][i][j - a[i]]);
				}
			}
		}
		for (i = mid+1; i < a.size(); i++) {
			for (j = 0; j < K; j++) {
				if (j - a[i] >= 0) {
					dp[1][i + 1][j] = (dp[1][i][j] | dp[1][i][j - a[i]]);
				}
			}
		}
		int flag = 0;

		if (cnt == -1) {

			cout << a[mid] << "は使わない" << endl;
			for (i = K - a[mid]; i < K; i++) {
				cout << "和を" << i << "にしたい" << endl;
				if (flag == 1) { break; }
				for (j = 0; j <= i; j++) {
					if (dp[0][mid][j]) {
						cout << a[mid] << "未満で" << j << "は作れる" << endl;
					}
					else {
						cout << a[mid] << "未満で" << j << "は作れない" << endl;
					}
					if (dp[1][a.size()][i - j]) {
						cout << a[a.size() - 1] << "以下で" << i - j << "は作れる" << endl;
					}
					else {
						cout << a[a.size() - 1] << "以下で" << i - j << "は作れない" << endl;
					}
					if (dp[0][mid][j] && dp[1][a.size()][i - j]) {
						flag = 1;
						break;
					}
				}
			}
		}
		else {
			for (i = K - a[mid]; i < K; i++) {
				if (flag == 1) { break; }
				for (j = 0; j <= i; j++) {
					if (dp[0][mid][j] && dp[1][a.size()][i - j]) {
						//cout << "確実に" << i << "は作れる" << endl;
						flag = 1;
						break;
					}
				}
			}
		}

		if (flag == 0) {
			left = mid + 1;
		}
		else {
			right = mid;
		}
		cnt++;
	}

	printf("%d\n",left);


	return 0;
}

Measured memory_bytes: 49280
using System;

public class Test
{
	public static void Main()
	{
		int d, n;
		string[] line = Console.ReadLine().Split(' ');
		d = int.Parse(line[0]);
		n = int.Parse(line[1]);
		
		if(n==100)
		{
			n++;
			
			for(int i=0;i<d;i++)
			{
				n *= 100;
			}
		}
		else
		{
			for(int i=0;i<d;i++)
			{
				n *= 100;
			}
		}
		Console.WriteLine(n);
	}
}

Measured memory_bytes: 11092
#include<stdio.h>
int main(void)
{
	int n,m;
	long long int i;
	scanf("%d",&n);
	(1<=n)&&(n<=20);
	i=1;
	m=n;
	while(m!=1) {
		i=i*m;
		m=m-1;
	}
	printf("%lld\n",i);
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int r, c;
    cin >> r >> c;
    int n;
    cin >> n;
    vector<pair<int, int>> q;
    forn(i, 0, n) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        bool ok = true;
        ok &= (x1 == 0 || x1 == r || y1 == 0 || y1 == c);
        ok &= (x2 == 0 || x2 == r || y2 == 0 || y2 == c);
        if (!ok) continue;
        if (x1 == 0) {
            q.eb(y1, i);
        } else if (y1 == c) {
            q.eb(x1 + c, i);
        } else if (x1 == r) {
            q.eb((c - y1) + c + r, i);
        } else {
            q.eb((r - x1) + c + c + r, i);
        }
        if (x2 == 0) {
            q.eb(y2, i);
        } else if (y2 == c) {
            q.eb(x2 + c, i);
        } else if (x2 == r) {
            q.eb((c - y2) + c + r, i);
        } else {
            q.eb((r - x2) + c + c + r, i);
        }
    }
    sort(all(q));
    set<int> used;
    stack<int> st;
    for (auto p : q) {
        if (used.count(p.sn)) {
            if (!st.empty() && st.top() == p.sn) st.pop();
            else {
                cout << "NO\n";
                return 0;
            }
        } else {
            used.insert(p.sn);
            st.push(p.sn);
        }
    }
    cout << "YES\n";
}


Measured memory_bytes: 6512
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int A = sc.nextInt();
		int B = sc.nextInt();

		sc.close();

		out.println(lcm(A, B));

	}

	// 最大公約数
	private static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	// 最小公倍数
	private static long lcm(long a, long b) {
		return (a / gcd(a, b)) * b; // a*bがオーバーフローしないように
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(){
    string s;
    cin>>s;
    for (int i=0; i<s.size(); i++) {
        if (i%2==0) {
            if (s.at(i)=='L') {
                cout<<"No"<<endl;
                return 0;
            }
        }else{
            if (s.at(i)=='R') {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin>>N;
  int a[N],b[N],c[N];
  rep(i,N){
    cin>>a[i]>>b[i]>>c[i];
  }
  int dp[N][3];
  rep(i,N){
    rep(j,3){
      dp[i][j]=0;
    }
  }
  dp[0][0]=a[0];
  dp[0][1]=b[0];
  dp[0][2]=c[0];
  rep(i,N-1){
    dp[i+1][0]=max(dp[i][1]+a[i+1],dp[i][2]+a[i+1]);
    dp[i+1][1]=max(dp[i][0]+b[i+1],dp[i][2]+b[i+1]);
    dp[i+1][2]=max(dp[i][1]+c[i+1],dp[i][0]+c[i+1]);
  }
  cout<<max(dp[N-1][0],max(dp[N-1][1],dp[N-1][2]))<<endl;;
}
  


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

int main(){
  string S;
  cin >> S;

  int64_t ans= 0;
  int64_t offset= 0;
  for(size_t i=0; i<S.size(); i++){
    if(S.at(i)=='W'){
      ans+= i- offset;
      offset++;
    }
  }

  cout << ans << endl;
}

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



int main() {
  ll X;
  cin>>X;
  ll y=100;
  ll ans;
  rep(i,i+1)
  {
    ans=i;
    y=y+y/100;
    if(y>=X)
    {
      break;
    }
  }
  cout<<ans+1<<endl;
  return 0;
}


Measured memory_bytes: 3640
match = ['eraser', 'erase', 'dreamer', 'dream']
len_m = [len(m) for m in match]
S = input()
n = len(S)
dp = [False] * (n + 1)
dp[0] = True
for i in range(1, n + 1):
    for w, word in zip(len_m, match):
        if S[i - w:i] == word and dp[i - w]:
            dp[i] = True
            break
print('YES' if dp[n] else 'NO')

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
using namespace std;


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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

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

	set<int> S;
	S.insert(a);
	S.insert(b);
	S.insert(c);

	cout << S.size() << endl;

	return 0;
}


Measured memory_bytes: 3628
parseInt(x) = parse(Int, x)

function main()
	n=readline() |> parseInt
	s = div(n,6)
	t = div(n,9)
	minim = 100000
	for i in 0:t
		count = 0
		x = i
		y = div(n-9*x,6)
		z = n-9*x-6*y
		count += z
		u=0
		v=0
		while 9^u<=x
			u+=1
		end
		while 6^v<=y
			v+=1
		end
		while x>0
			if 9^u<=x
				x-=9^u
				count += 1
			else
				u-=1
			end
		end
		while y>0
			if 6^v<=y
				y-=6^v
				count += 1
			else
				v-=1
			end
		end
		minim = min(count,minim)
	end
	print(minim)
end

main()

Measured memory_bytes: 109488
use std::io::*;
use std::str::*;
use std::cmp;

fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s.by_ref()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let s = stdin();
    let mut s = s.lock();
    let a: i32 = read(&mut s).unwrap();
    let b: i32 = read(&mut s).unwrap();
    let c: i32 = read(&mut s).unwrap();

    let large = cmp::max(cmp::max(a, b), c);
    let small = cmp::min(cmp::min(a, b), c);
    let middle = (a + b + c) - (large + small);

    let diff1 = large - middle;
    let diff2 = middle - small;

    if (diff2 % 2) == 0 {
        println!("{}", diff1 + diff2 / 2);
    } else {
        println!("{}", diff1 + diff2 / 2 + 2);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define ALL(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define COUT(x) cout << (x) << endl
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}
template<typename T>
T gcd(T x, T y){
    if ((x==1)||(y==1)) return 1;
    if (x>y) {
        if (x%y==0) {
            return y;
        }else{
            return gcd(y, x%y);
        }
    }else{
        if (y%x==0) {
            return x;
        }else{
            return gcd(x, y%x);
        }
    }
}

int main() {
    IN(int, n);
    vector<ll> ji(n);
    vector<ll> ai(n);
    map<ll, ll> kazu;
    REP(i, n){
        IN(ll, a);
        ji[i] = i-a;
        ai[i] = i+a;
        kazu[ai[i]]++;
    }
    sort(ALL(ji));
    ll ans = 0;
    REP(i, n){
        ans += kazu[ji[i]];
    }
    COUT(ans);
}


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

// macros
#define overload_rep(_1, _2 ,_3 ,name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i < (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << setprecision(20);
    }
} iosetup;

// SOLVE
const int mx = 100000;
vector<int> graph[mx * 2];
bool visited[mx * 2];
long long xcnt, ycnt;

void dfs(int v){
    if(visited[v])return;
    visited[v] = true;
    if(v < mx)xcnt++;
    else ycnt++;
    for(int u : graph[v]){
        dfs(u);
    }
}

int main(){

    int N;
    cin >> N;
    rep(i, N){
        int x, y;
        cin >> x >> y;
        x--; y--;
        graph[x].push_back(y + mx);
        graph[y + mx].push_back(x);
    }

    long long ans = 0;
    rep(i, mx){
        if(!visited[i]){
            xcnt = ycnt = 0;
            dfs(i);
            ans += xcnt * ycnt;
        }
    }
    cout << ans - N << endl;
    return 0;

}

Measured memory_bytes: 10240
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Tasks
{
    public class C
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = Scanner.Scan<long>();
            var builder = new StringBuilder();
            while (N > 0)
            {
                builder.Append((char)('a' + ((N - 1) % 26)));
                N = (N - 1) / 26;
            }

            var answer = builder.ToString();
            answer = new string(answer.Reverse().ToArray());
            Console.WriteLine(answer);
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


Measured memory_bytes: 28400
#include <bits/stdc++.h>
using namespace std;
using sint = int64_t;

template<class T> T read() {
	T t;
	cin >> t;
	return t;
}

template<class T> vector<T> read_vector(sint n) {
	vector<T> vs;
	for (sint i = 0; i < n; ++i) {
		vs.push_back(read<T>());
	}
	return vs;
}

inline void write() {
}

template<class T> void write(T const& t) {
	cout << t;
}

template<class T> void write(vector<T> const& ts) {
	if (ts.size() > 0) {
		cout << ts[0];
	}
	for (size_t i = 1; i < ts.size(); ++i) {
		cout << ' ' << ts[i];
	}
}

template<class T, class... Args> void write(T const& t, Args const&... args) {
	cout << t << ' ';
	write(args...);
}

template<class... Args> void writeln(Args const&... args) {
	write(args...);
	cout << '\n';
}

int main() {
	ios_base::sync_with_stdio(false);
	cin .exceptions(ios_base::badbit | ios_base::failbit);
	cout.exceptions(ios_base::badbit | ios_base::failbit);
	cin .tie(nullptr);
	cout.tie(nullptr);
	cout.precision(16);
	void run();
	run();
	return 0;
}

void run() {
	auto A = read<sint>();
	auto B = read<sint>();
	for (sint i = 1; i <= 3; ++i) {
		if (A != i && B != i) {
			writeln(i);
			break;
		}
	}
}

Measured memory_bytes: 256
N = gets.strip.to_i
evidences = []
max = 0
N.times do
  e = gets.strip.to_i
  one = []
  e.times do
    one.push(gets.strip.split(' ').map(&:to_i))
  end
  evidences.push one
end

[0,1].repeated_permutation(N).each do |kase|
  next unless kase.any?{ |n| n == 1 }
  validated = false
  evidences.each_with_index do |e, i|
    e.each do |person, testimony|
      if kase[i] == 1 && kase[person - 1] != testimony
        validated = true
        break
      end
    end
    break if validated
  end
  next if validated
  sum = kase.inject(:+)
  max = sum if max < sum
end
puts max

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
constexpr int MX = 200005;
int n, a[MX], b[MX], ans;
int main(){
	scanf("%d", &n);
	rep(i,n) scanf("%d%d", a+i, b+i);
	sort(a, a+n);
	sort(b, b+n);
	if(n % 2) ans = b[n/2] - a[n/2] + 1;
	else ans = b[n/2-1] - a[n/2-1] + b[n/2] - a[n/2] + 1;
	printf("%d\n", ans);
}

Measured memory_bytes: 5388
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(n)]
c = [list(map(int, input().split())) for _ in range(m)]
ans = [0]*n

for i in range(n):
    l = float('inf')
    for j in range(m):
        ls = abs(s[i][0]-c[j][0]) + abs(s[i][1]-c[j][1])
        if l > ls:
            l = ls
            ans[i] = j+1
for i in ans:
    print(i)
            
        

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,k;
vi a,b;

int main(){
	cin>>n>>k;
	a=vi(n);
	b=vi(n+1);
	for(int i=0;i<n;i++) cin>>a[i];
	map<int,int> mp;
	int S=0;
	for(int i=1;i<=n;i++){
		(S+=a[i-1])%=k;
		b[i]=(S-i%k+k)%k;
	}
	mp[0]++;
	ll res=0;
	for(int i=1;i<=n;i++){
		if(i>=k) mp[b[i-k]]--;
		res+=mp[b[i]];
		mp[b[i]]++;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 11136
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str = Console.ReadLine ().Split (' ');

            int N = int.Parse (str[0]);

            str = Console.ReadLine ().Split (' ');
            long[] A = new long[N];

            for (int i = 0; i < N - 1; i++)
            {
                A[long.Parse (str[i]) - 1] += 1;
            }

            for (int i = 0; i < N; i++)
            {
                Console.WriteLine (A[i]);
            }

        }
    }

    class MyLibrary
    {

        // 自作の関数
        public static int MyFunction (int n)
        {
            return 0;
        }
    }
}

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

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

Measured memory_bytes: 256
import java.util.*;
 
class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if ((a * b) % 2 == 0){
      System.out.println("Even");
    }else{
      System.out.println("Odd");
    }
  }
}

Measured memory_bytes: 21588
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
#include <fstream>
#include<string.h>
#include <algorithm>
#include<math.h>
#include<vector>
#include <queue>
#include <deque> 
#define ll long long
#define M 1000000007 
#define MM 998244353
#define INF 4e18
using namespace std;

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*ll t,tcitr;
    cin>>t;
    tcitr=0;
    while(tcitr<t)
    {*/
        ll n,i,j,k=-1;
        cin>>n;
        ll a[n],b[n];
        for(i=0;i<n;i++)cin>>a[i];
        for(i=0;i<n;i++)cin>>b[n-1-i];
        ll l=0,r=-1;
        for(i=0;i<n;i++)
        {
            if(a[i]==b[i])
            {
                l=i;
                k=a[i];
                break;
            }
        }
        for(i=n-1;i>=0;i--)
        {
            if(a[i]==k && b[i]==k)
            {
                r=i;
                break;
            }
        }
        for(i=0;i<n;i++)
        {
            if(a[i]!=k && b[i]!=k && l<=r)
            {
                swap(b[i],b[l]);
                l++;
            }
        }
        if(l<=r)cout<<"No\n";
        else 
        {
            cout<<"Yes\n";
            for(i=0;i<n;i++)cout<<b[i]<<" ";
            cout<<"\n";
        }
        /*tcitr++;
    }*/
    return 0;
}


Measured memory_bytes: 6792
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define half 500000004
int a[3005];
long long dp[3005][3005];
int main()
{
	int n,q;
	scanf("%d%d",&n,&q);
	long long cnt=0;
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		for (int j=1;j<i;j++)
		{
			if (a[j]>a[i])
			dp[j][i]=1;
			if (a[j]==a[i])
			{
				dp[j][i]=half;
				cnt++;
			}
		}
	}
	for (int _=0;_<q;_++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		if (a>b)
		swap(a,b);
		vector<pair<pair<int,int>,long long> > upd;
		for (int i=1;i<a;i++)
		upd.push_back({{i,a},dp[i][b]});
		for (int i=a+1;i<b;i++)
		upd.push_back({{a,i},(1-dp[i][b]+mod)%mod});
		for (int i=b+1;i<=n;i++)
		upd.push_back({{a,i},dp[b][i]});
		for (int i=1;i<a;i++)
		upd.push_back({{i,b},dp[i][a]});
		for (int i=a+1;i<b;i++)
		upd.push_back({{i,b},(1-dp[a][i]+mod)%mod});
		for (int i=b+1;i<=n;i++)
		upd.push_back({{b,i},dp[a][i]});
		for (auto p:upd)
		dp[p.first.first][p.first.second]=half*(dp[p.first.first][p.first.second]+p.second)%mod;
		dp[a][b]=half;
	}
	int res=0,tmp=1;
	for (int i=1;i<=n;i++)
	{
		for (int j=i+1;j<=n;j++)
		res=(res+dp[i][j])%mod;
	}
	for (int i=0;i<q-1;i++)
	tmp=(tmp*2)%mod;
	printf("%d",(2LL*res*tmp%mod-cnt*tmp%mod+mod)%mod);
}

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

int main(){
  int x,y,size;
  int map[10][10]={};
  while(scanf("%d,%d,%d",&x,&y,&size)!=EOF){
    switch(size){
    case 3:
      if(x>1) map[x-2][y]++;
      if(x<8) map[x+2][y]++;
      if(y>1) map[x][y-2]++;
      if(y<8) map[x][y+2]++;
    case 2:
      if(x>0 && y>0) map[x-1][y-1]++;
      if(x>0 && y<9) map[x-1][y+1]++;
      if(x<9 && y>0) map[x+1][y-1]++;
      if(x<9 && y<9) map[x+1][y+1]++;
    case 1:
      map[x][y]++;
      if(x>0) map[x-1][y]++;
      if(x<9) map[x+1][y]++;
      if(y>0) map[x][y-1]++;
      if(y<9) map[x][y+1]++;
    }
  }
  int max=0;
  int clear=0;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      if(map[i][j]==0) clear++;
      if(max < map[i][j]) max= map[i][j];
    }
  }
  cout<<clear<<endl<<max<<endl;
  return 0;
}

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

int main(){
	int n,a,b,s=0,v=0;
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++) {
		v=i%10;
		v+=i/10%10;
		v+=i/100%10;
		v+=i/1000%10;
		v+=i/10000;
		if(v>=a && v<=b){
			s+=i;
		}
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,r) RFOR(i,0,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define lower(a,x) lower_bound(all(a), x) - a.begin();
#define COUNT(a,x)  upper_bound(all(a), x) - lower_bound(all(a), x);
#define MCOUNT(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x);
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end());
#define scan(x) scanf("%lld",&x);
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
typedef double D;
const ll inf = 5555555555555555555;
const ll mod = 1000000007;
const D pi = acos(-1);
const D eps = 1e-10;

ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool ok, flag;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111

ll sm[MAX];
int main(void) {
  cin >> n;
  vll a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  a.pb(0);
  sm[0] = a[0];
  rep(i, n - 1) sm[i + 1] = a[i + 1] + sm[i];
  rrep(i, n) {
	if (sm[i] * 2 >= a[i + 1]) ans++;
	else break;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

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

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
vint distT(100001, -1), distA = distT;
int N, u, v;
vvint graph(100001);

void initDist(int p, bool A, int d = 0)
{
    if (A)
    {
        if (distA[p] == -1)
            distA[p] = d;
    }
    else
    {
        if (distT[p] == -1)
            distT[p] = d;
    }

    for (auto &&i : graph[p])
    {
        if (A)
        {
            if (distA[i] == -1)
            {
                distA[i] = d + 1;
                initDist(i, A, d + 1);
            }
        }
        else
        {
            if (distT[i] == -1)
            {
                distT[i] = d + 1;
                initDist(i, A, d + 1);
            }
        }
    }
}
int main()
{

    cin >> N >> u >> v;
    u--;
    v--;
    int a, b;
    for (size_t i = 0; i < N - 1; i++)
    {
        cin >> a >> b;
        a--;
        b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    initDist(u, false);
    initDist(v, true);
    int ans = 1;
    if (graph[u] == vint{v})
    {
        ans = 0;
    }
    for (size_t i = 0; i < N; i++)
    {
        if (distT[i] < distA[i])
        {
            chmax(ans, distA[i] - 1);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 10368