akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int s[N],n;
void update(int pos) {
	for(int i=pos;i<=n;i+=(i&-i)) {
		s[i]++;
	}
}
int query(int pos) {
	int ans=0;
	for(int i=pos;i;i-=(i&-i)) {
		ans+=s[i];
	}
	return ans;
}
int main() {
	scanf("%d",&n);
	int ans=0;
	for(int i=0,x;i<n;i++) {
		scanf("%d",&x);
		if(!query(x)) ans++;
		update(x);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    int n, q, t, sum = 0;
    cin >> n;
    int s[n];
    rep(i,n) cin >> s[i];
    cin >> q;
    rep(i,q) {
        cin >> t;
        if (*lower_bound(s, s+n, t) == t) sum++;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3464
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 998244353;



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

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

int H, W, K;
string S[312];
int a[312][312];
int cnt_h = -1;
int idx = 1;
int bef_h = 0;
int b_h = 0;

int main(){
    
    cin>>H>>W>>K;
    
    REP( i, H ) cin>>S[i];
    REP( i, H ) S[i] += '#';
    REP( i, W ) S[H] += '#';
    
    REP( i, H+1 ){
        int tmp = 0;
        REP( j, W ) if( S[i][j] == '#' ) tmp = 1;
        if( tmp ) cnt_h++;
        
        if( cnt_h == 1 ){
            int cnt_w = -1;
            int bef_w = 0;
            REP( j, W+1 ){
                if( S[bef_h][j] == '#' ) cnt_w++;
                if( cnt_w == 1 ){
                    FOR( k, b_h, i ){
                        FOR( l, bef_w, j ){
                            a[k][l] = idx;
                        }
                    }
                    bef_w = j;
                    cnt_w = 0;
                    idx++;
                }
            }
            b_h = i;
            cnt_h = 0;
        }
        
        if( tmp ) bef_h = i;
    }
    
    REP( i, H ){
        REP( j, W ){
            if( j ) printf(" ");
            cout<<a[i][j];
        }
        puts("");
    }
    
    return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n;
    cin >> n;
    int a, b;
    a = 0;
    vector<int> v(n);
    for(int i = 0; i < n; ++i) {
        cin >> v[i];
        if(a <= v[i]) {
            b = a;
            a = v[i];

        } else if(b <= v[i]) {
            b = v[i];
        }
    }

    for(int i = 0; i < n; ++i) {
        if(v[i] == a) {
            cout << b << endl;

        } else {
            cout << a << endl;

        }
    }
    return 0;
}



Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#define MAXN 105
using namespace std;

int n;
int cnt[MAXN], a[MAXN];
long long sol;

void bkt(int pos, long long S) {
    if (pos > n / 3) {
        vector<int> v;
        
        for (int i = pos; i <= n; ++i) {
            if (cnt[i] > 0)
                continue;
            if (2 * i <= n) {
                if (a[i] >= 0 || (!cnt[2 * i] && a[i] + a[2 * i] > 0))
                    S += a[i];
                else {
                    ++cnt[2 * i];
                    v.push_back(2 * i);
                }
            }
            else if (a[i] > 0)
                S += a[i];
        }
        while (!v.empty()) {
            --cnt[v.back()];
            v.pop_back();
        }

        sol = max(sol, S);
        return;
    }

    bkt(pos + 1, ((cnt[pos] == 0) ? (S + a[pos]) : S));
    if (cnt[pos] == 0) {
        for (int i = pos + pos; i <= n; i += pos)
            ++cnt[i];
        bkt(pos + 1, S);
        for (int i = pos + pos; i <= n; i += pos)
            --cnt[i];
    }
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    bkt(1, 0);

    cout << sol << "\n";

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
int n;
string s;
int main()
{
	cin>>n;
	cin>>s;
	for(int i=0;i<s.length();i++)
	{
		int id=s[i]-'A';
		id+=n;
//		cout<<id<<endl;
		id=id%26;
//		cout<<id<<endl;
		s[i]=(char)('A'+id);
	}
	cout<<s<<endl;
}

Measured memory_bytes: 256
N = int(input())
lst = [0] * 55556
prime = []
for i in range(2, 55556):
    if lst[i] == 0:
        if i % 10 == 1:
            prime.append(i)
        for j in range(i, 55556, i):
            lst[j] = 1
    if len(prime) == N:
        print (*prime)
        exit()

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int d[6]={};
  int i,j,k;
  double x;
  for(i=0;i<n;i++){
    cin >> x;
    if(x<165.0) d[0]++;
    else if(x<170.0) d[1]++;
    else if(x<175.0) d[2]++;
    else if(x<180.0) d[3]++;
    else if(x<185.0) d[4]++;
    else d[5]++;
  }
  for(i=0;i<6;i++){
    cout << (i+1) << ":";
    for(j=0;j<d[i];j++) cout << "*";
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1228
n = gets.to_i
a = n.times.map{gets.to_i}
b = Array.new(n,0) #chouhukucount
c = 0
loop do
  c = a[c]-1
  b[c] += 1
  if b[c] == 2
    puts -1
    break
  elsif b[1] == 1
    puts b.inject(:+)
    break
  end
end

Measured memory_bytes: 5500
import numpy as np
n, k = map(int,input().split())
a = np.array(list(map(int,input().split())))
a.sort()
posi = a[a>0]
zero = a[a==0]
nega = a[a<0]

# 2分探索, midより小さいものを数える
l = -10**18-1
r = 10**18+1
while r-l > 1:
    mid = (r+l)//2
    cnt = 0
    if mid >= 0:
        cnt += len(zero)*n
    
    # a.searchsorted(v, side="left"): a[i-1] < v <= a[i]であるvのindexを返す  
    # a.searchsorted(v, side="right"): a[i-1] <= v < a[i]であるvのindexを返す  

    cnt += a.searchsorted(mid//posi, side="right").sum()
    cnt += (n - a.searchsorted(-(-mid//nega), side="left")).sum()
    cnt -= np.count_nonzero(a*a <= mid)
    cnt //= 2
    # print("mid:", mid)
    # print("mid//posi:", mid//posi)
    # print("search:", a.searchsorted(mid//posi,side="right"))
    # print("-(-mid//nega):", -(-mid//nega))
    # print("search:", a.searchsorted(-(-mid//nega),side="left"))
    # print("nonzero_count:", np.count_nonzero(a*a<=mid))
    # print("count:", cnt)
    # print('-' * 20)
    if cnt >= k:
        r = mid
    else:
        l = mid
print(r)


Measured memory_bytes: 32496
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  ll N, Y;
  cin >> N >> Y;
  Y = Y / 1000;
  int C = Y - N;
  for (int i = 0; i <= min(N, Y / 10); i++) {
    int y = Y - (10 * i);
    int n = N - i;  // x + 5z=y : x+z=n : z = (y-n)/4
    int c = y - n;
    if (c < 0) continue;
    if (c % 4 == 0) {
      if (i + (c / 4) > N) continue;
      cout << i << " " << c / 4 << " " << N - i - (c / 4) << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

const int inf = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    vi v(n);
    for(auto &z : v)cin>>z;

    int resenje = inf;

    for(int i = 1; i <= 100; i++)
    {
        int trenutnoResenje=0;
        for(auto &z : v)
        {
            trenutnoResenje+=sqr(i-z);
        }
        resenje=min(resenje,trenutnoResenje);
    }

    cout << resenje << '\n';

    return 0;
}


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

int Satisfication(int N){
    int A[N]={};
    int B[N]={};
    int C[N]={};
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    for(int i=0;i<N;i++){
        cin >> B[i];
    }
    for(int i=0;i<N-1;i++){
        cin >> C[i];
    }


    /*for(int i=0;i<N;i++){
        cout << A[i];
    }
    cout << endl;
    for(int i=0;i<N;i++){
        cout << B[i];
    }
    cout << endl;
    for(int i=0;i<N;i++){
        cout << C[i];
    }*/


    int satis_sum=0;
    for(int i=0;i<N;i++){
        satis_sum += B[i];
    }
    for(int i=0;i<N-1;i++){
        if(A[i+1]==A[i]+1){
            satis_sum += C[A[i]-1];
        }
    }
    return satis_sum;
}

int main(){
    int N; cin >>N;
    cout << Satisfication(N) << endl;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val a = (1..n).map { sc.nextInt() }

  val aa = a.reversed()
  val b = mutableListOf<Int>()

  for ((i, ai) in aa.withIndex()) {
    if (i % 2 == 0) {
      b.add(ai)
    }
  }
  if (n % 2 == 0) {
    for ((i, ai) in a.withIndex()) {
      if (i % 2 == 0) b.add(ai)
    }
  } else {
    for ((i, ai) in a.withIndex()) {
      if (i % 2 != 0) b.add(ai)
    }
  }

  println(b.joinToString(" "))

}

Measured memory_bytes: 74876
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll N, K;
	cin >> N >> K;
	ll x[N + 1];
	for (ll i = 0; i < N; i++) {
		cin >> x[i];
	}
	ll cnt1 = 0, cnt2 = 0;
	for (ll i = 0; i < N; i++) {
		if (x[i] >= 0) cnt1++;
		if (x[i] <= 0) cnt2++;
	}
	if (cnt1 == N)cout << x[K - 1] << endl;
	else if (cnt2 == N)cout << abs(x[N - K]) << endl;
	else {
		ll y = 10000000000000000;
		for (ll i = 0; i < N-K+1; i++) {
			if (x[i + K-1] >=0 && x[i] <= 0) {
				ll a = 2*x[i + K-1]+abs(x[i]);
				ll b = x[i + K-1] + 2 * abs(x[i]);
				y = min(min(a, b),y);
			}
		}
		cout << y<< endl;
	}

}



Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    int total=0;
    int s[n];
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        total+=a;
        s[i]=a;
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        cout<<total+b-s[a-1]<<endl;
    }
}


Measured memory_bytes: 256
using namespace std;
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <assert.h>
#include <functional>
#include <iomanip>

typedef long long ll;

struct node {
    node* ch[26];
    long long with[26];
    node* par;

    node() {
        for (int i = 0; i < 26; i++) {
            with[i] = 0;
            ch[i] = 0;
        }
    }
};

ll insert(string s, node* root) {
    for (int i = s.size() - 1; i >= 1; i--) {
        if (root->ch[s[i] - 'a'] == 0) {

            root->ch[s[i] - 'a'] = new node();
            root->ch[s[i] - 'a']->par = root;
        }
        root = root->ch[s[i] - 'a'];
    }
    long long ans = root->with[s[0] - 'a'];
    if (root->ch[s[0] - 'a'] == NULL) {
        root->ch[s[0] - 'a'] = new node();
        root->ch[s[0] - 'a']->par = root;
    }
    root = root->ch[s[0] - 'a'];
    bool has[26];
    for (int i = 0; i < 26; i++) {
        has[i] = 0;
    }
    for (int i = 0; i < s.size(); i++) {
        has[s[i]-'a'] = true;
        root = root->par;
        for (int j = 0; j < 26; j++) {
            root->with[j] += has[j];
        }
    }
    return ans;
}

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

    int n;
    cin >> n;

    vector<pair<int, string>> s;
    for (int i = 0; i < n; i++) {
        string x;
        cin >> x;
        s.push_back({x.size(), x});
    }
    sort(s.rbegin(), s.rend());
    long long ans = 0;
    node* root = new node();
    for (auto p : s) {
        ans += insert(p.second, root);
    }
    cout << ans << endl;
}

Measured memory_bytes: 425968
use std::io::Read;
use std::cmp;

fn main() {
    let mut s = String::new();
    // 標準入力から全部bufに読み込む
    std::io::stdin().read_line(&mut s).unwrap();
    let ss = s.trim().to_owned();

    if ss <= "2019/04/30".to_string() {
        println!("{}", "Heisei");
    } else {
        println!("{}", "TBD");
    }

}

Measured memory_bytes: 4352
#include<cstdio>
#include<map>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<vector>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>TR;
const int N=1e5+5;
int n,a,b,X[N],Y[N],k,cnt[N];
long long t;
bool vis[N];
map<int,TR>R,C;
queue<int>q;
int count(TR&st,int l,int r){
	return(int)st.order_of_key(make_pair(r+1,0))-(int)st.order_of_key(make_pair(l,0));
}
void solve(TR&st,int l,int r){
	auto L=st.lower_bound(make_pair(l,0)),R=st.lower_bound(make_pair(r+1,0));
	vector<TR::iterator>vec;
	for(auto i=L;i!=R;++i){
		if(!vis[i->second])vis[i->second]=1,q.push(i->second);
		vec.push_back(i);
	}
	for(auto i:vec)st.erase(i);
}
int main(){
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;++i){
		int x,y;
		scanf("%d%d",&x,&y);
		X[i]=x+y-0*1000000000,Y[i]=x-y;
		R[X[i]].insert(make_pair(Y[i],i)),C[Y[i]].insert(make_pair(X[i],i));
	}
	k=max(abs(X[a]-X[b]),abs(Y[a]-Y[b]));
	for(int i=1;i<=n;++i)
	cnt[i]=count(R[X[i]-k],Y[i]-k,Y[i]+k-1)+count(C[Y[i]+k],X[i]-k,X[i]+k-1);
	q.push(a),q.push(b);
	vis[a]=vis[b]=1;
	while(!q.empty()){
		int u=q.front();q.pop();
		t+=cnt[u];
		solve(R[X[u]-k],Y[u]-k,Y[u]+k);
		solve(R[X[u]+k],Y[u]-k,Y[u]+k);
		solve(C[Y[u]-k],X[u]-k,X[u]+k);
		solve(C[Y[u]+k],X[u]-k,X[u]+k);
	}
	printf("%lld\n",t);
	return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

vector<ll> dp(110000, 0LL);

int main(){

    int n, m;
    cin >> n >> m;
    if(n == 1){
        ppp(1);
        return 0;
    }

    vector<ll> a(m);
    rep(i, m) cin >> a[i];

    int idx = 0;
    dp[0] = 1LL;
    dp[1] = 1LL;
    if(m != 0){
        if(a[0] == 1LL) {
            ++idx;
            dp[1] = 0LL;
        }
    }

    for(int i = 2; i <= n; ++i){
        if(idx < m) {
            if(i == a[idx]) {
                ++idx;
                continue;
            }
        }
        dp[i] = dp[i-2]+dp[i-1];
        dp[i] %= MOD;
    }
    cout << dp[n] << endl;
    return 0;
}


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

int N,X[1<<18],Y[1<<18];
char D[1<<18];

void Rotate(){
  for (int i=1;i<=N;i++){
    int cx=Y[i],cy=200000-X[i],cz;
    if(D[i]=='U') cz='R';
    if(D[i]=='R') cz='D';
    if(D[i]=='D') cz='L';
    if(D[i]=='L') cz='U';
    X[i]=cx; Y[i]=cy; D[i]=cz;
  }
}

vector<pair<int, char>> V1[1<<19];
vector<pair<int, char>> V2[1<<19];

int solve_01(){
  int Answer = (1<<24);
  for(int i=0;i<=500000;i++) V1[i].clear();
  for(int i=1;i<=N;i++){
    if(!(D[i]=='R'||D[i]=='U'))continue;
    V1[X[i]+Y[i]].push_back(make_pair(X[i],D[i]));
  }
  for(int i=0;i<=500000;i++){
    sort(V1[i].begin(),V1[i].end());
    for(int j=0;j<(int)V1[i].size()-1;j++){
      if(!(V1[i][j].second=='R' && V1[i][j+1].second=='U'))continue;
      Answer=min(Answer,V1[i][j+1].first-V1[i][j].first);
    }
  }
  return Answer*10;
}

int solve_02(){
  int Answer = (1<<24);
  for (int i=0;i<500000;i++) V2[i].clear();
  for (int i=1;i<=N;i++){
    if(!(D[i]=='L'||D[i]=='R')) continue;
    V2[Y[i]].push_back(make_pair(X[i],D[i]));
  }
  for (int i=0;i<=500000;i++){
    sort(V2[i].begin(),V2[i].end());
    for(int j=0;j<(int)V2[i].size()-1;j++){
      if(!(V2[i][j].second=='R' && V2[i][j+1].second=='L')) continue;
      Answer = min(Answer,V2[i][j+1].first-V2[i][j].first);
    }
  }
  return Answer*5;
}

int main(){
  cin >> N;
  for(int i=1;i<=N;i++) cin >> X[i] >> Y[i] >> D[i];
  
  int FinalAns = (1<<24);
  for (int t=0;t<4;t++){
    int val1=solve_01(); FinalAns=min(FinalAns,val1);
    int val2=solve_02(); FinalAns=min(FinalAns,val2);
    Rotate();
  }
  if (FinalAns==(1<<24)) cout << "SAFE" << endl;
  else  cout << FinalAns << endl;
  return 0;
}


Measured memory_bytes: 42736
n = gets.strip.to_i
ws = gets.strip.split.map(&:to_i)

sum = ws.inject(:+)

diff = 10 ** 7
(n - 1).times do |i|
    tmp_sum = ws.slice(0, i + 1).inject(:+)
    tmp = (sum - tmp_sum * 2).abs
    diff = [diff, tmp].min
end

puts diff

Measured memory_bytes: 3836
def cal(x,y,z)
  x**2 + y**2 + z**2 + x*y + y * z + z * x
end

n = gets.to_i
u = []
h = {}
m = 100
(1..m).each do |x|
  (1..m).each do |y|
    (1..m).each do |z|
      a = cal(x,y,z)
      if a <= 10**4
        u << a
        b = [x,y,z].sort
        unless h.has_key?(a)
            h[a]=[b]
        else
          h[a] << b
        end
      end
    end
  end
end

(1..n).each do |i|
  if h.has_key?(i)
    num = 0
    h[i].uniq.each do |x|
      y = x.uniq.count
      if y == 1
        num += 1
      elsif y == 2
        num += 3
      elsif y == 3
        num += 6
      else
        puts "???"
      end
    end
    puts num
  else
    puts 0
  end
end

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

int main() {
	int n;
	cin >> n;
	long long A[n];
	long long sum = 0;
	for(int i=0; i<n; i++){
		cin >> A[i];
		if(i > 0){
			if(A[i] < A[i-1]){
				sum += (A[i-1] - A[i]);
				A[i] = A[i] + A[i-1] - A[i];
			}
		}
	}
	cout << sum << endl;
  
}


Measured memory_bytes: 5148
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
#include <numeric>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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 int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}
#include <cstdint>

uintmax_t comb(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}
//桁数のカウント
//pow(x,n) == x^n
//sum = accumulate(v.begin(),v.end(),0);
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a,   b) * b;}



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

ll x,y,i = 1;
cin >> x >> y;
if(x%y == 0){
  cout << -1 << endl;
}else{
  while(1){
    if(x * i %  y != 0){
      cout << x*i << endl;
      return 0;
     }
     if(x*i > pow(10,18)){
       cout << -1 << endl;
       return 0;
     }
     i++;
  }

}


//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int64_t A[200000];

static int compare_int(const void *a, const void *b) {
	return (int)(*(int64_t *)a - *(int64_t *)b);
}

int main(void) {
	int64_t N;
	int64_t maxAIdx = 0;
	int64_t minAIdx = 0;

	scanf("%"PRId64"\n", &N);
	for (int64_t idx = 0; idx < N; idx++) {
		scanf(idx != N - 1 ? "%"PRId64" " : "%"PRId64, &(A[idx]));

		A[idx] -= idx + 1;
	}

	qsort(A, N, sizeof(int64_t), compare_int);

	int64_t sum = 0;
	const int64_t b = A[N/2];

	int64_t absSum = 0;
	for (int64_t i = 0; i < N; i++) {
		absSum += ABSS(A[i], b);
	}

	printf("%"PRId64, absSum);

	return 0;
}


Measured memory_bytes: 3324
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define rep1(i, n) for(int i = 1; i <= (int) n; i++)
#define all(v) v.begin(),v.end()

int main() {
    int n;
    cin >> n;
    vector<int> cnt(1e6);
    ll sum = 0;
    rep(i,n) {
        int a;
        cin >> a;
        sum += a;
        cnt[a]++;
    }
    int q;
    cin >> q;
    rep(i,q) {
        int b,c;
        cin >> b >> c;
        sum += cnt[b]*(c-b);
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 7184
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 1000000000

using namespace std;


int main()
{
    int n;
    int min = INF, ans = 0 ;
    cin >> n;
    rep(i,n){
        int p;
        cin >> p;
        if(p < min){
            ans++;
            min = p;
        }
    }
    cout << ans << endl;
}

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

vector<vector<int>> s;
vector<int> c, t;
vector<pair<int, int>> last;
vector<int64_t> b_score;
vector<vector<int64_t>> c_score;

void calc_score() {
    last.assign(26, {0, 0});
    for (auto i = 0; i < (int)t.size(); i++) {
        if(i != 0) {
            b_score[i] = b_score[i - 1];
            c_score[i] = c_score[i - 1];
        } else {
            b_score[i] = 0;
            c_score[i].assign(26, 0);
        }
        b_score[i] += s[i][t[i]];
        last[t[i]] = {i + 1, last[t[i]].first};
        for (auto j = 0; j < 26; j++) {
            c_score[i][j] -= c[j] * (i + 1 - last[j].first);
        }
    }
}

void calc_score(pair<int, int>& q) {
    last.assign(26, {0, 0});
    for (auto i = 0; i < (int)t.size(); i++) {
        if(i != 0) {
            b_score[i] = b_score[i - 1];
            c_score[i][q.first] = c_score[i - 1][q.first];
            c_score[i][q.second] = c_score[i - 1][q.second];
        } else {
            b_score[i] = 0;
            c_score[i][q.first] = 0;
            c_score[i][q.second] = 0;
        }
        last[t[i]] = {i + 1, last[t[i]].first};
        b_score[i] += s[i][t[i]];
        c_score[i][q.first] -= c[q.first] * (i + 1 - last[q.first].first);
        c_score[i][q.second] -= c[q.second] * (i + 1 - last[q.second].first);
    }
}

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

    c.resize(26);
    for (auto i = 0; i < 26; i++) cin >> c[i];

    s.assign(d, vector<int>(26));
    for (auto i = 0; i < d; i++) {
        for (auto j = 0; j < 26; j++) cin >> s[i][j];
    }

    t.resize(d); b_score.assign(d, 0);
    c_score.assign(d, vector<int64_t>(26, 0));
    for (auto i = 0; i < d; i++) {
        cin >> t[i]; t[i]--;
    }
    calc_score();
//    for (auto i = 0; i < d; i++) cout << b_score[i] + c_score[i] << endl;
//    cout << endl;

    int m; cin >> m;
    for (auto i = 0; i < m; i++) {
        int day; cin >> day; day--;
        pair<int, int> q; cin >> q.second; q.second--;
        q.first = t[day]; t[day] = q.second;
        calc_score(q);
        int64_t ans = b_score.back();
        for (auto j = 0; j < 26; j++) ans += c_score[(int)t.size() - 1][j];
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3696
import java.math.BigDecimal;
	import java.util.ArrayList;
	import java.util.Collections;
	import java.util.Comparator;
	import java.util.HashMap;
	import java.util.List;
	import java.util.Scanner;
	import java.util.regex.Matcher;
	import java.util.regex.Pattern;
	
	
	public class Main {
		static Scanner sc = new Scanner(System.in);
	
		public static void main (String [] args){
			//		String [][] boad = new String[4][4];
			int n = Integer.parseInt(sc.next());
			int m = Integer.parseInt(sc.next());
			List <Integer> list = new ArrayList<Integer>();
			int total = 0;
	        HashMap<Integer, Integer> count = new HashMap<Integer, Integer>();
			for(int i = 0;i<n;i++){
				int s = Integer.parseInt(sc.next()); 
				for(int j = 0;j<s;j++){
					list.add(Integer.parseInt(sc.next()));
				}
			}
			
			for(int j = 1;j<=m;j++){
				int c = 0;
				for(int k = 0;k<list.size();k++){
					if(j == list.get(k)){
						count.put(j,c+=1);
					}
				}
				if(count.get(j)!=null && count.get(j)>=n){
					total += 1;
				}
			}
			System.out.println(total);
			System.out.flush();
			sc.close();
		}
	}

Measured memory_bytes: 23636
#include <stdio.h>

//Istiyak Hossain

int main()
{
    int i, a, b, c, count = 0;

    scanf("%d %d %d", &a, &b, &c);

    for(i = a; i <= b; i++)
    {
        if(c % i == 0){
            count++;
        }
    }
    printf("%d\n", count);

    return 0;
}



Measured memory_bytes: 2064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int A, B, C, D, L;

int main(){
  scanf("%d%d%d%d%d", &L, &A, &B, &C, &D);
  printf("%d\n", L - max(A/C + ((A%C)?1:0), B/D + ((B%D)?1:0)));
  return 0;
}

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

int main(){
 long int n,nom,min,max,total;
 min=0;
 max=0;
 total=0;
 cin>>n;
 for(int i=0;i<n;i++){
  cin>>nom;
  if(i==0){
    min=nom;
    max=nom;
    total=nom;
   }else{
    if(nom<min){
      min=nom;
    }
    if(nom>max){
      max=nom;
    }
    total+=nom;
   }
 }
 cout<<min<<' '<<max<<' '<<total<<'\n';
 return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
using namespace std;
int mod=998244353;
int x[101000],y[101000];
int ans=0;
long long Pow(long long x,int p)
{
	long long ans=1;
	while(p)
	{
		if(p&1)ans=(ans*x)%mod;
		x=(x*x)%mod;p>>=1;
	}
	return ans;
}
int getans(int x){return (Pow(2,x) - ( (1 + x + x * ( x - 1 ) / 2) % mod) + mod ) % mod;}
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&x[i],&y[i]);
	int ans=getans(n);
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			int cnt=0;
			for(int k=1;k<=n;k++)
			{
				if(k==i||k==j)continue;
				if((x[k] - x[i]) * (y[k] - y[j]) != (x[k] - x[j]) * (y[k] - y[i]))continue;
				if(k<j)break;
				cnt++;
			}
			ans=(ans-getans(cnt+2)+mod)%mod;
		}
	}
	printf("%d",ans);return 0;
 } 

Measured memory_bytes: 256
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
mod = 10 ** 9 + 7

dp = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(n + 1):
    dp[i][0] = 1
for j in range(m + 1):
    dp[0][j] = 1

for i, ei in enumerate(s, 1):
    for j, ej in enumerate(t, 1):
        dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
        if ei == ej:
            dp[i][j] += dp[i-1][j-1]

        dp[i][j] %= mod

ans = dp[n][m]
print(ans)


Measured memory_bytes: 73180
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
	private	static	BufferedReader	br = null;
	private	static	char[][]		wt = { { 'a', 'b', 'c', 'd', 'e' }, { 'f', 'g', 'h', 'i', 'j' }, { 'k', 'l', 'm', 'n', 'o' }, { 'p', 'q', 'r', 's', 't' }, { 'u', 'v', 'w', 'x', 'y' }, { 'z', '.', '?', '!', ' ' } };

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
		String  stdin = null;
		while ((stdin = parseStdin()) != null) {
			int		i = 0;
			int		l = stdin.length();
			boolean	f = (l % 2 == 0);
			String	o = "";

			while (f && i < l) {
				int	j = (stdin.charAt(i)-'1');
				int	k = (stdin.charAt(i+1)-'1');

				if ((f = (0 <= j && j <= 5 && 0 <= k && k <= 4))) {
					o += wt[j][k];
					i+=2;
				}
			}

			System.out.println((f) ? o: "NA");
		}
	}

	private static String parseStdin() {
		String  stdin = null;

		try {
			stdin = br.readLine();
		}
		catch (IOException e) {}

		return stdin;
	}
}

Measured memory_bytes: 15256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
using namespace std;


int main()
{
	int n;
	long long int a[100000], s = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i % 2 == 0)
			s += a[i];
		else
			s -= a[i];
	}
	cout << s;
	s = s / 2;
	for (int i = 0; i < n-1; i++) {
		s = a[i] - s;
		cout << " " << 2 * s;
	}
	cout << endl;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int a[300001];

int main(){
    int num=0;
    cin>>n>>s;
    for(int i=1;i<n;i++){
        if(s[i]=='E'){
            num++;
        }
    }
    int x=num;
    for(int i=0;i<n-1;i++){
        if(s[i]=='W'){
            num++;
        }
        if(s[i+1]=='E'){
            num--;
        }
        if(x>num){
            x=num;
        }
    }
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 900
#include <iostream>
using namespace std;
int main()
{
    // 整数の入力
    int n;
    cin >> n;
    if (n % 2 == 0)
    {
        cout << n << endl;
    }
    else
    {
        cout << n * 2 << endl;
    }

    return 0;
}


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

int main() {
	long long N, M, A[1010], B[1010], CurA, CurB, ANS = 1, MOD = 1000000007;
	A[0] = 0, B[0] = 0;
	cin >> N >> M;
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = 1; i <= M; i++) cin >> B[i];
	sort(A, A + N + 1), sort(B, B + M + 1);
	CurA = N, CurB = M;
	for (int i = 1; i < N; i++) {
		if (A[i] == A[i + 1]) {
			cout << 0 << endl;
			return 0;
		}
	}
	for (int i = 1; i < M; i++) {
		if (B[i] == B[i + 1]) {
			cout << 0 << endl;
			return 0;
		}
	}
	for (int X = N * M; X > 0; X--) {
		if (A[CurA] == X && B[CurB] == X) {
			CurA--, CurB--;
		}
		else if (A[CurA] == X) {
			ANS *= (M - CurB);
			ANS = ANS % MOD;
			CurA--;
		}
		else if (B[CurB] == X) {
			ANS *= (N - CurA);
			ANS = ANS % MOD;
			CurB--;
		}
		else {
			ANS *= ((N - CurA) * (M - CurB) - (N * M - X));
			ANS = ANS % MOD;
		}
	}
	cout << ANS << endl;
}

Measured memory_bytes: 256
x,k,d=map(int,input().split())
x1=abs(x)%d
x2=abs(abs(x1)-d)
num=abs(x)//d
if((k-num)>=0):
    if((k-num)%2==0):
        print(x1)
    else:
        print(x2)
else:
    print(abs(x)-k*d)

Measured memory_bytes: 9188
Scanf.scanf "%d %d" @@ fun n m ->
let xs = Array.init m (fun _ -> Scanf.scanf " %d" ((+) 0)) in
Array.sort (-) xs;
let ds = Array.init (m-1) (fun i -> xs.(i+1) - xs.(i)) in
Array.sort (-) ds;
Array.sub ds 0 (max 0 @@ m-n) |> Array.fold_left (+) 0
|> Printf.printf "%d\n"

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

typedef long long LL;
typedef long double LD;
typedef string ST;


void func()
{
  LL A, B;
  cin >> A >> B;

#if 0
  LL X = A;
  for (LL i = A+1; i <= B; ++i) {
    X = X ^ i;
  }
  cout << X << endl;
#endif

  if (A == B) {
    cout << A;
    return;
  }

  if (A % 2 == 0 && B % 2 == 1) { // even-odd
    LL C = (B - A + 1) / 2;
    cout << C % 2;
    return;
  }

  if (A % 2 == 0 && B % 2 == 0) { // even-even
    LL C = ((B-1) - A +1)/2;
    cout << ((C % 2) ^ B);
    return;
  }

  if (A % 2 == 1 && B % 2 == 1) { // odd-odd
    LL C = (B - (A + 1) +1)/2;
    cout << ((C % 2) ^ A);
    return;
  }

  if (A % 2 == 1 && B % 2 == 0) { // odd-even
    if (B - A == 1) {
      cout << (A ^ B);
      return;
    }

    LL C = ((B-1) - (A + 1) + 1)/2;
    cout << ((C % 2) ^ A ^ B);
    return;
  }


}

#ifdef CALC_TIME 
#include <windows.h>
int main()
{
  LARGE_INTEGER freq;
  QueryPerformanceFrequency(&freq);
  LARGE_INTEGER start, end;
  QueryPerformanceCounter(&start);
  // 何かの処理
  func();
  QueryPerformanceCounter(&end);
  double time = static_cast<double>(end.QuadPart - start.QuadPart) * 1000.0 / freq.QuadPart;
  fprintf(stderr, "%lf[ms]\n", time);
  return 0;
}
#else 
int main()
{
  func();
  return 0;
}
#endif





Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());

        if (A >= 10 || B >= 10) {
            System.out.println(-1);
        } else {
            System.out.println(A * B);
        }

    }
}

Measured memory_bytes: 21844
import * as fs from 'fs';

const input = fs.readFileSync("/dev/stdin", "utf8").split(" ");

const [a, b] = input;

console.log(lcm(+a, +b))

function lcm(a, b) {
  var g = (n, m) => m ? g(m, n % m) : n
  return a * b / g(a, b)
}

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

constexpr int MOD = 1e9+7;
constexpr int COMB_MAX = 110000;
ll fac[COMB_MAX], finv[COMB_MAX], inv[COMB_MAX];

void initComb(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COMB_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 perm(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[n - k] % MOD;
}

int main(void){
    Cin(int, n, k);
    initComb();
    vc<vc<int>> a(n);
    Rep(n-1){
        Cin(int, x, y); x --, y --;
        a[x].push_back(y);
        a[y].push_back(x);
    }
    ll ans = 1;
    For(i, n){
        if(i == 0) ans = ans * perm(k, a[i].size()+1) % MOD;
        else ans = ans * perm(k-2, a[i].size()-1) % MOD;
    }
    Cout(ans);
}




Measured memory_bytes: 8696
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    long N,M;

    private void solve() {
        N = nextLong();
        M = nextLong();

        if (N * M == 1) {
            out.println(1);
            return;
        }

        if (N == 1 || M == 1) {
            long max = Math.max(N,M);
            out.println(max - 2);
            return;
        }

        if (N == 2 || M == 2) {
            out.println(0);
            return;
        }

        out.println((N -2) * (M - 2));
    }

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

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 21332
S = input(); N = len(S)
a,b,c,d = 0,0,0,1
mod = 10**9+7
for x in reversed(S):
  if x == "?":
    a,b,c,d = (3*a+b)%mod, (3*b+c)%mod, (3*c+d)%mod, 3*d%mod
  elif x == "A": a = (a+b)%mod
  elif x == "B": b = (b+c)%mod
  elif x == "C": c = (c+d)%mod
print(a)

Measured memory_bytes: 3188
n=int(input())+1
d=[0]*n*2
def update(i,x):
  i+=n
  d[i]=x
  while i//2:
    i//=2
    d[i]=d[i+i]|d[i-~i]
def query(l,r):
  l+=n
  r+=n
  s=0
  while l<r:
    if l&1:
      s|=d[l]
      l+=1
    if r&1:
      r-=1
      s|=d[r]
    l//=2
    r//=2
  return bin(s).count('1')
for i,c in enumerate(input(),n):d[i]=1<<ord(c)-97
for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i]
for _ in range(int(input())):
  q,a,b=input().split()
  if q>'1':print(query(int(a)-1,int(b)))
  else:update(int(a)-1,1<<ord(b)-97)

Measured memory_bytes: 43576
/*
      author : nishi5451
      created: 11.08.2020 20:05:54
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    int n;
    cin >> n;
    cout << n/3 << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ll n;
    cin>>n;
    if(n>=400 && n<600) cout<<"8";
    else if(n>=600 && n<800) cout<<"7";
    else if(n>=800 && n<1000) cout<<"6";
    else if(n>=1000 && n<1200) cout<<"5";
    else if(n>=1200 && n<1400) cout<<"4";
    else if(n>=1400 && n<1600) cout<<"3";
    else if(n>=1600 && n<1800) cout<<"2";
    else cout<<"1";
}

Measured memory_bytes: 3632
using System;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			for (int i = 1; i <= n; i++)
			{
				int x = i;
				if (x % 3 == 0) { Console.Write(" {0}", i); }
				else
				{
					while (x != 0)
					{
						if (x % 10 == 3)
						{
							Console.Write(" {0}", i);
							break;
						}
						x /= 10;
					}
				}
			}
			Console.Write("\n");
		}
	}
}

Measured memory_bytes: 9244
//maroonrk写経

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

const ll inf = 2e9;

int main(){ 
  int N; cin >> N;
  vector<pair<ll,ll>> P(N);
  
  ll lp = 0; // 左端の最大値
  ll rq = inf; //右端の最小値
  
  for(int i = 0; i < N; i++){ 
    ll L,R; cin >> L >> R;
    
    L--;
    
    lp = max(lp,L);
    rq = min(rq,R);
    
    P[i] = {L,R};
    
  }
  
  ll ans = 0;

  for(auto ne : P){
    
    ans = max( ans, max(0LL, rq-lp)+ne.second-ne.first);
    
  }
  
  vector<pair<ll,ll>> ti;
  
  for(auto ne : P ){ 
    
    ll a = max( 0LL, ne.second-lp );
    ll b = max( 0LL, rq-ne.first );
    
    ti.push_back({a,-b});
    
  }
  
  sort(ti.begin(),ti.end());
  
  ll w = inf;
  
  int cnt = 0;
  
  for(auto z : ti ){ 
    
    
     if( cnt ){ 
       
       ans = max( ans, w+z.first );
       
     }
    
    
    w = min(w, -z.second);
    cnt++;
    
  }
  
  cout << ans << endl;
  
  return 0;
}
    

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
long long res;
string s;
void dfs(int l,long long sum,long long num) {
    if (l==(int)s.length()) {
        res+=num+sum;
        return;
    }
    dfs(l+1,sum*10+s[l]-'0',num);
    if (sum) dfs(l+1,s[l]-'0',num+sum);
}
int main()
{
    cin>>s;
    dfs(0,0,0);
    cout<<res<<endl;
    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF 1e15

#define MAX_N 1000

int n;
ll p[111],m[111][111];

int main(){
	cin.sync_with_stdio(false);
	cin>>n;
	repl(i,1,n+1){
		cin>>p[i-1]>>p[i];
	}
	repl(l,2,n+1)repl(i,1,n-l+2){
		int j=i+l-1;
		m[i][j]=INF;
		repl(k,i,j)minch(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
	}
	cout<<m[1][n]<<endl;
	return 0;
}

Measured memory_bytes: 3236
package main

import "fmt"

func pow(b, n int) (r int) {
	r = 1
	for i := 0; i < n; i++ {
		r *= b
	}
	return r
}

func main() {
	var H, ans int
	fmt.Scan(&H)
	loop := 0
	if H == 1 {
		fmt.Println(1)
		return
	}
	for H > 0 {
		H /= 2
		loop++
		if H == 1 {
			ans += pow(2, loop) - 1
			ans += pow(2, loop)
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, S, total;
  cin >> K >> S;
  total = 0;
  for(int i = 0;i <= K;i++){
    for(int j = 0;j <= K;j++){

    if(0 <= S - i - j && S - i - j <= K) total++;
    }
  }
  cout << total << endl;
}

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

int main(){

	int a, b;
	char op;

	for (;;){
		cin >> a >> op >> b;
		if (op == '?')
			break;

		switch (op){
		
		case '+':
			cout << a + b << endl; break;
		case '-':
			cout << a - b << endl; break;
		case '*':
			cout << a * b << endl; break;
		case '/':
			cout << a / b << endl; break;
		}

	}



	return 0;
}

Measured memory_bytes: 1160
mod = 1000000007
nn,kk = map(int, raw_input().split())

factorial = [1]
for n in xrange(1, 2002):
    factorial.append(factorial[n-1]*n%mod)

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y/2)**2 % mod
    else            : return power(x, y/2)**2 * x % mod

inverseFactorial = [0] * 2002
inverseFactorial[2002-1] = power(factorial[2002-1], mod-2)
for n in xrange(2002-2, -1, -1):
    inverseFactorial[n] = inverseFactorial[n+1] * (n+1) % mod

def combi(n, m):
    return factorial[n] * inverseFactorial[m] * inverseFactorial[n-m] % mod

for i in range(1,kk+1):
    if(i-1<=nn-kk):
        print(combi(nn-kk+1,i)*combi(kk-1,i-1)%mod)
    else:
        print(0)

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

int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> c(26);
  for (int i = 0; i < n; i++) {
    c.at(s.at(i) - 'a')++;
  }
  long product = 1;
  for (int i = 0; i < 26; i++) {
    product *= c.at(i) + 1;
    product %= 1000000007;
  }
  cout << product - 1 << endl;
}


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

int main() {
	int h,w;cin>>h>>w;
	char a[h][w];
	int x[h][w];
	int y[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>a[i][j];
			if(a[i][j]=='#'){
				x[i][j]=1;
				y[i][j]=1;
			}else{
				x[i][j]=0;
				y[i][j]=0;
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=1;j<w;j++){
			x[i][j]+=x[i][j-1];
		}
	}
	for(int j=0;j<w;j++){
		for(int i=1;i<h;i++){
			y[i][j]+=y[i-1][j];
//			cout<<y[i][j];
		}
//		cout<<endl;
	}
	for(int i=0;i<h;i++){
		if(x[i][w-1]){
			for(int j=0;j<w;j++){
				if(y[h-1][j]){
					cout<<a[i][j];
				}
			}
			cout<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 384