akhauriyash/Code-Regression huggingface dataset:
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define pb puch_back
#define mk make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll n, k;

int main() {
  cin >> n >> k;

  if (k == 0) {
    cout << n*n << endl;
    return 0;
  }

  ll ans = 0;
  for (int b = k+1; b <= n; ++b) {
    ans += (n/b) * (b-k);
    if (n%b >= k) ans += (n%b)-k+1;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int d[6][2]={{2,3},{3,2},{-1,4},{2,-1},{5,1},{1,3}};
int main(void){
    while(1){
        string n;
        cin>>n;
        if(n=="#")break;
        int m=n.length();
        int now=0;
        for(int i=0;i<m;i++){
            now=d[now][n[i]-'0'];
            if(now==-1)break;
        }
        now==1 ? cout<<"Yes"<<endl : cout<<"No"<<endl;
    }
    return 0;
}

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

using namespace std;

vector<queue<int> > que;

void f0()
{
    int p1,p2;
    cin>>p1>>p2;

    que[p1].push(p2);
}

void f1()
{
    int p;
    cin>>p;

    if(!que[p].empty())
        cout<<que[p].front()<<endl;
}

void f2()
{
    int p;
    cin>>p;

    if(!que[p].empty()) que[p].pop();
}

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

    cin>>n>>q;

    que.resize(n);

    while(q--)
    {
        int op;
        cin>>op;

        switch(op)
        {
            case 0:f0();break;
            case 1:f1();break;
            case 2:f2();break;
        }
    }


    return 0;
}



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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void answer1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void answer2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void answer3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void answer(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i, j;
  //ll n,x;
  //cin >> n >> x;
  ll a, b, c,x,y;
  cin >> a >> b>>c>>x>>y;
  //string s; cin >> s;
  ll result =0;
  if(x<=y)
    result=min({x*2*c+(y-x)*b,a*x+y*b,y*2*c});
  else
    result=min({y*2*c+(x-y)*a,a*x+y*b,x*2*c});
  
  cout<<result<<endl;
  return 0;
}

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

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

    while (true) {
        int N, S;
        cin >> N >> S;
        if (N == 0 and S == 0) {
            break;
        }

        vector<vector<vector<LL>>> dp(110, vector<vector<LL>>(11, vector<LL>(1010, 0)));
        dp[0][0][0] = 1;
        FOR(d, 0, 101) {
            FOR(i, 0, dp[0].size()) {
                FOR(j, 0, dp[0][0].size()) {
                    if (dp[d][i][j] == 0) {
                        continue;
                    }
                    // not use
                    dp[d + 1][i][j] += dp[d][i][j];
                    // use
                    if (i + 1 < dp[0].size() and j + d < dp[0][0].size()) {
                        dp[d + 1][i + 1][j + d] += dp[d][i][j];
                    }
                }
            }
        }

        print(dp[101][N][S]);
    }

	return 0;
}


Measured memory_bytes: 12696
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cmath>
#include<bitset>
typedef long long ll;
#define PB	push_back
#define FOR(n)			for(int i = 0; i < n; ++i)
#define RFOR(n)			for(int i = n; i >= 0; --i)
#define FORR(start,end) for(int i = start; i < end; ++i)
#define COUT(n)			cout << n << " " << flush
#define vi(v)			vector<int> v
#define vii(v)			vector<pair<int,int>> v
#define pii(p)			pair<int,int> p
#define mii(m)			map<int, int> m
#define msi(m)			map<string, int, less<>> m
#define mmsi(m)			multimap<string, int, less<>> m
#define mkp(a,b)		make_pair(a,b)
#define ALL(obj)		obj.begin(), obj.end()
#define PI 3.141592
#define MOD 1e9+7
using namespace std;

void solve() {
	int n, r;
	cin >> n >> r;
	if (n < 10) {
		r += 100 * (10 - n);
	}
	cout << r << endl;
}

int main() {
	solve();
	return 0;
}

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


// k進数で表記した時の桁和
int digitSum(int num, int k){

	int sum = 0;

	while(num){

		sum += num % k;
		num /= k;
	}

	return sum;
}

int main(){

	int n;
	cin >> n;

	int ans = 1000000000;

	for(int six = 0; six <= n; ++six){
		
		int nine = n - six;

		ans = min(ans, digitSum(six, 6) + digitSum(nine, 9));

	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int max = 1;
		for (int i = 2; i <= 100; i++) {
			for (int j = 2; j < 10; j++) {
				int target = (int)Math.pow(i, j);
				if (target > x) {
					break;
				}
				if (target > max) {
					max = target;
				}
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 22612
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
count=0
for i in range(X+1,Y+1):
  if max(x)<i<=min(y):
    count+=1
if count==0:
  print("War")
else:
  print("No War")

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int gcd(int a, int b){
  if (a%b==0){
    return(b);
  }
  else{
    return(gcd(b,a%b));
  }
}


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


// int factorial(int n){
//   if(n == 0) return 1;
//   return n*factorial(n-1);
// }

// int divisor(int a){
//   int cnt = 0;
//   for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
//   return cnt;
// }

// int comb(int n, int k){
//   return fact(n) / (fact(n-k)*fact(k));
// }

int answer(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}






int main(){
  ll N;
  vector<ll> v;
  cin >> N;
  bool f = false;
  for(ll i = sqrt(N); i > 1; i--){
    if(N%i == 0){
      v.push_back(i);
      f = true;
      break;
    }
  }
  
  if(f) v[1] = N / v[0];

  if(!f) cout << N - 1 << endl;
  else cout << v[0] + v[1] - 2 << endl;





  
  return 0;
}







Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}


const ll MOD = (ll)1e9 + 7;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}

const int N = (1 << 16) + 7;
int dp[2][N];
int n, m, W;

void read() {
	int x, y, z;
	scanf("%d%d%d%d", &n, &x, &y, &z);
	m = x + y + z - 1;
	W = (1 << (x + y + z - 1)) ^ (1 << (y + z - 1)) ^ (1 << (z - 1));
}

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	read();
	dp[0][0] = 1;
	while(n--) {
		for (int i = 0; i <= (1 << m); i++)
			dp[1][i] = 0;
		dp[1][1 << m] = add(dp[1][1 << m], mult(dp[0][1 << m], 10));
		for (int mask = 0; mask < (1 << m); mask++) {
			for (int x = 1; x <= 10; x++) {
				int nmask = (mask << x) ^ (1 << (x - 1));
				if ((nmask & W) == W)
					nmask = 1 << m;
				else
					nmask &= (1 << m) - 1;
				dp[1][nmask] = add(dp[1][nmask], dp[0][mask]);
			}
		}
		for (int i = 0; i <= (1 << m); i++)
			dp[0][i] = dp[1][i];
	}
	printf("%d\n", dp[0][1 << m]);

	return 0;
}


Measured memory_bytes: 3708
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

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


	ll N = 0, K = 0;
	char c;
	while ((c = getchar_unlocked()) >= '0') N = N * 10 + c - '0';
	while ((c = getchar_unlocked()) >= '0') K = K * 10 + c - '0';

	int A[200001];
	int D2[200001];
	rep1(i, N) A[i] = getint();

	int d = 0;
	int p = 1;
	while (A[p] > 0) {
		D2[d] = p;
		int tugi = A[p];
		A[p] = -d++;
		p = tugi;
	}
	if (K > -A[p]) {
		ll k = K + A[p];
		k %= d + A[p];
		K = -A[p] + k;
	}
	printf("%d", D2[K]);

	Would you please return 0;
}

Measured memory_bytes: 3252
#include<bits/stdc++.h>
using namespace std;
#define ll int long long
#define mp make_pair
//#define for(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define N 1000000007
#define pq priority queue
#define pb push_back
#define mt make_tuple
#define prec(a) fixed<<setprecision(9)<<a
#define endl "\n"
#define fast_set s.max_load_factor(0.25);s.reserve(500);
int parity_check(int n)
{
	int par=n;
	par = par ^ (par >> 1); 
    par = par ^ (par >> 2); 
    par = par ^ (par >> 4); 
    par = par ^ (par >> 8); 
    par = par ^ (par >> 16); 
  
    if(par%2==1)
    {
    	return 1;
    }
    else
    {
    	return 0;
    }
    // true means odd parity
    // false means even parity
}
ll gcd(ll a,ll b)
{
	if(a==0)
	{
		return b;
	}
	return gcd(b%a,a);
}
ll lcm(ll a,ll b)
{
	ll pro=a*b;
	ll ans=gcd(a,b);
	pro=pro/ans;
	return pro;
}
ll fast_power(ll a,ll b,ll p)
{
	if(b==0)
	{
		return (1%p);
	}
	ll t=fast_power(a,b/2,p);
	ll ans=(t*t)%p;
	if(b%2)
	{
		ans=(ans*(a%p))%p;
	}
	return ans;
}
int lcs(string str1,string str2)
{
	int n=str1.length(),i,j;
	int m=str2.length();
	int dp[n+1][m+1]={0};
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=m;j++)
		{
			if(i==0||j==0)
			{
				dp[i][j]=0;
			}
			else if(str1[i-1]==str2[j-1])
			{
				dp[i][j]=1+dp[i-1][j-1];
			}
			else
			{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	return dp[n][m];
}
int main()
{
	fast;
	ll n,i,j,k;
	cin>>n;
	ll arr[n],save[n];
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
		save[i]=arr[i];
	}
	sort(arr,arr+n);
	map<ll,ll>m1,m2;
	for(i=0;i<n;i++)
	{
		m1[arr[i]]=i%2;
		m2[save[i]]=i%2;
	}
	int ans=0;
	for(i=0;i<n;i++)
	{
		if(m1[arr[i]]!=m2[arr[i]])
		{
			ans++;
		}
	}
	cout<<ans/2;
	return 0;
}//ontwnetwon


Measured memory_bytes: 14336
#include<stdio.h>
#include<math.h>


#define N 100
#define INFTY 10000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dijkstra(int,int*);

int M[N][N];

int main(void){
  int n,d[N];
  int u,k,v;
  int i,j;

  scanf(" %d",&n);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      M[i][j] = INFTY;
    }
  }
  
  for(i = 0; i < n; i++){
    scanf(" %d %d",&u,&k);
    for(j = 0; j < k; j++){
      scanf(" %d",&v);
      scanf(" %d",&M[u][v]);
    }
  }

  dijkstra(n,d);

  for(i = 0; i < n; i++){
    if(d[i] == INFTY){
      printf("%d %d\n",i,-1);
    }
    else{
      printf("%d %d\n",i,d[i]);
    }
  }
  
  return 0;
}

void dijkstra(int n, int *d){
  int mincost,color[N],p[N];
  int i,v,u=0;

  for(i = 0; i < n; i++){
    color[i] = WHITE;
    d[i] = INFTY;
  }

  d[0] = 0;
  p[0] = -1;

  while(1){
    mincost = INFTY;
    for(i = 0; i < n; i++){
      if(color[i] != BLACK && d[i] < mincost){
	mincost = d[i];
	u = i;
      }
    }

    if(mincost == INFTY) break;

    color[u] = BLACK;
    
    for(v = 0; v < n; v++){
      if(color[v] != BLACK && M[u][v] != -1){
	if(d[u]+M[u][v] < d[v]){
	  d[v] = d[u] + M[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    }
  }
}



Measured memory_bytes: 2112
N,K = map(int,input().split())
if K > (N-1)*(N-2)//2:
    print(-1)
else:
    edges = []
    for i in range(2,N+1):
        edges.append((1,i))
    cur = (N-1)*(N-2)//2
    if cur > K:
        for i in range(2,N+1):
            for j in range(2,N+1):
                if i > j:
                    edges.append((i,j))
                    cur -= 1
                    if cur == K:
                        break
            else:
                continue
            break
    print(len(edges))
    for i,j in edges:
        print(i,j)


Measured memory_bytes: 74424
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

typedef pair<int, string> P;
int n;
string s;

int main() {
  cin >> n;
  P p[n];
  for (int i=0; i<n; i++) {
    cin >> s;
    p[i] = P((int)s.size(), s);
  }
  // 全部の文字列に共通する文字を追加していって、最後に昇順に並び替えて出力
  sort(p, p+n);
  string ans = "";
  bool flag;
  for (int i=0; i<p[0].first; i++) {
    flag = true;
    for (int j=1; j<n; j++) {
      int cnt = 0;
      for (int k=0; k<p[j].first; k++) {
        if (p[j].second[k] != p[0].second[i]) {
          cnt++;
        } else {
          p[j].second.erase(p[j].second.begin() + k);
          break;
        }
      }
      if (cnt == p[j].first) {
        flag = false;
        break;
      }
    }
    if (flag) ans += p[0].second[i];
  }
  sort(ans.begin(), ans.end());
  cout << ans << endl;
  return 0;
}


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

struct Node{
    int key;
    Node *p,*l,*r;//parent,left,rightの意味
};

Node *root,*NIL;//虚無nodeとrootnode

void insert(int v){//keyがvな節点を受け取る関数。
    Node *y=NIL;//親を設定する用
    Node *x=root;//rootを設定
    Node *z;//挿入するやつ
    z=(Node*)malloc(sizeof(Node));
    z->key=v;
    z->l=NIL;
    z->r=NIL;
    while(x!=NIL){//xがNIL、つまり葉になるまで続ける
        y=x;//一つ下へ向かう時に親を保存しておく
        if(z->key < x->key){
            x=x->l;//視点をxに
        }else{
            x=x->r;
        }
    }
    z->p=y;//以下で、親の方にも追加しないと。
    if(y==NIL){
        root=z;
    }else{
        if(z->key < y->key){
            y->l=z;
        }else{
            y->r=z;
        }
    }
}
void find(int k){
    Node *x=root;//こいつを下げていく
    while(x!=NIL){
        if(x->key==k){
            cout<<"yes"<<endl;return;
        }else if(k < x->key){
            x = x->l;
        }else{
            x = x->r;
        }
    }
    cout<<"no"<<endl;return;
}

//出力用関数を二つ用意
void preorder(Node *u){
    if(u==NIL)return;
    cout<<" "<<u->key;
    preorder(u->l);
    preorder(u->r);
}
void inorder(Node *u){
    if(u==NIL)return;
    inorder(u->l);
    cout<<" "<<u->key;
    inorder(u->r);
}

int main(){
    int n;cin>>n;
    string order;int v;
    for(int i=0;i<n;i++){
        cin>>order;
        if(order=="insert"){
            cin>>v;insert(v);
        }else if(order=="find"){
            cin>>v;find(v);
        }else{
            inorder(root);cout<<endl;
            preorder(root);cout<<endl;
        }
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

  int n;
  cin >> n;

  int sum = 0;
  vector<int> v(n), va(n);
  rep(i, n) {
    cin >> v[i];
    sum += v[i];
  }

  sort(all(v));

  int a = 0;
  rep(i, n) {
    if (v[i] % 10 != 0) {
      a = v[i];
      break;
    }
  }
  int b = ((sum - a) % 10 == 0 ? 0 : sum - a);
  int bb = (sum % 10 == 0 ? 0 : sum);

  cout << max(b, bb) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	A = A == 1 ? 14 : A;
	B = B == 1 ? 14 : B;
	cout << (A == B ? "Draw" : A > B ? "Alice" : "Bob") << endl;

	return 0;
}


Measured memory_bytes: 256
import numpy as np

N, M = map(int, input().split())
AC_or_not = np.array([0] * N)
n_penalty = np.array([0] * N)

for _ in range(M):
    prob, wa_ac = input().split()
    prob = int(prob) - 1
    if wa_ac == 'AC':
        AC_or_not[prob] = 1
    else:
        if not AC_or_not[prob]:
            n_penalty[prob] += 1

print(sum(AC_or_not), sum(n_penalty * AC_or_not))

Measured memory_bytes: 14808
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
 ll n;
 cin>>n;
 if(n==3){
     cout<<2<<" "<<3<<" "<<25<<"\n";
     return 0;
 }
 if(n==4){
     cout<<2<<" "<<3<<" "<<4<<" "<<9<<"\n";
     return 0;
 }
 V<ll> ans,two1,two2,th;
 ll t=1;
 while(t*2<=30000){
     if(t%3==1)two1.push_back(t*2);
     else if(t%3==2)two2.push_back(t*2);
     t++;
 }
 t=1;
 while(t*3<=30000){
     if(t%2)th.push_back(t*3);
     t++;
 }
 ll m=n;
 for(int i=0;i<min(two1.size(),two2.size());i++){
     if(m<=3)break;
     m-=2;
     ans.push_back(two1[i]);
     ans.push_back(two2[i]);
 }
 for(int i=0;i<th.size();i+=2){
     if(m<2)break;
     m-=2;
    ans.push_back(th[i]);
    ans.push_back(th[i+1]);
 }
  t=1;
 while(m--){
     if(t>5000)break;
     ans.push_back(t*6);
     t++;
 }
 for(int i=0;i<n;i++){
  cout<<ans[i]<<" ";
 }
 cout<<"\n";
}

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

int main()
{
    int r, c;

    while( cin >> r >> c )
    {
        if( r + c == 0 )
            break;
        
        if( r * c % 2 == 0 )
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }

    return 0;
}


Measured memory_bytes: 3008
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] num = new int[5];

        for(int i=0; i<5; i++){
            num[i] = sc.nextInt();
        }

        int wake = (num[2]-num[0])*60-num[1]+num[3];
        int ans = wake-num[4];
        System.out.println(ans);
    }
}

Measured memory_bytes: 35824
package main

import (
	"fmt"
)

// Game is one game.
type Game struct {
	pointA, pointB int
}

func main() {
	var n int
	game := &Game{0, 0}
	fmt.Scanf("%d", &n)
	for n != 0 {
		game.initGame()
		game.execGame(n)
		game.printResult()
		fmt.Scanf("%d", &n)
	}
}

func (game *Game) execGame(n int) {
	var a, b int
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a)
		fmt.Scanf("%d", &b)
		switch {
		case a == b:
			game.pointA += a
			game.pointB += b
		case a > b:
			game.pointA += a + b
		case b > a:
			game.pointB += a + b
		}
	}
}

func (game *Game) initGame() {
	game.pointA = 0
	game.pointB = 0
}

func (game *Game) printResult() {
	fmt.Println(game.pointA, game.pointB)
}



Measured memory_bytes: 2704
while True:
    try:
        n,m = list(map(int,input().split()))
        if n == 0 and m == 0:
            break
        amari = n % m
        yasai = list(map(int,input().split())) 
        yasai.sort()

        s = 0
        if amari > 0:
            s = sum(yasai[0:amari])

        i = 0
        for y in yasai[amari:]:
            if i % m > 0:
                s += y
            i+=1

        print(s)
    except:
        pass

Measured memory_bytes: 6784
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> s;
  rep(i, Size(s)) {
    if (s[i] == 'g') {
      if (cnt >= 1) {
        cnt--;
        ans++;
      } else {
        cnt++;
      }
    } else {
      if (cnt >= 1) {
        cnt--;
      } else {
        cnt++;
        ans--;
      }
    }
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#define N 100
void swap(int *,int *);

int main(){
  int flag,i,j,n,count=0,minj;
  int A[N];
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<=n-1;i++){
    minj = i;
    
    for(j=i;j<=n-1;j++){
      
      if (A[j] < A[minj]){
	minj = j;
      }

    }
    if(i!=minj){
    swap(&A[i],&A[minj]);
    count++;
    }
  }
  
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i<n-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

void swap(int *a,int *b){
  int temp;
  
  temp = *a;
  *a=*b;
  *b=temp;
}



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

int main() {
    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n) cin >> a.at(i);
    for (int r = k; r < n; r++) {
        if(a[r - k] < a[r]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 4032
import qualified Data.ByteString.Char8 as C
import Data.List

mdl = 10^9 + 7

t a b = a * b `mod` mdl

positivize x = if x < 0 then x + mdl else x

main :: IO ()
main = do
    [n,a,b] <- unfoldr (C.readInt . C.dropWhile (==' ')) <$> C.getLine
    let al = powMod 2 n - 1
    let na = chooseOpt n a
    let nb = chooseOpt n b
    print $ positivize $ (al - na - nb) `mod` mdl

powMod = powModAux 1
powModAux :: Int -> Int -> Int -> Int
powModAux ac cur 0 = ac
powModAux ac cur n
    | even n = powModAux ac            (t cur cur) (div n 2)
    | odd n  = powModAux (t cur ac)    (t cur cur) (div n 2)

chooseOpt n i = choose n (min (n-i) i)
    where
    choose n i = t (prod' [n-i+1..n] ) $ modInv $ (prod' [1..i])
    prod' = foldr t 1

modInv = (`powMod` (mdl-2))


Measured memory_bytes: 8204
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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

    int N;
    cin >> N;
    auto x = make_vec<double>(N);
    auto u = make_vec<double>(N);
    REP(i, N) {
        string s;
        cin >> x.at(i) >> s;
        if (s == "JPY") {
            u[i] = 1;
        } else if (s == "BTC") {
            u[i] = 380000.0;
        }
    }

    double sum = 0;
    REP(i, N) { sum += x[i] * u[i]; }
    cout << setprecision(10) << sum << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;


public class Main{
	
	public static void main(String... args) {
		Map<Integer, Integer> m = new HashMap<Integer, Integer>();
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextInt()) {
			int in = sc.nextInt(); if(in == 0) break;
			if(m.containsKey(in)) {
				m.put(in, m.get(in) + 1);
			}else m.put(in, 1);
		}
		sc.close();
		
		List<Integer> modes = findMode(m);
		Collections.sort(modes, new Comparator<Integer>() {
			@Override
			public int compare(Integer o1, Integer o2){
				if(o1 < o2) return -1;
				else if(o1 == o2) return 0;
				else return 1;
			}});
		
		for(int i: modes) System.out.println(i);
	}
	
	static <K> List<K> findMode(Map<K, Integer> map){
		List<K> result = new ArrayList<K>();
		int max_value = 0;
		for(Map.Entry<K, Integer> e: map.entrySet()) {
			if(e.getValue() > max_value) {
				result = new ArrayList<K>();
				result.add(e.getKey());
				max_value = e.getValue();
			}else if(e.getValue() == max_value) {
				result.add(e.getKey());
			}
		}
		return result;
	}
}

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

const int MAX_N = 100010;

const int inf = 2147483647;
int dat[MAX_N * 4];
int n;

void init(int n_){
    n = 1;
    while(n < n_) n *= 2; // 2のn乗に切り上げる
    // 全て inf で初期化したいとき
    for(int i = 0; i < n*2; i++){
        dat[i] = inf;
    }
    // 配列 a の要素で初期化したいとき
    // for(int i = n; i < n+n; i++){
    //     dat[i] = a[i-n];
    // }
    // for(int i=n-1; i>=1; i--){
    //     dat[i] = min(dat[i*2], dat[i*2+1]);
    // }
}

void update(int i, int x){
    i += n;
    dat[i] = x;
    while(i > 0){
        dat[i/2] = min(dat[i], dat[i^1]);
        i /= 2;
    }
}

int query(int a, int b, int i, int l, int r){
    if(r <= a || b <= l) return inf;
    if(a <= l && r <= b) return dat[i];
    return min(query(a,b,i*2,l,(l+r)/2), query(a,b,i*2+1,(l+r)/2,r));
}

int query(int a, int b){
    return query(a,b,1,0,n);
}

int main(){
    int n, q;
    while(cin >> n >> q){
        init(n);
        for(int i = 0; i < q; i++){
            char c;
            int x, y;
            cin >> c >> x >> y;
            if(c == '0'){
                update(x,y);
            } else {
                cout << query(x,y+1) << endl;
            }
        }
    }
}

Measured memory_bytes: 2188
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

typedef struct {
  vector<pair<uint32_t, uint32_t>> Node;
} TreeType;

static inline void MainTask() {
  uint32_t N;
  cin >> N;
  vector<uint32_t> u(N - 1), v(N - 1), w(N - 1);
  for (uint32_t i = 0; i < N - 1; ++i) cin >> u[i] >> v[i] >> w[i];
  vector<TreeType> Tree(N);
  for (uint32_t i = 0; i < N - 1; ++i) {
    Tree[u[i] - 1].Node.push_back(make_pair(v[i] - 1, w[i]));
    Tree[v[i] - 1].Node.push_back(make_pair(u[i] - 1, w[i]));
  }
  queue<uint32_t> NextNode;
  NextNode.push(0);
  uint32_t node;
  vector<uint32_t> res(N), achieve(N);
  for (auto itr = achieve.begin(); itr != achieve.end(); ++itr) *itr = 0;
  res[0] = 0;
  while (!NextNode.empty()) {
    node = NextNode.front();
    NextNode.pop();
    if (achieve[node]) continue;
    for (uint32_t i = 0; i < Tree[node].Node.size(); ++i) {
      NextNode.push(Tree[node].Node[i].first);
      if (Tree[node].Node[i].second & 0x01)
        res[Tree[node].Node[i].first] = 0x01 ^ res[node];
      else
        res[Tree[node].Node[i].first] = res[node];
    }
    achieve[node] = 1;
  }
  for (auto itr = res.begin(); itr != res.end(); ++itr) {
    cout << *itr << endl;
  }
}

int main() {
  MainTask();
  return 0;
}


Measured memory_bytes: 8448
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	if(65<=n&&n<=90){
		cout << 1 << endl;
	}
	else if(97<=n&&n<=122){
		cout << 2 << endl;
	}
	else{
		cout << 0 << endl;
	}
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define INF 100000000
typedef long long ll;

int main(){
    VL a(3);
    cin>>a[0]>>a[1]>>a[2];
    sort(a.begin(),a.end());
    //cout<<0+(a[2]-a[1])+(a[1]-a[0]);
    cout<<a[2]-a[0];
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    float height, result;
    float max =0;
    float min = 10000000000;
    
    while(scanf("%f", &height) != EOF){
        if(height>max){
            max = height;
        }
        if(height<min){
            min = height;
        }
    }
    printf("%g\n", max-min);
    return 0;
}

Measured memory_bytes: 644
import sys
from collections import deque

read = sys.stdin.buffer.read


def main():
    MOD = 1000000007
    N, *AB = map(int, read().split())
    G = [[] for _ in range(N)]
    for a, b in zip(AB[::2], AB[1::2]):
        G[a - 1].append(b - 1)
        G[b - 1].append(a - 1)

    stack = deque([0])
    order = []
    prev = [0] * N
    prev[0] = -1
    while stack:
        v = stack.pop()
        order.append(v)
        for nv in G[v]:
            if nv != prev[v]:
                stack.append(nv)
                prev[nv] = v

    pow2 = [0] * (N + 1)
    pow2[0] = 1
    for i in range(N):
        pow2[i + 1] = pow2[i] * 2 % MOD

    nodes = [1] * N
    numer = 0

    for v in reversed(order):
        if prev[v] != -1:
            nodes[prev[v]] += nodes[v]
        numer = (numer + pow2[N - 1] - pow2[N - nodes[v]]) % MOD
        for nv in G[v]:
            if nv != prev[v]:
                numer = (numer - pow2[nodes[nv]] + 1) % MOD

    denom = pow2[N]
    ans = (numer * pow(denom, MOD - 2, MOD)) % MOD
    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 75328
# 1文字目からi文字目までに何個ACがあるかを調べておき
# その情報を使い回す
n,q=map(int,input().split())
s=input()
AC=[0]*(n+1)

for i in range(n):
    if s[i:i+2]=="AC":
        AC[i+1]=AC[i]+1
    else:
        AC[i+1]=AC[i]    

for _ in range(q):
    l,r=map(int,input().split())
    print(AC[r-1]-AC[l-1])
    

Measured memory_bytes: 6060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1e9+1e7;

string s;

int main(int argc, char const *argv[]) {
	cin >> s;
	bool flag = false;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'C') flag = true;
		else if (flag && s[i] == 'F') {
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef pair<ll,ll> pl;
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()
//#define max(a,b) (a>b ? a : b)
//#define min(a,b) (a<b ? a : b)
 
const int MOD = 998244353;
const int INF = 100000002;
const double PI =4*atan(1);
const double eps = 1e-7;
const long long oo = 1e18;

int main(){
  vector<int> data = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  cout << data[K-1] << endl;
}

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

int main() {
  int h,w;
  cin >> h >> w;
  
  vector<string> s(h+2);
  for(int i=0; i<w+2; i++) {
    s.at(0) += ".";
    s.at(h+1) += ".";
  }
  for(int i=0; i<h; i++) {
    cin >> s.at(i+1);
    s.at(i+1) = "." + s.at(i+1) + ".";
  }
  
  for (int i=1; i<=h; i++) {
    for(int j=1; j<=w; j++) {
      if(s.at(i).at(j) == '#') cout << "#";
      else {
        int count = 0;
        if(s.at(i-1).at(j-1) == '#') count++;
        if(s.at(i-1).at(j) == '#') count++;
        if(s.at(i-1).at(j+1) == '#') count++;
        if(s.at(i).at(j+1) == '#') count++;
        if(s.at(i+1).at(j+1) == '#') count++;
        if(s.at(i+1).at(j) == '#') count++;
        if(s.at(i+1).at(j-1) == '#') count++;
        if(s.at(i).at(j-1) == '#') count++;
        cout << count;
      }
    }
    cout << endl;
  }
} 

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int gcd(int a, int b)
{
    int x = max(a, b),
        y = min(a, b);
    if (x % y)
        gcd(b, a % b);
    else
        return b;
}
int main()
{
    int n, k;
    cin >> n >> k;
    bool ans = false;
    int g = 0, M = 0;
    cin >> g;
    M = g;
    if (g == k)
        ans = true;
    repi(i, n, 1)
    {
        int a;
        cin >> a;
        M = max(M, a);
        if (k == a)
            ans = true;
        g = gcd(g, a);
        if (k % g == 0 & M >= k)
            ans = true;
    }
    if (ans)
        puts("POSSIBLE");
    else
        puts("IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N, K; cin >> N >> K;
    vec P(N); cin >> P;

    int ans = 1;
    set<int> s;
    REP(i, K) s.insert(P[i]);
    REP(i, N - K){
        if(!(*s.begin() == P[i] && s.lower_bound(P[i + K]) == s.end())) ans++;
        s.erase(P[i]);
        s.insert(P[i + K]); 
    }

    int i0 = 0, c = 0;
    P.pb(-INF);
    REP(i, N){
        if(P[i] > P[i + 1]){
            int l = i - i0 + 1;
            if(l >= K) c++;
            i0 = i + 1;
        }
    }
    if(c >= 2) ans -= (c - 1);
    Out(ans);


    return 0;
}


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

int mizu(vector<unsigned int> h) {
	if (h.empty()) {
		return 0;
	}
	else if (h.size() == 1) {
		return h.at(0);
	}

	vector<unsigned int> tmp;
	int res = 0;
	for (auto i : h) {
		if (i == 0) {
			if (!tmp.empty()) {
				res += mizu(tmp) + 1;
				tmp.clear();
			}
		}
		else {
			tmp.push_back(i-1);
		}
	}
	if (!tmp.empty()) {
		res += mizu(tmp) + 1;
	}
	return res;
}

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

	cout << mizu(h) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>

#define rep(i, n) for(int i = 0;i < (n);i++)
#define rrep(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)

using namespace std;
using ll = long long;

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;}

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


//////////////////////////////////////////////////



int main() {
    int n; cin >> n;
    vector<ll> a(n);

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

    deque<ll> d;
    d.push_back(a[0]);
    for (int i = 1; i < n; i++)
    {
        int b = lower_bound(d.begin(), d.end(), a[i]) - d.begin();
        if (b == 0) d.push_front(a[i]);
        else d[b-1] = a[i];
    }
    
    cout << d.size() << endl;
    
    return 0;
}


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

string s;
int main(){
    int R = 0, B = 0, ans = 0;
    cin >> s;

    for(int i = 0; s[i] != '\0' ; i++) {
	if(s[i] == '0')
	    R++;

	if(s[i] == '1')
	    B++;			
    }

    ans = 2*min(R, B);

    cout << ans << endl;
    
}



Measured memory_bytes: 512
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    n = INT()
    d = LIST()

    ans =  0

    for i in range(n-1):
        for j in range(i+1, n):
            ans += d[i] * d[j]

    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 5844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define SZ(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define fst first
#define snd second

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

const int INF = 1e9 + 47;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, W;
    cin >> n >> W;
    vector<int> w(n), v(n);
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> w[i] >> v[i];
        sum += v[i];
    }
    vector<ll> dp(sum + 1, INF); // dp[i] - minimum weight having value i
    dp[0] = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = sum; j >= v[i]; j--)
        {
            dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
        }
    }
    for (int i = sum; i >= 0; i--)
    {
        if (dp[i] <= W)
        {
            cout << i;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i <= 11; i++)
    {
        if (i * 1000 >= n)
        {
            cout << i * 1000 - n << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3664
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
import heapq
from sys import stdin
input = stdin.readline


class MaxHeapObj(object):
  def __init__(self, val):
    self.val = val

  def __lt__(self, other):
    return self.val > other.val

  def __eq__(self, other):
    return self.val == other.val

  def __str__(self):
    return str(self.val)


class MinHeap(object):
  def __init__(self, L=None):
    if L is None:
      self.h = []
    else:
      heapq.heapify(L)
      self.h = L

  def heappush(self, x):
    heapq.heappush(self.h, x)

  def heappop(self):
    return heapq.heappop(self.h)

  def __getitem__(self, i):
    return self.h[i]

  def __len__(self):
    return len(self.h)


class MaxHeap(MinHeap):
  def __init__(self, L=None):
    super(MaxHeap, self).__init__(list(map(lambda x: MaxHeapObj(x), L)))

  def heappush(self, x):
    heapq.heappush(self.h, MaxHeapObj(x))

  def heappop(self):
    return heapq.heappop(self.h).val

  def __getitem__(self, i):
    return self.h[i].val


def main():
  N, M = list(map(int, input().split()))
  A = list(map(int, input().split()))

  PQ = MaxHeap(A)

  while M:
    now = PQ.heappop()
    PQ.heappush(int(now/2))
    M -= 1

  sum_ = 0
  for x in PQ.h:
    sum_ += x.val
  print(sum_)


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 98776
def digit_sums(N: int) -> bool:
    s = 0
    temp = N
    while temp > 0:
        s += temp % 10
        temp //= 10
    return N % s == 0


if __name__ == "__main__":
    N = int(input())
    yes = digit_sums(N)
    print('Yes' if yes else 'No')


Measured memory_bytes: 2940