akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const long long inf = 1e18+1;
int n, m;
long long p;
long long cst[2505];
vector < pair< pair<int,int> , long long>> edg;
int v[2505],v1[2505];
vector <int> ig[2505] , ig1[2505];
void dfs(int nod){
    v[nod] = 1;
    for(auto i : ig[nod]){
        if(v[i]==0){
            dfs(i);
        }
    }
}
void dsf(int nod){
    v1[nod] = 1;
    for(auto i : ig1[nod]){
        if(v1[i]==0){
            dsf(i);
        }
    }

}
int main(){
    cin >> n >> m >> p;
    int a, b , c;
    for(int i = 2 ; i <= n ; i++)cst[i]=inf;
    for(int i = 1 ; i <= m ; i++){
        cin >> a >> b >> c;
        edg.pb({{a,b},p-c});
        ig[b].pb(a);
        ig1[a].pb(b);
    }
    dfs(n);
    dsf(1);
    int t = n - 1;
    while(t--){
        for(auto e : edg){
            if(cst[e.first.second] > cst[e.first.first] + e.second){
                cst[e.first.second] = cst[e.first.first] + e.second;
            }
        }
    }
    t = 1;
    for(auto e : edg){
        if(cst[e.first.second] > cst[e.first.first] + e.second && v[e.first.second]==1 && v1[e.first.second]==1)t=0;
    }
    if(t == 0){
        cout << -1;
        return 0;
    }else{
        cout << max((long long)0,-cst[n]);
    }
    return 0;
}


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

int main(){
  int N; cin >> N;
  vector<int> b(N);
  for(int i = 0; i < N; i++){
    cin >> b[i];
    b[i]--;
  }
  
  vector<int> a;
  for(int i = 0; i < N; i++){
    for(int j = b.size() - 1; j >= 0; j--){
      if(b[j] == j) {
        a.emplace_back(b[j] + 1);
        b.erase(b.begin() + j);
        break;
      }
    }
  }
  
  if(b.empty()) {
    for(int i = N - 1; i >= 0; i--){
      cout << a[i] << endl;
    }
  }else {
    cout << -1;
  }
}

Measured memory_bytes: 384
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include "bits/stdc++.h" 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

void Flash(){
    ll n;
    cin>>n;
    bool ans=false;
    while(n){
        if((n%10)==7){
            ans=true;
        }
        n/=10;
    }
    if(ans){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
}

int main(int argc, char const *argv[]){
    ThunderClap;
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
using ll = long long;
int main(){
  int n,m;
  cin>>n>>m;
  int E = n*(n-1)/2;
  int O = m*(m-1)/2;
  
  cout<<E+O<<endl;
  
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    //D - Binomial Coefficients
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long[] ai = new long[n];
        long maxA = 0;
        int maxI = 0;
        for(int i = 0; i < n; i++) {
            ai[i] = scanner.nextLong();
            if (ai[i] > maxA) {
                maxA = ai[i];
                maxI = i;
            }
        }

        int maxJ = 0;
        long nearest = Long.MAX_VALUE;
        for(int i = 0; i < n; i++) {
            long d = Math.abs(maxA / 2 - ai[i]);
            if ( d == 0 ) {
                maxJ = i;
                break;
            }
            else if ( maxI != i && d < nearest ) {
                nearest = d;
                maxJ = i;
            }
        }
        System.out.printf("%d %d\n", maxA, ai[maxJ]);
    }
}


Measured memory_bytes: 49192
#include <cstdio>
#include <cctype>

int main(){
    char a;
    while(a != '\n'){
        scanf("%c", &a);
        if (isupper(a)){
            printf("%c", tolower(a));
        } else if (islower(a)){
            printf("%c", toupper(a));
        } else {
            printf("%c", a);
        }
    }
}


Measured memory_bytes: 2704
#![allow(unused_imports)]
use std::io;
use std::cmp::*;
use std::collections::*;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}
#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().trim().parse().unwrap()
}
#[allow(dead_code)]
fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect()
}

fn main() {
    let _: i32 = read();
    let s: String = read();
    let mut cnt = 0;
    let mut pre = 0;
    for c in s.bytes() {
        // let c = c as char;
        if c == b'(' {
            cnt += 1;
        } else {
            if cnt == 0 {
                pre += 1;
            } else {
                cnt -= 1;
            }
        }
    }
    println!("{}{}{}",
             String::from_utf8(vec![b'(';pre]).unwrap(),
             s,
             String::from_utf8(vec![b')';cnt]).unwrap());
    // let mut ans = String::new();
    // for _ in 0..pre {
    //     ans.push('(');
    // }
    // ans += &s;
    // for _ in 0..cnt {
    //     ans.push(')');
    // }
    // println!("{}", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>
int main(){
  int s, t;
  scanf("%d",&s);
  scanf("%d",&t);
  if (s == 1 && t == 2)
    printf("3\n");
  else if (s == 1 && t == 3)
    printf("2\n");
  else if (s == 2 && t == 3)
    printf("1\n");
  else if (s == 2 && t == 1)
    printf("3\n");
  else if (s == 3 && t == 2)
    printf("1\n");
  else if (s == 3 && t == 1)
    printf("2\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

LL cao(LL h,LL w) {
  LL maxs,mins,s1,s2,s3,a,b,ans = h * w,c;
  if (w & 1) a = w / 2 + 1,b = w - a;
  else a = b = w / 2;
  for (LL i = 1; i < h; ++i) {
    s1 = a * i,s2 = b * i,s3 = h * w - s1 - s2;
    maxs = max({s1,s2,s3});
    mins = min({s1,s2,s3});
    ans = min(maxs - mins,ans);
    s1 = a * i,s2 = b * h,s3 = h * w - s1 - s2;
    maxs = max({s1,s2,s3});
    mins = min({s1,s2,s3});
    ans = min(maxs - mins,ans);
    s1 = a * h ,s2 = b * i,s3 = h * w - s1 - s2;
    maxs = max({s1,s2,s3});
    mins = min({s1,s2,s3});
    ans = min(maxs - mins,ans);
  }
  a = b = c = w / 3;
  ans = min(ans,h);
  return ans;
}
int main() {
  LL h,w,ans;
  scanf("%lld%lld",&h,&w);
  ans = h * w;
  if (h % 3 == 0 || w % 3 == 0) printf("0\n");
  else {
    ans = cao(h,w);
    ans = min(ans,cao(w,h));
    printf("%lld\n",ans);
  }
}
    


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <climits>
using namespace std;
typedef long long ll;

int n;
vector<pair<int, ll>> *adj_yen, *adj_snook;
ll *d_yen, *d_snook;

void dijkstra(int start, vector<pair<int, ll>> *adj, ll *d) {
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> PQ;
    for (int i = 0; i < n + 1; i++) {
        d[i] = LLONG_MAX;
    }
    d[start] = 0;

    PQ.push(make_pair(0, start));
    while (!PQ.empty()) {
        pair<ll, int> f = PQ.top();
        PQ.pop();
        int u = f.second;
        for (int i = 0; i < adj[u].size(); i++) {
            int v = adj[u][i].first;
            if (d[u] + adj[u][i].second < d[v]) {
                d[v] = d[u] + adj[u][i].second;
                PQ.push(make_pair(d[v], v));
            }
        }
    }
}

int main() {
    int m, s, t;
    scanf("%d %d %d %d", &n, &m, &s, &t);

    adj_yen = new vector<pair<int, ll>>[n+1];
    adj_snook = new vector<pair<int, ll>>[n+1];
    d_yen = new ll[n+1];
    d_snook = new ll[n+1];

    for (int i = 0; i < m; i++) {
        int u, v;
        ll a, b;
        scanf("%d %d %lld %lld", &u, &v, &a, &b);
        adj_yen[u].push_back(make_pair(v, a));
        adj_snook[u].push_back(make_pair(v, b));
        adj_yen[v].push_back(make_pair(u, a));
        adj_snook[v].push_back(make_pair(u, b));
    }

    dijkstra(s, adj_yen, d_yen);
    dijkstra(t, adj_snook, d_snook);

    vector<ll> costs;
    costs.push_back(d_yen[n] + d_snook[n]);
    for (int i = n - 1; i > 0; i--) {
        costs.push_back(min(costs.back(), d_yen[i] + d_snook[i]));
    }

    for (int i = n - 1; i >= 0; i--) {
        printf("%lld\n", 1000000000000000 - costs[i]);
    }

    return 0;
}

Measured memory_bytes: 19840
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int n; cin >> n;
	vector<string>vec(n);
	rep(i, 0, n)cin >> vec[i];

	string ans;
	vector<map<char, int>>mp(n);
	rep(i, 0, n) {
		rep(j, 0, vec[i].size())mp[i][vec[i][j]]++;
	}
	for (auto p : mp[0]) {
		bool ok = true;
		int cnt = p.second;
		rep(i, 1, n) {
			if (!mp[i].count(p.first)) {
				ok = false;
				break;
			}
			chmin(cnt, mp[i][p.first]);
		}
		if (ok) {
			string a = string(cnt, p.first);
			ans += a;
		}
	}
	sort(all(ans));
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3708
#include<bits/stdc++.h>
#define inf 1<<29
using namespace std;

int n,m,K,a,b;
string s,ans="Yes";
int skill[101][101][2];
vector<int> v[101];
bool checked[101]={},visited[101]={};

void init(){
  for(int i=0;i<101;i++){
    for(int j=0;j<101;j++){
      skill[i][j][0]=-1;
      skill[i][j][1]=inf;
    }
  }
}

void dfs(int num){
  if(visited[num]){
    ans="No";
    return;
  }
  visited[num]=true;
  for(int i=0;i<v[num].size();i++){
    if(!checked[v[num][i]])dfs(v[num][i]);
  }
  checked[num]=true;
  visited[num]=false;
}

int main()
{
  init();
  cin>>m>>n;
  for(int i=0;i<m;i++){
    cin>>K;
    for(int j=0;j<K;j++){
      cin>>a>>s>>b;
      a--;
      if(s[0]=='>')skill[i][a][0]=max(b,skill[i][a][0]);
      else skill[i][a][1]=min(b,skill[i][a][1]);
    }
  }
  for(int i=0;i<m;i++){
    for(int j=0;j<m;j++){
      for(int k=0;k<n;k++){
	if(skill[i][k][1]==inf || skill[j][k][0]==-1)continue;
	if(skill[i][k][1]<skill[j][k][0]){
	  v[i].push_back(j);
	  break;
	}
      }
    }
  }
  for(int i=0;i<m;i++){
    if(!checked[i])dfs(i);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;

int main(){
    ll N;
    cin >> N;
    vector<ll> even;
    for (int i = 0; i < N; i++) {
      ll a = 0;
      cin >> a;
      if (a % 2 == 0) even.push_back(a);
    }

    ll cnt = 0;
    bool check = true;
    for (int i = 0; i < even.size(); i++){
        while(even[i]%2==0){
          even[i] /= 2;
          cnt++;
        }
    } 
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3720
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define MAX_N 10000
#define MAX_R 5000

void
solve(int n)
{
	int bins[MAX_N / 2];
	int remains[MAX_R];

	int ix = 0;
	for (int i = 1; i < n; ++i)
	{
		int r = (i * i) % n;

		int j;
		for (j = 0; j < ix; ++j)
		{
			if (r == remains[j])
				break;
		}

		if (j >= ix)
			remains[ix++] = r;
	}

	int m = (n - 1) / 2;
	for (int i = 1; i <= m; ++i)
		bins[i] = 0;

	for (int i = 0; i < ix; ++i)
	{
		for (int j = i + 1; j < ix; ++j)
		{
			if (i != j)
			{
				int d = remains[i] - remains[j];
				if (d < 0)
					d += n;

				if (d > m)
					d = n - d;

				bins[d]++;
			}
		}
	}

	for (int i = 1; i <= m; ++i)
		printf("%d\n", 2 * bins[i]);
}

int
main(int argc, char **argv)
{
	while (true)
	{
		int n;
		scanf("%d", &n);
		if (n == 0)
			break;

		solve(n);
	}

	return 0;
}

Measured memory_bytes: 1748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; i++)
int main(){
    string s,t; cin >> s >> t;
    vector<char> Slist(26,-1),Tlist(26,-1);
    int judge = 1;
    rep(i,s.size()){
        if(Slist[s[i]-'a'] == -1){
            Slist[s[i]-'a'] = t[i];
        }else{
            if(Slist[s[i]-'a'] != t[i]) judge = 0;
        }
        if(Tlist[t[i]-'a'] == -1){
            Tlist[t[i] - 'a'] = s[i];
        }else{
            if(Tlist[t[i]-'a'] != s[i]) judge = 0;
        }
    }
    if(judge){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 776
#include <map>
#include <list>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int a[5];
int main()
{
	fast;
	cin>>a[1]>>a[2]>>a[3];
	sort (a,a+4);
	cout<<a[1]+a[2]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;
struct mint
{
    ll x;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }

    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }

    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const
    {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const
    {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const
    {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    mint inv() const
    {
        return pow(mod - 2);
    }
    mint &operator/=(const mint a)
    {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const
    {
        mint res(*this);
        return res /= a;
    }
};

mint c[4005][4005];

void init(){
    c[0][0] = 1;
    rep(i, 4001){
        rep(j, i+1){
            c[i+1][j] += c[i][j];
            c[i+1][j+1] += c[i][j]; 
        }
    }
}

mint comb(int n, int k){
    return c[n][k];
}

mint f2(int n, int k){
    return comb(n+k-1,k-1);
}

mint f(int n, int k){
    if(n < k) return 0;
    if(n == 0 && k == 0) return 1;
    if(k < 1) return 0;
    return f2(n-k, k);
}

int main(){
    init();
    int k, n;
    cin >> n >> k;

    mint b;
    mint r;

    rrep(i, k){
        b = f(k, i);
        r = f(n-k, i-1) + f(n-k, i)*2 + f(n-k, i+1);
        mint ans = b*r;
        cout << ans.x << endl;
    }

    return 0;
}


Measured memory_bytes: 125696
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, k; cin >> n >> k;
	vector<ll>a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];
	sort(all(a)); reverse(all(a));
	ll sm = 0;
	for (ll i = k; i < n; i++) {
		sm += a[i];
	}
	cout << sm << endl;
	return 0;
}

/*
3
0 1
3 0
1 0
*/

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

#define ll long long

using namespace std;

int main() {
    
    ll n;
    cin>>n;
    ll arr[n-1];
    for(ll i=0;i<n;i++)
    cin>>arr[i];
    ll pre_sum[n-1], pre_rsum[n-1];
    
    pre_sum[0] = arr[0];
    pre_rsum[n-1] = arr[n-1];
//    cout<<"pre_rsum[n-1]:"<<pre_rsum[n-1]<<"\n";
    
    for(ll i=1;i<n;i++)
        pre_sum[i] = pre_sum[i-1] + arr[i];
    for(ll i=n-2;i>=0;i--)
        pre_rsum[i] = pre_rsum[i+1] + arr[i];
    
    ll ans = LONG_MAX;
    for(ll i=0;i<n-1;i++)
    {
        ans = min(ans, abs(pre_sum[i]-pre_rsum[i+1]));
    }
    cout<<ans<<"\n";
    
/*    
    for(int i=0;i<n;i++)
    cout<<pre_sum[i]<<" ";
    cout<<"\n";
    for(int i=0; i<n; i++)
    cout<<pre_rsum[i]<<" ";
*/
    
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int N=2e5+10;
const int maxn=1e6;
int fa1[N],fa2[N];
int find1(int x)
{
    if(fa1[x]!=x) fa1[x]=find1(fa1[x]);
    return fa1[x];
}
int find2(int x)
{
    if(fa2[x]!=x) fa2[x]=find2(fa2[x]);
    return fa2[x];
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,k,l,x,y;
    cin>>n>>k>>l;
    for(int i=1;i<=n;i++) fa1[i]=i,fa2[i]=i;
    for(int i=1;i<=k;i++)
    {
        cin>>x>>y;
        int r1=find1(x);
        int r2=find1(y);
        if(r1!=r2) fa1[r2]=r1;
    }
    for(int i=1;i<=l;i++)
    {
        cin>>x>>y;
        int r1=find2(x);
        int r2=find2(y);
        if(r1!=r2) fa2[r2]=r1;
    }
    for(int i=1;i<=n;i++)
    {
        find1(i);
        find2(i);
    }
    map<pair<int,int>,int>f;
    for(int i=1;i<=n;i++)
    {
        f[make_pair(fa1[i],fa2[i])]++;
    }
    for(int i=1;i<=n;i++) cout<<f[make_pair(fa1[i],fa2[i])]<<" ";
    return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
        
        int32_t main() {
            
            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
           
            int x,n;
            cin>>x>>n;
            vector<int> p(102);
            for(int i=0;i<n;i++){
                int y;cin>>y;
                p[y]=1;
            }
            int ans=INT_MAX;
            int z=x;
            for(int i=0;i<102;i++){
                if( p[i]==0 && abs(x-i)<ans ){
                    ans = abs(x-i);
                    z = i;
                }
            }
            cout<<z<<endl;
            return 0;
        }

 

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

int main(){
  ll n;cin>>n;
  
  vector<int> ans;
  while(n){
    if(n%26==0){
      ans.push_back(26);
      n/=26;n--;
    }else{
    ans.push_back(n%26);
    n/=26;
    }
  }
  vector<char> as(0);
  for(auto x:ans){
    as.push_back((char)(x+96));
  }
  reverse(as.begin(),as.end());
  
  for(auto x:as)cout<<x;
  cout<<endl;
}

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

int main ()
{
    int n, x;
    while(cin >> n >> x)
    {
        if (n == 0 && x == 0) break;
        
        int cnt = 0;
        for (int i = 1;i <= n-2;i++)
        {
            for (int j = i + 1;j  <= n-1;j++)
            {
                for (int k = j + 1;k <= n;k++)
                {
                    if (i + j + k == x) cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
from fractions import gcd
n = int(input())
lcm = list(map(int, input().split()))
ans = [1] * n
while len(lcm) < (1 << 14):
  lcm.append(1)
  ans.append(0)
for i in range(13, -1, -1):
  bit = 1 << i
  for j in range(bit):
    new = lcm[j] // gcd(lcm[j], lcm[j | bit]) * lcm[j | bit]
    ans[j] = new // lcm[j] * ans[j] + new // lcm[j | bit] * ans[j | bit]
    ans[j] %= 1000000007
    lcm[j] = new
print(ans[0])
    
  

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

using namespace std;

int main(){
    int n,i = 1;
    cin>>n;
    CHECK_NUM:
    int x = i;
    if ( x % 3 == 0 ){
        cout << " " << i;
        goto END_CHECK_NUM;
    }
    INCLUDE3:
    if ( x % 10 == 3 ){
        cout << " " << i;
        goto END_CHECK_NUM;
    }
    x /= 10;
    if ( x ) goto INCLUDE3;
    END_CHECK_NUM:
    if ( ++i <= n ) goto CHECK_NUM;

    cout << endl;
}


Measured memory_bytes: 3124
N=int(input())
L=[]
for i in range(N):
  L.append(input())
if not len(set(L))==len(L):
  print("No")
else:
  for n in range(N):
    if n==(N-1):
      print("Yes")
    elif L[n][-1] == L[n+1][0]:
      continue
    else:
      print("No")
      break

Measured memory_bytes: 3060
<?php

while (true) {
    $a = str_split(rtrim(fgets(STDIN)));
    if (feof(STDIN)) {
        break;
    }
    $dp = array($a);
    for ($i = 1; $i < 10; $i++) {
        $dp[] = array();
        for ($j = 0; $j < 10 - $i; $j++) {
            $sum = (string) ($dp[$i - 1][$j] + $dp[$i - 1][$j + 1]);
            $dp[$i][$j] = $sum[strlen($sum) - 1];
        }
    }
    echo $dp[9][0] . PHP_EOL;
}

Measured memory_bytes: 6660
import sys
sys.setrecursionlimit(1000000)

def dfs(v, visited, edges, order):
  visited[v] = True
  for to in edges[v]:
    if not visited[to]:
      dfs(to, visited, edges, order)
  order.append(v)

def search_strongly_connection(v, visited, reverse_edges, parent, num):
  visited[v] = True
  for to in reverse_edges[v]:
    if not visited[to]:
      parent[to] = num
      search_strongly_connection(to, visited, reverse_edges, parent, num)


v,e=map(int,input().split())
edges=[[] for _ in range(v)]
reverse_edges = [[] for _ in range(v)]
#有向グラフ
for _ in range(e):
    s,t=map(int,input().split())
    edges[s].append(t)
    reverse_edges[t].append(s)

order=[]
visited=[False]*v
for i in range(v):
    if not visited[i]:
        dfs(i,visited,edges,order)
order.reverse()

visited=[False]*v
parent=[i for i in range(v)]
for i in order:
    if not visited[i]:
        search_strongly_connection(i,visited,reverse_edges,parent,i)

q=int(input())
for _ in range(q):
    u,v=map(int,input().split())
    print(1 if parent[u]==parent[v] else 0)


Measured memory_bytes: 19192
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int n,a[101],i,j,t,b,c,d,e;
    e=99999999;
    d=0;
    c=0;
    t=0;
    b=0;
    cin>>n;
    for (i=0;i<n;i++){
        cin>>a[i];
        c=c+a[i];
    }
    for (i=0;i<n;i++){
        t+=1;
        for (j=0;j<t;j++){
            d=d+a[j];
            b=c-2*d;
        }
        if (b<0){
            b=-b;
        }
        if (b<=e){
            e=b;
        }
        d=0;
        b=0;
    }
    cout<<e;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ar array
 
const int mxN=2e5;
int n, a[mxN];
ll c[mxN], ans;
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	cin >> n;
	for(int i=0; i<n; ++i) {
		cin >> a[i], --a[i];
		++c[a[i]];
	}
	for(int i=0; i<n; ++i)
		ans+=c[i]*(c[i]-1)/2;
	for(int i=0; i<n; ++i) {
		ans-=c[a[i]]*(c[a[i]]-1)/2;
		--c[a[i]]*(c[a[i]]-1)/2;
		ans+=c[a[i]]*(c[a[i]]-1)/2;
		cout << ans << "\n";
		ans-=c[a[i]]*(c[a[i]]-1)/2;
		++c[a[i]]*(c[a[i]]-1)/2;
		ans+=c[a[i]]*(c[a[i]]-1)/2;
	}
}

Measured memory_bytes: 4096
def main():
    n = input()
    dd = map(int, raw_input().split())
    count = {}
    for d in dd:
        count[d] = count.get(d, 0) + 1
    if count.get(0, 0) != 1 or dd[0] != 0:
        print 0
        return
    ans = 1
    pre = 0
    for c in sorted(count)[1:]:
        if pre + 1 != c:
            print 0
            return
        ans = ans * pow(count[pre], count[c], 998244353) % 998244353
        pre = c
    print ans


main()


Measured memory_bytes: 55408
# def gen_is_prim(n):
#     is_prim = [i%2==1 for i in range(n+1)]
#     is_prim[1] = False; is_prim[2] = True
#     for i in range(3, n+1, 2):
#         if not is_prim[i]: continue
#         for j in range(i+i, n+1, i):
#             is_prim[j] = False
#     return is_prim

def gen_d_prim(n):
    D = [n+1 if i%2 else 2 for i in range(n+1)]
    D[0] = D[1] = 0
    for i in range(3, n+1, 2):
        if D[i] != n+1: continue
        for j in range(i, n+1, i): D[j] = i
    return D

def gcd_all(A):
    from math import gcd
    g = 0
    for a in A: g = gcd(g, a)
    return g

def is_pairwise():
    # MAX_A = 10**6 + 1
    # C = [0] * MAX_A
    # for a in A: C[a] += 1
    # if sum(C[2::2]) > 1: return False
    # for i in range(3, MAX_A, 2):
    #     if sum(C[i::i]) > 1: return False
    # return True

    MAX_A = 10**6
    D = gen_d_prim(MAX_A)
    C = [0] * (MAX_A + 1)
    all_p = set()
    for a in A:
        p = set()
        while a != 1:
            if not D[a] in p:
                if D[a] in all_p:
                    return False
            all_p.add(D[a])
            p.add(D[a])
            a //= D[a]
        # print('pre {}'.format(pre))
        # print('now {}'.format(now))
        # print('now & pre {}'.format(now & pre))
        # if len(now & all) > 0: return False
        # all = all | now
    return True

def solve():
    if is_pairwise(): return 0
    if gcd_all(A) == 1: return 1
    return 2

    # if gcd_all(A) > 1: return 2
    # if is_pairwise(): return 0
    # return 1


n = int(input())
A = [*map(int, input().split())]
print(['pairwise','setwise','not'][solve()], 'coprime')


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

const int N = 505;
int n, m; char a[N], r[N][N], b[N][N];
int main () {
	scanf("%d%d", &n, &m);
	memset(r, '.', sizeof r);
	memset(b, '.', sizeof b);
	for (int i = 1; i <= n; ++i) {
		if (i & 1) {
			for (int j = 1; j < m; ++j) r[i][j] = '#';
		} else r[i][1] = '#';
	}
	for (int i = 1; i <= n; ++i) {
		if (~i & 1) {
			for (int j = 2; j <= m; ++j) b[i][j] = '#';
		} else b[i][m] = '#';
	}
	for (int i = 1; i <= n; ++i) {
		scanf("%s", a + 1);
		for (int j = 1; j <= m; ++j) {
			if (a[j] == '#') r[i][j] = b[i][j] = '#';
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) putchar(r[i][j]);
		putchar('\n');
	}
	putchar('\n');
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) putchar(b[i][j]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1280
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-19 21:04:10
*/

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

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

    int sum = 0;
    for (int i = 0; i < m; i++)
        sum += a[i];

    cout << max(-1, n-sum) << endl;

    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
signed main(){
    int n; cin>>n;
    vector<int>v(n); rep(i,n)cin>>v[i];
    sort(all(v));
    //  rep(i,n)if(i)cout<<" "<<v[i]; else cout<<v[i]; cout<<endl;
    map<int,int>mp;
    rep(i,n)mp[v[i]]++;
    int res=0;
    int cnt=0;
    for(auto itr:mp){
        if(itr.second%2)mp[itr.first]=1;
        else mp[itr.first]=2;
    }
    for(auto itr:mp){
        if(itr.second==1)cnt++;
        else {
            res++;
        }
    }
    cout<<cnt+(res%2?res-1:res)<<endl;
}



Measured memory_bytes: 7296
N=int(input())
A=[int(x) for x in input().split()]
cnt=0
for i in range(N-1):
  if A[i]==i+1:
    A[i],A[i+1]=A[i+1],A[i]
    cnt+=1
if A[N-1]==N:
  cnt+=1
print(cnt)

Measured memory_bytes: 13880
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
typedef long long ll;
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template <typename Head> void dump(Head &&head) {
  cerr << head;
  dump();
}
template <typename Head, typename... Tail>
void dump(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  dump(forward<Tail>(tail)...);
}
#define debug(...)                                                               \
  do {                                                                         \
    cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = ";                        \
    dump(__VA_ARGS__);                                                         \
  } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

const ll LINF = 1LL << 60;
const int INF = 1001001001;

/////////////////////////////////////////////////////////////////////


int main()
{
  ll x; cin >> x;
  cout << (x^1) << endl;

  return 0;
}


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

using namespace std;

//int N,M,K,L,R,H,W;
long long int N,M,K,L,R,H,W;

//constexpr long long int MOD=1000000007;
//constexpr  int MOD=1000000007;
constexpr int MOD=998244353;
//constexpr long long int MOD=998244353;

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

	cin>>N;
	vector<set<int>>edge(N);
	for(int i=1;i<N;i++){
		cin>>L>>R;
		L--;
		R--;
		edge[L].insert(R);
		edge[R].insert(L);
	}
	string s;
	cin>>s;
	queue<int>QQ;
	for(int i=0;i<N;i++){
		if(edge[i].size()==1&&s[i]=='B')QQ.push(i);
	}
	int ans=2*N-2;
	while(!QQ.empty()){
		int cn=QQ.front();
		QQ.pop();
		if(edge[cn].empty())continue;
		ans-=2;
		edge[*edge[cn].begin()].erase(cn);
		if(edge[*edge[cn].begin()].size()==1&&s[*edge[cn].begin()]=='B')QQ.push(*edge[cn].begin());
		edge[cn].clear();
	}
	vector<int>add(N,1);
	for(int i=0;i<N;i++){
		if(edge[i].empty())add[i]--;
		else if(s[i]=='B'&&edge[i].size()%2==0)add[i]--;
		else if(s[i]=='W'&&edge[i].size()%2==1)add[i]--;
	//	cout<<i<<" "<<add[i]<<endl;
	}
	if(ans==0){
		for(auto i:s)ans|=i=='W';
		cout<<ans<<endl;
		
		return 0;
	}
	vector<int>box(N,-1);
	for(int i=0;i<N;i++){
		if(edge[i].empty())continue;
		queue<int>Q;
		box[i]=add[i];
		Q.push(i);
		while(!Q.empty()){
			int cn=Q.front();
			Q.pop();
			for(auto j:edge[cn]){
				if(box[j]==-1){
					box[j]=box[cn]+add[j];
					Q.push(j);
				}
			}
		}
      break;
	}
	int st=0;
	for(int i=1;i<N;i++){
		if(box[i]>box[st])st=i;
	}
	for(auto &i:box)i=-1;
	queue<int>Q;
		box[st]=add[st];
		Q.push(st);
		while(!Q.empty()){
			int cn=Q.front();
			Q.pop();
			for(auto j:edge[cn]){
				if(box[j]==-1){
					box[j]=box[cn]+add[j];
					Q.push(j);
				}
			}
		}
		//cout<<ans<<" "<<*max_element(box.begin(),box.end())<<endl;
		int sum=accumulate(add.begin(),add.end(),0);
		ans+=sum-*max_element(box.begin(),box.end());
 // cout<<sum<<" "<<*max_element(box.begin(),box.end())<<endl;
	cout<<ans-*max_element(box.begin(),box.end())<<endl;
	return 0;
}

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

int main() {
  int N, K, x, sum = 0;
  cin >> N >> K;
  for (auto i = 0; i < N; i++) {
    cin >> x;
    if (x > K/2)
      sum += (K - x) * 2;
    else
      sum += x * 2;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int sum =1;

		for(int i =0; i<n; i++) {
			sum = Math.min(sum*2, sum+k);
		}

		System.out.println(sum);
	}
}

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

const int N=100005;
int fst[N],deg[N],a[N],tot=0;

struct Edge{
	int to,nxt;
}e[N*2];

void addedge(int x,int y){
	e[++tot].to=y;e[tot].nxt=fst[x];fst[x]=tot;deg[y]++;
}

bool dfs(int x,int father){
	if (deg[x]==1){
		
		return 1;
	}
	int sum=0,mx=0;
	for (int i=fst[x];i;i=e[i].nxt){
		int y=e[i].to;
		if (y!=father){
			if (!dfs(y,x)) return 0;
			sum+=a[y];
			mx=std::max(mx,a[y]);
		}
	}
	a[x]=a[x]*2-sum;
	return (a[x]>=0 && mx*2-sum<=a[x] && a[x]<=sum);
}

int main(){
	int n,root=0;
	scanf("%d\n",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		addedge(x,y);
		addedge(y,x);
	}
	if (n==2){
		printf(a[1]==a[2]?"YES":"NO");
		return 0;
	}
	for (int i=1;i<=n;i++)
		if (deg[i]>1) root=i;
	if (dfs(root,0) && !a[root]) printf("YES\n");
		else printf("NO\n");
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる





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

  vector<int> p(n);
  int x;
  rep(i,2*m){
    cin>>x;
    p[x-1]++;
  }

  rep(i,n){
    cout << p[i] << endl;
  }

}

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

int main(){
    ll w,h,x,y;
    cin >> w >> h >> x >> y;
    printf("%.10lf ",(double)w*h/2);
    if(x*2==w&&y*2==h)  cout << 1;
    else cout << 0;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define fo(i,n)   for(i=0;i<n;i++)
#define mod       1000000007
using namespace std;

int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("codefi.txt", "r", stdin);
	freopen("codefo.txt", "w", stdout);
#endif


	int N, A[3][3], b[10];
	bool appear[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) cin >> A[i][j];
	}
	cin >> N;
	for (int i = 0; i < N; i++) cin >> b[i];
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			appear[i][j] = false;
			for (int k = 0; k < N; k++) {
				if (A[i][j] == b[k]) appear[i][j] = true;
			}
		}
	}
	string ANS = "No";
	for (int i = 0; i < 3; i++) {
		if (appear[i][0] and appear[i][1] and appear[i][2]) ANS = "Yes";
	}
	for (int i = 0; i < 3; i++) {
		if (appear[0][i] and appear[1][i] and appear[2][i]) ANS = "Yes";
	}
	if (appear[0][0] and appear[1][1] and appear[2][2]) ANS = "Yes";
	if (appear[0][2] and appear[1][1] and appear[2][0]) ANS = "Yes";
	cout << ANS << endl;
	return 0;
}


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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

VPL prime_factorize(ll n) {
    VPL res;  // first: prime, second: count
    for (ll p = 2; p * p <= n; p++) {
        if (n % p != 0) continue;
        int cnt = 0;
        while (n % p == 0) {
            cnt++;
            n /= p;
        }
        res.push_back(PL(p, cnt));
    }
    if (n != 1) res.push_back(PL(n, 1));
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, p;
    cin >> n >> p;
    VPL p_cnts = prime_factorize(p);
    ll ans = 1;
    for (auto p_cnt : p_cnts) REP(i, p_cnt.second / n) ans *= p_cnt.first;
    cout << ans << ln;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0, 0,-1,1,-1, 1,-1};
int dy[]={0,1,-1, 0,1,-1,-1, 1};

 
vector<LL> fact;
vector<LL> inver(200001);
 
LL combi(int n,int r){
    if(n<r||n<0||r<0) return 0;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}
 
 
LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}
 
void set_combi(){
    LL s=1;
    fact.push_back(1);
    for(int i=1;i<=200000;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[200000]=fpow(fact[200000],mod-2);
    for(int i=199999;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
}
 



int main(){
    set_combi();
    LL n,k;cin >> n >> k;
    vector<LL> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    LL ans = 0;
    sort(ALL(a));
    for (int i = 0; i < n-k+1; i++) {
        if(a[i]<0){
            ans = (ans + (abs(a[i]) * combi(n-1-i,k-1)%mod))%mod;
        }
        else{
            ans = (ans + mod - (abs(a[i]) * combi(n-1-i,k-1)%mod))%mod;
        }
    }
    for (int i = 0; i < n-k+1; i++) {
        if(a[n-1-i]<0){
            ans = (ans + mod - (abs(a[n-1-i]) * combi(n-1-i,k-1)%mod))%mod;
        }
        else{
            ans = (ans + (abs(a[n-1-i]) * combi(n-1-i,k-1)%mod))%mod;
        }
    }
    cout << ans << endl;
    return 0;
}



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

#define ll long long
#define ull unsigned long long 
#define endl '\n'
#define pii pair<int, int>
#define all(a) a.begin(),a.end()
template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

int main(){
    int n, x;
    cin >> n >> x;
    vector<int> a;

    a.push_back(x);
    for(int i=0; i<n; ++i){
        int l;
        cin >> l;
        a.push_back(l);
    }
    sort(all(a));

    if(n==1){
        cout << gcd(0, a[1]-a[0]);
        return 0;
    }


    vector<int> z;
    for(int i=1; i<=n; ++i){
        z.push_back(a[i]-a[i-1]);
    }

    int ans=0;
    for(int i=0; i<n; ++i)
        ans = gcd(ans, z[i]);
    cout << ans;
}

Measured memory_bytes: 4216
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define N 1000005
typedef long long int ll;
//const int mx=1e5+7;
//int n,m;
//vector<int> a(mx),b(mx);
// vector<int> g[mx];
// int deg[mx];
//vector<int> adj[mx];
//vector<int> ans;
//---dfs--
// bool visited[mx];
// vector<ll> val(mx,0);

// void dfs(int s,int e,int c1,int c2){
// 	if(a[s]^c1!=b[s]) {ans.push_back(s), c1^=1;}
// 	for(auto u:adj[s]){
// 		if(u!=e){
// 			dfs(u,s,c2,c1);
// 		}
// 	}
// }
//---dfs---

//---primes---
// const int N = 1e7 + 10;

// bool prime[N];
 
// int spf[N];
 
// void calc(){
// 	for(int i = 2; i<1e4; i++){
// 		if(prime[i])
// 			continue;
// 		spf[i] = i;
// 		for(int j = i * i; j < N; j += i){
// 			prime[j] = 1;
// 			spf[j] = i;
// 		}
// 	}
// 	for(int i = 2; i < N; i++)
// 		if(!spf[i])
// 			spf[i] = i;
// }

// vector<pair<int,int>> getp(int x){
// 	int curr=x;
// 	vector<pair<int,int>> ans;
// 	while(curr>1){
// 		int a=spf[curr];
// 		int count=0;
// 		while(curr%a==0){ curr/=a; count++;}
// 		ans.push_back(make_pair(a,count));
// 	}
// 	return ans;
// }

// bool ispr(int n) {
// 	if(n==1) return false;
//     for (int i=2;i*i<=n;++i){
//         if(n%i==0){
//             return false;
//         }
//     }
//     return true;
// }
//---primes---

//---segment_tree---
// int upd(int t,int val,int l,int r,int y, int z){
// 	if(y<l||y>r) return tr[val];
// 	if(l==r) return tr[val]=z;
// 	int s=(l+r)/2;
// 	upd(t^1,2*val+1,l,s,y,z);
// 	upd(t^1,2*val+2,s+1,r,y,z);
// 	if(t) tr[val]=tr[2*val+1]|tr[2*val+2];
// 	else tr[val]=tr[2*val+1]^tr[2*val+2];
// 	return tr[val];
// }
//int query(){}
//---segment_tree---

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	int t=1;
	//cin>>t;
	while(t--){
		int x;
		cin>>x;
		if(x>=30) cout<<"Yes\n";
		else cout<<"No\n";
 	}
}

Measured memory_bytes: 3644
N = int(input())
s = input()

cnt = 0
flg = 0
for i in range(N):
  if s[i] == "A":
    flg = 1
  elif flg == 1 and s[i] == "B":
    flg = 2
  elif flg == 2 and s[i] == "C":
    flg = 0
    cnt += 1
  else:
    flg = 0

print(cnt)
    

Measured memory_bytes: 3060
input = readlines()

n, k = input.shift.chomp.split("\s").map{|x| x.to_i}

list = {}
(1..n).each do |ni|
  list[ni] = false
end

input.each_with_index do |l, i|
  next if i.even?
  l.chomp.split("\s").each do |li|
    ni = li.to_i
    list[ni] = true
  end
end

cnt = 0
list.each do |k, h|
  cnt += 1 unless h == true
end

puts cnt


Measured memory_bytes: 14344
s = input()
t = input()

len_s=len(s)
len_t=len(t)

# dp[len(s)][len(t)]
# dp表をつくる
dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]

for i in range(1,len_s+1):
  for j in range(1,len_t+1):
    if s[i-1]==t[j-1]:
      dp[i][j]=dp[i-1][j-1]+1
    else:
      dp[i][j]=max(dp[i][j-1],dp[i-1][j])
#print(dp)

#復元する
rev = ""
i = len_s
j = len_t
while (i>=1 and j>=1):
  if dp[i][j] == dp[i][j-1]:
    j -=1
  elif dp[i][j] == dp[i-1][j]:
    i -=1
  else:
    rev = t[j-1] + rev
    i -=1
    j -=1

print(rev)

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



int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL); 
    int n;
    cin>>n;
    vector<int> v;
    vector<int> c;
    for(int i=0;i<n;i++){
       char t;
       cin>>t;
       if(t=='R'){
        v.push_back(i);
       }else{
        c.push_back(i);
       }
    }
    int f=0;
    sort(v.rbegin(),v.rend());

    int e=c.size();
    int g=v.size();
    for(int i=0;i<min(e,g);i++){
      if(c[i]<v[i]){
        f++;
      }
    }
    cout<<f<<endl;
  
  
  
}
  

Measured memory_bytes: 4528
#include <iostream>
#include <bitset>
#include <cstdio>

using namespace std;

int main()
{
  bitset<60000> is_prime;
  is_prime.set();
  is_prime[0] = false, is_prime[1] = false;
  for (int i = 2; i * i <= 60000; i++) {
    for (int j = i + i; j  <= 60000; j += i) {
      is_prime[j] = false;
    }
  }

  int N;
  while (scanf("%d ", &N) == 1) {
    int d_m, u_m;
    for (int i = N - 1;; i--) {
      if (is_prime[i]) {
	d_m = i;
	break;
      }
    }
    for (int i = N + 1;; i++) {
      if (is_prime[i]) {
	u_m = i;
	break;
      }
    }
    printf("%d %d\n", d_m, u_m);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,ans=0;
	cin >> n;
	int c[n];
	for(int i=0;i<n;i++)
		cin >> c[i];
	for(int i=1;i<n-1;i++)
		if((c[i]<c[i+1] && c[i]>c[i-1]) || (c[i]>c[i+1] && c[i]<c[i-1]))
			ans++;
	cout << ans;
	return 0;
}

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

int main(){
  int A, B;
  cin >> A >> B;
  if(0 < A && A < 10 && 0 < B && B < 10){
    cout << A * B << endl;
  }
  else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int h,r;
	cin>>h>>r;
	if(h+r==0) cout<<0<<endl;
	else if(h+r>0) cout<<1<<endl;
	else cout<<-1<<endl;
	
	return 0;
}


Measured memory_bytes: 3108
#include <cstdio>
    #include <cmath>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
     
    using namespace std;
    typedef long long ll;
    ll a[10000000];
    ll b[10000000];
    int main()
    {
    	ll n, i;
    	while(~scanf("%lld", &n))
    	{
    		memset(a, 0, sizeof(a));
    		memset(b, 0, sizeof(b));
    		ll k = 0;
    		for(i = 1; i <= n; i++)
    		{
    			scanf("%lld", &a[i]);
    			if(a[i] > n)
    				k++;
    			else	
					b[a[i]]++;
    		}
    		/*ll m = a[1];
			int j = 0;
    		for(i = 1; i <= n; i++)
    		{
    			if(a[i] >= m)
    				m = a[i];
    			if(n < a[i])
    			{
    				j++;
    				a[i] = -1;
				}

    		}
    		
		**/

    	//	ll k = 0;
    		for( i = 1; i <= n; i++)
    		{
    			if(b[i] != 0)
    			{
    				if(b[i] < i)
    					k = k + b[i];
    				else 
    					k = k + b[i] - i;
    			}
    		}
    		printf("%lld\n", k);
    		//	printf("%lld\n",m);
    	}
    }

Measured memory_bytes: 156672
#include <stdio.h>
#include <string.h>
int main()
{
    int n,x=0,max=0,i;
    char a;

    scanf("%d",&n);
    scanf("%c",&a);
    char id[n+1];

    for(i=0;i<n;i++){
        scanf("%c",&id[i]);


    }
    id[n]='\0';


    for(i=0;i<n;i++){
            if(id[i]=='I'||id[i]=='D'){
                if(id[i]=='I'){
                    x++;


                }
            else{
                x--;

            }
            if(x>max)
                max=x;
        }


    }
    printf("%d",max);



    return 0;
}

Measured memory_bytes: 128