akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}


// end of Template
int st,fn,ans;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    st = max(a,c);
    fn = min(b,d);
    ans = max(0,fn-st);
    cout<<ans<<newl;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]

    ans = 0
    for idx in range(N):
        for inc in range(2):
            if A[idx+inc] <= B[idx]:
                ans += A[idx+inc]
                B[idx] -= A[idx+inc]
                A[idx+inc] = 0
            else:
                ans += B[idx]
                A[idx+inc] -= B[idx]
                B[idx] -= B[idx]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 81892
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
S=input()
rt,gt,bt=S.count("R"),S.count("G"),S.count("B")
R,G,B=[],[],[]
rc,gc,bc=0,0,0
ans=0
for i in range(n):
  if S[i]=="R":
    ans+=gc*(bt-bc)+bc*(gt-gc)
    for b in B:
      if 2*i-b<n and S[2*i-b]=="G":
        ans-=1
    for g in G:
      if 2*i-g<n and S[2*i-g]=="B":
        ans-=1
    R.append(i)
    rc+=1
  elif S[i]=="G":
    ans+=rc*(bt-bc)+bc*(rt-rc)
    for b in B:
      if 2*i-b<n and S[2*i-b]=="R":
        ans-=1
    for r in R:
      if 2*i-r<n and S[2*i-r]=="B":
        ans-=1
    G.append(i)
    gc+=1
  else:
    ans+=gc*(rt-rc)+rc*(gt-gc)
    for r in R:
      if 2*i-r<n and S[2*i-r]=="G":
        ans-=1
    for g in G:
      if 2*i-g<n and S[2*i-g]=="R":
        ans-=1
    B.append(i)
    bc+=1
print(ans)




Measured memory_bytes: 9332
import collections
import queue


class Dinic:
    def __init__(self, N):
        self.N = N
        self.edges = collections.defaultdict(list)
        self.level = [0 for _ in range(self.N)]
        self.iter = [0 for _ in range(self.N)]

    def add(self, u, v, c, directed=True):
        """
        0-indexed
        u = from, v = to, c = cap
        directed = Trueなら、有向グラフである
        """
        if directed:
            self.edges[u].append([v, c, len(self.edges[v])])
            self.edges[v].append([u, 0, len(self.edges[u])-1])
        else:  # TODO
            self.edges[u].append([v, c, len(self.edges[u])])

    def bfs(self, s):
        self.level = [-1 for _ in range(self.N)]
        self.level[s] = 0
        que = queue.Queue()
        que.put(s)
        while not que.empty():
            v = que.get(s)
            for i in range(len(self.edges[v])):
                e = self.edges[v][i]
                if e[1] > 0 and self.level[e[0]] < 0:
                    self.level[e[0]] = self.level[v] + 1
                    que.put(e[0])

    def dfs(self, v, t, f):
        if v == t:
            return f
        for i in range(self.iter[v], len(self.edges[v])):
            self.iter[v] = i
            e = self.edges[v][i]
            if e[1] > 0 and self.level[v] < self.level[e[0]]:
                d = self.dfs(e[0], t, min(f, e[1]))
                if d > 0:
                    e[1] -= d
                    self.edges[e[0]][e[2]][1] += d
                    return d
        return 0

    def maxFlow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            if self.level[t] < 0:
                return flow
            self.iter = [0 for _ in range(self.N)]
            f = self.dfs(s, t, float('inf'))
            while f > 0:
                flow += f
                f = self.dfs(s, t, float('inf'))


X, Y, E = map(int, input().split())

graph = Dinic(X+Y+2)
s = X+Y
t = X+Y+1
for i in range(X):
    graph.add(s, i, 1)

for i in range(Y):
    graph.add(X+i, t, 1)

for _ in range(E):
    x, y = map(int, input().split())
    graph.add(x, X+y, 1)

print(graph.maxFlow(s, t))


Measured memory_bytes: 8732
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < A[i].size(); j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

template < typename A, size_t N, typename T >
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	int D, T, S;
	cin >> D >> T >> S;
	if (D - T * S > 0) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		while(true) {
			
		    //入力
			int n = scanner.nextInt();		
			int x = scanner.nextInt();
			
			if ((n == 0) && (x == 0)) {
				
				break;
				
			}
			
			int sum = 0;
			
			for(int i= 1; i <= n -2; i++) {
				
				for(int j = i + 1; j <= n -1; j++) {
					
					if(x < i + j) {
						break;
					}
					
					for(int k = j + 1; k <= n; k++) {
						
						if(i + j + k > x) {
							break;
						}
						
						if(i + j + k == x) {
							sum += 1;
						}
						
					}
				}
				
			}
			
			System.out.println(sum);
			
		}
		
	}
}


Measured memory_bytes: 26544
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n, k; cin >> n >> k;
    vector<int> l(n);
    rep(i, n) cin >> l[i];

    sort(l.begin(), l.end(), greater<int>());
    int ans = 0;
    rep(i, k) {
        ans += l[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}

int main() {
	string N,M;
	cin >> N>>M;
	if (N == "ABC") {
		N = "ARC";
	}
	else {
		N = "ABC";
	}


	cout<<  N<<endl;
}


Measured memory_bytes: 3632
A, B, K = map(int, input().split())
ans = []
for i in range(A,A+K):
  if i<=B and i not in ans:
    ans.append(i)
for i in range(B-K+1,B+1):
  if i>=A and i not in ans:
    ans.append(i)
print(*ans, sep='\n')



Measured memory_bytes: 3060
n,d=map(int,input().split())
l=[i**2 for i in range(130)]
set_l=set(l)
cnt=0
X=[list(map(int,input().split())) for i in range(n)]
from itertools import combinations
comb=list(combinations(range(0,n),2))
for pair in comb:
    v=0
    for j in range(d):
        v+=(X[pair[0]][j] - X[pair[1]][j])**2
    if v in set_l:
        cnt+=1
print(cnt)    

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

int main(){
    using namespace std;
    constexpr unsigned long MOD = 1000000007;
    // 冪剰余 a^n mod MOD
    const auto& modpow = [](unsigned long a, unsigned long n) -> unsigned long {
        unsigned long r{1};
        while(n){
            if(n & 1)(r *= a) %= MOD;
            (a *= a) %= MOD;
            n >>= 1;
        }
        return r;
    };

    unsigned long N, K;
    cin >> N >> K;

    vector<unsigned long> v(K + 1);
    // v[i] = floor(K/i)^N で初期化
    for(unsigned long i{1}; i <= K; ++i)v[i] = modpow(K / i, N);
    // 正しい v[i] を計算していきます
    // 素因数 p でまとめて小さいほうから計算します
    // 処理はエラトステネスの篩のように行います
    vector sieve(K + 1, 1);
    for(unsigned long p{2}; p <= K; ++p)if(sieve[p]){
        // p は素数
        for(unsigned long i{1}; i * p <= K; ++i){
            sieve[i * p] = 0;
            (v[i] += MOD - v[i * p]) %= MOD;
        }
    }

    // ans = Σ i v[i]
    unsigned long ans{0};
    for(unsigned long i{0}; i <= K; ++i)ans += i * v[i];
    cout << ans % MOD << endl;

    return 0;
}

Measured memory_bytes: 4576
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S,T;
  cin>>S;
  cin>>T;
  int ans=0;
  for (int i=0;i<3;i++){
    if (S[i]==T[i]){
      ans++;

    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long a, b, c=0, d, e, f, g, h, i, j, k, l, m, n, o, p, x=0, y, z;
d=0;
cin>>n;
for(i=0;i<n;i++)
		{

cin>>a>>b;
if(a==b) 
{ 

 
d++;
} 
else d=0;
		
if(d>=3)
   x=1;



			} 

if(x==1) 
cout<<"Yes" <<endl;
else cout <<"No" <<endl;

} 

Measured memory_bytes: 3640
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
  int n, k, p[1010], ans=0;
  scanf("%d%d", &n, &k);
  for(int i=0;i<n;i++) scanf("%d", &p[i]);
  sort(p, p+n);
  for(int i=0;i<k;i++) ans += p[i];
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)
#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
#define popcountL __builtin_popcountll
#define popcount __builtin_popcount
/// int other=mask^((1<<n)-1);
typedef long long ll;
typedef long long int lln;
ll INF=1<<28;
//typedef long long lld;
const double pi=acos(-1.0);
int fx[]={1,-1,0,0}; //direction array
int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
const long double EPS=1e-7;
//#define INF 10000
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}

bool cmp(int a, int b)
{
    return a<b;
}
struct compare
{
  bool operator()(const int& l, const int& r)
  {
      return l>r;
  }
};
int on(int mask,int pos)
{
    return mask|(1<<pos);
}
int off(int mask,int pos)
{
    return mask&(~(1<<pos));
}
//bool check(int mask,int pos)
//{
//    return mask&(1<<pos);
//}
ll inf=1e18;
//ll mod=1e9+7;
ll mod=993344777;
ll arr[2000];
const int sz=300005;

int main(void){
    int n,k;
    sf(n);
    int a,b;
    sf2(a,b);
    cout<<min(a,b)<<" ";
    cout<<max(0,(a+b)-n)<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
     
#define int  long long
#define endl '\n'
const int MOD = 1e9 + 7;
const int INF = 1e18;

void solve(){
 int r;
 cin >> r;
 cout << r * r << endl;
}

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  solve();	
}


Measured memory_bytes: 256
#include <stdio.h>
#define Large 200000000
struct Card {
  char s;
  int val;
};

struct Card L[50002],R[50002];

void merge1(struct Card A[],int n,int l,int m,int r){
  int n1,n2,i;
  n1=m-l;     //?????´???????????¨
  n2=r-m;     //?????´???????????¨
  for(i=0;i<n1;i++){
    L[i]=A[l+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[m+i];
  }
  L[n1].val=Large;
  R[n2].val=Large;
  int i1=0,i2=0,j;
  for(j=l;j<r;j++){
    if(L[i1].val<=R[i2].val){
      A[j]=L[i1];
      i1++;
    }else{
      A[j]=R[i2];
      i2++;
    }
  }
}

void mergeSort(struct Card A[],int n,int l, int r){
  int m;
  if(l+1<r){
      m=(r+l)/2;
      mergeSort(A,n,l,m);
      mergeSort(A,n,m,r);
      merge1(A,n,l,m,r);
  }
}
int partition(struct Card A[],int n,int p, int r){
    int i,j;
    struct  Card x,kari;
    x=A[r];
    i=p-1;
    for(j=p;j<r;j++){
      if(A[j].val<=x.val){
        i++;
        kari=A[i];
        A[i]=A[j];
        A[j]=kari;
      }
    }
    kari=A[i+1];
    A[i+1]=A[r];
    A[r]=kari;
    return i+1;
}
void quickSort(struct Card A[],int n,int p, int r){
  int q;
  if(p<r){
    q=partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main(int argc, char const *argv[]) {
  int n,i,v;
  struct Card A[100000],B[100000];
  char S[10];
  int flag=1;

  scanf("%d",&n);

  for (i = 0; i < n; i++) {
    scanf("%s %d", S,&v);
    A[i].s=B[i].s=S[0];
    A[i].val=B[i].val=v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].s!=B[i].s) flag=0;
  }
  if(flag==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",B[i].s,B[i].val);
  }
  return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    
    vector<int> p(n,0);
    rep(i,n) cin >> p[i];
    sort(p.begin(),p.end());
    long long ans = 0;
    rep(i,k) ans += p[i];
    cout << ans << endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
#define EPS (1E-10)
const int maxn=100000+10;
int n;

struct Point
{
    double x,y;
    Point() {}
    Point(double _x,double _y):x(_x),y(_y) {}
    Point operator -(Point p)
    {
        return Point(x-p.x,y-p.y);
    }
    bool operator <(Point p)
    {
        return x==p.x?y<p.y:x<p.x;
    }
    double cross(Point p)
    {
        return x*p.y-y*p.x;
    }
    double dot(Point p)
    {
        return x*p.x+y*p.y;
    }
    double norm()
    {
        return x*x+y*y;
    }
    double abs()
    {
        return sqrt(norm());
    }

};
 struct Article
{
    Point o;
    double r;
};
Article article1,article2;

void intersect_cc(Article article1,Article article2)
{
    Point OO=article2.o-article1.o;
    double t=atan2(OO.y,OO.x);
    double ss=(article1.r*article1.r+OO.norm()-article2.r*article2.r)/(2*article1.r*OO.abs());
    double a=acos(ss);
    Point p1=Point(article1.o.x+article1.r*cos(t-a),article1.o.y+article1.r*sin(t-a));
    Point p2=Point(article1.o.x+article1.r*cos(t+a),article1.o.y+article1.r*sin(t+a));
    if(p1.x>p2.x) swap(p1,p2);
    else if(p1.x==p2.x&&p1.y>p2.y) swap(p1,p2);
    printf("%.8lf %.8lf %.8lf %.8lf\n",p1.x,p1.y,p2.x,p2.y);
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%lf%lf%lf",&article1.o.x,&article1.o.y,&article1.r);
    scanf("%lf%lf%lf",&article2.o.x,&article2.o.y,&article2.r);
    intersect_cc(article1,article2);

    return 0;

}

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

int main()
{
	int A, B, K;
	cin >> A >> B >> K;
	for (int i = 0;i < K;) {
		if (i % 2 == 0) {
			if (A % 2 == 1) {
				A -= 1;
			}
			else if (A % 2 == 0) {
				A /= 2;
				B += A;
				i++;
			}
		}
		else {
			if (B % 2 == 1) {
				B -= 1;
			}
			else if (B % 2 == 0) {
				B /= 2;
				A += B;
				i++;
			}
		}
	}
	cout << A<<" "<<B<<endl;  
	return 0;
}

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


int main(){
  ll n; cin>>n;
  vector<ll>a(n);
  for(ll i=0;i<n;i++){
    cin>>a[i];
  }
  ll m=a[0];
  ll ans=0;
  for(ll i=1;i<n;i++){
    if(a[i]>=m){
      m=a[i];
    }else{
      ans+=m-a[i];
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        BigInteger n = new BigInteger(scan.next());
        System.out.println(n.remainder(new BigInteger("9")).toString().equals("0") ? "Yes" : "No");
    }

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


Measured memory_bytes: 41988
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    h, w = list(map(int, ipti().split()))
    ans = 0
    ans += ((w + 1) // 2) * ((h + 1) // 2)
    ans += (w // 2) * (h // 2)

    if h == 1 or w == 1:
        ans = 1

    print(ans)


if __name__ == '__main__':
    main()

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

int main() {
    int n; cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) cin >> d[i];
    sort(d.begin(), d.end());
    int ans = 0;
    for (int i = d[n / 2 - 1]; i < d[n / 2]; i++) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 640
import java.io.*;
import java.util.*;

public class Main{
    public static void main(String args[]) throws IOException{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));


	Stack stack=new Stack(1000);
	
	String str[]=br.readLine().split(" ");

	for(int i=0;i<str.length;i++){
	    if ( str[i].equals("+")){
		int a=stack.pop();
		int b=stack.pop();
		stack.push(b+a);
	    } else if ( str[i].equals("-") ){
		int a=stack.pop();
		int b=stack.pop();
		stack.push(b-a);
	    } else if ( str[i].equals("*")){
		int a=stack.pop();
		int b=stack.pop();
		stack.push(b*a);
	    } else {
		int x = Integer.parseInt(str[i]);
		stack.push(x);
	    }
	}
	System.out.println(stack.pop());
    }
}
class Stack{
    int top;
    final int MAX;
    int S[];
    
    public Stack(int MAX){
	top=0;
	this.MAX=MAX;
	S=new int[MAX];
    }
    public boolean isEmpty(){
	return top==0;
    }

    public boolean isFull(){
	return top>=MAX-1;
    }

    public void push(int x){
	if(!isFull()){
	    top++;
	    S[top]=x;
	}
    }
    public int pop(){
	if(!isEmpty()){
	    top--;
	    return S[top+1];
	}
	return -1;
    }
}



Measured memory_bytes: 24300
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main(void){
	char input[1000];
	int n, m;
	int i, j;
	int *vectorA;
	int *vectorb;
	int *vectorc;
	fgets(input, sizeof(input), stdin);
	n = atoi(strtok(input, " "));
	m = atoi(strtok(NULL, " "));
	vectorA = (int *)malloc(sizeof(int) * n * m);
	vectorb = (int *)malloc(sizeof(int) * m);
	vectorc = (int *)malloc(sizeof(int) * n);
	for (j = 0; j < n; j++){
		fgets(input, sizeof(input), stdin);
		for (i = 0; i < m; i++){	
			if(i == 0){
				vectorA[j * m + i] = atoi(strtok(input, " "));
			}else{
				vectorA[j * m + i] = atoi(strtok(NULL, " "));
			}
		} 	
	}
 
	for (i = 0; i < m; i++){
		fgets(input, sizeof(input), stdin);
		vectorb[i] = atoi(input) ;
	}

	for (j = 0; j < n; j++){
		for (i = 0; i < m; i++){	
				vectorc[j] += vectorA[j * m + i] * vectorb[i];
		} 	
	}
 
	for (j = 0; j < n; j++){
		printf("%d\n", vectorc[j]);
	}
	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x,0,sizeof(x))
#define all(a)      a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
/*---------------------------------------------------------------------------------------------------*/


void solve()
{
  int n,ans=0;
  cin >> n;
  vector<int> dp(n);
  fp(i,1,n)
    dp[i]=1;
  fp(i,2,n)
  {
      for(int j=i;j<=n;j+=i)
      {
          dp[j]++;
      }
  }
  fp(i,1,n)
   ans+=(i*dp[i]);
  cout << ans << '\n';
  return;
} 

signed main()
{
  FAST
  int T=1;
//   cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 81328
class Node
  attr_accessor :key, :left, :right, :parent
end

def print_heap(heap)
  heap.each.with_index(1) do |node, i|
    print "node #{i}: key = #{node.key},"
    print " parent key = #{heap[node.parent].key}," if node.parent
    print " left key = #{heap[node.left].key}," if heap[node.left]
    print " right key = #{heap[node.right].key}," if heap[node.right]
    print " \n"
  end
end

_n = gets
heap_keys = gets.split.map(&:to_i)
heap = []

heap_keys.each.with_index(1) do |e, i|
  node = Node.new
  node.key = e
  node.left = i * 2 - 1
  node.right = i * 2 + 1 - 1
  node.parent = i / 2 - 1 if i > 1

  heap.push(node)
end

print_heap(heap)



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

int main() {
    int m, nmin, nmax;
    while(cin >> m >> nmin >> nmax, m) {
        vector<int> p(m);
        for(int i = 0; i < m; ++i) {
            cin >> p[i];
        }
        sort(rbegin(p), rend(p));
        int val = 0;
        int ans = 0;
        for(int i = nmin - 1; i < nmax; ++i) {
            if(val <= p[i] - p[i + 1]) {
                val = p[i] - p[i + 1];
                ans = i + 1;
            }
        }

        cout << ans << endl;
    }
}



Measured memory_bytes: 3072
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * @author yousack
 */
public class Main {
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        int N = in.nextInt();
        Set<String> userSet = new HashSet<String>();
        for (int i = 0; i < N; i++) {
            userSet.add(in.next());
        }
        
        int M = in.nextInt();
        boolean locked = true;
        for (int i = 0; i < M; i++) {
            String user = in.next();
            if (userSet.contains(user)) {
                if (locked) {
                    System.out.println("Opened by " + user);
                } else {
                    System.out.println("Closed by " + user);
                }
                
                locked = !locked;
            } else {
                System.out.println("Unknown " + user);
            }
        }
    }
}

Measured memory_bytes: 20564
using System;

class P
{
public static void Main()
{
            bool z = true;
            
            while(z)
            {
                //?????????????????????
                string a = Console.ReadLine();

                //????????????????????????????????????
                var b = a.Split(' ');

                int A = Int32.Parse(b[0]);
                int B = Int32.Parse(b[1]);

                if (!(A == 0 & B == 0))
                {
                    if (A <= B)
                    {
                        Console.WriteLine(A + " " + B);
                    }
                    else
                    {
                        Console.WriteLine(B + " " + A);
                    }
                }
                else
                {
                    z = false;
                }

            }
}
}

Measured memory_bytes: 9244
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

int h, w;

ll func(ll h, ll w) {
	ll ans = 100005LL * 100005LL;
	for (ll i = 1; i < h; i++) {
		ll x = h - i;
		ll y = x / 2LL;
		ll z = (x + 1LL)/2LL;
		ll a1 = y*w, a2 = i*w, a3 = z*w;
		ll ma = max(max(a1, a2), a3);
		ll mi = min(min(a1, a2), a3);
		ans = min(ans, abs(ma-mi));
		y = w / 2LL;
		z = (w + 1LL) / 2LL;
		a1 = i*w; a2 = y*(h - i); a3 = z*(h - i);
		ma = max(max(a1, a2), a3);
		mi = min(min(a1, a2), a3);
		ans = min(ans, abs(ma - mi));

	}
	return ans;
}

int main(){
	cin >> h >> w;

	ll ans = func(h, w);
	ans = min(ans, func(w, h));
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	int ans = 0;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			for (int k = 0; k <=c; k++) {
				if (500 * i + 100 * j + 50 * k == x) ans++;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

int keta(int n) {
	if (n < 10)return 1;
	if (n < 100)return 2;
	if (n < 1000)return 3;
	if (n < 10000)return 4;
	if (n < 100000)return 5;
	if (n < 1000000)return 6;
	if (n < 10000000)return 7;
	if (n < 100000000)return 8;
}

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

	int ans = 0;
	REP(i, 1, n + 1) {
		if (keta(i) % 2 == 1) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
	int A, B;
	cin >> A >> B;
	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0) cout << "Possible" << endl;
	else cout << "Impossible" << endl;
}

Measured memory_bytes: 256
n=int(input())
s=[input() for _ in range(n)]
isFinishA=[s[i][-1]=='A' for i in range(n)]
isStartB=[s[i][0]=='B' for i in range(n)]
ans=0
for si in s:
    wasA=False
    for sij in si:
        if sij=='B':
            if wasA:
                ans+=1
        wasA=(sij=='A')
cnt=[isFinishA.count(True),isStartB.count(True)]
ans+=min(cnt)
fromBtoA=0
for i in range(n):
    if isFinishA[i] and isStartB[i]:
        fromBtoA+=1

if cnt[0]==cnt[1]==fromBtoA:
    if cnt[0]!=0:
        ans-=1
print(ans)


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;



int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            if(i * j == n) return cout << "Yes", 0;
        }
    }
    cout << "No";

    return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>

int main(){
    int a,b,c,result;
    scanf("%d %d %d", &a,&b,&c);
    if(a>b){
        result=a;
        a=b;
        b=result;}
    if(b>c){
        result=b;
        b=c;
        c=result;}
    if(a>b){
        result=a;
        a=b;
        b=result;
    }
    printf("%d %d %d\n",a,b,c);
}


Measured memory_bytes: 2048
#include<stdio.h>

int main(void){
	
    int x,d,s;
     
    while(scanf("%d",&d)!=EOF){
        s=0;
        x=d;
        while(x < 600){
            s += d * x*x;
            x += d;
        }
        printf("%d\n",s);
        
    }
    return 0;
}

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

V, E = map(int, input().split())

#dist[i][j]: i -> jへの距離
dist = [[float("inf")] * V for i in range(V)]
for _ in range(E):
    s, t, d = map(int, input().split())
    dist[s][t] = d

dp = [[-1] * V for i in range(2**V)]

#dp[s][v]: 集合sを経由して今vに居るとき、始点に戻る最短経路長
def rec(s, v, dp):
    #　計算済みかどうか
    if dp[s][v] >= 0:
        return dp[s][v]
    
    #　すべての頂点を訪れたか
    if s == 2**V - 1 and v == 0:
        dp[s][v] = 0
        return 0
    
    res = 10**100
    for i in range(V):
        if (s>>i & 1) == 0:
            # i の箇所が訪れていないとき（0の時）次はiに行く
            # s|(1<<i) は、今まで訪れたsに加えて、頂点iをおとずれたことを加えた和集合
            res = min(res, rec(s|(1<<i), i, dp) + dist[v][i])
    
    dp[s][v] = res
    return dp[s][v]

ans = rec(0, 0, dp)
if ans == 10**100:
    ans = -1
print(ans)


Measured memory_bytes: 15464
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    string X;
    cin>>X;
    int ans=X.size();
    int cou=0;
    rep(i,X.size()){
        if(X[i]=='S')cou++;
        else{
            if(cou>0){
                cou--;
                ans-=2;
            }
        }
    }
    cout << ans << endl;



}


Measured memory_bytes: 720
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <climits>
#include <queue>


#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
template<typename T1, typename T2>
inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2>
inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
const ll MOD = 1000000007;
const ll INF = 1LL << 60;



int main()
{
	ll a;
	long double b;
	cin >> a >> b;

	long double c;
	c = (long double)a * b;
	ll d;
	d = (ll)c;

	cout << d;
	


}

Measured memory_bytes: 3724
import sys

for line in sys.stdin:
    ll = list(map(int, line.split(',')))
    s = ll[:10]
    v1, v2 = ll[10], ll[11]
    p = sum(s) / (v1 + v2) * v1

    ss = 0
    for i, l in enumerate(s):
        ss += l
        if ss >= p:
            print(i + 1)
            break

Measured memory_bytes: 6732
#include <cstdio>
#include <algorithm>

using namespace std;

const int N=1e5+10;

struct Edge{ int to,next; };

Edge way[N<<1];
int n,tot,num[N],l[N],r[N],col[N],k;

void Build(int a,int b) { way[++tot]=(Edge){b,num[a]}; num[a]=tot; }

void Init()
{
	scanf("%d",&n);
	int a,b;
	for (int i=2;i<=n;++i)
	{
		scanf("%d%d",&a,&b);
		Build(a,b);
		Build(b,a);
	}
	for (int i=1;i<=n;++i) l[i]=-1e6,r[i]=1e6;
	scanf("%d",&k);
	for (int i=1;i<=k;++i)
	{
		scanf("%d%d",&a,&b);
		l[a]=r[a]=b;col[a]=b;
	}
}

void Dfs(int x,int fa)
{
	for (int i=num[x];i;i=way[i].next)
	{
		int v=way[i].to;
		if (v==fa) continue;
		l[v]=max(l[x]-1,l[v]);
		r[v]=min(r[x]+1,r[v]);
		Dfs(v,x);
	}
	if (fa)
	{
		l[fa]=max(l[x]-1,l[fa]);
		r[fa]=min(r[x]+1,r[fa]);
	}
}

bool use[2000010];
bool FindAns(int x,int fa)
{
	for (int i=num[x];i;i=way[i].next)
	{
		int v=way[i].to;
		if (l[v]==r[v]) use[l[v]+1000000]=1;
	}
	col[x]=l[x];
	while (use[col[x]+1000000] && col[x]<=r[x]) col[x]++;
	if (col[x]>r[x]) { col[x]=-1e7; return 0; }
	
	l[x]=r[x]=col[x];
	for (int i=num[x];i;i=way[i].next)
	{
		int v=way[i].to;
		if (l[v]==r[v]) use[l[v]+1000000]=0;
	}
	
	for (int i=num[x];i;i=way[i].next)
	{
		int v=way[i].to;
		if (v==fa) continue;
		l[v]=max(l[x]-1,l[v]);
		r[v]=min(r[x]+1,r[v]);
		if (!FindAns(v,x)) return 0;
	}
	return 1;
	
}

void Solve()
{
	Dfs(1,0);
	
	Dfs(1,0);
	
	bool fl=1;
	for (int i=1;i<=n;++i) if (l[i]>r[i]) fl=0;
	
	if (!fl) printf("No\n");
	else 
	{
		fl=FindAns(1,0);
		if (!fl) { printf("No\n"); return ; }
		printf("Yes\n");
		for (int i=1;i<=n;++i) printf("%d\n",col[i]);
	}
	
}

int main()
{
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 8704
n=input()
m=input()
x=len(n)

y=len(m)

dp=[[0 for i in range(y+1)] for j in range(x+1)]
#print(len(dp),len(dp[0]))
for i in range(0,x+1):
  for j in range(0,y+1):
    if(i==0 or j==0):
      dp[i][j]=0
    elif n[i-1]==m[j-1]:
      dp[i][j]=1+dp[i-1][j-1]
    else:
      dp[i][j]=max(dp[i-1][j],dp[i][j-1])
j=y
i=x
ans=""
#print(i,j)
while(i>0 and j>0):
  if dp[i][j]==dp[i-1][j]:
    i -= 1
  elif dp[i][j]==dp[i][j-1]:
    j -= 1
  else:
    ans = n[i-1]+ans
    i -= 1
    j -= 1
print(ans)

Measured memory_bytes: 119516
object Main extends App {
  val n = io.StdIn.readLine.toInt
  val as = io.StdIn.readLine.split(" ").map(_.toInt)
  var bs = new Array[Int](n)

  val bool = (n to 1 by -1).foldLeft(true)((b, i) => b match {
    case false => false
    case true => {
      val bb = (i * 2 to n by i).map(x => bs(x - 1)).sum & 1
      if (bb == as(i - 1)) {
        bs(i - 1) = 0
        true
      } else {
        bs(i - 1) = 1
        true
      }
    }
  })

  if (bool) {
    val bs2 = bs.zipWithIndex.filter(t => (t._1 & 1) == 1)
    println(bs2.length)
    println(bs2.map(t => t._2 + 1).mkString(" "))
  } else
    println(-1)
}


Measured memory_bytes: 124960
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;

int main() {

    vector<int>A(3);
    cin >> A[0]>>A[1]>>A[2];
   /* vector<int>A(N);
    for (int i = 0; i < N; i++) { cin >> A.at(i); }
    */
  sort(A.begin(),A.end());
  
    cout<<A[2]*10+A[1]+A[0]<<endl;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
typedef long long ll;
using namespace std;

int main()
{
	string s;
	cin >> s;
	int ans = 0;
	int cur = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i]=='A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G')
		{
			cur++;
		}
		else
		{
			ans = max(ans, cur);
			cur = 0;
		}
	}
	ans = max(ans, cur);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

using namespace std;

typedef long long lint;

void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

const lint MOD = 1000000007LL;
lint K2[100010];
lint F[100010];

lint mod_exp(lint a, int x)
{
    if (x == 0)
        return 1LL;
    if (x % 2 == 1)
        return mod_exp(a, x - 1) * a % MOD;
    lint ret = mod_exp(a, x / 2);
    return ret * ret % MOD;
};

lint f(int v, vector<vector<int> >& edges, int par, int K)
{
    int children = 0;
    lint prod = 1;
    for (int c : edges[v])
        if (c != par) {
            prod = prod * f(c, edges, v, K) % MOD;
            children++;
        }

    prod = K2[children] * prod % MOD;
    return F[children] * prod % MOD;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, K;
    cin >> N >> K;

    lint t = 1;
    for (int i = 0;i < K - 1;i++) {
        K2[i] = t;
        t = t * (K - 2 - i) % MOD;
        t = t * mod_exp(i + 1, MOD - 2) % MOD;
    }

    F[0] = 1LL;
    for (int i = 1;i <= K;i++)
        F[i] = F[i - 1] * i % MOD;

    vector<vector<int> > edges(N);
    for (int i = 0;i < N - 1;i++) {
        int a, b;
        cin >> a >> b;
        a--;b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    // K * (K - 1 choose children of root)
    int rootc = edges[0].size();
    lint ret = rootc == 0 ? 1 : 
                    (rootc > K - 1 ? 0 : (K2[rootc - 1] + K2[rootc]) % MOD);
    ret = K * 1LL * ret % MOD;
    ret = ret * F[rootc] % MOD;
    for (int c : edges[0])
        ret = ret * f(c, edges, 0, K) % MOD;
    cout << ret << endl;
    return 0;
};


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

typedef long long ll;
typedef vector<int> vint;
typedef vector<double> vdou;
typedef vector<string> vstr;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}

int main(){
  int n;
  cin >> n;
  
  vint p1(n), p2(n);
  cin >> p1; //vectorもシンプルにinできる
  
  std::copy(p1.begin(), p1.end(), p2.begin());
  
  std::sort(p1.begin(), p1.end());
  
  int count=0;
  for(int i=0; i<n; i++){
    if(p1[i]!=p2[i]){count++;}
  }
  
  if(count==2 or count==0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
using namespace std;

const int Maxn = 200000;

int main(){
    int n, m, vis[Maxn];
    while(~scanf("%d %d", &n, &m) && n){
        int flag = 0;
        memset(vis, 0, sizeof(vis));
        for(int i = 1; i <= m; i++){
            int u, v;
            scanf("%d %d", &u, &v);
            if(flag) continue;
            if(u == 1){
               if(vis[v]) flag = 1;
               else vis[v] = 1;
            }
            else if(v == 1) {
                if(vis[u]) flag = 1;
                else vis[u] = 1;
            }
            else if(v == n) {
                if(vis[u]) flag = 1;
                else vis[u] = 1;
            }
            else if(u == n) {
                if(vis[v]) flag = 1;
                else vis[v] = 1;
            }
        }
        if(flag) printf("POSSIBLE\n");
        else printf("IMPOSSIBLE\n");
    }
    return 0;
}

Measured memory_bytes: 896
//Program.cpp
//Author : Aaryan Srivastava 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#define pb push_back
#define popb pop_back
#define ull unsigned long long  
#define beg begin
#define mp make_pair
#define pii pair<int, int>
#define piii pair<pii,int>
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define ff first
#define ss second 
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using ll = long long;
#define int ll
const int N = 2*1e5 +5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace std;
#ifdef AaryanS
#define mycout cout
#define mycerr cerr 
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#define AaryanS 0 
#endif

vector<int> adj[100*1000 + 5];
pair<int,int> dfs(int u, int p=-1){
	int white_niggas = 1;
	int some_black_kid = 0;  
	for(auto it : adj[u]){
		if(it == p) continue;
		auto kid = dfs(it,u);
		int tmp = white_niggas%mod ; 
		white_niggas = (kid.second * white_niggas)%mod;
		some_black_kid = (tmp * (kid.first))%mod + (kid.second+kid.first)*some_black_kid%mod;  
	}
	return {white_niggas%mod, (some_black_kid + white_niggas)%mod} ;
}
void solve()
{
	int n ;
	cin >> n; 
	for(int i = 0 ; i < n - 1 ;++i){
		int x,y ;
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	cout << (dfs(1).ff + dfs(1).ss)%mod ;
}
    
int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case " << t << ":\n" ;
        solve();
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}


Measured memory_bytes: 12672
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main() {
	int M, D;
	cin >> M >> D;
	int a, ans = 0;
	for (int i = 10; i <= D; i++) {
		a = 0;
		if (i % 10 > 1 && i / 10 > 1) {
			a = (i % 10) * (i / 10);
		}
		if (a <= M && a > 0) {
			ans++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
void trace(int *, int);
void insertion(int *, int);





void trace(int A[], int N){
  int i;
  for(i=0;i<N;i++){
    if(i>=0){
      if(i==N-1)
      printf("%d\n",A[i]);
      else printf("%d ",A[i]);
 
    }
  }

}
  
void insertion(int A[],int N) {
  int j,i,v;
  for (i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j + 1]=A[j];
      j--;
    }
    A[j + 1]=v;
    trace(A, N);
  }
}

int main() {
  int N,i,j;
  int A[100];
  
    
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  
  trace(A, N);
  insertion(A, N);
  
  return 0;
}



Measured memory_bytes: 2080
#include <stdio.h>

int main() {
  int P, Q, R;
  scanf ("%d %d %d", &P, &Q, &R);
  if      (P>=Q && P>=R) printf ("%d\n", Q+R);
  else if (Q>=P && Q>=R) printf ("%d\n", P+R);
  else if (R>=P && R>=Q) printf ("%d\n", P+Q);
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int a = ni();
        int b = ni();
        int c = ni();
        int K = ni();
        int count = 0;
        while(b<=a){
            b *= 2;
            count++;
        }
        while(c<=b){
            c *= 2;
            count++;
        }
        if(count <= K) out.println("Yes");
        else out.println("No");
    }

    final int mod = 1000000007;
    final BigInteger MOD = BigInteger.valueOf(mod);
    int mul(int x, int y){
        int val = (int)((x * 1L * y) % mod);
        return val>=0 ? val : val+mod;
    }
    int add(int x, int y) {
        x += y;
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 32948
#include<stdio.h>
int N,i,f;
double x[11],ans;
char u[10][3];
int main(void){
    scanf("%d",&N);
    for(i = 0;i<N;i++){
        scanf("%lf",&x[i]);
        
        scanf("%s",u[i]);
        
    }
   
    for(i = 0;i<N;i++){
        if(u[i][0] > 'C'){
        ans += x[i];
        }else{
            ans += x[i]*380000;
        }
        
    }
    printf("%lf",ans);


}

Measured memory_bytes: 128