akhauriyash/Code-Regression huggingface dataset:
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int itemCount = int.Parse(Reader.ReadLine());

        this.PartsTop = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).OrderBy(a=>a).ToArray();
        this.PartsMiddle = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).OrderBy(a=>a).ToArray();
        this.PartsBottom = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).OrderBy(a=>a).ToArray();

        long ans = 0;
        for (int i = 0; i < PartsMiddle.Length; i++) {
            long topIdx = GetTopIdx(0, itemCount - 1, PartsMiddle[i]);
            long bottomIdx = GetBottomIdx(0, itemCount - 1, PartsMiddle[i]);
            long topCount = topIdx + 1;
            long bottomCount = itemCount - bottomIdx;
            ans += topCount * bottomCount;
        }
        Console.WriteLine(ans);
    }

    private long GetTopIdx(int min, int max, long val) {
        if(max-min<=1) {
            if(val > PartsTop[max]) {
                return max;
            } else if(val > PartsTop[min]) {
                return min;
            } else {
                return min - 1;
            }
        }
        int mid = (max + min) / 2;
        if(PartsTop[mid]<val) {
            return GetTopIdx(mid, max, val);
        } else {
            return GetTopIdx(min, mid, val);
        }

    }

    private long GetBottomIdx(int min, int max, long val) {
        if (max - min <= 1)
        {
            if(val >= PartsBottom[max]) {
                return max + 1;
            } else if(val >= PartsBottom[min]) {
                return max;
            } else {
                return min;
            }
        }
        int mid = (max + min) / 2;
        if(PartsBottom[mid]<=val) {
            return GetBottomIdx(mid, max, val);
        } else {
            return GetBottomIdx(min, mid, val);
        }
    }

    private long[] PartsTop;
    private long[] PartsMiddle;
    private long[] PartsBottom;

    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"



4
2 2 1 2
2 2 2 2
2 2 2 3


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 42100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = -1;

ll solve(ll b,ll n){
    if(n<b)return n;
    else return solve(b,n/b)+n%b;
}

int main()
{
ll n,s;
cin >> n>>s;
if(n==s){
    cout << n+1 << endl;
    return 0;
}
rep(i,sqrt(n)){
    if(solve(i+2,n)==s){
        cout << i+2 << endl;
        return 0;
    }
}
rep(i,sqrt(n)){
    if(s-i-1<0)break;
    if((n-s+i+1)%(i+1)==0&&(s-i-1)<((n-s+i+1)/(i+1))){
        ans=(n-s+i+1)/(i+1);
        //cout << ans <<" "<<i <<endl;
    }
    
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int A,B;
    cin>>A>>B;
    set<int> st={1,2,3};
    st.erase(A);
    st.erase(B);
    cout<<*st.begin()<<endl;;
}


Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,M = inpl()
lines = defaultdict(set)
hh = [0]*N
for _ in range(M):
    x,y = inpl()
    x,y = x-1, y-1
    lines[x].add(y)
    hh[y] += 1

def TopologicalSort(N,lines,hh):
    q = queue.Queue()
    for t in range(N):
        if hh[t] == 0:
            q.put(t)

    topological = []
    while not q.empty():
        s = q.get()
        topological.append(s)
        for t in lines[s]:
            hh[t] -= 1
            if hh[t] == 0:
                q.put(t)

    return topological

topo = TopologicalSort(N,lines,hh)
dp = [0]*N

for s in topo:
    for t in lines[s]:
        dp[t] = max(dp[t],dp[s]+1)

print(max(dp))


Measured memory_bytes: 100948
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
  LL N;
  string S;
  cin >> N >> S;
  LL R = count(begin(S), end(S), 'R');
  LL ans = 0;
  for(auto g=0; g<N; ++g) {
    for(auto b=0; b<N; ++b) {
      if(S[g] != 'G') continue;
      if(S[b] != 'B') continue;
      ans += R;
      auto d = abs(g-b);
      for(auto r: {(g+b)/2, min(g,b)-d, max(g,b)+d}) {
        vector<LL> i = {r, g, b};
        sort(begin(i), end(i));
        if(S[r] != 'R') continue;
        if(i[2]-i[1] != i[1]-i[0]) continue;
        if(i[0]<0 || N-1<i[2]) continue;
        --ans;
      }
    }
  }
  cout << ans << endl;
}


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

int main(){
    long long int n;
    cin >> n;
    long long int lim = sqrt(n);
    long long int a = 1;
    long long int b = n;
    for(int i = 1; i <= lim+1; i++){
        if(n % i == 0){
            a = i;
            b = n / i;
        }
    }

    int count = 0;
    while(a){
        count++;
        a /= 10;
    }
    int res = count;
    count = 0;
    while(b){
        count++;
        b /= 10;
    }
    if(count > res) res = count;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void lcs(string s,string t)
{
  int n,m;
  n=s.size();
  m=t.size();
  int dp[n+1][m+1];
  for(int i=0;i<=n;i++)
  {
    for(int j=0;j<=m;j++)
    {
      if(i==0||j==0)
      {
        dp[i][j]=0;
      }
      else
      {
        if(s[i-1]==t[j-1])
        {
          dp[i][j]=dp[i-1][j-1]+1;
        }
        else
        {
          dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
      }
    }
  }
  char l[dp[n][m]+1];
  int index=dp[n][m];
  l[index]='\0';
  int i,j;
  i=n,j=m;
  while(i>0&&j>0)
  {
    if(s[i-1]==t[j-1])
    {
      l[index-1]=s[i-1];
      i--;
      j--;
      index--;
    }
    else if(dp[i-1][j]>dp[i][j-1])
    {
      i--;
    }
    else
      j--;
  }
  cout<<l<<endl;

  //cout<<dp[n][m];
}
int main()
{
  string s,t;
  cin>>s;
  cin>>t;
  lcs(s,t);
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> v(N);
  for (int i = 0; i < N; i++) cin >> v[i];

  sort(v.begin(), v.end(), greater<int>());
  int ans = 0;
  for (int i = 0; i < K; i++) ans += v[i];
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

class union_find_tree {
private:
	static const int MAX_N = 100002;
	int par[MAX_N], ran[MAX_N];
public:
	union_find_tree(int n) {
		if (n > MAX_N) cout << "BAD INPUT" << endl;
		for (int i = 0; i < n; i++) {
			par[i] = i;
			ran[i] = 0;
		}
	}
private:
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}
public:
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;

		if (ran[x] < ran[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (ran[x] == ran[y]) ran[x]++;
		}
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}
};


int main() {
	int N, M; cin >> N >> M;
	vector<int> p(N);
	union_find_tree uft(N);
	for (int i = 0; i < N; i++) {
		cin >> p[i];
		p[i]--;
	}
	for (int i = 0; i < M; i++) {
		int x, y; cin >> x >> y;
		x--; y--;
		uft.unite(x, y);
	}
	int ans = 0;
	for (int i = 0; i < N; i++) ans += uft.same(i, p[i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
#define ld long double
using namespace std;
ll n;
vector<ll> a;
vector<vector<ll> > adj(300009);
vector<ll> ans;
vector<ll> dp(300000);

pair<ll,pair<ll,ll> >  fun(ll x)
{
  auto it=lower_bound(dp.begin(),dp.end(),x);
  ll f;
  if(it==dp.end()) dp.pb(x),f=-1;
  else f=*it,*it=x;

  ll z=dp.size();
  return {f,{z,it-dp.begin()}};
}

void dfs(ll node,ll par)
{
  pair<ll,pair<ll,ll> >p=fun(a[node]);
  ans[node]=p.ss.ff;

  for(auto j:adj[node])
  if(j!=par)dfs(j,node);

  
  if(p.ff==-1)dp.pop_back();
  else
   dp[p.ss.ss]=p.ff;

}

int main()
{ 

fast;

cin>>n;
a.assign(n,0);
for(ll i=0;i<n;i++)cin>>a[i];
  ans.assign(n,1);


for(ll i=0;i<n-1;i++)
{
  ll x,y;
  cin>>x>>y;
  x--,y--;
  adj[x].pb(y);
  adj[y].pb(x);
}
dp.resize(0);
dfs(0,-1);

for(ll i=0;i<n;i++)
cout<<ans[i]<<'\n';


}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> tmp(n);
    rep(i, n){
        cin >> v.at(i);
        tmp.at(i) = v.at(i);
    }
    sort(all(tmp));
 
    rep(i, n) {
        if(v.at(i) <= tmp.at(n/2 -1)){
            cout << tmp.at(n/2) << endl;
        }else{
            cout << tmp.at(n/2 - 1) << endl;
        }
    }

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

int main(void){
	string S;

	REP(i,3){
		cin>>S;
		cout<<S[0];
	}
	cout<<endl;
	

	return 0; 
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <unordered_map>

#define DEBUG(x) cout << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<pair<T, T> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, m;
	cin >> n >> m;

	int ways = 0;
	vector<int> balls;
	for (int i = 2; i <= 2 * n; i += 2) {
		balls.push_back(i);
	}

	for (int i = 1; i <= 2 * m; i += 2) {
		balls.push_back(i);
	}	

	for (int i = 0; i < balls.size(); ++i) {
		for (int j = i + 1; j < balls.size(); ++j) {
			if ((balls[i] + balls[j]) % 2 == 0) {
				++ways;
			}
		}
	}

	cout << ways << "\n";

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}
int s;

int fun(int n) {
    if (n % 2 == 0) {
        return n / 2;
    } else {
        return 3 * n + 1;
    }
}

int main() {
    cin >> s;
    int ai = s;
    set<int> used;
    int count = 1;
    used.insert(ai);
    while (true) {
        count++;
        int newai = fun(ai);
        if (used.count(newai) == 0) {
            used.insert(newai);
            ai = newai;
        } else {
            cout << count << endl;
            exit(0);
        }
    }
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        s: Chars,
    }

    let mut ans: i64 = 0;
    let mut ans_max = 0;
    for i in 0..n {
        if s[i]=='I' {
            ans += 1;
        } else {
            ans -= 1;
        }
        ans_max = max(ans_max, ans);
    }

    println!("{}", ans_max);

}


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

int main(){
    long long  N;
    cin>>N;
    long long  a[N];
    map<long long,long long> mpr;
    map<long long,long long> mpl;
    map<long long,long long>  mpX;
    for(long long i=0;i<N;i++){
        cin>>a[i];
        mpr[1+i+a[i]]++;
        mpl[1+i-a[i]]++;
        mpX[i+1+a[i]]++;
    }
    long long ans=0;
    
    for(auto itr=mpX.begin();itr !=mpX.end();itr++){
       if(mpr[itr->first]*mpl[itr->first] !=0){
        ans=ans+mpr[itr->first]*mpl[itr->first];
        }
    }

    cout<<setprecision(20)<<ans<<endl;
    return 0;
}



Measured memory_bytes: 50916
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<double> v(n);
  for(int i = 0; i < n; ++i) cin >> v[i];
  sort(v.begin(), v.end());
  double next = (v[0] + v[1]) / 2;
  for(int i = 2; i < n; ++i){
    next = (next + v[i]) / 2;
  }
  printf("%f\n", next);
}

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

int main() {
  double n,t,a,p = 1,h1;
  cin >> n >> t >> a >> h1;
  double T1 = abs(a-(t-h1*0.006));
  for(int i = 1;i < n;i++){
    int h;
    cin >> h;
    if(abs(a-(t-h*0.006)) < T1){
      p = i+1;
      T1 = abs(a-(t-h*0.006));
    }
  }
  cout << p << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int x, y;
	scanf("%d%d", &x, &y);
	if (y % 2 != 0)
		printf("No\n");
	else {
		if (x <= y / 2 && x * 2 >= y / 2)
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 1616
/*
** 科赫曲线
*/

# include <cstdio>
# include <cmath>
#define M_PI 3.14159265358979323846

int n;

struct PointPair {
    double x, y;
};

void koch(int k, PointPair p1, PointPair p2) {
    if (k == 0)
        return;
    PointPair s, u, t;
    double th = M_PI * 60.0 / 180.0;
    s.x = (2.0 * p1.x + 1.0 * p2.x) / 3.0;
    s.y = (2.0 * p1.y + 1.0 * p2.y) / 3.0;
    t.x = (1.0 * p1.x + 2.0 * p2.x) / 3.0;
    t.y = (1.0 * p1.y + 2.0 * p2.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;
    

    koch(k - 1, p1, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(k - 1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(k - 1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(k - 1, t, p2);
}

int main() {
    // freopen("infile", "r", stdin);
    // freopen("outfile", "w", stdout);
    scanf("%d", &n);
    PointPair p1, p2;
    p1.x = 0.0;
    p1.y = 0.0;
    p2.x = 100.0;
    p2.y = 0.0;
    printf("%.8f %.8f\n", p1.x, p1.y);
    koch(n, p1, p2);
    printf("%.8f %.8f\n", p2.x, p2.y);
    return 0;
}


Measured memory_bytes: 2748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define togglebit(n,i) ((n)^(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
ll oddsum[500005];
ll evensum[500005];
ll a[500005];
int main(){
    fastread;
    ll n,i,j,k,l;
    ll m;
    cin>>n>>m;
    ll mini=n%m;
    ll kola=m-mini;
    mini=min(mini,kola);
    cout<<mini;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>

int a[100000];

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

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	int idx = partition(a, 0, n - 1);

	for (int i = 0; i < n; i++)
	{
		if (i > 0)
			printf(" ");
		if (i == idx)
			printf("[%d]", a[i]);
		else
			printf("%d", a[i]);
	}
	printf("\n");

	return 0;
}



Measured memory_bytes: 3088
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define pll pair<double,ll>

vector<vector<ll>> dp;

int main()
{
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    ostringstream ss;
    int dx = tx - sx;
    int dy = ty - sy;
    for(int i = 0;i < dx;i++)
    {
        ss << 'R';
    }
    for(int i = 0;i < dy;i++)
    {
        ss << 'U';
    }
    for(int i = 0;i < dx;i++)
    {
        ss << 'L';
    }
    for(int i = 0;i < dy;i++)
    {
        ss << 'D';
    }
    ss << 'D';
    for(int i = 0;i <= dx;i++)
    {
        ss << 'R';
    }
    for(int i = 0;i <= dy;i++)
    {
        ss << 'U';
    }
    ss << 'L';
    ss << 'U';
    for(int i = 0;i <= dx;i++)
    {
        ss << 'L';
    }
    for(int i = 0;i <= dy;i++)
    {
        ss << 'D';
    }
    ss << 'R';
    cout << ss.str() << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;

struct point{
    ll x, y;
};

/*FUNCs=================================================*/



/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int a, b;
    cin >>a >> b;

    int x = 1, cnt;
    while(x  < b){
        x += a -1;
        cnt++;
    }
cout << cnt;
}


Measured memory_bytes: 256
N = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

ans = 0

soinsu_list = factorization(N)
#print(soinsu_list)
for i in range(len(soinsu_list)):
    cnt = 0
    while soinsu_list[i][0] != 1:
        cnt += 1
        soinsu_list[i][1] -= cnt
        if soinsu_list[i][1] < 0:
            cnt -= 1
            break
    ans += cnt
print(ans)


Measured memory_bytes: 9364
import sys
n = int(sys.stdin.readline().strip('\n'))
h = list(map(int, sys.stdin.readline().strip('\n').split()))
dp = [float('inf') for _ in range(n)]
dp[0] = 0
dp[1] = abs(h[0]-h[1])
for i in range(2, n):
  dp[i] = min(dp[i-1] + abs(h[i-1]-h[i]), 
             dp[i-2] + abs(h[i-2]-h[i]))
print(dp[n-1])

Measured memory_bytes: 13976
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve() {
    ll a, b, k; cin >> a >> b >> k;
    int f = 1;
    while(k){
        if(f == 1){
            k--;
            b += a/2;
            a /= 2;
            f = 0;
        }else if(f == 0){
            k--;
            a += b/2;
            b /= 2;
            f = 1;
        }
    }
    cout << a << " " << b << endl;
}

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

    solve();
    return 0;
}
 


Measured memory_bytes: 256
#include <stdio.h>
#define N 10
int main(){
  int i,j,n,s;
  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf("%d",&s);
    printf("Case %d:\n",i+1);
    for (j=0;j<N;j++){
      s=s*s/100%10000;
      printf("%d\n",s);
    }
  }
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)



int main() {
    int x;
    cin >> x;
    
    cout << (x / 500 * 1000) + (x % 500 / 5 * 5) << endl;
    
    return 0;
}




Measured memory_bytes: 3592
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
 
    int A = stdIn.nextInt();
    int B = stdIn.nextInt();
    int C = stdIn.nextInt();

    int num = A + B + C;
    if (num ==17)
        System.out.println("YES");
    else
        System.out.println("NO");
    }
}

Measured memory_bytes: 8788
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n, m, b;
  cin >> n >>m >> b;
  n += m - 1;
  n /= m;
  fin (n * b);
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(4); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX(a,b) (a > b) ? a : b
#define MIN(a,b) (a < b) ? a : b
const int inf = 1000000000; // 10^9

int main (){
   int a,b,c;scanf("%d %d %d",&a,&b,&c);
   if(((a == 5||a == 7) && (b == 5||b == 7) && (c == 5||c == 7))&&((a+b+c) == 17))printf("YES\n");
   else printf("NO\n");
}


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

using namespace std;

#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)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n, k;
	cin >> n >> k;
	vector<ll> a(n);
	rep (i, n) cin >> a[i];
	FOR (i, k, n) {
	  if (a[i] > a[i - k]) cout << "Yes" << endl;
	  else cout << "No" << endl;
	}
    
    return 0;
}



Measured memory_bytes: 4792
#include<stdio.h>
int main (){//10001
  int n,i;
  int A[100001];
  scanf("%d",&n);
  for(i=1;i<=n;i++) scanf("%d",&A[i]);
  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(i/2>=1) printf("parent key = %d, ",A[i/2]);
    if(i*2<=n) printf("left key = %d, ",A[i*2]);
    if(i*2+1<=n) printf("right key = %d, ",A[i*2+1]);
    printf("\n");
  }
  return 0;
}



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

int inf = 1e9;

int main()
{
	int n; scanf("%d", &n);
	int m1 = inf, m2 = inf, s1 = 0, s2 = 0;
	for(int i = 1; i <= n; i++)
	{
		int x; scanf("%d", &x);
		if(x < m1)
		{
			if(m2 != inf) return 0 * puts("No");
			m2 = m1; s2 = s1;
			m1 = x; s1 = 1;
		}
		else if(x <= m1) s1++;
		else if(x < m2)
		{
			if(m2 != inf) return 0 * puts("No");
			m2 = x; s2 = 1;
		}
		else if(x <= m2) s2++;
		else return 0 * puts("No");
	}
	if(s2 && m2 != m1 + 1) return 0 * puts("No");
	if(s2 == 0)
	{
		if(m1 == n - 1 || m1 <= n / 2) return 0 * puts("Yes");
		else return 0 * puts("No");
	}
	int Min = s1, Max = s1 + s2 / 2 - 1;
	if(Min <= m1 && m1 <= Max) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    a = list(map(int,input().split()))
    tmp = 0
    for j in range(m):
        tmp += a[j]*b[j]
    if tmp+c > 0:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#define pi 3.14159265358979323846264338327950



int main() {
    std::string s; std::cin >> s;
    int x = s.length(), i;
    std::vector<bool> q(26);
    for (i = 0; i < x; i++) q[s[i] - 'a'] = true;
    for (i = 0; i < 26; i++) {
        if (q[i] == false) {
            std::cout << (char)('a' + i) << std::endl;
            return 0;
        }
    }
    std::cout << "None" << std::endl;
}

Measured memory_bytes: 3724
#include <iostream>
#include <cmath>

using namespace std;

int get_head(int a){
    return a / int(pow(10, int(log10(a))));
}

int num( int a, int b, int N){
    int ans = 0;
    for(int i=1; i<=N; i++){
        if(get_head(i) == a && i%10 == b) {
            ans ++;
            i+= 9;
        }
    }
    return ans;
}

int main(){
    int N;
    cin >> N;
    int d[100];
    for(int i=1; i<10; i++){
        for(int j=1; j<10; j++){
            d[i*10 + j] = 0;
        }
    }
    for(int i=1; i<=N; i++){
        d[10 * get_head(i) + i%10]++;
    }
    long ans = 0;
    for(int i=1; i<10; i++){
        for(int j=1; j<10; j++){
            ans += long(d[i*10 + j]) * long(d[j*10 + i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;


int main() {

    string s;
    while(true){
        cin>>s;
        if(s[0]=='#'){break;}
        int y,m,d;
        cin>>y>>m>>d;
        bool hei=true;
        if(y>=32){
            hei=false;
        }else if(y==31){
            if(m>=5){
                hei=false;
            }
        }
        if(hei){
            cout<<"HEISEI"<<" "<<y<<" "<<m<<" "<<d<<endl;
        }else{
            cout<<'?'<<" "<<y-30<<" "<<m<<" "<<d<<endl;
        }
    }



    return 0;
}



Measured memory_bytes: 3152
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <map>

#define ll long long
using namespace std;

int main(){
	ll w, h;
	cin >> w >> h;
	std::vector<pair<ll, ll> > v;
	for (ll i = 0; i < w; ++i)
	{
		ll p;
		cin >> p;
		v.push_back(pair<ll, ll>(p, 0)); 
	}
	for (ll i = 0; i < h; ++i)
	{
		ll q;
		cin >> q;
		v.push_back(pair<ll, ll>(q, 1));
	}
	sort(v.begin(), v.end());

	ll ans = 0;
	ll a = w + 1;
	ll b = h + 1;

	for (ll i = 0; i < w+h; ++i)
	{
		ll tmp;
		if (v[i].second == 0)
		{
			ans += v[i].first * b;
			a--; 
		}else{
			ans += v[i].first * a;
			b--;
		}
	}

	cout << ans << endl;

}


Measured memory_bytes: 4592
n = int(input())
s = input()

def z_algorithm(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A


length = n

ans = 0
for i in range(length):
    temp = z_algorithm(s[i:])
    for j in range(len(temp)):
        if min(temp[j],j) > ans:
            ans = min(temp[j],j)
print(ans)

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

int main() {
    int N;
    cin >> N;
    vector<int>x(N);
    int mx=-1;
    for(int i=0; i<N; i++){
        cin >> x[i];
       mx = max(x[i],mx);
    }
    int mn=9999999;
    for(int i=0; i<=mx; i++){
        int sum = 0 ;
        for(int j=0; j<N; j++){
            int tmp =  pow(x[j]-i,2);   
            sum += tmp;       
        }
       mn =  min(sum,mn);
    }

    cout << mn;
}


Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
const int MAXN=2e5+1;
ll ans=0;
int n,m;
int arr[MAXN];
inline bool CMP(int a,int b){
	return a<b;
}
inline int read(){
	int x=0,f=1;char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<3)+(x<<1)+c-'0';
	return x*f;
}
int main(){
	n=read();
	for(int i=1;i<=n;++i) arr[i]=read()-i;
	sort(arr+1,arr+n+1,CMP);
	m=(n&1)?((n>>1)+1):(n>>1);
	for(int i=1;i<=n;++i) ans+=(ll)abs(arr[i]-arr[m]);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#define int long long 
using namespace std;

signed main() {
	int N, A, B, nb, ns;
	cin>>N>>A>>B;
	
	int answer = 0;
	answer = (N/(A+B))*A;
	if(N%(A+B) >= A)
	{
		answer += A;
		cout<<answer;
	}
	else
	{
		answer += (N%(A+B));
		cout<<answer;
	}

	
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S;
  int K;
  cin >> N >> S >> K;
  char dif = S.at(K-1);
  
  for(int i = 0; i < N; i++){
  	if(S.at(i) != dif){
    	cout << "*";
    }else{
    	cout << S.at(i);
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
a, *a_n = map(int, open(0).read().split())


flag = 1
for num in a_n:
    if num % 2 == 0:
        if num % 3 != 0 and num % 5 != 0:
            flag = 0
            break
        
if flag == 1:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <regex>
#ifdef _DEBUG
#include "debug.h"
#endif
#define int ll
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define mkpr make_pair
#define mktp make_tuple
#define tv(tp, i) get<(i)>(tp)
#define CLEAR(obj) obj = decltype(obj)()
#define var auto
#define OUT(type) type &
#define IN(type) const type &
#define self (*this)
#define in :
#define True true
#define False false
using namespace std; using str = string; using cstr = const str;
using ll = long long; using ull = unsigned long long; using cint = const int; using cll = const ll;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>;
using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>;
static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7;
static const ll LINF = LLONG_MAX/2;
#ifdef int
static const int INF = LINF;
#else
static const int INF = INT_MAX/2;
#endif
static double EPS = 1e-9;
static inline bool DBLEQ(double a, double b) {return abs(a - b) < EPS;}
static inline void EPR(str msg) {cerr << msg << endl;}
static inline void AST(bool exp, str msg) {if(!exp){EPR(msg);} assert(exp);}
static inline void TAST(bool exp, str msg) {if(!exp){EPR(msg);} while(!exp){}}


int32_t main(int32_t argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef _DEBUG
    vs args(argv, argv+argc);
    string sample = make_sample(args, 4);
    ifstream ifs(sample); cin.rdbuf(ifs.rdbuf());
#endif


    int K; cin>>K;

    queue<int> que;
    FOR(i,1,10) que.push(i);
    int x = 0;
    REP(i,K) {
        x = que.front(); que.pop();
        if (x%10 == 0) {
            que.push(x*10 + 0);
            que.push(x*10 + 1);
        }  else if (x%10 == 9) {
            que.push(x*10 + 8);
            que.push(x*10 + 9);
        } else {
            que.push(x*10 + x%10-1);
            que.push(x*10 + x%10);
            que.push(x*10 + x%10+1);
        }
    }

    int ans = x;
    cout << ans << endl;


    return 0;
}


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

#define ll     long long
#define fr     first
#define sec    second
#define rep(i,n)  for(i=0;i<n;i++)
#define vi     vector <int>
#define vc     vector <char>
#define vl     vector <ll>
#define vb     vector <bool>
#define pb     push_back
#define M      1000000007
#define ios    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define open   freopen("input.txt","r",stdin);
#define close  freopen("output.txt","w",stdout);
#define M_PI   3.14159265358979323846
#define pp     pair<int,int>
#define nn 100003

int main()
{
    ios;
    ll n,i,q,b,c,sum=0;
    map <ll,ll> mp;
    cin>>n;
    ll a[n];
    rep(i,n)
    {
        cin>>a[i];
        sum+=a[i];
        mp[a[i]]++;
    }
    cin>>q;
    rep(i,q)
    {
        ll currsum;
        cin>>b>>c;
        if(mp.find(b)!=mp.end())
        {
            ll x=mp[b];
            currsum=sum-x*b+x*c;
            sum=currsum;
            mp.erase(b);
            if(mp.find(c)!=mp.end())
                mp[c]+=x;
            else
                mp[c]=x;
        }
        else
            currsum=sum;
        cout<<currsum<<"\n";
    }
    return 0;
}


Measured memory_bytes: 8360
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

void solve(int tc) {
    int x;
    cin>>x;
    cout<<!x<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    for(int tc=1; tc<=t; ++tc) {
        solve(tc);
    }    
    return 0;
}

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

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

    vector<int> a(n), x(n), y(n);
    for(int i = 0; i < n; i++){
        a[i] = i;
        cin >> x[i] >> y[i];
    }

    double sum = 0.0;
    do{
        for(int i = 0; i < n - 1; i++){
            double dx = x[a[i]] - x[a[i + 1]];
            double dy = y[a[i]] - y[a[i + 1]];
            sum += pow(dx*dx + dy*dy, 0.5);
        }
    }while(next_permutation(a.begin(), a.end()));
   
    int Factorial = 1;
    for(int i = 2; i <= n; i++) 
        Factorial *= i;

    cout << fixed << setprecision(10) << sum / Factorial << endl;
    return 0;
}

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

using namespace std;

int main(){

    int n, x; cin >> n >> x;

    vector<int> q;

    int donuts = 0;
    for( int i = 0; i < n; i++){
        int val; cin >> val;
        x -= val;
        donuts ++;
        q.push_back(val);
    }

    int minn = *min_element(q.begin(), q.end());

    while( x >= minn){
        x -= minn;
        donuts ++;
    }

    cout << donuts;
    return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		br.close();

		int mod = 1000000007;
		NCR ncr = new NCR(m, mod);
		long sum = 0;
		for (int i = 0; i <= n; i++) {
			long val1 = ncr.comb(n, i);
			long val2 = ncr.perm(m - i, n - i);
			long val = val1 * val2 % mod;
			if (i % 2 == 0) {
				sum += val;
			} else {
				sum = sum - val + mod;
			}
			sum %= mod;
		}
		long ans = sum * ncr.perm(m, n) % mod;
		System.out.println(ans);
	}

	static class NCR {
		long[] p, pi;
		int m;

		public NCR(int n, int mod) {
			n++;
			m = mod;
			p = new long[n];
			pi = new long[n];
			p[0] = 1;
			pi[0] = 1;
			for (int i = 1; i < n; i++) {
				p[i] = p[i - 1] * i % m;
			}
			pi[n - 1] = BigInteger.valueOf(p[n - 1])
					.modInverse(BigInteger.valueOf(m)).longValue();
			for (int i = n - 1; i > 1; i--) {
				pi[i - 1] = pi[i] * i % m;
			}
		}

		public long comb(int n, int r) {
			if (n < r) return 0;
			return p[n] * pi[r] % m * pi[n - r] % m;
		}

		public long perm(int n, int r) {
			if (n < r) return 0;
			return p[n] * pi[n - r] % m;
		}
	}
}


Measured memory_bytes: 41236
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
    int N,i,j;
    while(scanf("%d",&N)!=EOF)
    {
         int a[N][2];
         for(i=0;i<N;i++)
            for(j=0;j<2;j++)
                scanf("%d",&a[i][j]);
                int sum=0;
            for(i=0;i<N;i++)
                sum=sum+a[i][1]-a[i][0];
            printf("%d\n",sum+N);
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int N=2100,mod=1e9+7;
int n,k,jc[N*N],inv[N*N],f[N][N];
int ksm(int x,int k)
{
	int s=1;for(;k;k>>=1,x=1ll*x*x%mod)
				if(k&1) s=1ll*s*x%mod;return s;
}
void add(int &x,int y) {x+=y;if(x>=mod) x-=mod;}
int mul(int x,int y) {return 1ll*x*y%mod;}
int C(int n,int k) {return n<k?0:mul(mul(jc[n],inv[k]),inv[n-k]);}
int main()
{
	cin>>n>>k;jc[0]=inv[0]=1;
	if(k==1) return puts("1"),0;
	for(int i=1;i<=n*k;i++)
		jc[i]=mul(jc[i-1],i),inv[i]=ksm(jc[i],mod-2);
	f[0][0]=1;
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n;j++)
		{
			if(!f[i][j]) continue;
			add(f[i+1][j],f[i][j]);
			if(i>=j+1) add(f[i][j+1],mul(mul(f[i][j],n-j),C(n*k-j*k+j-i-1,k-2)));
		}
	cout<<f[n][n]<<endl;return 0;
}

Measured memory_bytes: 50560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define INF 1e8
typedef long long int ll;
const double PI = acos(-1);

using Graph = vector<vector<int>>;
int main()
{
  int x;
  cin >> x;
  if (x >= 30)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
	ll N, M;
	cin >> N >> M;
	map<ll, ll> order;
	for (ll i = 0; i < M; i++)
	{
		ll c, s;
		cin >> s >> c;
		if (s == 1 && c == 0 && N != 1) {
			cout << -1 << endl;
			return 0;
		}
		else if (order.find(s) == order.end()) {
			order[s] = c;
		}
		else {
			if (order[s] != c) {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	string ans;
	for (ll i = 1; i <= N; i++)
	{
		if (order.find(i) == order.end()) {
			if (i == 1 && N != 1) ans += '1';

			else ans += '0';
		}
		else {
			ans += to_string(order[i]);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

class UnionFind{
public:
    //親の番号を格納する。親だった場合はー（その集合のサイズ）
    vector<int> parents;

    //作る時はparentsを-1で初期化する
    //こうすることで全部ばらばらになる
    UnionFind(int n){
        parents = vector<int>(n, -1);
    }

    //Aがどのグループにいるか調べる
    int root(int A){
        if(parents[A]<0) return A;
        return parents[A] = root(parents[A]);
    }

    //自分のいるグループの大きさを調べる
    int size(int A){
        return -parents[root(A)];
    }

    //AとBをくっつける
    bool connect(int A, int B){
        //AとBを直接ではなく親同士をくっつける
        A=root(A);
        B=root(B);
        if(A==B){
            return false;
        }

        //大きい方（A)に小さい方（B)をくっつけたい
        if(size(A)<size(B)) swap(A, B);

        parents[A] += parents[B];
        parents[B] = A;

        return true;
    }
};



typedef tuple<ll, ll, ll> T;


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

    int n, m; cin >> n >> m;
    UnionFind uni(n);
 
    for(int i=0; i<m; i++){
        int x,y,z; cin >> x >> y >> z;
        --x; --y;
        uni.connect(x, y);
    }
 
    map<int, int> mp;
    for(int i=0; i<n; i++) ++mp[uni.root(i)];
    cout << mp.size() << endl;

	return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int n;
	cin >> n;
	vector<pii> v(n);
	rep(i, n) {
		int a;
		cin >> a;
		v[i] = {a, i + 1};
	}
	sort(all(v));
	rep(i, n) {
		printf("%d%c", v[i].second, i + 1 == n ? '\n' : ' ');
	}
}

Measured memory_bytes: 1664
n, m = map(int, raw_input().split())
x = map(int, raw_input().split())
y = map(int, raw_input().split())
M = 10**9+7
ansx = 0
for i in range(n-1):
    ansx += (x[i+1]-x[i])*(i+1)*(n-i-1)
    ansx %= M
ansy = 0
for j in range(m-1):
    ansy += (y[j+1]-y[j])*(j+1)*(m-j-1)
    ansy %= M
print (ansx*ansy)%M


Measured memory_bytes: 14500
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <numeric>
using namespace std;

int main(){
    long long N;
    cin >> N;
    long long Sum = 0;

    for(long long i = 1 ; i*i <= N; i++){
        if(N % i != 0) continue;
        long long T = (N / i) - 1;
        if(i < T) Sum = Sum + T;
    }

    cout << Sum << endl;
}

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

int main() {
    int N;
  int T;
  int M=1001;
  
  cin>>N>>T;
  
  vector<int> c(N);
  vector<int> t(N);
for (int i = 0; i < N; i++) {
  cin >> c.at(i)>>t.at(i);
}
  
  

  
  
  for (int i = 0; i < N; i++) {
  if(t.at(i)<=T){
    M=min(M,c.at(i));
  }
}
  
  if(M!=1001){
    cout<<M<<endl;
  }
  else{
    cout<<"TLE"<<endl;
  }
 
  
  
  
}

Measured memory_bytes: 256
import sys

S = input()
if len(S) == 1:
    print(int(S))
    sys.exit()

ls = []
for i in range(1<<(len(S)-1)):
    ans = 0
    num = format(i, 'b').zfill(len(S)-1)
    start = 0
    for j, x in enumerate(num):
        if x == '1':
            ans += int(S[start:j+1])
            start = j + 1
    ans += int(S[start:len(S)])
    ls.append(ans)
print(sum(ls))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char b;
	cin>>b;
	if(b=='A')
	cout<<'T';
	else if(b=='T')
	cout<<'A';
	else if(b=='C')
	cout<<'G';
	else
	cout<<'C';
	return 0;
}     	

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

#define MAX_V 110
#define INF 1<<29

template <typename T>
struct MaxFlow {
  struct edge { int to, rev; T cap; };

  typedef vector<edge> Edges;
  vector<Edges> G;
  int V;
  vector<int> level, iter;
  
  MaxFlow(int V) : V(V) { G.resize(V); }

  void add_edge(int from, int to, T cap) {
    G[from].push_back((edge){to, (int)G[to].size(), cap});
    G[to].push_back((edge){from, (int)G[from].size(), 0});
  }

  void bfs(int source) {
    level.assign(V, -1);
    queue<int> que;
    que.push(source);
    level[source] = 0;
    while (!que.empty()) {
      int v = que.front(); que.pop();
      for (int i = 0; i < (int)G[v].size(); i++) {
	edge &e = G[v][i];
	if (e.cap > 0 && level[e.to] < 0) {
	  level[e.to] = level[v] + 1;
	  que.push(e.to);
	}
      }
    }
  }

  T dfs(int v, int sink, T flow) {
    if (v == sink) return flow;
    for (int &i = iter[v]; i < (int)G[v].size(); i++) {
      edge &e = G[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
	T d = dfs(e.to, sink, min(e.cap, flow));
	if (d > 0) {
	  e.cap -= d;
	  G[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }

  T dinic(int source, int sink) {
    T flow = 0;
    while (true) {
      bfs(source);
      if (level[sink] < 0) return flow;
      iter.assign(V, 0);
      T f;
      while ((f = dfs(source, sink, INF)) > 0) {
	flow += f;
      }
    }
  }
};


int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int V, E;
  cin >> V >> E;
  MaxFlow<int> mf(V);
  REP(i, E) {
    int u, v, c;
    cin >> u >> v >> c;
    mf.add_edge(u, v, c);
  }
  cout << mf.dinic(0, V-1) << endl;  
  return 0;
}

Measured memory_bytes: 3252
#include<iostream>
#include<cmath>

#define PIE 3.14159265358979323846264 
#define ANG PIE/180.0	//RADツづ可陛渉環キ

using namespace std;

int main(void){

	double x,y,angle,step,dir;
	
	x=y=angle=0.0;
	
	while(1){
		
		scanf("%lf,%lf",&step,&dir);
		if(step==0&&dir==0){
			break;
		}
		
		x=x+step*sin(angle*ANG);
		y=y+step*cos(angle*ANG);
		
		angle=angle+dir;
	}	
	
	cout<<(int)x<<endl<<(int)y<<endl;

	return 0;
}

Measured memory_bytes: 0