akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;

int main()
{
  while (true)
  {
    int a, b;
    string op;
    cin >> a >> op >> b;
    if (op == "?")
      return 0;

    if (op == "+")
      cout << a + b << endl;
    else if (op == "-")
      cout << a - b << endl;
    else if (op == "*")
      cout << a * b << endl;
    else
      cout << a / b << endl;
  }
}

Measured memory_bytes: 3148
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
	int main(){
		int n;
		cin>>n;
		string s,ans;
		cin>>s;
		if(n>=s.size())
			cout<<s<<endl;
		else{
			for(int i=0;i<n;i++)
				ans+=s[i]; 
			ans+='.',ans+='.',ans+='.';
			cout<<ans<<endl;
		} 
	}

Measured memory_bytes: 3604
n=int(input())
a=list(map(int,input().split()))

b1=[]
b2=[]
offset=0
if n%2==1:
    offset=1
for i in range(n):
    if (i+offset)%2==0:
        b1.append(a[i])
    else:
        b2.append(a[i])
b2=list(reversed(b2))
b=b2+b1
for i in b:
    print(i,end=" ")

Measured memory_bytes: 26360
c = { 
    'S' : [0 for _ in range(13)], 'H' : [0 for _ in range(13)],
    'C' : [0 for _ in range(13)], 'D' : [0 for _ in range(13)]
}
 
x = int(input())
for _ in range(x):
    (a, b) = input().split()
    b = int(b)
    c[a][b - 1] = b
 
for a in ('S', 'H', 'C', 'D'):
    for b in range(13):
        if c[a][b] == 0:
            print('{0:s} {1:d}'.format(a, b+1))

Measured memory_bytes: 7740
#include<cstdio>
#include<algorithm>
using namespace std;

void print(int a[], int n){
    int first = 1;
    for(int i = 0; i < n; i++){
        if(first) first = 0;
        else printf(" ");
        printf("%d", a[i]);
    }
}

int main(){
    int a[105], n;
    while(~scanf("%d", &n)){
        for(int i = 0; i < n; i++){
            scanf("%d", &a[i]);
        }
        for(int i = 0; i < n - 1; i++){
            print(a, n);
            puts("");
            int x = a[i + 1];
            int b = upper_bound(a, a + i + 1, x) - a, j;
            for(j = i; j >= b; j--){
                a[j + 1] = a[j];
            }
            a[j + 1] = x;
        }
        print(a, n);
        puts("");
    }
    return 0;
}



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

bool jif(int t, int x_0, int x_1, int y_0, int y_1);

int main(){
  
  int N;
  int x[110000]={0};
  int y[110000]={0};
  int t[110000]={0};
  int dt=0;
  int dxdy=0;

  bool judge=true;
  
  cin >> N;
  for(int i=1;i<=N;i++) cin >> t[i] >> x[i] >> y[i];

  for(int i=0;i<N;i++){
     //Is it possible to reach from (i-1) to i?
    dt = t[i+1] - t[i];
    dxdy = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
    if(dt < dxdy || (dt - dxdy) %2 == 1) judge = false;
    //If unreachable, break
    if(judge==false) break;
  }

  if(judge) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

int main(){
    int N;
    cin >> N;
    priority_queue<int> que;
    int val;
    for(int i=0; i<N; i++){
        cin >> val;
        que.push(val);
    }

    int large_val;
    int small_val;
    while(que.size() > N/2){
        large_val = que.top(); que.pop();
    }
    small_val = que.top();

    cout << large_val - small_val << endl;
}

Measured memory_bytes: 3900
#include <cstdio>

using namespace std;

int main(){
    long long int N,M,ans = 0;

    scanf("%lld%lld",&N,&M);

    if(2*N<=M){
        ans = N;
        M -= 2*N;
        ans += M/4;
    }
    else{
        ans = M/2;
    }

    printf("%lld\n",ans);

    return 0;
}

Measured memory_bytes: 256
//Fennec Vs Monster
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int n, k;
	cin >> n >> k;
	long long sum = 0, a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = 0; i < n - k; i++) {
		sum += a[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<ll> vec(n);
    rep(i,n) cin >> vec[i];
    ll ans = vec[0];
    for(int i=1;i<n;i++){
        ans = gcd(ans, vec[i]);
    }
    cout << ans << endl;
    
    
}

Measured memory_bytes: 1024
import java.util.Scanner;

/**
 * https://abc046.contest.atcoder.jp/tasks/abc046_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		sc.close();
		
		long ans = (long) (K*Math.pow(K-1, N-1));
		System.out.println(ans);

	}

}


Measured memory_bytes: 21844
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())
 
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const ll MOD = (ll)1000000007;//10^9+7
const ll INF2 = (ll)100000000000000000;//10^18


int main() {
    string s;
    cin>>s;
    int n = s.size();
    VI v(n,0);
    REP(i,n){
        v[i] = s[i]-'0';
    }
    ll ans;
    for(int bit = 0; bit<(1<<(n-1));bit++){
        ll ten = 1;
        REP(i,n){
            if(bit&(1<<(n-i-1))){
                ten = 1;
            }
            ans+=v[n-i-1]*ten;
            ten *=10;
        }
    }
    cout<<ans<<endl;
}


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

#define N 10010

int n, c[N];
set<int> e[N];
set<int> leaf;
int a[N];

int main() {
	scanf("%d", &n);
	for (int i = 1, a, b; i < n; i ++) {
		scanf("%d%d", &a, &b);
		e[a].insert(b);
		e[b].insert(a);
	}
	for (int i = 1; i <= n; i ++) scanf("%d", c + i);
	for (int i = 1; i <= n; i ++) if (e[i].size() == 1) leaf.insert(i);
	sort(c + 1, c + n + 1);
	int now = 1;
	int sum = 0;
	while (!leaf.empty()) {
		int x = *leaf.begin();
		leaf.erase(x);
		int y = *e[x].begin();
		sum += c[now];
		a[x] = c[now++];
		if (e[y].size() == 1) leaf.erase(y);
		e[y].erase(x);
		if (e[y].size() == 1) leaf.insert(y);
	}
	for (int i = 1; i <= n;i ++) if (!a[i]) a[i] = c[n];
	printf("%d\n", sum);
	for (int i = 1; i <= n; i ++) printf("%d ", a[i]);
	return 0;
}


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

using namespace std;
typedef long long int ll;

ll gcd(int a, int b){
	return b==0 ? a: gcd(b,a%b);
}

void simp(vector<ll> &k, int d){
	for(int i=0; i<k.size(); i++){
		int tgcd=gcd(k[i],d);
		k[i]/=tgcd;
		d/=tgcd;
	}
}

pair<pair<ll,int>,ll> sol(vector<ll> &a, int n, int l){
	unordered_map<ll,int> cnt, cnt1;
	ll num=0, deno=0;
	for(int i=n-1; i>=n-l; i--){
		auto fitr=cnt.find(a[i]);
		if(fitr!=cnt.end()) fitr->second++;
		else cnt.insert(make_pair(a[i],1));
		num+=a[i];
		deno++;
	}

	for(int i=0; i<n-l; i++){
		auto fitr=cnt1.find(a[i]);
		if(fitr!=cnt.end()) fitr->second++;
		else cnt1.insert(make_pair(a[i],1));
	}
	
	ll dcnt=0;
	for(auto b=cnt1.begin(); b!=cnt1.end(); b++){
		if(cnt.find(b->first)!=cnt.end()){
			ll k1=min(b->second,cnt[b->first]), k2=max(b->second,cnt[b->first]);
			vector<ll> dd;
			for(ll i=k2+1; i<=k1+k2; i++){
				dd.push_back(i);
			}

			for(ll i=1; i<=k1; i++){
				simp(dd,i);
			}

			ll td=1;
			for(int i=0; i<dd.size(); i++) td=td*dd[i];	
			
			dcnt+=td;
		}
	}
	
	return make_pair(make_pair(num,deno),max((ll)1,dcnt));
}

int main(){
	int n, a, b;
	cin>>n>>a>>b;
	
	vector<ll> v(n);
	for(int i=0; i<n; i++) cin>>v[i];
	sort(v.begin(),v.end());

	vector<pair<pair<ll,int>,ll> > ss; 	
	for(int i=a; i<=b; i++){
		pair<pair<ll,int>,ll> tp=sol(v,n,i);
		ss.push_back(tp);
	}

	ll num=0, deno=1;
	for(int i=0; i<ss.size(); i++){
		if(num*ss[i].first.second<deno*ss[i].first.first){
			num=ss[i].first.first;
			deno=ss[i].first.second;
		}
	}

	ll cnt=0;
	for(int i=0; i<ss.size(); i++){
		if(num*ss[i].first.second==deno*ss[i].first.first){
			cnt+=ss[i].second;
		}
	}

	printf("%0.6f\n%lld\n", 1.0*num/deno, cnt);
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int a, b, t;
    cin >> a >> b >> t;
    cout << t / a * b << endl;

    return 0;
}

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

// 1-based index
int dp[2001][2001]; // iまでのWとjまでのBを左に並べたときの最小回数
int ind[2][2001];// ind[c_i][a_i] = i
int mgi[2][2001][4001];// hdr[c][a][i]: a以下のcがiの位置より右にいくつあるか


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	char c; int a, b;
	for (int i = 1; i <= 2*N; ++i) {
		cin >> c >> a;
		b = (c == 'W') ? 0 : 1;
		ind[b][a] = i;
		for (int j = 1; j < i; ++j) {
			mgi[b][a][j] = 1;
		}
		for (int j = i; j <= 2*N; ++j) {
			mgi[b][a][j] = 0;
		}
	}
	
	for (int j = 1; j <= 2*N; ++j) {
		mgi[0][0][j] = 0;
		mgi[1][0][j] = 0;
		for (a = 2; a <= N; ++a) {
			mgi[0][a][j] += mgi[0][a - 1][j];
			mgi[1][a][j] += mgi[1][a - 1][j];
		}
	}

	int kmin, mmin;
	for (int k=0; k <= N; ++k) {
		for (int m=0; m <= N; ++m) {
			if (k == 0 && m == 0) {
				dp[0][0] = 0;
				continue;
			}
			kmin = 2000 * 2000, mmin = 2000 * 2000;//とにかくでかい数字
			if (k > 0) {
				// k番目の白をk+m番目に持って来るので、
				// 初期位置i=ind[0][k]からmgi[0][k-1][i]+mgi[1][m][i]だけ右にズレているので
				int i = ind[0][k];
				kmin = dp[k - 1][m] + (i + mgi[0][k - 1][i] + mgi[1][m][i]) - (k + m);
			}
			if (m > 0) {
				int i = ind[1][m];
				mmin = dp[k][m - 1] + (i + mgi[0][k][i] + mgi[1][m - 1][i]) - (k + m);
			}
			dp[k][m] = min(kmin, mmin);
		}
	}
	cout << dp[N][N] << endl;

}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct edge {
  int to, cost;
  edge(){}
  edge(int to, int cost):to(to), cost(cost){}
};

int n, m, c;
vector< vector<edge> > graph;

struct State {
  int now, cost, chg;
  State(){}
  State(int now, int cost, int chg):now(now), cost(cost), chg(chg){}
  bool operator < (const State& s) const {
    return cost > s.cost;
  }
};

vector<vint> mincost;

int dijkstra() {
  resz(mincost, n+1, vint(n, inf));
  priority_queue<State> que;
  mincost[0][0] = 0;
  que.emplace(0, 0, 0);
  while(!que.empty()) {
    State s = que.top(); que.pop();
    int v = s.now, cost = s.cost, chg = s.chg;
    if(mincost[chg][v] < cost) continue;
    for(edge& e : graph[v]) {
      if(cost + e.cost < mincost[chg][e.to]) {
	mincost[chg][e.to] = cost + e.cost;
	que.emplace(e.to, mincost[chg][e.to], chg);
      }
      if(chg < n && cost < mincost[chg+1][e.to]) {
	mincost[chg+1][e.to] = cost;
	que.emplace(e.to, mincost[chg+1][e.to], chg+1);
      }
    }
  }
  rep(i, n+1) {
    if(mincost[i][n-1] <= c) return i;
  }
  return n;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(cin >> n >> m >> c, n+m+c) {
    resz(graph, n);
    rep(i, m) {
      int f, t, cc;
      cin >> f >> t >> cc;
      --f, --t;
      graph[f].emplace_back(t, cc);
    }
    cout << dijkstra() << endl;
  }

  return 0;
}

Measured memory_bytes: 3528
# coding: utf-8


def solve(*args: str) -> str:
    s = args[0]
    return 'Yes' if (
        s[0::2].count('L') == 0 and
        s[1::2].count('R') == 0
    ) else 'No'


if __name__ == "__main__":
    print(solve(*[input() for _ in range(1)]))


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front

// #define fisier 1

using namespace std;

typedef long long ll;

const int mod = 1000000007;
const double dancila = 3.14159265359; // PI 
const double eps = 1e-9;

int n, h[100002];
int dp[100002];  // dp[i] = min cost to get to i

int main()
{

    #ifdef fisier
        ifstream f("input.in");
        ofstream g("output.out");
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	
	cin >> n;
	for(int i = 1; i <= n; ++i)
		cin >> h[i];
	for(int i = 1; i <= n; ++i)
		dp[i] = (1<<30);
	dp[1] = 0;
	for(int i = 1; i < n; ++i)
	{
		// i -> i+1
		if(dp[i] + abs(h[i] - h[i+1]) < dp[i+1])
			dp[i+1] = dp[i] + abs(h[i] - h[i+1]);
		// i -> i+2
		if(i + 2 <= n && dp[i] + abs(h[i] - h[i+2]) < dp[i+2])
			dp[i+2] = dp[i] + abs(h[i] - h[i+2]);
	}
	cout << dp[n];
    return 0;
}


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

int main(){
	long long n, a, b;
	
	cin >> n >> a >> b;
	long long blues = 0;
	
	long long times = floor(n / (a + b));
	blues += a * times;
	
	long long remain = n % (a + b);
	if (remain >= a){
		blues += a;
	}
	else{
		blues += remain;
	}
	
	
	cout << blues;	
	
	
	return 0;
}


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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll h, w; cin >> h >> w;
    vector<vector<bool>> b(h+2, vector<bool>(w+2, true)); // trueで黒
    queue<P> que;
    vector<vector<ll>> dist(h+2, vector<ll>(w+2, 0));
    rep(i, h) {
        string s; cin >> s;
        rep(j, w) {
            if(s[j] == '.') {
                b[i+1][j+1] = false;
            }
            else {
                que.push(make_pair(i+1, j+1));
            }
        }
    }
    while(!que.empty()) {
        P t = que.front(); que.pop();
        ll x = t.first, y = t.second;
        if(!b[x-1][y]) {
            dist[x-1][y] = dist[x][y]+1;
            b[x-1][y] = true;
            que.push(make_pair(x-1, y));
        }
        if(!b[x+1][y]) {
            dist[x+1][y] = dist[x][y]+1;
            b[x+1][y] = true;
            que.push(make_pair(x+1, y));
        }
        if(!b[x][y-1]) {
            dist[x][y-1] = dist[x][y]+1;
            b[x][y-1] = true;
            que.push(make_pair(x, y-1));
        }
        if(!b[x][y+1]) {
            dist[x][y+1] = dist[x][y]+1;
            b[x][y+1] = true;
            que.push(make_pair(x, y+1));
        }
    }

    ll ans = 0;
    rep(i, h) {
        rep(j, w) {
            if(ans < dist[i+1][j+1]) {
                ans = dist[i+1][j+1];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 27552
from sys import stdin, gettrace
import sys
 
if not gettrace():
    def input():
        return next(stdin)[:-1]
 
 
# def input():
#    return stdin.buffer.readline()
 
def mincost(n,h,k):
  dp=[-1 for i in range(n)]
  dp[n-1]=0
  dp[n-2]=abs(h[n-2]-h[n-1])
  for i in range(n-3,-1,-1):
    mn=min(i+k+1,n)
    mnm=sys.maxsize
    for j in range(i+1,mn):
      mnm=min(dp[j]+abs(h[j]-h[i]),mnm)
    dp[i]=mnm    
  return dp[0]
 
def main():
  n,k=map(int,input().split())
  h=[int(x) for x in input().split()]
  print(mincost(n,h,k)) 
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 56616
#include<bits/stdc++.h>
using namespace std;
#include<string>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define intarr(arr, n)  ll arr[n];  for (ll i = 0; i < n; i++)  cin >> arr[i]
#define inpvec(vec,n) for(ll i=0;i<n;i++){ll v;cin>>v;vec.push_back(v);}
#define ff first
#define ss second
#define pb push_back
#define mkp make_pair
#define vec vector<ll>
#define pi pair<ll,ll>
#define changeline cout<<endl
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(),v.end()
#define mod2 998244353
#define NO cout << "NO" <<endl
#define YES cout << "YES" <<endl
#define mem(arr,val) memset(arr,val,sizeof(arr));
const ll mod=1e9+7;
#define piii 3.14159265358979323846264338327950


bool prime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
bool subsequence_checker(string str1, string str2, ll m, ll n) 
{ 
    if (m == 0) return true; 
    if (n == 0) return false; 
    if (str1[m-1] == str2[n-1]) 
        return subsequence_checker(str1, str2, m-1, n-1); 
    return subsequence_checker(str1, str2, m, n-1); 
}
ll inv(ll a)
{
    ll p=mod2;
    ll b=p-2,ans=1;
    for(;b > 0;a = a * a % p,b >>= 1)if(b & 1)ans = ans * a % p;
    return ans;
}
ll ncr(ll n,ll m)
{
    ll p=mod2;
    if(m > n)return 0;
    ll up=1,down=1;
    for(int i=n-m+1;i<n+1;i++)up*=i,up%=p;
    for(int i=1;i<m+1;i++)down*=i,down%=p;
    return up*inv(down)%p;
}

ll countDigit(ll n)
{   
    return floor(log10(n) + 1); 
}  
ll a_pow_b(ll a,ll b)
{
    ll p=1000000007;
    ll ans=1;
    for(;b > 0;a = a * a % p,b >>= 1)if(b & 1)ans = ans * a % p;
    return ans;
}
ll gcd(ll a,ll b) 
{ 
    if (b==0) 
        return a; 
    return gcd(b,a%b);      
} 
ll lcm(ll a, ll b)  
{  
    return (a*b)/gcd(a, b);  
}
bool isPerfectSquare(ll x) 
{   
  long double sr = sqrt(x); 
  return ((sr - floor(sr)) == 0); 
}
ll ncr123(ll n, ll k){
    if (k == 1) {
        return n;
    }
    if (k == 2) {
        return n * (n - 1) / 2;
    }
    if (k == 3) {
        return n * (n - 1) * (n - 2) / 6;
    }
}
bool com(const pi &a,const pi &b)   //acc to second element sort for vec of pi
{ 
    if(a.second==b.second)
        return a.first<b.first;
    return a.second<b.second;
}



void solve(){

    ld a,b, h,m;
    cin>>a>>b>>h>>m;

    ld ang=piii*2*(h/12.0 + (m/60)/12.0 - m/60.0);

    ld ans=a*a+b*b-(2*a*b)*cos(ang);


    cout<<fixed<<setprecision(20)<<sqrt(ans);
    return;
}
 
 
int main()
{
    IOS;
    ll t;
    //cin>>t;
    t=1;

    while(t--){
        solve();
        cout<<endl;
    }

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define intMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int n, w;

int main(){
  cin >> n >> w;
  vector<int>weight(n), value(n);
  for(int i = 0; i<n; i++) cin >> weight[i] >> value[i];
  ll dp[n+1][w+1];
  for(int i = 0; i < n+1; i++){
    for(int j = 0; j < w+1; j++){
      dp[i][j] = 0;
    }
  }

  for(int i = 0; i < n; i++){
    for(int j = 0; j < w+1; j++){
      if(j - weight[i] >= 0){
        ll tmp = dp[i][j-weight[i]] + value[i]; //品物を拾う場合
        dp[i+1][j] = max(dp[i][j], tmp);
      }else{
        dp[i+1][j] = dp[i][j];
      }
    }
  }
  cout << dp[n][w] << endl;
}

Measured memory_bytes: 79104
#include <iostream>

using namespace std;

int main() {
	int pay;
	int change[] = { 500,100,50,10,5,1 };
	while (cin >> pay, pay) {
		int ans = 0;
		int c = 1000 - pay;
		for (int i = 0; i < 6; ++i) {
			ans += c / change[i];
			c %= change[i];
		}
		cout << ans << endl;
	}

	return 0;
}


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

int main() {
    int N;
    int ABC[3];
    cin >> N;
    rep(i, 3) cin >> ABC[i];
    int l[N] = {0};
    rep(i, N) cin >> l[i];

    int dp[3][1<<N]; //A,B,Cの材料にする竹を選択し、消費MPを記録するNbitのdpテーブル

    //A,B,Cすべてについて、使用する竹に対応する消費MPを全パターン計算する
    for(int i=1; i<(1<<N); i++) {
        int cnt = 0, sum = 0;

        //使用する竹の個数と長さの合計を計算
        rep(j, N) {
            if(i & (1<<j)) {
                cnt++;
                sum += l[j];
            }
        }

        //A,B,Cすべてに対して消費MPを記録
        rep(j, 3) {
            dp[j][i] = (cnt-1)*10 + abs(ABC[j]-sum);
        }
    }

    int ans = 1000000007;
    for(int i=1; i<(1<<N); i++) {
        for(int j=1; j<(1<<N); j++) {
            for(int k=1; k<(1<<N); k++) {

                //使用する竹が重複しない場合の合計消費MPを計算し、最小値を求める
                if((i&j) == 0 && (j&k) == 0 && (i&k) == 0) {
                    ans = min(ans, dp[0][i] + dp[1][j] + dp[2][k]);
                }

            }
        }
    }

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#include<iostream>

int main(){
	int n;
	while(std::cin>>n){
		int ans=0,data[12],back[12];
		if(n==0)break;
		for(int i=0;i<n;i++)std::cin>>data[i],back[i]=data[i];
		while(true){
			for(int i=0;i<n;i++){
				int count=0;
				for(int j=0;j<n;j++){
					if(back[i]==back[j])count++;
				}
				data[i]=count;
			}
			bool f=true;
			for(int i=0;i<n;i++){
				if(data[i]!=back[i])f=false;
			}
			if(f)break;
			for(int i=0;i<n;i++)back[i]=data[i];
			ans++;
		}
		std::cout<<ans<<std::endl;
		for(int i=0;i<n;i++){
			if(i!=n-1)std::cout<<data[i]<<" ";
			else std::cout<<data[i];
		}
		std::cout<<std::endl;
	}
	return 0;
}

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

int main(){
  	int n,m,num[50],a,b;
  	cin >> n >> m;
  
  	rep(i,0,n){
      num[i] = 0;
    }
  	
  	rep(i,0,m){
      cin >> a >> b;
      num[a-1]++;
      num[b-1]++;
    }
  
  	rep(i,0,n){
      cout << num[i] << endl;
    }
  
  	return 0;
}

Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("avx2")
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <functional>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <climits>
#include <numeric>

using namespace std;
#define open_streams ifstream fin("olympiad.in");ofstream fout("olympiad.out")
#define close_streams fin.close();fout.close()
#define speed cout.tie(0);cin.tie(0);ios_base::sync_with_stdio(0)
#define ll long long
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define UNIQ(a) a.resize(unique(all(a)) - a.begin())
#define eps 1e-6
const double PI = M_PI;
const int INF = INT_MAX;
const ll limit = 1LL * 4e18;
const int MOD = 1e9 + 711;
const int MOD2 = 1e9 + 933;
//---------------------------------------------------------------------------
const int mod = 1e9 + 7;
const int maxn = 2e5 + 100;





signed main() {
    speed;
    int n;
    cin >> n;
    vector<int> a(n+1);
    for(int i = 1; i < n;++i) {
        int x;
        cin >> x;
        a[x]++;
    }
    for(int i = 1; i <= n;++i) {
        cout << a[i] << '\n';
    }
    return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int n;
    cin >> n;
    int c=0;
    rep(i,0,n){
        int a;
        cin >> a;
        if(a%2==1) c++;
    }
    if(c%2==0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	char[] s = sc.next().toCharArray();
      	int ans = 0;
      	for(int i = 0; i < s.length; i++){
        	if(s[i] == '1') ans++;
        }
      	System.out.println(ans);
    }
}

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

int main(){
  int H,W;cin>>H>>W;
  char C[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++) cin>>C[i][j];
  }
  char ans[2*H][W];
  for(int i=0;i<2*H;i++){
    int k=i/2;
    for(int j=0;j<W;j++){
      ans[i][j]=C[k][j];
    }
  }
  for(int i=0;i<2*H;i++){
    for(int j=0;j<W;j++) cout<<ans[i][j];
    cout<<"\n";
  }
}

Measured memory_bytes: 3628
#include <iostream>
#include <bits/stdc++.h>
#define loop(N) for(int i=0;i<N;i++)
#define vi vector<int>
#define vs vector<string>
#define vl vector<long long int>
#define vpi vector<pair<int,int>>
#define msi map<string,int>
#define mil map<int,long long int>
#define lli long long int
#define ulli unsigned long long int

using namespace std ;
void ps(string i){
    cout << i << endl;
}

template <class T>
void pt(T s){
    cout << s << endl;
}

void pi(int i){
    cout << i << endl;
}

template <class T>
void pv(vector<T> v){
    loop(v.size()){
        pt<T>(v[i]);
    }
}

/*********************************reused****************************/
int main()
{
    string x,y;
    cin>>x>>y;
    if(x>y)
        cout<<">"<<endl;
    else if(x<y)
        cout<<"<"<<endl;
    else
        cout<<"="<<endl;

   return 0;
}


Measured memory_bytes: 256
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n = inn()
ac = wa = tle = re = 0
for i in range(n):
    s = ins()
    if s =='AC':
        ac += 1
    elif s =='WA':
        wa += 1
    elif s =='TLE':
        tle += 1
    else:
        re += 1
print('AC x {}'.format(ac))
print('WA x {}'.format(wa))
print('TLE x {}'.format(tle))
print('RE x {}'.format(re))


Measured memory_bytes: 69852
#define FALSE 0
#define TRUE 1

#include <stdio.h>
#include <stdlib.h>


typedef struct tag_card {
	char suit_;
	int num_;
}card_t;

void displayArray(card_t *c, int n);

void swap(card_t *x, card_t *y);

void selectionSort(card_t *C, int n);

void bubbleSort(card_t *C, int n);

int isStable(card_t cBubble[], card_t cSelection[], int n);

int main(void) {
	int n, i;
	scanf("%d%*c", &n);

	card_t C1[36] = {};
	card_t C2[36] = {};

	for (i = 0; i < n; i++) {
		scanf("%c%d%*c", &C1[i].suit_, &C1[i].num_);
		C2[i] = C1[i];
	}

	bubbleSort(C1, n);
	selectionSort(C2, n);

	displayArray(C1, n);
	printf("Stable\n");
	displayArray(C2, n);
	if (isStable(C1, C2, n))
		printf("Stable\n");
	else
		printf("Not stable\n");

	return 0;
}

void displayArray(card_t *c, int n) {
	int i = 0;

	for (i = 0; i < n; i++) {
		if (i)
			printf(" ");
		printf("%c%d", c[i].suit_, c[i].num_);
	}
	printf("\n");
}

void swap(card_t *x, card_t *y) {
	card_t tmp;

	tmp = *x;
	*x = *y;
	*y = tmp;
}

void selectionSort(card_t *C, int n) {
	int i = 0;
	int j = 0;
	int minj = 0;

	card_t tmp;
	
	for (i = 0; i < n; i++) {
		minj = i;
		
		for (j = i; j < n; j++) {
			if (C[j].num_ < C[minj].num_)
				minj = j;
		}

		swap(&C[i], &C[minj]);
	}
}

void bubbleSort(card_t *C, int n) {
	int i = 0;
	int j = 0;

	for (i = 0; i < n; i++) {
		for (j = n - 1; j > i; j--) {
			if (C[j].num_ < C[j - 1].num_)
				swap(&C[j], &C[j - 1]);
		}
	}

}

int isStable(card_t cBubble[], card_t cSelection[], int n) {
	int i = 0;

	for (i = 0; i < n; i++) {
		if (cBubble[i].suit_ != cSelection[i].suit_)
			return FALSE;
	}

	return TRUE;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n,m;
    cin >> n >> m;
    int a[m];
    rep(i,m)cin >> a[i];
    int sum = 0;
    rep(i,m){
        sum += a[i];
    }
    if(sum > n)cout << -1 << endl;
    else cout << n-sum << endl;
    return 0;
}


Measured memory_bytes: 3676
def main():
  s = input()
  if int(s[0:4])<=2018:
    print( "Heisei" )
  elif int(s[0:4])==2019:
    if int(s[5:7])<=4:
      print( "Heisei" )
    else:
      print( "TBD" )
  else:
      print( "TBD" )
  
main()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
//errichto
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()

void boost(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int N=1e4+4;

ll dp[2*N];

struct Node{
	int w,s,v;
}arr[N];

bool comp(Node& n1,Node &n2){
	return n1.w+n1.s<n2.w+n2.s;
}

void solve(){
	int n;
	cin>>n;
	fr(i,0,n){
		cin>>arr[i].w>>arr[i].s>>arr[i].v;
	}
	sort(arr,arr+n,comp);
	fr(i,0,n){
		fri(j,arr[i].s,0){
			dp[arr[i].w + j]=max(dp[arr[i].w + j],dp[j]+arr[i].v);
		}
	}
	ll ans=*max_element(dp,dp+2*N);
	cout<<ans<<endl;
	return;
}

int main()
{
	boost();
	
	int tc=1;
	//cin>>tc;
	while(tc--)
		solve();
	return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

int main()
{
	string s, t;
	cin >> s >> t;
	int maxv = 0;
	for (int i = 0; i <= s.size() - t.size(); i++) {
		int count = 0;
		for (int j = 0; j < t.size(); j++) {
			if (s[i + j] == t[j]) count++;
		}
		maxv = max(maxv, count);
	}
	cout << t.size() - maxv << endl;
}


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

int main() {
    double r;
    cin >> r;
    double pi = 3.14159265;

    double ans = 2.0 * pi * r;

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


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;

void test_case(){
    
}

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL);
    
    string s; cin >> s;
    int n = s.length();
    
    int q;
    cin >> q;
    
    string left = "";
    string right = "";
    
    int type, f, p = 0; char c;
    while(q--){
        cin >> type;
        if(type == 1){
            p++;
        }
        else{
            cin >> f >> c;
            if( f == 1){
                if( p%2 == 0){
                    left += c;
                }
                else{
                    right += c;
                }
            }
            else{
                if( p%2 == 0){
                    right += c;
                }
                else{
                    left  += c;
                }
            }    
        }
        
    }
    string res;
    
    if( p %2 == 1){
         reverse(right.begin(), right.end());
         reverse( s.begin(), s.end());
         res = right + s + left;
    }
    else{
         reverse(left.begin(), left.end());
         res = left + s + right;
    } 
    cout<<res<<endl;
    
    
	return 0;
}






Measured memory_bytes: 1300
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);

		String str;
		while((str=br.readLine())!=null){
			String[] sp = str.split(" ");

			int h = Integer.parseInt(sp[0]);
			int r = Integer.parseInt(sp[1]);

			if(h + r == 0){
				System.out.println(0);
			} else if(h + r > 0){
				System.out.println(1);
			} else{
				System.out.println(-1);
			}
		}
	}
}

Measured memory_bytes: 24408
#include <iostream>
#include <vector>
#include <numeric>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
using namespace std;
template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }
const int l  = 60 * 60 * 24;
const int l3 = 60 * 60 * 3 + 1;
int main() {
    int n; cin >> n;
    vector<int> cnt(l);
    for (int t = 0; n --; ) {
        int a, b; cin >> a >> b;
        t += a;
        t %= l;
        cnt[t] += 1;
        t += b;
    }
    int ans = 0;
    int acc = accumulate(cnt.begin(), cnt.begin() + l3, 0);
    repeat (t,l) {
        acc += - cnt[t] + cnt[(t + l3) % l];
        setmax(ans, acc);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
import numpy as np

def calc(i,x):
    if i ==0:
        return int((x % 4 == 1) or (x % 4 == 2))
    else:
        return int((x % (2**(i+1)) >= 2**i) and (x % 2 == 0))

def main():
    N,A,B,C = map(int, input().split())
    
    l = [int(input()) for i in range(N)]
    
    num = 4**N
    cre = 5000
    
    for i in range(num):
        num_A = 0
        num_B = 0
        num_C = 0
        new_cre_A = 0
        new_cre_B = 0
        new_cre_C = 0
        s = i
        for m in range(N):
            num_A += int(s % 4 == 1)
            num_B += int(s % 4 == 2)
            num_C += int(s % 4 == 3)
            s = s // 4
            #print(num_A)
        #print(num_A,num_B,num_C)
        #exit()
        s = i
        if num_A > 0 and num_B > 0 and num_C > 0:
            for j in range(N):
                new_cre_A += l[j]*int(s % 4 == 1)
                new_cre_B += l[j]*int(s % 4 == 2)
                new_cre_C += l[j]*int(s % 4 == 3)
                s = s // 4
                
            new_cre_A = abs(new_cre_A - A) + (num_A-1) * 10
            new_cre_B = abs(new_cre_B - B) + (num_B-1) * 10
            new_cre_C = abs(new_cre_C - C) + (num_C-1) * 10
            new_cre_A = new_cre_A + new_cre_B + new_cre_C
            #print(new_cre_A,cre)
            #exit()
            if cre > new_cre_A:
                cre = new_cre_A

    print(cre)
    
main()

Measured memory_bytes: 12512
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
 
int main()
{
  string s;
  cin >> s;
  cout << ((s == "ARC") ? "ABC" : "ARC")<< endl;
  return 0;
}

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

int powmod(ll x, ll y){
    ll ans=1;
    rep(i,y){
        ans=ans*x%mod;
    }
    return ans;
}

int main(){
  int n;
  cin >> n;
  ll ans=powmod(10,n)-powmod(9,n)-powmod(9,n)+powmod(8,n);
  ans%=mod;
  ans=(ans+mod)%mod;
  cout << ans << endl;
}

Measured memory_bytes: 3624
n, m = gets.chop.split(' ').map(&:to_i)

a = Array.new(n).map{Array.new(m,0)}
0.step n-1 do |i|
  a[i] = gets.chop.split(' ').map(&:to_i)
end

b = Array.new(m,0)
0.step m-1 do |j|
  b[j] = gets.chop.to_i
end

0.step n-1 do |ni|
  tmp = 0
  0.step m-1 do |mj|
    tmp += a[ni][mj] * b[mj]
  end
  puts tmp
end



Measured memory_bytes: 8924
#include <iostream>
using namespace std;
int a[3][110],f[3][110],n;
int main()
{
	cin>>n;
	for(int i=1;i<=2;i++)
		for(int j=1;j<=n;j++)
			cin>>a[i][j];
	for(int i=1;i<=2;i++)
		for(int j=1;j<=n;j++)
			f[i][j]=max(f[i-1][j]+a[i][j],f[i][j-1]+a[i][j]);
	cout<<f[2][n]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////
ll N, K;
ll fac[510000], finv[510000], inv[510000];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < 510000; ++i) {
		fac[i] = fac[i - 1] * i%INF;//i!のmod INF
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}

ll ans(int k,int i) {
	ll key = COM(k - 1, i - 1);
	ll key2 = COM(N - k - 1, i - 2) + 2 * COM(N - k - 1, i - 1) + COM(N - k - 1, i);
	return key * key2%INF;
}
int main() {
    cin >> N >> K;
	COMinit();
	for (int i = 1; i <= K; ++i) {
		if (i == 1) {
			cout << N - K + 1 << endl;
		}
		else {
			cout << ans(K, i) << endl;
		}
	}
	return 0;
}


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

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

  vector<pair<int, int>> AB(N);
  for(auto& ab: AB){
    cin >> ab.first >> ab.second;
  }
  sort(AB.begin(), AB.end());

  int ans = 0;
  // dp[n][t] := With AB[0: n) and within t minutes,
  // one can eat dp[n][t] delicious food
  // ans = dp[n][T - 1] + B[n - 1]
  vector<vector<int>> dp(N + 1, vector<int>(T, 0));
  for(int n = 0; n < N; n++){
    ans = max(ans, dp[n][T - 1] + AB[n].second);
    for(int t = 0; t < T; t++){
      int a = AB[n].first, b = AB[n].second;
      dp[n + 1][t] = dp[n][t];
      if(t - 1 >= 0){
        dp[n + 1][t] = max(dp[n + 1][t], dp[n][t - 1]);
      }
      if(t - a >= 0){
        dp[n + 1][t] = max(dp[n + 1][t], dp[n][t - a] + b);
      }
    }
  }
  cout << ans << endl;
   

}


Measured memory_bytes: 35584
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#define _MATH_DEFINES_DEFINED
using namespace std;
int n;
int a[10010];
double d[1001][1001],xx[1001],yy[1001],ans;
void dooo()
{
	for(int i=1;i<=n;i++)a[i]=i;
	do{
		for(int i=1;i<=n-1;i++)
		{
			ans+=d[a[i]][a[i+1]];
		}
	}while(next_permutation(a+1,a+1+n));
	for(int i=1;i<=n;i++)ans/=(double)i;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		cin>>xx[i]>>yy[i];	
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			d[i][j]=sqrt((xx[i]-xx[j])*(xx[i]-xx[j])+(yy[i]-yy[j])*(yy[i]-yy[j]));			
		}
	}
	dooo();
	printf("%.10lf",ans);
	return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
  
   input = input.split("\n");
   var NK = input[0].split(" ");
  var N= parseInt(NK[0], 10);
 var K= parseInt(NK[1], 10);
 
 
  // var S = input[1].split(" ");
   var S = input[1];
 //  console.log(N,K,S);
   var K = K - 1;
   
var p = S[K];
//console.log(p);
if( p == 'A'){var p = 'a';}
             else if ( p == 'B'){var p = 'b';}
                     else {var p = 'c';}
                     
 //console.log(
 var SS = S.substr(0,K) + p + S.substr(K+1);
 
 //var SS= S.replace(S[K],p);
  console.log(SS);                  

  
}
 
  
  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  

Measured memory_bytes: 7372
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<10)
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll n, r=0, g=0, b=0;
  ll count=0;
  string s;

  cin>>n>>s;

  for(ll i=0;i<n;i++){
    if(s[i]=='R')r++;
    if(s[i]=='G')g++;
    if(s[i]=='B')b++;
  }
  for(ll dist=0;dist<=(n-3)/2;dist++){
    for(ll left=0;left<n;left++){
      if(left+2+dist*2>=n)break;
      else{
        if(s[left]!=s[left+dist+1]&&s[left+dist+1]!=s[left+dist+1+dist+1]&&s[left]!=s[left+dist+1+dist+1])count++;
      }
    }
  }

  cout<<r*g*b-count;

  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const int n=10;
int a[n][n];

bool f(string s){
	int x=0;
	for(int i=0;i<5;i++) x=a[x][s[i]-'0'];
	return x==0;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(1){
		string s;
		int x;
		cin>>s>>x;
		int n=s.size(),t=s[0]-'0';
		for(int i=1;i<n;i+=2){
			if(s[i]=='+') t+=s[i+1]-'0';
			else t*=s[i+1]-'0';
		}
		bool b1=0,b2=0;
		if(x==t) b1=1;
		t=0;
		s+='+';
		int tmp=1;
		for(int i=0;i<=n;i+=2){
			if(s[i+1]=='+'){
				tmp*=s[i]-'0';
				t+=tmp;
				tmp=1;
			}
			else{
				tmp*=s[i]-'0';
			}
		}
		if(x==t) b2=1;
		if(b1&&b2) cout<<'U'<<endl;
		if(b1&&!b2) cout<<'L'<<endl;
		if(!b1&&b2) cout<<'M'<<endl;
		if(!b1&&!b2) cout<<'I'<<endl;
		break;
	}
}


Measured memory_bytes: 3228
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int i = 3;
		while(i <= n) {
			if(i % 3 == 0 || String.valueOf(i).contains("3")) {
				Integer.valueOf(i);
				System.out.printf(" %d", i);
			}
			i++;
		}
		System.out.println();
	}
}

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

#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
int M[N][N];
void initialize(){
  int i;
  for(i=0;i<N;i++){
    row[i] = FREE;
    col[i] = FREE;
  }
  for(i=0;i<2*N-1;i++){
    dpos[i]=FREE;
    dneg[i]=FREE;
  }
}

void printBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(M[i][j]){
	if(row[i] != j)return;
      }
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j){
	printf("Q");
      }
      else {
	printf(".");
      }
    }
    printf("\n");
  }
}

void recursive(int i){
  int j;
  if(i==N){
    printBoard();
    return;
  }
  
  for(j=0;j<N;j++){
    if(NOT_FREE == col[j] || NOT_FREE == dpos[i+j] || NOT_FREE == dneg[i-j+N-1])continue;
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    recursive(i+1);
    row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }

}

int main(){
  int i,r,j,a,b;
  initialize();

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      M[i][j] = 0;
    }
  }
    scanf("%d",&r);
    for(i=0;i<r;i++){
      scanf("%d%d",&a,&b);
      M[a][b] = 1;
    }
    recursive(0);
    return 0;
  
}

  
    
    
    
    



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

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define watch(x);       cout << "\n" <<  #x << " is: " << x << "\n";
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd(a,b)
#define sq(a)           (a)*(a)
#define loop(i,a,b)     for (ll i = a; i <= b; i++)
#define rloop(i,a,b)    for (int i = a; i >= b; i--)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)

int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        ll n;
        cin>>n;
        ll a[n];
        map<ll,ll>mp;

        loop(i,0,n-1)
        {
            cin>>a[i];
            mp[a[i]]++;
        }
        ll ans=0;
        for(ll i=0;i<sz(mp);i++)
             ans+=mp[i]*(mp[i]-1)/2;
        loop(i,0,n-1)
        {
            ll p=mp[a[i]];
            ll x=((p-1)*(p-2)/2)-(p*(p-1)/2);
            cout<<ans+x;
            nl;
        }

    }
    return 0;
}


Measured memory_bytes: 17704