akhauriyash/Code-Regression huggingface dataset:
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int mod = 1e9 + 7;

int n, m;

void read_input()
{
    cin >> n >> m;
}

int fact(int n)
{
    int res = 1;
    for(int i = 1; i <= n; ++i)
        res = res * 1LL * i % mod;
    return res;
}

void solve()
{
    if(abs(n - m) > 1)
    {
        cout << "0\n";
        return;
    }
    int ans = fact(n) * 1LL * fact(m) % mod;
    if(n == m) ans = ans * 2LL % mod;
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    read_input();
    solve();
}



Measured memory_bytes: 256
from collections import deque
N = int(input())
graph = [[] * N for _ in range(N)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append([b, c])
    graph[b].append([a, c])
    
Q, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(Q)]

# BFSのためのデータ構造
dist = [-1 for _ in range(N)]   # 全頂点を未訪問に
que = deque()

# 初期条件(頂点 K-1 を初期ノードとする)
dist[K-1] = 0
que.append(K-1)

# BFS 開始(キューが空になるまで探索を行う)
while que:
    v = que[0]
    que.popleft()
    for new_v_list in graph[v]:
        new_v = new_v_list[0]
        if dist[new_v] != -1:   # すでに探索済みの頂点は探索しない
            continue
        # 新たな頂点 new_vについて距離情報を更新してキューに追加する
        dist[new_v] = dist[v] + new_v_list[1]
        que.append(new_v)


for i in range(Q):
    print(dist[xy[i][0] - 1] + dist[xy[i][1] - 1])


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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
// constexpr ll mod = 1e9+7;


int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
  }
  int loop = min(50, K);
  while(loop--){
    vector<int> sum(N+1, 0);
    REP(i, N){
      int right =min(A[i]+i+1, N);
      int left = max(i-A[i], 0);
      sum[right]--;
      sum[left]++;
    }
    REP(i, N){
      sum[i+1] += sum[i];
      A[i] = sum[i];
    }
  }
  REP(i, N){
    cout << A[i] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 4792
N = int(input())
S = [None] * N

count_AB = 0
right_A = 0
left_B = 0
right_A_left_B = 0

for i in range(N):
    s = input()
    count_AB += s.count('AB')
    if s[0] == "B" and s[-1] == "A":
        right_A_left_B += 1
    elif s[0] == "B":
        left_B += 1
    elif s[-1] == "A":
        right_A += 1

if right_A_left_B > 0:
    count_AB += (right_A_left_B - 1)
    right_A_left_B = 1
    # OK

if right_A_left_B == 0:
    min_AB = min(right_A, left_B)
    count_AB += min_AB
else:
    # right_A_left_B = 1
    if right_A == 0 or left_B == 0:
        if max(right_A, left_B) > 0:
            count_AB += 1
            right_A_left_B = 0
    else:
        count_AB += 1
        right_A_left_B = 0
        min_AB = min(right_A, left_B)
        count_AB += min_AB
print(count_AB)

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	ll n; cin >> n;
	ll ret = INF;
	for (ll i=1; i*i <= n; i++) {
		if (n%i==0 && (ret > (n/i + i - 2))) {
			ret = n/i + i - 2;
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
sstr=list(input())
s=list(map(int,sstr))

op=["" for _ in range(3)]
for i in range(2**3):
    tmp=0
    tmp+=s[0]
    for j in range(3):
        if (i>>j)&1:
            tmp+=s[j+1]
            op[j]="+"
        else:
            tmp-=s[j+1]
            op[j]="-"
    if tmp==7:
        ans=sstr[0]+op[0]+sstr[1]+op[1]+sstr[2]+op[2]+sstr[3]+"=7"
        print(ans)
        break

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

int main(){
    
    int ans;
    
    for (int i = 0; i < 5; i++) {
        int buf;
        cin >> buf;
        if (buf == 0) {
            ans = i + 1;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3584
def mod_comb_k(n, k):
    return fact[n] * fact_inv[k] * fact_inv[n-k] % mod


n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))

mod = 10 ** 9 + 7

fact = [1]
fact_inv = [0] * (n+1)
for i in range(n):
    fact.append(fact[-1] * (i+1) % mod)
fact_inv[-1] = pow(fact[-1], mod-2, mod)
for i in range(n-1, -1, -1):
    fact_inv[i] = fact_inv[i+1] * (i+1) % mod

sum_max = 0
for i in range(k-1, n):
    sum_max = (sum_max + a[i] * mod_comb_k(i, k-1) % mod) % mod

sum_min = 0
for i in range(n-k+1):
    sum_min = (sum_min + a[i] * mod_comb_k(n-i-1, k-1) % mod) % mod

print((sum_max - sum_min) % mod)

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s=max(s,t);
#define chmin(s, t) s=min(s,t); 

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n){
    const ll FMOD = 1e9+7;
    ll ret = n;
    for(ll i=n-1;i>0;i--){
        ret*=i;
        ret%=FMOD;
    }
    return (ret?ret:1);
}


int main(){

    ll n; cin >> n;

    ll ans = 0;

    rep2(a, 1, n){
        for(ll b=1;a*b<n;b++){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h> 
#define MAX 1e+7
using namespace std;
int dp[1000010][2];
int main(){
    string s;
    cin>>s;
    s+='0';
    reverse(s.begin(),s.end());
	s+='0';
	for(int i=0;i<s.size();i++) s[i]-='0';
    dp[0][1]=MAX;
	for(int i=1; i<=s.size()-1; ++i){
    	dp[i][0]=min(dp[i-1][0]+s[i],dp[i-1][1]+s[i]+1);
    	dp[i][1]=min(dp[i-1][0]+10-s[i],dp[i-1][1]+9-s[i]);
    }
    cout<<dp[s.size()-1][0];
    return 0;
}

Measured memory_bytes: 9220
X, N = map(int,input().split())
p_list = list(map(int,input().split()))

temp = -1
for i in range(102):
  if(temp == -1):
    if(i not in p_list):
      temp = abs(X - i)
      ans = i
  elif(temp > abs(X-i) and i not in p_list):
   temp = abs(X-i)
   ans = i

print(ans)

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

struct node{
  int key;
  struct node *parent,*left,*right;
};

struct node *root,*NIL;

struct node * find(struct node *u, int k){
  while(u!=NIL&&k!=u->key){
    if(k<u->key) u=u->left;
    else u=u->right;
  }
  return u;
}

void insert(int k){
  struct node *y=NIL;  //xの親
  struct node *x=root;
  struct node *z;

  z=(struct node*)malloc(sizeof(struct node));

  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key) x=x->left;
    else x=x->right;
  }

  z->parent=y;

  if(y==NIL) root=z;
  else if(z->key<y->key) y->left=z;
  else y->right=z;
  }

void inorder(struct node *u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(struct node *u){
  if(u==NIL) return;
   printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int num,i,k;
  char c[10];
  struct node *judge;

  scanf("%d",&num);

  for(i=0;i<num;i++){
    scanf("%s",c);
    if(c[0]=='i'){
      scanf("%d",&k);
      insert(k);
    }
    else if(c[0]=='f'){
      scanf("%d",&k);
      judge=find(root,k);
      if(judge!=NIL) printf("yes\n");
      else printf("no\n");
    }
    else{
      inorder(root);
            printf("\n");
      preorder(root);
      printf("\n");
    }
      }

  return 0;
}


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

int main() {
    string s;
    cin >> s;
    int pay;
    pay = 700;

    for(int i = 0; i < s.size(); i++) {
        if(s.at(i) == 'o') {
            pay += 100;
        }
    }
    cout << pay << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var D int
	fmt.Scan(&D)
	cs := make([]int, 26)
	for i := 0; i < 26; i++ {
		fmt.Scan(&cs[i])
	}

	ss := make([][26]int, D)
	for i := 0; i < D; i++ {
		for j := 0; j < 26; j++ {
			fmt.Scan(&ss[i][j])
		}
	}

	ts := make([]int, D)
	for i := 0; i < D; i++ {
		fmt.Scan(&ts[i])
	}
	var M int
	fmt.Scan(&M)
	var d, q int
	for i := 0; i < M; i++ {
		fmt.Scan(&d, &q)
		d--
		ts[d] = q

		sat := solve(D, ts, cs, ss)
		fmt.Println(sat)
	}
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func solve(D int, ts []int, cs []int, ss [][26]int) int {
	last := [26]int{}
	sat := 0
	for d := 0; d < D; d++ {
		j := ts[d] - 1
		last[j] = d + 1
		for i := 0; i < 26; i++ {
			sat -= (d + 1 - last[i]) * cs[i]
		}
		sat += ss[d][j]
	}

	return sat
}


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


int main() {
  vector<int> a(5);
  for (int i=0; i<5; i++) {
    cin >> a[i];
  }
  
  int minimum = 10;
  vector<int> b(5);
  for (int i=0; i<5; i++) {
    if (a[i]%10 == 0)
      b[i] = a[i];
    if (a[i]%10 != 0) {
      b[i] = a[i] + 10 - a[i]%10;
      minimum = min(minimum, a[i]%10);
    }
  }
  
  int ans = -10+minimum;
  for (int i=0; i<5; i++) {
    ans += b[i];
  }
  
  cout << ans << endl;
  
  
 
}

Measured memory_bytes: 256
from collections import Counter


def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = Counter(a)
    q = int(input())
    s = sum(a)
    for _ in range(q):
        b, c = map(int, input().split())
        s -= cnt[b]*b

        s += cnt[b]*c
        cnt[c] += cnt[b]
        cnt[b] = 0
        print(s)

if __name__ == "__main__":
    main()


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

int main(){
    int n;
    cin >> n;
    int ans=0;

    for(int i=1; i<=n; i++){
        if(i<=9){
            ans++;
        }
        if((i>=100) && (i<=999)){
            ans++;
        }
        if((i>=10000) && (i<=99999)){
            ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
  n,m,l = map(int, input().split())

  A = [list(map(int, input().split())) for _ in range(n)]
  B = [list(map(int, input().split())) for _ in range(m)]
  C = list()

  for i in range(n):
    row = list()
    for j in range(l):
      cell = 0
      for k in range(m):
        cell += A[i][k]*B[k][j]
      row.append(cell)
    C.append(row)

  for c_row in C:
    print(*c_row)

if __name__ == '__main__':
  main()


Measured memory_bytes: 7068
from collections import Counter
def main():
    n = int(input())
    a = list(map(int,input().split()))
    full = [0 for i in range(n+1)]
    one = [0 for i in range(n+1)]


    c = Counter(a)
    for i in range(1,n+1):
        if 1 <= c[i]:
            full[i] = c[i]*(c[i]-1)//2
        if 2 <= c[i]:
            one[i] = (c[i]-1)*(c[i]-2)//2
    sum_full = sum(full)

    for i in range(len(a)):
        print(sum_full - full[a[i]]+one[a[i]])

    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 91984
#include<stdio.h>
 
int s[1000000], n;
 
int binarySearch(int key){
    int left = 0;
    int right = n;
    int mid;
 
    while(left < right){
        mid = (left + right) / 2;
        if( key == s[mid] ) return 1;
        if( key > s[mid] ) left = mid + 1;
        else if( key < s[mid] ) right = mid;
    }
    return 0;
}
 
int main(void){
    int i, q, t,c = 0;
 
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &s[i]);
    }
    scanf("%d", &q);
    for(i = 0; i < q; i++){
        scanf("%d", &t);
        if(binarySearch(t) ) c++;
    }
    printf("%d\n", c);
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std ;
using ll = long long;

int main(){
    int n,l;
    string s;
    cin >> n >> l;
    vector<string>v;
    for(int i=0; i<n; i++){
        cin >> s;
        v.push_back(s);
    }
    sort(v.begin(),v.end());

    for(int i=0; i<n; i++){
        cout << v[i];
    }
    return 0 ;
}

Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    auto s = sread();
    writeln(s.front, s.length - 2, s.back);
}


Measured memory_bytes: 256
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
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);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int k,s;cin >> k >> s;
    int count = 0;
    for(int i = 0;i<=k;i++) {
        for(int j = 0;j<=k;j++) {
            if(s-i-j<=k&&i+j<=2*k&&s-i-j>=0) {
                count++;
                // cout << i  << ' ' << j << ' ' << s-i-j << endl;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3560
#include<stdio.h>
int main(){
	int H,W;
	for(int i=0;i<300;i++){
		scanf("%d %d",&H,&W);
		if(H==0&&W==0)break;
		for(int i=1;i<=H;i++){
			for(int j=1;j<=W;j++){
				if(i==1||i==H)printf("#");
				else if(j==1||j==W)printf("#");
				else printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2620
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define BTC 380000
const ll MOD=1e9+7;
using namespace std;
ll gcd(ll a, ll b) {
  if(a==0) return b;
  if(a>b) return gcd(a%b, b);
  else return gcd(b%a, a);
}
ll lcm(ll a, ll b) {
  ll tmp=gcd(a,b);
  return (a/tmp)*(b/tmp)*tmp;
}

int main() {
  int N;
  cin >> N;
  double sum=0;
  rep(i,N){
    double x;
    string u;
    cin >> x >> u;
    if(u=="BTC"){
      sum+=x*BTC;
    }else{
      sum+=x;
    }
  }
  printf("%.5f\n",sum);
}

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

int main(){
  int a, b, k;
  cin >> a >> b >>k;
  
  for(int i = 100; i >= 0; i--){
    if(a % i == 0 && b % i == 0){
      k--;
    }
    
    if(k == 0){
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int N;
int X[201010];
int Xsorted[201010];

int main() {
  cin >> N;
  rep(i, 0, N) {
    cin >> X[i];
    Xsorted[i] = X[i];
  }
  sort(Xsorted, Xsorted + N);
  int mid = N / 2;
  int midr = Xsorted[mid];
  int midl = Xsorted[mid - 1];

  rep(i, 0, N) {
    if (X[i] >= midr) {
      cout << midl << endl;
    } else {
      cout << midr << endl;
    }
  }
}

Measured memory_bytes: 3712
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::input;
use proconio::marker::{Bytes, Chars};
use std::collections::*;

fn main() {
    input! {
        n:usize,
        d:i64,
        xy:[(i64,i64);n],
    }
    let ans = xy.iter().filter(|&(p, q)| p * p + q * q <= d * d).count();
    println!("{}", ans);
}

Measured memory_bytes: 7836
import Foundation

private func readWords<T>(_ f: (Substring) -> T?) -> [T] {
    return readLine()!.split(separator: " ").compactMap(f)
}

prefix operator *
private prefix func *<T>(a: inout IndexingIterator<[T]>) -> T {
    return a.next()!
}

extension Optional {
    func pleaseAC(){
        print(self!)
    }
}

readLine().map { line -> Any in 
    var nmk = line.split(separator: " ").compactMap { Int($0) }.makeIterator()
    let n = *nmk
    let m = *nmk
    let k = *nmk
    
    let A = readWords { Int($0) }
    let B = readWords { Int($0) }
    
    var cumA = [Int]()
    cumA.append(0)
    var cumB = [Int]()
    var totalA = 0
    for a in A {
        let x = totalA + a
        if x > k {
            break
        }
        cumA.append(x)
        totalA = x
    }
    
    var totalB = 0
    for b in B {
        let x = totalB + b
        if x > k {
            break
        }
        cumB.append(x)
        totalB = x
    }
    
    if cumA.count == 1 && cumB.isEmpty {
        print(0)
        return ""
    }
    
    if cumA.count == 1 {
        print(cumB.count)
        return ""
    }
    
    if cumB.isEmpty {
        print(cumA.count)
        return ""
    }

    var ans = 0
    for (i, a) in cumA.enumerated() {
        var l = -1
        var r = cumB.count
        while r - l > 1 {
            let mid = l + (r - l) / 2
            if cumB[mid] + a > k {
                r = mid
            } else {
                l = mid
            }
        }
        ans = max(ans, i+r)
    }
    
    return ans
}
.pleaseAC()


Measured memory_bytes: 32448
import java.util.*;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int m = scan.nextInt();
		int a = 0;
		for(int i=0;i<m;i++) {
			a += scan.nextInt();
			if(a>n) {
				System.out.println(-1);
				System.exit(0);
			}
		}
		
		System.out.println(n-a);
		
		
	}	
	
	
	//最小公約数
	/*
	static int gcd (int a, int b) {
		int temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	*/
	
}

Measured memory_bytes: 46320
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	bool eve=true;
	cin>>n;
	ll mn=LINF,ans=0;
	vl v(n);
	rep(i,n)cin>>v[i];
	rep(i,n){
		if(v[i]<0)eve=!eve;
		ans+=abs(v[i]);
		chmin(mn,abs(v[i]));
	}
	cout<<ans-(eve?0:mn*2)<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
  cout << (S[2] == S[3] && S[4] == S[5] ? YES : NO) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    string Str;
    cin >> N >> Str >> K;
    K--;
    for(int i=0; i<N; i++){
        if(Str.at(i)==Str.at(K)){
            cout << Str.at(K);
        }else{
            cout << '*';
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed main(){
  string S;
  cin >> S;
  if(S=="SUN") cout << 7 << endl;
  else if(S=="MON") cout << 6 << endl;
  else if(S=="TUE") cout << 5 << endl;
  else if(S=="WED") cout << 4 << endl;
  else if(S=="THU") cout << 3 << endl;
  else if(S=="FRI") cout << 2 << endl;
  else if(S=="SAT") cout << 1 << endl;
  return 0;
}


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

int main() {
	int n; cin >> n;
	string s, t; cin >> s >> t;
	
	string ans = "";
	rep(i, 0, n) {
		ans += s[i];
		ans += t[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  娌规紗宸?
//
//  Created by RMBP on 2019/11/5.
//  Copyright 漏 2019 RMBP. All rights reserved.
//

#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int a[3],i,b,j;
    b=3;
    for (i=0;i<3;i++){
        cin>>a[i];
    }
    for (i=0;i<3;i++){
        for (j=0;j<i;j++){
            if (a[i]==a[j]){
                b=b-1;
                break;
            }
        }
    }
    cout<<b;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	string s;
	cin>>s;
	int k = s.size();
	int cnt = 0;
	for(int i = 0; i < k; i++){
		if(s[i]=='o') cnt++;
	}
	cout<<(cnt+15-k>=8?"YES":"NO")<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;

ll isSubstring(string s1,string s2){ 
    ll M = s1.length(); 
    ll N = s2.length(); 

    for(ll i=0;i<=N-M;i++){ 
        ll j; 
        for(j=0;j<M;j++) {
            if(s2[i+j]!=s1[j]) 
                break; 
        }
  
        if(j==M) 
            return i; 
    } 
  
    return -1; 
} 

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

    string s;
    string t;
    cin>>s>>t;

    ll n=s.length();
    ll m=t.length();

    ll mini=INT_MAX;
    for(ll i=0;i<n-m+1;i++){
    	ll count{0};

    	for(ll j=0;j<m;j++){
    		if(t[j]!=s[i+j])
    			count++;
    	}

    	if(count<mini)
    		mini=count;
    }

    cout<<mini<<endl;
	
	return 0;
}



Measured memory_bytes: 3648
function Main(input) {
	input = input.split("\n");
	const N = parseInt(input[0])
	const As = input[1].split(" ").map(x => parseInt(x))
	const boxs = new Array(N)
	boxs.fill(1)
	for(i=0; i < N; i++){
		var id = N-i
		var sum = 0
		for(j=1; j <= N/id; j++){
			sum = (sum + boxs[j*id-1]) % 2
		}
		if(sum != As[id-1]) boxs[id-1] = 0
	}
	var results = ""
	var count = 0
	for(i=0; i < N; i++){
		if(boxs[i] == 1){
			count++
			results += " " + (i+1)
		}
	}
	console.log(count)
	if(results != "") console.log(results.slice(1))
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 38396
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
float PHI = 1.6180339;
//const float  PI_F=3.14159265358979f;
#define MAX 100000 
#define endl "\n"    
//typedef long long float;
#define int long long
//#define float unsigned long long
  


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cout << fixed << setprecision(7);

    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n==1 || n%2==1)
    {
        cout<<"No"<<endl;
    }
    else
    {
        int j=n/2;
        int flag=1;
        for(int i=0;i<n/2;i++)
        {
            if(s[i]!=s[j])
            {
                flag=0;
                break;
            }
            ++j;
        }
        if(flag==1)
        cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
#define MOD 1e9 + 7
#define f first
#define s second
#define N 1e5
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll a,b,c,count=0;
	cin>>a>>b>>c;
	cout<<min(a+b,min(b+c,c+a));
}	

Measured memory_bytes: 256
import math
x1, y1, x2, y2 = map(int, input().split())
p3 = 0
q3 = 0
p4 = 0
q4 = 0

for x3 in range(-301, 301):
    for y3 in range(-301, 301):
        length1 = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
        length2 = math.sqrt((x3 - x2)**2 + (y3 - y2)**2)
        if x2 != x1 and x3 != x2:
            slope = (y2 - y1)/(x2 - x1)*(y3 - y2)/(x3 - x2)
            if y1 != y2 and length1 == length2 and slope == -1 and\
                x2 > x1 and y3 > (y2 - y1)/(x2 - x1)*x3 +(x2*y1 - y2*x1)/(x2 - x1):
                p3 = x3
                q3 = y3
            elif y1 != y2 and length1 == length2 and slope == -1 and\
                x2 < x1 and y3 < (y2 - y1)/(x2 - x1)*x3 +(x2*y1 - y2*x1)/(x2 - x1):
                p3 = x3
                q3 = y3
        else:
            if x2 == x1 and y2 > y1 and y3 == y2 and x3 == x2 - length1:
                p3 = x3
                q3 = y3
            elif x2 == x1 and y2 < y1 and y3 == y2 and x3 == x2 + length1:
                p3 = x3
                q3 = y3
            elif x2 > x1 and y2 == y1 and x3 == x2 and y3 == y2 + length1:
                p3 = x3
                q3 = y3
            elif x2 < x1 and y2 == y1 and x3 == x2 and y3 == y2 - length1:
                p3 = x3
                q3 = y3

for x4 in range(-301, 301):
    for y4 in range(-301, 301):
        length1 = math.sqrt((p3 - x2)**2 + (q3 - y2)**2)
        length2 = math.sqrt((x4 - p3)**2 + (y4 - q3)**2)
        if x2 != p3 and p3 != x4:
            slope = (q3 - y2)/(p3 - x2)*(y4 - q3)/(x4 - p3)
            if y2 != q3 and length1 == length2 and slope == -1 and\
                p3 > x2 and y4 > (q3 - y2)/(p3 - x2)*x4 +(p3*y2 - q3*x2)/(p3 - x2):
                p4 = x4
                q4 = y4
            elif y2 != q3 and length1 == length2 and slope == -1 and\
                p3 < x2 and y4 < (q3 - y2)/(p3 - x2)*x4 +(p3*y2 - q3*x2)/(p3 - x2):
                p4 = x4
                q4 = y4
        else:
            if p3 == x2 and q3 > y2 and y4 == q3 and x4 == p3 - length1:
                p4 = x4
                q4 = y4
            elif p3 == x2 and q3 < y2 and y4 == q3 and x4 == p3 + length1:
                p4 = x4
                q4 = y4
            elif p3 > x2 and q3 == y2 and x4 == p3 and y4 == q3 + length1:
                p4 = x4
                q4 = y4
            elif p3 < x2 and q3 == y2 and x4 == p3 and y4 == q3 - length1:
                p4 = x4
                q4 = y4

print(p3, q3, p4, q4)

Measured memory_bytes: 3320
#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

template<typename T>
bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>
bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

class UnionFind{
	vector<ll> rank;
	vector<ll> diff_weight;
	vector<ll> num;
public:
	vector<ll> par;

	UnionFind(ll N):par(N),num(N),rank(N),diff_weight(N){
		for(ll i=0;i<N;i++){
			par[i]=i;
			num[i]=1;
			rank[i]=0;
			diff_weight[i]=0;
		}
	}

	ll root(ll x){
		if(par[x]==x){
			return x;
		}
		ll r = root(par[x]);
		diff_weight[x]+=diff_weight[par[x]];
		return par[x]=r;
	}

	void unite(ll x,ll y){
		ll rx = root(x);
		ll ry = root(y);
		if (rx == ry) return;
		if(rank[rx]<rank[ry]) swap(rx,ry);
		if(rank[rx]==rank[ry]) ++rank[rx];
		par[ry] = rx;
		num[rx] += num[ry];
	}

	void relate(ll x,ll y,ll w){
		w+=weight(x),w-=weight(y);
		ll rx = root(x);
		ll ry = root(y);
		if (rx == ry) return;
		if(rank[rx]<rank[ry]){
			swap(rx,ry);
			w = -w;
		}
		if(rank[rx]==rank[ry]) ++rank[rx];
		par[ry] = rx;
		diff_weight[ry] = w;
		num[rx] += num[ry];
	}

	bool same(ll x,ll y){
		ll rx = root(x);
		ll ry = root(y);
		return rx == ry;
	}

	ll getsize(ll x){
		return num[root(x)];
	}

	ll weight(ll x){
		root(x);
		return diff_weight[x];
	}

	ll diff(ll x,ll y){
		return weight(y)-weight(x);
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	auto N=in();
	vector<ll> L(N),R(N);

	REP(i,N){
		L[i]=in();
		R[i]=in();
	}

	sort(ALL(L));
	sort(ALL(R));
	if(N%2){
		out(R[N/2]-L[N/2]+1);
	}
	else{
		out(R[N/2]+R[N/2-1]-(L[N/2]+L[N/2-1])+1);
	}
	
	return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N;
  vector<int> T(N);
  REP(i, N) cin >> T[i];
  cin >> M;
  vector<vector<int>> px(M, vector<int>(2));
  REP(i, M) cin >> px[i][0] >> px[i][1];
  for(int i = 0; i < M; i++) {
    int sum = 0;
    for(int j = 0; j < N; j++) {
      if(px[i][0] - 1 == j)
        sum += px[i][1];
      else
        sum += T[j];
    }
    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import heapq 
N, M = map(int, input().split())
A = list(map(int, input().split()))
q = []
for a in A:
  q += [-a]
heapq.heapify(q)

for _ in range(M):
  a = heapq.heappop(q)
  heapq.heappush(q, a/2)
ans = 0 
for p in q:
  ans += int(-p)
print(ans)

Measured memory_bytes: 93208
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Program
    {

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            String S = Console.ReadLine();
            String[] line = S.Split(' ');
            int[] A = new int[N];

            for(int i=0; i<N; i++)
            {
                A[i] = int.Parse(line[i]);
            }

            Array.Sort(A);
            bool ck = false;

            for(int i=1; i<N; i++)
            {
                if (A[i] == A[i - 1])
                {
                    ck = true;
                    break;
                }
            }

            if(ck == true)
            {
                Console.WriteLine("NO");
            }
            else
            {
                Console.WriteLine("YES");
            }

        }
    }
}

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

static int dp[1 << 10][10001] = {};

int main(){
	int n,s;
	while(cin >> n >> s){
		int res = 0;
		for(int i = 0;i < (1 << 10);i++){
			for(int j = 0;j <= 10000;j++) dp[i][j] = 0;
		}
		dp[0][0] = 1;
		for(int i = 1;i < (1 << 10);i++){
			int cnt = 0;
			for(int j = 0;j < 10;j++){
				if((i >> j) & 1) cnt++;
			}
			if(cnt > n) continue;
			for(int j = 0;j < 10;j++){
				if((i >> j) & 1){
					for(int k = 0;k <= s;k++){
						if(k - cnt * j >= 0) dp[i][k] += dp[i - (1 << j)][k - cnt * j];
					}
				}
			}
		}
		for(int i = 0;i < (1 << 10);i++){
			int cnt = 0;
			for(int j = 0;j < 10;j++) if((i >> j) & 1) cnt++;
			if(cnt == n) res += dp[i][s];
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 43060
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
int n,m,ans,d;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i*i<=m;i++) if (m%i==0){
		d=m/i;
		if (i>ans&&d>=n) ans=i;
		if (d>ans&&i>=n) ans=d;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
M = int(max(max(A), K)).bit_length()

maxVal = [0] * M  # digit以下の桁で取れる最大値

for digit in range(M):
    cnt = 0
    mask = (1 << digit)
    for a in A:
        if (mask & a) > 0:
            cnt += 1
    cnt = max(cnt, N - cnt)
    maxVal[digit] = cnt * mask
    if digit > 0:
        maxVal[digit] += maxVal[digit - 1]

upperValK = [0] * (M + 1)

for digit in range(M)[:: -1]:
    mask = (1 << digit)
    maskedK = (K & mask)
    cnt = 0
    for a in A:
        if (a & mask) != maskedK:
            cnt += mask
    upperValK[digit] = cnt + upperValK[digit + 1]

ans = upperValK[0]
for mid in range(M):
    mask = (1 << mid)
    if not (mask & K) > 0:
        continue

    cnt = upperValK[mid + 1]
    for a in A:
        if (a & mask) > 0:
            cnt += mask
    if mid > 0:
        cnt += maxVal[mid - 1]
    ans = max(ans, cnt)

print(ans)

Measured memory_bytes: 14620
from math import pi,cos,sin,atan2

while(1):
    n = int(input())
    if n == -1:
        break
    n -= 1
    ang = 0.0
    x = 1.0
    y = 0.0
    for i in range(n):
        ang += pi/2
        x += cos(ang)
        y += sin(ang)
        ang = atan2(y,x)
    print("{:.2f}".format(x))
    print("{:.2f}".format(y))


Measured memory_bytes: 5800
#include <iostream>
#include <vector>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ranked_index.hpp>

using namespace std;
using namespace boost::multi_index;
using Container = multi_index_container<
    int64_t,
    indexed_by<
        ranked_non_unique<identity<int64_t>>
    >
>;

int main()
{
    int n, k;
    cin >> n >> k;
    
    vector<int64_t> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    vector<int64_t> b(n + 1);
    for(int i = 0; i < n; i++) {
        b[i + 1] = b[i] + a[i] - k;   
    }
    
    Container c;
    int64_t ans = 0;
    
    for(int i = 0; i < n + 1; i++) {
        ans += c.upper_bound_rank(b[i]);
        c.insert(b[i]);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 12800
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() {
	ll x,y,res=0;cin>>x>>y;
	for(ll i=x;i<=y;i*=2,res++);
	cout<<res;
}


Measured memory_bytes: 256
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

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

    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> sorted_A(N);
    rep(i, N) {
        int tmp;
        cin >> tmp;
        A[i] = tmp;
        sorted_A[i] = tmp;
    }

    debug("----");
    sort(sorted_A.begin(), sorted_A.end());
    rep(i, N) {
        if (A[i] == sorted_A[N - 1]) {
            cout << sorted_A[N - 2] << endl;
        } else {
            cout << sorted_A[N - 1] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		
		if(a <10 && b < 10) {
			System.out.println(a*b);
		} else {
			System.out.println("-1");
		}
	}

}


Measured memory_bytes: 21844
N, M = input().split()
#　宿題の日数
Work = input().split()
#　宿題の合計執行日数
Worksum = 0
for n in Work:
  Worksum += int(n)
 
if int(N)-Worksum < 0:
  print(-1)
else:
  print(int(N)-Worksum)

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

#define y1 aklsdja
#define ii pair < int , int >
#define iii pair < int , ii >
#define iv pair < ii , ii >

#define fi first
#define se second
#define pb push_back
#define t top()
#define fr front()

#define FOR(i , x , n) for(int i = x ; i <= n ; ++i)
#define REP(i , x) for(int i = 0 ; i < x ; ++i)
#define FORD(i , x , n) for(int i = x ; i >= n ; --i)

#define oo 1e17 + 5
#define ll long long
#define int long long
#define pow poww

const int N = 3e3 + 5;
int n;
double res;
double p[N];
double dp[N][N];

main()
{
    //freopen("I.inp","r",stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    FOR(i , 1 , n)
        cin >> p[i];
    dp[1][1] = p[1];
    dp[1][0] = 1 - p[1];
    FOR(i , 2 , n)
    {
        FOR(j , 0 , i)
        {
            dp[i][j] = dp[i - 1][j] * (1 - p[i]);
            if(j >= 1)
                dp[i][j] += (dp[i - 1][j - 1] * p[i]);
        }
    }
    FOR(i , n / 2 + 1 , n)
        res += dp[n][i];
    cout << setprecision(10) << fixed << res;
}


Measured memory_bytes: 69120
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

long P = 998244353L;

void main()
{
    auto ns = readln.split.to!(int[]);
    auto N = ns[0];
    auto S = ns[1];
    auto AS = readln.split.to!(int[]);

    auto DP = new long[][](N+1, S+1);
    DP[0][0] = 1;

    foreach (i; 0..N) {
        foreach (j; 0..S+1) {
            (DP[i+1][j] += DP[i][j] * 2) %= P;
            if (j + AS[i] <= S) (DP[i+1][j+AS[i]] += DP[i][j]) %= P;
        }
    }

    writeln(DP[N][S]);
}

Measured memory_bytes: 74868
S = str(input())
T = str(input())

exchange = [-1] * 26
alpha2num = lambda c: ord(c) - ord('a')
#print(alpha2num('y')) #==> 24

for i in range(len(S)):
    now_num = alpha2num(S[i])
    #print(now_num, exchange[now_num], alpha2num(T[i]))
    if exchange[now_num] == -1:
      exchange[now_num] = alpha2num(T[i])
    elif exchange[now_num] == alpha2num(T[i]):
      #print("yeee")
      continue
    else:
      print("No")
      quit()
  #print(exchange)    
  
exchange = sorted(exchange)
for i in range(1, 26):
  if exchange[i] == exchange[i - 1]:
    if exchange[i] != -1:
      print("No")
      quit()
  
print("Yes")


Measured memory_bytes: 9448
#include <bits/stdc++.h>
using namespace std;
#define LLI long long int

const int _mx = 2e6;
int a[_mx+5];

int main() {
    // freopen("in.txt", "r", stdin);

    string s;
    LLI a, b, n, ans;
    stack <LLI> st;
    while (cin >> s) {
        if (s[0] == '+') {
            a = st.top(); st.pop();
            b = st.top(); st.pop();
            st.push(a + b);
        }
        else if (s[0] == '-') {
            a = st.top(); st.pop();
            b = st.top(); st.pop();
            st.push(b - a);
        }
        else if (s[0] == '*') {
            a = st.top(); st.pop();
            b = st.top(); st.pop();
            st.push(a * b);
        }
        else {
            n = s[0] - '0';
            for (int j = 1; j < s.size(); j++) n = n * 10 + (s[j] - '0');
            st.push(n);
        }
    }
    cout << st.top() << endl;

    return 0;
}



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

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int X; cin >> X;
    cout << 360 / __gcd(360,X) << endl;
}



Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	if(s=="hi") return puts("Yes"),0;
	if(s=="hihi") return puts("Yes"),0;
	if(s=="hihihi") return puts("Yes"),0;
	if(s=="hihihihi") return puts("Yes"),0;
	if(s=="hihihihihi") return puts("Yes"),0;
	puts("No");
}

Measured memory_bytes: 3604