akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=40;
int n,S;
char str[N];
ll sum;
map<pair<string,string>,int>dd;
int main(){
	int i;
	scanf("%d",&n);
	scanf("%s",str+1);
	for(S=0;S<1<<n;S++){
		string R="",B="";
		for(i=0;i<n;i++)((S>>i&1)?R:B)+=str[i+1];
		++dd[make_pair(R,B)];
	}
	for(S=0;S<1<<n;S++){
		string R="",B="";
		for(i=0;i<n;i++)((S>>i&1)?R:B)+=str[2*n-i];
		sum+=dd[make_pair(R,B)];
	}
	printf("%lld\n",sum);
}

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

int H, W;
const int inf = 1001001001;
const int dx[] = {-1, 0, 0, 1}, dy[] = {0, -1, 1, 0};

bool inside(int x, int y) {
  return (0 <= x && x < W && 0 <= y && y < H);
}

int main() {
  cin >> H >> W;

  vector<vector<char>> s(H, vector<char>(W));
  for (auto &i : s) {
    for (auto &j : i) cin >> j;
  }

  vector<vector<int>> d(H, vector<int>(W, inf));
  d[0][0] = 1;

  queue<pair<int, int>> q;
  q.push(make_pair(0, 0));

  while (!q.empty()) {
    int x = q.front().second;
    int y = q.front().first;
    q.pop();

    for (int i = 0; i < 4; ++i) {
      int nx = x + dx[i];
      int ny = y + dy[i];

      if (!inside(nx, ny)) continue;
      if (s[ny][nx] == '#') continue;

      if (d[ny][nx] > d[y][x] + 1) {
        d[ny][nx] = d[y][x] + 1;
        q.push(make_pair(ny, nx));
      }
    }
  }

  if (d.back().back() == inf) {
    cout << -1 << endl;
    return 0;
  }

  int ans = H * W - d.back().back();
  for (auto &i : s)
    for (auto &j : i)
      if (j == '#') ans--;

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
       int a,b,x;
       scanf("%d%d%d",&x,&a,&b);
       printf("%d",(x-a)%b);
       return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
 
 
 
#define NO "NO"
#define YES "YES"
typedef long long ll;
//---------------------------------------------------------------------------------------------------
ll N, A, B, C, D;
string solve() {
    ll d = abs(A - B);
 
    ll i = 0LL;
    while (i * 2LL <= N - 1LL) {
        ll ma = D * (N - 1LL - i * 2LL);
        ll mi = C * (N - 1LL - i * 2LL);
 
        ll mma = abs(C - D) * i;
 
        if (mi - mma <= d && d <= ma + mma) return YES;
 
        i++;
    }
    return NO;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> A >> B >> C >> D;
    cout << solve() << endl;
}

Measured memory_bytes: 256
def isKaibun(S):
    if S == S[::-1]:
        return True
    else:
        return False

inS = str(input()) 
N = len(inS)

if(isKaibun(inS) and isKaibun(inS[0:(N-1)//2]) and isKaibun(inS[(N+1)//2:N])):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
import numpy as np   
n,m = [int(i)for i in input().split()]

l = [[int(i)-1 for i in input().split()] for _ in range(m)]

line = np.array([1 for _ in range(n)])
is_red = np.zeros(n,dtype = np.int32)
is_red[0] = 1

for x,y in l:
    line[x] -= 1 if line[x] > 0 else 0
    line[y] += 1
    is_red[y] = 1 if is_red[x] == 1 else is_red[y]
    is_red[x] = is_red[x] if line[x] > 0 else 0
    

ans = np.count_nonzero(is_red[line > 0])

print(ans)
    

    


Measured memory_bytes: 31876
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
contest
son
---+/
/+:---test
contest
programming
---+/
/+:---test
contest
sentence
---+/

void main(string[] args) {
  const S = readln.chomp;
  const T = readln.chomp;

  const Sn = S.length;

  long[][] chpos;
  chpos.length = 'z'-'a';
  foreach (i, c; S) {
    chpos[c-'a'] ~= i;
  }

  long rotation;
  long offset;
  foreach (i, c; T) {
    auto pos = chpos[c-'a'].assumeSorted;
    if (pos.length == 0) {
      "-1".writeln;
      return;
    }

    auto upper_pos = pos.upperBound(offset-1);
    if (upper_pos.length > 0) {
      offset = upper_pos[0]+1;
    } else {
      offset = pos[0]+1;
      ++rotation;
    }
  }
  (rotation*Sn + offset).writeln;
}


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

int main(){
int N, Q;
string S;
  cin>>N>>Q>>S;
  
  vector<int>count(N+10);
  for(int i=1; i<N; i++){
   if(S.substr(i-1, 2)=="AC"){count[i+1]=count[i]+1;}
   else{count[i+1]=count[i];} 
  } // count[i]はi文字目までの"AC"の数
  
  int l,r;
  for(int i=0; i<Q; i++){
    cin>>l>>r;
    cout<<count[r]-count[l]<<endl;
  }  // l文字目までの"AC"の数からr文字目までの"AC"を引くと答えになる
}

Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int a;
    string s;
    cin >> a >> s;

    if(a >= 3200)
        cout << s << endl;
    else
        cout << "red" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	
	vector<ll> A(N);
	REP(i, N) scanf("%lld", &A[i]);
	
	ll X = 0;
	FOR(i, 2, N) X ^= A[i];
	ll S = A[0] + A[1];
	
	ll ans = 0;
	bool ng = false;
	
	ng |= S - X < 0 || S - X & 1;
	ll D = S - X >> 1;
	ng |= (X & D) > 0;
	
	if (!ng) {
		REP(i, 51) if (D >> i & 1 && ~X >> i & 1) ans += 1ll << i;
		for (int i = 50; i >= 0; --i) {
			if (~D >> i & 1 && X >> i & 1) {
				if (ans + (1ll << i) <= A[0]) ans += 1ll << i;
			}
		}
	}
	
	ng |= ans == 0 || ans > A[0];
	
	if (ng) ans = -1;
	else ans = A[0] - ans;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3660
#include <algorithm>
#include <functional>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <sstream>
using namespace std;

#define LL long long
#define LD long double
#define PR pair<int,int>

#define Min(a,b) a=min(a,b)
#define Max(a,b) a=max(a,b)
#define Sz(s) int((s).size())
#define All(s) (s).begin(),(s).end()
#define Fill(s,v) memset(s,v,sizeof(s))
#define pb push_back
#define mp make_pair
#define x first
#define y second

template<typename T> T Abs(T x) { return(x<0 ? -x : x); }
template<typename T> T Sqr(T x) { return(x*x); }

const int INF = (int)1e9;
const LD EPS = 1e-12;
const LD PI = acos(-1.0);



int N, M, L, R, l, r;

int main() {
	scanf("%d %d", &N, &M);
	scanf("%d %d", &L, &R);
	for (int i = 0; i < M-1; i++) {
		scanf("%d %d", &l, &r);
		Max(L, l);
		Min(R, r);
	}
	cout << max(0, R - L + 1) << endl;
}

Measured memory_bytes: 256
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ

int main(){
	int a,b;scanf("%d%d",&a,&b);
	printf("%d\n",a*(a-1)/2+b*(b-1)/2);
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n+1, 0);
  vector<ll> b(m+1, 0);
  for(int i = 1; i <= n; i++){
    if(i != 0) a[i] = a[i-1];
    ll t; cin >> t;
    a[i] += t;
  }
  for(int i = 1; i <= m; i++){
    if(i != 0) b[i] = b[i-1];
    ll t; cin >> t;
    b[i] += t;
  }
  int ans = 0;
  for(int i = 0; i <= n; i++){
    int ansa, ansb;
    if(a[i] > k) break;
    ansa = i;
    ansb = upper_bound(b.begin(), b.end(), k - a[i]) - b.begin() - 1;
    ans = max(ansa + ansb, ans);
  }
  cout << ans << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 6400
// C - *3 or /2

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	int ans = 0;

	for (int i=0; i<N; i++) {
		int a;
		cin >> a;
		while(a % 2 == 0) {
			ans++;
			a /= 2;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3552
<?php
  

$abc = explode(" ",trim(fgets(STDIN)));
fscanf(STDIN,"%d",$k);

rsort($abc);
$bai = $abc[0];

for($i=0;$i<$k;$i++){
  $bai = $bai*2;
}

$sum = $bai +$abc[1]+$abc[2];

echo $sum."\n";

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

int main(){
    double N;
    double K=0;
    cin >> N;
    
    for(int i=0; i<N; i++){
        if(i%2 == 0) K++;
    }
    cout << K/N <<endl;
    
    return 0;
}

Measured memory_bytes: 256
let iota ?(start=0) ?(step=1) cnt =
  let rec doit i acc =
    if i <= 0 then acc
    else doit (i - 1) (start + step*(i - 1) :: acc) in
  doit cnt []

let rec solve (n, s) =
  let rec doit = function
    | (0, 0, _) -> 1
    | (0, _, _) -> 0
    | (n, s, lst) ->
      List.map (fun e ->
        doit (n - 1, s - e, List.filter (fun x -> x > e) lst))
        lst
      |> List.fold_left (+) 0 in
  doit (n, s, iota 10)

let () =
  let rec main_loop () =
    let (n, s) = Scanf.scanf "%d %d " (fun n s -> n, s) in
    if n = 0 && s = 0 then ()
    else begin
      solve (n, s) |> Printf.printf "%d\n";
      main_loop ()
    end in
  main_loop ()

Measured memory_bytes: 4368
#include <bits/stdc++.h>
using namespace std;
int n;
int a[109];
bool rsn(int h){
	bool f=0;
	for(int i=0;i<n;i++){
		if(a[i]==h){
			f=1;
		}
	}
	return f;
}
int main() {
	int x;
	cin>>x>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int k=x;
	while(1){
		if(!rsn(k))break;
		k--;
	}
	int l=x;
	while(1){
		if(!rsn(l))break;
		l++;
	}
	if((x-k)<=(l-x))
	cout<<k;
	if((x-k)>(l-x))
	cout<<l;
	return 0;
}

Measured memory_bytes: 3632
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int a,b;

  cin >> a >> b;

  if(a <=5) cout << 0;
  else if(a <= 12) cout << b / 2;
  else  cout << b;

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}

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

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

const ll mod = 1000000007;
const int N = 100005;

ll fac[N], ifac[N], inv[N];

void pre(){
	fac[0] = ifac[0] = fac[1] = ifac[1] = inv[1] = 1;
	for(int i = 2; i < N; i++){
		fac[i] = (fac[i - 1]*i)%mod;
		inv[i] = (mod - mod/i)*inv[mod%i]%mod;
		ifac[i] = (ifac[i - 1]*inv[i])%mod;
	}
}

inline ll ncr(int n, int r){
	if(r < 0 || r > n)return 0;
	return fac[n]*(ifac[r]*ifac[n - r]%mod)%mod;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	pre();
	int n; cin>>n;
	vector<int> a(n + 1);
	vector<int> vis(n, - 1);
	int pos1, pos2;
	for(int i = 0; i <= n; i++){
		cin>>a[i]; a[i]--;
		if(vis[a[i]] != -1){
			pos1 = vis[a[i]];
			pos2 = i;
		}else{
			vis[a[i]] = i;
		}
	}
	int m = n - pos2 + pos1;
	for(int k = 1; k <= n + 1; k++){
		ll ans = ncr(n + 1, k);
		ans += mod - ncr(m, k - 1);
		if(ans >= mod)ans -= mod;
		cout<<ans<<'\n';
	}

	return 0;
}

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

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

double EPS = 1e-10;
double PI = acos(-1.0);

double add(double a, double b) {
  if (abs(a + b) < EPS * (abs(a) + abs(b))) return 0;
  return a + b;
}

struct P {
  double x, y;
  P() {}
  P(double x, double y) : x(x), y(y) {}
  P operator+(P p) {
    return P(add(x, p.x), add(y, p.y));
  }
  P operator-(P p) {
    return P(add(x, -p.x), add(y, -p.y));
  }
  P operator*(double d) {
    return P(x * d, y * d);
  }
  double dot(P p) {
    return add(x * p.x, y * p.y);
  }
  double det(P p) {
    return add(x * p.y, -y * p.x);
  }
  double abs() {
    return sqrt(add(x * x, y * y));
  }
  P rotate90() {
    return P(y, -x);
  }
  bool operator==(P& p) {
    return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
  }
};

bool cmp_x(const P& p, const P& q) {
  if (p.x != q.x) return p.x < q.x;
  return p.y < q.y;
}

vector<P> convex_hull(vector<P> ps, int n) {
  sort(ps.begin(), ps.end(), cmp_x);
  int k = 0;
  vector<P> qs(n * 2);
  for (int i = 0; i < n; i++) {
    while (k > 1 && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0) k--;
    qs[k++] = ps[i];
  }
  for (int i = n - 2, t = k; i >= 0; i--) {
    while (k > t && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0) k--;
    qs[k++] = ps[i];
  }
  qs.resize(k - 1);
  return qs;
}

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

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

  vector<P> b = convex_hull(a, N);
  int bz = b.size();
  vector<double> ans(N, 0.0);
  for (int i = 0; i < N; i++) {
    int id = -1;
    for (int j = 0; j < bz; j++) {
      if (b[j] == a[i]) id = j;
    }
    if (id < 0) continue;
    P L = (b[id == 0 ? bz - 1 : id - 1] - b[id]).rotate90();
    P R = (b[id == bz - 1 ? 0 : id + 1] - b[id]).rotate90();
    ans[i] = bz == 2 ? 0.5 : (PI - acos(L.dot(R) / L.abs() / R.abs())) / 2 / PI;
  }

  for (int i = 0; i < N; i++) {
    printf("%.10f\n", ans[i]);
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int N; ll _A[1010];
ll* A;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> _A[i];
    A = _A;

    ll ans = -infl;
    rep(i, 0, N) chmax(ans, A[i]);

    vector<int> buf;

    if (ans <= 0) {
        // コーナーケース
        printf("%lld\n", ans);
        int idx = -1;
        rep(i, 0, N) if (A[i] == ans) idx = i;
        rep(i, 0, N - idx - 1) buf.push_back(N - 1 - i);
        rep(i, 0, idx) buf.push_back(0);
        int n = buf.size();
        printf("%d\n", n);
        rep(i, 0, n) printf("%d\n", buf[i] + 1);
        return;
    }

    ll sm[2] = { 0, 0 };
    rep(i, 0, N) if (0 < A[i]) sm[i % 2] += A[i];
    
    if (sm[0] < sm[1]) {
        ans = sm[1];
        buf.push_back(0);
        N--;
        A++;
    } else ans = sm[0];

    if (N % 2 == 0) {
        buf.push_back(N - 1);
        N--;
    }

    while (A[0] <= 0) {
        buf.push_back(0);
        buf.push_back(0);
        A += 2;
        N -= 2;
    }

    while (A[N - 1] <= 0) {
        buf.push_back(N - 1);
        N--;
        buf.push_back(N - 1);
        N--;
    }

    int pre = 0, cnt = 0;
    for (int i = 0; i < N; i += 2) {
        if (A[i] <= 0) {
            buf.push_back(i + pre);
            pre -= 2;
        } else cnt++;
    }

    rep(i, 0, cnt - 1) {
        buf.push_back(1);
    }

    int n = buf.size();
    printf("%lld\n%d\n", ans,n);
    rep(i, 0, n) printf("%d\n", buf[i] + 1);
    printf("\n");
}

Measured memory_bytes: 256
from sys import stdin
input = int(stdin.readline().rstrip())
# search_area = int(input / 2) + 1
search_area = 1
tf = True
output = (input - 1)
while(tf):
    if (input % search_area) == 0:
        output_temp = int(search_area + (input / search_area) - 2)
        if output > output_temp:
            output = output_temp
    search_area += 1
    if search_area > (input)**(1/2) + 1:
        tf = False

print(output)


Measured memory_bytes: 3188
#include       <set>
#include       <map>
#include     <queue>
#include     <cmath>
#include    <cstdio>
#include    <cctype>
#include    <vector>
#include   <cstring>
#include <algorithm>
using namespace std;

typedef long long ll;
const ll mod = 1e9+7;
const double eps = 1e-7;
const int maxn = 100005;

ll fast_pow(ll a,ll b,ll mod){
    ll ans = 1;
    while(b){
        if(b&1)
            ans = ans*a%mod;
        a = a*a%mod;
        b>>=1;
    }
    return ans;
}

int main(){
    char str[55], ptr[55];
    memset(str,0,sizeof(str));
    memset(ptr,0,sizeof(ptr));
    scanf("%s%s",str,ptr);
    for(int i=0;str[i]||ptr[i];i++){
        if(str[i])putchar(str[i]);
        if(ptr[i])putchar(ptr[i]);
    }
    return 0;
}


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

using namespace std;

int main(void){
  int n, m, l, a[100][100], b[100][100];
  scanf("%d %d %d", &n, &m, &l);

  for(int i = 0;i < n;++i){
    for(int j = 0;j < m;++j){
      scanf("%d", &a[i][j]);
    }
  }

  for(int i = 0;i < m;++i){
    for(int j = 0;j < l;++j){
      scanf("%d", &b[i][j]);
    }
  }

  for(int i = 0;i < n;++i){
    for(int j = 0;j < l;++j){
      long long int c = 0;
      for(int k = 0;k < m;++k){
        c += a[i][k] * b[k][j];
      }
      if(j == l - 1){
        printf("%lld\n", c);
      }else{
        printf("%lld ", c);
      }
    }
  }

  return 0;
}



Measured memory_bytes: 3276
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int x,a;
  cin>>x>>a;
  if(x<a){
    cout<<0;
  }else{
    cout<<10;
  }
}

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

int main(void) {
  vector<int> v(2);
  cin >> v[0] >> v[1];
  if (find(v.begin(), v.end(), 1) == v.end()) {
    cout << 1 << endl;
  } else if (find(v.begin(), v.end(), 2) == v.end()) {
    cout << 2 << endl;
  } else {
    cout << 3 << endl;
  }

  return 0;
}

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

#include <string>

using namespace std;

int main() {
    int n;
    int m;
 
   cin >> n >> m;
  
   int ans = 0;
  
   for(int i = n;i<=m;i++){
     
     string a = to_string(i);
     
     
     if(a[0]==a[4]&&a[1]==a[3]){
       
       ans = ans + 1;
     }
     
     
   }
  
  
  
  
   cout << ans << endl;
 
  
  return 0;
}

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

public class Main {

	/* several useful subroutines */
	private static final BigDecimal BD1000000007 = new BigDecimal(1000000007);
	private static BufferedReader brStdin = new BufferedReader(new InputStreamReader(System.in));
	private static String[] readBuf = null;
	private static int readPtr = 0;
	private static String getString() throws IOException {
		while ( readBuf == null || readPtr >= readBuf.length ) {
			readBuf = brStdin.readLine().split(" ");
			readPtr = 0;
		}
		return readBuf[readPtr++];
	}
	private static int getInt() throws IOException {
		return Integer.parseInt(getString());
	}
	private static long getLong() throws IOException {
		return Long.parseLong(getString());
	}
	private static BigDecimal getBD() throws IOException {
		return new BigDecimal(getString());
	}
	@SuppressWarnings("unused")
	private static String[] getStringArray(int size) throws IOException {
		String stringArray[] = new String[size];
		for (int i = 0; i < stringArray.length; i++) {
			stringArray[i] = getString();
		}
		return stringArray;
	}
	@SuppressWarnings("unused")
	private static int[] getIntArray(int size) throws IOException {
		int intArray[] = new int[size];
		for (int i = 0; i < intArray.length; i++) {
			intArray[i] = getInt();
		}
		return intArray;
	}
	@SuppressWarnings("unused")
	private static long[] getLongArray(int size) throws IOException {
		long longArray[] = new long[size];
		for (int i = 0; i < longArray.length; i++) {
			longArray[i] = getLong();
		}
		return longArray;
	}
	@SuppressWarnings("unused")
	private static BigDecimal[] getBDArray(int size) throws IOException {
		BigDecimal bdArray[] = new BigDecimal[size];
		for (int i = 0; i < bdArray.length; i++) {
			bdArray[i] = getBD();
		}
		return bdArray;
	}
	private static BigDecimal mod1000000007(BigDecimal bd) {
		return bd.subtract(BD1000000007.multiply(bd.divide(BD1000000007, BigDecimal.ROUND_DOWN))) ;
	}
	@SuppressWarnings("unused")
	private static BigDecimal mod1000000007(int i) {
		return mod1000000007(new BigDecimal(i)) ;
	}
	@SuppressWarnings("unused")
	private static BigDecimal mod1000000007(long l) {
		return mod1000000007(new BigDecimal(l)) ;
	}

	
	/* main routine */
	public static void main(String args[]) throws IOException {
		long n = getLong();
		--n;
		long ans = (1L+n) * n / 2L;
		System.out.println(ans);
	}
}


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

int main(){
    int N;cin>>N;
    vector<string> s(N);
    int c1=0,c2=0,c3=0,m=0;
    REP(i,N){
        cin>>s[i];
        int l= (s[i][0]=='B')?1:0;
        int r= (s[i].back()=='A')?1:0;
        
        c1+=(l&r);
        c2+=l-(l&r);
        c3+=r-(l&r);
        REP(j,s[i].size()-1){
            if(s[i].substr(j,2)=="AB") m++;
        }
    }
    if(c2==0){
        if(c3==0) cout<<m+(c1?c1:1)-1<<endl;
        else cout<<m+c1<<endl;
    }
    else if(c3==0) cout<<m+c1<<endl;
    else cout<<m+c1+min(c2,c3)<<endl;
}

Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#define Max zhi5968
typedef long long ll;
using namespace std;

int main ()
{
	int a,ans=0;
	cin>>a;
	int t=a;
	while(t%10==0)
	{
		t=t/10;
	} 
	while(a)
	{
		ans+=a%10;
		a/=10;
	}
	if(t==1)
		cout<<"10"<<endl;
	else
		cout<<ans<<endl;
	return 0;
}

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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  string s;
  cin >> s;
  int a = s[0]-'0';
  int b = s[1]-'0';
  int c = s[2]-'0';
  int d = s[3]-'0';
  int ab = a*10+b;
  int cd = c*10+d;
  if(1<=ab && ab<=12){
    if(1<=cd && cd<=12){
      cout << "AMBIGUOUS" << endl;
    }else{
      cout << "MMYY" << endl;
    }
  }else{
    if(1<=cd && cd<=12){
      cout << "YYMM" << endl;
    }else{
      cout << "NA" << endl;
    }
  }
}

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

struct node{
  int key;
  struct node *next,*prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int);
void init(void);
void printList(void);
void deleteNode(NodePointer);
void deleteFirst(void);
void deleteLast(void);
void deleteKey(int);
void insert(int);

int main(){
  int key,N,i;
  int size = 0;
  char com[20];
  int np=0,nd=0;

  scanf("%d",&N);

  init();

  for(i=0;i<N;i++){
    scanf("%s%d",com,&key);

    if(com[0]=='i'){
      insert(key);
      np++;
      size++;
    }
    else if(com[0]=='d'){

      if(strlen(com) > 6){

        if(com[6]=='F')deleteFirst();
        else if(com[6]=='L')deleteLast();
      }

      else {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }

  printList();

  return 0;
}

NodePointer listSearch(int key){
  NodePointer cur;

  cur = nil->next;

  while(cur != nil && cur->key != key){
    cur = cur->next;
  }

  return cur;
}

void init(void){
  nil = (NodePointer)malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(void){
  NodePointer cur;
  int isf = 0;
  
  cur = nil->next;

  while(1){
    if(cur==nil)break;
    if(isf++>0)printf(" ");
    printf("%d",cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t==nil)return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(void){
  deleteNode(nil->next);
}

void deleteLast(void){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

void insert(int key){
  NodePointer x;

  x = (NodePointer)malloc(sizeof(struct node));
  x->key = key;

  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}



Measured memory_bytes: 33104
#include <stdio.h>
#include <math.h>
#define maxn 65
#define eps 1e-8
double x[maxn],y[maxn],c[maxn],X[65*65*2],Y[65*65*2],r[maxn];
int tot,N,K;
double dis(double x,double y,double c,double X,double Y){
	return c*sqrt((X-x)*(X-x)+(Y-y)*(Y-y));
}
void cal(double x1,double y1,double r1,double x2,double y2,double r2){//计算两圆交点坐标
	double D;//A=a*a,H=h*h,D=d*d;
	double ad,h;//ad=a*d;
	D=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
	if(D==0)return;
	ad=(r1*r1+D-r2*r2)/2;//2*a*d=r1*r1+D-r2*r2
	h=D*r1*r1-ad*ad;
	if(h<0)return;//漏了此句的判定
	h=sqrt(h);
	tot++,X[tot]=x1+ad*(x2-x1)/D-(y2-y1)*h/D,Y[tot]=y1+ad*(y2-y1)/D+(x2-x1)*h/D;
	tot++,X[tot]=x1+ad*(x2-x1)/D+(y2-y1)*h/D,Y[tot]=y1+ad*(y2-y1)/D-(x2-x1)*h/D;
}
int judge(double t){
	int i,j,cnt;
	for(i=1;i<=N;i++)r[i]=t/c[i];
	tot=0;
	for(i=1;i<=N;i++){//计算出不同圆之间的交点坐标
		tot++,X[tot]=x[i],Y[tot]=y[i];//别忘了将圆心坐标放入交点坐标//此处错写成tot++,X[i]=x[i],Y[i]=y[i];
		for(j=i+1;j<=N;j++)
			cal(x[i],y[i],r[i],x[j],y[j],r[j]);
	}
	for(i=1;i<=tot;i++){
		cnt=0;
		for(j=1;j<=N;j++)
			if(dis(x[j],y[j],c[j],X[i],Y[i])<t+eps)cnt++;//浮点比大小无等于的情况，这是由浮点误差决定的。
		if(cnt>=K)return 1;
	}
	return 0;
}
int main(){
	double l,r,mid;
	int i;
	scanf("%d%d",&N,&K);
	for(i=1;i<=N;i++)scanf("%lf%lf%lf",&x[i],&y[i],&c[i]);
	l=0,r=1000010;
	while(l+eps<r){
		mid=(l+r)/2;
		if(judge(mid))r=mid;
		else l=mid;
	}
	printf("%.6f\n",r);
	return 0;
}

Measured memory_bytes: 384
"""bit全探索"""

ticket = tuple(map(int, input()))
res = []

for i in range(8, 16):
    s = ticket[0]
    equation = str(s)
    for j in range(1, 4):
        if int(bin(i)[-j]):
            s += ticket[j]
            equation += "+" + str(ticket[j])
        else:
            s -= ticket[j]
            equation += "-" + str(ticket[j])

    if s == 7:
        equation += "=7"
        res.append(equation)

print(res[0])


Measured memory_bytes: 3064
char s[100][101];h;r[100],R,c[100],C,i,j,x;
main(w){scanf("%d%d",&h,&w);for(i=h;i--;){scanf("%s",s[i]);
x=0;for(j=w;j--;x+='.'-s[i][j]);if(x)r[R++]=i;}
for(j=w;j--;){x=0;for(i=h;i--;)if(s[i][j]=='#')x=1;if(x)c[C++]=j;}
for(i=0;i<R;i++){for(j=C;j--;)putchar(s[r[i]][c[j]]);puts("");}
}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF /*1000000007*/ 1000000000000000003
#define MOD 1000000007

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;

using namespace std;
using P = pair<long long, long long>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;
	
	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

int main() {

	ll H, W, N;
	cin >> H >> W >> N;

	map<P, ll>m;
	for (int i = 0; i < N;++i) {
		int a, b;
		cin >> a >> b;
		if (a + 2 <= H && b + 2 <= W)m[make_pair(a, b)]++;//左上
		if (a + 2 <= H && 0 < b - 1 && b + 1 <= W)m[make_pair(a, b - 1)]++;//上中央
		if (a + 2 <= H && 0 < b - 2)m[make_pair(a, b - 2)]++;//右上
		if (a + 1 <= H && 0 < a - 1 && b + 2 <= W)m[make_pair(a - 1, b)]++;//左
		if (a + 1 <= H && 0 < a - 1 && 0 < b - 1 && b + 1 <= W)m[make_pair(a - 1, b - 1)]++;//中央
		if (a + 1 <= H && 0 < a - 1 && 0 < b - 2)m[make_pair(a - 1, b - 2)]++;//右
		if (0 < a - 2 && b + 2 <= W)m[make_pair(a - 2, b)]++;//左下
		if (0 < a - 2 && 0 < b - 1 && b + 1 <= W)m[make_pair(a - 2, b - 1)]++;//中央下
		if (0 < a - 2 && 0 < b - 2)m[make_pair(a - 2, b - 2)]++;//右下
	}

	vector<ll>ans(10, 0);
	ans[0] = (H-2)*(W-2) - m.size();
	for (auto s : m) {
		ans[s.second]++;
	}
	for (int i = 0; i < 10; ++i)cout << ans[i] << endl;
}

Measured memory_bytes: 56448
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




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

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  while(1){
    ll n,r;cin>>n>>r;
    if(n==0 && r==0) break;
    ll a[n];
    rep(i,n) a[i]=0;
    ll tmp=r;
    ll cur=0;
    while(1){
      if(tmp>0){
        a[cur]++;
        tmp--;
        if(a[cur]==r){
          cout<<cur<<endl;
          break;
        }
      }else if(a[cur]>0){
        tmp=a[cur];
        a[cur]=0;
      }
      cur++;
      cur%=n;
    }
  }
}


Measured memory_bytes: 3216
#include <stdio.h>

long calc(int max, int count) {
  int i;
  long mx = 0, mn = 0;
  for(i = 0;i < count;i++) {
    mn += i;
    mx += max - i;
  }
  return mx - mn + 1;
}

int main(void) {
  int n, k;
  
  scanf("%d %d", &n, &k);
  if(k > n) {
    printf("1\n");
    return 0;
  }
  int i;
  long ret = 0;
  for(i = k;i <= n + 1;i++) {
    ret += calc(n, i);
  }
  ret %= 1000000007;
  printf("%ld\n", ret);
  return 0;
}
  

Measured memory_bytes: 2152
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	map<int,int>ma;
	rep(i,n){
		int a;cin>>a;
		ma[a]++;
	}		
	int m;
	bool h=true;
	cin>>m;
	rep(i,m){
		int a;cin>>a;
		if(ma[a]){
			ma[a]--;
		}else h=false;
	}
	if(h)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}



Measured memory_bytes: 9600
#include <stdio.h>

int main (){
    int a;
    scanf("%d", &a);
    int pangkat;
    int sum=0;

    for(int i =0; i <= a; i++){
    pangkat = a * a;
    sum = sum + pangkat;
    }
    printf("%d\n", sum+a);
    return 0;
}

Measured memory_bytes: 1736
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [0]*q
c = [0]*q
for i in range(q):
    b[i], c[i] = map(int, input().split())

sum_i = 0
map_ai = [0]*100001
for ai in a:
    sum_i += ai
    map_ai[ai] += 1

for i in range(q):
    bi = b[i]
    ci = c[i]
    num_bi = map_ai[bi]
    sum_i -= (bi-ci) * num_bi
    print(sum_i)
    map_ai[bi] -= num_bi
    map_ai[ci] += num_bi


Measured memory_bytes: 84668
# include <iostream>
# include <stdio.h>
# include <cstring>
using namespace std;
int main(){
  char s1[100],s2[200],p[100];
  scanf("%s %s",s1,p);
  strcpy(s2,s1);
  strcat(s2,s1);
  // printf("%s \n",s2);
  if(strstr(s2,p) == NULL) printf("No\n");
  else printf("Yes\n" );
  return 0;
}


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
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 = (1 << 30) - 1;
const ll INFL = 1LL << 60;
const ll mod = 998244353;




int main() {

	int n;
	cin >> n;

	VLL a(n);
	REP(i, n) {
		cin >> a[i];
	}

	sort(ALL(a));
	reverse(ALL(a));

	ll ans = 0;

	FOR(i, 1, n) {
		ans += a[i / 2];
	}
	cout << ans << endl;



}

Measured memory_bytes: 4840
import itertools
import math

n = int(input())
p = [tuple(map(int, input().split())) for _ in range(n)]

s = 0
c = list(itertools.permutations(p, n))
for v in c:
    for i in range(n - 1):
        s += math.sqrt((v[i + 1][0] - v[i][0]) ** 2 + (v[i + 1][1] - v[i][1]) ** 2)
print(s * 1.0 / len(c))

Measured memory_bytes: 7972
import Control.Monad
import Data.Array
import Data.Array.Unboxed as UA
import Data.Array.ST
import Control.Monad.ST
import qualified Data.ByteString.Char8 as B

main=B.interact $ B.pack.f.take 2.B.lines

f [s,t]=mk "" (ls-1) (lt-1) where
    ls = B.length s
    lt = B.length t
    mk as si ti
        | si<0 || ti<0 = as
        | B.index s si == B.index t ti = mk (B.index s si:as) (si-1) (ti-1)
        | aa UA.! (si+1,ti)>aa UA.! (si,ti+1) = mk as si (ti-1)
        | otherwise = mk as (si-1) ti
    aa :: UA.UArray (Int,Int) Int
    aa = runSTUArray $ do
        dp <- newArray ((0,0),(ls,lt)) 0 :: ST s (STUArray s (Int,Int) Int)
        forM_ [(i,j)|i<-[1..ls], j<-[1..lt]] $ \(i,j)->
            if B.index s (i-1) == B.index t (j-1)
                then writeArray dp (i,j) =<< (+1) <$> readArray dp (i-1,j-1)
                else writeArray dp (i,j) =<< max <$> readArray dp (i-1,j) <*> readArray dp (i,j-1)
        return dp

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

int main() {
  double n;
  cin >> n;
  int intans = n / 1.08;
  int subint = (intans + 1) * 1.08;
  if (intans * 1.08 == n)
    cout << intans << endl;
  else if (subint == n)
    cout << intans+1 << endl;
  else
    cout << ":(" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll a,b; char x; cin >> a >> x >> b;
  if(x == '+'){
    cout << a+b;
  }
  else{
    cout << a-b;
  }
}

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

int main()
{
  int n;
  cin>>n;
  int* d = new int[n];
  for(int i=0;i<n;i++)
    cin>>d[i];
  
  sort(d,d+n);
  int x = d[n/2], y = d[n/2 - 1];
  cout<<x-y<<endl;
  return 0;
}
  

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) v.erase(remove(v.begin(), v.end(), a), v.end())
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

vector<int> car[200000];
vector<int> train[200000];

int car_id[200001];
int train_id[200001];

vector<int> car_vec[200001];

int flg[200001];
int id_list[200001];
int id_cnt[200001];
int id_table[200000];

signed main()
{
	int N, K, L;
	cin >> N >> K >> L;

	REP(i, K)
	{
		int p, q;
		cin >> p >> q;
		car[p - 1].push_back(q - 1);
		car[q - 1].push_back(p - 1);
	}

	REP(i, L)
	{
		int p, q;
		cin >> p >> q;
		train[p - 1].push_back(q - 1);
		train[q - 1].push_back(p - 1);
	}

	int cid_max = 1;
	REP(i, N)
	{
		if (car_id[i] > 0) continue;
		queue<int> q;
		q.push(i);
		car_id[i] = cid_max;
		car_vec[cid_max].push_back(i);
		while (q.size() > 0)
		{
			int size = q.size();
			REP(j, size)
			{
				int p = q.front();
				q.pop();
				for (int c : car[p])
				{
					if (car_id[c] > 0) continue;
					car_id[c] = cid_max;
					q.push(c);
					car_vec[cid_max].push_back(c);
				}
			}
		}
		cid_max++;
	}
	cid_max--;

	int id = 1;
	REP(i, N)
	{
		if (train_id[i] > 0) continue;
		queue<int> q;
		q.push(i);
		train_id[i] = id;
		while (q.size() > 0)
		{
			int size = q.size();
			REP(j, size)
			{
				int p = q.front();
				q.pop();
				for (int t : train[p])
				{
					if (train_id[t] > 0) continue;
					train_id[t] = id;
					q.push(t);
				}
			}
		}
		id++;
	}

	id = 0;
	for (int i = 0; i < cid_max; i++)
	{
		int cid = i + 1;
		for (int j : car_vec[cid])
		{
			int tid = train_id[j];
			if (flg[tid] != cid)
			{
				id++;
				id_list[tid] = id;
				flg[tid] = cid;
			}
			id_table[j] = id_list[tid];
			id_cnt[id_list[tid]]++;
		}
	}

	REP(i, N)
	{
		cout << id_cnt[id_table[i]] << " ";
	}
}

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

int main() {
	while(true) {
		int n;
		if(scanf("%d",&n)<1)break;
		int count = 0;
		for(int a = 0; a < 10; a++)
			for(int b = 0; b < 10; b++)
				for(int c = 0; c < 10; c++)
					for(int d = 0; d < 10; d++)
						if(a+b+c+d==n)count++;
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 0
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn main() {
    input!{
        n: usize,
        mut a_vec: [usize; n],
    }

    a_vec.sort();
    a_vec.reverse();

    let mut ans = 0;

    let mut t = n - 1;

    for i in 0..n {
        let lim = if i == 0 { 1 } else { 2 };
        for _ in 0..lim {
            if t > 0 {
                ans += a_vec[i];
                t -= 1;
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 6228