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

namespace AC {
#define ll long long
#define PLL pair<ll, ll>
#define PDD pair<double, double>
#define PDPLL pair<double, PLL>
#define PLPLL pair<ll, PLL>
#define pb push_back
#define fi first
#define se second
#define ls rt << 1
#define rs rt << 1 | 1

    const ll N = 2e5 + 66;

    ll BUGS = 1;

    inline ll read(){
        ll x = 0;    bool flag = 1;   char ch = getchar();
        while(ch < '0' || ch > '9') { if(ch == '-') flag = 0; ch = getchar(); }
        while(ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); }
        if(flag) return x;  return (~(x - 1));
    }

    inline void read(ll arr[], ll s, ll e) { for(ll i = s; i <= e; ++i) arr[i] = read(); }

    inline void write(ll x){
        if(x < 0) { x = ~(x - 1); putchar('-'); }
        if(x > 9) write(x / 10); putchar(x % 10 + '0');
    }

    inline void print(ll x) { write(x); puts(""); }

    inline void print(ll arr[], ll s, ll e) {
        for(ll i = s; i <= e - 1; ++i) write(arr[i]), putchar(' ');
        write(arr[e]); puts("");
    }

    inline ll max3(ll a, ll b, ll c) { return max(a, max(b, c)); }

    inline ll min3(ll a, ll b, ll c) { return min(a, min(b, c)); }

    inline void debugNum(ll num, string ss) { cout << "BUGS" << BUGS++ << " : " << ss << " : " << num << endl; }

    inline void debugArr(ll arr[], ll s, ll e, string ss) {
        cout << "BUGS" << BUGS++ << " : " << ss << " : " << endl;
        for(ll i = s; i <= e; ++i) cout << "i : " << i << " val : " << arr[i] << endl;
    }

    inline void IO() {
        //ios::sync_with_stdio(false), cout.tie(0), cin.tie(0);
        //cout << setiosflags(ios::fixed) << setprecision(1); //保留小数点后1位
        //cout << setprecision(1); //保留1位有效数字
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    }
}using namespace AC;

ll n, arr[N];

int main() {
    //IO();
    while(~scanf("%lld", &n)) {
        read(arr, 1, n);

        sort(arr + 1, arr + 1 + n);
        reverse(arr + 1, arr + 1 + n);

        ll ans = arr[1], cur = n - 2;
        for(ll i = 2; i <= n; ++i) {
            if(cur >= 2) {
                ans += 2 * arr[i];
                cur -= 2;
            } else {
                ans += cur * arr[i];
                break;
            }
        }

        print(ans);
    }
    return 0;
}



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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    // int q;
    // scanf("%d",&q);
    // while (q--){
    //     ll n,k,a,b;
    //     scanf("%lld%lld%lld%lld",&k,&n,&a,&b);
    //     k-=a*n;
    //     if(k>0)printf("%d\n",n);
    //     else{
    //         k*=-1;
    //         ll diff = a-b;
    //         ll cant = (k+diff)/diff;
    //         if(cant>n)puts("-1");
    //         else printf("%lld\n",n-cant);
    //     }
    // }
    ll n;
    scanf("%lld",&n);
    printf("%lld",(n*(n-1))/2);
    
    return 0;
}

Measured memory_bytes: 384
#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>;

const ll INF = 1e18;
const int MX = 2005;

int main() {
  int s , w;
  cin >> s >> w;
  if(s > w) cout << "safe" << endl;
  else cout << "unsafe" << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
long long a,b,c[200005],n,d,ans,x[200005],y[200005],l,k;
struct node
{
    long long x,y;
} w[200005];
inline bool cmp(node x,node y)
{
    return x.x<y.x;
}
int main()
{
    scanf("%lld%lld%lld",&n,&d,&a);
    d*=2;
    for(int i=1; i<=n; ++i)
    {
        scanf("%lld%lld",&w[i].x,&w[i].y);
        w[i].y=(w[i].y+a-1)/a;
    }
    sort(w+1,w+n+1,cmp);
    l=1;
    for(int i=1; i<=n; ++i)
    {
        while(l<i&&w[i].x-w[l].x>d)
            k-=c[l++];

        c[i]=w[i].y-k;
        if(c[i]<0)
            c[i]=0;
        ans+=c[i];
        k+=c[i];
    }
    printf("%lld",ans);
}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
void solve(){
	string s,t;
	cin>>s>>t;
	ll n=sz(s);
	ll res=n;
	for(ll i=0;i<n;i++){
		ll sum=0;
		if(i+sz(t)>n)
			break;
		for(ll j=0;j<sz(t);j++)
			if(s[i+j]!=t[j])
				sum++;
		res=min(res,sum);
	}
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++)
        solve();
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}

Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000
int a[300009],b[300009];

int main(){
  int n;
  int ans=INF;
  string s;
  cin>>n>>s;
  for(int i=1;i<=n;i++){
    a[i]=a[i-1];
    if(s[i-1]=='E')a[i]++;
  }
  for(int i=n;i>=1;i--){
    b[i]=b[i+1];
    if(s[i-1]=='W')b[i]++;
  }
  for(int i=1;i<=n;i++){
    ans=min(ans,n-a[i-1]-b[i+1]-1);
  }
  cout<<ans<<endl;
  return(0);
}


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


struct P
{
    //string r;
    int x;
    long long y,z;

   /* bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
              return y>a.y;
    }*/
};


vector<int> v[111];
//bitset<4001000> b;
int a,c,i,b,k,n,d,m;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int l[12];

int o[5][111455];
int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,-1,1,-1,1},dz[10]={0,0,0,0,1,-1};

int e;

long long x,y,mod=1000000007;
long long z[11];
P j[400];
P u[10],u1[100];
//stack<int> s;
//queue<int> q;
set<int> s;
priority_queue<int,vector<int>,greater<int> > q;
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
//list<int> l;
string r1,r;
//char r[5][111][111];
//deque<int> de;

//20921
bool as(P a,P b)
{
    return a.x<b.x;
}

int main()
{
    scanf("%d",&a);
    n=1987654321;
    for(int t=1;t<=a;t++)
    {
        scanf("%d %d",&b,&c);
        if(c<b) n=min(n,c);
        x+=c;
    }
    if(n==1987654321) puts("0");
    else printf("%lld",x-n);
}


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

ll dfs(ll pos, string ss) {
  ll ret = 0;
  if(pos == n) {
    string sub = "";
    for(int i=0;i<ss.size();i++) {
      if(ss[i] == '+') {
        ret += stoll(sub);
        sub = "";
      } else {
        sub += ss[i];
      }
    }
    ret += stoll(sub);
    return ret;
  }

  ret += dfs(pos+1, ss+s[pos]);
  if(pos > 0)
    ret += dfs(pos+1, ss+'+'+s[pos]);

  return ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s;
  n = s.size();
  cout << dfs(0, "") << endl;
}


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

//ライブラリ始まり

//定数

//円周率
const double PI = 3.1415926535897932384;

//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15

//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";

//関数

//ctoi
int ctoi(char c){
  if (c == '0') {
    return 0;
  }
  if (c == '1') {
    return 1;
  } 
  if (c == '2') {
    return 2;
  } 
  if (c == '3') {
    return 3;
  }
  if (c == '4') {
    return 4;
  } 
  if (c == '5') {
    return 5;
  } 
  if (c == '6') {
    return 6;
  }
  if (c == '7') {
    return 7;
  } 
  if (c == '8') {
    return 8;
  } 
  if (c == '9') {
    return 9;
  }
  return -1;  
}

//素数判定
bool PN(int x) {
  if (x <= 1) {
    return false;
  }
  if (x == 2) {
    return true;
  }
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

//ライブラリ終わり
 
int main() {
  int X1, Y1, X2, Y2;
  cin >> X1 >> Y1 >> X2 >> Y2;
  cout << X2 - (Y2 - Y1) << " " << Y2 + (X2 - X1) << " ";
  cout << X1 - (Y2 - Y1) << " " << Y1 + (X2 - X1) << endl;
}

Measured memory_bytes: 3648
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    d = i_input()
    c_list = i_list()
    s_list = i_row_list(d)

    for i in range(d):
        tmp = s_list[i][10] % 26 + 1
        if tmp <= 0:
            tmp = 1
        if tmp >= 27:
            tmp = 26
        print(tmp)

if __name__ == '__main__':
    main()


Measured memory_bytes: 72964
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

a,b,c = map(int, input().split())

ans = "No"

if a + b == c or a + c == b or b + c == a:
    ans = "Yes"

print(ans)


Measured memory_bytes: 9008
#include<cstdio>
#include<iostream>

using namespace std;

int a, b;
int gcd, lcm;

void GCD(){

	int big, small;

	big = a;
	small = b;

	while (big) {
		if (small > big) swap(big, small);
		big = big % small;
	}
	gcd = small;

}

void LCM() {
	lcm = a / gcd * b;
}




int main(){
	while (cin >> a >> b) {

		GCD();
		LCM();
		cout << gcd << " " << lcm << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
import heapq
T=int(input())

for _ in range(T):
  N=int(input())
  
  llist=[]
  rlist=[]
  base=0
  for _ in range(N):
    K,L,R=map(int,input().split())
    base+=min(L,R)
    if L>R:
      llist.append((K,L-R))
    elif L<R:
      rlist.append((N-K,R-L))
      
  llist.sort()
  rlist.sort()      
  #print(base)
  #print(llist)
  #print(rlist)
  
  hq_left=[]
  for i,l in llist:
    heapq.heappush(hq_left,l)
    if len(hq_left)>i:
      heapq.heappop(hq_left)
  hq_right=[]
  for i,r in rlist:
    heapq.heappush(hq_right,r)
    if len(hq_right)>i:
      heapq.heappop(hq_right)
      
  answer=base
  while hq_left:
    answer+=heapq.heappop(hq_left)
  while hq_right:
    answer+=heapq.heappop(hq_right)
    
  print(answer)

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int cal(int x1, int y1, int x2, int y2, vector<vector<int>>& imos)
{
  int ret =  imos[y2][x2] - imos[y2][x1] - imos[y1][x2] + imos[y1][x1];
  return ret;
}

int main()
{
  int N, K; scanf("%d %d", &N, &K);
  int x, y;
  char ch;
  vector<vector<int>> imos(K + 5, vector<int>(2 * K + 5, 0));
  for (int i = 0; i < N; ++i) {
    scanf("%d %d %c", &x, &y, &ch);
    if (ch == 'B') { x += K; }
    x %= 2 * K;
    y %= 2 * K;
    if (y >= K) {
      x = (x + K) % (2 * K);
      y %= K;
    }
    ++imos[y + 1][x + 1];
  }

  for (int i = 1; i <= K; ++i) {
    for (int j = 1; j <= 2 * K; ++j) {
      imos[i][j] += imos[i][j - 1] + imos[i - 1][j] - imos[i - 1][j - 1];
    }
  }

  int ans = 0;
  for (int y = 1; y <= K; ++y) {
    for (int x = 1; x <= 2 * K; ++x) {
      int val = cal(max(0, x - K), max(0, y - K), x, y, imos) +
                cal(x, y, min(2 * K, x + K), K, imos) +
                cal(min(2 * K, x + K), max(0, y - K), 2 * K, y, imos) +
                cal(0, y, max(0, x - K), K, imos);
      ans = max(ans, val);
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

#define ll long long
#define P pair<int,int>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define asort(x) sort(x.begin(),x.end())

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    for(int i=a; i<=b; i++) {
        if(i%k == 0) {
            cout << "OK" << endl;
            exit(0);
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<10000;i++){
		if(i*8/100==a&&i*10/100==b){
			printf("%d",i);
			return 0;
		}
	}
	puts("-1");
}

Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

int partition(int A[],int p,int r){
  int x=A[r];
  int i = p-1;
  for(int j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1],A[r]);
  return i+1; 
    
}

int main(){
  
  int n;
  cin>>n;
  int A[n];
  rep(i,n) cin>>A[i];
  
  int i = partition(A,0,n-1);
  
  for(int j=0;j<i;j++){
    if(j)cout<<" ";
    cout<<A[j];
  }
  cout<<" ["<<A[i]<<"]";
  for(int j=i+1;j<n;j++){
    cout<<" "<<A[j];
  }
  cout<<endl;
  
  return 0;
}


Measured memory_bytes: 3388
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N; cin>>N;
  vector<ll> C(N-1),S(N-1),F(N-1); rep(i,N-1) cin>>C[i]>>S[i]>>F[i];
  vector<ll> vec(N,0);
  
  rep(i,N-1){
    ll ans=S[i];
    for(int j=i;j<N-1;j++){
      ans+=C[j];
      if(j==N-2) {vec[i]=ans; break;}
      ans=max(S[j+1],(ans+F[j+1]-1)/F[j+1]*F[j+1]);
    }
  }
  
  for(auto t:vec) cout<<t<<'\n';
  
  return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>

using namespace std;

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

	vector<string> v( n );
	for(auto& x : v) {
		cin >> x;
	}

	vector<int_least32_t> count(26, 100), temp(26);
	for(auto& x : v) {
		for(auto i = 0U; i < x.length(); ++i) {
			++temp[x[i] - 'a'];
		}

		for(auto i = 0; i < 26; ++i) {
			count[i] = min(temp[i], count[i]);
		}
		fill(temp.begin(), temp.end(), 0);
	}

	for(auto i = 0U; i < count.size(); ++i) {
		for(auto j = 0; j < count[i]; ++j) {
			cout << static_cast<char>('a' + i);
		}
	}
	cout << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int A,B,C;
  scanf("%d %d %d",&A,&B,&C);
  if(A==B&&A!=C)printf("Yes");
   else if(A==C&&A!=B)printf("Yes");
   else if(B==C&&A!=B)printf("Yes");
   else printf("No");
  return 0;
}

Measured memory_bytes: 2140
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
      string[] input = Console.ReadLine().Split();
      int a = int.Parse(input[0]);
      int b = int.Parse(input[1]);
      if ((a*b)%2==0){
        Console.WriteLine("Even");
        
      }
      else{
        Console.WriteLine("Odd");
      }
    }
}


Measured memory_bytes: 27276
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

// type alias
using ll = long long;
using ull = unsigned long long;

template<class ll>
inline ll getCeilExponent(ll a)
{
	if (a <= 0)
	{
		throw invalid_argument("vaule equal to or less than 0 should not be valid");
	}

	ll index = 0;
	--a;
	for (; a != 0; a >>= 1)
	{
		++index;
	}
	return index;
}

template<class ll>
inline ll getFloorExponent(ll a)
{
	if (a <= 0)
	{
		throw invalid_argument("vaule equal to or less than 0 should not be valid");
	}

	ll index = 0;
	a >>= 1;
	for (; a != 0; a >>= 1)
	{
		++index;
	}
	return index;
}

// computational complexity: o(log(max(a, b))) 
template<class ll>
inline ll getGcd(ll a, ll b)
{
	if (b == 0)
	{
		return a;
	}
	return getGcd(b, a % b);
}

// computational complexity: o(log(max(a, b))) 
template<class ll>
inline pair<ll, ll> getBezoutsIdentitySolution(ll a, ll b)
{
	if (b == 0)
	{
		return { 1, 0 };
	}
	auto sol = getBezoutsIdentitySolution(b, a % b);
	return { sol.second, sol.first - (a / b) * sol.second };
}

template<class Integer>
inline Integer getPower(Integer base, unsigned exponential)
{
	Integer res = 1;
	while (exponential >= 1)
	{
		if (exponential & 1)
		{
			res *= base;
		}
		base = base * base;
		exponential >>= 1;
	}

	return res;
}

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

	ll N;
	cin >> N;

	cout << 180 * (N - 2) << endl;

	return 0;
}


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

unsigned long long n;

unsigned long long power(unsigned long long x, unsigned long long y){
	unsigned long long ret=1;
	while (y>0){
		if (y&1){
			ret*=x;
		}
		y>>=1;
		x*=x;
	}
	return ret;
}

int main(){
	cin >> n;
	if (n%2) cout << 0 << "\n";
	else{
		unsigned long long ans=0;
		for (unsigned long long i=25;i>0;i--){
			ans+=(n/(power(5,i)))/2;
		}
		cout << ans << "\n";
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    auto f = [](auto&& l, auto&& r) {
        int a = l.second < 30 ? l.first >> l.second : 0;
        int b = r.second < 30 ? r.first >> r.second : 0;
        return a < b;
    };

    priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(f)> pq(f);
    rep(i, N) {
        pq.emplace(A[i], 0);
    }

    rep(i, M) {
        auto a = pq.top();
        pq.pop();
        pq.emplace(a.first, a.second + 1);
    }

    ll ans = 0;
    while (!pq.empty()) {
        auto p = pq.top();
        pq.pop();
        ans += p.second < 30 ? p.first >> p.second : 0;
    }

    write(ans);
}

Measured memory_bytes: 1784
<?php
while (true) {
    list($H, $W) = array_map("intval", explode(' ', trim(fgets(STDIN))));
    if ($H == 0 && $W == 0) {
        break;
    }
    
    $line1 = str_repeat('#.', (int) floor($W / 2)) . str_repeat('#', $W % 2) . "\n";
    $line2 = str_repeat('.#', (int) floor($W / 2)) . str_repeat('.', $W % 2) . "\n";
    $lines = $line1 . $line2;

    $board = str_repeat($lines, (int) floor($H / 2)) . str_repeat($line1, $H % 2);

    print($board . "\n");
}
?>


Measured memory_bytes: 9380
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;

 
int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS 



  int n;
  cin >> n;
  vector<int> v(n);

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

    int mx = v[0];

    int ans = 0;

    for(int i = 0; i < n; i++)
    {
      mx = max(mx,v[i]);
      ans += mx - v[i];
    }


    cout << ans;




    return 0;
}


Measured memory_bytes: 4744
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<time.h>
using namespace std;
char s[100008]={0};
int jd(int i)
{
    if(s[i-4]=='d'&&s[i-3]=='r'&&s[i-2]=='e'&&s[i-1]=='a'&&s[i]=='m')return 1;
    else return 0;
}
int jdr(int i)
{
    if(s[i-6]=='d'&&s[i-5]=='r'&&s[i-4]=='e'&&s[i-3]=='a'&&s[i-2]=='m'&&s[i-1]=='e'&&s[i]=='r')return 1;
    else return 0;
}

int je(int i)
{
    if(s[i-4]=='e'&&s[i-3]=='r'&&s[i-2]=='a'&&s[i-1]=='s'&&s[i]=='e')return 1;
    else return 0;
}
int jer(int i)
{
    if(s[i-5]=='e'&&s[i-4]=='r'&&s[i-3]=='a'&&s[i-2]=='s'&&s[i-1]=='e'&&s[i]=='r')return 1;
    else return 0;
}

int main()
{
    int i,j,k,n,l;
    cin>>s;
    l=strlen(s);
    for(i=l-1;i>=0;)
    {
      int f=0;
      if(i>=4&&jd(i))
      {
          f=1;
          i=i-5;
      }
      else if(i>=4&&je(i))
      {
          f=1;
          i=i-5;
      }

      else if(i>=6&&jdr(i))
      {
          f=1;
          i=i-7;
      }
      else if(i>=5&&jer(i))
      {
          f=1;
          i=i-6;
      }
      if(f==0||(i<4&&i>0))
      {
          printf("NO\n");
          exit(0);
      }
    }
    printf("YES\n");
    return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#include<iomanip>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
const long long mod=1000000007;
typedef long long ll;

int main(){
  int a,b,c=0;
  cin>>a>>b;
  c=b-a;
  for(int i=0;i<a*2-1;i++){
    cout<<c+1<<" ";
    c+=1;
  }
  cout<<endl;
}


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

#define ll long long 
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);


int main()
{
    int ar[126];
    memset(ar,0,sizeof ar);
    string s;
    cin >> s;
    for(int i=0;i<s.size();i++)
    {
        ar[s[i]]++;
    }
    for(int i=0;i<126;i++)
    {
        if(ar[i]%2==1) 
        {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}

Measured memory_bytes: 3628
#include<cstdio>
#include<cstring>
#define ll long long
char str[15];
int len;
ll ans=0;
ll change(int i,int j)
{
    ll sum=0;
    while(i<=j)
    {
        sum=sum*10+(str[i]-'0');
        i++;
    }
    return sum;
}
int fun(int a,int b)
{
    if(a==len-1)
    {
        ans+=str[a]-'0';
        return 1;
    }
    if(a>len-1)
        return 0;
    int num,sum;
    num=sum=0;
    for(int i=a;i<len;i++)
    {
        num=fun(i+1,len-1);
        ans=ans+change(a,i)*num;
        sum+=num;
    }
    ans+=change(a,b);
    return sum+1;
}
int main()
{
    scanf("%s",str);
    len=strlen(str);
    int num;
    for(int i=0;i<len;i++)
    {
        num=fun(i+1,len-1);
        ans=ans+change(0,i)*num;
    }
    ans+=change(0,len-1);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
X = int(input())
flag=False

if X>=2100:
  print(1)
  flag=True
else:
  for i in range(0,22):
    for j in range(0,22-i):
      for k in range(0,22-i-j):
        for l in range(0,22-i-j-k):
          for m in range(0,22-i-j-k-l):
            for n in range(0,22-i-j-k-l-m):
              if 100*i+101*j+102*k+103*l+104*m+105*n==X:
                if flag==False:
                  print(1)
                  flag=True
                  break
              
if flag==False:
  print(0)


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

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

    int ans = 0;
    REP(i, 0, N - 1) {
        if (S[i] == S[i + 1]) ans++;
    }

    cout << min(N - 1, ans + 2 * K) << endl;
    return 0;
}

Measured memory_bytes: 512
/*
	##############################
	## Author: Pratyush Gaurav ###
	## College: NIT ROURKELA #####
	##############################
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long/*--------------------*/lli;
typedef long double/*------------------*/ld;
typedef pair<lli, lli >/*--------------*/plli;
typedef vector<lli>/*------------------*/vlli;
typedef vector<plli >/*----------------*/vplli;

#define rep(i,a)/*---------------------*/for(i = 0 ; i < a ; i++)
#define repr(i,a)/*--------------------*/for(i = a ; i >= 0 ; i--)
#define REP(i,a,b)/*-------------------*/for(i = a ; i <= b ; i++)
#define REPR(i,a,b)/*------------------*/for(i = a ; i >= b ; i--)

#define scan(N)/*----------------------*/scanf("%lld",&N)
#define print(N)/*---------------------*/printf("%lld",N)
#define scan2(N1,N2)/*-----------------*/scanf("%lld %lld",&N1,&N2)
#define print2(N1,N2)/*----------------*/printf("%lld %lld",N1,N2)
#define scan3(N1,N2,N3)/*--------------*/scanf("%lld %lld %lld",&N1,&N2,&N3)
#define print3(N1,N2,N3)/*-------------*/printf("%lld %lld %lld",N1,N2,N3)

#define mem(a,b)/*---------------------*/memset(a,b,sizeof(a))
#define opt/*--------------------------*/ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a, b)/*--------------------*/__gcd(a, b)
#define lcm(a, b)/*--------------------*/((a)*((b)/gcd(a,b)))
#define sqr(x)/*-----------------------*/(x)*(x)
#define all(a)/*-----------------------*/a.begin(),a.end()
#define makepair/*---------------------*/make_pair
#define pushback/*---------------------*/push_back

#define endl/*-------------------------*/'\n'
#define inf/*--------------------------*/(lli)2000000000000
#define MOD/*--------------------------*/(lli)1000000007
#define MAXN/*-------------------------*/100005

template<class T> bool is_prime(T n)
{
	if((n%2 == 0 and n > 2) or n < 2 )
		return false;
	for(T i = 3; i*i <= n ; i += 2)
	{
		if( n % i == 0)
			return false;
	}
	return true;
}
lli power(lli a,lli b)
{
    lli value;
    if(!b)
    	return 1;
    else if(b%2==0)
    {
        value = power(a,b/2)%MOD;
        return (value * value)%MOD;
    }
    else
    {
        value = power(a,b/2)%MOD;
        return ((a*value)%MOD*(value))%MOD;
    }
}

int main()
{
	opt;
	lli n;
	cin >> n;
	vlli v(n);
	lli i;
	lli ans = 1;
	rep(i,n) cin >> v[i];
	sort(all(v));
	reverse(all(v));
	REP(i,1,n-1)
	{
        if(v[i] < v[i-1])
            ans++;
	}
	cout << ans;
	return 0;
}










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

public class Main {


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

	private void solve() {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		String L = sc.nextLine();

		int N = S.length();
		int M = L.length();

		int [][] dp = new int[N+1][M+1];

	 

		for(int i=N-1;i>=0;i--){
			for(int j=M-1;j>=0;j--){
				char a = S.charAt(i);
				char b = L.charAt(j);

				if (a==b) {
					dp[i][j] = 1+ dp[i+1][j+1];					 
				} else{
					dp[i][j] = Math.max(dp[i+1][j], dp[i][j+1]);
				}
			}
		}
		
		//for(int i=0;i<=N;i++) System.out.println(Arrays.toString(dp[i])); 

		int i=0,j=0;
		while(i<N && j<M) {
			char a = S.charAt(i);
			char b = L.charAt(j);			  
			if (a==b) {
				System.out.printf("%c",a);
				i++;
				j++;
			} else {
				if (dp[i+1][j]>=dp[i][j+1]) i++;
				else j++;
			}
		}


 
	} 
}

Measured memory_bytes: 87920
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define RREP(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define NL cerr << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int from, to; int cost; };
ostream& operator << (ostream& s, const edge& e) {
   s << "(" << e.from << "->" << e.to << ": " << e.cost << ")";
   return s;
}
bool operator< (const edge &edge1, const edge &edge2){
   return edge1.cost < edge2.cost;
};

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

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T> ostream& operator << (ostream& s, const set<T>& se) {
   s << "{";
   for (auto i = se.begin(); i != se.end(); ++i) {
      s << *i;
      if (next(i) != se.end()) s << ", ";
   }
   s << "}";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}

int f(int b, int n) {
   if (n < b) {
      return n;
   } else {
      return f(b, n/b) + (n % b);
   }
}

signed main()
{
   int n, s; cin >> n >> s;

   REP(b, 2, (int)sqrt(n)+1) {
      if (f(b,n) == s) {
         cout << b << endl;
         return 0;
      }
   }

   RREP(a1, 1, (int)sqrt(n)+1) {
      int a0 = s - a1;
      if ((n - a0) % a1 == 0) {
         int b = (n - a0) / a1;
         if (0 <= a0 && a0 < b && a1 < b && 2 <= b) {
            cout << b << endl;
            return 0;
         }
      }
   }

   if (n == s) {
      cout << n+1 << endl;
      return 0;
   }

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

Measured memory_bytes: 256
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let _n = read::<usize>();

    let v = read_vec::<f64>();
    let t = v[0];
    let a = v[1];

    let hs = read_vec::<f64>();
    let mut min = 10000000.0;
    let mut mini = 0;
    for (i, temp) in hs.into_iter().map(|h| (a - (t - 0.006 * h)).abs()).enumerate() {
        if min > temp {
            min = temp;
            mini = i
        }
    }
    println!("{}", mini+1);
}


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

class UnionFind {
public:
    vector<ll>par; // 各元の親を表す配列
    vector<ll>siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
  int n,m,ans;
  cin >> n >> m;
  ans = n;
  UnionFind tree(n);
  rep(i,0,m){
    int x,y,z;
    cin >> x >> y >> z;
    x--;y--;
    if(!tree.issame(x,y)){tree.merge(x,y);ans--;}
  }
  cout << ans << endl;
}

Measured memory_bytes: 4816
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

n, k = input_a
s = input_s

a = s.chars
# 0, 1の連続している個数を格納する配列(連続する個数を記録するとき、常に0,1は交互に現れる)
# 最初と最後に必ず1の個数が入るものとする(入力文字列Sがそうでない場合1の個数は0)
counts = []

before = "1"
cnt = 0
# 0, 1が切り替わる度にpush
a.each do |s|
  if s != before
    counts.push(cnt)
    cnt = 1
    before = s
    next
  end
  cnt += 1
end
# 最後の0, 1は切り替わりが行われないため個別にpush
counts.push(cnt)
# 最後が1でなかった場合にpush
if a.last == "0"
  counts.push(0)
end

# 最大K回反転可能であるということは、0のcountを最大K回1のcountに反転できるのと同義である
# countsの左端から右端まで、しゃくとり法で各区間の和を計算することで、最大値が求められる
# 1は反転する必要がないので、区間の長さは2Kとなる→両端が1のとき、1,0の個数は奇数になるので2K+1
# また、連続する1の個数が最大になるのは、両端が0ではなく1になるときであるため、区間は2ずつ進める
# でもしゃくとり法で計算するの混乱する。。。

# 累積和の計算
sums = Array.new(counts.size + 1)
sums[0] = 0
(counts.size).times do |i|
  sums[i + 1] = sums[i] + counts[i]
end

# 左端から2ずつずらして、各区間の総和を累積和から計算する
result = 0
left = 0
while left < sums.size do
  right = left + (k * 2 + 1)
  # rightがはみ出さないように処理
  if right >= sums.size
	right = sums.size - 1
  end
  result = [result, sums[right] - sums[left]].max
  left += 2
end

p result

Measured memory_bytes: 11004
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
int main(void){
    ll n;cin>>n;
    typedef pair<int, bool> shogen;
    vector<shogen> p[n];
    REP(i,n){
        ll a;cin>>a;
        int x;bool y;
        REP(j,a){
            cin>>x>>y;x--;
            p[i].push_back(make_pair(x,y));
        }
    }
    int ans=0;
    bool flag;int cnt;
    for(int bit=0;bit<(1<<n);bit++){//集合を決め打ち
        flag=true;cnt=0;
        for(int i=0;i<n;i++){
            if(bit & 1<<i){cnt++;//決め打たれた正直者
                for(auto r:p[i]){//各証言
                    int x=r.first;
                    bool y=r.second;
                    if((bit & (1<<x)) && y)continue;
                    if(!(bit & 1<<x) && !y)continue;
                    flag=false;
                    break;
                }
                if(!flag)break;
            }
        }
        if(flag){
            ans=max(ans,cnt);
        }
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 256
n = int(input())
e_min = 1000000000
x        =- 1000000000

for i in range(n):
    e1 = int(input())
    if i>0 and x < e1 - e_min:
        x = e1 - e_min
    e_min = min(e_min,e1)
print(x)

Measured memory_bytes: 7712
#include<bits/stdc++.h>
#define st first
#define nd second


using ll = long long;
using namespace std;
using pii = pair<int, int>;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;

int way[N], fac[N], ifac[N], comp[N];
std::vector<int> gr[N];

int mul(int a, int b){
	return 1LL * a * b % mod;
}
int f_pow(int val, int idx){
	int ret = 1, pt = 0;
	while((1 <<pt) < idx){
		if(idx & (1 << pt)){
			ret = mul(ret, val);
		}
		pt++;
		val = mul(val, val);
	}
	return ret;

}
int C(int po, int n, int r){
	if(r == n) return 1;
	if(po == 1) return mul(fac[n], mul(ifac[n - r], ifac[r]));
	else return mul(ifac[n], mul(fac[n-r], fac[r]));
}


void dfs(int node, int from){
	for(auto it: gr[node]){
		if(it == from) continue;
		dfs(it, node);
		way[node] = mul(way[node] , mul(way[it] , C(1, comp[it] + comp[node], comp[it]))); 
		comp[node] += comp[it];
	}
	comp[node] ++;
	return;
}
void dis(int node, int from){

	if(node != 1){
		int fromPar = mul(way[from] ,mul(f_pow(way[node], mod - 2), C(-1, comp[from] - 1, comp[node])));
		way[node] = mul(way[node], mul(fromPar,C(1, comp[from] - 1, comp[node] - 1))); 
		comp[node] = comp[from];
	}
	for(auto it: gr[node]){
		if(it != from) dis(it, node);
	}
}
int main(){
	int n;
	scanf("%d", &n);
	for(int i = 1; i < n; i++){
		int x, y;
		scanf("%d %d", &x, &y);
		gr[x].push_back(y);
		gr[y].push_back(x);
	}
	fac[0] = 1;
	for(int i = 1; i <= n + 1; i ++){
		way[i] = 1;
		fac[i] = mul(fac[i-1],i);
	}
	ifac[n + 1]  = f_pow(fac[n+1], mod - 2), ifac[0] = 1;
	for(int i = n; i > 0; i--){
		ifac[i] = mul(i + 1, ifac[i + 1]);
	} 
	dfs(1, 0);

	dis(1, 0);
	for(int i = 1;i <= n; i++){
		printf("%d\n", way[i]);
	}

}

Measured memory_bytes: 17012
a = int(input())
comb_num = list(map(int, input().split()))
b = int(input())
ans_num = list(map(int, input().split()))

gen = 1

for i in comb_num:
    gen = gen<<i|gen

for j in ans_num:
    if gen>>j&1:
        print('yes')
    else:
        print('no')


Measured memory_bytes: 5620
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=0;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const int MAX = 4;

static const ll MAX_N = 100001;
static const ll MAX_M = 100001;

bool w[100][100];
int main() {
	ll n; cin >> n;
	ll maxV = 0;
	rep(i, 0, n) {
		ll a; cin >> a;
		maxV = max(a, maxV);
		rep(j, 0, a) {
			w[i][j] = 1;
		}
	}
	ll ans = 0;
	rep_r(i, 0, maxV) {
		bool r = false;
		rep(j, 0, n) {
			if (!r && w[j][i]) {
				r = true;
				ans++;
			}
			else if (r && !w[j][i] || j == n - 1) {
				r = false;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class I,class V=typename I::value_type>V sum_up(const I&l,const I&r){V v;for(I i=l;i!=r;i++)v=i==l?*i:v+*i;return v;}
template<class I,class T=iterator_traits<I>>I operator+(I it,int n){for(int i=0;i<n;i++)it++;return it;}
template<class I,class T=iterator_traits<I>>I operator-(I it,int n){for(int i=0;i<n;i++)it--;return it;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}
void R_YESNO(bool p){cout<<(p?"YES":"NO")<<endl;}
void R_YesNo(bool p){cout<<(p?"Yes":"No")<<endl;}
int main() {
    string N;
    cin >> N;
    for(char c : N) if(c == '7') {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3596
a = gets.chomp.to_i
sum = 0
sum1 = 0
while a - 500 >= 0
  a = a - 500
  sum += 1
end
while a - 5 >= 0
  a = a - 5
  sum1 += 1
end
puts sum * 1000 + sum1 * 5

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

int main(void){
  int n;
  int c[50], v[50];
  int ans = 0;
  
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> v[i];
  }
  for(int i = 0; i < n; i++){
    cin >> c[i];
    ans += (v[i] - c[i] > 0) ? (v[i] - c[i]) : 0;
  }
  
  cout << ans << endl;

  return 0;
}

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

using namespace std;

const int mod = 1e9 + 7;

inline long long multiply(long long a, long long b) {
	return ((a % mod) * (b % mod)) % mod;
}

inline long long add(long long a, long long b) {
	return (a % mod + b % mod) % mod;
}

inline long long power(long long a, long long b) {
    long long res = 1ll;
    a = a % mod;
    while(b > 0) {
        if(b & 1) {
            res = multiply(res, a);
        }
        b = b / 2;
        a = multiply(a, a);
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
    string s;
    cin >> s;
    long long ans = 0;
    long long n = s.length();
    long long sim = 1ll;
    for(int i = 0; i < n - 1; i++) {
    	if(s[i] == '1') {
    		long long temp = multiply(power(3, n - i - 1ll), sim);
    		ans = add(ans, temp);
    		sim = multiply(sim, 2);
    	}
    }

    if(s[n - 1] == '1') ans = add(ans, multiply(sim, 3));
    else ans = add(ans, sim);

    cout << ans;

    return 0;
}

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

int n, a, b;

int main(void){
    // Here your code !
    scanf("%d %d %d", &n, &a, &b);

    if ((b - a) % 2 != 0) printf("Borys\n");
    else printf("Alice\n");

    return 0;
}


Measured memory_bytes: 384
A, B, K = STDIN.gets.chomp.split(' ').map(&:to_i)

takahashi = A
aoki = B

K.times do |i|
  if i % 2 == 0
    takahashi -= 1 unless takahashi % 2 == 0
    aoki += (takahashi / 2)
    takahashi /= 2
  else
    aoki -= 1 unless aoki % 2 == 0
    takahashi += (aoki / 2)
    aoki /= 2
  end
end

puts "#{takahashi} #{aoki}"


Measured memory_bytes: 3836
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>  // min, max
#include <fstream>  // ifstream
#include <iomanip>  // setprecision
using namespace std;
typedef long long ll;

bool string_order(std::pair<string, int> first_entry,
                  std::pair<string, int> second_entry)
{
    int foo = (first_entry.second & 0xFF);
    int bar = (second_entry.second & 0xFF);
    return (foo > bar);
}

int main(void)
{
    ifstream inputFile("data/input.txt");
    if (getenv("SSH_CONNECTION") != nullptr) {
        cin.rdbuf(inputFile.rdbuf());
    }

    int N;
    cin >> N;
    vector<pair<string, int>> data(N);
    for (int i = 0; (i < N); ++i) {
        cin >> data[i].first >> data[i].second;
        data[i].second += (i * 256);
    }
    sort(data.begin(), data.end());
    data.emplace_back("", 0);
    int i = 0;
    while (i < N) {
        int j = i;
        vector<pair<string, int>> temp;
        temp.emplace_back(data[j].first, data[j].second);
        while (data[i].first == data[j+1].first) {
            ++j;
            temp.emplace_back(data[j].first, data[j].second);
        }
        sort(temp.begin(), temp.end(), string_order);
        int k;
        for (k = 0; (k < temp.size()); ++k) {
            cout << ((temp[k].second & 0xFF00) / 256) + 1 << endl;
        }
        i += k;
    }
    return 0;
}


Measured memory_bytes: 256
const main = input => {
  const inputArray = input.split('\n');
  const n = inputArray[0];
  let a = inputArray[1].split(' ').map(x => parseInt(x, 10));
  const q = inputArray[2];

  const counter = {};
  let sum = 0;

  for (let ai of a) {
    sum += ai;
    counter[ai] = ~~counter[ai] + 1;
  }

  for (i = 0; i < q; i ++) {
    const [bi, ci] = inputArray[i + 3].split(' ');
    const diff = ci - bi;
    sum += diff * ~~counter[bi];
    counter[ci] = ~~counter[ci] + ~~counter[bi];
    counter[bi] = 0;
    console.log(sum);
  }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 63636