akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int a,b;
	int i;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a>>b;
		if(a%b==0){
			cout<<b<<endl;
		}
		else{
			cout<<a%b<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define N 200005
#define inf 0x3f3f3f3f
using namespace std;
int n;
int head[N],ver[N],nxt[N],tot;
void add(int a,int b)
{
	tot++;nxt[tot]=head[a];head[a]=tot;ver[tot]=b;return ;
}
int k,v[N],l[N],r[N],flag,s[N];
void dfs(int x,int f)
{
	l[x]=-inf;r[x]=inf;s[x]=-1;
	for(int i=head[x];i;i=nxt[i])
	{
		if(ver[i]==f)continue;
		dfs(ver[i],x);
		l[x]=max(l[x],l[ver[i]]-1);
		r[x]=min(r[x],r[ver[i]]+1);
		if(s[ver[i]]!=-1&&s[x]==-1)s[x]=s[ver[i]]^1;
		else if(s[ver[i]]!=-1&&s[x]!=(s[ver[i]]^1))flag=1;
	}
	if(r[x]<l[x])flag=1;
	if(v[x]!=inf)
	{
		if(l[x]>v[x]||r[x]<v[x])flag=1;
		if(s[x]!=-1&&s[x]!=v[x]%2)flag=1;
		s[x]=v[x]%2;
		l[x]=r[x]=v[x];
	}
	return ;
}
void dffs(int x,int f)
{
	if(v[x]==inf)v[x]=l[x];
	else l[x]=r[x]=v[x];
	for(int i=head[x];i;i=nxt[i])
	{
		if(ver[i]==f)continue;
		l[ver[i]]=max(l[ver[i]],v[x]-1);
		r[ver[i]]=min(r[ver[i]],v[x]+1);
		dffs(ver[i],x);
	}
}
int main()
{
	scanf("%d",&n);int t1,t2;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&t1,&t2);
		add(t1,t2);add(t2,t1);
	}
	scanf("%d",&k);
	memset(v,0x3f,sizeof(v));
	for(int i=1;i<=k;i++)
	{
		scanf("%d%d",&t1,&t2);
		v[t1]=t2;
	}
	dfs(1,-1);
	if(flag)
	{
		puts("No");
	}
	else
	{
		puts("Yes");
		dffs(1,-1);
		for(int i=1;i<=n;i++)
		{
			printf("%d\n",v[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 9856
/**
 *   author: sahushivam
 *   created: 01 March 2020 (Sunday)  17:29:03
**/
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e18
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define int long long

void solve(){
	int n;
	cin>>n;
	int ans=(n-1)/2+1;
	cout<<ans;
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int t=1; while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [a, b] = input[0].split(" ").map((x: string): number => +x);

const lb = Math.floor(Math.min(a / 0.08, b / 0.1)) - 1;
const ub = Math.floor(Math.max(a / 0.08, b / 0.1)) + 1;

let result = -1;
for (let i = lb; i <= ub; i++) {
	if (Math.floor(i * 0.08) === a && Math.floor(i * 0.1) === b) {
		result = i;
		break;
	}
}

console.log(result);


Measured memory_bytes: 11468
#include<iostream>
using namespace std;
int p[21]={0};
int f(int a,int b,int c)
{
	if(a<=b && b<=c)
		return 1;
	if(c<=b && b<=a)
		return 1;
	return 0;
}
int main()
{
	int n,cnt=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>p[i];
		if(i-1>1 && i-1<n)
		{
			cnt+=f(p[i-2],p[i-1],p[i]);
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
using namespace std;

int N;
vector<int> A;
void solve() {
	cin >> N;
	A.clear();
	A.resize(N);
	for (int n = 0; n < N; n++)cin >> A[n];
	vector<int> dp;
	dp.resize(N, -1);
	dp[0] = A[0];
	for (int n = 1; n < N; n++) {
		int s = -1, e = N-1;
		while (e - s > 1) {
			int m = (e + s) / 2;
			if (dp[m] >= A[n])s = m;
			else e = m;
		}
		dp[e] = A[n];
	}
	int n = 0;
	for (; n < N; n++) {
		if (dp[n] == -1)break;
	}
	cout << n << endl;
	return;
}

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

int main() {
#ifdef DEBUGTIME
	for (int time = 0; time < DEBUGTIME; time++) {
		solve();
		cout << "####################" << endl;
	}
#else
	solve();
#endif
	return 0;
}


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

int n,t;
int a[100002];
int b[100002];

int mx=0,mn=1000000002,dif=0;

int main(){

	cin>>n>>t;t/=2;
	for(int i=0;i<n;i++){
		cin>>a[i];
		b[i] = mn;
		dif = max(dif,a[i]-b[i]);
		mn = min(a[i],mn);
	}

	int ans = 0;
	for(int i=0;i<n;i++){
		if(a[i]-b[i]==dif){
			ans++;t--;
		}
	}
	cout<<ans<<endl;

	return(0);
}

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

#define  int        long long int
 #define    sp(x)                 setprecision(x)
#define    bp(x)           __builtin_popcount(x)
 #define  ld         long double
 #define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)       for(int i = n; i >= j; i--)
 #define  all(container)       container.begin() , container.end()
#define  sz(container)   (int)container.size()
 #define  ff             first
#define  ss             second
 #define  pii      pair <int , int>
#define  sp(x)       setprecision(x)
 #define  endl    "\n"
#define  mod  1000000007
 #define  pb    push_back
#define  mp    make_pair
 #define  T     int ttt; cin >> ttt; while(ttt--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    fast
    int n,a,b,c,k=0;
    cin>>a>>b>>c>>n;
    while(b<=a)
    {
        b=b*2;
        k++;
    }
     while(c<=b)
    {
        c=c*2;
        k++;
    }
    if(k<=n)
            cout<<"Yes";
        else
            cout<<"No";
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=100000000000000000;


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


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

int main() {
  int N,M;
  cin >> N;
  M = N-1;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(M);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> B.at(i);
  }
  for(int i=0;i<M;i++){
    cin >> C.at(i);
  }
  //入力までおわり
  vector<int> manz(N);
  int ans=0;
  for(int i=0;i<N;i++){
    ans += B.at(A.at(i)-1);
    if(i < N-1){
      if(A.at(i) == A.at(i+1)-1){
        ans += C.at(A.at(i)-1);
      }
    }
  }
  cout << ans << '\n';
}

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

using namespace std;

int n, m, a, b;
int arr[600][600];

int main() {
    int i, j;

    scanf("%d%d%d%d",&n,&m,&a,&b);
    if (n%a==0&&m%b==0) {
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
    for (i=0;i<n;i+=a) {
        for (j=0;j<m;j+=b) arr[i][j] = 1000000;
    }
    for (i=a-1;i<n;i+=a) {
        for (j=b-1;j<m;j+=b) arr[i][j] = -1000001;
    }
    for (i=0;i<n;i++) {
        for (j=0;j<m;j++) printf("%d ",arr[i][j]);
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 3456
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class Main{

	private static int res = 0;

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

		String str = null;
		try{
			str = br.readLine();
		}catch(IOException ex){
			ex.printStackTrace();
		}

		if(str == null)
			return;

		List<Character> cube = new ArrayList<>();

		for(char c : str.toCharArray()){
			cube.add(c);
		}

		cube = cube.stream()
				.filter(s -> s.equals('0'))
				.collect(Collectors.toList());
		int zero = cube.size();
		int one = str.length() - zero;
		
		System.out.println(Math.min(one, zero) * 2);
	}
}


Measured memory_bytes: 30420
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

int h,w,k;
string s[8];

int g(int x,int y)
{
    int cnt=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(x&(1<<i)) continue;
            if(y&(1<<j)) continue;
            if(s[i][j]=='#') cnt++;
        }
    }
    return (cnt==k);
}

int main()
{
    int ans=0;
    cin>> h >> w >> k;
    for(int i=0;i<h;i++) cin>> s[i];
    int x=1<<h,y=1<<w;
    for(int i=0;i<x;i++){
        for(int j=0;j<y;j++){
            ans+=g(i,j);
        }
    }
    cout<< ans <<endl;
    return 0;
}

Measured memory_bytes: 3632
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>

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

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll case1 = 0;
    ll case2 = 0;
    ll case3 = 0;
    case1 = max(a - 1, b - 1);
    case2 = max(n - a, b - n);
    if(abs(a - b) % 2LL != 0LL)
    {
        ll temp = abs(a - b);
        if(a < b)
        {
            if(a - 1 < n - b)
            {
                case3 = a + (temp - 1) / 2;
            }else{
                case3 = n - b + 1 + (temp - 1) / 2;
            }
        }else{
            if(b - 1 < n - a)
            {
                case3 = b + (temp - 1) / 2;
            }else{
                case3 = n - a + 1 + (temp - 1) / 2;
            }
        }
    }else{
        case3 = abs(a - b) / 2LL;
    }
    ll result = min(case1, case2);
    result = min(result, case3);
    cout << result << endl;
}

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

// 平方分割 ver

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

    // input
    ll N;
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    ll b = sqrt(N); // 1箱あたりの要素数
    if(b*b!=N) b++;
    
    ll num;
    if(N%b==0){
        num = N/b;
    }else{
        num = N/b + 1;
    }
    vector<ll> B(num); // 各箱内のgcd

    FOR(i, 0, num){
        ll g = A[b*i];
        FOR(j, b*i, min(N, b*(i+1))){
            g = gcd(g, A[j]);
        }
        B[i] = g;
    }

    ll ma = 0;

    // A[i]を除外して左右のgcdを求める
    FOR(i, 0, N){
        ll index = i/b;
        
        ll left_gcd = 0;
        // ざっくり
        FOR(j, 0, index){
            left_gcd = gcd(left_gcd, B[j]);
        }
        // こまかく
        FOR(j, index*b, i){
            left_gcd = gcd(left_gcd, A[j]);
        }

        ll right_gcd = 0;
        // こまかく
        FOR(j, i+1, min(N, b*(index+1))){
            right_gcd = gcd(right_gcd, A[j]);
        }
        // ざっくり
        FOR(j, index+1, num){
            right_gcd = gcd(right_gcd, B[j]);
        }

        ll a = gcd(left_gcd, right_gcd);
        ma = max(ma, a);
    }
    p(ma);

    return 0;
}

Measured memory_bytes: 1024
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = myconv(next(),1);
    myout(Math.ceil(N / 2));
}

Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+50;
int d1[maxn],d2[maxn],n;
int main()
{
    cin>>n;
    for(int i=0;i<n;++i)
    {
        int x,y;
        cin>>x>>y;
        d1[i]=x+y;
        d2[i]=x-y;
    }  
    sort(d1,d1+n);
    sort(d2,d2+n);
    cout<<max(d1[n-1]-d1[0],d2[n-1]-d2[0])<<endl;
    return 0;
}

Measured memory_bytes: 5168
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	
	cin>>N;
	
	cout<<(N-1)*N/2<<endl;
	
	return 0;
}

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

int main(){
  int n, k;
  cin >> n >> k;
  int ma;
  double p = 0;
  if(k > n){
    ma = n;
  }else{
    ma = k - 1;
    p += (n - k + 1) / double(n);
  }
  for(int i = 1; i < ma + 1; i++){
    double p_tmp = (1 / double(n));
    int i_tmp = i;
    while(i_tmp < k){
      p_tmp *= 1 / double(2);
      i_tmp *= 2;
    }
    p += p_tmp;
  }
  cout << setprecision(20) << p;
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define all(v) (v).begin(),(v).end()
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string S; cin >> S; 
  if(S[2]==S[3] && S[4]==S[5]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
N=gets.strip.to_i
a=[]
(0..N-1).each do |i|
  a<<gets.strip.to_i
end
c=0
t=a[0]
if t!=0
  puts "-1"
  exit
end
(1..N-1).each do |i|
  if a[i]==0
  elsif t+1==a[i]
    c+=1
  elsif t>=a[i]
    c+=a[i]
  else
    puts "-1"
    exit
  end

  t=a[i]
end
puts c


Measured memory_bytes: 3452
#include<iostream>
#include<string>

using namespace std;

class Dice{
  public:
    int a[6], tmp, i;

    Dice(int input[6]){
      for (i = 0; i < 6; i++) {
        a[i] = input[i];
      }
    }

    void e() {
      tmp = a[2]; a[2] = a[0]; a[0] = a[3]; a[3] = a[5]; a[5] = tmp;
    }

    void n() {
      tmp = a[0]; a[0] = a[1]; a[1] = a[5]; a[5] = a[4]; a[4] = tmp;
    }

    void w() {
      tmp = a[0]; a[0] = a[2]; a[2] = a[5]; a[5] = a[3]; a[3] = tmp;
    }

    void s() {
      tmp = a[0]; a[0] = a[4]; a[4] = a[5]; a[5] = a[1]; a[1] = tmp;
    }
    bool ismatch(int a2[6]) {
      int count1 = 0, count2 = 0;
      while (1) {
        if (a[0] == a2[0]) {
          count2 = 0;
          while (1) {
            if (a[1] == a2[1]) {
              if (a[2] == a2[2] && a[3] == a2[3] && a[4] == a2[4] && a[5] == a2[5])
                return true;
              else break;
            }
            e();
            n();
            w();
            count2++;
            if (count2 >= 4) break;
          }
        }
        if (count1 < 3 ) e();
        else n();
        count1++;
        if (count1 > 6) return false;
      }
    }
};


int main(void)
{
  int i, in[6];
  for (i = 0; i < 6; i++) cin >> in[i];
  Dice d1(in);
  for (i = 0; i < 6; i++) cin >> in[i];
  Dice d2(in);
  if (d1.ismatch(d2.a)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 1160
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var t, x, y int
	var p1, p2 *point
	p1 = &point{0, 0, 0}
	ret := true
	for i := 0; i < n; i++ {
		fmt.Scan(&t, &x, &y)
		p2 = &point{t, x, y}
		time := p2.t - p1.t
		diff := diff(*p1, *p2)
		if diff > time {
			ret = false
			break
		}
		if (time-diff)%2 == 1 {
			ret = false
			break
		}
		p1 = p2
	}
	if ret {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

type point struct {
	t int
	x int
	y int
}

func diff(p1, p2 point) int {
	return abs(p2.x-p1.x) + abs(p2.y-p1.y)
}

func abs(x int) int {
	if x < 0 {
		return -1 * x
	}
	return x
}


Measured memory_bytes: 5504
//#include"cpp_kyopro.h"
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <stdlib.h>
#include <math.h>
using namespace std;

int main() {
	int k, x, a, b; cin >> k >> x;
	a = x + k - 1;
	b = x - k + 1;

	for(int i=b;i<=a;i++) cout <<i <<" ";


	
	return 0;
}

Measured memory_bytes: 256
// AtCoder ABC104: B - AcCepted
// 2019.9.10 bal4u

#include <stdio.h>

char S[15];

int main()
{
	int i, j;
	
	scanf("%s", S);
	if (S[0] != 'A') goto WA;
	j = -1; for (i = 1; S[i]; i++) {
		if (S[i] == 'C' && j < 0) j = i;
		else if (S[i] >= 'A' && S[i] <= 'Z') goto WA;
	}
	if (j < 2 || j > i-2) goto WA;
	puts("AC");
	return 0;
WA: puts("WA");
	return 0;
}

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

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

    int A[N];
    for(int i=0; i<N; i++) cin >> A[i];

    int total[N];
    for(int i=0; i<N; i++) total[i] = 0;
    for(int i=0; i<N; i++) total[A[i]-1]++;

    sort(total, total+N);

    int i = 0;
    while(total[i] == 0) i++;

    int ans = 0;
    for(int j=0; j<(N-i)-K; j++) ans += total[j+i];

    cout << ans;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define F first
#define S second
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define p_b push_back
#define all(c)              c.begin(), c.end()
using namespace std;
typedef long long ll; //printf("%lld ", ll); to out put long
typedef pair <int , int> pii;
typedef pair <ll , ll> pll;
const double eps = 1e-6;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
bool ODD(ll O) {return (O % 2 != 0);}
ll gcd(ll a, ll b) {return __gcd(a , b);}
ll lcm(ll a, ll b) {return a * b / gcd(a , b);}
int dx[] = {1, 0, -1 ,0 , -1 , 0};
int dy[] = {0, 1, 0, -1 , -1 , 0};
ll power (ll x, ll y) {
    if(y == 0) return 1;
    if(ODD(y)) return x * power(x , y / 2) * power(x , y / 2);
    return power(x , y / 2) * power(x , y / 2);
}
/*------ never give up --------*/
int dp[MAXN][3], arr[MAXN];
int n;
int solve(int idx , int cur) {
    if(idx >= n) return INT_MAX;
    if(idx == n - 1) return 0;
    int &ret = dp[idx][cur];
    if(ret != -1) return ret;
    ret = INT_MAX;
    int sol_1 = INT_MAX, sol_2 = INT_MAX;
    // 1 step
    sol_1 = solve(idx + 1 , 1) + abs(arr[idx] - arr[idx + 1]);
    // 2 steps
    if(idx + 2 >= n) {
        sol_2 = solve(idx + 1 , 2) + abs(arr[idx] - arr[idx + 1]);
    } else {
        sol_2 = solve(idx + 2  , 2) + abs(arr[idx] - arr[idx + 2]);
    }
    ret = min(sol_1 , sol_2);
    return ret;
}
int main () {
    int t = 1;
    //cin >> t;
    while(t--) {
        cin >> n;
        for(int i = 0; i < n; i++) cin >> arr[i];
        memset(dp , -1 , sizeof dp);
        cout << solve(0 , 0);

    }

    return 0;
}


Measured memory_bytes: 12912
from math import gcd
from functools import reduce
n=int(input())
ans=0
for i in range(1,n+1):
  for j in range(i+1,n+1):
    for k in range(j+1,n+1):
      ans+=reduce(gcd,(i,j,k))*6
for i in range(1,n+1):
  for j in range(i+1,n+1):
    ans+=gcd(i,j)*6
for i in range(n+1):
  ans+=i
print(ans)

Measured memory_bytes: 9612
# Problem C - Average Length

from itertools import permutations
import math

# input
N = int(input())
distance_list = []
for i in range(N):
    x, y = map(int, input().split())
    distance_list.append([x, y])

# initialization
distance = 0
pattern_num = 0
pattern_moto = [i for i in range(1, N+1)]
for p in permutations(pattern_moto):
    pattern_num += 1
    tmp_distance = 0
    for d in range(len(p)-1):
        d_1 = distance_list[p[d]-1]
        d_2 = distance_list[p[d+1]-1]
        tmp = math.sqrt((d_1[0]-d_2[0])**2 + (d_1[1]-d_2[1])**2)
        tmp_distance += tmp
    distance += tmp_distance

# output
distance = distance / pattern_num
print(distance)


Measured memory_bytes: 42220
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int result = 0;
		for(int i = 1; i <= N; i++) {
			int sum = 0;
			int num = i;
			for(; num > 0 ;) {
				sum += num % 10;
				num = num /10;
			}
			if(A <= sum && sum <= B) {
				result += i;
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int main(){
    IOS();
    int a,b;
    cin >> a >> b;
    if (a <= 0 && b >= 0) cout << "Zero" << endl;
    else {
        if (a > 0) cout << "Positive" << endl;
        else {
            b = min(-1,b);
            int len = b-a;
            if (len&1) cout << "Positive" << endl;
            else cout << "Negative" << endl;
        }
    }
}


Measured memory_bytes: 3660
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>

using namespace std;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<ll, ll> pll;

ll n = 0, m = 0, k = 0, ans = 0, sum = 0, cnt = 0, temp = 0;
string s;
bool flag;

//----------------------------------------------------------------------

#define MAX 110000

#define INF 111111111111111111
#define NOT 0
#define VIS 1
#define COMP 2

ll stt[MAX];
ll mini[MAX];
vector<pll> edge[MAX];
priority_queue<pll,vector<pll>, greater<pll>> pq;

void dijkstra(ll start) {
  pll min;
  FOR(i, 0, n) {
	stt[i] = NOT;
	mini[i] = INF;
  }
  mini[start] = 0;
  pq.push(make_pair(0, start));

  while (!pq.empty()) {
	min = pq.top();
	pq.pop();
	m = min.second;
	stt[m] = COMP;

	if (mini[m] < min.first) continue;

	FOR(i, 0, edge[m].size()) {
	  k = edge[m][i].first;
	  if (stt[k] != COMP) {
		if (edge[m][i].second + mini[m] < mini[k]) {
		  mini[k] = edge[m][i].second + mini[m];
		  stt[k] = VIS;
		  pq.push(make_pair(mini[k], k));
		}
	  }
	}
  }

}

int main(void) {
  ll a, b, c, q, x, y;
  cin >> n;

  FOR(i, 0, n - 1) {
	cin >> a >> b >> c;
	edge[a - 1].push_back(make_pair(b - 1, c));
	edge[b - 1].push_back(make_pair(a - 1, c));
  }

  cin >> q >> k;

  dijkstra(k - 1);

  FOR(i, 0, q) {
	cin >> x >> y;
	cout << mini[x - 1] + mini[y - 1] << endl;
  }

  return 0;
}

Measured memory_bytes: 12288
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static final int MOD = 1000000007;

	public static void main(String[] args) {
		int N = sc.nextInt();
		long[][] dp = new long[2][N + 1];
		dp[0][0] = 1;
		int t = 1;
		for (int i = 0; i < N; ++i) {
			char v = sc.next().charAt(0);
			if (v == '-') continue;
			Arrays.fill(dp[t], 0);
			if (v == 'D') {
				for (int j = 1; j <= i; ++j) {
					dp[t][j] += dp[1 - t][j] * j % MOD;
					dp[t][j - 1] += dp[1 - t][j] * j * j % MOD;
				}
			} else {
				for (int j = 0; j <= i; ++j) {
					dp[t][j + 1] += dp[1 - t][j];
					dp[t][j] += dp[1 - t][j] * j % MOD;
				}
			}
			t = 1 - t;
		}
		System.out.println(dp[1 - t][0] % MOD);
	}
}

Measured memory_bytes: 19372
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

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


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

	priority_queue<int> que;
	rep(i, n) {
		int a;
		cin >> a;
		que.push(a);
	}
	rep(i, m) {
		int cur = que.top();		
		que.pop();
		cur /= 2;
		que.push(cur);
	}
	ll ans = 0;
	while(!que.empty()) {
		ll cur = que.top();
		ans += cur;
		que.pop();
	}

	cout << ans << endl;


	

	return 0;
}

Measured memory_bytes: 892
#include<stdio.h>
 
int main(void){
  int a,b,x,j,i=0,count;
  scanf("%d",&x);
  scanf("%d",&a);
  scanf("%d",&b);
  j=x-a;
  while(1){
          j=j-b;
          if(j<b)
            break;
  }
  printf("%d\n",j);
  return 0;
}

Measured memory_bytes: 128
using System;
 
class A{
 	static void Main()
 	{
      int i;
      var x = Console.ReadLine();
      if(x.Length==3){
      	char[] y = x.ToCharArray();
      	for(i=2;i>=0;i--){
        	Console.Write("{0}",y[i]);
      	}
      }
      else Console.Write("{0}",x);
   }  
}

Measured memory_bytes: 13140
#include<stdio.h>
#include<stdlib.h>

#define NIL NULL

typedef struct node{
  int key;
  struct node *l;
  struct node *r;
  struct node *p;
} Node;

typedef struct node* NodePointer;
 
NodePointer root;

void insert(int key){

  NodePointer x, y, z;

  y = NIL;
  x = root;

  z = malloc(sizeof(struct node));
  z->key = key;
  z->l = NIL;
  z->r = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->l;
    else x = x->r;
    z->p = y;
  }

  z->p = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->l = z;
  else y->r = z;

}

void inorder(NodePointer t){

  if(t->l != NIL) inorder(t->l);
  printf(" %d", t->key);
  if(t->r != NIL) inorder(t->r);

}

void preorder(NodePointer t){
 
  printf(" %d", t->key);
  if(t->l != NIL) preorder(t->l);
  if(t->r != NIL) preorder(t->r);

}

int main(){
     
  int i, n, x;
  char com[10];
  
  scanf("%d",&n);
  
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if(com[0] == 'i'){
      scanf("%d", &x);
      insert(x);
    } 
    else if(com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;

}

Measured memory_bytes: 24040
fun main (args:Array<String>) {
    val (numOfSunuke , numOfCandy) = readLine()!!.split(" ").map(String::toInt)
    val haveList :MutableSet<Int> = mutableSetOf()
    for (i in 1..numOfCandy){
        val safeSunuke = readLine()!!.toInt()
        val b = readLine()!!.split(" ").map(String::toInt)
        haveList.addAll(b)

    }
    print(numOfSunuke - haveList.size)
}

Measured memory_bytes: 38964
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

struct TCard
{
	char Suit;
	int  Number;
	bool operator==(const TCard& A)const;
};

bool TCard::operator==(const TCard& A)const
{
	return Suit == A.Suit && Number == A.Number;
}

bool CompareCards(const TCard& Small, const TCard& Large)
{
	return Small.Number < Large.Number;
}

typedef std::vector<TCard> TCards;

int Partition(std::vector<TCard>& A, int p, int r)
{
	TCard X = A[r];
	int i = p - 1;
	for(int j = p; j < r; j++){
		if(CompareCards(A[j], X) || A[j].Number == X.Number){
			i++;
			std::swap(A[i], A[j]);
		}
	}
	std::swap(A[i+1], A[r]);
	return i + 1;
}

void QuickSort(TCards& Cards, int p, int r)
{
	if(p < r){
		int q = Partition(Cards, p, r);
		QuickSort(Cards, p, q - 1);
		QuickSort(Cards, q + 1, r);
	}
}

std::string IsStable(const TCards& Sorted, TCards& Original)
{
	std::stable_sort(Original.begin(), Original.end(), CompareCards);
	if(Sorted == Original) return "Stable";
	return "Not stable";
}

int main()
{
	int Count;
	std::cin >> Count;
	TCards Cards(Count);
	for(int i=0; i < Count; i++){
		std::cin >> Cards[i].Suit;
		std::cin >> Cards[i].Number;
	}
	TCards Original = Cards;
	QuickSort(Cards, 0, Count - 1);
	std::cout << IsStable(Cards, Original) << std::endl;
	for(int i=0; i < Count; i++){
		std::cout << Cards[i].Suit << " " << Cards[i].Number << std::endl;
	}
	return 0;
}

Measured memory_bytes: 4632
from functools import reduce
a=int(input())
b=list(map(int,input().split()))
c=reduce(lambda a,b:a+b,b)
d=int(c/a)
def x(a,b,c):
    t=a.copy()
    c=[c]*b
    t=list(map(lambda x,y:x-y,t,c))
    return reduce(lambda a,b:a+b*b,t,0)
ans=min(x(b,a,d),x(b,a,d+1),x(b,a,d-1))
print(ans)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b; cin >> a >> b;
  if(a+b == 15){
    cout << "+" << endl;
  }else if(a*b == 15){
    cout << "*" << endl;
  }else{
    cout << "x" << endl;
  }
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
long long mmin(long long &a,long long b) {
	a = min(a, b);
	return a;
}
long long mmax(long long &a,long long b) {
	a = max(a, b);
	return a;
}
int nibu(vector<int> &v, int tan) {
	int up = v.size()-1;
	int lo = 0;
	if (tan <= v[0]) {
		return 0;
	}
	while (up - lo > 1) {
		int mi = (up + lo) / 2;
		if (tan <= v[mi]) {
			up = mi;
		}
		if (v[mi] < tan) {
			lo = mi;
		}
	}
	return up;
}
int main() {
	int n, m; cin >> n >> m;
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		int x; cin >> x;
		a[i] = x - 1;
	}
	vector<int> s(n,0);
	for (int i = 0; i < m; i++) {
		int di = 0;
		for (int j = 0; j < n; j++) {
			int x;
			cin >> x;
			x--;
			if (x == a[i]) {
				s[j]++;
			}
			else {
				di++;
			}
		}
		s[a[i]] += di;
	}
	for (int i = 0; i < n; i++) {
		cout << s[i] << endl;
	}
}


Measured memory_bytes: 3088
n=int(input())
ans=0
A=[[] for _ in range(n)]
for i in range(n):
  a=int(input())
  for j in range(a):
    A[i].append(tuple(map(int,input().split())))
for i in range(2**n):
  ii=str(bin(i))[2:].zfill(n)
  chk=True
  cur=0
  for j in range(n):
    if ii[j]=="0":
      continue
    else:
      cur+=1
      for x,y in A[j]:
        if y==1 and ii[x-1]=="0":
          chk=False
        elif y==0 and ii[x-1]=="1":
          chk=False
  if chk:
    ans=max(ans,cur)
print(ans)


Measured memory_bytes: 45148
#include<stdio.h>
#define N 100
int main(){
  int i,j,n,key,A[N],count=0,mini;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<=n-1;i++){
    mini=i;
    for(j=i;j<=n-1;j++){
    if(A[j]<A[mini]){
      mini=j;
    }
    }
    if(A[i]>A[mini]){
      key=A[i];
      A[i]=A[mini];
      A[mini]=key;
      count++;
    }
  }
  printf("%d",A[0]);
  for(i=1;i<n;i++){
    printf(" %d",A[i]);
  }
  printf("\n%d\n",count);
      return 0;

  }

Measured memory_bytes: 600
#include<cstdio>
#include<cstring>
#define N 3005
int n,m;
char s[N],t[N];
int dp[N][N];
int pre[N][N];
void print(int x,int y){
	if(!x&&!y)return;
	if(pre[x][y]==1)print(x-1,y);
	else if(pre[x][y]==2)print(x,y-1);
	else print(x-1,y-1),putchar(s[x]);
}
int main(){
	scanf("%s%s",s+1,t+1);
	n=strlen(s+1);
	m=strlen(t+1);
	for(int i=0;i<=n;++i)for(int j=0;j<=m;++j){
		if(!i&&!j)continue;
		dp[i][j]=-1e9;
		if(i&&dp[i-1][j]>dp[i][j])dp[i][j]=dp[i-1][j],pre[i][j]=1;
		if(j&&dp[i][j-1]>dp[i][j])dp[i][j]=dp[i][j-1],pre[i][j]=2;
		if(i&&j&&s[i]==t[j]&&dp[i-1][j-1]+1>dp[i][j])dp[i][j]=dp[i-1][j-1]+1,pre[i][j]=3;
	}
	print(n,m);
	return 0;
}

Measured memory_bytes: 70656
#include<cstdio>
#include<cstring>
using namespace std;
const int _=100010;
int d[_];
int vis[_];
int n,m;
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=1;i<=n;i++)
        {
            vis[i]=0;
            d[i]=1;
        }
        vis[1]=1;
        for(int i=1;i<=m;i++)
        {
            int x,y;scanf("%d%d",&x,&y);
            if(vis[x])
            {
                vis[y]=1;
                if(d[x]==1)
                    vis[x]=0;
            }
            d[x]--;d[y]++;
        }
        int ans=0;
        for(int i=1;i<=n;i++)ans+=vis[i];
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 896
N,M,C = list(map(int,input().split()))
B = list(map(int,input().split()))
A = []
for i in range(N):
    A.append(list(map(int,input().split())))
S = []
count = 0
for i in range(N):
    for j in range(M):
        S.append(A[i][j]*B[j])
    if sum(S) > -1 * C:
        count += 1
    S = []
print(count)

Measured memory_bytes: 38384
import itertools

def train_ticket(n):
	sum_n = n[0]
	A = ["+", "-"]
	for i in itertools.product(A, repeat=3):
		for idx,j in enumerate(i):
			if j == "+":
				sum_n += n[idx+1]
			else:
				sum_n -= n[idx+1]
		if sum_n == 7:
			print("{0}{1}{2}{3}{4}{5}{6}=7".format(n[0], i[0],n[1],i[1],n[2],i[2],n[3]))
			break
		else:
			sum_n = n[0]



n_ticket = list(map(int, input()))
train_ticket(n_ticket)

Measured memory_bytes: 3064
#include<bits/stdc++.h>		
using namespace std;
typedef long long ll;
#define ff first
#define ss second
#define forl(n) for(int i=0;i<n;i++)
#define forp(i,n) for(int i=0;i<n;i++)
#define fort(i,m,n) for(int i=m;i<n;i++)
#define fora(arr,n) for(int i=0;i<n;i++) cin>>arr[i];
#define begud(k) cout<<"\t-->"<<#k<<" = "<<k<<"\n";
#define endl "\n";
ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	ll res = power(a,b/2);
	if(b%2==0)
		return res*res;
	return a*res*res;
}
// bool cust(const pair<int,int> &a,const pair<int,int> &b)                
// {
//     return (a.first > b.first); 
// } 

//const int MX = 100005;
#define inf 10000000000
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 	int n,k;
 	cin>>n>>k;
 	int h[n];
 	fora(h,n)
 	vector<ll>dp(n,inf);
 	dp[0] = 0;
 	dp[1] = abs(h[1]-h[0]);
 	fort(i,2,n)
 	{
 		fort(j,1,k+1)
 		{
 			if(i-j >= 0)
 			{
 				dp[i] = min(dp[i],dp[i-j] + abs(h[i]-h[i-j]));
 			}	
 		} 		
 	}	
 	cout<<dp[n-1]<<endl;
    //cout<<'\n'<<"time elapsed: "<<clock()*1000.0 / CLOCKS_PER_SEC<<" ms"<<'\n';
	return 0;
}

Measured memory_bytes: 1408
//c++ テンプレ
#include<bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
#define sort(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())

priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


void solve(){
    int n;
    cin >> n;
    string s;
    map<string,int>mp;
    mp["AC"]=0;
    mp["WA"]=0;
    mp["TLE"]=0;
    mp["RE"]=0;
    for(int i=0;i<n;i++){
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;


}

int main(){
    solve();
    return 0;
}




Measured memory_bytes: 3596
from collections import defaultdict
c=defaultdict(int)
n,m=map(int,input().split())
for i in range(2,int(m**0.5)+1):
    if m%i==0:
        d=0
        while m%i==0:
            d+=1
            m//=i
        else:
            c[i]+=d
            if m==1:
                break
if m!=1:
    c[m]+=1
def comb(x, y):
    y = min(y, x - y)
    a = 1
    for i in range(x, x - y, -1):
        a *= i
    b = 1
    for i in range(1, y + 1):
        b *= i
    return a // b
a=1
for i in c.values():
    a=comb(n+i-1,i)*a%(10**9+7)
print(a)

Measured memory_bytes: 3316
#include<stdio.h>
long long a[100010];
int main(void)
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	int zero = 0;
	for (int i = 0; i < n; i++)
		if (a[i] == 0)
			zero++;
		if (zero > 0)
		{
			printf("0\n");
			return 0;
		}
	long long sum = 1;
	for (int i = 0; i < n; i++)
	{
		if (a[i] <= 1000000000000000000/sum)
			sum *= a[i];
		else
		{
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n", sum);
	return 0;
}


Measured memory_bytes: 2884
import java.util.Scanner;

class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] N = new int[6];
			for(int i=0;i<6;i++)N[i]=Integer.parseInt(sc.next());
		//String order = sc.next();
		//char[] charOrder = order.toCharArray();
		Dice dice = new Dice(N);
		
		int q = Integer.parseInt(sc.next());
		
		for(int i=0;i<q;i++){
			int N1 = Integer.parseInt(sc.next());
			int N2 = Integer.parseInt(sc.next());
			int roll=0;int front=0;
			for (int j=0;j<6;j++)if(N[j]==N1)roll=j;
			for (int j=0;j<6;j++)if(N[j]==N2)front=j;
			int answer=dice.getRightRoll(roll,front);
			System.out.println(answer);
		}
		
		sc.close();
	}

}

class Dice{
	private int[] roll=new int[6];
	private int[] nowRoll= new int[6];
	Dice(int[] N){
		for(int i = 0;i<6;i++){
			this.roll[i]=N[i];
			this.nowRoll[i]=N[i];
		}
	}

	public int getNow(){
		return nowRoll[0];
	}

	public void roll(char c){
		//int dir;
		int[] tmpRoll=new int[6];
		for(int i=0;i<6;i++)tmpRoll[i]=this.nowRoll[i];
		int[][] mapRoll={{3,1,0,5,4,2},{1,5,2,3,0,4},{4,0,2,3,5,1},{2,1,5,0,4,3}};
		int dir=0;
		if(c=='E') dir=0;
		if(c=='N') dir=1;
		if(c=='S') dir=2;
		if(c=='W') dir=3;
		for(int i=0;i<6;i++)this.nowRoll[i]=tmpRoll[mapRoll[dir][i]];
	}
	public int getRightRoll(int roll,int front){
		int[][] a={{-1,2,4,1,3,-1},{3,-1,0,5,-1,2},{1,5,-1,-1,0,4},{4,0,-1,-1,5,1},{2,-1,5,0,-1,3},{-1,3,1,4,2,-1}};
		int r=a[roll][front];
		return this.nowRoll[r];
	}
}

Measured memory_bytes: 26180
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {
	
	private class Node {
		int id, parent=-1, depth=0;
		int[] children = null;
		public Node(int id) {
			this.id = id;
		}
		public Node(int id, int noOfChildren) {
			this.id = id;
			children = new int[noOfChildren];
		}
		public void setNoOfChildren(int noOfChildren) {
			children = new int[noOfChildren];
		}
		public String toString() {
			StringBuilder sb = new StringBuilder();
			sb.append("node " + id + ": ");
			sb.append("parent = " + parent + ", ");
			sb.append("depth = " + depth + ", ");
			if (parent == -1) {
				sb.append("root");
			} else if (children == null || children.length == 0) {
				sb.append("leaf");
			} else {
				sb.append("internal node");
			}
			sb.append(", ");
			sb.append("[");
			if (children != null && children.length != 0) {
				for (int i = 0; i < children.length; i++) {
					sb.append(children[i]);
					if (i != children.length - 1) {
						sb.append(", ");
					}
				}
			}
			sb.append("]");
			return sb.toString();
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		Node[] nodes = new Node[n];
		for (int i = 0; i < n; i++) {
			StringTokenizer st = new StringTokenizer(reader.readLine());
			int id = Integer.parseInt(st.nextToken());
			int k = Integer.parseInt(st.nextToken());
			if (nodes[id] == null) {
				nodes[id] = new Node(id, k);
			} else {
				nodes[id].setNoOfChildren(k);
			}
			for (int j = 0; j < k; j++) {
				int childId = Integer.parseInt(st.nextToken());
				nodes[id].children[j] = childId;
				if (nodes[childId] == null) {
					nodes[childId] = new Node(childId);
				}
				nodes[childId].parent = id;
			}
		}
		reader.close();
		
		int rootId = -1;
		for (int i = 0; i < n; i++) {
			if (nodes[i].parent == -1) {
				rootId = nodes[i].id;
				break;
			}
		}
		
		Stack<Integer> stack = new Stack<Integer>();
		stack.push(rootId);
		while (!stack.isEmpty()) {
			Node current = nodes[stack.pop()];
			for (int i = 0; i < current.children.length; i++) {
				int childId = current.children[i];
				nodes[childId].depth = current.depth + 1;
				stack.push(childId);
			}
		}
 		
		for (int i = 0; i < n; i++) {
			System.out.println(nodes[i]);
		}
	}
}


Measured memory_bytes: 95168
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

#define STACK_SIZE 100

typedef struct{
	int s[STACK_SIZE];
	int top;
}stack_t;

void stack_push(int n, stack_t* st){
	if(st->top>=STACK_SIZE-1){
		printf("error: full stack\n");
	}else{
		st->top++;
		st->s[st->top]=n;
	}
}

int stack_pop(stack_t* st){
	if(st->top<=-1){
		printf("error: empty stack\n");
		return 0;
	}else{
		st->top--;
		return st->s[st->top+1];
	}
}

int main(void){
	char c;
	int i;
	int tmp1,tmp2;
	stack_t st;
	st.top=-1;
	stack_t* stack=&st;
	while(scanf("%c",&c)!=EOF){
		if(c>=48 && c<=57){
			i=(int)c-48;
			while(scanf("%c",&c)!=EOF){
				if(c<48 || c>57)break;
				i*=10;
				i+=(int)c-48;
				
			}
		}
		switch(c){
		case '+':
			tmp1=stack_pop(stack);
			tmp2=stack_pop(stack);
			tmp1+=tmp2;
			stack_push(tmp1,stack);
			scanf("%c",&c);
			break;
		case '-':
			tmp1=stack_pop(stack);
			tmp2=stack_pop(stack);
			tmp1=tmp2-tmp1;
			stack_push(tmp1,stack);
			scanf("%c",&c);
			break;
		case '*':
			tmp1=stack_pop(stack);
			tmp2=stack_pop(stack);
			tmp1*=tmp2;
			stack_push(tmp1,stack);
			scanf("%c",&c);
			break;
		default:
			stack_push(i,stack);
			break;
		}
	}
	printf("%d\n",stack_pop(stack));
	
	return 0;
}




Measured memory_bytes: 2092
#include <array>
#include <cmath>
#include <cstdio>
#define int long long
int d, g;
std::array<int, 11> p;
std::array<int, 11> c;

int sum = 0;
int ans = 1000000;

signed main()
{
    scanf("%lld", &d);
    scanf("%lld", &g);
    for (int i = 0; i < d; i++) {
        scanf("%lld", &p.at(i));
        scanf("%lld", &c.at(i));
    }
    for (int i = 0; i < static_cast<int>(std::pow(2, d)); i++) {
        int tmp_ans = 0;
        sum = 0;
        bool use = false;
        int max_num = 0;
        for (int j = 0; j < d; j++) {
            use = ((i / static_cast<int>(std::pow(2, j))) % 2 == 1 ? true : false);
            if (use) {
                sum += p.at(j) * (j + 1) * 100 + c.at(j);
                tmp_ans += p.at(j);
                //       printf("+%lld*%lld", j, p.at(j));
            } else {
                max_num = j;
                //      printf("-%lld", j);
            }
        }
        if (g - sum > 0) {
            //printf("rest is %lld", g - sum);
            tmp_ans += ((g - sum - 1) / ((max_num + 1) * 100)) + 1;
            if (((g - sum - 1) / ((max_num + 1) * 100)) + 1 > p.at(max_num)) {
                continue;
            }
        }
        //printf("d:%lld\n", tmp_ans);
        ans = (ans < tmp_ans ? ans : tmp_ans);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#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 RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
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;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, n ;
  cin >> h >> n ;
  int sum = 0 ;
  REP(i,n){
    int d ;
    cin >> d ;
    sum += d ;
  }
  if(h<=sum){
    yes() ;
  }
  else{
    no() ;
  }
  
  
  
  return 0 ;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<numeric>
using namespace std;
class dsu{
	public:
	vector<int>p;
	int n;
	dsu(int _n):n(_n){
		p.resize(n);
		iota(p.begin(),p.end(),0);
	}
	inline int get(int x){
		return (x==p[x]?x:(p[x]=get(p[x])));
	}
	inline bool unite(int x,int y){
		x=get(x);
		y=get(y);
		if(x!=y){
			p[x]=y;
			return true;
		}
		return false;
	}
};
int main()
{
	int n,m;
	cin>>n>>m;
	vector<int>a(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	dsu d(n);
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		d.unite(x,y);
	}
	vector< vector<int> >comp(n);
	for(int i=0;i<n;i++)
	{
		comp[d.get(i)].push_back(a[i]);
	}
	int cnt=0;
	for(int i=0;i<n;i++){
		if(!comp[i].empty()){
			cnt++;
		}
	}
	if(cnt==1){
		puts("0");
		return 0;
	}
	int choose=2*cnt-2;
	long long ans=0;
	vector<int>other;
	for(int i=0;i<n;i++){
		if(!comp[i].empty()){
			sort(comp[i].begin(),comp[i].end());
			ans+=comp[i][0];
			choose--;
			for(int j=1;j<(int)comp[i].size();j++){
				other.push_back(comp[i][j]);
			}
		}
	}
	if(choose>(int)other.size()){
		puts("Impossible");
		return 0;
	}
	sort(other.begin(),other.end());
	for(int i=0;i<choose;i++){
		ans+=other[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6528