akhauriyash/Code-Regression huggingface dataset:
n=int(input())
s=0
k=0
ans=[]
if n==0:
  print(0)
while n!=0:
  if k%2==0:
    x=n%(2**(k+1))
    if x==0:
      ans.append('0')
    else:
      ans.append('1')
      n-=x
  else:
    x=n%(2**(k+1))
    if x==0:
      ans.append('0')
    else:
      ans.append('1')
      n+=x
  k+=1
print(''.join(ans)[::-1])

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

int main() {
    int n, k, q;
    scanf("%d %d %d", &n, &k, &q);
    vector<int> p(n+1);
    rep(i, q) {
        int a;
        scanf("%d", &a);
        p[a]++;
    }
    rep(i, n+1) {
        if (i == 0) continue;
        if (k - q + p[i] > 0) printf("Yes\n");
        else printf("No\n");
    }
}

Measured memory_bytes: 3764
n=int(input())
a=1
b=1
c=1
z=0
while a<=3500:
    b=a
    if z==1:
        break
    while b<=3500:
        d=4*a*b- b*n -a*n
        if  d > 0:
            c=a*b*n/(d)
            if int(c)==c:
                print(a, b, int(c)) 
                z=1
                break 
        b+=1
    a+=1



Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
  
using namespace std;
  
int main(void){
  int i,array[10];
  
  for(i=0;i<10;i++)  scanf("%d",&array[i]);
  sort(array,array+10);
  for(i=9;i>=7;i--)  printf("%d\n",array[i]);
  
  return 0;
}
 

Measured memory_bytes: 1044
import math

s=list(input().split('T'))
sn=[]

for i in range(len(s)):
    sn.append(len(s[i]))

x, y = map(int,input().split(' '))
x = x-sn[0]

snx=[]
sny=[]

for i in range(2,len(sn),2):
    snx.append(sn[i])

for i in range(1,len(sn),2):
    sny.append(sn[i])

#X軸判定
xflg = 0
ansx=[]
prex=[0]
tmpx=[0]
for i in range(len(snx)):
    tmpx=set()
    for j in prex:
        tmpx.add(j+snx[i])
        tmpx.add(j-snx[i])
    prex=tmpx

if x in tmpx:
    xflg = 1

#y軸判定
yflg = 0
prey=[0]
tmpy=[0]
for i in range(len(sny)):
    tmpy=set()
    for j in prey:
        tmpy.add(j+sny[i])
        tmpy.add(j-sny[i])
    prey=tmpy

if y in tmpy:
    yflg = 1

if xflg == 1 and yflg == 1:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3944
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
const ll infinity = 9e18;

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast


        
    int n,k;
    cin>>n>>k;

    int val,count = 0;
    forn(i,0,n)
    {
        cin>>val;
        if(val >= k) count++;
    }    


    cout<<count;









    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int b[300];
int n,m;
int g[300][300];
int main(){
	int a;
	while(scanf("%d",&a),a){
		scanf("%d",&n);
		m=a;
		for(int i=0;i<n;i++)scanf("%d",b+i+1);
		b[0]=b[n+1]=0;
		for(int i=0;i<n+2;i++)for(int j=0;j<n+2;j++)g[i][j]=0;
		for(int i=0;i<n+1;i++){
			for(int j=1;j<=m;j++){
				int to=i+j;
				if(to>n+1)to=n+1;
				to+=b[to];
				if(to>n+1)to=n+1;
				if(to<0)to=0;
				g[i][to]=1;
			}
		}
		for(int i=0;i<n+2;i++)g[i][i]=1;
		for(int k=0;k<n+2;k++)for(int i=0;i<n+2;i++)for(int j=0;j<n+2;j++)
			g[i][j]|=(g[i][k]&g[k][j]);
		bool ok=true;
		for(int i=0;i<n+1;i++)if(g[0][i]&&!g[i][n+1])ok=false;
		if(ok)printf("OK\n");
		else printf("NG\n");
	}
}

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

int main() {
  string s;
  cin >> s;
  int ans;
  for (int i = 1; i < s.size(); i++) { if (s[i] != s[i-1]) ans++; }
  cout << ans << endl;
}

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

int n,x,m;
int l[11],r[11],s[11];
vector<int> ans;
int anssum;

void rec(int d, vector<int> &v){
  if(d==n){
    for(int i=0;i<m;i++){
      int sum = 0;
      for(int j=l[i]-1;j<r[i];j++)sum += v[j];
      if(sum!=s[i])return;
    }
    int total = 0;
    for(int i=0;i<n;i++)total += v[i];
    if(total > anssum){
      anssum = total;
      ans = v;
    }
    return;
  }

  for(int i=0;i<=x;i++){
    v.push_back(i);
    rec(d+1,v);
    v.pop_back();
  }
}

int main(){

  cin >> n >> x >> m;
  for(int i=0;i<m;i++)cin >> l[i] >> r[i] >> s[i];

  vector<int> v;
  anssum = -1;
  rec(0,v);
  if(anssum<0)cout << "-1\n";
  else{
    for(int i=0;i<n;i++){
      cout << ans[i] << (i==n-1?"\n":" ");
    }
  }
}

Measured memory_bytes: 1220
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ff first
#define pii pair<int, int>
#define vii vector< pair<int,int> >
#define vi vector<int>
#define vvi vector< vector< int> >
#define ss second
#define MOD 998244353LL
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace4(x, y, z, d)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#d<<": "<<d<<endl

#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1, 0};int dy[]={0,1,0, -1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
bool compare(const pair<int,int> &a,
             const pair<int,int> &b)
{
    if(a.ff == b.ff) {
        return (b.ss < a.ss);
    }
    return (a.ff<b.ff);
}
int findlcm(int arr[], int n) 
{ 
    // Initialize result 
    int ans = arr[0]; 
  
    // ans contains LCM of arr[0], ..arr[i] 
    // after i'th iteration, 
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (__gcd(arr[i], ans))); 
  
    return ans; 
}
bool prime[1000001];
void SieveOfEratosthenes(int n) 
{
    // Create a boolean array "prime[0..n]" and initialize
    // aint entries it as true. A value in prime[i] wiint
    // finainty be false if i is Not a prime, else true.

    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
  }
}
int32_t main()
{
    IOS;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    /********************* From here ***********************/
    int n,k;
    string s;
    cin >>n >> k;
    
    cin >> s;
    s[k-1]  = s[k-1]+32;
    cout << s;	
}

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

int a[101]={0};

int main(){
	int n, x;
	cin >> n;  
	
	for (int i=1; i<=n; i++){
		cin >> x;
		a[x]=1;
	}
	
	int s=0;
	for(int i=1; i<=100; i++){
		if (a[i]==1) s++;
	}
	
	cout << s;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int boss=1e5;
int n,m,vis[boss+10];
vector<int> lj[boss+10];
int dfs(int u,int fa)
{
if (lj[u].size()>2) return u;
for (int i:lj[u]) if (i!=fa) return dfs(i,u);
return u;
}
int main()
{
int i,u,v;//
scanf("%d",&n);
for (i=1;i<n;i++) scanf("%d%d",&u,&v),u++,v++,lj[u].push_back(v),lj[v].push_back(u);
for (i=1;i<=n;i++) if (lj[i].size()==1) vis[dfs(i,0)]=1,m++;
for (i=1;i<=n;i++) if (vis[i]) m--;
printf("%d",max(m,1));
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define RREP(i,n) for(int i=int(n)-1; i>=0; i--)
#define FOR(i,f,t) for(int i=int(f); i<=int(t); i++)
#define RFOR(i,f,t) for(int i=int(f); i>=int(t); i--)
#define ALL(vec) (vec).begin(),(vec).end()
#define ASORT(vec) sort(ALL(vec))
#define DSORT(vec) sort(ALL(vec), greater<int>());
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define YES(ans) if(ans) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define Yes(ans) if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define yes(ans) if(ans) cout<<"yes"<<endl; else cout<<"no"<<endl;

int main() {
    int a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;
    ll l, m;
    l = abs(a-b);
    m = abs(v-w);
    bool f=true;
    if(v<=w) f = false;
    if(l>m*t) f = false;
    YES(f);
}


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

int main() {
  int sum = 0;
  string s;
  cin >> s;
  for (int i = 0; i < 4; i++) {
    char a = s[i];
    if (a == '+') sum++;
    else sum--;
  }
  cout << sum << endl; 
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void swap(int array[], int a, int b)
{
  int tmp = array[a];
  array[a] = array[b];
  array[b] = tmp;
}

int main(void)
{
  int w, n;
  char buf[6 + 1];
  char *num;
  int a, b, i, tmp;
  int lots[30];

  for (i = 0; i < 30; i++) {
    lots[i] = i + 1;
  }

  fgets(buf, sizeof(buf), stdin);
  w = atoi(buf);
  fgets(buf, sizeof(buf), stdin);
  n = atoi(buf);
  for (i = 0; i < n; i++) {
    fgets(buf, sizeof(buf), stdin);
    a = atoi(strtok(buf, ","));
    b = atoi(strtok(NULL, ","));

    swap(lots, a - 1, b - 1);
  }

  for (i = 0; i < w; i++) {
    printf("%d\n", lots[i]);
  }

  return 0;
}

Measured memory_bytes: 528
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;

ll n,v,u;
vec<vec<ll>> g(100010);
void dfs(ll now, ll pre,vec<ll> &depth){
    if(depth[now] != -1)return;
    depth[now] = depth[pre] + 1;
    for(auto next : g[now])dfs(next,now,depth);
    return;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> u >> v;
    --u; --v;
    rep(i,n-1){
        ll a,b; cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vec<ll>depth_a(n,-1),depth_t(n,-1);
    dfs(v,v,depth_a); dfs(u,u,depth_t);
    ll ans = 0;
    rep(i,n){
        if(depth_t[i] < depth_a[i])ans = max(ans,depth_a[i]);
    }
    --ans;
    cout << ans << endl;
}

Measured memory_bytes: 11264
package main

import (
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	idx, value int
	a, b       int
	index      int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func FactoredPrimeNumber(num int) map[int]int {
	m := map[int]int{}
	return factor(m, num, 2)
}

func factor(result map[int]int, num, pnum int) map[int]int {
	if pnum*pnum > num {
		if num != 1 {
			result[num] += 1
		}
		return result
	}

	if num%pnum == 0 {
		num /= pnum
		result[pnum]++
	} else {
		pnum++
	}
	return factor(result, num, pnum)
}

func GCD(a, b int) int {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

type P struct {
	l, r int
}

func main() {
	var X int
	fmt.Scanf("%d\n", &X)

	var A, B int
	for i := -118; i <= 119; i++ {
		for j := -119; j <= 118; j++ {
			AN := i * i * i * i * i
			BN := j * j * j * j * j
			if AN-BN == X {
				A = i
				B = j
				break
			}
		}
	}

	fmt.Printf("%d %d\n", A, B)
}

func Reverse(runes []rune) []rune {
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return runes
}


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

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        int b; cin>>b;
        a[b-1]=i+1;
    }
    for(int i=0;i<n;i++){
        cout<<a[i]<<' ';
    }
    cout<<endl;
    return 0;
}

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


int main()
{
    int n; string s;
    cin >> n >> s;
    vector<bool> v(n);
    for(int i = 0; i < 2; ++i) {
        for(int j = 0; j < 2; ++j) {
            v[0] = i;
            v[1] = j;
            for(int k = 2; k < n; ++k) v[k] = v[k-1] ^ v[k-2] ^ (s[k-1] == 'x');
            if(v[0] == (v[n-1] ^ v[n-2] ^ (s[n-1] == 'x')) && (v[1] == v[0] ^ v[n-1] ^ (s[0] == 'x'))) {
                for(bool b : v) cout << (b?'W':'S');
                cout << endl;
                return 0;
            }
        }
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int>B(N-1);
  for(int i=0; i<N-1; i++) cin >> B.at(i);
  
  int sum = B.at(0)+B.at(N-2);
  
  for(int i=1; i<N-1; i++){
    int curmin = min(B.at(i-1),B.at(i));
    sum+=curmin;
  }
  
  cout << sum << endl;
  
  
  
  
}


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

using namespace std;

int main(){
  int N,L; cin >> N >> L;
  vector<string> S(N); string T;
  for(int i = 0; i < N; i++){cin >> S[i];}
  sort(S.begin(),S.end());
  for(int i = 0 ; i < N; i++){
    T += S[i];}
 cout << T << endl;
  return 0;}
  

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

int main()
{
	int N;
	string S;
	cin >> N >> S;
	vector<int> B(N+1, 0);
	vector<int> W(N+1, 0);

	int black = 0, white = 0;
	for (int i = 0; i < N; i++) {
        if (S[i] == '#') {
			black++;
		}
		B[i + 1] = black;
		if (S[N - i - 1] == '.') {
			white++;
		}
		W[N - i - 1] = white;
	}

	int ans = 10e8;
	for (int i = 0; i <= N; i++) {
		ans = min(ans, B[i] + W[i]);
	}
	cout << ans << endl;	
}

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

const int64_t MOD = 1e9+7;
const int64_t MAX = 1e5;
const int64_t NMAX = 110;
int64_t dp[NMAX][MAX]; //i番目にjを使った時に何通りあるか？
 
int main(){
  int64_t N, K;
  cin >> N >> K;
  vector<int64_t> A(0);
  for(int i=1; i*i<=N; i++){
    if(i*i == N){
      A.push_back(i);
    }
    else{
      A.push_back(i);
      A.push_back(N/i);
    }
  }
  sort(A.begin(),A.end());
  int a = A.size();
  vector<int> num(a);
  for(int i=0; i<a; i++){
    if(i == 0){
      num[i] = 1;
    }
    else{
      num[i] = A[i] - A[i-1];
    }
  }
  
  vector<int64_t> sum(a);
  
  for(int i=0; i<a; i++){
    dp[0][i] = num[i];
    if(i == 0){
      sum[i] = dp[0][i];
    }
    else{
      sum[i] = sum[i-1] + dp[0][i];
      sum[i] %= MOD;
    }
  }
  

  
  for(int i=1; i<K; i++){
    vector<int64_t> Nsum(a);
    for(int j=0; j<a; j++){
      int idx = a - j - 1;
      dp[i][j] = sum[idx]*num[j];
      dp[i][j] %= MOD;
      Nsum[j] = dp[i][j];
    }
    for(int j=0; j<a; j++){
      if(j == 0){
        sum[j] = Nsum[j];
      }
      else{
        sum[j] = sum[j-1] + Nsum[j];
        sum[j] %= MOD;
      }
    }
  }
  
  cout << sum[a-1] << endl;
}

Measured memory_bytes: 54744
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <map>
#include <ctime>
#include <cstdlib>
#include <random>
using namespace std;

int main(){
	long long ans = 0;
	long long n;
	cin >> n;
	long long a, b;
	cin >> a >> b;
	ans = n / (a + b) * a;
	ans += min(n%(a+b), a);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
module DirectedGraph
  (* 道の表現 *)
  (Path : sig
    type t
    (* 辺の名前 *)
    type edge
    (* 長さ0の道 *)
    val nil : t
    (* 道の後ろに辺を付け足した道 *)
    val snoc : t -> edge -> t
  end) :
sig
  (* BFSにより，重みのないグラフの最短経路を求める *)
  val bfs :
    (* 頂点数（Hashtblを用いるので目安程度） *)
    int ->
    (* 辺の名前が付いた隣接リスト *)
    ('v -> ('v * Path.edge) list) ->
    (* 始点 *)
    'v ->
    (* 最短経路を返す関数 辿り着けなければNoneを返す） *)
    ('v -> Path.t option)
end = struct
  let rec bfs_aux es d frontier t =
    try Some (Hashtbl.find d t) with
    | Not_found ->
        match !frontier with
        | [] -> None
        | _ :: _ ->
            frontier := List.fold_right (fun u ->
              List.fold_right (fun (v, e) frontier ->
                if Hashtbl.mem d v
                then frontier
                else (Hashtbl.add d v (Path.snoc (Hashtbl.find d u) e); v :: frontier))
              (es u)) !frontier [];
            bfs_aux es d frontier t

  (*
   * 終点に辿り着いた時点で探索を切り上げるが，
   * 戻り値の関数を覚えておくと，途中まで探索した結果が再利用される
   * （#trace bfs_aux すると分かりやすい）
   *)
  let bfs n es s =
    let d = Hashtbl.create n in
    Hashtbl.add d s Path.nil;
    let frontier = ref [s] in
    bfs_aux es d frontier
end

(* 距離だけ欲しい場合 *)
module G = DirectedGraph (struct
  type t = int
  type edge = unit
  let nil = 0
  let snoc t _ = t + 1
end)

let () = Scanf.scanf "%d %d %d\n" @@ fun h w k ->
  let ass = Array.init h @@ fun _ -> Scanf.scanf "%s\n" @@ fun as_ -> as_ in
  let sy, sx =
    List.find (fun (y, x) -> ass.(y).[x] = 'S') @@
    List.concat @@ Array.to_list @@ Array.init h @@ fun y ->
      Array.to_list @@ Array.init w @@ fun x -> (y, x) in
  let d = G.bfs (h * w) (fun (i, j) ->
    List.map (fun ij -> (ij, ())) @@
    List.filter (fun (i, j) -> try ass.(i).[j] <> '#' with _ -> false)
    [(i - 1, j); (i + 1, j); (i, j - 1); (i, j + 1)]) (sy, sx) in
  Printf.printf "%d\n" @@ succ @@
  Array.fold_left (Array.fold_left min) max_int @@
  Array.init h @@ fun i ->
    Array.init w @@ fun j ->
      if
        match d (i, j) with
        | None -> true
        | Some d -> k < d
      then max_int
      else (min (min i j) (min (h - 1 - i) (w - 1 - j)) + k - 1) / k


Measured memory_bytes: 66684
// Ashish Agarwal @ashuag007
// references: geeksforgeeks

#include<bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
typedef long long ll;



int main(void)
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll a,b,c,d;
    cin>>a>>b>>c;
    d=b;
    if(c-b>0)
    {
        d+=b;
        c=c-b;
    }
    d+=min(a,c);
    if(c-a>0)
    d+=1;
    cout<<d<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL

struct Edge {
	int from, to;
	ll w;
};
typedef vector<vector<Edge>> Graph;

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


bool BellmanFord(Graph g, int s, vector<ll>& dis) { //is huheiro aru
#define INF 10000000000000LL
	fill(ALL(dis), INF);
	dis[s] = 0;
	REP(cc, g.size()*10) {

		REP(v, g.size()) {
			for (auto e : g[v]) {
				if (cc >= g.size() && e.to == g.size()-1 && dis[e.to] > dis[e.from] + e.w) return 1;
				dis[e.to] = min(dis[e.to], dis[e.from] + e.w);
			}
		}

	}


	return 0;
}

signed main(void) {

	ll x, y;

	cin >> x >> y;

	cout << (abs(x-y) > 1 ? "Alice" : "Brown") << endl;

	return 0;
}



Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int main() {

    int a, b;
    char op;

    int answer;
    
    while (1) {
        scanf("%d %c %d", &a, &op, &b);

        if (op == '+') {
            answer = a + b;
        } else if (op == '-') {
            answer = a - b;
        } else if (op == '*') {
            answer = a * b;
        } else if (op == '/') {
            answer = a / b;
        } else if (op == '?') {
            break;
        }

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

    }

    return 0;
}


Measured memory_bytes: 2756
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

int N, L;
vector<int> a;
vector<int> ans;
int n1, n2;

void rec(int l, int r, int res) {
  if (l >= r) {

    cout << "Possible" << endl;
    for (auto x : ans) {
      cout << x << endl;
    }
    return;
  }

  if (l != n1) {
    ans.push_back(l);
    rec(l + 1, r, res - a[l]);

  } else {
    ans.push_back(r - 1);
    rec(l, r - 1, res - a[r]);
  }
}

signed main() {
  cin >> N >> L;
  a.resize(N + 1);

  int sum = 0;
  bool flag = true;
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
    sum += a[i];
    if (i >= 1 && a[i - 1] + a[i] >= L) {
      n1 = i - 1, n2 = i;
      flag = false;
    }
  }

  if (flag) {
    cout << "Impossible" << endl;
    return 0;
  }

  rec(1, N, sum);
  return 0;
}


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

vector <vector <int>> S;
vector <int> P;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	S.resize(m);
	P.resize(m);
	for (int i = 0; i < m; i++){
		int k;
		cin >> k;
		S[i].resize(k);
		for (int j = 0; j < k; j++){
			cin >> S[i][j];
			S[i][j] --;
		}
	}
	for (int i = 0; i < m; i++){
		cin >> P[i];
	}
	int ans = 0;
	for (int mask = 0; mask < (1 << n); mask++){
		bool f = true;
		for (int i = 0; i < m; i++){
			int U = 0;
			for (auto s: S[i]){
				if (mask & (1 << s)){
					U ++;
				}
			}
			if (U % 2 != P[i]){
				f = false;
				break;
			}
		}
		if (!f)
			continue;
		ans ++;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef vector< long long > vi;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define fr(n) for(ll i=0;i<n;i++)
#define tr(a) for(auto it=a.begin();it!=a.end();it++)
#define N 10001
#define PI 3.1415926535897932384
#define F first
#define S second
#define elasped_time    1.0 * clock() / CLOCKS_PER_SEC
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
  
// Function to find postorder traversal. 

  
// Driver code 
int main() 
{ 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout); 
#endif
ll n;
cin>>n;
string s;
cin>>s;
int i=0,j=n-1,ans=0;
while(i<=j){
    while(s[i]=='R' and i<=j) i++;
    while(s[j]=='W' and i<=j) j--;
    //cout<<i<<" "<<j<<endl;
    if(i<=j)ans++;
    i++;
    j--;
}
cout<<ans;
    return 0; 
} 

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define test(t) int t ; cin>>t ; while(t--)
int n;
int main(){
    cin >> n;
    int comp = n;
    int sum = 0;
    while(n>0){
        sum += n%10;
        n = n/10;
    }
    if(comp%sum == 0){
        cout << "Yes";
    }else{
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

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

int main()
{
  ll a,b;cin>>a>>b;
  
  cout<< (a*b)/gcd(a,b)<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    int n,m;
    cin>>n>>m;
    cout<<(n-1)*(m-1);
}

Measured memory_bytes: 256
using System;
using System.Linq;

/*
 */

public class ALDS1_5_C
{
    public static void Main(string[] args)
    {
        //var exStdIn = new System.IO.StreamReader( "input.txt" );
        //System.Console.SetIn( exStdIn );

        int n = int.Parse(Console.ReadLine());

        float px = 0f;
        float py = 0f;
        float qx = 100f;
        float qy = 0f;

        Console.WriteLine(String.Format("{0} {1}", px, py));
        Solve(n, 0f, 0f, 100f, 0f);
        Console.WriteLine(String.Format("{0} {1}", qx, qy));
    }

    private static void Solve(int n, float px, float py, float qx, float qy)
    {
        if (n == 0)
        {
            return;
        }

        var sx = px + (qx - px) / 3;
        var sy = py + (qy - py) / 3;

        var tx = px + (qx - px) / 3 * 2;
        var ty = py + (qy - py) / 3 * 2;

        var ux = (float)((tx - sx) * Math.Cos(Math.PI / 3f) - (ty - sy) * Math.Sin(Math.PI / 3f) + sx);
        var uy = (float)((tx - sx) * Math.Sin(Math.PI / 3f) + (ty - sy) * Math.Cos(Math.PI / 3f) + sy);

        Solve(n-1, px, py, sx, sy);
        Console.WriteLine(string.Format("{0} {1}", sx, sy));
        Solve(n-1, sx, sy, ux, uy);
        Console.WriteLine(string.Format("{0} {1}", ux, uy));
        Solve(n-1, ux, uy, tx, ty);
        Console.WriteLine(string.Format("{0} {1}", tx, ty));
        Solve(n-1, tx, ty, qx, qy);

    }
}



Measured memory_bytes: 18032
#include<iostream>
#include<algorithm>

#define MAX 100000

using namespace std;

int n, A[MAX + 1], L[MAX];

int lis() {
  L[0] = A[0];
  int length = 1;

  for (int i = 1; i < n; i++) {
    if (L[length - 1] < A[i]) {
      L[length++] = A[i];
    } else {
      *lower_bound(L, L + length, A[i]) = A[i];
    }
  }

  return length;
}

int main() {
  cin >> n;

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

  cout << lis() << endl;

  return 0;
}


Measured memory_bytes: 3788
A,B,C,D = gets.split.map(&:to_i)
if A <= B && B <= C && C <= D
    puts 0
elsif A <= C && C <= B && B <= D
    puts (B-C)
elsif C <= A && A <= B && B <= D
    puts (B-A)
elsif A <= C && C <= D && D <= B
    puts (D-C)
elsif C <= A && A <= D && D <= B
    puts (D-A)
elsif C <= D && D <= A && A <= B
    puts 0
end

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define pr_arr(name, a, b) \
  for (int i = (a); i < (b); i++) { \
    for (int j = (a); j < (b); j++) {\
      if (j > (a)) printf(" "); \
      printf("%lld", name[i][j]); \
    }\
    printf("\n");\
  }\

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

int ans;
int N;

int main(void) {
    scanf("%d", &N);

    rep(i, 1, N+1) {
      int x = floor(i * 108 / 100);
      if (N==x) {printf("%d\n", i); return 0;}
    }
    
    puts(":(");

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>

using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const ll LINF = 1e18;
const ll MOD = 86400;
double EPS = 1e-8;
const double PI = acos(-1);

struct Edge{
	int to;
	ll cost;
};

ll d[100100];
vector<Edge> es[100100];

int main(){
	int v, e, s;
	cin>>v>>e>>s;
	rep(i, e){
		int a, b, c;
		cin>>a>>b>>c;
		es[a].pb({b,c});
	}
	rep(i, 100100) d[i] = 1e18;
	auto dijkstra =[&]{
		typedef pair<ll, int> P;
		priority_queue<P, vector<P>, greater<P> > q;
		P p;
		q.push({0LL, s});
		d[s] = 0LL;
		while(!q.empty()){
			p = q.top();
			q.pop();
			int from = p.se;
			ll c = p.fi;
			for(auto & e : es[from]){
				int to = e.to;
				ll cost = c + e.cost;
				if(cost < d[to]){
					d[to] = cost;
					q.push({cost, to});
				}
			}
		}
	};
	dijkstra();
	rep(i, v) {
		if(d[i] == 1e18) cout<<"INF"<<endl;
		else cout<<d[i]<<endl;
	}
}

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

bool kiemtra (int N)
{
    int i;
    if (N < 2) return false;
    if (N == 2) return true;
    for (i = 2; i <= trunc(sqrt(N)); i++)
      if (N%i == 0) return false;
    return true;
}

int main()
{
    long N;
    cin>>N;
    bool b = false;
    if (kiemtra(N) == true)
    {
        cout<<N;
        return 0;
    }
    else
        while (b != true)
        {
            N++;
            b = kiemtra(N);
        }
    cout<<N;
    return 0;
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
A,B = LIR(N,2)

from operator import itemgetter
def index_sort(A):
    A_sort = sorted(enumerate(A),key=itemgetter(1))
    index = [a[0] for a in A_sort]
    sorted_A = [a[1] for a in A_sort]
    return index, sorted_A

C = [A[i]+B[i] for i in range(N)]
index,_ = index_sort(C)
ans = 0
for i in range(N)[::-1]:
    if i%2 == (N-1)%2:
        ans += A[index[i]]
    else:
        ans -= B[index[i]]

print(ans)

Measured memory_bytes: 79964
N,M=map(int,input().split())
PS=[input().split() for i in range(M)]
wa,ac=[0]*N,[0]*N
for p,s in PS:
    p=int(p)-1
    if s=='WA' and ac[p]==0:
        wa[p]+=1
    elif s=='AC':
        ac[p]=1
for i in range(N):
    if ac[i]==0:
        wa[i]=0
print(sum(ac),sum(wa))

Measured memory_bytes: 33696
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define mod 998244353
#define mp make_pair
#define ff first
#define ss second
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define sc(a) scanf("%lld",&a)
#define pf printf
#define sz(a) (ll)(a.size())
#define psf push_front
#define ppf pop_front
#define ppb pop_back
#define pb push_back
#define pq priority_queue
#define all(s) s.begin(),s.end()

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,wt;
	cin>>n>>wt;
	int w[n],v[n],sum=0;
	f(i,0,n)
		cin>>w[i]>>v[i],sum+=v[i];
	// cout<<sum<<"\n";
	ll dp[n+1][sum+1];
	f(i,0,sum+1)
		dp[0][i]=1e18;
	f(i,0,n+1)
		dp[i][0]=0;
	f(i,1,n+1)
	{
		f(j,1,sum+1)
		{
			if(v[i-1]>j)
				dp[i][j]=dp[i-1][j];
			// else if(i==1)
			// 	dp[i][j]=w[i-1];
			else
				dp[i][j]=min(dp[i-1][j],w[i-1]+dp[i-1][j-v[i-1]]);
		}
	}
	int ans=0;
	for(int j=sum;j>=0;j--)
	{
		if(dp[n][j]<=wt)
		{
			// cout<<"Ent\n";
			ans=j;
			break;
		}
	}
	// cout<<dp[n][140]<<"\n";
	// f(i,0,n+1)
	// {
	// 	f(j,0,sum+1)
	// 		cout<<dp[i][j]<<' ';
	// 	cout<<"\n";
	// }
	// cout<<dp[3][30]<<' '<<dp[2][50]<<' '<<dp[3][80]<<' '<<dp[3][90]<<' '<<dp[3][140]<<' '<<dp[3][60]<<"\n";
	cout<<ans;
}

Measured memory_bytes: 79104
#include<stdio.h>
int main(void)
{
    int n,s,r[100],i,j,c,cnt=0,min;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&r[i]);
    }
    
    for(i=0;i<n;i++)
    {
        min = i;
        for(j=i;j<n;j++)
        {
            if(r[min] > r[j])
            {
                min = j;
            }
        }
        if(min != i) cnt++;
        c = r[i];
        r[i] = r[min];
        r[min] = c;
    }
    for(i=0;i<n-1;i++)
    {
        printf("%d ",r[i]);
    }
    printf("%d\n%d\n",r[i],cnt);
    return 0;
}


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

struct Card {char suit; int value;};

void print(struct Card A[], int n){
    for(int i=0;i<n;i++){
        if(i) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

void bubble_sort(struct Card A[], int n){
    Card t;
    bool flag = 1;
    for(int i=0;flag;i++){
        flag = 0;
        for(int j=n-1;j>i;j--){
            if(A[j].value < A[j-1].value){
                flag = 1;
                t = A[j]; A[j] = A[j-1]; A[j-1] = t;
            }
        }
    }
}

/*
void insertion_sort(struct Card A[], int n){
    int j;
    Card v;
    for(int i=1;i<n;i++){
        v = A[i];
        j = i - 1;
        while(j >= 0 && v.value < A[j].value){
            A[j+1] = A[j];
            j -- ;
        }
        A[j+1] = v;
    }
}
*/

void selection_sort(struct Card A[], int n){
    int mini;
    for(int i=0;i<n;i++){
        mini = i;
        for(int j=i+1;j<n;j++){
            if(A[mini].value > A[j].value){
                mini = j;
            }
        }
        if(i != mini){
            swap(A[i], A[mini]);
        }
    }
}


bool isStable(struct Card A1[], struct Card A2[], int n){
    for(int i=0;i<n;i++){
        if(A1[i].suit != A2[i].suit){
            return false;
        }
    }
    return true;
}

int main(){
    Card A1[36], A2[36];
    int n=0;

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> A1[i].suit >> A1[i].value;
        A2[i] = A1[i];
    }

    bubble_sort(A1, n);
    print(A1, n);
    cout << "Stable" << endl;

    selection_sort(A2, n);
    print(A2, n);
    if(isStable(A1, A2, n)){
        cout << "Stable" << endl;
    }
    else{
        cout << "Not stable" << endl;
    }
    return 0;
}



Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e4+10;
set<string> se;
int main()
{
    int n;
    string s;
    cin>>n;
    while(n--){
        cin>>s;
        se.insert(s);
    }
    cout<<se.size()<<endl;
    return 0;
}


Measured memory_bytes: 19180
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    
    char c = *min_element(s.begin(), s.end());
    string t = s;
    reverse(t.begin(), t.end());
    string u = s + t;
    int m = 1;
    while (k > 1 && m < n) {
        m = min(n, 2 * m);
        --k;
    }
    string ans;
    for (int i = 0; i <= n; ++i) {
        s = u.substr(i, n);
        if (s.back() != c)
            continue;
        int len = 0;
        while (len < n && s[n - len - 1] == c)
            ++len;
        int f = min(n, len * m);
        s = s.substr(f - len, n - f);
        while (s.length() < n)
            s += c;
        reverse(s.begin(), s.end());
        if (ans.empty() || ans > s)
            ans = s;
    }
    cout << ans << endl;
    return 0;
}

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

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

    int n, k;
    cin>>n>>k;

    if (k == 1 || k==2*n-1) {
        cout<<"No"<<endl;
        return 0;
    }

    if (n == k) {
        cout<<"Yes"<<endl;
        for (int i=1; i<2*n; i++)    cout<<i<<"\n";
        cout<<endl;
    }
    else {
        vector<int> ans(2*n), done(2*n);
        ans[n] = k;
        if (k > n)  ans[n+1] = 2*n-1, ans[n+2] = k-1, ans[n-1] = k-2;
        else        ans[n+1] = 1, ans[n+2] = k+1, ans[n-1] = k+2;

        for (int i=n-1; i<=n+2; i++)    done[ans[i]] = 1;

        int cur = 1;
        for (int i=1; i<2*n; i++) {
            if (ans[i]) continue;
            while(done[cur])    cur++;
            ans[i] = cur;
            done[cur]=1;
        }
        cout<<"Yes"<<endl;
        for (int i=1; i<2*n; i++)   cout<<ans[i]<<"\n";
        cout<<endl;
    }
}


Measured memory_bytes: 3072
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

pair<int,int> dfs(const int  now, const int from, const vector<vector<pair<int, int>>>&edges) {
	vector<int>lens(2,0);
	int dia = 0;
	int len = 0;
	for (auto e : edges[now]) {
		if (e.first == from)continue;
		else {
			auto p = dfs(e.first, now, edges);
			dia = max(dia, p.second);
			lens.push_back(e.second+p.first);
			sort(lens.begin(), lens.end(), greater<int>());
			lens.resize(2);
		}
	}
	dia =max(dia, lens[0] + lens[1]);
	len = lens[0];
	return make_pair(len, dia);
	
}

int main() {
	int V; cin >> V;
	vector<vector<pair<int,int>>>edges(V);
	for (int i = 0; i < V-1; ++i) {
		int a, b, c; cin >> a >> b >> c;
		edges[a].push_back(make_pair(b, c));
		edges[b].push_back(make_pair(a, c));
	}
	auto p = dfs(0, -1, edges);
	cout << p.second << endl;
	return 0;
}

Measured memory_bytes: 25468
#include<bits/stdc++.h> 
using namespace std; 
 
 void print(vector<int> s)
 {
     for(int i=0;i<s.size();i++)
     {
         cout<<s[i];
     }
 }

int main()
{
    int a,b;
    cin>>a>>b;
    
    vector<int> s,t;
    
    for(int i=0;i<b;i++)
    {
        s.push_back(a);
    }
    
    for(int j=0;j<a;j++)
    {
        t.push_back(b);
    }
    

    if(lexicographical_compare(s.begin(),s.end(),t.begin(),t.end() ))
    {
        print(s);
    }
    
    else
    {
        print(t);
    }
}


Measured memory_bytes: 256
#!/usr/bin/env python

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
INF = float("inf")

def main():
    N,T = map(int,input().split())        
    AB = [(0,0)] + [tuple(map(int,input().split())) for _ in range(N)]

    # 最後に食べるものを全探索し, それ以外でDPしたくなる
    # 普通にやると TLE だが, 左から,右から で事前にDPしておくことで計算量を落とせる

    # このとき, 配列添字を 1〜N にしておくと楽
    #   1番目の料理を最後に食べるとき : dp1[0][] + b + dp2[2][], このときに index out of range しないのが嬉しい
    #   2番目の料理を最後に食べるとき : dp1[1][] + b + dp2[3][]
    #   ...
    #   N番目の料理を最後に食べるとき : dp1[N-1][] + b + dp2[N+1][], dp2 は N+2 の長さがあると良さそう

    # dp1[i][j] : 1〜i 番目の料理から選んで T 分以内に食べるときの美味しさの和の最大値
    dp1 = [[0 for _ in range(T+1)] for _ in range(N+1)]
    for i in range(1,N+1):
        a,b = AB[i]
        for j in range(T+1):
            # 食べる
            if j >= a:
                dp1[i][j] = max(dp1[i-1][j], dp1[i-1][j-a] + b)
            # 食べない
            else:
                dp1[i][j] = dp1[i-1][j]

    # dp2[i][j] : i〜N 番目の料理から選んで T 分以内に食べるときの美味しさの和の最大値
    dp2 = [[0 for _ in range(T+1)] for _ in range(N+2)]
    for i in range(N,0,-1):
        a,b = AB[i]
        for j in range(T+1):
            # 食べる
            if j >= a:
                dp2[i][j] = max(dp2[i+1][j], dp2[i+1][j-a] + b)
            # 食べない
            else:
                dp2[i][j] = dp2[i+1][j]
    
    # 最後に食べる料理で全探索
    ans = 0
    for i in range(1,N+1):
        a,b = AB[i]
        for j in range(T):
            ans = max(ans, dp1[i-1][j] + b + dp2[i+1][T-1-j])
    
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 232700
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll int
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
vl a[505];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,m,q,l,r;
    cin>>n>>m>>q;
    rep(i,0,m)
    {
    	cin>>l>>r;
    	a[l].pb(r);
    }
    rep(i,1,n+1)
    sort(all(a[i]));
    while(q--)
    {
    	cin>>l>>r;
    	ll ans=0;
    	rep(i,l,r+1)
    	{
    		ans+=ub(all(a[i]),r)-a[i].begin();
    	}
    	cout<<ans<<"\n";
    }
}


Measured memory_bytes: 2176
#include<stdio.h>
int c(const void *a,const void *b){return *(int*)a-*(int*)b;}
int n,h[200000],k,i;
long r=0;
int main(){
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++)scanf("%d",&h[i]);
    qsort(h,n,4,c);
    for(i=0;i<n-k;i++)r+=h[i];
    printf("%ld",r);
    return 0;
}

Measured memory_bytes: 1788
class Tree {
  static get Node() {
    return class {
      constructor(id, parent, children) {
        this.id = id;
        this.parent = parent;
        this.children = children;
      }

      get type() {
        if (this.parent === null) return 'root';
        if (this.children.length === 0) return 'leaf';
        return 'internal node';
      }

      get depth() {
        const getDepth = (node, i) => {
          return node.parent === null ? i : getDepth(node.parent, i + 1);
        };
        return getDepth(this, 0);
      }

      toString() {
        return `node ${this.id}: parent = ${this.parent !== null ? this.parent.id : -1}, depth = ${this.depth}, ${this.type}, [${this.children.map(n => n.id).join(', ')}]`;
      }
    };
  }

  constructor(n) {
    this.nodes = [];
    let Node = Tree.Node;
    for (let i = 0; i < n; i++) this.nodes[i] = new Node(i, null, []);
  }

  add(id, childrenIds) {
    let node = this.find(id);
    childrenIds.forEach((cid) => {
      let c = this.find(cid);
      c.parent = node;
      c.id = cid;
      node.children.push(c);
    })
  }

  find(id) {
    return this.nodes[id];
  }

  print() {
    console.log(this.nodes.sort((a, b) => a.id - b.id).map(n => n.toString()).join('\n'));
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  let tree = new Tree(n);

  let id, k, childrenIds;
  lines.map(l => l.split(' ')).forEach(function(line) {
    id = Number(line.shift());
    k = Number(line.shift());
    childrenIds = line.map(Number);
    tree.add(id, childrenIds);
  });

  tree.print();
})();



Measured memory_bytes: 158412
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, K = LI()
d = [0 for i in range(K)]
A = [[] for i in range(K)]
for k in range(K):
    d[k] = int(input())
    A[k] = LI()

sunuke = [0 for i in range(N)]
for k in range(K):
    for s in A[k]:
        sunuke[s - 1] += 1

ans = 0
for s in sunuke:
    if s == 0:
        ans += 1
print(ans)
    

Measured memory_bytes: 10848