akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[2] = {1, 0};
const int dy[2] = {0, 1};

void solve() {
  int h, w; cin >> h >> w;
  vector<string> v(h); rep(i, h) cin >> v[i];

  const int MAX = 100;
  int mins[MAX + 1][MAX + 1] = {{}};

  for (int i = 0; i <= MAX; i++) {
    for (int j = 0; j <= MAX; j++) {
      mins[i][j] = MOD;
    }
  }
  mins[0][0] = v[0][0] == '.' ? 0 : 1;
  queue<ll> qx; qx.push(0);
  queue<ll> qy; qy.push(0);
  queue<ll> qc; qc.push(mins[0][0]);

  while (!qx.empty()) {
    int x = qx.front(); qx.pop();
    int y = qy.front(); qy.pop();
    int c = qc.front(); qc.pop();
    // debug3(x, y, c);

    for (int i = 0; i < 2; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx >= 0 && nx < w && ny >= 0 && ny < h) {
        int nc = v[ny][nx] == '#' && v[y][x] == '.' ? c + 1 : c;
        if (nc >= mins[ny][nx]) continue;

        mins[ny][nx] = nc;
        qx.push(nx);
        qy.push(ny);
        qc.push(nc);
      }
    }
  }
  outl(mins[h-1][w-1]);
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 384
n = int(input())
s = [input() for i in range(n)]

d = {}
for st in s:
    d[st] = d.get(st, 0) + 1

t = max(d.values())
ans = []
for p in d:
    if d[p] == t:
        ans.append(p)

ans.sort()
print("\n".join(ans))

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const LL INF = 1e17;

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

  int N;
  cin >> N;
  VL xs(N);
  cin >> xs;

  VL acc(N+1), acc_b(N+1);
  REP(i,N) acc[i+1] = acc[i] + xs[i];
  for(int i=N-1;i>=0;--i)
	acc_b[i] = acc_b[i+1] + xs[i];

  vector<pair<LL,PLL>> div_f(N, MP(INF,MP(INF,INF))), div_b(N, MP(INF,MP(INF,INF)));
  REP(i,N){
	LL s = acc[i];
	LL s2 = s / 2;
	int ix = upper_bound(ALL(acc), s2) - begin(acc);
	if(ix == i) --ix;
	for(int d=0;d<3&&0<ix;++d,--ix){
	  mini(div_f[i], MP(abs(acc[i] - acc[ix] - acc[ix]), MP(acc[i]-acc[ix], acc[ix])));
	}
  }
  for(int i=N-1;i>=0;--i){
	LL s = acc_b[i];
	LL s2 = s / 2;
	int ix = upper_bound(RALL(acc_b), s2) - rbegin(acc_b);
	ix = N - 1 - ix;
	if(ix == i) ++ix;
	for(int d=0;d<3&&ix<N;++d,++ix){
	  mini(div_b[i], MP(abs(acc_b[i] - acc_b[ix] - acc_b[ix]), MP(acc_b[i] - acc_b[ix], acc_b[ix])));
	}
  }

  /*
  REP(i,N){
	cout << div_f[i] << " -- " << div_b[i] << endl;
  }
  */

  LL ans = INF;
  for(int i=2;i<=N-2;++i){
	auto t1 = div_f[i].SS;
	auto t2 = div_b[i].SS;
	LL mn = min({t1.FF, t1.SS, t2.FF, t2.SS});
	LL mx = max({t1.FF, t1.SS, t2.FF, t2.SS});
	mini(ans, mx - mn);
  }
cout << ans << endl;

  return 0;
}


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

#define N 25
#define NIL -1


typedef struct {
  int pare, sib, left, right;
}Node;

void Preorder(int);
void Inorder(int);
void Postorder(int);

Node node[N];
int n = 0;


int main () {
  
  int i, j, k = 0, m = 0, child = 0, x = 0, root = 0;

  scanf("%d", &n);


  for(i = 0 ; i < n ; i++) {
    node[i].pare = NIL;
    node[i].sib = NIL;
    node[i].left = NIL;
    node[i].right = NIL;
  }
  
  for(i = 0 ; i < n ; i++){
    
    scanf("%d",&m);

    for(j = 0 ; j < 2 ; j++) {
      scanf("%d",&child);
      if(j == 0) {
	x = child;
	node[m].left = child;
      }
      else {
	node[child].sib = x;
	node[x].sib = child;
	node[m].right = child;
      }
      node[child].pare = m;
    }
  }


  for(i = 0 ; i < n ; i++) {
    if(node[i].pare == NIL) root = i;
  }

  

  printf("Preorder\n");
  Preorder(root);
  printf("\n");

  printf("Inorder\n");
  Inorder(root);
  printf("\n");

  printf("Postorder\n");
  Postorder(root);
  printf("\n");
  
  return 0;
}


void Preorder(x) {

  if(x != NIL) {
    printf(" %d",x);
    Preorder(node[x].left);
    Preorder(node[x].right);
  }
    
}


void Inorder(x) {

  if(x != NIL) {
    Inorder(node[x].left);
    printf(" %d",x);
    Inorder(node[x].right);
  }
}


void Postorder(x) {

  if(x != NIL) {
    Postorder(node[x].left);
    Postorder(node[x].right);
    printf(" %d",x);
  }
}



Measured memory_bytes: 2052
#include<iostream>
#include<cstdio>
using namespace std;
inline int read(){
	char ch=getchar();int o=0;
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) o=(o<<3)+(o<<1)+(ch^48),ch=getchar();
	return o;
}
int n,ans;
int main(){
	n=read();
	if(n-n/2<=n/2) cout<<n/2-1<<endl;
	else cout<<n/2<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import math


def solve(A: int, B: int, H: int, M: int):
    ra = (H + M / 60.0) / 12.0 * 2.0 * math.pi
    rb = M / 60.0 * 2.0 * math.pi
    xa = A * math.cos(ra)
    ya = A * math.sin(ra)
    xb = B * math.cos(rb)
    yb = B * math.sin(rb)
    answer = math.sqrt((xb - xa) ** 2 + (yb - ya) ** 2)
    return answer


def main():
    A, B, H, M = map(int, input().split())
    answer = solve(A, B, H, M)
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9412
let input = require('fs').readFileSync('/dev/stdin', 'utf8')
// let input = require('fs').readFileSync('./sample_c.txt', 'utf8')
.split(/\n| /)
.slice(0 ,-1)
.map(item => parseInt(item))


const [L, ..._numbers] = input
const numbers = _numbers.map(BigInt)
const MOD = BigInt(1e9 + 7)

let sum = BigInt(0)
let base = numbers.reduce( (prev, item) => prev + item, BigInt(0))



for( let i=0; i<L; i++){
    base -= numbers[i]
    sum += base * numbers[i]
    sum %= MOD
}

console.log(Number(sum))

Measured memory_bytes: 81696
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), k = sc.nextInt();
		long res = k;
		for(int i = 1; i < n; i++){
			res *= k - 1;
			if(res > Math.pow(2, 31) - 1){
				System.out.println(Integer.MAX_VALUE);
				return;
			}
		}
		System.out.println(res);
		sc.close();			
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35728
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	int N, X, Y;
	cin >> N >> X >> Y;
	X--; Y--;
	vector<vector<int> > F(N, vector<int>(N, INF));
	for (int i = 0; i < N - 1; ++i) {
		F[i][i + 1] = 1;
		F[i + 1][i] = 1;
	}
	for (int i = 0; i < N; ++i) {
		F[i][i] = 0;
	}
	F[X][Y] = 1;
	F[Y][X] = 1;
	for (int i = 0; i < N; ++i) {
		for (int k = 1; k < N; ++k) {
			if (i + k > N - 1) {
				break;
			}
			int A, B,res;
			A = i;
			B = i + k;
			res = B - A;
			if (A <= X && Y <= B) {
				res = X-A+1+B-Y;
			}
			else if (X <= i && i + k <= Y) {
				if (res > A - X + 1 + Y - B) {//1 ==: X-Y
					res = A - X + 1 + Y - B;
				}
			}
			else if (X <= A && A <= Y) {
				if (res > A - X + 1 + B - Y) {
					res = A - X + 1 + B - Y;
				}
			}
			else if (X <= B && B <= Y) {
				if (res > X - A + 1 + Y - B) {
					res = X - A + 1 + Y - B;
				}
			}
			F[A][B] = res;
		}
	}
	vector<int> ans(N , 0);
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			//i<j
			ans[F[i][j]]++;
		}
	}
	for (int i = 1; i < N ; ++i) {
		cout << ans[i] << endl;
	}
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
    #define debug(...) printf(__VA_ARGS__)
#else
    #define debug(...) (void)0
#endif
#define mp make_pair
#define pb push_back
#define LL long long
#define pii pair<int,int>
#define PII pair<long long, long long>
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
const int inf = 0x7fffffff; //beware overflow
const LL INF = 0x7fffffffffffffff; //beware overflow
#define mem(x, y) memset(x, (y), sizeof(x) );
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) {
     return s<<"("<<p.first<<","<<p.second<<")";
}
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c) {
    s << "[ ";
    for (auto it : c) s << it << " ";
    s << "]";
    return s;
}
template<typename T>
ostream& operator << (ostream &o, const set<T> &st) {
    o << "{";
    for (auto it=st.begin(); it!=st.end(); it++) o << (it==st.begin() ? "" : ", ") << *it;
    return o << "}";
}
template<typename T1, typename T2>
ostream& operator << (ostream &o, const map<T1, T2> &mp) {
    o << "{";
    for (auto it=mp.begin(); it!=mp.end(); it++) {
        o << (it==mp.begin()?"":", ") << it->fi << ":" << it->se;
    }
    o << "}";
    return o;
}
inline LL getint(){
   LL _x=0,_tmp=1; char _tc=getchar();
   while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
   if( _tc == '-' ) _tc=getchar() , _tmp = -1;
   while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
   return _x*_tmp;
}
#define maxn 100005
int a[maxn];
LL ans=0;
int main() {
    int n, x;
    cin>>n>>x;;
    for(int i=0;i<n;i++)a[i]=getint();
    for(int i=1;i<n;i++) {
        int s = a[i]+a[i-1];
        if( s > x ) {
            ans += s-x;
            a[i] = max( a[i]-s+x, 0);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 200005;
ll A[MAX_N],B[MAX_N];

int main()
{
	int N;
	cin >> N;
	rep(i,N)
	{
		cin >> A[i] >> B[i];
	}
	sort(A,A+N);
	sort(B,B+N);
	if (N % 2 == 0)
	{
		cout << B[N/2-1]+B[N/2]-A[N/2-1]-A[N/2]+1 << endl;
	}
	else
	{
		cout << B[(N+1)/2-1] - A[(N+1)/2-1] + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 6716
# abc163_a.py
# https://atcoder.jp/contests/abc163/tasks/abc163_a

# A - Circle Pond /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# 半径 Rの円の周長を出力してください。

# 制約
#     1≤R≤100
#     入力は全て整数である。

# 入力
# 入力は以下の形式で標準入力から与えられます。
# R

# 出力
# 円の周長を出力せよ。 なお、想定解答との絶対誤差または相対誤差が 10−2以下であれば正解として扱われる。

# 入力例 1
# 1

# 出力例 1
# 6.28318530717958623200

# 10−2以下の絶対誤差・相対誤差が許容されるので、 6.28 も正解になりますが、6は不正解となります。

# 入力例 2
# 73

# 出力例 2
# 458.67252742410977361942


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    R = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = R * 2 * 3.141592653589793238

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['1']
        lines_export = [6.28318530717958623200]
    if pattern == 2:
        lines_input = ['73']
        lines_export = [458.67252742410977361942]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9200
($n, $m, $x, $y) = split(/ /, <>);

@empire_x = sort {$b <=> $a} split(/ /, <>);
@empire_y = sort {$a <=> $b} split(/ /, <>);

$r = "War";
for $i ($empire_x[0] + 1 .. $empire_y[0]){
	if(($x < $i) and ($y >= $i)){
		$r = "No War";
		last;
	}
}

print "$r\n";


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<pair<ll, ll>> AB(N);
  ll a, b;
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    AB[i] = {a, b};
  }
  sort(AB.begin(), AB.end());
  if (AB[N - 1].second == 0) {
    cout << AB[N - 1].first << endl;
  } else {
    cout << AB[N - 1].first + AB[N - 1].second << endl;
  }
  return 0;
}

Measured memory_bytes: 4852
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define stop char nyaa;cin>>nyaa;

string x[3] = { "Sunny","Cloudy","Rainy" };
void solve() {
	string s; cin >> s;
	rep(i, 3) {
		if (s == x[i]) {
			cout << x[(i + 1) % 3] << endl; return;
		}
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math
import itertools
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    x,a,b = inputMap()
    
    if abs(x-a) < abs(x-b):
        print("A")
    else:
        print("B")
    
    
if __name__ == "__main__":
	main()


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

const ll INF = 1e18;

struct edge{int to;ll cost;};
vector<edge> G[100000];

ll d0[100000],d1[100000],d2[1000000];
int V,E;

// 頂点rからの最小距離
void dijkstra(int r){
    fill(d0,d0+100000,INF);
    fill(d1,d1+100000,INF);
    fill(d2,d2+100000,INF);
    queue<int> q;
    q.push(r);
    d0[r] = 0;

    while(q.size()){
        int s = q.front();
        q.pop();

        for(int i = 0;i < G[s].size();i ++){
            int t = G[s][i].to;
            if(d0[s]+G[s][i].cost < d1[t]) {
                d1[t] = d0[s]+G[s][i].cost;
                q.push(t);
            }
            if(d1[s]+G[s][i].cost < d2[t]) {
                d2[t] = d1[s]+G[s][i].cost;
                q.push(t);
            }
            if(d2[s]+G[s][i].cost < d0[t]) {
                d0[t] = d2[s]+G[s][i].cost;
                q.push(t);
            }
        }
    }
}
int main(){
    cin >> V >> E;
    for(int i = 0;i < E;i ++){
        int u,v;
        cin >> u >> v;
        u --,v --;
        G[u].push_back({v,1});
    }
    int s,t;
    cin >> s >> t;
    s --,t --;
    dijkstra(s);
    cout << (d0[t]==INF?-1:d0[t]/3) << endl;
    return 0;
}

Measured memory_bytes: 9856
#include <stdio.h>

int main(void){
	int i, sequence_num, sequence[100], reverse[100];
	
	scanf("%d", &sequence_num);
	
	if(sequence_num > 100){
		puts("Array Number is Over.");
		return 0;
	}
	
	for(i = 0; i < sequence_num; i++){
		scanf("%d", &sequence[i]);
		reverse[sequence_num - (i + 1)] = sequence[i];
	}
	
	for(i = 0; i < sequence_num; i++){
		printf("%d", reverse[i]);
		if(i != (sequence_num - 1)){
			putchar(' ');
		}
	}
	putchar('\n');
	
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  char array[H][W];
  for (int i = 0; i < H; i++){
      for (int j = 0; j < W; j++){
        cin >> array[i][j];
      }
  }
  for (int i = 0; i < W + 2; i++){
    cout << "#" ;
  }
  cout << endl ;
  for (int i = 0; i < H; i++){
    cout << "#";
    for (int j = 0; j < W; j++){
      cout << array[i][j];
    }
    cout << "#" << endl;
  }
  for (int i = 0; i < W + 2; i++){
    cout << "#" ;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define N 100000
struct Node{
  int parent,left,right;
};
struct Node a[N],tmp;
void initialize(int n){
  int i;
  for (i =0;i<n;i++){
    a[i].parent = a[i].right = a[i].left = -1;
  }
}
int main(){
  int n;
 
  scanf("%d",&n);
  int i;
  initialize(n);
  int my,k,j,c,el;
  for(i=0;i<n;i++){
    scanf("%d %d",&my,&k);
      
    for(j=0;j<k;j++){
      scanf("%d",&c);
      if(j==0) a[my].left = c;
      else a[el].right = c;
      a[c].parent = my;
      el=c;
    }
  }
  int Parent,depth;
  for(i=0;i<n;i++){
    depth = 0;
    Parent = a[i].parent;
      
    while(Parent != -1){
      Parent = a[Parent].parent;
      depth++;
    }
      
    if(a[i].parent == -1){
      printf("node %d: parent = %d, depth = %d, root, [",
       i,a[i].parent,depth);
    }
    else if(a[i].left == -1) printf("node %d: parent = %d, depth = %d, leaf, [",i,a[i].parent,depth);
    else printf("node %d: parent = %d, depth = %d, internal node, [",i,a[i].parent,depth);
      
    Parent = a[i].left;
    if(Parent != -1) printf("%d",Parent);
      
    while(Parent != -1){
      Parent = a[Parent].right;
      if(Parent != -1) printf(", %d",Parent);
    }
    printf("]\n");
  }
  
  return 0;
}

Measured memory_bytes: 1784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
/* ちゃんと考えて実装して問題なくACできた時嬉しいよ！！ */


// Union-Find Tree
int par[100010];
int height[100010];

// n要素で初期化(親が自分自身で、高さ0)
void init_uf(int n){
    for(int i=0; i<n; i++){
        par[i] = i;
        height[i] = 0;
    }
}

// 親を見つける(再帰的)(記録して返す)
int find_par(int x){
    if(par[x] == x){
        return x;
    }
    else{
        return par[x] = find_par(par[x]);
    }
}

// 併合(根を共有させる)(heightに注意)
// 集合の情報は根っこにもたせてると考えてok
void unite(int x, int y){
    x = find_par(x);
    y = find_par(y);
    if(x == y) return;

    if(height[x] < height[y]){
        par[x] = y; // 高い方にいく
    }
    else{
        par[y] = x;
        // 高さ一緒だったら x の方が一段高くなる
        if(height[x] == height[y]) height[x]++;
    }
}

// 同グループかどうかの判定(根が等しいか)
bool same(int x, int y){
    return find_par(x) == find_par(y);
}

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

    // union find tree の初期化
    init_uf(n);

    
    for(int i=0; i<m; i++){
        int x,y,z;
        cin >> x >> y >> z;
        unite(x-1,y-1);
    }

    // 異なるグループの数を数える
    int ans = 0;
    for(int i=0; i<n; i++){
        if(par[i] == i) ans += 1;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    LL ans=0;
    REP1(i,1,n) {
        LL r=n/i;
        ans+=i*(1+r)*r/2;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int maxn = 3e5 + 10;
const int S = 7;
int n, m;
int id[maxn];
ll cnt[8], fac[maxn], ans = 1;
char s[maxn];
int main()
{
	id['R'] = 1; id['G'] = 2; id['B'] = 4;
	scanf("%d", &n);
	m = 3 * n;
	fac[0] = 1;
	for(int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % mod;
	scanf("%s", s + 1);
	for(int i = 1; i <= m; ++i)
	{
		bool match = 0;
		int cur = id[s[i]];
		for(int j = S - cur; j; j = (j - 1) & (S - cur))
			if(cnt[j])
			{
				match = 1;
				ans = ans * cnt[j] % mod;
				--cnt[j];
				if(cur + j != S) ++cnt[cur + j];
				break;
			}
		if(!match) ++cnt[cur];
	}
	ans = ans * fac[n] % mod;
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;

int main() {
  int r;
  string contest;
  cin >> r;
  if( r < 1200 )
    contest = "ABC";
  else if( r >= 1200 && r < 2800 )
    contest = "ARC";
  else
    contest = "AGC";
  cout << contest << endl;
  return 0;
}

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

int main()
{
	std::vector<int> train;

	std::vector<int> out;

	int n;

	while(std::cin >> n)
	{
		if(n!=0)
		{
			train.push_back(n);
		}
		else
		{
			out.push_back(train[train.size()-1]);

			train.pop_back();
		}
	}

	for(size_t i=0;i<out.size();++i)
	{
		std::cout << out[i] << '\n';
	}
}

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

A = list(map(int,input().split()))

"""

2べきになる条件は？
→片方が2の補数であること

Nが大きい→貪欲的に
最大の奴はそれより小さい奴としかペアを組めない
→大きい奴から貪欲にとっけいけばいける？

いけそうかなぁ
"""

A.sort()
dic = {}
lis = []

for i in range(N):
    
    if i == 0 or A[i-1] != A[i]:
        dic[A[i]] = 1
        lis.append(A[i])
    else:
        dic[A[i]] += 1

lis.reverse()
ans = 0
d2lis = {}
for i in range(32):
    d2lis[2**i] = i

import math

for i in lis:

    if i in d2lis:
        ans += dic[i]//2
        dic[i] %= 2
    else:
        t = 2 ** (int(math.log(i,2)) + 1)
        if t-i in dic:
            ans += min(dic[i],dic[t-i])
            dic[t-i] = max(0, dic[t-i]-dic[i])

print (ans)
        

Measured memory_bytes: 118612
using System;
using System.Linq;
public class Hello{
    public static void Main(){
        // Your code here!
        
        string s = Console.ReadLine();
        if(s=="SUN"){
            Console.WriteLine("7");
        }else if(s=="MON"){
            Console.WriteLine("6");
        }else if(s=="TUE"){
            Console.WriteLine("5");
        }else if(s=="WED"){
            Console.WriteLine("4");
        }else if(s=="THU"){
            Console.WriteLine("3");
        }else if(s=="FRI"){
            Console.WriteLine("2");
        }else if(s=="SAT"){
            Console.WriteLine("1");
        }
    }
}

Measured memory_bytes: 11092
#include<stdio.h>
int main(void){
   int W,H,x,y,r;
   scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

   if((r<=x) && (r<=y)){
   if((W>=(r+x)) && (H>=(r+y))){
      printf("Yes\n");
      return 0;
   }
   }
   
   printf("No\n");
   return 0;
}


Measured memory_bytes: 2108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        int N, H, maxA = 0, ans = 0, totalDamage = 0;
        int[] a, b;
        List<Integer> bLargerThanMaxA = new ArrayList<>();

        void solve(InputReader in, PrintWriter out) {
            N = in.nextInt();
            H = in.nextInt();
            a = new int[N];
            b = new int[N];

            for (int i = 0; i < N; i++) {
                a[i] = in.nextInt();
                b[i] = in.nextInt();
                maxA = Math.max(maxA, a[i]);
            }

            for (int i = 0; i < N; i++) {
                if (b[i] > maxA) bLargerThanMaxA.add(b[i]);
            }

            Collections.sort(bLargerThanMaxA, Collections.reverseOrder());

            for (int bCandidate : bLargerThanMaxA) {
                totalDamage += bCandidate;
                ans++;
                if (totalDamage >= H) break;
            }

            while (totalDamage < H) {
                totalDamage += maxA;
                ans++;
            }

            out.println(ans);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

        int[] nextIntArray(int n) {
        	int[] arr = new int[n];
        	for (int i = 0; i < n; ++i) {
        		arr[i] = nextInt();
        	}
        	return arr;
        }
    }
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int2(a, b);

    int ret = 0;
    if (a == b && a == 1) {
        cout << 300000 + 300000 + 400000 << endl;
        return 0;
    }
    if (a == 1) {
        ret += 300000;
    } else if (a == 2) {
        ret += 200000;
    } else if (a == 3) {
        ret += 100000;
    }

    if (b == 1) {
        ret += 300000;
    } else if (b == 2) {
        ret += 200000;
    } else if (b == 3) {
        ret += 100000;
    }


    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int n;
int k;
bool d[10];
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++)
	{
		int x;
		scanf("%d",&x);
		d[x]=true;
	}
	for(int i=n;;i++)
	{
		int t=i;
		bool f=true;
		while(t!=0)
		{
			if(d[t%10])
			{
				f=false;
				break;
			}
			t=t/10;
		}
		if(f)
		{
			printf("%d",i);
			return 0;
		}
	} 
	return 0;
} 

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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

int N,K;
signed main(){
    cin>>N>>K;
    string S;cin>>S;
    deque<int>d(N);
    rep(i,N)d[i]=S[i]=='B';

    bool rev=false;
    for(int i=0;i<555555&&K;i++,K--){
        if((d[0]^rev)==0){
            d[0]^=1;
            continue;
        }
        d.pop_front();
        rev^=1;
        d.push_back(rev);
    }
    
    K%=2;
    if(K){
            if((d[0]^rev)==0){
            d[0]^=1;
        }
        else{
        d.pop_front();
        rev^=1;
        d.push_back(rev);
        }
    }

    rep(i,N){
        if((d[i]^rev)==0)printf("A");
        else printf("B");
    }
    puts("");
    return 0;
}


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


int main(){
	int A, P;
	cin >> A >> P;
	cout << (A*3+P)/2 << endl;
}












Measured memory_bytes: 3596
n = int(input())

counter = 0

b_and_a = 0
first_b = 0
last_a = 0
for _ in range(n):
    w = input()
    counter += w.count("AB")

    if w[0] == "B" and w[-1] == "A":
        b_and_a += 1
    elif w[0] == "B":
        first_b += 1
    elif w[-1] == "A":
        last_a += 1
    else:
        pass

if b_and_a == 0:
    counter += min(first_b, last_a)
else:
    if b_and_a >= 2:
        counter += (b_and_a - 1)

    if first_b >= 1:
        counter += 1
        first_b -= 1
    if last_a >= 1:
        counter += 1
        last_a -= 1

    counter += min(first_b, last_a)

print(counter)



Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, K;
lint arr[200000];
lint sum = 0;
int main() {
	cin >> N >> K;
	REP(i, N) {
		cin >> arr[i];
	}
	REP(i, N - K) {
		if (arr[i] < arr[K + i]) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

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

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout if (false) cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力

#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"



void Main()
{
	int N;
	cin>>N;
	vec(v,10e5+1);
	int t=0;
	rep(i,N){
		cin>>t;
		v[t]++;
	}
	ll ans = 0;
	rep(i,10e5+1){
		ans += i*v[i];
	};

	int Q;
	cin>>Q;
	vec(A,Q);
	vec(B,Q);
	rep(i,Q){
		cin>>A[i]>>B[i];
	}
	dout<<_n2;
	rep(i,Q){
		ans -= (ll)A[i]*v[A[i]];
		ans += (ll)B[i]*v[A[i]];
//		dout<<_n<<"A[i]:"<<A[i]<<"\tv"<<v[A[i]]<<_n<<_t;
		v[B[i]] += v[A[i]];
		v[A[i]]=0;
		cout<<ans<<_n;
	}
}



int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 7868
/**
 * Title: D - Prediction and Restriction
 * Url: https://atcoder.jp/contests/abc149/tasks/abc149_d
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int win(char c, int r, int s, int p) {
    if(c=='r') return p;
    if(c=='s') return r;
    if(c=='p') return s;
}

char wint(char c) {
    if(c=='r') return 'p';
    if(c=='s') return 'r';
    if(c=='p') return 's';
}

int main() {
    int n, k; cin >> n >> k;
    int r, s, p; cin >> r >> s >> p;
    string t; cin >> t;
    string past;
    int ans = 0;
    for(int i=1; i<=n; i++) {
        // k番目以降
        if(i>k) {
            // 勝つための手
            char tmpt = wint(t[i-1]);

            // k回前にすでに出している時
            if(past[i-k-1]==tmpt) {
                if(past[i-k-1]=='r') {
                    // s, p が出せる
                    if(i+k<=n) {
                        // k回後に勝つための手
                        char tmp = t[i+k-1];
                        if(tmp == 'r') {
                            past += 's';
                        } else if (tmp == 's') {
                            past += 's';
                        } else {
                            past += 'p';
                        }
                    } else {
                        past += 's';
                    }
                } else if(past[i-k-1]=='s') {
                    // r, p が出せる
                    if(i+k<=n) {
                        // k回後に勝つための手
                        char tmp = t[i+k-1];
                        if(tmp == 'r') {
                            past += 'r';
                        } else if (tmp == 's') {
                            past += 'p';
                        } else {
                            past += 'r';
                        }
                    } else {
                        past += 'r';
                    }
                } else {
                    // r, s が出せる
                    if(i+k<=n) {
                        // k回後に勝つための手
                        char tmp = t[i+k-1];
                        if(tmp == 'r') {
                            past += 'r';
                        } else if (tmp == 's') {
                            past += 's';
                        } else {
                            past += 'r';
                        }
                    } else {
                        past += 's';
                    }
                }
            } else {
                ans += win(t[i-1], r, s, p);
                past += wint(t[i-1]);
            }
        } else {
            ans += win(t[i-1], r, s, p);
            past += wint(t[i-1]);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int x, y; cin >> x >> y;

    // a + b = x
    // 2a + 4b = y
    //
    // a = x - b

    for (int b = 0; 0 <= x - b; ++b) {
        int a = x - b;
        if (a * 2 + b * 4 == y) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}



Measured memory_bytes: 3516
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int mod = 1e9 + 7;

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

ll dp[100005][2]; //[current bit][taken lower?]

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	string l;
	cin >> l;
	int n = l.size();
	rep(i, 100005) rep(j, 2) dp[i][j] = 0LL;
	dp[0][1] = 1;
	dp[0][0] = 2; //either a or b
	repn(i, 1, n){
		if(l[i] == '1'){
			(dp[i][1] += (2 * (dp[i - 1][1]))) %= mod; //take
			(dp[i][1] += (dp[i - 1][1] + dp[i - 1][0])) %= mod; //not take
			(dp[i][0] += (2 * dp[i - 1][0])) %= mod; //take
			//(dp[i][0] += (dp[i - 1][0])) %= mod; //not take
		}
		else{
			(dp[i][1] += (2 * (dp[i - 1][1]))) %= mod; //take
			(dp[i][1] += dp[i - 1][1]) %= mod; //not take
			//(dp[i][0] += (2 * dp[i - 1][0])) %= mod; //take
			(dp[i][0] += (dp[i - 1][0])) %= mod; //not take
		}
	}
	cout << (dp[n - 1][1] + dp[n - 1][0]) % mod << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 2000
from functools import lru_cache


def popcnt(x):
    return bin(x).count("1")


@lru_cache(maxsize=None)
def rec(n):
    if n == 0:
        return 0
    else:
        return rec(n % popcnt(n)) + 1


n = int(input())
arr = input()

ALL_ARR = int(arr, 2)

# ALL_ARR mod popcnt±1を予め計算しておく
cnt = popcnt(int(arr, 2))
init_big = ALL_ARR % (cnt + 1)
if cnt == 1:
    init_small = 0
else:
    init_small = ALL_ARR % (cnt - 1)

# 変更部分だけ調整して剰余を再計算する
# 調整部分だけでも数が大きいためpowの引数modで高速化
li = [0] * n
for i in range(n):
    if arr[i] == "0":
        li[i] = (init_big + pow(2, n - i - 1, cnt + 1)) % (cnt + 1)

    # 0除算回避のためにフラグを立てておく
    elif ALL_ARR - (1 << (n - i - 1)) == 0 or cnt - 1 == 0:
        li[i] = "flg"
    else:
        li[i] = (init_small - pow(2, n - i - 1, cnt - 1)) % (cnt - 1)

ans = []

for x in li:
    if x == "flg":
        ans.append(0)
    else:
        ans.append(rec(x) + 1)

print(*ans, sep="\n")

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n;
  cin >> n;
  vector<pair<ll, ll>> x(n);
  rep(i, n) cin >> x[i].first >> x[i].second;

  double dist = 0, ans;
  ll dp[1000];
  dp[0] = 1;
  for (int i = 1; i <= n; ++i) dp[i] = dp[i - 1] * i;

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i == j) continue;
      dist += sqrt((x[i].first - x[j].first) * (x[i].first - x[j].first) +
                   (x[i].second - x[j].second) * (x[i].second - x[j].second));
      // cout << dist << endl;
    }
  }

  ans = dist * (n - 1) * dp[n - 2] / dp[n];
  cout << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n,k= map(int, input().split())
a= [list(map(int, input().split())) for i in range(k)]
s=[]


mod=998244353
# dp[i]:i番目のマスへの行き方
dp=[0]*(n+6)

for j in range(k):
    l = a[j][0]
    r = a[j][1]
    dp[l+1] += 1
    dp[r+2] -= 1


for i in range(1,n+1):
    dp[i+1]+=dp[i]
    dp[i+1]%=mod
    x=dp[i+1]
    for j in range(k):
        l=a[j][0]
        r=a[j][1]
        if l+i<=n:
            dp[i + l + 1] += x
        if r+i<=n:
            dp[i + 2 + r] -= x



print(dp[n]%mod)

Measured memory_bytes: 70036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！
const double pi = 3.14159265359;

int main() {
  ll A,B,H,M;
  cin >> A >> B >> H >> M;
  double wh = pi / 360.000000;
  double wm = pi / 30;
  double ans;

  double sita = abs(wh*(60*H+M) - wm*M);

  double ansans =  pow(A,2) + pow(B,2) - 2*A*B*cos(sita);
  
  ans = pow(ansans, 0.5);
  cout << fixed << setprecision(16) << ans << endl;
}

Measured memory_bytes: 4356
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;
typedef pair<long long, long long> pll;
// scanf("%d %d %d %d", &w, &b, &d, &s); %lld
// printf("%d\n", points);
// const double PI = acos(-1);

int main()
{
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    #else
        fastIO;
    #endif
        string s;
        int q, t, f;
        char c;
        bool rev = false;
        cin >> s >> q;
        while(q--){
            cin >> t;
            if(t==1)
                rev = rev == false;
            else{
                cin >> f >> c;
                if((f==1 && !rev) || (f==2 && rev))
                    s = c + s;
                else
                    s+=c;
            }
        }
        if(rev)
            reverse(all(s));
        cout << s << endl;
        return 0;
}

Measured memory_bytes: 4668
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include<iterator>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<ii> vii;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
/////////////////////////////////////////////////////////////////////
int main()
{
    long long n, A[10000], i, j, prime[2000000] = {0}, maxi = 0, maxp[1000001] = {0}, cnt;
    long long prod, sum, mod = 1000000007;
    
    vector<int> lcm, diff;
    cin >> n;
    vector<vector<int>> V(10000);
    for (i = 0; i < n; i++)
    {
        cin >> A[i];
        maxi = max(maxi, A[i]);
    }
    prime[1] = 1;
    for (i = 2; i <= maxi; i++)
    {
        if (prime[i] == 0)
        {
            prime[i] = i;
            for (j = i * i; j <= maxi; j += i)
            {
                if (prime[j] == 0)
                prime[j] = i;
            }
        }
    }
    for (i = 0; i < n; i++)
    {
        while(A[i] > 1)
        {
            V[i].push_back(prime[A[i]]);
            maxp[prime[A[i]]] = 1;
            A[i] /= prime[A[i]];
        }
    }
    for (i = 2; i < 1000000; i++)
    {
        maxi = 0;
        if (maxp[i] == 1)
        {
            for (j = 0; j < n; j++)
            {
                cnt = count(V[j].begin(), V[j].end(),i);
                maxi = max(maxi, cnt);
            }
            for (j = 0; j < maxi; j++)
            {
                lcm.push_back(i);
            }
        }
    }
    sum = 0;
    for (i = 0; i < n; i++)
    {
        set_difference(lcm.begin(), lcm.end(), V[i].begin(), V[i].end(), inserter(diff, diff.begin()));
        prod = 1;
        while (!diff.empty())
        {
            prod = (prod * diff.back()) % mod;;
            diff.pop_back();
        }
        sum = (sum + prod) % mod;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 24576
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>

using namespace std;
using ll = long long;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI = acos(-1.0);

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

int main() {
    int A, P; cin >> A >> P;

    int sum = 3 * A + P;

    cout << sum / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
#define chmax(x,y) (x = max(x, y))
void solve(); int main() { solve(); return 0; }

void solve() {
  string n; cin >> n;
  int cnt = 0;
  for (auto&&c:n) {
    cnt += c =='+';
  }
  cout << cnt - (4-cnt) << endl;
}

Measured memory_bytes: 3404
#include <iostream>
#include <string>
#define rep(i,n) for(long long i=0;i<n;i++)

using namespace std;
using ll = long long;

int main(void)
{
    int n;
    cin >> n;
    int a[3];
    a[0]=n%10;
    a[1]=((n-a[0])/10)%10;
    a[2]=(n-a[0]-10*a[1])/100;
    int s=0;
    rep(i,3) 
    {
        if(a[i]==7) s=1;
    }
    if(s==1) cout << "Yes" << endl;
    else cout << "No" <<endl;
    return 0;
}

Measured memory_bytes: 3632