akhauriyash/Code-Regression huggingface dataset:
// Polygon Area
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_A&lang=jp
// 
// 

#include <iostream>
#include <complex>
#include <cmath>
#include <cstdio>

using namespace std;
typedef std::complex<double> xy_t;

int N, x, y;
xy_t P[110];

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }

double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }

xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }

double calc_area(xy_t A, xy_t B, xy_t C){ //面積を計算
    xy_t a = B - A, b = C - A; //ベクトルの始点を原点に移動
    double area = cross_product(a, b)/2.0; //外積の値の半分
    return area;
}

int main(){
    cin >> N;

    for(int i = 0; i < N; ++i){
        cin >> x >> y;
        P[i] = xy_t(x, y);
    }  

    double sum = 0.00000;

    xy_t A = P[0];

    for(int i = 0; i < (N-2); ++i){
        xy_t B = P[i+1], C = P[i+2];
        sum += calc_area(A, B, C);
    }

    printf("%.1f\n", sum);
}


Measured memory_bytes: 3192
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


ll gcd(ll x,ll y){
  return y==0? x:gcd(y,x%y);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A,B,C,D;cin>>A>>B>>C>>D;
  cout <<max(0,min(B,D)-max(A,C))<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;++i)
using namespace std;
int main(){
	int a[190],c=0,n;
	r(i,1,190)a[c++]=i*i;
	while(cin>>n,n){
		int c=0;
		r(i,0,n+1){
			if(a[i]>n)break;
			if(a[i]==n)c++;
			r(j,i,n+1){
				if(a[i]+a[j]>n)break;
				if(a[i]+a[j]==n)c++;
				r(k,j,n+1){
					if(a[i]+a[j]+a[k]>n)break;
					if(a[i]+a[j]+a[k]==n)c++;
					r(l,k,n+1){
                       if(a[i]+a[j]+a[k]+a[l]>n)break;
					   if(a[i]+a[j]+a[k]+a[l]==n)c++;
					}
				}
			}
		}
		cout<<c<<endl;
	}
}

Measured memory_bytes: 3084
import * as fs from "fs";
const input = fs.readFileSync("/dev/stdin", "utf-8");

function Main(input: string) {
  const [NM, ...abcd] = input.split("\n");
  const [N] = NM.split(" ").map((str) => Number(str));
  const AB = abcd.slice(0, N);
  const CD = abcd.slice(N, -1);
  AB.forEach((ab) => {
    const [a, b] = ab.split(" ").map((str) => Number(str));
    const distances = CD.map((cd) => {
      const [c, d] = cd.split(" ").map((str) => Number(str));
      const tmp = Math.abs(a - c) + Math.abs(b - d);
      return tmp;
    });
    const min = distances.reduce((x, y) => Math.min(x, y));
    console.log(distances.indexOf(min) + 1);
  });
}

Main(input);


Measured memory_bytes: 33680
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var S = parseInt(input[0].split(" ")[1]);
  var A = input[1].split(" ").map(i => parseInt(i)).sort(function(a,b){return a-b});
  var mod = 998244353n;
  //var mod = 7n
  var memo = new Array(S);
  for(var i=0;i<S+1;i++){
    var memosub = [i,0n];
    memo[i]=memosub;
  }
  function modpow(a, n, mod) {
    res = 1n;
    while (n > 0) {
        if (n & 1n) res = res * a % mod;
        a = a * a % mod;
        n >>= 1n;
    }
    return res;
  }
  function modinv(a, mod) {
    return modpow(a, mod - 2n, mod);
  }
  var inv = modinv(2n,mod);
  var y = 1n;
  for(var i=0;i<N-1;i++){
    y = (y * 2n)%mod;
  }
  memo[0] = [0,1n];
  var ans = 0n;
  for(var i=0;i<N;i++){
    for(var j=memo.length-1;j>=0;j--){
      if(memo[j][0]+A[i]<=S&&j==0){
        memo[j+A[i]][1]=(memo[j+A[i]][1]+y)%mod;
      }else if(memo[j][0]+A[i]<=S){
        memo[j+A[i]][1]=(memo[j+A[i]][1]+(memo[j][1]*inv)%mod)%mod;
      }
    }
  }
  var ans = memo[memo.length-1][1].toString();
  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 47976
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int n,m[100001],k;
int main()
{
	cin>>n;
	k=2*n-2;
	int a=0,b=0,c=0;
	for(int i=1;i<=n;i++)
	{
		cin>>m[i];
		if(m[i]%4==0)
		{
			k=k-2;
			c++;
		}
		else if(m[i]%2==0)
		{
			k=k-1;
			a++;
		}
		else
		{
			b++;
		}
	}
	if(a<=b&&a!=0)
	{
		k++;
	}
	if(k<n)
	{
		cout<<"Yes";
	}
	else 
	{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int q = in.nextInt();
        String[] line = new String[n];
        Queue tasks = new Queue();
        in.nextLine();
        for (int i = 0; i < n; i++) {
            line[i] = in.nextLine();
            tasks.enqueue(new Task(line[i].split(" ")[0], Integer.parseInt(line[i].split(" ")[1])));
        }
        int costTime = 0;
        int totalTime = 0;
        while (tasks.head != tasks.tail) {
            Task current = tasks.dequeue();
            costTime = Math.min(q, current.time);
            current.time -= costTime; // 计算剩余的所需时间
            totalTime += costTime; // 累计已经过的时间
            if(current.time > 0) {
                tasks.enqueue(current);
            }
            else {
                System.out.println(current.name + " " + totalTime);
            }
        }
    }
}

class Task {
    public String name;
    public int time;

    public Task(String name, int time) {
        this.name = name;
        this.time = time;
    }
}

class Queue {
    public int head;
    public int tail;
    private Task[] queue;
    private int len = 1000001;

    public Queue() {
        this.head = this.tail = 0;
        this.queue = new Task[this.len];
    }

    public boolean isFull() {
        return (this.head == (this.tail + 1) % (this.len));
    }

    public boolean isEmpty() {
        return (this.head == this.tail);
    }

    public void enqueue(Task task) throws Exception {
        if (isFull()) {
            throw (new Exception("上溢出"));
        }
        this.queue[this.tail] = task;
        if (this.tail + 1 == this.len) {
            this.tail = 0;
        } else {
            this.tail++;
        }
    }

    public Task dequeue() throws Exception {
        if (isEmpty()) {
            throw (new Exception("下溢出"));
        }
        Task task = this.queue[this.head];
        if (this.head + 1 == this.len) {
            this.head = 0;
        } else {
            this.head++;
        }
        return task;
    }
}


Measured memory_bytes: 113936
#include <iostream>
using namespace std;
 
int gcd(int x, int y) {
    int amari;
    while(y != 0) {
        amari = x % y;
        x = y;
        y = amari;
    }
    return x;
}
 
int lcm(int x, int y) {
    int g = gcd(x, y);
    return x/g*y;
}

int main() {
    int a, b;
    while(true){
        cin >> a >> b;
        if (std::cin.eof()) {
            break;
        }
        cout << gcd(a, b) << ' ' << lcm(a, b) << endl;
    }
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
void InfiniteCoins() {
	int N, A;
	cin >> N;
	cin >> A;
	cout << ((N % 500) > A ? "No" : "Yes") << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

const double eps = 1e-10;
inline bool eq(double a, double b) { return fabs(a - b) < eps; }
const double pi = acos(-1);

struct Point {
    double x, y;
    Point() {}
    Point(double x, double y) : x(x), y(y) {}
    Point operator+(const Point &p) { return Point(x + p.x, y + p.y); }
    Point operator-(const Point &p) { return Point(x - p.x, y - p.y); }
    Point operator*(double k) { return Point(x * k, y * k); }
    Point operator/(double k) { return Point(x / k, y / k); }
};
Point rotate(double theta, const Point &p) {
    return Point(cos(theta) * p.x - sin(theta) * p.y, sin(theta) * p.x + cos(theta) * p.y);
}
double radian_to_degree(double r) { return (r * 180.0 / pi); }
double degree_to_radian(double d) { return (d * pi / 180.0); }

struct Line {
    Point a, b;
    Line() {}
    Line(Point a, Point b) : a(a), b(b) {}
    Line(double A, double B, double C) { // Ax + By = C
        if (eq(A, 0))
            a = Point(0, C / B), b = Point(1, C / B);
        else if (eq(B, 0))
            a = Point(C / A, 0), b = Point(C / A, 1);
        else
            a = Point(0, C / B), b = Point(C / A, 0);
    }
};

struct Circle {
    Point p;
    double r;
    Circle() {}
    Circle(Point p, double r) : p(p), r(r) {}
};
double norm(const Point &a) { return a.x * a.x + a.y * a.y; }
double abs(const Point &a) { return sqrt(norm(a)); }
double cross(const Point &a, const Point &b) { return a.x * b.y - a.y * b.x; }
double dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; }

Point projection(Line l, Point p) {
    double t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
    return l.a + (l.a - l.b) * t;
}
Point reflect(Line l, Point p) { return p + (projection(l, p) - p) * 2; }

int main() {
    Point p1, p2;
    cin >> p1.x >> p1.y >> p2.x >> p2.y;
    Line base(p1, p2);
    int q;
    cin >> q;
    vector<Point> r(q);
    for (int i = 0; i < q; ++i) {
        cin >> r[i].x >> r[i].y;
    }
    cout << fixed << setprecision(10);
    for (int i = 0; i < q; ++i) {
        Point ret = projection(base, r[i]);
        cout << ret.x << " " << ret.y << "\n";
    }
}


Measured memory_bytes: 3312
#include <iostream>

using namespace std;

int main(int argc, char const* argv[])
{
	for( int i = 1;i <= 9;i++ ){
		for( int j = 1;j <= 9;j++ ){
			cout << i << 'x' << j << '=' << i * j << endl;
		}
	}

	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <queue>
#include <iomanip>
#include <iterator>

#define MOD 1000000007
#define INF 1000000001

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


template <class T>
ostream &operator<<(ostream &o, const vector<T>&obj) {
    o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U>&obj) {
    o << "(" << obj.first << ", " << obj.second << ")"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const queue<T>&obj) {
    queue<T> obj_cp = obj;
    bool first = true;
    o << "{";
    while (!obj_cp.empty()) { o << (!first ? ", " : "") << obj_cp.front(); obj_cp.pop(); first = false; }
    o << "}"; return o;
}

void print() {
    cout << "\n";
}
template<class Head, class... Body>
void print(Head head, Body... body) {
    cout << head << " ";
    print(body...);
}


int H, W, K;
vector<int> pattern_nums;

void init_pnums() {
    pattern_nums.resize(W);
    pattern_nums[0] = 1;
    pattern_nums[1] = 2;
    for (int i = 0; i <= W-2; ++i) {
        pattern_nums[i+2] = pattern_nums[i] + pattern_nums[i+1];
    }
}

int get_pnum(int h) {
    if (h < 0) return 1;
    return pattern_nums[h];
}

int main(int argc, char const *argv[]) {
    cin >> H >> W >> K;
    init_pnums();
    // print(pattern_nums);

    vector<vector<ull>> dp(H+1, vector<ull>(W, 0));
    dp[0][0] = 1;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            dp[i+1][j] = (dp[i][j] * get_pnum(j-1) * get_pnum(W-j-2)) % MOD;
            // print(i, j, "center", dp[i][j] * get_pnum(j-1) * get_pnum(W-j-2));
            if (j > 0) {
                dp[i+1][j] = (dp[i+1][j] + dp[i][j-1] * get_pnum(j-2) * get_pnum(W-j-2)) % MOD;
                // print(i, j, "left", dp[i][j-1] * get_pnum(j-2) * get_pnum(W-j-2));
            }
            if (j < W-1) {
                dp[i+1][j] = (dp[i+1][j] + dp[i][j+1] * get_pnum(j-1) * get_pnum(W-j-3)) % MOD;
                // print(i, j, "right", dp[i][j+1] * get_pnum(j-1) * get_pnum(W-j-3));
            }
        }
        // print(i+1, dp[i+1]);
    }

    cout << dp[H][K-1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
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 if (b=='G'){
    cout<<'C';
  }
}

Measured memory_bytes: 3040
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long y = sc.nextLong();

        sc.close();

        int cnt = 0;

        while (true) {
            if (x > y) {
                break;
            }
            cnt++;
            x *= 2;
        }

        System.out.println(cnt);

    }

}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,i;
    cin>>n;
    int a[n];
    for (i=0;i<n;i++)
        cin>>a[i];
    cout<<*max_element(a,a+n)-*min_element(a,a+n)<<endl;
}

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

int main() {
  int N;
  cin >> N;
  bool b = false;
  
  for (int i = 0; i < 26; i++) {
  	for (int j = 0; j < 16; j++) {
    	int total = 4 * i + 7 * j;
        if(total == N) {
        	b = true;
          break;
        }
    }
  }
  if (b) {
  	cout << "Yes" << endl;
  }
  else {
  	cout << "No" << endl;
  } 
}



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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n, y;
    cin>>n>>y;
    y /= 1000;
    ll ans = 0;
    REP(i,n+1) REP(j,(n+1-i)){
        ll ab = (10*i)+(5*j);
        int left = n-i-j;
        ll temp = y - ab;
        if(temp < 0) continue;
        else if(temp == left) {
            printf("%d %d %d\n",i,j,left);
            return 0;
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

using namespace std;

long long mod = 1e9 + 7;

int d, n, i, j, k;

vector<int> v;
vector< vector<long long> > x[2];
string s;

int main() {
    cin >> s >> d;
    n = s.size();
    v.resize(n);
    for (i = 0; i < n; i++) {
        v[i] = s[i] - '0';
    }
    x[0].resize(n, vector<long long>(d, 0));
    x[1].resize(n, vector<long long>(d, 0));
    for (i = 0; i < v[0]; ++i) {
        ++x[0][0][i % d];
    }
    ++x[1][0][v[0] % d];
    for (i = 1; i < n; ++i) {
        for (j = 0; j < d; ++j) {
            for (k = 0; k < 10; ++k) {
                x[0][i][(j + k) % d] += x[0][i - 1][j];
                x[0][i][(j + k) % d] %= mod;
            }
            for (k = 0; k < v[i]; ++k) {
                x[0][i][(j + k)%d] += x[1][i - 1][j];
                x[0][i][(k + k)%d] %= mod;
            }
            x[1][i][(j + v[i]) % d] += x[1][i - 1][j];
            x[1][i][(j + v[i]) % d] %= mod;
        }
    }
    cout << (x[0][n - 1][0] + x[1][n - 1][0] + mod - 1) % mod << "\n";
    return 0;
}


Measured memory_bytes: 16768
import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))
MAXBITS = 40
bits = np.ndarray((N, MAXBITS), dtype=int)
for i in range(N):
    a = A[i]
    bits[i] = np.array([(a >> j) & 1 for j in range(MAXBITS-1, -1, -1)])
sm = bits[0]
for b in bits[1:]:
    sm += b
lower = False
Kbits = np.array([(K >> j) & 1 for j in range(MAXBITS-1, -1, -1)])
ans = 0
for i in range(MAXBITS):
    ones = sm[i]
    zeros = N-sm[i]
    base = 2**(MAXBITS-i-1)
    bit = 0
    if ones >= zeros:
        bit = 0
    elif lower or Kbits[i] == 1:
        bit = 1
    if Kbits[i] > bit:
        lower = True
    ans += ones*base if bit == 0 else zeros*base
print(ans)


Measured memory_bytes: 63696
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
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<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vi a;

int main(){
	cin>>n;
	a=vi(n);
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a.begin(),a.end());
	vp b(n-1);
	for(int i=0;i<n-1;i++){
		int sa=abs(a[n-1]/2-a[i]);
		if(n%2==1&&a[i]>a[n-1]/2) sa--;
		b[i]={sa,a[i]};
	}
	sort(b.begin(),b.end());
	cout<<a[n-1]<<' '<<b[0].second<<endl;
}

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

#define max 30
#define NIL -1
typedef struct {
 int node, left, right, depth, parent, height, sub, degree;
}Tree;

Tree tree[max];


int getsib(int i) 
{
    if (tree[i].parent == NIL) return NIL;
    if (tree[tree[i].parent].left != i && tree[tree[i].parent].left != NIL)
    return tree[tree[i].parent].left;
    if (tree[tree[i].parent].right != i && tree[tree[i].parent].right != NIL)
    return tree[tree[i].parent].right;
    return NIL;
}


void getdepth(int i, int j) 
{
    if (i == NIL) return;
    tree[i].depth = j;
    getdepth(tree[i].left, j + 1);
    getdepth(tree[i].right, j + 1);
}

int getheight(int i) 
{
    int h1 = 0, h2 = 0;
    if (tree[i].left != NIL)
     h1 = getheight(tree[i].left) + 1;
    if (tree[i].right != NIL)
    h2 = getheight(tree[i].right) + 1;
    return tree[i].height = (h1 > h2 ? h1 : h2);
}
void printing(int i, int n)
{
    for (i = 0; i<n; i++) 
{
    printf("node %d: ", i);
  printf("parent = %d, ", tree[i].parent);
  printf("sibling = %d, ", getsib(i));
  int degree = 0;
  if (tree[i].left != NIL) degree++;
  if (tree[i].right != NIL) degree++;
  printf("degree = %d, ", degree);
  printf("depth = %d, ", tree[i].depth);
  printf("height = %d, ", tree[i].height);

  if (tree[i].parent == NIL) 
  {
      printf("root\n");
  }
  else if (tree[i].left == NIL && tree[i].right == NIL)
   {
       printf("leaf\n");
  }
  else
  {
      printf("internal node\n");
  }
  
 }

}


int main() {
 int i, n;
 int x;
 scanf("%d", &n);

 //set all to NIL
 for (i = 0; i<n; i++) {
  tree[i].node = tree[i].left = tree[i].right =
   tree[i].depth = tree[i].parent = tree[i].height =
   tree[i].sub = tree[i].degree = NIL;
 }

 //scaning
 int node, left, right;
 for (i = 0; i<n; i++) {
  scanf("%d %d %d", &node, &left, &right);
  tree[node].left = left;
  tree[node].right = right;
  if (left != -1) tree[left].parent = node;
  if (right != -1) tree[right].parent = node;
 }

 
 for (int i = 0; i<n; i++)
  if (tree[i].parent == NIL)  x=i;
 getdepth(x ,0);
 getheight(x);

 printing(i,n);
 

 return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 105;
int a[N];
int res = 0,n;
void insertionSort()
{
	for(int i = 0;i < n;++i)
	{
		int minv = a[i],pos = i;
		for(int j = i+1;j < n;++j)
		{
			if(a[j] < minv)
				minv = a[j],pos = j;
		}
		if(minv != a[i])
			swap(a[pos],a[i]),++res;
	}
}
int main()
{
	cin >> n;
	for(int i = 0;i < n;++i)
		cin >> a[i];
	insertionSort();
	for(int i = 0;i < n;++i)
	{
		cout << a[i];
		if(i != n-1)
			cout << " ";
	}
	cout <<  endl <<res << endl;
	return 0;
} 


Measured memory_bytes: 3108
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n;
    cin>>n;
    long long temp=n;
    long long cnt=0;
    while(temp){
        temp/=2;
        ++cnt;
    }//ff
    long long ans=0;
    ans=2*pow(2,cnt-1)-1;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    string s, t;
    cin >> s >> t;
    if(t.substr(0,s.size())==s)puts("Yes");
    else puts("No");
}


Measured memory_bytes: 3636
r, c, k = gets.split.map(&:to_i)

v = Hash.new{|h,k| h[k] = {}}
k.times do
    i, j, vv = gets.split.map(&:to_i)
    v[i][j] = vv
end

dp = Array.new(c+1) {Array.new(4,0)}
s = Array.new(c+1) {Array.new(4,0)}

1.upto(r) do |i|
    1.upto(c) do |j|
        vv = v[i][j]

        dp[j][0] = dp[j-1][0] if dp[j][0] < dp[j-1][0]
        dp[j][1,3] = dp[j-1][1,3]
        3.downto(1) {|m| dp[j][m] = dp[j][m-1] + vv if dp[j][m] < dp[j][m-1] + vv} if vv

        s[j][0] = dp[j].max
    end
    dp, s = s, dp
end

p dp[c][0]


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long

int main() {
    fastio;
    int n, d;
    cin >> n >> d;
    vector<vector<int>> v(n, vector<int> (d));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < d; ++j) {
            cin >> v[i][j];
        }
    }
    int c = 0;
    for (int fir = 0; fir < n - 1; fir++) {
        for (int sec = fir + 1; sec < n; ++sec) {
            double ans = 0;
            for (int start = 0; start < d; ++start) {
                ans += pow(v[fir][start] - v[sec][start], 2);
            }
            ans = sqrt(ans);
            if (floor(ans) == ans) c++;
        }
    }
    cout << c;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int id = 1;
map<string, int> mp;
map<pair<int, int>,int> freq;
int idx(string &s) {
	int &ret = mp[s];
	if (ret)
		return ret;
	ret = id++;
	return ret;
}
ll res = 0;
void gen(string s, bool rev) {
	for (int mask = 0; mask < (1 << s.size()); ++mask) {
		string a, b;
		for (int i = 0; i < s.size(); ++i)
			if ((mask >> i) & 1)
				a += s[i];
			else
				b += s[i];
		if (rev) {
			reverse(a.begin(), a.end());
			reverse(b.begin(), b.end());
			res += freq[{idx(a), idx(b)}];
		}else
			++freq[{idx(a), idx(b)}];
	}
}
int main()
{
	int n;
	scanf("%d", &n);
	string s;
	cin >> s;
	gen(s.substr(0, n), false);
	gen(s.substr(n, n), true);
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 79872
#include<bits/stdc++.h>
using namespace std;
#define rg register
#define rep(i,a,b) for (rg int i=(a);i<=(b);i++)
#define per(i,a,b) for (rg int i=(b);i>=(a);i--)
#define pb push_back
#define lowbit(x) (x&(-x))
#define replow(i,a,b) for(rg int i = (a);i<=(b);i+=lowbit(i))
#define perlow(i,a,b) for(rg int i = (b);i>=(a);i-=lowbit(i))
#define mk make_pair
#define VI vector<int>
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define fi first
#define se second
#define il inline
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define inf 0x3f3f3f3f
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<15,stdin),p1==p2)?EOF:*p1++)
char buf[1<<15],*p1 = buf,*p2 = buf;
inline ll read(){
    #define num ch-'0'
    char ch;bool flag=0;ll res;
    while(!isdigit(ch=getc()))
    (ch=='-')&&(flag=true);
    for(res=num;isdigit(ch=getc());res=res*10ll+num);
    (flag)&&(res=-res);
    #undef num
    return res;
}
inline void write(ll x){
	if (x < 0) x = ~x + 1ll, putchar('-');
	if (x > 9) write(x / 10ll);
	putchar(x % 10ll + '0');
}
#define mid ((l + r)>>1)
#define ls (x<<1)
#define rs ((x<<1)|1)
#undef mid
#undef ls
#undef rs
void solve()
{
	ll n = read();
	ll lim = (ll)sqrt(n * 1.0);
	per(i,1,lim)
	{
		if(n % i == 0)
		{
			cout<<(i+n/i-2);
			break;
		}
	}
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("data.txt","r",stdin);
	#endif
//	int T = read();
//	while(T--)
	solve();
}

Measured memory_bytes: 3664
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	numSeq := GetArgs()
	BubbleSort(numSeq)
}

// GetArgs 数列の長さを表す整数 Nと数列を取得する
func GetArgs() []int {
	sc.Split(bufio.ScanWords)
	elmCnt := NextInt()

	var numSeq []int
	for i := 0; i < elmCnt; i++ {
		numSeq = append(numSeq, NextInt())
	}
	return numSeq
}

// NextInt 個々の数値を取得する
func NextInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

// BubbleSort バブルソートを実行する
func BubbleSort(numSeq []int) {
	flg := true
	exchangeCnt := 0
	for flg {
		flg = false
		for j := len(numSeq) - 1; j > 0; j-- {
			if numSeq[j] < numSeq[j-1] {
				tmp := numSeq[j]
				numSeq[j] = numSeq[j-1]
				numSeq[j-1] = tmp
				flg = true
				exchangeCnt++
			}
		}
	}
	OutputResult(numSeq, exchangeCnt)
}

// OutputResult ソート結果を出力する
func OutputResult(numSeq []int, exchangeCnt int) {
	for i, v := range numSeq {
		if i == len(numSeq)-1 {
			fmt.Printf("%d\n", v)
		} else {
			fmt.Printf("%d ", v)
		}
	}
	fmt.Println(exchangeCnt)
}



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

int A[20];
int x[20][20];
int y[20][20];

int main() {
  int N;
  scanf("%d", &N);

  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
    for (int j = 0; j < A[i]; ++j) {
      scanf("%d%d", &x[i][j], &y[i][j]);
    }
  }

  int ans = 0;
  // bit全探索
  for (int bits = 0; bits < (1 << N); ++bits) {
    bool is_consistent = true;

    for (int i = 0; i < N; i++)
      if ((bits >> i) & 1) {
        // シミュレートしている状態と各正直者の証言が整合しているか確認
        for (int j = 0; j < A[i]; j++) {
          if ((bits >> (x[i][j] - 1)) & 1) {
            // 正直者と仮定しているが、不親切と証言している場合は不整合
            if (y[i][j] == 0) is_consistent = false;
          } else {
            // 不親切と仮定しているが、正直者と証言している場合は不整合
            if (y[i][j] == 1) is_consistent = false;
          }
        }
      }

    if (is_consistent) ans = max(ans, (int)bitset<15>(bits).count());
  }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,a[51];
	int ans=0;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+n+1);
    for(int i=n;i>(n-k);i--)
    {
	ans+=a[i];
    }
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

#define int long long

/*************** using variables ***************/
int a, b, c;
int x, y;
/**********************************************/

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> a >> b >> c >> x >> y;
    
    LL ans = 0;
  /* 
    if(a + b >= c*2 && a >= c*2 && b >= c*2){
        ans += max(x, y) * (c*2);
    }else if(a + b >= c*2 && a >= c*2){
        ans += c*2 * x;
        ans += min(0LL, y-x) * b;
    }else if(a + b >= c*2 && b >= c*2){
        ans += c*2 * y;
        ans += min(0LL, x-y) * a;
    }else if(a + b >= c*2){
        ans += c*2 * min(x, y);
        if(x > y) ans += a*(x-y);
        else ans += b*(y-x);
    }else{
        ans = a*x + b*y;
    }
    */

    if(x > y){
        ans = min(min(a*x+b*y, c*x*2),c*y*2 + a*(x-y));
    }else{
        ans = min(min(a*x+b*y, c*y*2),c*x*2 + b*(y-x));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

int main()
{

        std::vector<int> vec;
        int a;

        for(int i = 0; i < 10; ++i)
        {
                std::cin >> a;
                vec.push_back(a);
        }

        std::sort(vec.begin(),vec.end());

        for(int i = 0; i < 3; ++i) std::cout << vec.at(9-i) << std::endl;

        return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int ll;

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

	int n, k, x, nn;
	cin >> n >> k;
	vector<int> d[n + 2];
	for (int i = 1; i <= k; ++i) {
		cin >> nn;
		for (int j = 0; j < nn; ++j) {
			cin >> x;
			d[x].pb(i);
		}
	}
	int ct = 0;
	for (int i = 1; i <= n; ++i) {
		if (d[i].size() == 0) ++ct;
	}
	cout << ct << '\n';
}



Measured memory_bytes: 3672
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt();
        Node sentinel = new Node(' ');
        Node [] a = new Node[n];
        Set<Node> set = new HashSet<>();
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            Node cur = sentinel;
            for (int j = s.length() - 1; j >= 0; j--) {
                boolean found = false;
                for (Node node: cur.children) {
                    if (s.charAt(j) == node.c) {
                        cur = node;
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    Node add = new Node(s.charAt(j));
                    add.parent = cur;
                    cur.children.add(add);
                    cur = add;
                }
            }
            a[i] = cur;
            set.add(cur);
        }
        long ans = 0;
        for (int i = 0; i < n; i++) {
            Node cur = a[i]; Set<Character> seen = new HashSet<>();
            while (cur != null) {
                for (Node child: cur.children) {
                    if (seen.contains(child.c) && set.contains(child) && child != a[i]) {
                        ans++;
                    }
                }
                seen.add(cur.c);
                cur = cur.parent;
            }
        }
        out.println(ans);
        out.close();
    }

    static class Node {
        char c; Node parent;
        ArrayList<Node> children;
        Node(char c) {
            this.c = c;
            children = new ArrayList<>();
        }
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

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

int n;
string s;

int K;
vector<string> res;

void dfs(string t) {
	if ((int)res.size() == K) return;
	bool ok = false;
	if (!t.empty()) {
		for (int i = 0; i + (int)t.size() <= n; i++) {
			if (s.substr(i, t.size()) == t) {
				res.push_back(t);
				ok = true;
				break;
			}
		}
	}
	else {
		ok = true;
	}
	if (!ok || (int)t.size() == 5) return;
	for (char c = 'a'; c <= 'z'; c++) {
		t.push_back(c);
		dfs(t);
		t.pop_back();
	}
}

int main()
{
	cin >> s >> K;
	n = s.size();
	dfs("");
	cout << res[K - 1] << endl;
	return 0;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
int c[220000];
int a[220000], b[220000];
vint G[220000];
int m[220000];
int h[220000];
map<int, int> mem[220000];
void dfs(int cur, int par) {
    rep(i, G[cur].size()) {
        if (G[cur][i] == par) { continue; }
        dfs(G[cur][i], cur);
        int k = h[G[cur][i]] - mem[G[cur][i]][c[cur]];
        m[c[cur]] += k * (k + 1) / 2;
        h[cur] += h[G[cur][i]];
        if (mem[G[cur][i]].size() > mem[cur].size()) { swap(mem[G[cur][i]], mem[cur]); }
        for (auto p:mem[G[cur][i]]) { mem[cur][p.first] += p.second; }
    }
    h[cur]++;
    mem[cur][c[cur]] = h[cur];
}
signed main() {
    cin >> N;
    rep(i, N) {
        cin >> c[i];
        c[i]--;
    }
    rep(i, N - 1) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    dfs(0, -1);
    rep(i, N) {
        int k = N - mem[0][i];
        m[i] += k * (k + 1) / 2;
    }
    rep(i, N) { cout << N * (N + 1) / 2 - m[i] << endl; }
}


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

const int N = 100010;

int n;
bool flag[N];

int main(){
	scanf("%d", &n);
	for (int i = 0, x; i < n; ++ i){
		scanf("%d", &x);
		flag[x] = true;
	}
	int ans = 0;
	for (int i = 0; i < N; ++ i){
		ans += flag[i];
	}
	if (!(ans & 1)){
		-- ans;
	}
	return printf("%d", ans), 0;
}

Measured memory_bytes: 384
//arc075_c.cpp
//Sat Jun  9 08:04:35 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;

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

	int sum = 0;
	int a[n];
	for (int i=0;i<n;i++){
		cin >> a[i];
		sum = sum + a[i];
	}

	sort (a,a+n);

	int ans = 0;

	if (sum%10!=0){
		ans = sum;
	}else {
		int flag = 0;
		for (int i=0;i<n;i++){
			sum = sum - a[i];
			if (sum%10!=0){
				ans = sum;
				flag = 1;
				break;
			}
			sum = sum + a[i];
		}
		if (flag == 0){
			ans = 0;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np
N=list(map(int,input().split()))
A,B=max(N),min(N)
#ユーグリッド
GCD=1
while True:
    r=A%B
    if r==0:
        GCD=B
        break
    else:
        A=B
        B=r

if GCD==1:
    print(1)
else:
    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

    _GCD=factorization(GCD)
    num_list=[1]
    for num in _GCD:
        num_list+=[num[0]]
    #これで素因数分解の加工が完全に完了
    print(len(num_list))

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

using namespace std;

typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++)
    {
        if (i % k == 0)
        {
            cout << "OK\n";
            return 0;
        }
    }
    cout << "NG\n";
    return 0;
}

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

ll fact(ll n){
  if(n==0){return 1;}
  return fact((n-1)%MOD)*n%MOD;
}

ll power(ll a,ll b){
  ll res=1;
  while(b>0){
    if(b&1) res=res*a%MOD;
    a=a*a%MOD;
		b>>=1;
	}
  return res;
}
ll factinv(ll a){
	ll res=power(fact(a),MOD-2);
	return res;
}

ll comb(ll n, ll r){
  ll res;
  if(n<0||r<0||n<r){res=0;}
  else{res=(fact(n)*factinv(r))%MOD*factinv(n-r)%MOD;}
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,k;
  cin>>n>>k;
  for(int i=1;i<=k;i++){
    cout<<comb(n-k+1,i)*comb(k-1,i-1)%MOD<<endl;
  }
        return 0;
}


Measured memory_bytes: 384
import bisect
n = int(input())
A = list(map(int,input().split()))
A = sorted(A)
if n==2:
    cur = [A[1],A[0]]
else:
    a = A[-1]
    ind = bisect.bisect_right(A,a//2)
    b = a-A[ind]
    c = A[ind-1]
    if c>=b:
        cur = [a,c]
    else:
        cur = [a,a-b]
print(cur[0],cur[1])

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

  int main() {
    int a, b;
    cin >> a >> b;
    if ((a + b) % 2 == 0) {
      cout << (a + b) / 2 << endl;
    }
    else {
      cout << (a + b) / 2 + 1 << endl;
    }
  }

Measured memory_bytes: 256
s = input()
l = []
cnt = 0
flg = 0
for c in s:
    if (c == '<') ^ flg:
        cnt += 1
    else:
        l.append(cnt)
        flg ^= 1
        cnt = 1
l.append(cnt)
if len(l) % 2:
    l.append(0)
ans = 0
for i in range(len(l) // 2):
    x = l[i * 2]
    y = l[i * 2 + 1]
    ans += x * (x - 1) // 2 + y * (y - 1) // 2 + max(x, y)
print(ans)

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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};

 
int main(){
  int n;
  cin >> n;
  ll a[100005]={}, s=0;
  for(int i=0; i<n; i++){
    ll ai;
    cin >> ai;
    a[ai]++;
    s+=ai;
  }
  int q;
  cin >> q;
  for(int i=0; i<q; i++){
    ll b, c;
    cin >> b >> c;
    s -= b*a[b];
    s += c*a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << s << endl;
  }
  return 0;
}


Measured memory_bytes: 4420
#include <stdio.h>
#include <string.h>

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

	int i;
	int result;
	int a_score = 0;
	int b_score = 0;
	char a_card[100];
	char b_card[100];
	for (i = 0; i < n; i++)
	{
		scanf("%s %s", a_card, b_card);
		result = strcmp(a_card, b_card);
		if (result == 0)
		{
			a_score += 1;
			b_score += 1;
		}
		if (result > 0)
		{
			a_score += 3;
		}
		if (result < 0)
		{
			b_score += 3;
		}
	}
	printf("%d %d\n", a_score, b_score);

	return 0;
}

Measured memory_bytes: 604
from math import cos, radians, sqrt

A, B, H, M = map(int, input().split())
rad = 0 if H==0 and M==0 else radians(abs(360/(720/(60*H+M))-6*M))
ans = sqrt((A**2)+(B**2)-2*A*B*cos(rad))
print(ans)


Measured memory_bytes: 9464
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int H = int.Parse(str[0]);
		int W = int.Parse(str[1]);
		int K = int.Parse(str[2]);
		int[,]A = new int[H,W];
		for(var i=0;i<H;i++){
			string s = Console.ReadLine();
			for(var j=0;j<W;j++){
				if(s.Substring(j,1)=="#"){
					A[i,j] = 1;
				}
			}
		}
		int ans = 0;
		int N = (int)Math.Pow(2,H+W);
		for(var h=0;h<N;h++){
			int[,]B = new int[H,W];
			for(var i=0;i<H;i++){
				for(var j=0;j<W;j++){
					B[i,j] = A[i,j];
				}
			}
			for(var i=0;i<H;i++){
				if(h/(int)Math.Pow(2,i)%2==1){
					for(var j=0;j<W;j++){
						B[i,j] = 0;
					}
				}
			}
			for(var i=0;i<W;i++){
				if(h/(int)Math.Pow(2,H+i)%2==1){
					for(var j=0;j<H;j++){
						B[j,i] = 0;
					}
				}
			}
			int ct = 0;
			for(var i=0;i<H;i++){
				for(var j=0;j<W;j++){
					if(B[i,j] == 1){
						ct++;
					}
				}
			}
			if(ct==K){
				ans++;
			}
		}
		Console.WriteLine(ans);
	}
}

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

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

	int N;
	int i,j;
	int answer;
	int max=0;
	int counter=0;
	double ave;
	string tmp;
	map<string,int> mp;
	vector<string> given;

	cin >> N;

	for(i=0;i<N;i++){
		cin >> tmp;
		given.push_back(tmp);
	}

	for(i=0;i<N;i++){
		auto itr=mp.find(given[i]);
		mp[given[i]]++;
	}

	for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
			if(max < itr->second) max=itr->second;
	}

	for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
			if(max==itr->second) cout << itr->first << endl;
	}

	return 0;
}



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

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

    int64_t ans = 0;
    for (int64_t i = 0; i < N; i++) {
        if ((A[i] | K) == K) {
            ans += B[i];
        }
    }

    for (int64_t i = 0; i < 30; i++) {
        //i - 1桁目までどうでもよく、j桁目が1ではなく0で、i + 1桁目以降は同一
        if ((K & (1LL << i)) == 0) {
            continue;
        }

        int64_t Ki = K;
        Ki ^= (1LL << i);
        for (int64_t j = 0; j < i; j++) {
            Ki |= (1LL << j);
        }

        int64_t curr = 0;
        for (int64_t j = 0; j < N; j++) {
            if ((A[j] | Ki) == Ki) {
                curr += B[j];
            }
        }
        ans = max(ans, curr);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
t = int(input())
early_value = int(input())
for i in range(t-1):
	value = int(input())
	if not i:
		later_value = value
		profit = later_value - early_value
		#print('Profit seted:', profit)
		#has_lesser = False
	if value < early_value:
		early_value = value
		#has_lesser = True
	#elif has_lesser:
		#if profit < value - early_value:
			#later_value = value
			#profit = later_value - early_value
			#print('Profit changes:', profit)
	elif profit < value - early_value:
		later_value = value
		profit = later_value - early_value
		#print('Profit changes:', profit)
print(profit)


Measured memory_bytes: 5612
//#include"bits/stdc++.h"
#include<algorithm>
#include<cassert>
#include<cmath>
#include<climits>
#include<iostream>
#include<map>
#include<set>
#include<vector>
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define rep(i, j) FOR(i, 0, j, 1)
#define MP make_pair
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define DEB(x) cout<<"##"<<x<<"##"<<endl
const int INF=(int)2e9+9;
const int SIZE=(int)2e5+5;
//Brute force answers(BINARY SEARCH) symmetry
//Change perspective
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ll k;
    cin>>k;
    if(k%2==0){
        cout<<-1;
    }
    else{
        int min1=0,temp=k;
        while(temp>0){
            temp/=10;
            min1++;
        }
        int ans=0,pref=0;
        ll cnt=7;
        while(1){
            ans++;
            pref+=cnt;
            pref%=k;
            if(pref==0){
                break;
            }
            cnt=(cnt*10)%k;
            if(ans>=(int)1e6){
                ans=-1;
                break;
            }
        }
        cout<<ans;
    }
} 

Measured memory_bytes: 3548