akhauriyash/Code-Regression huggingface dataset:
S = gets.strip

def test(i)
  S[i] == S[i + 1] || S[i + 1] == S[i + 2] || S[i] == S[i + 2]
end

if S.size == 2 
  puts S[0] == S[1] ? "1 2" : "-1 -1"
else
  idx = (0..(S.size - 3)).find {|i| test(i)}
  puts idx ? [idx + 1, idx + 3].join(' ') : "-1 -1"
end


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



int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,m;
    cin>>n>>m;
    if(m>=n)
    {
    	cout<<"Yes"<<endl;
	}
	else 
	{
		cout<<"No"<<endl;
	}
	return 0;
	
	
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private static final long x = 1000000000 + 7;

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n+1];
		for(int i=2;i<n+1;i++){
			int y = i;
			while(1 < y) {
				for(int j=2;j<y+1;j++){
					if(y % j == 0){
						a[j]++;
						y /= j;
						break;
					}
				}
			}
		}

		long count = 1;
		for(int i=0;i<n+1;i++){
			if(a[i] != 0){
				count *= (a[i] + 1);
				count %= x;
			}
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 22996
while(True):
    n, x = map(int, input().split())
    if(n==0):break
    
    res = 0
    for a in range(1, n-1):
        for b in range(a+1, n):
            for c in range(b+1, n+1):
                
                if(a+b+c == x): res += 1
    
    print(res)


Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vvi            vector<vi>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(c,i)        for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x)    ((c).find(x) != (c).end()) 
#define cpresent(c,x)    (find(all(c),x) != (c).end()) 
using namespace std;
ll mod=1e9+7;
#define N  100005

ll mulm(ll x, ll y){
    return ((x%mod)*(y%mod))%mod;
}

ll adm(ll x, ll y){
    return (x%mod + y%mod)%mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
    //cin>>TESTS;
    //ll cs=1;
    while(TESTS--)
    {
        ll n; cin >> n; vi a(n);
        rep(i,0,n) cin >> a[i];
        vi pre(n); pre[0] = a[0];
        rep(i,1,n) pre[i] = pre[i-1] + a[i];
        ll ans = 0;
        rep(i,0,n){
            ans = adm(ans, mulm(a[i],(pre[n-1]-pre[i])));
        }
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 6360
import math
x = int(input())

# if x==2 or x==3:
#     print(x)
#     exit()
#
# lst = [i for i in range(x,x*2+2)]
#
# max = int(x**0.5)
# for i in range(2,max+1):
#     for j in lst:
#         if j%i==0:
#             lst.remove(j)
#
# print(lst[0])


def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

for i in range(x,x*2+2):
    if is_prime(i):
        print(i)
        exit()


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

struct Node { int parent, left, right; };
struct Node T[10000];
int n;

void preParse(int u)
{
	if (u == -1) return;
	cout << " " << u;
	preParse(T[u].left);
	preParse(T[u].right);
}

void inParse(int u)
{
	if (u == -1) return;
	inParse(T[u].left);
	cout << " " << u;
	inParse(T[u].right);
}

void postParse(int u) 
{
	if (u == -1) return;
	postParse(T[u].left);
	postParse(T[u].right);
	cout << " " << u;
}

int main()
{
	int v, l, r, root;

	cin >> n;
	for (int i = 0; i < n; i++) T[i].parent = -1;

	for (int i = 0; i < n; i++) 
	{
		cin >> v >> l >> r;
		T[v].left = l;
		T[v].right = r;
		if (l != -1) T[l].parent = v;
		if (r != -1) T[r].parent = v;
	}

	for (int i = 0; i < n; i++) if (T[i].parent == -1) root = i;

	cout << "Preorder" << endl;
	preParse(root);
	cout << endl;
	cout << "Inorder" << endl;
	inParse(root);
	cout << endl;
	cout << "Postorder" << endl;
	postParse(root);
	cout << endl;

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  n %= 10;
  if (n == 2 or n == 4 or n == 4 or n == 5 or n == 7 or n == 9)
    cout << "hon" << endl;
  else if (n == 3)
    cout << "bon" << endl;
  else
    cout << "pon" << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
using namespace std;
typedef long long ll;
ll g(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return g(b,a%b);
}
int main()
{
    int n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    ll x, lcm=a[0];
    for(int i=0;i<n;i++)
    {
       lcm=a[i]/g(a[i],lcm)*lcm;
    }
    cout<<lcm;
        return 0;
}


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

using namespace std;
typedef long long ll;
int n;
int a[105];
int main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    vector < pair < int, int >  >ed;
    if (n % 2 == 0) {
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                if ((i + j) == n + 1) continue;
                ed.emplace_back(i, j);
            }
        }
    }
    else {
        for (int i = 1; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                if ((i + j) == n) continue;
                ed.emplace_back(i, j);
            }
        }
    }
    cout << ed.size() << '\n';
    for (auto t : ed) {
        cout << t.first << " " << t.second << '\n';
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  std::string O, E; std:: cin >> O >> E;
  for(int i=0; i<sz(O); i++) {
    std::cout << O[i];
    if ( i < sz(E) ) std::cout << E[i];
  }
  return 0;
}


Measured memory_bytes: 256
Scanf.scanf "%d %d" (fun n m ->
    let hist = Array.make 100001 0 in
    let modgrp = Array.make m 0 in
    for i = 1 to n do
        Scanf.scanf " %d" (fun x ->
            hist.(x) <- hist.(x) + 1;
            modgrp.(x mod m) <- modgrp.(x mod m) + 1;
        )
    done;
    let modpar = Array.make m 0 in
    Array.iteri (fun i x -> modpar.(i mod m) <- modpar.(i mod m) + x / 2) hist;
    let calc1 i = modgrp.(i) / 2 in
    let calc2 i j =
        let i, j = if modgrp.(i) <= modgrp.(j) then i, j else j, i in
        let rest = (modgrp.(j) - modgrp.(i)) / 2 in

        modgrp.(i) + min rest modpar.(j)
    in
    let rec loop i acc =
        if i * 2 > m then acc else
            let acc = if i = 0 || i * 2 = m then acc + calc1 i
                                            else acc + calc2 i (m - i)
            in
            loop (i + 1) acc
    in
    loop 0 0 |> Printf.printf "%d\n"
)

Measured memory_bytes: 5632
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define pb push_back
#define ll long long int
# define pll pair<ll,ll>
# define fio ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{   fio;
    ll n;
    cin>>n;
    ll a=0,t=0,r=0,c=0l;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        if(s[0]=='A') a++;
        if(s[0]=='R') r++;
        if(s[0]=='W') c++;
        if(s[0]=='T') t++;
    }
    cout<<"AC x "<<a<<"\n";
    cout<<"WA x "<<c<<"\n";
    cout<<"TLE x "<<t<<"\n";
    cout<<"RE x "<<r<<"\n";
}


Measured memory_bytes: 3652
S = int(input())

a = S
indx = 1

nums = set()
nums.add(a)

while True:
    if a % 2 == 0:
        a /= 2
    else:
        a = 3 * a + 1
    indx += 1
    if a in nums:
        break
    else:
        nums.add(a)
print(indx)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 #define int long long

#define all(X) (X).begin(), (X).end()
#define reset(X) memset(X, 0, sizeof(X))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define endl '\n'
#define fi first
#define se second


using namespace __gnu_pbds;
using namespace std;
const int mod=1e9+7;
 // const int mod=998244353;
 // const int mod=1e9+9;
const int INF=4e18+10;
// const int INF=4e18+10;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define read(n) int n; cin>>n;
#define readv(x, n) vector<int> x(n); for(auto &i:x) cin>>i;


typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

template<typename T1,typename T2>
void set_min(T1& a, T2 b)
{
    a=min(a, (T1)b);
}


int multiply(int a, int b, int in_mod){return (a*b)%in_mod;}
int mult_identity(int a){return 1;}


auto power(auto a, int b, int in_mod)
{
    auto prod=mult_identity(a);
    auto mult=a%in_mod;
    while(b!=0)
    {
        if(b%2)
        {
            prod=multiply(prod,mult, in_mod);

        }
        mult=multiply(mult, mult,in_mod);
        b/=2;
    }
    return prod;
}
int mod_inv(int q, int in_mod)
{

    return power(q, in_mod-2,in_mod);
}


void solve()
{
    int n;
    cin>>n;
    readv(a,n);
    const int maxn=2e6+100;
    sort(all(a));
    vector<int> marked(maxn, false);

    int cnt=0;

    map<int, int> repeat;
    for(auto i:a)
        repeat[i]++;
    for(auto i:a)
    {
        if(!marked[i])
        {
            if(repeat[i]==1)
                cnt++;
            for(int j=i;j<maxn;j+=i)
            {
                marked[j] = true;
            } 
        }
    }

    cout<<cnt<<endl;

}

signed main()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen("INPUT.txt", "r", stdin);
        freopen("OUTPUT.txt", "w", stdout);
    }
#endif
    auto clk = clock();
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    // -------------------------------------Code starts here---------------------------------------------------------------------

    int t = 1;
    // cin>>t;

    for (int test = 1; test <= t; test++)
    {
        // cout<<"Case #"<<test<<": ";
        // cout<<endl;
        solve();
        // cout<<endl;
    }

    // -------------------------------------Code ends here------------------------------------------------------------------

    clk = clock() - clk;
    // cerr << fixed << setprecision(6) << "Time: " << ((long double)clk) / CLOCKS_PER_SEC << "\n";
    return 0;
}


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

const int INF = 1 << 30;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<int> dp(n + 1, INF);
	rep(i, n) {
		auto itr = lower_bound(dp.begin(), dp.end(), a[i]);
		*itr = a[i];
	}
	cout << lower_bound(dp.begin(), dp.end(), INF) - dp.begin() << endl;
	return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

ll a,b,c,d,ac,bc,ad,bd,divR,e,ae,be;

int main()
{

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

    cin >> a >> b >> c >> d;
    e = c*d/__gcd(c,d);

    ac = ceil( (ld)(a)/(ld)(c) )*c;
    bc = b/c;
    bc*= c;

    ad = ceil( (ld)(a)/(ld)(d) )*d;
    bd = b/d;
    bd*= d;

    ae = ceil( (ld)(a)/(ld)(e) )*e;
    be = b/e;
    be*= e;

    if( ac <= bc ) divR+=1+(bc-ac)/c;
    if( ad <= bd ) divR+=1+(bd-ad)/d;
    if( ae <= be ) divR-=1+(be-ae)/e;

    cout << b-a+1-divR;

    return 0;
}


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

struct UnionFind {
  UnionFind(int n) : n(n), v(n, -1) {}
  int n;
  vector<int> v;

  inline int root(int x) {
    return (v[x] < 0 ? x : v[x] = root(v[x]));
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (v[x] > v[y]) swap(x, y);
      v[x] += v[y];
      v[y] = x;
    }
  }

  int size(int x) {
    return -v[x];
  }
};

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

  UnionFind uf(n);
  while (q--) {
    int c, x, y;
    cin >> c >> x >> y;
    if (c) {
      cout << uf.same(x, y) << endl;
    } else {
      uf.unite(x, y);
    }
  }
}

Measured memory_bytes: 3160
import random
import math
import sys
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
yes = lambda: print("Yes")
no = lambda: print("No")
I = lambda: list(input())
J = lambda x: "".join(x)
II = lambda: int(input())
SI = lambda: input()
#---khan17---template
a,b,c,k = MI()
ans = 0
ans+=min(a,k)
k-=min(a,k)
if k>0:
	k-=min(b,k)
if k>0:
	ans-=min(c,k)
print(ans)

Measured memory_bytes: 9596
def solve(string):
    h, w = map(int, string.split(" "))
    a = [list(map(lambda x: int(x) % 2 == 1, input().strip().split(" "))) for _i in range(h)]
    move = []
    for i in range(h):
        for j in range(w):
            if not a[i][j]:
                continue
            if j < w - 1:
                a[i][j + 1] ^= True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 1, j + 2))
            elif i < h - 1:
                a[i + 1][j] ^= True
                move.append("{} {} {} {}".format(i + 1, j + 1, i + 2, j + 1))
    move.insert(0, str(len(move)))
    return "\n".join(move)
 
 
if __name__ == '__main__':
    line = input().strip()
    print(solve(line))

Measured memory_bytes: 16344
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e5+100;
typedef long long LL;
char s[MAXN*2];
int main()
{
    int a,b;
    cin>>a>>b;
    int t=a;
    int pa=a,pb=b;
    while(t)
    {
        t/=10;
        pb*=10;
    }
    t=b;
    while(t)
    {
        t/=10;
        pa*=10;
    }
    pa+=b;
    pb+=a;
    //cout<<pa<<" "<<pb;
    int spa=sqrt(pa);
    int spb=sqrt(pb);
    if(spa*spa==pa||spb*spb==pb){
        cout<<"Yes"<<endl;
    }else cout<<"No"<<endl;
    return 0;
}


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

#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define vi vector<int>
using namespace std;
int mod = 1'000'000'000 + 7;

void COME_LET_THE_GAMES_BEGIN() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
}

int main() {
    COME_LET_THE_GAMES_BEGIN();
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
}

Measured memory_bytes: 256
import math
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n,m = (int(x) for x in input().split())
a = list(map(int, input().split()))

lc = int(lcm_list(a) // 2)

tmp = 0
bol = 0
num = a[0]
while num % 2 == 0:
        num = num // 2
        tmp += 1
cnt = 0
for num in a:
    cnt = 0
    while num % 2 == 0:
        num = num // 2
        cnt += 1
    if cnt != tmp:
        bol = 1

if lc > m: print(0)
elif bol == 1: print(0)
else: print(int(((m / lc) + 1) // 2))

Measured memory_bytes: 16308
n, m = map(int, input().split())

lr = [list(map(int, input().split())) for i in range(m)]
left = lr[0][0]
right = lr[0][1]

for i in range(1, m):
    left = max(lr[i][0], left)
    right = min(lr[i][1], right)

if right - left + 1 > 0:
    print(right - left + 1)
else:
    print(0)

Measured memory_bytes: 27336
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;

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;
}







int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n,ans=0;
    cin >> n;
    int a[n];
    rep(i,n) {
        cin >> a[i];
        if(i%2 == 0 && a[i]%2 == 1){
            ans ++;
        }
        
    }
    cout << ans << endl;
    return 0;
    


    
}


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

int main(){

  int h,r,s,d;
  cin >> h >> r;

  s = h + r;

  if(s > 0){
    d = 1;
  }else if(s < 0){
    d = -1;
  }else d = 0;

  cout << d << endl;
  


  
  return 0;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> p(n),q(n), r(n);
  for(int i=0;i<n;i++)cin >> p[i];
  for(int i=0;i<n;i++)cin >> q[i];
  long long cnt = 0;
  r=min(p,q);
  p=max(p,q);
  while(r != p){
    next_permutation(r.begin(), r.end());
    cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  ALDS1_5_B
//
//  Created by ptyuan on 2018/10/28.
//  Copyright © 2018 Sy. All rights reserved.
//

#include <iostream>
#include <cstdio>
using namespace std;

const int kMaxValue = 2000000000;
const int kMax = 500000;

int A[kMax] = {0};

int L[kMax / 2 + 2];
int R[kMax / 2 + 2];
int cmpCount = 0;

void _merge(int *A, int n, int left, int mid, int right) {
    int n1 = mid - left;
    for (int i = 0; i < n1; i++) {
        L[i] = A[left + i];
    }
    
    int n2 = right - mid;
    for (int i = 0; i < n2; i++) {
        R[i] = A[mid + i];
    }
    
    L[n1] = kMaxValue;
    R[n2] = kMaxValue;
    int l1 = 0;
    int l2 = 0;
    for (int k = left; k < right; k++) {
        ++cmpCount;
        if (L[l1] <= R[l2]) {
            A[k] = L[l1++];
         } else {
             A[k] = R[l2++];
         }
    }
}

void mergeSort(int *A, int n, int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        _merge(A, n, left, mid, right);
    }
}



int main(int argc, const char * argv[]) {
    int n = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", A + i);
    }
    
    mergeSort(A, n, 0, n);
    for (int i = 0; i < n; i++) {
        int value = A[i];
        if (i > 0) {
            printf(" ");
        }
        printf("%d", value);
    }
    printf("\n");
    printf("%d\n", cmpCount);
    
    
    return 0;
}



Measured memory_bytes: 7012
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K;
	string s;
	while(cin>>N) {
		double ans=M_PI*2*N;
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3244
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            List<int> lstA = new List<int>();
            List<int> lstB = new List<int>();
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            int iM = int.Parse(sS[1]);
            lstA.Add(int.Parse(sS[2]));
            lstB.Add(int.Parse(sS[3]));
            sS = System.Console.ReadLine().Trim().Split(' ');
            for (int i = 0; i < iN; i++) { lstA.Add(int.Parse(sS[i])); }
            sS = System.Console.ReadLine().Trim().Split(' ');
            for (int i = 0; i < iM; i++) { lstB.Add(int.Parse(sS[i])); }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "War";
            lstA.Sort(delegate (int mca1, int mca2) { return (int)(mca2 - mca1); });    // 降順
            lstB.Sort();                                                                // 昇順
            if (lstB[0] > lstA[0]) { sOut = "No War"; }

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define ll long long

int main() {
  int n;cin>>n;
  int ans=0;
  vector<int>a(n),b(n),c(n-1);
  for(int i=0;i<n;i++)
    cin>>a.at(i);
  for(int i=0;i<n;i++)
    cin>>b.at(i);
  for(int i=0;i<n-1;i++)
    cin>>c.at(i);
  for(int i=0;i<n;i++)
  {
    ans+=b.at(a.at(i)-1);
  }
   for(int i=0;i<n-1;i++)
   {
     if(a.at(i)==a.at(i+1)-1)
       ans+=c.at(a.at(i+1)-2);
   }
  cout<<ans;
}

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

using ll = long long;

const int INF = 1000000000;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int N = S.size();
    vector<int> rl;
    for (int i = 0; i < N;) {
        char s = S[i];
        int cnt = 0;
        while (i < N && s == S[i]) {
            ++cnt;
            ++i;
        }
        rl.push_back(cnt);
    }
    vector<int> ans(N, 0);
    int a = 0;
    int b = 0;
    for (int i = 0; i < (int)rl.size(); i += 2) {
        b = a + rl[i];
        a = b - 1;
        int R = rl[i];
        int L = rl[i + 1];
        ans[b] = (R + L) / 2;
        ans[a] = R + L - ans[b];
        if ((max(R, L) - 1) % 2 == 0) {
            if (R < L) swap(ans[a], ans[b]);
        }
        else {
            if (R > L) swap(ans[a], ans[b]);
        }
        a += rl[i + 1] + 1;
    }
    for (int i : ans) cout << i << " ";
    cout << endl;
}


Measured memory_bytes: 1480
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

    int main(){
      ll n,m;
      cin >> n >> m;
      string s,t;
      cin >> s >> t;
      bool flag=true;
      ll g=__gcd(m,n);
      ll a=n/g;
      ll b=m/g;
      REP(k,0,g){
       if(s[k*a]!=t[k*b]){
         flag=false;
       }
      }
      if(flag)cout << m*(n/g) << endl;
      else cout << -1 << endl;
      return 0;}


Measured memory_bytes: 512
import cmath
def f():
 global d
 p=[]
 for i in range(len(d)-1):
  a,b=d[i],d[i+1]
  r=(b-a)/3
  p+=[a,a+r,a+r+r*(1+3**.5*1j)/2,b-r]
 d=p+[d[-1]]
d=[0j,100+0j]
for _ in[0]*int(input()):f()
for e in d:print(e.real,e.imag)


Measured memory_bytes: 5996
n=int(input())
s=list(input())
ans=[]
count=0
num=[]

for i in range(1,n+1):
  l=s[:i]
  r=s[i:]
  
  l=sorted(l)
  r=sorted(r)
  
  for j in l:
    if j in r:
      if j not in num:
        count+=1
        num.append(j)
        
  ans.append(count)
  num.clear()
  count=0
  
print(max(ans))

Measured memory_bytes: 9096
import math
a,b,x=map(int,input().split())
half=(a*a*b)/2
ta=2*x/(a*b)
if half<x:
    ta=2*(half*2-x)/a**2
    print(math.degrees(math.atan2(ta,a)))
else:
    print(math.degrees(math.atan2(b,ta)))

Measured memory_bytes: 3060
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
static long checkNum = 0;

	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		int m = int.Parse(input[1]);
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    List<long> numList = new List<long>();
    Array.Sort(nums);
    Array.Reverse(nums);
    long answer = 0;
    for(int i = 0; i < n; i++)
    {
      numList.Add(nums[i]);
    }
    
    for(int i = 0; i < m; i++)
    {
      numList = PopHeap(numList);
      numList = PushHeap(numList, checkNum/2);
    }

    for(int i = 0; i < n; i++)
    {
      answer += numList[i];
    }

		Console.WriteLine(answer);
	}

  static List<long> PushHeap(List<long> nums, long addNum)//現在のヒープnumsにaddNumを追加
{
  int n = nums.Count;
  nums.Add(addNum);

  while (n > 0)
  {
    int i = (n-1)/2;
    if (nums[n] > nums[i])//親のほうが大きいなら入れ替え。
    {
      long tmp = nums[n];
      nums[n] = nums[i];
      nums[i] = tmp;
    }
    n = i;
  }
  return nums;
}

static List<long> PopHeap(List<long> nums)//ヒープnumsからポップ
{
  int n = nums.Count - 1;
  checkNum = nums[0];//捨てる値の保存
  nums[0] = nums[n];//最小値である根を削除してリストの最後を持ってくる
  nums.RemoveAt(n);

  for (int i = 0, j; (j = 2*i+1) < n; )
  {
    if ((j != n-1) && (nums[j] < nums[j+1]))// ２つの子のうち、値の小さい方を選ぶ
      j++;
    if (nums[i] < nums[j])//子が親より小さいなら入れ替え
    {
      long tmp = nums[j];
      nums[j] = nums[i];
      nums[i] = tmp;
    }
    i = j;
  }
  return nums;
}
  
}

Measured memory_bytes: 27356
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    a = list(int(_) for _ in input().split())
    cnt = 0
    for i in range(N):
        tmp = float(a[i])
        while tmp > 0 and tmp.is_integer():
            if tmp%2 == 1:
                break
            tmp = tmp / 2
            cnt += 1
    print(cnt)
    
if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
    int height, width, d;
    cin >> height >> width >> d;

    vector <int> X(height*width + 1);
    vector <int> Y(height*width + 1);

    for(int i = 1; i <= height; i++)
    {
        for(int j = 1; j <= width; j++)
        {
            int value;
            cin >> value;

            X[value] = i;
            Y[value] = j;
        }
    }

    vector <int> cost(height*width + 1, 0);
    for(int i = d + 1; i <= height*width; i++)
    {
        cost[i] = cost[i - d] + abs(X[i - d] - X[i]) + abs(Y[i - d] - Y[i]);
    }

    int no_of_queries;
    cin >> no_of_queries;

    while(no_of_queries--)
    {
        int left, right;
        cin >> left >> right;
        cout << (cost[right] - cost[left]) << "\n";
    }

    return 0;
}


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

int main(){
  int w, h, x, y, r;
  cin >> w >> h >> x >> y >> r;
  if(w >= x + r && h >= y + r && x >= r && y >= r) 
    cout << "Yes" << endl;
  else 
    cout << "No" << endl;
	return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef pair<int,int> ii;
const int IINF = INT_MAX;

vector<ii> G[100010];
int mincost[100010];
int V,E,r;

struct Data{
  int cur,cost;
  bool operator < (const Data& data) const{ return cost > data.cost; }
};

int main(){
  scanf("%d %d %d",&V,&E,&r);

  int s,t,d;
  rep(i,E){
    scanf("%d %d %d",&s,&t,&d);
    G[s].push_back(ii(t,d));
  }

  // Shortest Path Faster Algorithm 
  // O(kE)

  rep(i,V) mincost[i] = IINF;
  mincost[r] = 0;
  deque<int> deq; deq.push_back(r);
  vector<int> in_queue(V,0); in_queue[r] = 1;
  vector<int> time_stamp(V,0); time_stamp[r] = 1;

  bool found = false;
  while(!deq.empty()){
    int u = deq.front(); deq.pop_front(); in_queue[u] = 0;
    rep(i,(int)G[u].size()){
      int v = G[u][i].first, c = G[u][i].second;
      if( mincost[v] > mincost[u] + c ) {
        mincost[v] = mincost[u] + c;
        if( !in_queue[v] ) {
          deq.push_back(v);
          in_queue[v] = 1;
          time_stamp[v]++;
          if( time_stamp[v] >= V-1 ) {
            found = true;
            goto Skip;
          }
        }
      }
    }
  }
 Skip:;
  if( found ){
    puts("NEGATIVE CYCLE");
    return 0;
  }
  rep(i,V) {
    if( mincost[i] == IINF ) puts("INF");
    else printf("%d\n",mincost[i]);
  }

  return 0;
}

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

signed main(){

  int N,W;
  cin>>N>>W;
  vector<int> v(N),w(N);
  for(int i=0;i<N;++i)cin>>v[i]>>w[i];

  constexpr int64_t inf = 1ll<<60;
  auto chmax = [](auto& a,auto b){if(a<b)a=b;};
  auto chmin = [](auto& a,auto b){if(a>b)a=b;};
  // dp[i][j] := i番目 価値j 重さ最小
  vector<vector<int64_t>> dp(N+1,vector<int64_t>(1e5,inf));
  for(int i=0;i<=N;++i)dp[i][0]=0;
  for(int i=0;i<N;++i){
    for(int j=0;j<1e5;++j){
      chmin(dp[i+1][j],dp[i][j]);
      if(j+v[i]<1e5)chmin(dp[i+1][j+v[i]],dp[i][j]+w[i]);
    }
  }
  int64_t ans = 0;
  for(int i=0;i<1e5;++i)
    if(dp[N][i]<=W)ans=i;
  cout<<(ans)<<endl;


}


Measured memory_bytes: 82796
# 最大公約数
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

# 最小公倍数
def lcm(m, n):
    return m//gcd(m, n)*n

A,B,C,D = map(int, input().split())

def f(n,C=C,D=D):
    return n - (n//C + n//D - n//lcm(C,D))
print(f(B)-f(A-1))

Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
#define M(a,b) (a<b?a:b)
#define S(a,b) sqrt(a*a+b*b)
int main(){
	for(int a,b,c,n,r;scanf("%d%d%d",&a,&b,&c),a|b|c;){
		for(scanf("%d",&n);n--;){
			scanf("%d",&r);
			puts(
				(2*r>M(M(S(a,b),S(b,c)),S(c,a)))?
				"OK":"NA"
			);
		}
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A.at(i);
  }
  bool loop = true;
  int ans = 0;
  while (true) {
    for (int i = 0; i < N; ++i) {
      if (A.at(i) % 2 == 0) {
        A.at(i) /= 2;
      } else {
        loop = false;
        break;
      }
    }
    if (!loop) {
      break;
    }
    ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader tec = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		for (String line; (line = tec.readLine()) != null;) {
			int n = Integer.parseInt(line.trim());
			int[] arr = new int[n];
			StringTokenizer st = new StringTokenizer(tec.readLine());
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(st.nextToken());
			if (n == 1) {
				out.println(1);
				break;
			}
			int cont = 1;

			for (int indice = 0; indice < arr.length; indice++) {

				boolean bool = true;
				boolean decidido=false;
				// true ascendente
				boolean cambio=false;
				for (int i = indice; i < arr.length - 1; i++) {
					if(arr[i]<arr[i+1]&&!decidido){
						decidido=true;
						bool=true;						
					}
					if(arr[i]>arr[i+1]&&!decidido){
						decidido=true;
						bool=false;						
					}					
					if (arr[i] < arr[i + 1] && !bool&&decidido) {
						cont++;
						bool = !bool;
						indice=i;
						cambio=true;
						break;
					}
					if (arr[i] > arr[i + 1] && bool&&decidido) {
						cont++;
						bool = !bool;
						indice=i;
						cambio=true;
						break;
					}
				}
				if(!cambio){
					break;
				}
			}
			out.println(cont);
		}
		out.close();
	}
}

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

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

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

	return false;
}

const int MAX_N = 1e5 + 10;
const long long INF = 1LL << 60;

int n, h[MAX_N];
long long dp[MAX_N];
int main()
{
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> h[i];
	}

	for (int i = 0; i < MAX_N; ++i)
	{
		dp[i] = INF;
	}

	dp[0] = 0;
	for (int i = 0; i < n; ++i)
	{
		chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
		chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
	}

	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = 2000100;

int fac[N], inv[N];
int powi(int a, int b) {int c = 1; for (; b; b >>= 1, a = 1ll * a * a % MOD) if (b & 1) c = 1ll * c * a % MOD; return c;}
int C(int n, int m) {return 1ll * fac[n + m] * inv[n] % MOD * inv[m] % MOD;}
int G(int x1, int y1, int x2, int y2)
{
    return (0ll + MOD + MOD + C(x2 + 1, y2 + 1) - C(x2 + 1, y1) - C(x1, y2 + 1) + C(x1, y1)) % MOD;
}
int ans;
int main()
{
    int x1, x2, x3, x4, x5, x6;
    int y1, y2, y3, y4, y5, y6;
    cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6;
    cin >> y1 >> y2 >> y3 >> y4 >> y5 >> y6;
    fac[0] = 1; for (int i = 1; i < N; ++ i) fac[i] = 1ll * fac[i - 1] * i % MOD;
    inv[N - 1] = powi(fac[N - 1], MOD - 2);
    for (int i = N - 2; ~i; -- i) inv[i] = 1ll * inv[i + 1] * (i + 1) % MOD;
    for (int i = x3; i <= x4; ++ i)
    {
        ans = (1ll * (MOD + x3 - i) * G(x5 - i, y5 - y3, x6 - i, y6 - y3) % MOD
            * G(i - x2, y3 - 1 - y2, i - x1, y3 - 1 - y1) + ans) % MOD;
        ans = (1ll * (i - x3 + y4 - y3 + 1) * G(x5 - i, y5 - y4 - 1, x6 - i, y6 - y4 - 1) % MOD
            * G(i - x2, y4 - y2, i - x1, y4 - y1) + ans) % MOD;
    }
    for (int i = y3; i <= y4; ++ i)
    {
        ans = (1ll * (MOD + y3 - i) * G(x5 - x3, y5 - i, x6 - x3, y6 - i) % MOD
            * G(x3 - 1 - x2, i - y2, x3 - 1 - x1, i - y1) + ans) % MOD;
        ans = (1ll * (i - y3 + x4 - x3 + 1) * G(x5 - x4 - 1, y5 - i, x6 - x4 - 1, y6 - i) % MOD
            * G(x4 - x2, i - y2, x4 - x1, i - y1) + ans) % MOD;
    }
    cout << ans;
}


Measured memory_bytes: 15872
small = ['a', 'b', 'c']
capital = ['A', 'B', 'C']
 
tmp = input().split(" ")
N = int(tmp[0])
K = int(tmp[1])
str = list(input())
 
str[K - 1] = small[capital.index(str[K - 1])]
 
print("".join(str))

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,A,B,C;
  cin >> N >> K;
  C=1;
for(int i=0; i<N; i++ ){
  A= C + K;
  B= C * 2;
 if(A<B) C=A;
 else C=B;
}
cout<<C<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e12;
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
bool operator == (const P& a, const P& b){
    return abs(a-b) < EPS;
}

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}

double getarea(const VP &poly){
    int n = poly.size();
    double ret = 0;
    for (int i=0; i<n; i++){ 
        ret += cross(poly[i], poly[(i+1)%n]);
    }
    return ret*0.5;
}

int dx[4] = {1, 1, -1, -1};
int dy[4] = {1, -1, 1, -1};
vector<vector<pair<int, int> > > xy;
VP p;

int dfs(int now, int end, const vector<int> &len){
    if(now == end){
        if(p[end] == P(0, 0)){
            return getarea(p)+EPS;
        }
        return -1;
    }

    int remain = 0;
    for(int i=now+1; i<end; i++){
        remain += len[i];
    }
    int ret = -1;
    for(int i=0; i<(int)xy[len[now]].size(); i++){
        int x = xy[len[now]][i].first;
        int y = xy[len[now]][i].second;
        if(now==0 && x>y) break; //45度以下
        for(int d=0; d<4; d++){
            p[now+1] = p[now] +P(x*dx[d], y*dy[d]);
            if(now > 0){
                P edge[4] = {p[now] -p[now-1], p[now+1] -p[now], p[0] -p[now+1], p[1] -p[0]};
                //折れ曲がる方向
                if((cross(edge[0], edge[1]) < -EPS ||
                    (abs(cross(edge[0], edge[1])) < EPS && dot(edge[0], edge[1]) < 0)) ){
                    continue;
                }
                //閉じるために曲がる方向
                if((cross(edge[1], edge[2]) < -EPS ||
                    (abs(cross(edge[1], edge[2])) < EPS && dot(edge[1], edge[2]) < 0)) ){
                    continue;
                }
                //閉じたときの曲がる方向
                if((cross(edge[2], edge[3]) < -EPS ||
                    (abs(cross(edge[2], edge[3])) < EPS && dot(edge[2], edge[3]) < 0)) ){
                    continue;
                }
            }
            //囲めない
            if(abs(p[now+1]) > remain +EPS){
                continue;
            }
            ret = max(ret, dfs(now+1, end, len));
            //1本目は第一象限のみ
            if(now == 0) break;
        }
    }
    return ret;
}

int main(){
    xy.resize(301);
    for(int l=0; l<=300; l++){
        for(int x=0; x<=l; x++){
            for(int y=0; y<=l; y++){
                if(x*x +y*y == l*l){
                    xy[l].emplace_back(x, y);
                }
            }
        }
    }
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;

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

        int ans = -1;
        sort(l.begin(), l.end());
        p.resize(n+1);
        p[0] = P(0, 0);
        do{
            ans = max(ans, dfs(0, n, l));
        }while(next_permutation(l.begin()+1, l.end())); //1本目は固定でよい
        cout << fixed << setprecision(0);
        cout << ans << endl;
    }

}


Measured memory_bytes: 3192
n=int(input())
d=list(map(int,input().split()))
cnt=[0]*24
cnt[0]=1
for i in range(n):
  cnt[d[i]]+=1
  cnt[(24-d[i])%24]+=1
  if cnt[d[i]]>=3 or cnt[24-d[i]]>=3:
    print(0)
    exit()
ans=[0]*24
ans[0]=1
right=True
for i in range(1,13):
  if cnt[i]>=2:
    ans[i]=1
    ans[24-i]=1
  elif cnt[i]==0:
    continue
  else:
    if right:
      right=False
      ans[i]=1
    else:
      right=True
      ans[24-i]=1
L=24
num=0
for i in range(1,24):
  if ans[i]==0:
    num+=1
  else:
    L=min(L,num)
    num=0
L=min(L,num)
print(L+1)

Measured memory_bytes: 3064
#include <cstdio>
using namespace std;
const int N=100010;
typedef long long ll;
int n;
ll subsum;
int a[N],maxa;
int b[N];
inline int max(int x,int y){
	return x>y?x:y;
}
void readData(){
	scanf("%d",&n);
	subsum=1ll*n*(n+1)/2;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		maxa=max(maxa,a[i]);
	}
}
namespace BIT{
	int n;
	int a[N*2];
	void setup(int _n){
		n=_n;
		for(int i=1;i<=n;i++) a[i]=0;
	}
	void add(int u,int x=1){
		for(;u&&u<=n;u+=u&-u)
			a[u]+=x;
	}
	int que(int u){
		int res=0;
		for(;u;u-=u&-u)
			res+=a[u];
		return res;
	}
}
ll calc(int x){
	b[0]=0;
	for(int i=1;i<=n;i++){
		b[i]=(a[i]>=x)?1:-1;
		b[i]+=b[i-1];
	}
	BIT::setup(2*n+1);
	BIT::add(n+1);
	ll res=0;
	for(int i=1;i<=n;i++){
		res+=BIT::que(b[i]+(n+1));
		BIT::add(b[i]+(n+1));
	}
	return res;
}
bool judge(int x){
	return calc(x)>=((subsum+1)>>1);
}
int solve(){
	int l=1,r=maxa,mid;
	while(l<=r){
		mid=(l+r)>>1;
		if(judge(mid))
			l=mid+1;
		else
			r=mid-1;
	}
	return r;
}
int main(){
	readData();
	printf("%d\n",solve());
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> vc(n);
  for (int i=0;i<n;i++){
    cin >> vc.at(i);
  }
  sort(vc.begin(), vc.end());
  int ans = 0;
  int x = vc.size()/2;
  if (vc.size()%2==0 && 
  vc.at(x)!=vc.at(x-1)){
    ans = vc.at(x) - vc.at(x-1);
  }
  cout << ans << endl;
}


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

using namespace std;

const int N = 100005;

typedef long long ll;

ll v[N];

int main(){

    int n;

    scanf("%d", &n);

    for(int i = 0; i < n; i++)
        scanf("%lld", v+i);

    sort(v, v+n);

    long long a = 0, b = 0;

    int i;
    for(i = n-1; i > 0; i--){
        if(v[i] == v[i-1]){
            a = v[i];
            i -= 2;
            break;
        }
    }

    for(; i > 0; i--){
        if(v[i] == v[i-1]){
            b = v[i];
            break;
        }
    }

    printf("%lld\n", a * b);

}


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

int main() {
  int r, c;
  cin >> r >> c;

  int arr[r][c];
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> arr[i][j];
    }
  }

  for (int i = 0; i < r; i++) {
    int sum_r = 0;
    for (int j = 0; j < c; j++) {
      cout << arr[i][j] << " ";
      sum_r += arr[i][j];
    }
    cout << sum_r << endl;
  }

  int total = 0;
    
  for (int i = 0; i < c; i++) {
    int sum_c = 0;
    for (int j = 0; j < r; j++) {
      sum_c += arr[j][i];
    }
    cout << sum_c << " ";
    total += sum_c;
  }

  cout << total << endl;

  return 0;
}



Measured memory_bytes: 3100
store=[]
str=["N","S","E","W"]
rep={
 "N":[4,0,2,3,5,1],
 "S":[1,5,2,3,0,4],
 "E":[2,1,5,0,4,3],
 "W":[3,1,0,5,4,2]}

def rotate_dice(b,s):
 result = [0]*6
 for i in range(6):result[i]=b[rep[s][i]]
 return result
     
def check(a,b):
 if not b in store:
  store.append(b)
  for s in str:
   check(a,rotate_dice(b,s))
 
a=input().split()
b=input().split()
r=check(a,b)
if a in store:
 print("Yes")
else:
 print("No")

Measured memory_bytes: 7600
#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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
const int V = 100010;
vector<int> to[V * 2];

bool visited[V * 2];
array<ll, 2> cnt;

void DFS(int i)
{
    if (visited[i]) return;
    visited[i] = true;
    ++cnt[i / V];
    for (const int j : to[i])
    {
        DFS(j);
    }
}

void _main()
{
    int N;
    cin >> N;
    rep(i, 0, N)
    {
        int x, y;
        cin >> x >> y;
        y += V;
        to[x].push_back(y);
        to[y].push_back(x);
    }

    ll ans = 0;
    rep(i, 0, V * 2)
    {
        cnt.fill(0);
        DFS(i);
        ans += cnt[0] * cnt[1];
    }
    ans -= N;
    cout << ans << endl;
}


Measured memory_bytes: 10240