akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();

		List<Queue<Integer>> queueList = new ArrayList<Queue<Integer>>();
		for(int i = 0; i < n; i++) {
			queueList.add(new PriorityQueue<Integer>(Comparator.reverseOrder()));
		}

		for(int i = 0; i < q; i++)	{
			int query = sc.nextInt();
			int t = sc.nextInt();

			switch(query){
			case 0:
				int x = sc.nextInt();
				queueList.get(t).add(x);
				break;

			case 1:  //getMax(t)
				if(!(queueList.get(t).isEmpty())) System.out.println(queueList.get(t).peek());
				break;

			case 2:  //deleteMax(t)
				if(!(queueList.get(t).isEmpty())) queueList.get(t).poll();
				break;
			}
		}
	}

}



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

using namespace std;

int main () {
	int a,b,s=1;
	cin>>a>>b;
	while(a<=b){
		if(a<0){
			s*=-1;		
		}
		else if(a==0){
			s=0;
			cout<<"Zero"<<endl;
			break;
		}
		if(a>0){
			break;
		}
		a++;
	}
	if(s==-1){
		cout<<"Negative"<<endl;
	}
	else if(s==1){
		cout<<"Positive"<<endl;
	}
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
void dump(){cout<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cout<<h<<", ";dump(forward<Ts>(t)...);}
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

void solve1();void solve2();
int main(){
  solve1();
  return 0;
}

void solve1(){

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

  map<ll,ll>cnt;
  for(auto x:a){
    cnt[x]++;cnt[x+1]++;cnt[x-1]++;
  }

  ll ans = -1;
  for(auto x:cnt)chmax(ans,x.second);
  cout<<(ans)<<endl;
}

Measured memory_bytes: 6912
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int W = sc.nextInt();
        int[] w = new int[N];
        int[] v = new int[N];
        for (int i = 0; i < N; i++) {
            w[i] = sc.nextInt();
            v[i] = sc.nextInt();
        }
        //dp objective: minimum weight such that accomplish v-value or larger value.
        int maxValue = 1000*N;
        long[][] dp = new long[N+1][maxValue+1];
        for(int i = 0; i < N+1; i++) {
            for (int j = 1; j < maxValue + 1; j++) {
                dp[i][j] = 1_000_000_007;                
            }
        }
        for (int i = 1; i < N+1; i++) {
            for (int j = 1; j < maxValue + 1; j++) {
                //case 1: Do not use item i-1
                dp[i][j] = dp[i-1][j];
                //case 2: Use item i-1
                int diff = Math.max(j - v[i-1],0);
                dp[i][j] = Math.min(dp[i][j], dp[i-1][diff] + w[i-1]);
            }
        }
        //Bin search on maximum v such that dp[N][v] <= W.
        //constraint => dp[N][1] <= W
        long ans;
        if (dp[N][maxValue] <= W) {
            ans = maxValue;
        } else {
            int ng = maxValue;
            int ok = 0;
            while(Math.abs(ng-ok) > 1) {
                int mid = (ok+ng)/2;
                if(dp[N][mid] <= W){
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            ans = ok;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 128208
// B - Counting of Trees
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)
#define MOD 998244353

int main(){
	int N; cin>>N;
	map<int,int> M;
	rpz(i, N){
		int d; cin>>d;
		if((i==0 && d!=0) || (i>0 && d<=0)){
			cout<< 0 <<endl;
			return 0;
		}
		M[d]++;
	}
	ll ans = 1;
	rp(d, 1, M.size()) rpz(i, M[d]) ans  = ans * M[d-1] % MOD;
	cout<< ans <<endl;
}

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

int main() {
    int n; cin >> n;
    vector<int> ls(n), rs(n);
    rep(i, n){
        cin >> ls[i] >> rs[i];
    }
    sort(ls.begin(), ls.end());
    sort(rs.begin(), rs.end());
    int ans = 0;
    int l, r;
    if(n%2 == 1){
        l = ls[n/2];
        r = rs[n/2];
        ans = r-l+1;
    }else{
        l = ls[n/2-1]+ls[n/2];
        r = rs[n/2-1]+rs[n/2];
        ans = r-l+1;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4812
import java.util.Scanner;

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

	public void solve(Scanner sc) {
		String s = sc.next();
		String t = sc.next();
		
		for(int i=0; i<s.length(); i++) {
			StringBuilder sb = new StringBuilder();
			sb.append(s.charAt(s.length()-1));
			sb.append(s.substring(0, s.length()-1));
			
			if(sb.toString().equals(t)) {
				System.out.println("Yes");
				return;
			}
			s = sb.toString();
		}
		
		System.out.println("No");
	}
}

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

using namespace std;

const int N = 200100;

int val[N];
int vec[N], vec2[N];

int get(int a, int b, int c) {
	vector <int> v;
	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	sort(v.begin(), v.end());
	return v[1];
}

int main() {
	int n, x;
	scanf("%d%d", &n, &x);

	// 16 + 10
	// generate
	int k = -4;

	/*for (int i = 1; i <= 2*n-1; ++i) {
		val[i-1] = (i+k-1 + 2*n-1)%(2*n-1)+1;
	}
	vector <int> ans;
	do {
		for (int i = 0; i < 2*n-1; ++i) {
			//printf("%d ", val[i]);
			vec[i] = val[i];
		}
		//printf("\n");
		int sz = 2*n-1;
		while(sz > 1) {
			for (int i = 0; i < sz-2; ++i) {
				vec2[i] = get(vec[i], vec[i+1], vec[i+2]);
			}
			sz = sz-2;
			for (int i = 0; i < sz; ++i) {
				vec[i] = vec2[i];
			}
		}
		ans.push_back(vec[0]);
	} while(next_permutation(val, val+2*n-1));
	sort(ans.begin(), ans.end());
	ans.erase(unique(ans.begin(), ans.end()), ans.end());
	for (int x: ans) {
		printf("%d\n", x);
	}
	*/
	if(x == 1 || x == 2*n-1) {
		puts("No");
	}
	else {
		int k = x-n;
		for (int i = 1; i <= 2*n-1; ++i) {
			val[i-1] = (i+k-1 + 2*n-1)%(2*n-1)+1;
		}
		puts("Yes");
		for (int i = 0; i < 2*n-1; ++i) {
			printf("%d\n", val[i]);
		}
	}

}

Measured memory_bytes: 2304
/**
 *   author: Shubham Srivastava
 *   created: 02 May 2020  17:44:46
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define MOD 1000000007
#define INF 0x7fffffff
#define sorti(v) sort(v.begin(),v.end())
#define sortd(v) sort(v.rbegin(),v.rend())
typedef pair<ll, ll> pll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
ll parent[2000005];

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n;cin>>n;
    ll val = 100;
    ll count = 0;
    while(val < n){
        val += val/100;
        //cout<<val<<" ";
        count++;
    }
    cout<<count;
return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)


template <typename T>
void printV(vector<T> A) {
    if (A.empty()) cerr << "EMTPY\n";
    else { 
        cerr << "\n[";
        for (int i = 0; i < A.size() -1 ; ++i) {
            cerr << A[i] << ", ";
        }
        if (A.size()) cerr << A.back() << "]\n";
    }
}


template <typename T>
void printVV(vector<vector<T>> A) {
    cerr << "\n[";
    for (auto v : A) {
        printV<T>(v);
    }
    cerr << "]\n";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}

int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    ll a, b, k;
    cin >> a >> b >> k;
    
    cout << max(0LL, a - k) << ' ' << max(0LL, b + min(0LL,a-k)) << endl;


    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
//---------------------------------------------------------------------------------------------------
typedef pair<string,string> P;

int main(void){
    // Your code here!
    int n; 
    string s; cin >> n >> s;
    int m = 2*n;
    string s1 = "",s2 = "";
    rep(i,n) s1 += s[i];
    rep(i,n) s2 += s[i+n];
    ll ans = 0;
    map<P,ll> mp;
    rep(i,1<<n) {
        string sw = "",sv = "";
        rep(j,n) {
            if (i >> j & 1) sw += s1[j];
            else sv += s1[j];
        }
        reverse(all(sv));
        ++mp[P(sw,sv)];
    }
    rep(i,1<<n) {
        string su = "",st = "";
        rep(j,n) {
            if (i >> j & 1) su += s2[j];
            else st += s2[j];
        }
        reverse(all(st));
        ans += mp[P(st,su)];
    }
    cout << ans << endl;
}


Measured memory_bytes: 60892
#include <iostream>
#include<algorithm>
#include<stack>
#include<vector>
#include <cmath>
using namespace std;
const long long N = 100005;
long long M= 1000000007;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n, m;
	cin >> n >> m;
	m += (n * 3);
	cout << m / 2;
} 

Measured memory_bytes: 256
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


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

    string s;
    cin >> s;

    const string S = "Sunny";
    const string C = "Cloudy";
    const string R = "Rainy";

    if (s == S)
        print(C);
    else if (s == C)
        print(R);
    else
        print(S);

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int i;
        String str = "1";
        int sum = 0;
        int value = 1;
        while (true) {
            str = sc.next();
            if(str.equals("0")){
                break;
            }
            for (i = 0; i < str.length(); i++) {
                str.charAt(i);
                value = str.charAt(i) -'0';
                sum += value;
            }
            System.out.println(sum);
            sum = 0;    
        }
        sc.close();
    }
}


Measured memory_bytes: 26348
N=input()
keta=len(N)
K=int(input())

# 桁DP
# dp[桁数][未満フラグ][0じゃない数の数]
# 010みたいなときに頭の0を数えないよう注意（0を数えると面倒、0じゃないを数えれば問題なし）

dp=[[[0 for i in range(K+1)] for j in range(2)] for k in range(keta)]

# ある数が与えられたときに、その数未満で0じゃない数の値を返す
def getMiman(X):
  if X>0:
    return X-1
  else:
    return 0

x0=int(N[0])
# 未満じゃないのに先頭が0はあり得ない
dp[0][0][0]=0
# 未満で、0じゃない数が存在しないのは先頭から0の場合のみ
dp[0][1][0]=1
# 未満じゃなく、0でない数が1->元の数の場合なので1
dp[0][0][1]=1
# 未満で、0でない数が1　3の場合2,1
dp[0][1][1]=getMiman(x0)

for i in range(1,keta):
  # 全桁をDP
  x=int(N[i])
  # 未満じゃないのに0じゃない数が0個なのはあり得ない
  dp[i][0][0]=0
  # 未満で、0じゃない数が存在しないのはここまでずっと0だった場合のみ
  dp[i][1][0]=1
  for j in range(1,K+1):
    # 未満じゃなくて、0じゃない数がj個なのは以下の合計：
    # ・前の桁（未満じゃない）で0じゃない数がj-1個で、今回の桁が0じゃない場合
    # ・前の桁（未満じゃない）で0じゃない数がj個で、今回の桁が0
    dp[i][0][j]=dp[i-1][0][j-1]*(x!=0)+dp[i-1][0][j]*(x==0)
    
    # 未満で、0じゃない数がj個なのは以下の合計：
    # ・前の桁（未満じゃない）で0じゃない数がj-1個で、今回の桁が未満相当（getMiman）
    # ・前の桁（未満じゃない）で0じゃない数がj個で、今回の桁が0でない場合に0を選択する
    # ・前の桁（未満）で0じゃない数がj-1個で、今回は1-9まで選べるので9通り
    # ・前の桁（未満）で0じゃない数がj個で、今回は0を選ぶ
    dp[i][1][j]=dp[i-1][0][j-1]*getMiman(x)+dp[i-1][0][j]*(x!=0)+dp[i-1][1][j-1]*9+dp[i-1][1][j]*1
  
print(dp[keta-1][0][K]+dp[keta-1][1][K])  

Measured memory_bytes: 38384
N, A, B = map(int, input().split())
ans = 0

for i in range(0, N+1, 10):
    for j in range(10):
        temp = str(i + j)
        if (int(temp) > N):
            break

        sum = 0
        for k in range(len(temp)):
            sum += int(temp[k])
        if (B < sum):
            break
        elif (A <= sum) and (sum <= B):
            ans += int(temp)

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
int n,ans;
int a[400000],sum[400000];
map<int,int>mp;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>a[i];
        if(i==0)sum[i]=a[i];
        else sum[i]=sum[i-1]+a[i];
        mp[sum[i]]++;
    }
    int ans=mp[0];
    rep(i,n){
        int num=mp[sum[i]];
        if(num>0)ans+=(num*(num-1))/2;
        mp[sum[i]]=0;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 18432
import sys
N=sys.stdin.read()
K=len(N)
N=N.lower()
U=[0]*26
list="abcdefghijklmnopqrstuvwxyz"
for i in range(K):
  for u in range(26):
    if N[i]==list[u]:
      U[u]+=1
for h in range(26):
    print(f"{list[h]} : {U[h]}")


Measured memory_bytes: 5576
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <string.h>
#include <iomanip>

using namespace std;

int main()
{
	map<char, int> mp;
	string s;
	cin >> s;
	
	sort(s.begin(), s.end());
	
	if (s[0] == s[1] && s[2] == s[3] && s[0]!=s[3])
	cout <<"Yes"<<endl;
	else cout <<"No" <<endl;
	
	
	
	
	return 0;
	
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define MAX 50000

string s;
int size=0;
map<string,int> mp[MAX];
string name[MAX];
int cnt[MAX];

int main(){
  string str;
  getline(cin,str);
  stack<P> st;
  st.push(P(-1,0));
  
  while(getline(cin,s)){
    size++;
    string a="",b="";
    int i,len=s.size(),ra=0;
    for(i=0;s[i]==' ';i++)ra++;
    for(;s[i]!=':';i++)a.push_back(s[i]);
    if(i+1<len&&s[i+1]==' '){
      for(i=i+2;i<len;i++)b.push_back(s[i]);
    }
    //cout<<ra<<' '<<a<<' '<<b<<endl;

    P p;
    while(1){
      p=st.top();
      if(p.first >= ra){
        st.pop();
      }else{
        break;
      }
    }

    mp[p.second][a]=size;
    // cout<<p.second<<' '<<a<<' '<<size<<endl;

    if(b=="")name[size]="object";
    else name[size]=b;

    cnt[p.second]++;
    st.push(P(ra,size));
  }
  

  for(int i=0;i<(int)str.size();i++){
    if(str[i]=='.')str[i]=' ';
  }

  stringstream ss(str);
  string tmp;
  int p=0;
  vector<string> vec;
  while(ss>>tmp)vec.push_back(tmp);
  
  for(int i=0;i<(int)vec.size();i++){
    if(mp[p][vec[i]]==0){
      cout<<"no such property"<<endl;
      return 0;
    }
    p=mp[p][vec[i]];
  }
  if(cnt[p]==0)cout<<"string \""<<name[p]<<"\""<<endl;
  else cout<<name[p]<<endl;

  return 0;
}

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

#define ll              long long
#define LMx             LLONG_MAX
#define LMn             LLONG_MIN
#define PI              3.14159265
#define endl            '\n'
#define cd              cout << '\n';
#define ys              cout << "YES"; return;
#define no              cout << "NO"; return;
#define pii             pair<int,int>
#define IOS             ios::sync_with_stdio(0);
#define vi              vector<int>
#define vll             vector<long long>
#define vpii            vector<pair<int,int>>
#define vpll            vector<pair<long long, long long>>
#define pb              push_back
#define in              insert
#define mp              make_pair
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define fr              first
#define sc              second
#define sz(a)           a.size()
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define buga(i,n,a)     for(i = 0; i < n; ++i) cout << a[i] << " ";
#define bugv(i,n,v)     cout << endl; for(i = 0; i < n; ++i) cout << v[i].first << " " << v[i].second << endl; cout << endl;
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2,fma")

using namespace std;

/*ll myceil(ll a, ll b)
{
	return ((a+b-1)/b);
}

ll myfloor(ll a, ll b)
{
	return a/b;
}*/


void solve()
{
	ll c, d, i, j, k, l, m, n, x, y, z, r, sum = 0, ans = 0, tmp;
	//string s, t;
	map <int, int> cnt;
	ll mod = 1000000007;
	cin >> n;
	vll a(n);
	for(i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	bool ok = true;
	if(n % 2) {
		x = n-1;
		for(i = x; i > 0 && ok; i--) {
			if(i % 2 == 0 && cnt[i] != 2)
				ok = false;
			if(i % 2 && cnt[i] != 0)
				ok = false;
		}
		if(cnt[0] != 1)
			ok = false;
	}
	else {
		x = n-1;
		for(i = x; i >= 0; i--) {
			if(i % 2 && cnt[i] != 2)
				ok = false;
		}
	}
	if(ok) {
		x = n/2;
		ans = 1;
		for(i = 0; i < x; i++) {
			ans*= 2;
			ans%= mod;
		}
	}
	cout << ans;
}


int main()
{
    IOS;
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
        cout << endl;
    }
    return 0;
}

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

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

if(n==0){break;}
int s[10000];
int al=0;
int mx=0;
int mi=10000;

for(int i=0;i<n;i++){
cin>>s[i];
al+=s[i];
mx=max(mx,s[i]);
mi=min(mi,s[i]);
}

al=(al-mx-mi)/(n-2);
cout<<al<<endl;
}



return 0;
}


Measured memory_bytes: 3088
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




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

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

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

signed main(){
	int x, k, d;
	cin >> x >> k >> d;

	__int128 xx = abs(x);
	__int128 dd = d; 

	int l = 0, r = k;
	x = abs(x);
	while(r-l > 1){
		int mid = (r+l)/2;
		if(xx-mid*dd >= 0) l = mid;
		else r = mid;
	} 

	if(k % 2 == l % 2){
		cout << abs(x-d*l) << endl;
	}else{
		cout << abs(x-d*r) << endl;
	}

	return 0;
}


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

using namespace std;

int main (){
        int a, b, k, ans;

        cin >> a >> b >> k;
        
        for(int i=min(a, b), j=0;j<k;i--){
                if (a%i==0 and b%i==0){
                        ans=i;
                        j++;
                }       
        }

        cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
from collections import Counter

N = int(input())
A = Counter(list(map(int,input().split())))
keysA =  list(A.keys())
len_keysA = len(keysA)

if len_keysA == 1:
  print(N)
  exit()
ans = -float('inf')
for i in range(len_keysA):
  tmp_ans = A[keysA[i]]
  if i != 0 and abs(keysA[i]-keysA[i-1]) <= 1: tmp_ans += A[keysA[i-1]]
  if i != len_keysA-1 and abs(keysA[i]-keysA[i+1]) <= 1: tmp_ans += A[keysA[i+1]]  
  ans = max(ans, tmp_ans)
print(ans)  

Measured memory_bytes: 57068
#include<bits/stdc++.h>
using namespace std;
int n,ansn,a[100010];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)scanf("%d",&a[i]);
	for (int i=1,j=0;i<=n;i=j+1){
		while (a[j+1]==a[i])j++;
		ansn+=(j-i+1)/2;
	}
	cout<<ansn<<endl;
	return 0;
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  REP(i, n) cin >> a[i] >> b[i];

  vector<ll> idx(n);
  iota(ALL(idx), 0);
  sort(ALL(idx), [&](ll l, ll r){
    return a[l] + b[l] < a[r] + b[r];
  });
  reverse(ALL(idx));
  // cout << idx << endl;

  ll ret = 0;
  REP(i, n) {
    if(i%2 == 0) {
      ret += a[idx[i]];
    } else {
      ret -= b[idx[i]];
    }
  }
  cout << ret << endl;

  return 0;
}

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

using namespace std;



int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  set <int> s;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    s.insert(k);
  }
  cout << s.size() << endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np
def main():
    N = int(input())
    A = np.array(list(map(int,input().split())))
    S = np.sum(A)
    s = N*(N+1)//2
    if S%s : print("NO");return
    k = S//s
    B = A - np.arange(1,N+1)*k
    D = B[1:]-B[:-1]
    if (np.all(D<=0)) and (np.all(D%N==0)):
        print("YES")
    else:
        print("NO")
    
main()

Measured memory_bytes: 25124
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
    int n, b=0;
    ll k, a[100000], x=0, f=0, w=0, g=0;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(ll i=40;i>=0;i--){
        int z=0;
        for(int j=0;j<n;j++){
            if(((a[j]>>i)&1)==0)z++;
        }
        if(z<=n/2)continue;
        ll y=((ll)1<<i);
        if(b==0){
            if(x+y>k)continue;
            w=x;
            x+=y;
            b=1;
        }else{
            if(x+y<=k)x+=y;
            w+=y;
        }
        
    }
    
    for(int i=0;i<n;i++){
        f+=(x^a[i]);
        g+=(w^a[i]);
    }
    cout<<max(f, g)<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define rep(i, n) for(int i=0;i<n;i++)
#define pb(x) push_back(x)
#define all(x) (x).begin(), (x).end()
#define szz(x) (int)(x).size()
#define Fi first
#define Se second
typedef long double ldouble;

const int P1 = 1e9 + 103;
const int P2 = 1e9 + 289;
const int PV = 1e9 + 9;

pii operator-(pii a, pii b) { return pii(a.Fi-b.Fi<0 ? a.Fi-b.Fi+P1 : a.Fi-b.Fi, a.Se-b.Se<0 ? a.Se-b.Se+P2 : a.Se-b.Se); }
pii operator+(pii a, pii b) { return pii(a.Fi+b.Fi>=P1 ? a.Fi+b.Fi-P1 : a.Fi+b.Fi, a.Se+b.Se>=P2 ? a.Se+b.Se-P2 : a.Se+b.Se); }
pii operator*(pii a, pii b) { return pii((ll)a.Fi*b.Fi%P1, (ll)a.Se*b.Se%P2); }

char S[660][660];
pii pw[660];
pii S1[660][660], S2[660][660];

void solve() {
	pw[0] = pii(1, 1);
	for(int i=1;i<660;i++) pw[i] = pw[i-1] * pii(PV, PV);
	int N; scanf("%d", &N);
	rep(i, N) scanf("%s", S[i]);
	rep(i, N+N) rep(j, N+N) {
		S[i][j] = S[i%N][j%N];
	}
	rep(i, N+N) rep(j, N+N) {
		S1[i][j] = (j ? S1[i][j-1] : pii(0, 0)) + pii(S[i][j], S[i][j]) * pw[j];
		S2[i][j] = (i ? S2[i-1][j] : pii(0, 0)) + pii(S[i][j], S[i][j]) * pw[i];
	}
	int ans = 0;
	rep(a, N) rep(b, N) {
		int ok = 1 ;
		for(int c=0;c<N-1;c++) {
			pii t1 = (S1[a+c][b+N-1] - (b+c == 0 ? pii(0, 0) : S1[a+c][b+c-1])) * pw[620 - (b+N-1)];
			pii t2 = (S2[a+N-1][b+c] - (a+c == 0 ? pii(0, 0) : S2[a+c-1][b+c])) * pw[620 - (a+N-1)];
			if(t1 != t2) { ok = 0; break; }
		}
		ans += ok;
	}
	printf("%d\n", ans);
}

int main() {
	//DM(); return 0;
	int tc = 1; // scanf("%d", &tc);
	for(int t=1;t<=tc;t++) {
	//	printf("Case #%d: ", t);
		solve();
	}
	return 0;
}


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

int n, a[200010], ans;
typedef pair<int, int> P;
vector<P> v;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=0; i<n; ++i) cin >> a[i];
	sort(a, a+n);
	reverse(a, a+n);
	v.push_back(P(a[0], 1));
	for(int i=1; i<n; ++i){
		if(a[i] == a[i-1]) ++v[v.size()-1].second;
		else v.push_back(P(a[i], 1));
	}
	for(int i=0; i<v.size(); ++i){
		while(v[i].second > 0){
			--v[i].second;
			for(int k=30; k>0; --k){
				int t = (1<<k) - v[i].first;
				if(t < 0) break;
				int l = v[i].second > 0 ? i : i+1;
				int r = v.size();
				while(l+1 < r){
					int m = (l+r)/2;
					if(v[m].first >= t) l = m;
					else r = m;
				}
				if(v[l].first == t && v[l].second > 0){
					--v[l].second;
					++ans;
					break;
				}
			}
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3188
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  console.log(' ' + buildMaxHeap(lines.shift().split(' ').map(Number)).join(' '));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest = i;
    left = 2 * i + 1;
    right = 2 * i + 2;
    if (left >= n && right >= n) return;
    if (left < n && arr[left] > arr[i]) largest = left;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
  return arr;
}



Measured memory_bytes: 110720
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			int R = scan.nextInt();
			
			double a = 2.0*(double)R*3.1415926535897;
			
			System.out.println(a);
			
		}
		
		
	}
		

}


Measured memory_bytes: 35964
v, e = map(int, input().split())

inf = 10**7
edges = [[inf]*v for _ in range(v)]

for i in range(e):
    s, t, d = map(int, input().split())
    edges[s][t] = d

#Dpは全体集合の部分集合Sについて最後がvであるという制約の下で順序を最適化したときのSの中での最小コスト
dp = [[inf]*v for _ in range(2**v)]
dp[0][0] = 0

#集合（訪れたか訪れていないかを表す二進数）
for x in range(2**v):
    #最後に訪れたノード
    for y in range(v):
        #最後に訪れた以外のノード
        for z in range(v):
            #1.すでに訪れたかどうか 2.最後に訪れたノードではないか 3. yとzはそもそもつながっているのか
            if ((x >> y) & 1) and y != z and edges[z][y] < 10**6:
                dp[x][y] = min(dp[x][y], dp[x^(1<<y)][z]+edges[z][y])

if dp[-1][0] > 10**6:
    print(-1)
else:
    print(dp[-1][0])


Measured memory_bytes: 19800
//  Copyright © 2020 Kavish Lodha. All rights reserved.
#include <bits/stdc++.h>
using namespace std;
#define vll vector<long long>
#define mll map<long long,long long>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define pb push_back
#define prll pair<long long,long long>
typedef long long ll;
typedef long double ld;
#define rep(i,a,n)   for(ll i=a; i<n; i++)
#define rrep(i,a,n)  for(ll i=n-1; i>=a; i--)
typedef map<string,ll> msl;
#define mx 100001
#define mod 1000000007
ll gcd(ll a, ll b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll extgcd(ll a,ll b,ll& x,ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = extgcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}
ll revrsno(ll n){
    ll k=0;
    vll z;
    while(n>0){
        z.pb(n%10);
        n/=10;
    }
    rep(i,0,z.size()) k=k*10+z[i];
    return k;
}
bool isPrime(ll n){
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}
bool isPowerOfTwo(ll n) { 
   if(n==0) 
   return false; 
   return (ceil(log2(n)) == floor(log2(n))); 
}
ll powm(ll a,ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)
			res = (res * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return res;
}
ll divide(ll a,ll b) {
	return (a % mod) * powm(b, mod - 2) % mod;
}
ll mul(ll a,ll b) {
	return ((a % mod) * (b % mod)) % mod;
}
 
ll add(ll a,ll b) {
	return (a % mod + b % mod) % mod;
}
ll Totfun(ll n){
    ll z=n;
    if(n%2==0){
        while(n%2==0){
            n/=2;
        }
        z/=2;
    }
    for(ll i=3;i<=sqrt(n);i+=2){
        if(isPrime(i)&&n%i==0){
          while(n%i==0){
            n/=i;
          }
        z-=z/i;  
        }
    }
    if(n>1){
        z-=z/n;
    }
    return z;
}
ll maxPrimeFactor(ll n) { 
    ll maxPrime=-1; 
    while(n%2==0){
        maxPrime=2; 
        n>>=1; 
    } 
    for (ll i=3;i<=sqrt(n);i+=2) { 
        while(n%i==0){ 
            maxPrime=i; 
            n=n/i; 
        } 
    } 
    if (n>2) maxPrime=n; 
    return maxPrime; 
} 
ll nCr(ll n,ll r){
    if(r>n||r<0) return 0;
    ll z=1;
    for(ll i=n-r+1;i<=n;i++){
        z*=i;
        z/=(i+r-n);
    }
    return z;
}
/*
vll a[mx];
ll l[mx],d[mx];
void dfs(ll x,ll y){
   l[x]=1; d[x]=y;
   for(ll i:a[x])
   if(!l[i])
   dfs(i,y+1);
}
void bfs(ll x){
    queue<ll> q;
    q.push(x);
    l[x]=1;
    d[x]=0;
    while(!q.empty()){
        ll cur=q.front();
        q.pop();
        for(ll i : a[cur]){
            if(1-l[i]){
                q.push(i);
                d[i]=d[cur]+1;
                l[i]=1;
            }
        }
    }
}
*/
 /*sort(a,a+n);
    ll d=1;
    vll z;
    for(ll i=1;i<n;i++){
    if(a[i]==a[i-1]){
        d++;
    }
    else{
            z.pb(d);
            d=1;
    }
    }
    z.pb(d);*/
int main(){
   ios_base::sync_with_stdio(false); 
   cin.tie(NULL);
   cout.tie(NULL);
   ll a,b;
   cin>>a>>b;
   cout<<a*b;
   return 0;
}

Measured memory_bytes: 3684
#include <algorithm>
#include <string>
#include <iostream>
#include <sstream> // isstringstream
using namespace std;

int main(){
	int sum = 0;
	string w = "";
	string line = "";
	string word = "";

	cin >> w;
	while(1){
		getline(cin, line);
		if(line == "END_OF_TEXT")
			break;
		transform(line.begin(), line.end(), line.begin(), ::tolower);

		istringstream words(line);
		while(words >> word){
			if (word == w) ++sum;
		}
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3148
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

using namespace std;

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;


int main(){
    int N, C;
    int s[100000], t[100000], c[100000];
    int sm[200002];
    int tt[200002];
    cin >> N >> C;
    rep(i, N) {
        cin >> s[i] >> t[i] >> c[i];
    }
    rep(i, C){
        rep(j, 200002){
            tt[j] = 0;
        }

        rep(j, N){
            if(c[j] == i + 1){
                // 同じチャンネルのときだけ0.5秒間重複してもよい.
                tt[s[j] * 2 - 1] ++;
                tt[2 * t[j]] --;
            }
        }
        rep(j, 200002){
            if(j == 0){
                continue;
            }
            tt[j] += tt[j - 1];
        }
        rep(j, 200002){
            if(tt[j] > 0){
                sm[j] ++;
            }
        }

    }
    int mx = 0;
    rep(j, 200002){
        mx = max(sm[j], mx);
    }
    cout << mx << endl;

    return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;++i)
int main(){
  int x,y,s;
  while(cin>>x>>y>>s, x){
    int ans = 0;
    x += 100; y += 100;
    
    FOR(i,1,s) FOR(j,1,s){
        if((i*x/100 + j*x/100) == s)
          ans = max(ans, i*y/100 + j*y/100);
    }
    cout<<ans<<"\n";
  }
  return 0;
}

Measured memory_bytes: 3080
import itertools
import sys
import heapq
sys.setrecursionlimit(10**5 + 1)
n, m = map(int, input().split())

graph = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = map(lambda x: int(x) - 1, input().split())

    graph[a].append(b)
    graph[b].append(a)

rooted = [[] for _ in range(n)]
rev_rooted = [[] for _ in range(n)]
que = [(0, -1, 0)]
bfs_target = []
while que:
    node, parent, distance = que.pop()
    heapq.heappush(bfs_target, (-distance, node))
    for child in graph[node]:
        if child != parent:
            que.append((child, node, distance + 1))
            rooted[node].append(child)
            rev_rooted[child].append(node)
            # print(node, child)

def mod(v):
    if v >= m:
        return v % m
    return v


dp = [1] * n
while bfs_target:
    node = heapq.heappop(bfs_target)[1]
    for parent in rev_rooted[node]:
        dp[parent] = mod(dp[parent] * (dp[node] + 1))
        que.append(parent)

rev_dp = [0] * n
que = [0]
while que:
    node = que.pop()
    cp = [1]
    rev_cp = [1]
    for i, child in enumerate(rooted[node]):
        cp.append(mod(cp[i] * (dp[child] + 1)))
    for i, child in enumerate(reversed(rooted[node])):
        rev_cp.append(mod(rev_cp[i] * (dp[child] + 1)))
    rev_cp = rev_cp[::-1]
    for i, child in enumerate(rooted[node]):
        rev_dp[child] = mod(cp[i] * rev_cp[i + 1] * (rev_dp[node] + 1))
        que.append(child)


# print(dp)
for v1, v2 in zip(dp, rev_dp):
    print(mod(v1 * (v2 + 1)))


Measured memory_bytes: 143764
def resolve():
    def check(arr):
        height = 0
        for b, h in arr:
            if height+b < 0:
                return False
            height += h
        return True

    N = int(input())
    plus = []
    minus = []
    total = 0
    for _ in range(N):
        # 1つのパーツを処理
        S = input()
        cum = 0 # 累積和(最高地点)
        bottom = 0 # 最下地点
        for s in S:
            if s == "(":
                cum += 1
            else:
                cum -= 1
            bottom = min(bottom, cum)

        total += cum
        if cum > 0:
            plus.append((bottom, cum))
        else:
            minus.append((bottom-cum, -cum))

    plus.sort(reverse=True)
    minus.sort(reverse=True)

    if check(plus) and check(minus) and total == 0:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 80332
#include <bits/stdc++.h>
using namespace std;
int main(){
    cout << fixed << setprecision(6);
    double a,b,x;
    cin >> a >> b >> x;
    double rad,deg,PI;
    PI=acos(-1);
    if(x/a>=(a*b)/2){
        double h=2*b-(2*x/(a*a));
        rad=atan2(h,a);
        deg=rad*360/(2*PI);
        cout << deg << endl;
        return 0;
    }
    else{
        double h=(2*x)/(a*b);
        rad=atan2(b,h);
        deg=rad*360/(2*PI);
        cout << deg << endl;
        return 0;
    }
}

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

int main(void){
    string s,t;
    cin >> s >> t;
    bool check = false;
    for(int i = 0;i < s.size();i++){
        string s1 = s.substr(i) + s.substr(0,i);
        if(s1 == t)check = true;
    }
    if(check == true)cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N;
ll A[100000];
int cnt[1000000];
vector<int> facs[10000];

#define N_MAX 1000002
typedef pair<ll, ll> P;

const ll MOD = 1000000007;

ll inv[N_MAX];

void init(){
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
}

vector<int> fac(int n, vector<int> &ans){
    for(int i = 2; i*i <= n; i++){
        int c = 0;
        while(n%i == 0){
            n /= i;
            c++;
            ans.push_back(i);
        }
        cnt[i] = max(cnt[i], c);
    }
    if(n != 1) {
        ans.push_back(n);
        cnt[n] = max(cnt[n], 1);
    }
    return ans;
}

int main(){
    init();
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        fac(A[i], facs[i]);
    }
    ll ans = 0;
    vector<int> ps;
    for(int i = 0; i < 1000000; i++){
        if(cnt[i] != 0) ps.push_back(i);
    }
    ll lcm = 1;
    for(int i = 0;i < ps.size(); i++){
        for(int j = 0; j < cnt[ps[i]]; j++){
            lcm *= ps[i];
            lcm %= MOD;
        }
    }
    for(int i = 0; i < N; i++){
        ans += (lcm*inv[A[i]])%MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

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

const int INF=1e9;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

int N;
int Par[100005],Rank[100005];
P x[100005],y[100005];
PP xy[200005]; 

void init(int n){
    for(int i=0; i<n; i++){
        Par[i]=i;
        Rank[i]=0;
    }
}
int find(int x){
    if(Par[x]==x){
        return x;
    }else{
        return Par[x]=find(Par[x]);
    }
}
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y) return;
 
    if(Rank[x]<Rank[y]){
        Par[x]=y;
    }else{
        Par[y]=x;
        if(Rank[x]==Rank[y]) Rank[x]++;
    }
}
bool same(int x,int y){
    return find(x)==find(y);
}
  
int main(){
 
cin>>N;

for(int i=0; i<N; i++){
    scanf("%d %d",&x[i].first,&y[i].first);
    x[i].second=i; y[i].second=i;
}

sort(x,x+N); sort(y,y+N);

for(int i=1; i<N; i++){
    xy[i-1].first=x[i].first-x[i-1].first; xy[i-1].second=P(x[i].second,x[i-1].second);
}
//for(int i=0; i<N-1; i++) cout<<xy[i].first<<endl;
for(int i=1; i<N; i++){
    xy[i+N-2].first=y[i].first-y[i-1].first; xy[i+N-2].second=P(y[i].second,y[i-1].second);
}
//for(int i=N-1; i<2*N-2; i++) cout<<xy[i].first<<endl;
sort(xy,xy+2*N-2);

init(N); 

ll ans=0LL;
for(int i=0; i<2*N-2; i++){
    int p=xy[i].second.first;
    int q=xy[i].second.second;
    if(!same(p,q)){
        unite(p,q); ans+=xy[i].first;
    }
}

cout<<ans<<endl;

}

Measured memory_bytes: 4992
#include <iostream>
#include <set>

using namespace std;

long long int gcd(long long int x, long long int y) {
  if (x < y) {
    return gcd(y, x);
  }

  if (y == 0) {
    return x;
  }

  return gcd(y, x%y);
}

int main() {
  long long int a, b;
  cin >> a >> b;

  long long int g = gcd(a, b);

  set<long long int> f;
  for (long long int i = 2; i*i <= g; ++i) {
    while (g%i == 0) {
      f.insert(i);
      g /= i;
    }
  }
  if (g != 1) f.insert(g);

  cout << f.size() + 1 << endl;

  return 0;
}


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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n, m, q;
string s;

Vs cs = {"a", "c", "g", "t"};

bool isOK(string s) {
    if (s.find("agc") != -1) {
        return false;
    }
    REP(i, s.size()-1) {
        string t = s;
        swap(t[i], t[i+1]);
        if (t.find("agc") != -1) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> n;

    V<Msi> v(n, Msi());
    FOR(i, cs) {
        v[0].insert({*i, 1});
    }
    REP2(i, 1, n) {
        FOR(j, v[i-1]) {
            string key = j->first;
            int val = j->second;
            FOR(k, cs) {
                string newk = key + *k;
                if (!isOK(newk)) {
                    continue;
                }
                if (newk.size() < 4) {
                    v[i].insert({newk, val});
                    continue;
                }
                string newkEnd = newk.substr(1, 3);
                if (v[i].count(newkEnd) == 0) {
                    v[i].insert({newkEnd, val});
                } else {
                    v[i][newkEnd] += val;
                    v[i][newkEnd] %= MOD;
                }
            }
        }
    }

    int res = 0;
    FOR(i, v.back()) {
        res += i->second;
        res %= MOD;
    }
    std::cout << res << '\n';

    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
   int n;
    cin >> n;
    
    int a[n];
    f(i,n) cin >> a[i];
    
    int mx = a[0];
    int res = 0;
    
    for(int i=1;i<n;i++)
    {
        if(a[i] < mx)
        {
            res+=mx-a[i];
        }
        
        mx = max(mx,a[i]);
    }
    
    cout << res;
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 5184