akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

#define N 100001

int partition(int *, int, int);

int main () {
  int A[N], i, n = 0, p = 0;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++) {
    scanf("%d",&A[i]);
  }

  p = partition(A, 0, n - 1);

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

  return 0;
}


int partition(int *A, int p, int r) {
  int i, j, x = 0, tmp = 0;

  x = A[r];
  i = p - 1;

  for(j = p ; j < r ; j++) {
    if(A[j] <= x) {
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;

  return i+1;
}



Measured memory_bytes: 2096
#include<bits/stdc++.h>
// #include <atcoder/all>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
// using namespace atcoder;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    int k;
    cin >> k;
    rep(i,k) {
        cout << "ACL";
    }
    cout << endl;
}

Measured memory_bytes: 3612
//Knapsack Problem

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define NMAX 101
#define WMAX 10001
int dp[NMAX][WMAX] = {};
struct Item {int v, w;};

int main() {
	int n,w;
	Item items[NMAX+1] = {};
	cin >> n >> w;
	
	for(int i=1;i<=n;i++) {
	cin >> items[i].v >> items[i].w;
	}
	
	for(int weight=1;weight<=w;weight++) {
	for(int goods=1;goods<=n;goods++) {
	if (items[goods].w <= weight) {
	dp[goods][weight] = max(dp[goods-1][weight-items[goods].w] + items[goods].v, dp[goods-1][weight]);
	}
	else 
	{
	dp[goods][weight] = dp[goods-1][weight];
	}
	}
	}
/*
	for (int i=0;i<=w;i++) {
	for (int j=0;j<=n;j++) {
	cout << dp[i][j] << " ";
	}
	cout << endl;
	}	
*/
	cout << dp[n][w] << endl;
	return 0;
}	

Measured memory_bytes: 6992
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N, ans = 0; cin >> N;
    rep (i, 0, N) {
        long long in; cin >> in;
        if (in % 2 == 0) {
            while (true) {
                if (in == 1 or in % 2 != 0) break;
                in /= 2;
                ++ans;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
strength = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]
a_strength, b_strength = gets.chomp.split(" ").map(&:to_i).map {|card| strength.index(card)}

puts "Alice" if a_strength > b_strength
puts "Draw" if a_strength == b_strength
puts "Bob" if a_strength < b_strength

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

using namespace std;

int main() {
    int k, n, i, j, a[300000], b[300000]={}, max=0;
    scanf("%d %d", &k, &n);
    for(i=1;i<=n;i++)
        scanf("%d", &a[i]);
    for(i=1;i<=n;i++)
    {
        
        if(i==n)
            b[i]=k+a[1]-a[i];
        else
            b[i]=a[i+1]-a[i];
        
        if(max<b[i])
            max=b[i];
    }
    
    
    printf("%d", k-max);
    return 0;
}

Measured memory_bytes: 1024
// 5/10 リアルタイム参加
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
// #include <math.h>

static const double pi = 3.141592653589793;

int main() {
    int N, M;
    cin >> N >> M;
    // vector<int> A(M), B(M);
    // rep(i, M) cin >> A[i] >> B[i];

    Graph G(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> dist(N, -1), from(N, -1);
    queue<int> que;

    dist[0] = 0;
    que.push(0);

    while (!que.empty()) {
        int v = que.front();
        que.pop();

        for (int nv : G[v]) {
            if (dist[nv] != -1) continue;

            dist[nv] = dist[v] + 1;
            from[nv] = v;
            que.push(nv);
        }
    }

    bool b = true;
    for (int i = 1; i < N; i++) {
        if (from[i] == -1) {
            b = false;
            break;
        }
    }

    if (b) {
        cout << "Yes" << endl;
        for (int i = 1; i < N; i++) {
            cout << from[i] + 1 << endl;
        }
    } else {
        // cout << -1 << endl;
        // cout << "Yes" << endl;
        cout << "No" << endl;
    }
}


Measured memory_bytes: 10644
// Author -- Frame

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-x))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())
#define pb push_back

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

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x7fffffffffffffff;
const double eps=1e-10;

template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline bool _cmp(const _Tp &a,const _Tp &b){return abs(a-b)<=eps;}
template <typename _Tp>Finline void read(_Tp &x)
{
	register char ch(getchar());
	bool f(false);
	while(ch<48||ch>57) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();
	while(ch>=48&&ch<=57) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	if(f) x=-x;
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args)
{
	read(t);read(args...);
}
Finline int read_str(char *s)
{
	register char ch(getchar());
	while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	register char *tar=s;
	*tar=ch,ch=getchar();
	while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=100005;
ll x[N],y[N];
int main()
{
	int n;
	read(n);
	bool flag1=0,flag2=0;
	for(int i=1;i<=n;++i)
	{
		read(x[i],y[i]);
		if((x[i]+y[i])%2) flag1=true;
		else flag2=true;
	}
	if(flag1&&flag2)
	{
		printf("-1\n");
		return 0;
	}
	std::vector<ll> v;
	if(flag2) printf("37\n1 "),v.pb(1);
	else printf("36\n");
	for(int i=0;i<=35;++i)
	{
		printf("%lld ",1ll<<i);
		v.pb(1ll<<i);
	}
	printf("\n");
	std::reverse(v.begin(),v.end());
	auto calc=[](ll x1,ll y1,ll x2,ll y2)->ll{return abs(x1-x2)+abs(y1-y2);};
	for(int i=1;i<=n;++i)
	{
		std::vector<char> ans;
		ll a=0,b=0;
		for(auto it:v)
		{
			ll x1=a-it,y1=b;
			ll x2=a+it,y2=b;
			ll x3=a,y3=b-it;
			ll x4=a,y4=b+it;
			ll dis1=calc(x1,y1,x[i],y[i]);
			ll dis2=calc(x2,y2,x[i],y[i]);
			ll dis3=calc(x3,y3,x[i],y[i]);
			ll dis4=calc(x4,y4,x[i],y[i]);
			ll minn=min(min(dis1,dis2),min(dis3,dis4));
			if(dis1==minn) a=x1,b=y1,ans.pb('L');
			else if(dis2==minn) a=x2,b=y2,ans.pb('R');
			else if(dis3==minn) a=x3,b=y3,ans.pb('D');
			else if(dis4==minn) a=x4,b=y4,ans.pb('U');
		}
		assert(a==x[i]&&b==y[i]);
		std::reverse(ans.begin(),ans.end());
		for(auto it:ans) printf("%c",it);
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

vector<int> a,b,bas,bbs;
int ans1,ans2,n;

signed main(){
	read(n);
	for(int i=1;i<=n;i++) bas.push_back(i);
	for(int i=1,x;i<=n;i++) a.push_back(read(x));
	for(int i=1,x;i<=n;i++) b.push_back(read(x));
	ans1=1,ans2=1;
	bbs=bas;
	while(bas!=a){
		ans1++;
		next_permutation(bas.begin(),bas.end());
	}
	while(bbs!=b){
		ans2++;
		next_permutation(bbs.begin(),bbs.end());
	}
	write(abs(ans2-ans1));
}


Measured memory_bytes: 256
// Oh boi here we go again
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

#define all(s) s.begin(), s.end()
#define ok puts("ok")
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >
#define pii pair < int, pi >
#define next next123
#define left left123

const int N = 5e5 + 7;
const int INF = 1e9 + 7;

int a[N];
string s;

main(){
    cin >> s;
    int balance = 0;
    if (s[0] == '<')
        balance++;
    for (int i = 1; i <= s.length(); i++){
        a[i] = balance;
        if (s[i] == '<')
            balance++;
        else
            balance = 0;
    }
    ll sum = a[s.length()];
    balance = 0;
    for (int i = s.length() - 1; i >= 0; i--){
        if (s[i] == '>')
            balance++;
        else
            balance = 0;
        a[i] = max(a[i], balance);
        sum += a[i];
    }
    cout << sum;
}


Measured memory_bytes: 2820
import java.util.*;
public class Main {
    public static void main(String[] args){
        Main main = new Main();
        String ans = main.solve()<0?"No":"Yes";
        System.out.println(ans);
    }
    long solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i=0;i<n; i++) h[i] = sc.nextInt();

        for(int j=n-2;j>=0;j--){
            if(h[j]<=h[j+1]) continue;
            else if(h[j]==h[j+1]+1){
                h[j] -= 1;
            } else{
                return -1;
            }
        }
        return 0;
    }
}


Measured memory_bytes: 50396
#include <bits/stdc++.h>
using namespace std;
#define trace1(a) cout << a << 'n';
#define trace2(a, b) cout << a << ' ' << b << 'n';
#define trace3(a, b, c) cout << a << ' ' << b << ' ' << c << 'n';
#define trace4(a, b, c, d) cout << a << ' ' << b << ' ' << c << ' ' << d << 'n';
#define trace5(a, b, c, d, e) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << 'n';
#define trace6(a, b, c, d, e, f) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << ' ' << f << 'n';
#define range(n) for(int i = 0; i < n; i++)
#define printArr(harry, tam) range(tam) cout << harry[i] << " n"[i == tam -1];
#define maxn -2000000 //negative value to break code and force you to put right constraint
#define mod 1000000007
#define md(x) (x) % mod;
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ps push
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF 1000000000
#define INFd 1e9
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<double> vd;

int main(){
  ll n;
  cin>>n;
   vector<ll> a(n+1),b(n+1);
   for(ll i=1;i<=n;i++)
    cin>>a[i];
    vector<ll> v;
  for(ll i=n;i>0;i--)
  {
    ll cnt=0;
      for(ll j=2;(i*j)<=n;j++)
        if(b[i*j])
          cnt++;
    if(cnt%2==1){
        if(a[i])
          b[i]=0;
        else
          b[i]=1;
    }
    else
    {
        if(a[i])
          b[i]=1;
        else
          b[i]=0;
    }
      if(b[i])
        v.pb(i);

  }
  reverse(v.begin(),v.end());
  cout<<v.size()<<endl;
  for(ll i=0;i<v.size();i++)
    cout<<v[i]<<" ";

}


Measured memory_bytes: 4980
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

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

    int a, b, c;
    a = 0;
    b = n/2;
    c = n;
    vector<char> st;
    cout << 0 << endl;
    string S;
    cin >> S;
    if(S[0] == 'V') return 0;
    st.push_back(S[0]);

    cout << b << endl;
    cin >> S;
    if(S[0] == 'V') return 0;
    st.push_back(S[0]);

    rep(i, 18) {
        if((((b-a)&1) && st[0] != st[1]) || (!((b-a)&1) && st[0] == st[1])) {
            a = b;
            b = (c+b)/2;
            st[0] = st[1];
        } else {
            c = b;
            b = (c+a)/2;
        }
        cout << b << endl;
        cin >> S;
        if(S[0] == 'V') return 0;
        st[1] = S[0];
    }

}

Measured memory_bytes: 852
#include<bits/stdc++.h>
using namespace std;
main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long i,j,k,l,m,n,o,p,q;
    while(cin>>m)
    {cout<<(24-m)+24<<endl;
    }
    return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define met(s) memset(s, 0, sizeof(s))
const int MOD = 100000007;
const int MAXN = 1000000;
const int inf = 0x3f3f3f3f;
int main()
{
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if (a == b && b == c && a == c) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    string ans = "APPROVED";

    for(int i = 0; i < N; i++){
        int tmp;
        cin >> tmp;
        if(tmp % 2 == 0){
            if(tmp % 3 != 0 && tmp % 5 != 0){
                ans = "DENIED";
                break;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000000
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main(){
  char C;
  cin >> C;
  C++;
  cout << C << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long int ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main(){

   fast
   long double a,b;
   cin>>a>>b;
   long long int c = a*b;
   cout<<c;
}

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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

// Macro
#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 REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

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

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
  if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
  if (a < b) return a = b, true; else return false;
}


void solve(){
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  char pre = S[0];
  int count = 0;
  REP(i, 1, N){
    if(pre != S[i]){
      count++;
      pre = S[i];
    }
  }

  int ans =  N - 1 - count + min(count - count % 2, 2 * K);
  if(count % 2 == 1 && count < 2 * K){
    ans++;
  }

  cout << ans << endl;
}

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

Measured memory_bytes: 512
def main(n,a):
    #カードを大きい順に並び替える
    a.sort(reverse = True)
    #奇数番目がアリス、偶数番目がボブ
    alis = a[0::2]
    bob = a[1::2]
    return sum(alis) - sum(bob)

n = int(input())
a = list(map(int, input().split()))
print(main(n,a))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

int main() {
    fastio;
    ll ans=Inf;
    ll N;
    cin >> N;
    vector<int> x(N);
    rep(i,N) cin >> x[i];
    for (int p=1; p <= 100; ++p) {
        ll s=0;
        rep(i,N) {
            int d = x[i]-p;
            s += d*d;
        }
        updmin(ans, s);
    }
    cout << ans << endl;
}


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

int main(void){
        int n;
        cin >> n;
        vector<int> d(n*2);
        for(int i = 0; i < n*2; i+=2){
                cin >> d[i] >> d[i+1];
        }
        for(int i = 0; i <= n*2-6; i+=2){
                if(d[i] == d[i+1] 
                                and d[i+2] == d[i+3] 
                                and d[i+4] == d[i+5]){
                        cout << "Yes" << endl;
                        return 0;
                }
        }
        cout << "No" << endl;
        return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

string s;

int main(){
    cin >> s;
    if(s == "Sunny"){
        cout << "Cloudy";
    } else if(s == "Cloudy"){
        cout << "Rainy"; 
    } else{
        cout << "Sunny"; 
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const ll INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(ll i=0;i<(ll)(s.size());++i) {
    cout << s[i];
    if(i == (ll)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
vector<ll> add;
vector<ll> cost;
void dfs(const vvi &tr, ll now, ll prev, ll nowc) {
  nowc += add[now];
  cost[now] = nowc;
  for(ll i=0;i<(ll)(tr[now].size());++i) {
    ll next = tr[now][i];
    if(next != prev) {
      dfs(tr, next, now, nowc);
    }
  }
}
signed main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  ll n, q; cin >> n >> q;
  vvi tr(n);
  for(ll i=0;i<n-1;++i) {
    ll a, b; cin >> a >> b;
    a--; b--;
    tr[a].push_back(b);
    tr[b].push_back(a);
  }
  add.resize(n, 0);
  for(ll i=0;i<q;++i) {
    ll p, x; cin >> p >> x;
    p--;
    add[p] += x;
  }
  cost.resize(n);
  dfs(tr, 0, -1, 0);
  for(ll i=0;i<n;++i) {
    cout << cost[i];
    if(i == n-1) cout << endl;
    else cout << " ";
  }
}


Measured memory_bytes: 28928
#include<iostream>
#include<vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

int main(){
	long long int n,d;
	cin>>n>>d;
	vector<long long int>x(n),y(n);
	rep(i,n)cin>>x[i]>>y[i];
	long long int sum = 0;
	rep(i,n){
		if(x[i]*x[i]+y[i]*y[i]<=d*d)sum++;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 6424
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] c = new int[n][n];
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				c[i][j] = sc.nextInt();
			}
		}
		int[] p = new int[n];
		iota(p);
		int id = 0;
		HashMap<Integer,Integer> hm = new HashMap<Integer, Integer>();
		do {
			hm.put(hash(p), id);
			id++;
		} while(nextPermutation(p));
		Graph g = new Graph(id);
		iota(p);
		do {
			int u = hm.get(hash(p));
			for(int i=0;i<n;i++) {
				for(int j=i+1;j<n;j++) {
					swap(p, i, j);
					int v = hm.get(hash(p));
					swap(p, i, j);
					g.addEdge(u, v, c[i][j]);
				}
			}
		} while(nextPermutation(p));
		int[] dist = g.minDistDijkstra(0);
		int max = 0;
		for(int i=0;i<id;i++) {
			max = Math.max(max,dist[i]);
		}
		System.out.println(max);
	}

	static void iota(int[] p) {
		for(int i=0;i<p.length;i++) {
			p[i] = i;
		}
	}

	static void swap(int[] p,int i,int j) {
		int temp = p[i];
		p[i] = p[j];
		p[j] = temp;
	}

	static boolean nextPermutation(int[] p) {
		for(int a=p.length-2;a>=0;--a) {
			if(p[a]<p[a+1]) {
				for(int b=p.length-1;;--b) {
					if(p[b]>p[a]) {
						int t = p[a];
						p[a] = p[b];
						p[b] = t;
						for(++a, b=p.length-1;a<b;++a,--b) {
							t = p[a];
							p[a] = p[b];
							p[b] = t;
						}
						return true;
					}
				}
			}
		}
		return false;
	}

	static int hash(int[] p) {
		int h = 0;
		for(int i=0;i<p.length;i++) {
			h *= 8;
			h += p[i];
		}
		return h;
	}
}

class Graph {
	public static final int INF = 1<<29;
	int n;
	ArrayList<Edge>[] graph;

	@SuppressWarnings("unchecked")
	public Graph(int n) {
		this.n = n;
		this.graph = new ArrayList[n];
		for(int i=0;i<n;i++) {
			graph[i] = new ArrayList<Edge>();
		}
	}

	public void addBidirectionalEdge(int from,int to,int cost) {
		addEdge(from,to,cost);
		addEdge(to,from,cost);
	}
	public void addEdge(int from,int to,int cost) {
		graph[from].add(new Edge(to, cost));
	}

	//dijkstra O(ElogV)
	public int[] minDistDijkstra(int s) {
		int[] dist = new int[n];
		Arrays.fill(dist, INF);
		dist[s] = 0;
		PriorityQueue<Node> q = new PriorityQueue<Node>();
		q.offer(new Node(0, s));
		while(!q.isEmpty()) {
			Node node = q.poll();
			int v = node.id;
			if (dist[v] < node.dist) {
				continue;
			}
			for(Edge e:graph[v]) {
				if (dist[e.to] > dist[v] + e.cost) {
					dist[e.to] = dist[v] + e.cost;
					q.add(new Node(dist[e.to], e.to));
				}
			}
		}
		return dist;
	}

	class Edge {
		int to;
		int cost;
		public Edge(int to,int cost) {
			this.to = to;
			this.cost = cost;
		}
	}
	class Node implements Comparable<Node>{
		int dist;
		int id;
		public Node(int dist,int i) {
			this.dist = dist;
			this.id = i;
		}
		public int compareTo(Node o) {
			return (this.dist < o.dist) ? -1 : ((this.dist == o.dist) ? 0 : 1);
		}
	}
}

Measured memory_bytes: 99984
import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int A = sc.nextInt();
        int B = sc.nextInt();

        if (A == B) {
        	System.out.println("Draw");
        	return;
        }
        
        A = A == 1 ? 14:A;
        B = B == 1 ? 14:B;
        
        System.out.println(A > B ? "Alice" : "Bob");
    }
}

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<int>& a) { for (int x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

signed main() {
  while (true) {
    i32 n, r;
    cin >> n >> r;
    if (n == 0) break;
    vector<i32> deck(n);
    iota(RALL(deck), 1);
    REP(_, r) {
      i32 p, c;
      cin >> p >> c;
      rotate(deck.begin(), deck.begin() + p - 1, deck.begin() + p - 1 + c);
    }
    cout << deck[0] << endl;
  }
}



Measured memory_bytes: 3076
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <vector>
using namespace std;
const int maxx = 100010;
int n, m;
int u, num, v;
int flag[maxx];
int color[maxx];
vector<int> G[maxx];

int c = 1;
void dfs(int t) {
	stack<int>s;
	s.push(t);
	color[t] = c;
	while (!s.empty()) {
		int u = s.top(); s.pop();
		int len = G[u].size();
		for (int i = 0; i < len; i++) {
			int v = G[u][i];
			if (flag[v] == 0) {
				color[v] = c;
				flag[v] = 1;
				s.push(v);
			}
		}
	}
}
int main()
{
	int q;
	memset(flag, 0, sizeof(flag));
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &u, &v);
		//?°???¶???v????????°G[u]??°??????
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for (int i = 0; i < n; i++) {
		if (flag[i] == 0) {
			dfs(i);
			c++;
		}
	}
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%d %d", &u, &v);
		if (color[u] == color[v]) {
			printf("yes\n");
		}
		else {
			printf("no\n");
		}
	}
	return 0;
}

Measured memory_bytes: 9440
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <complex>
#include <vector>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()

typedef complex<int> P;
typedef vector<P> L;

ostream& operator<<(ostream& os, const L& l){
    rep(i,l.size()){
        os<<l[i]<<" ";
    }
    return os;
}

L _getline(){
    int m; cin>>m;
    L l(m);
    rep(i,m){
        int x,y; cin>>x>>y;
        l[i]=P(x,y);
    }
    return l;
}

L normal(L l){
    P dir=l[1]-l[0];
    dir/=abs(dir);
    for(int i=l.size()-1;i>=0;i--){
        l[i]-=l[0];
        l[i]/=dir;
    }
    return l;
}

int main(){
    int n;
    while(cin>>n && n){
        L l1 = normal(_getline());
        L l2 = l1;
        reverse(all(l2));
        l2=normal(l2);
        // cout << l1 << endl;
        // cout << l2 << endl;
        
        rep(i,n){
            L m = normal(_getline());
            if(l1==m || l2==m){
                cout << i+1 << endl;
            }
        }
        cout << "+++++" << endl;
    }
}

Measured memory_bytes: 1200
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

sat_sum = 0

for i in range(n):
  sat_sum += b[a[i]-1]
  if a[i] == a[i-1]+1 and i != 0:
    sat_sum += c[a[i-1]-1]
print(sat_sum)


Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {

	private static Scanner sc;

	public static void main(String[] args) {

		sc = new Scanner(System.in);
		String str = sc.next();
		int count = 0;

		if (str.substring(0,1).contentEquals("1")) count+=1;
		if (str.substring(1,2).contentEquals("1")) count+=1;
		if (str.substring(2,3).contentEquals("1")) count+=1;

		System.out.print(count);
	}

}


Measured memory_bytes: 21844
/// a.cpp
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < decltype(v.x) > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pll pair < ll , ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define fail puts("-1")
# define yes puts("Yes")
# define no puts("No")
# define PP puts("Possible")
# define II puts("Impossible")
# define vii vector < pii >
# define vll vector < pll >
# define pb push_back
# define pdd pair < db , db >
# define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    fi>>n;
    int a = 0,b = 0,c = 0;
    for (int i = 0;i < n;++i)
    {
        int v;
        fi>>v;
        if (v & 1)
            ++a;
        else
        if (v % 4 == 2)
            ++b;
        else
            ++c;
    }
    int mn = min(a,c);
    a -= mn;c -= mn;
    if (a >= 2)
        return no * 0;
    if (a == 1 && b)
        return no * 0;
    yes;
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import itertools
import math
def main():
    N,M = map(int,input().split())
    root = [[] for _ in range(N)]
    ans = math.factorial(N-1)
    for i in range(M):
        a,b = map(int,input().split())
        root[a-1].append(b-1)
        root[b-1].append(a-1)

    for i in itertools.permutations([j for j in range(1,N)]):
        if i[0] not in root[0]:
            ans -= 1
        else:
            for j in range(N-2):
                if i[j+1] not in root[i[j]]:
                    ans -= 1
                    break

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <atcoder/lazysegtree>
using namespace std;
using namespace atcoder;
using ll = int64_t;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()

ll le = 200010;
vector<vector<ll>> M(le, vector<ll>(10, 0));
vector<ll> MODS(le, 0);
ll mod = 998244353;

struct S {ll v, size;};

S op(S a, S b) {
  // cout << "MODS " << b.size << " " << MODS[b.size] << '\n';
  return {(MODS[b.size]*a.v + b.v) % mod, a.size + b.size};
}

S e() {
  return {0, 0};
}

S mapping(ll f, S x) {
  // cout << M[x.size][f] << '\n';
  if (f != 0) {
    return {M[x.size][f], x.size};
  } else {
    return x;
  }
}

ll composition(ll f, ll g) {
  if (f != 0) {
    return f;
  } else {
    return g;
  }
}

ll id() {
  return 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, q, l, r, d;
  cin >> n >> q;
  vector<S> A;
  rep(i, n) {
    A.push_back(S{1, 1});
  }
  
  rep(i, 10) {
    M[1][i] = i;
  }
  rep(i, 10) {
    for (int j=2; j<le; j++) {
      M[j][i] = (M[j-1][i] * 10) % mod;
    }
    for (int j=2; j<le; j++) {
      M[j][i] = (M[j][i] + M[j-1][i]) % mod;
    }
  }
  MODS[0] = 1;
  for (int j=1; j<le; j++) {
    MODS[j] = (MODS[j-1] * 10) % mod;
  }

  lazy_segtree<S, op, e, ll, mapping, composition, id> seg(A);

  // cout << seg.all_prod().v << '\n';
  rep(i, q) {
    cin >> l >> r >> d;
    seg.apply(l-1, r, d);
    cout << seg.all_prod().v << '\n';
  }
  
}

// 「#define _GLIBCXX_DEBUG」をコメントアウトしましたか？？

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);

  for (int i{}; i < N; ++i) {
    cin >> d[i];
  }
  sort(d.begin(), d.end());

  cout << d[N / 2] - d[N / 2 - 1] << endl;
  return 0;
}


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

using namespace std;

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

  int n, x;
  cin >> n >> x;

  int a = x;
  int m;
  int sum = 0;
  for  (int i = 0; i < n; ++i) {
    cin >> m;
    sum += m;
    a = min(a, m);
  }
  cout << n + (x - sum) / a << endl; 

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define NOT_FOUND -1
int n,q;

int main(){
  int i,a,count=0;
  
  scanf("%d",&n);
  int s[n];

  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }
  
  scanf("%d",&q);
  int t[q];

  for(i=0;i<q;i++){
    scanf("%d",&t[i]);
  }

  for(i=0;i<q;i++){
    a = binarySearch(s,t[i]);
    if(a != -1){
      count++;
    }
  }

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

  return 0;
  
}

int binarySearch(int *A,int key){
  int left=0,right=n,mid;
  while(left<right){
    mid = (left+right)/2;
    if(key == A[mid]){
      return mid;
    }
    if(key > A[mid]){
      left=mid+1;
    }
    else if(key < A[mid]){
      right = mid;
    }
  }
  return NOT_FOUND;
}



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

typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

#define DEBUG

// bool check(ll x){
//     ll n = 1;
//     while(n <= x){
//         n *= 10;
//     }
//     n /= 10;
//     ll dig = x / n;
//     x %= n;
//     n /= 10;
//     while(n > 0){
//         if(abs(x/n - dig) <= 1){
//             // ok
//         }else{
//             return false;
//         }
//         dig = x/n;
//         x %= n;
//         n /= 10;
//     }
//     return true;
// }

void print(vec<ll> xs){
    for(auto iter: xs){
        cout << iter;
    }
    cout << endl;
}

void solve(long long K){
    vec<vec<ll>> runrun{{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}};
    ll cnt = 0;
    while(true){
        if(runrun.size() >= K){
            print(runrun.at(K-1));
            break;
        }
        for(int i=0; i <= 9; i++){
            if(abs(runrun.at(cnt).back() - i) <= 1){
                vec<ll> temp = runrun.at(cnt);
                temp.push_back(i);
                runrun.push_back(temp);
            }
        }
        cnt++;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


Measured memory_bytes: 11464
#include<stdio.h> 
#include<vector>
#include<set>
#include<string>
#include<iostream>
using namespace std;

int main(){
string st1,st2;
cin>>st1>>st2;
//printf("%d %d",st1.length(),st2.length()); 
int a=st1.length();
int b=st2.length();
int count=b;
int j1=b-1;
while(count--&&j1>=0){
	int i=0;
	int j=j1;
	while(st1[i]==st2[j]&&i<a){
		i++;
		j=(j+1)%b;
	}
	if(i==a){
		
		printf("Yes");
		return 0;
		
	}
	j1--;
}
printf("No");
	return 0;
}

Measured memory_bytes: 256
/**
 * @author karayuu
 */
fun main(args: Array<String>) {
    val string = readLine()!!
    val list = mutableListOf<Int>()
    ('a'..'z').forEach { character ->
        list.add(string.count { it == character })
    }

    if (list.isSame()) print("Yes") else print("No")
}

fun MutableList<Int>.isSame() : Boolean {
    for (j in this) {
        if (!j.isEven()) return false
    }
    return true
}

fun Int.isEven() : Boolean = this % 2 == 0

Measured memory_bytes: 33784
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }

int n, m;

vector<int> amida(const vector<int>& a) {
	vector<int> res;
	res.reserve(n);
	for(int i = 0; i < n; ++i) {
		int pos = i;
		for(int j = 0; j < m; ++j) {
			if(pos == a[j]) {
				--pos;
			}
			else if(pos + 1 == a[j]) {
				++pos;
			}
		}
		res.emplace_back(pos);
	}

	return res;
}

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

	cin >> n >> m;

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

	vector<int> goals = amida(a);

	sort(a.begin(), a.end());
	int ans = INT_MAX;

	do {
		if(goals == amida(a)) {
			vector<int> h(n + 1, 0);
			for(int i = 0; i < m; ++i)
				h[a[i]] = max({h[a[i] - 1], h[a[i]], h[a[i] + 1]}) + 1;

			chmin(ans, *max_element(h.begin(), h.end()));
		}
	} while(next_permutation(a.begin(), a.end()));

	cout << ans << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <time.h>
#include <fstream>
#include <map>

using namespace std;

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

	for(int i = 0; i < n; i++){		
		cin>>a[i]>>b[i];
	}
	sort(a.rbegin(), a.rend());
	sort(b.rbegin(), b.rend());
	int atts = 0;
	for(int i = 0; i < n; i++){
		if (b[i] < a[0]) break;
		h -= b[i];
		atts++;
		if (h <= 0){
			cout<<atts<<endl;
			return 0;
		}
	}
	atts += (h + a[0] - 1)/a[0];
	cout<<atts;
	return 0;
}


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

using namespace std;

int main(){
    int N;
    int dp[100001];
    cin>>N;
    for(int i=1; i<=N; i++){
        dp[i]=dp[i-1]+1;
        for(int j=6; j<=i; j*=6) dp[i]=min(dp[i],dp[i-j]+1);
        for(int j=9; j<=i; j*=9) dp[i]=min(dp[i],dp[i-j]+1);
    }
    cout<<dp[N]<<endl;
}

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

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

  int card[4][13] = {
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
  };
  // 絵柄を数字と対応。0:S, 1:H, 2:C, 3:D

  char mark;
  int num;

  for(int i=0;i<n;i++){
    cin >> mark >> num;

    switch(mark){
      case 'S':
        card[0][num-1] = 0;
        break;
      case 'H':
        card[1][num-1] = 0;
        break;
      case 'C':
        card[2][num-1] = 0;
        break;
      case 'D':
        card[3][num-1] = 0;
        break;
    }
  }

  // for(int j=0;j<4;j++){
  //   for(int k=0;k<13;k++){
  //     cout << card[j][k] << " ";
  //   }
  //   cout << endl;
  // }

  for(int j=0;j<4;j++){
    for(int k=0;k<13;k++){
      if(card[j][k] == 1){
        switch(j){
          case 0:
            cout << 'S' << " " << k+1 << endl;
            break;
          case 1:
            cout << 'H' << " " << k+1 << endl;
            break;
          case 2:
            cout << 'C' << " " << k+1 << endl;
            break;
          case 3:
            cout << 'D' << " " << k+1 << endl;
            break;
        }
      }
    }
  }
}



Measured memory_bytes: 3120
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
long long co[200010] = { 0 };
stack<int> dfs;
int main() {
	int n, q, a, b, p, x;
	cin >> n >> q;
	vector<vector<int>> g(n + 1);
	bool root[200010] = { false };
	for (int c = 0; c < n - 1; c++) {
		cin >> a >> b;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	for (int d = 0; d < q; d++) {
		cin >> p >> x;
		co[p] += x;
	}
	dfs.push(1);
	root[1] = true;
	while (1) {
		if (dfs.empty()) {
			break;
		}
		int t = dfs.top();
		if (g[t].empty()) {
			dfs.pop();
			continue;
		}
		for (int i = 0; i < g[t].size(); i++) {
			if (root[g[t][i]] == false) {
				dfs.push(g[t][i]);
				root[g[t][i]] = true;
				co[g[t][i]] += co[t];
			}
		}
		for (int j = 0; j <= g[t].size(); j++) {
			g[t].pop_back();
		}
	}
	for (int k = 1; k <= n; k++) {
		cout << co[k];
		if (k != n) {
			cout << " ";
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 16500
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int sum = 0;
  int x;
  cin>>x;
  if(x<4)
    sum += (4-x)*100000;
  
  cin>>x;
  if(x<4)
    sum += (4-x)*100000;
  
  if(sum==600000)
    sum += 400000;
  
  cout << sum << endl;
    
}

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

using namespace std;

typedef long long ll;
int n;
int sub;
ll res;
ll A[100100];
char op[100100];

ll calc(int s) {
	if (s==n) return 0;
	if (s==n-1||op[s+1]=='-') return A[s];
	int p; ll tmp = A[s];
	for (p=s+1;p<n&&op[p]=='+';p++) {
		tmp += A[p];
	}
	return min(A[s]+calc(p),tmp);
}

int main() {
	int i;

	scanf("%d",&n);
	for (i=0;i<n;i++) {
		if (i==0) scanf("%lld",&A[i]);
		else scanf(" %c %lld",&op[i],&A[i]);
	}
	for (i=0;i<n;i++) res += A[i];
	for (i=1;i<n;i++) if (op[i]=='-') break;
	if (i==n) {
		printf("%lld\n",res);
		return 0;
	}
	printf("%lld\n",res-2*calc(i));

    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define inf (int)(3e18)
#define P pair<int,int>
#define int long long
using namespace std;
int n;
int ans[500][500];
signed main(){
	cin>>n;
	int k=ceil(sqrt(2*n));
	rep(i,k)ans[0][i]=i+1;
	for(int i=1;i<k;i++){
		for(int j=0;j<i;j++)ans[i][j]=ans[j][i-1];
		for(int j=i;j<k-1;j++)ans[i][j]=ans[i-1][k-2]+(j-i+1);
	}
	if(k*(k-1)/2!=n)puts("No");
	else {
		puts("Yes");
		cout<<k<<endl;
		rep(i,k){
			cout<<k-1<<" ";
			rep(j,k-1)cout<<ans[i][j]<<" ";
			cout<<endl;
		}
	}
}

Measured memory_bytes: 3200
#include <iostream>
#include <string>

using namespace std;

bool rev(string s){
    bool ret = true;
    for(int i=0;i<s.length()/2;i++){
        ret &= s[i] == s[s.length()-1-i];
    }
    return ret;
}

int main(void){
    string S;
    bool res = true;
    cin >> S;
    res &= rev(S);
    res &= rev(S.substr(0,(S.length()-1)/2));
    res &= rev(S.substr((S.length()+3)/2-1));
    cout << (res ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1 << 30;
const ll MOD = 1000000007;
int main(void) {
  int r;
  cin >> r;
  cout << r * r * r << endl;

  return 0;
}


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

int main(){
  int r, D;
  cin >>r >>D;
  vector<int> mo(11);
  cin >>mo.at(0);
  
  for(int t = 0;t<10;t++){
    mo.at(t+1) =mo.at(t)*r-D;
    cout <<mo.at(t+1)<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define per(i,m,n) for(int i=m;i>=n;i--)
#define si(x) scanf("%d",&x)
#define pi(x) printf("%d",x)
#define sl(x) scanf("%lld",&x)
#define pl(x) printf("%lld",x)
const int N = 1e6+10;
const int mod = 1e9+7;
#define maxn 1000086

const int inf=1<<30;

int main() {
    int n,a=-inf,b=inf,c=-inf,d=inf;
    for(scanf("%d",&n);n--;) {
        int x,y;
        scanf("%d%d",&x,&y);
        a=max(a,x+y);
        b=min(b,x+y);
        c=max(c,x-y);
        d=min(d,x-y);
    }
    pi(max(a-b,c-d));
    return 0;
}


Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N;
	cin >> N;
	vector<ll> A(N);
	for (int i = 0; i < N; i++)cin >> A[i];
	sort(A.begin(), A.end());
	vector<ll> B(N);
	B[0] = A[0];
	for (int i = 0; i < N - 1; i++)B[i + 1] = B[i] + A[i + 1];
	ll ans = 1;
	for (int i = N - 2; i >= 0; i--) {
		if (B[i] * 2 >= A[i + 1])ans++;
		else break;
	}
	cout << ans << endl;
	return 0;
}

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

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

    int N;
    cin >> N;

    if(N <= 999){
        cout << "ABC" << "\n";
    }
    else{
        cout << "ABD" << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline


class SegTree():
    # ここでは操作の都合上根元のindexを1とする
    def __init__(self, lists, function, basement):
        self.n = len(lists)
        self.K = (self.n-1).bit_length()
        self.f = function
        self.b = basement
        self.seg = [basement]*2**(self.K+1)
        X = 2**self.K
        for i, v in enumerate(lists):
            self.seg[i+X] = v
        for i in range(X-1, 0, -1):
            self.seg[i] = self.f(self.seg[i << 1], self.seg[i << 1 | 1])

    def update(self, k, value):
        X = 2**self.K
        k += X
        self.seg[k] = value
        while k:
            k = k >> 1
            self.seg[k] = self.f(self.seg[k << 1], self.seg[(k << 1) | 1])

    def query(self, L, R):
        num = 2**self.K
        L += num
        R += num
        vL = self.b
        vR = self.b
        while L < R:
            if L & 1:
                vL = self.f(vL, self.seg[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.f(self.seg[R], vR)
            L >>= 1
            R >>= 1
        return self.f(vL, vR)


def main():
    N = int(input())
    S = list(input())
    Q = int(input())
    que = [tuple(input().split()) for i in range(Q)]
    alpha = "abcdefghijklmnopqrstuvwxyz"
    Data = {alpha[i]: [0]*N for i in range(26)}
    for i in range(N):
        Data[S[i]][i] += 1
    SEG = {alpha[i]: SegTree(Data[alpha[i]], max, 0) for i in range(26)}
    for X, u, v in que:
        if X == "1":
            u = int(u)-1
            NOW = S[u]
            S[u] = v
            SEG[NOW].update(u, 0)
            SEG[v].update(u, 1)
        else:
            u, v = int(u)-1, int(v)-1
            res = 0
            for j in range(26):
                res += SEG[alpha[j]].query(u, v+1)
            print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 391392
/*
 $ Viole
 @ 19.09.2020 18:01:23 IST
*/






#include <bits/stdc++.h>   


#define for0(i, n) for (int i = 0; i < (int)(n); ++i) 
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) 
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) 
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) 
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) 


#define pb push_back
#define fi first
#define se second


#define all(x) (x).begin(), (x).end() 
#define rall(x) (x).rbegin, (x).rend() 

#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)


#define present(c,x) ((c).find(x) != (c).end())


#define cpresent(c,x) (find(all(c),x) != (c).end())

#define sz(a) int((a).size())


using namespace std;


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
    
    string s;
    getline(cin, s);
    vector<char> vc(s.begin(), s.end());
    int n = vc.size();
    if( vc[n-1] == 's'){
    vc.push_back('e'); vc.push_back('s');
    for( auto i = vc.begin(); i != vc.end(); i++)
    cout<< *i;
 }
    else
   { vc.push_back('s');
     for( auto i = vc.begin(); i != vc.end(); i++)
    cout<< *i;
}    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 3576
#include <stdio.h>

int main(){
  int x, y, n, m;

  scanf("%d%d",&x,&y);

  while(1){
    n = x%y;
    if(n == 0)break;
    x = y;
    y = n;
  }
  printf("%d\n",y);
  return 0;
}



Measured memory_bytes: 2128