akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#include <queue>
#define INF LONG_MAX
typedef long long ll;
struct edge{ll to, cost;};
typedef pair<ll,ll> P;

struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    for(int i = 0; i < V; i++){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    for(int i = 0; i < V; i++){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};

/*
graph g(n);

と書けばn頂点のグラフが作成され、

  g.add_edge(a,b,cost);

とすれば頂点aから頂点bへのコストcostの辺が張られます。そして

  g.dijkstra(s);

とすれば頂点sから各頂点への最短経路をダイクストラ法で探索できます。探索結果は

  int dist = g.d[i]:

と呼び出して使うことができます。
*/


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,u,v;
  cin >> n >> u >> v;
  graph g(n);
  graph f(n);
  VI a(n),b(n);
  rep(i,n-1){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    g.add_edge(a[i],b[i],1);
    g.add_edge(b[i],a[i],1);
    f.add_edge(a[i],b[i],1);
    f.add_edge(b[i],a[i],1);
  }

  g.dijkstra(u-1);
  f.dijkstra(v-1);
  if(g.G[u-1].size() == 1){
    for(edge x: g.G[v-1]){
      if(g.G[u-1][0].to == x.to){
        cout << 1 << endl;
        return 0;
      }
    }
  }
  ll ans = 0;
  ll maxDist = -1;
  rep(i,n){
    if(g.d[i] < f.d[i] && maxDist < f.d[i]){
      maxDist = f.d[i];
      ans = f.d[i]-1;
    }
  }

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


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int BIT_MAX = 4010;

template <class T> class BIT{
	T x[BIT_MAX + 1];
	
public:
	
	BIT(){
		fill(x,x+BIT_MAX+1,0);
	}
	
	void add(int a , T b){
		for(++a ; a <= BIT_MAX ; a += a & -a) x[a] += b;
	}
	
	T get(int a){
		T b = 0;
		for(++a ; a > 0 ; a -= a & -a) b += x[a];
		return b;
	}
};

const int MC = 2003;
int N,b[MC],w[MC];
int dp[MC][MC];

int main(){
	cin >> N;
	repp(i,0,2*N){
		char c; int a; cin >> c >> a;
		(c=='B'?b:w)[a-1] = i;
	}
	repp(i,0,N+1) fill(dp[i],dp[i]+MC,1e9);
	dp[0][0] = 0;
	BIT<int> bit0;
	repp(i,0,N+1){
		BIT<int> bit1;
		repp(j,0,N+1){
			if(i < N) dp[i+1][j] = min(dp[i+1][j] , dp[i][j] + b[i] - bit0.get(b[i]) - bit1.get(b[i]));
			if(j < N) dp[i][j+1] = min(dp[i][j+1] , dp[i][j] + w[j] - bit0.get(w[j]) - bit1.get(w[j]));
			bit1.add(w[j],1);
		}
		bit0.add(b[i],1);
	}
	cout << dp[N][N] << endl;
	return 0;
}


Measured memory_bytes: 16000
use std::io::{BufReader,BufRead};
fn main() {
    let input = BufReader::new(std::io::stdin()).lines()
        .filter_map(|e|e.ok())
        .nth(0)
        .unwrap();
    let mut stack:Vec<isize> = vec![];
    for op in input.split_whitespace(){
        match op {
            "+" => {
                let x = stack.pop().unwrap();
                let y = stack.pop().unwrap();
                stack.push(x + y);
            },
            "-" =>{
                let x = stack.pop().unwrap();
                let y = stack.pop().unwrap();
                stack.push(y - x);
            }    ,
            "*" => {
                let x = stack.pop().unwrap();
                let y = stack.pop().unwrap();
                stack.push(x * y);
            },
            
            x => stack.push(x.parse().unwrap()),
        }
    }
    println!("{}",stack.last().unwrap());
}



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

int n,m;
ll path[200005];	//longest path originating from i
vector<int> child[200005];

ll dfs(int u){
	if (path[u] != -1) return path[u];
	ll mx = 0;	//longest path originating from u
	for (int i : child[u]){
		mx = max(mx, dfs(i));
	}
	return path[u] = 1 + mx;	//child path length + itself
}

int main(){
	cin >> n >> m;
	int x,y;
	for (int i = 0; i < m; ++i){
		cin >> x >> y;
		child[x].pb(y);
	}
	memset(path,-1,sizeof(path));
	ll mx = 0;	//no of nodes on longest path
	for (int i = 1; i <= n; ++i){
		mx = max(mx, dfs(i));
	}
	//no. of edges = visited node - 1
	cout << mx - 1 << '\n';
	return 0;
}

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

typedef pair<double, int>DI;
typedef pair<int, int>II;
typedef pair<DI, II>DIII;

double dp[33][33][33];
vector<int>path[33];
int length[33][33];
int limit[33][33];
void init(){
    for(int i = 0; i < 33; i++){
        for(int j = 0; j < 33; j++){
            for(int k = 0; k < 33; k++){
                dp[i][j][k] = 5000;
            }
            length[i][j] = -1;
            limit[i][j] = -1;
        }
        path[i].clear();
    }
}

int main(){

    for(int n, m, s, g; cin >> n >> m, n;){
        cin >> s >> g;
        init();
        for(int i = 0; i < m; i++){
            int x, y, d, c;
            cin >> x >> y >> d >> c;
            path[x].push_back(y);
            length[x][y] = d;
            limit[x][y] = c;            
            path[y].push_back(x);
            length[y][x] = d;
            limit[y][x] = c;            
        }
        priority_queue<DIII, vector<DIII>, greater<DIII> >Q;
        Q.push(DIII(DI(0, 1), II(s, -1)));
        double ans = -1;
        while(!Q.empty()){
            double cost = Q.top().first.first;
            int v = Q.top().first.second;
            int now = Q.top().second.first;
            int pre = Q.top().second.second;
            Q.pop();
            if(dp[v][now][pre] < 4900)continue;
            dp[v][now][pre] = cost;
            // cout << "cost["<< v << "][" << now << "][" << pre << "] -> " << cost << endl;
            if(now == g && v==0){
                ans = cost;
                break;
            }
            if(v == 0)continue;
            for(int i = 0; i < path[now].size(); i++){
                int nxt = path[now][i];
                if(nxt == pre)continue;
                if(limit[now][nxt] < v)continue;
                double tim = (double)length[now][nxt] / v;
                for(int dv = -1; dv <= 1; dv++){
                    if(dp[v + dv][nxt][now] >= cost + tim){
                        Q.push(DIII(DI(cost + tim, v + dv), II(nxt, now)));
                    }
                }
            }
        }
        if(ans < 0)cout << "unreachable" << endl;
        else printf("%.9f\n", ans);
    }

    return 0;
}


Measured memory_bytes: 15624
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.nextLine();
        String keyence = "keyence";
        for (int i = 0; i < s.length(); i++) {
            for (int j = i; j < s.length(); j++) {
                if (keyence.equals(s.substring(0,i)+s.substring(j,s.length()))) {
                    System.out.println("YES");
                    return;
                }
            }
        }
        System.out.println("NO");
    }
}

Measured memory_bytes: 21844
n , k = map(int,input().split(" "))
r , s , p = map(int,input().split(" "))
t = input()
yu = len(t)
ans = 0

for i in range(yu):
    if i <= k-1:
        if t[i] == "r":
            ans += p
        elif t[i] == "s":
            ans += r
        elif t[i] == "p":
            ans += s
    elif t[i] == t[i-k]:
        t = t[:i] + "x" + t[i+1:]
    else:
        if t[i] == "r":
            ans += p
        elif t[i] == "s":
            ans += r
        elif t[i] == "p":
            ans += s
print(ans)

Measured memory_bytes: 3472
n,w=map(int,input().split())

weight=[]
value=[]

for i in range(n):
    a,b=map(int,input().split())
    weight+=[a]
    value+=[b]

dp=[[0]*(w+1) for i in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if j<weight[i]:
            dp[i+1][j]=dp[i][j]
        else:
            dp[i+1][j]=max(dp[i][j],dp[i][j-weight[i]]+value[i])

print(dp[n][w])

Measured memory_bytes: 147296
n = input()

m = list(n)
mm = list(reversed(m))

if mm[0] == "2" or mm[0] == "4" or mm[0] == "5" or mm[0] == "7" or mm[0] == "9" :
    print("hon")
elif mm[0] == "0" or mm[0] == "1" or mm[0] == "6" or mm[0] == "8":
    print("pon")
else:
    print("bon")

Measured memory_bytes: 61664
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
using namespace std;

int main(){
	int i, n;
	double x, y, rad, turn;
	turn = -0.5 * M_PI;
	while(true){
		cin >> n; if(n == -1) break;
		x = 1.0;
		y = 0.0;
		rad = M_PI;
		for(i=2; i<=n; i++){
			rad = rad + turn;
			x += cos(rad);
			y += sin(rad);
			rad = atan2(y, x);
		}
		cout << fixed << setprecision(2);
		cout<<y<<endl<<x<<endl;
	}
	return 0;
}

Measured memory_bytes: 1312
def elip():
    return map(int,input().split())
N = int(input())
A = list(elip())
B = list(elip())
kill = 0
for i in range(len(B)):
    if A[i] > 0 and B[i] >= A[i]:
        B[i] -= A[i]
        kill += A[i]
        A[i] = 0
    else:
        if A[i] > 0:
            A[i] -= B[i]
            kill += B[i]
            B[i] = 0
            continue
    if A[i+1] > 0 and B[i] >= A[i+1]:
        B[i] -= A[i+1]
        kill += A[i+1]
        A[i+1] = 0
    else:
        if A[i+1] > 0:
            A[i+1] -= B[i]
            kill += B[i]
            B[i] = 0
print(kill)

Measured memory_bytes: 19004
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;


#define REP(i, n) for(ll i = 0; i < n; i++)






























int main(){
    int h, w, m;
    scanf("%d %d %d", &h, &w, &m);
    set<pair<int, int>> st;
    vector<int> y(m), x(m);
    vector<pair<int, int>> cnth(h + 1), cntw(w + 1);
    for(int i = 0; i <= h; i++){
        cnth[i].second = i;
    }
    for(int i = 0; i <= w; i++){
        cntw[i].second = i;
    }
    for(int i = 0; i < m; i++){
        scanf("%d %d", &y[i], &x[i]);
        st.insert({y[i], x[i]});
        cnth[y[i]].first++;
        cntw[x[i]].first++;
    }
    sort(cnth.begin(), cnth.end(), greater<pair<int, int>>());
    sort(cntw.begin(), cntw.end(), greater<pair<int, int>>());
    int ans = cnth[0].first + cntw[0].first - 1;
    for(int i = 0; i <= h; i++){
        if(cnth[0].first != cnth[i].first) break;
        for(int j = 0; j <= w; j++){
            if(cntw[0].first != cntw[j].first) break;
            if(st.find({cnth[i].second, cntw[j].second}) == st.end()){
                printf("%d\n", ans + 1);
                return 0;
            }
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 24400
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] in = br.readLine().split(" ");
        long n = Long.parseLong(in[0]);
        int m = Integer.parseInt(in[1]);
        in = br.readLine().split(" ");
        long sum=0;
        for(int i=0;i<m;i++){
            sum+=Long.parseLong(in[i]);
        }
        if(n>=sum) {
            System.out.println(n-sum);
        }else{
            System.out.println(-1);
        }
    }
}


Measured memory_bytes: 34544
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>
using namespace std;
#define all(x) (x).begin(), (x).end()

const int N = 500000;
const long long MOD = 1e9 + 7;

long long n;
string ans;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < 2 * n + 1; i++) ans += ".";
    int l = 1, r = n + 1;
    cout << "? ";
    for (int i = 1; i <= n; i++) cout << i << " ";
    cout << endl;
    string s;
    cin >> s;
    if (s == "Red")
    {
        while (l + 1 < r)
        {
            int mid = (l + r) / 2;
            cout << "? ";
            for (int i = mid; i < mid + n; i++) cout << i << " ";
            cout << endl;
            string s;
            cin >> s;
            if (s == "Red") l = mid;
            else r = mid;
        }
        ans[l] = 'R';
        ans[l + n] = 'B';
    }
    else
    {
        while (l + 1 < r)
        {
            int mid = (l + r) / 2;
            cout << "? ";
            for (int i = mid; i < mid + n; i++) cout << i << " ";
            cout << endl;
            string s;
            cin >> s;
            if (s == "Blue") l = mid;
            else r = mid;
        }
        ans[l] = 'B';
        ans[l + n] = 'R';
    }
    for (int i = 1; i <= 2 * n; i++)
    {
        if (i < l || l + n < i)
        {
            cout << "? ";
            for (int j = l + 1; j < l + n; j++) cout << j << " ";
            cout << i << endl;
            string s;
            cin >> s;
            if (s == "Red") ans[i] = 'R';
            else ans[i] = 'B';
        }
        if (l < i && i < l + n)
        {
            cout << "? ";
            for (int j = 1; j < l; j++) cout << j << " ";
            for (int j = l + n + 1; j <= 2 * n; j++) cout << j << " ";
            cout << i << endl;
            string s;
            cin >> s;
            if (s == "Red") ans[i] = 'R';
            else ans[i] = 'B';
        }
    }
    cout << "! ";
    for (int i = 1; i <= 2 * n; i++) cout << ans[i];
    cout << endl;
}


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

using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S; cin >> S;
    if(S[0] == 'R' && S[1] == 'R' && S[2] == 'R') cout << 3 << '\n';
    else if(S[0] == 'R' && S[1] == 'R' || S[1] == 'R' && S[2] == 'R') cout << 2 << '\n';
    else if(S[0] == 'R' || S[1] == 'R' || S[2] == 'R') cout << 1 << '\n';
    else cout << 0 << '\n';
    return 0;
}

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

void bubbleSort(int *,int);
int main(){
  int n,num,i,j;
  int a[110];
  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&a[i]);
  }
  bubbleSort(a,n);
  return 0;
}

void bubbleSort(int *a, int n){
  int v,i,j;
  int flag = 1,cnt = 0;
  while(flag){
    flag =0;
    for(j = n - 1; j > 0; j--){
      if(a[j] < a[j-1]){
        v = a[j];
        a[j] = a[j-1];
        a[j-1] = v;
        flag = 1;
        cnt++;
      }
    }
  }
  for(j = 0; j < n; j++){
    if(j)printf(" ");
      printf("%d",a[j]);
  }
  printf("\n%d\n",cnt);
  return;
}



Measured memory_bytes: 2048
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n, m = LI()
ans = 0
if 2 * n <= m:
    # Sを全部使う
    ans += n
    m -= 2 * n
    n -= n
    # c のあまりで作る
    if m >= 4:
        ans += m // 4
        m -= 4 * (m // 4)
    print(ans)

else:
    ans += m // 2
    n -= m // 2
    m -= 2 * (m // 2)
    print(ans)


Measured memory_bytes: 9104
/*1 insert(T, z)
2     y = NIL // x の親
3     x = 'T の根'
4     while x ≠ NIL
5         y = x // 親を設定
6         if z.key < x.key
7             x = x.left // 左の子へ移動
8         else
9             x = x.right // 右の子へ移動
10    z.p = y
11
12    if y == NIL // T が空の場合
13        'T の根' = z
14    else if z.key < y.key
15        y.left = z // z を y の左の子にする
16    else
17        y.right = z // z を y の右の子にする*/

#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  if(x->right != NIL) return treeMinimum(x->right);
  Node y;
  y = x->parent;
  while(y !=NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y != z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

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

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

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
  }
  else return;
}

void preorder(Node u){
  if(u != NIL){
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
  }
  else return;
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20548
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const double EPS = 1.0e-10;

class Point
{
public:
    double y, x;
    Point(){
        y = x = 0.0;
    }
    Point(double y0, double x0){
        y = y0;
        x = x0;
    }
    Point operator+(const Point& p) const{
        return Point(y + p.y, x + p.x);
    }
    Point operator-(const Point& p) const{
        return Point(y - p.y, x - p.x);
    }
    Point operator*(double a) const{
        return Point(y * a, x * a);
    }
    Point operator/(double a) const{
        return Point(y / a, x / a);
    }
    double length() const{
        return sqrt(y * y + x * x);
    }
    double dist2(const Point& p) const{
        return pow(y - p.y, 2) + pow(x - p.x, 2);
    }
    double dot(const Point& p) const{
        return y * p.y + x * p.x; // |a|*|b|*cos慮
    }
    double cross(const Point& p) const{
        return x * p.y - y * p.x; // |a|*|b|*sin慮
    }
};

double segmentPointDist(const Point& a1, const Point& a2, const Point& p)
{
    if((a2-a1).dot(p-a1) < 0)
        return a1.dist2(p);
    else if((a1-a2).dot(p-a2) < 0)
        return a2.dist2(p);
    else
        return pow(abs((a2-a1).cross(p-a1)), 2) / a1.dist2(a2);
}

double segmentsDist(const Point& a1, const Point& a2, const Point& b1, const Point& b2)
{
    if(((a2-a1).cross(b1-a1) * (a2-a1).cross(b2-a1) < -EPS) && ((b2-b1).cross(a1-b1) * (b2-b1).cross(a2-b1) < -EPS))
        return 0.0;

    double ret = segmentPointDist(a1, a2, b1);
    ret = min(ret, segmentPointDist(a1, a2, b2));
    ret = min(ret, segmentPointDist(b1, b2, a1));
    ret = min(ret, segmentPointDist(b1, b2, a2));
    return ret;
}

int main()
{
    int n;
    cin >> n;
    if(n > 101 * 101 / 2){
        cout << 0 << endl;
        return 0;
    }

    vector<Point> p1(n), p2(n);
    for(int i=0; i<n; ++i)
        cin >> p1[i].x >> p1[i].y >> p2[i].x >> p2[i].y;

    double ret = DBL_MAX;
    for(int i=0; i<n; ++i){
        for(int j=0; j<i; ++j){
            ret = min(ret, segmentsDist(p1[i], p2[i], p1[j], p2[j]));
        }
    }
    printf("%.10f\n", sqrt(ret));

    return 0;
}

Measured memory_bytes: 1076
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1e18;
// using boost::multiprecision::cpp_int;

int main() {
  ll n, ans = 1, a, bans;
  bool over = false, zero = false;
  cin >> n;
  rep(i, n) {
    cin >> a;
    bans = ans;
    ans *= a;
    if (ans > INF || bans > ans) over = true;
    if (a == 0) zero = true;
  }

  if (zero)
    cout << 0 << endl;
  else
    cout << (over ? -1 : ans) << endl;
  return 0;
}


Measured memory_bytes: 3632
use std::io::{self, BufReader, Read};
use std::str::FromStr;
use std::string::String;

fn main() {
	let mut sc = ::Scanner::new(io::stdin());
	let n: i32 = sc.next_as().unwrap();
	let ans = (0..n / 4 + 1).any(|i| (n - 4 * i) % 7 == 0 );
	println!("{}", if ans { "Yes" } else { "No" });
}

#[derive(Debug)]
pub struct Scanner<R> {
	reader: BufReader<R>
}

impl<R: io::Read> Scanner<R> {
	
	pub fn new(read: R) -> Scanner<R> {
		Scanner { reader: BufReader::new(read) }
	}

	pub fn next_str(&mut self) -> Option<String> {
		let mut buf = [0; 1];
		let size = self.reader.read(&mut buf).unwrap();
		if size == 0 {
			None{}
		} else {
			let first = self.skip_whitespace(&mut buf);
			if first.is_none() {
				return None{}
			}
			let mut v = vec![buf[0]];
			loop {
				let size = self.reader.read(&mut buf).unwrap();
				if size == 0 || char::from(buf[0]).is_whitespace() {
					break;
				}
				v.push(buf[0]);
			}
			Some(String::from_utf8(v).unwrap())
		}
	}

	pub fn next_line(&mut self) -> Option<String> {
		let mut buf = [0; 1];
		let mut v :Vec<u8> = vec![];
		let mut size = self.reader.read(&mut buf).unwrap();
		if size == 0 {
			return None{}
		}
		loop {
			if size == 0 || char::from(buf[0]) == '\n' {
				return Some(String::from_utf8(v).unwrap())
			}
			v.push(buf[0]);
			size = self.reader.read(&mut buf).unwrap();
		}
	}

	pub fn next_vec<S: FromStr>(&mut self, size: u32) -> Vec<S> {
		let mut v: Vec<S> = vec![];
		for _ in 0..size {
			let token = self.next_str().unwrap();
			v.push(S::from_str(&token).ok().unwrap());
		}
		v
	}

	pub fn next_as<S: FromStr>(&mut self) -> Option<S> {
		if let Some(s) = self.next_str() {
			if let Ok(v) = S::from_str(&s) {
				return Some(v)
			}
		}
		None{}
	}

	pub fn next_i32(&mut self) -> Option<i32> {
		self.next_as::<i32>()
	}

	pub fn next_i64(&mut self) -> Option<i64> {
		self.next_as::<i64>()
	}

	pub fn next_f32(&mut self) -> Option<f32> {
		self.next_as::<f32>()
	}

	pub fn next_f64(&mut self) -> Option<f64> {
		self.next_as::<f64>()
	}

	fn skip_whitespace(&mut self, mut buf: &mut [u8]) -> Option<u8> {
		loop {
			if !char::from(buf[0]).is_whitespace() {
				return Some(buf[0])
			}
			let size = self.reader.read(&mut buf).unwrap();
			if size == 0 {
				return None{}
			}
		}
	}
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, m; 
	cin >> n >> m; 
	
	int a[n + 2]; 
	memset(a, 0, sizeof a); 
	
	for (int i = 0; i < m ; i++)
	{
		int x, y; 
		cin >> x >> y; 
		
		a[x]++; 
		a[y + 1] --; 
		
	}
	
	for(int i = 1; i <= n; ++i){
		  a[i] += a[i-1]; 
	  }
		
	 int count = 0; 
	for(int i = 1; i <= n; ++i){
		if(a[i] == m){
			count++; 
		}
	}
	
	cout << count << endl; 
}
	
	
	


Measured memory_bytes: 4068
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        x: i64,
        a: i64,
    }

    let ans = if x < a {0} else {10};

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


Measured memory_bytes: 4352
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

typedef pair<ll, ll> P;

int main() {
  ll n, h; cin >> n >> h;
  vector<P> A(n);
  loop(i,0,n) cin >> A[i].first >> A[i].second;
  sort(A.rbegin(), A.rend());
  ll max_a = A[0].first;
  ll cnt = 0;
  ll sum = 0;
  sort(A.rbegin(), A.rend(), [](const P a, const P b) {
    return a.second < b.second;
  });
  for (auto &&p: A) {
    if (p.second > max_a) {
      cnt++;
      sum += p.second;
      if (sum >= h) {
        cout << cnt << endl;
        return 0;
      }
    }
  }
  h -= sum;
  cout << cnt + h/max_a + (h%max_a != 0) << endl;
  return 0;
}


Measured memory_bytes: 4792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();

		// 期待値計算
		double[] p = new double[N];
		double[] expects = new double[N];
		for (int i = 0; i < N; i++) {
			p[i] = sc.nextDouble();
			expects[i] = (1.0 + p[i]) / 2;
		}

		// 累積和計算
		double[] S = new double[N];
		for (int i = 0; i < expects.length; i++) {
			if (i == 0) {
				S[i] = expects[i];
			} else {
				S[i] = S[i - 1] + expects[i];
			}
		}

		// 最大期待値の計算
		if (N == K) {
			System.out.println(S[S.length-1]);
		} else {
			double max = 0;
			for (int i = 0; i < S.length - K; i++) {

				double j = S[i + K] - S[i];
				if (j > max) {
					max = j;
				}
			}
			System.out.println(max);
		}
	}
}

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

int A,B,X;

int main(){
	cin>>A>>B>>X;
	if (A > X) {
		cout<<"NO"<<endl;
	}
	else if ((X - A) <= B){
		cout<<"YES"<<endl;
	}
	else {
		cout<<"NO"<<endl;
	}
}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main() {
  ll n,k;
  cin>>n>>k;
  ll a = 0;
  rep(i,0,n){
    ll b;
    cin>>b;
    if(b>=k)a++;
  }
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==5&&b==5&&c==7)
	{
	cout<<"YES"<<endl;
	return 0;
	}if(a==5&&b==7&&c==5)
	{
	cout<<"YES"<<endl;
	return 0;
	}if(a==7&&b==5&&c==5)
	{
	cout<<"YES"<<endl;
	return 0;
	}else
	cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque

def isPa(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

def MaxInP(w,k,p):
    maxinp = 0
    tmp = 0
    d = deque(w)
    while(d):
        tmp += d.popleft();
        if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
    return maxinp

n,k = [int(x) for x in input().split()]
w = deque()
for i in range(n):
    w.append(int(input()))
    
mean = int(sum(w)/k)
maxinp = MaxInP(w,k,mean)

if k == 1:
    print(mean)
else:
    minP = mean
    maxP = maxinp
    while(True):
        m = int ((minP + maxP)/2)
        if ( isPa(w,k,m) ):
            maxP = m
        else:
            minP = m
        if (minP+1 == maxP or minP == maxP):
            print(maxP)
            break

Measured memory_bytes: 12704
use std::cmp::*;
use std::io::*;
const MOD: usize = 1_000_000_007;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let mut a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();
    a.sort();

    // check
    if n % 2 == 1 {
        for i in 0..n {
            if (i + 1) / 2 * 2 != a[i] {
                println!("{}", 0);
                return;
            }
        }
    } else {
        for i in 0..n {
            if i / 2 * 2 + 1 != a[i] {
                println!("{}", 0);
                return;
            }
        }
    }
    let mut ans = 1;
    for _ in 0..n / 2 {
        ans = ans * 2 % MOD;
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#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)
typedef long long ll;
using ll = long long;
using vi = vector<int>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

ll dfs(ll sum, ll cur, int i, vi &a, int n) 
{
    if(i >= n) return sum + cur;
    // '+'
    ll Sum = dfs(sum + cur, a[i], i+1, a, n);
    // no '+'
    Sum += dfs(sum, cur * 10 + a[i], i+1, a, n);
    return Sum;
}

int main()
{
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    vi a(n);
    REP(i, n) {
        a[i] = s[i] -'0';
    }
    cout << dfs(0, a[0], 1, a, n) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);


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

    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    int res = 0;
    for (int i = 0; i < n; ++i) {
        bool good = true;

        for (auto j : graph[i]) {
            if (H[i] <= H[j]) {
                good = false;
                break;
            }
        }
        if (good) {
            ++res;
        }
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 8744
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
  int N,K; cin>>N>>K;
  REP(i,100){
    if(N/K==0){
      cout<<i<<endl;
      return 0;
    }
    N/=K;
  }
}

Measured memory_bytes: 3592
import sys
input = sys.stdin.readline

def standard_form(A):
    C = A[:]
    L = 60
    E = []
    ids = []
    for i in range(L):
        e = j0 = None
        mask = (1 << i)-1
        for j, a in enumerate(C):
            if (a >> i) & 1 and (a & mask) == 0:
                e = a
                j0 = j
                break
        else:
            continue
        ids.append(j0)
        for j, a in enumerate(C):
            if j0 == j:
                continue
            if (a >> i) & 1:
                C[j] ^= e
    return [C[e] for e in ids]


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    s = input()
    A = []
    B = []

    task = set([0])

    now = s[n-1]
    if now == "1":
        print(1)
        continue


    q = []
    win = "0"
    for i in range(n-1, -1, -1):
        if now == "0":
            if s[i] == "0":
                q.append(a[i])
            else:
                q = standard_form(q)
                task = task | set(q)
                task = set(standard_form(list(task)))
                q = [a[i]]
                now = "1"
        else:
            if s[i] == "1":
                q.append(a[i])
            else:
                q = standard_form(q)
                q = set(q) | task
                q = set(standard_form(list(q)))
                if task != task | q:
                    win = "1"
                    break

                q = [a[i]]
                now = "0"

    if now == "1":
        q = standard_form(list(q))
        q = set(q) | task
        q = standard_form(list(q))
        q = set(q)
        if task != task | q:
            win = "1"

    print(win)


Measured memory_bytes: 69888
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	now := 1
	for i := 0; i < n; i++ {
		if now > k {
			now += k
		} else {
			now *= 2
		}
	}
	fmt.Println(now)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define maxn 200086

using namespace std;

int n, x;
long long a[maxn], ans = 1e18;

int main(){
	scanf("%d%d", &n, &x);
	for(int i = 1;i <= n;i++) scanf("%lld", &a[i]);
	reverse(a + 1, a + 1 + n);
	for(int i = 1;i <= n;i++) a[i] += a[i - 1];
	for(int i = 1;i <= n;i++){
		long long sum = 1ll * (i + n) * x;
		for(int j = 1, cnt = 1;j <= n;j += i, cnt++){
			int k = min(j + i - 1, n);
			sum += (cnt == 1 ? 5 : (2 * cnt + 1)) * (a[k] - a[j - 1]);
			if(sum >= ans) break;
		}
		ans = min(ans, sum);
	}
	printf("%lld", ans);
}

Measured memory_bytes: 5276
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <bitset>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define rg register
#define LL long long
#define __space putchar(' ')
#define __endl putchar('\n')
template <typename qwq> inline void read(qwq & x)
{
    x = 0;
    rg int f = 1;
    rg char c = getchar();
    while (c < '0' || c > '9')
    {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
    {
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }
    x *= f;
}
template <typename qaq> inline void print(qaq x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    if (x > 9) print(x / 10);
    putchar(x % 10 + '0');
}
struct node
{
	int val,data;
}a[233333];
int n;
LL ans;
bitset<1000000005> s;
inline bool cmp(node x,node y)//预处理为有序 
{
	return x.val < y.val;
}
int main()
{
	read(n);
	ans = n;
	for (rg int i = 1;i <= n;++i)
	{
		read(a[i].val);
		a[i].data = i;
	}
	stable_sort(a + 1,a + 1 + n,cmp);
	for (rg int i = 1;i <= n;++i)
	{
		if (s[a[i].val]) continue;
		rg bool odd_i = i & 1,odd_data = a[i].data & 1;
		if (odd_i == odd_data) s[a[i].val] = true,--ans;//若位置变化后与变化前的奇偶性相同
		//说明他们必须用操作1才可达到,其余的均可用操作2达到 
	}
	print(ans >> 1);//一个奇数位置需要操作1,定有一个对应的偶数位置需要操作1,故/ 2 
}

Measured memory_bytes: 123648
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	int R, G;
	cin >> R >> G;
	int p = 2 * G - R;
	cout << p << endl;
	return 0;
}

Measured memory_bytes: 3608
// https://atcoder.jp/contests/dp/tasks/dp_a

import * as fs from "fs";

const split_number = (str: string): number[] => {
  return str.split(" ").map((v: string) => +v);
};

function main(input: string) {
  const lines = input.split("\n");
  const [n] = split_number(lines[0]);

  const h: number[] = split_number(lines[1]);
  let dp: number[] = new Array(n).fill(Infinity);
  dp[0] = 0;

  let result: number = 0;

  for (let i = 0; i < n; i++) {
    if (i >= 2) {
      dp[i] = Math.min(dp[i], dp[i - 2] + Math.abs(h[i] - h[i - 2]));
    }
    if (i >= 1) {
      dp[i] = Math.min(dp[i], dp[i - 1] + Math.abs(h[i] - h[i - 1]));
    }
  }

  console.log(dp[n - 1]);
}

main(fs.readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 27568
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N;
long L;
vector<pair<long,long> >A,B;
int a,b;
main()
{
	cin>>N>>L;
	for(int i=0;i<N;i++)
	{
		long l,r;cin>>l>>r;
		A.push_back(make_pair(l,1));
		A.push_back(make_pair(r,-1));
		B.push_back(make_pair(l,r));
	}
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	long r=0;
	long q=0;
	for(pair<long,long>p:B)
	{
		if(r<p.first)
		{
			r=q;
			a++;
		}
		q=max(q,p.second);
	}
	a+=r<L;
	r=0;
	b=N;
	long pre=0;
	for(pair<long,long>p:A)
	{
		if(pre!=p.first)b=min(b,(int)r);
		pre=p.first;
		if(p.second==-1)r--;
		else r++;
	}
	cout<<a<<" "<<N-b+1<<endl;
}



Measured memory_bytes: 15800
#include<stdio.h>
int maxt(int a,int b){
	if(a%b==0) return b;
	return maxt(b,a%b);
}
int minb(int a,int b){
	return a*b/maxt(a,b);
}
int main(){
	int x;
	scanf("%d",&x);
	int k=minb(x,360)/x;
	printf("%d",k);
	return 0;
}

Measured memory_bytes: 1728
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

#define ll long long
const int N = 1e5+7;

ll a[N];
ll n;
int o = 0;

int main(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		if(a[i]==0){
			cout << 0;
			return 0;
		}
	}
	ll ans = 1;
	for(int i = 1; i <= n; i++){
		if(a[i] > 1000000000000000000/ans){
			cout << -1;
			return 0;
		}
		ans *= a[i];
	}
	cout << ans;
}

Measured memory_bytes: 3900
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int slen = s.size();
  int odd_dp[slen],even_dp[slen], dp[slen];
  for(int i = 0; i < slen; i ++) {
    /*
    if(i%2 == 0){
      odd_dp[i] = 0;
      even_dp[i] = 1;
    }else {
      even_dp[i] = 1;
      odd_dp[i] = 0;
    }
    */
    dp[i] = 1;
  }
  for(int i = 0; i < slen-2; i ++){
    if(s[i] == 'R' && s[i+1] == 'R'){
      dp[i+2] += dp[i];
      dp[i] = 0;
    //}else if(s[i] == 'R',s[i+1] =='L'){
    //}else if(s[i] == 'L',
    }
  }  

  for(int i = slen; i > 1 ; i--){
    if(s[i] == 'L'&& s[i-1] == 'L'){
      dp[i-2] += dp[i];
      dp[i] = 0;
    }
  }
  for(int i = 0; i < slen; i ++) cout << dp[i] << " ";
  cout << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;

int main(){
    fastio;
    ll n, ans = 0, r = 0, g = 0, b = 0;
    string s;
    cin >> n >> s;
    ll a[n][3];
    memset(a, 0, sizeof(a));
    for(int i = n - 1; i >= 0; --i){
        if(s[i] == 'R') r++;
        else if(s[i] == 'G') g++;
        else b++;
        a[i][0] = r;
        a[i][1] = g;
        a[i][2] = b;
    }
    for(ll i = 0; i < n - 2; ++i){
        for(ll j = i + 1; j < n - 1; ++j){
            int f1 = 0, f2 = 0, f3 = 0;
            if(s[i] == 'R') f1 = 1;
            else if(s[i] == 'G') f2 = 1;
            else f3 = 1;
            if(s[j] == 'R') f1 = 1;
            else if(s[j] == 'G') f2 = 1;
            else f3 = 1;
            if(s[i] != s[j]){
                if(f1 == 0){
                    ans += a[j + 1][0];
                    if(s[2 * j - i] == 'R') ans--;
                }
                else if(f2 == 0){
                    ans += a[j + 1][1];
                    if(s[2 * j - i] == 'G') ans--;
                }
                else{
                    ans += a[j + 1][2];
                    if(s[2 * j - i] == 'B') ans--;
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3684
#include<iostream>
#include<cstdio>
#define MN 20
#define mod 1000000007
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int f[1<<MN],g[1<<MN],n,m,K,d[MN+5][MN+5],C[1<<MN],ans=0;
inline void R(int&x,int y){x+=y;x>=mod?x-=mod:0;}
int main()
{
	n=read();m=read();K=read();f[0]=1;
	for(int i=1;i<=K;++i) 
	{
		int x=read(),y=read();
		d[x][y]=read()+1;	
	}
	for(int i=1;i<1<<n;++i)
		for(int j=0;j<n;++j) if(i&(1<<j)) {C[i]=i^(1<<j);break;}	
	for(int i=1;i<=m;++i) for(int j=1;j<n;++j) 
	{
		for(int k=0;k<1<<n;++k) if(f[k])
		{
			int pre=k&((1<<j-1)-1),aft=k-pre;
			if(d[i][j]!=2&&!(aft&(1<<j-1))) R(g[k],f[k]);
			if(d[i][j]!=1) R(g[pre|(1<<j-1)|C[aft]],f[k]);
		}
		for(int k=0;k<1<<n;++k) f[k]=g[k],g[k]=0;
	}
	for(int i=0;i<1<<n;++i) R(ans,f[i]);
	cout<<ans;
	return 0;
}



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

long long pow9[4];

inline long long NchooseK(int N, int K) {
	long long res = 1;
	for (int i = 1; i <= K; i++, N--) {
		res = res * N / i;
	}
	return res;
}

long long dfs(const string& N, int index, int K, bool bounded) {
	if (K < 0) return 0;
	if (index == N.size()) {
		return K == 0;
	}
	int remain = N.size() - index;
	if (remain < K) return 0;
	if (!bounded) {
		return NchooseK(remain, K) * pow9[K];
	}
	long long res = 0;
	for (int i = 0; i <= N[index] - '0'; i++) {
		res += dfs(N, index + 1, K - (i != 0), i == N[index] - '0');
	}
	return res;
}

int main() {
	pow9[0] = 1;
	for (int i = 1; i < 4; i++) {
		pow9[i] = pow9[i - 1] * 9;
	}
	string N;
	int K;
	cin >> N >> K;
	cout << dfs(N, 0, K, true) << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
mod = 10**9+7

q1 = 0
for i in range(N):
    for j in range(i, N):
        if A[i]>A[j]:
            q1 += 1

q2 = 0
for i in range(N):
    for j in range(N):
        if A[i]>A[j]:
            q2 += 1

tmp1 = (K-1)*K//2 %mod * q2 %mod
tmp2 = q1*K%mod
ans = (tmp1 + tmp2)%mod
print(int(ans))

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

public class Main{ 
	
	static class FastReader{ 
		BufferedReader br; 
		StringTokenizer st; 

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

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

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

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

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

		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 
	}
  
  	static int findd(int n){
      int res = 0;
      while(n>0){
          res++;
          n/=10;
      }
      return res;
	}

	public static void main(String[] args) 
	{ 
		FastReader sc = new FastReader(); 
		int n = sc.nextInt(), ans=0;
		for(int i=1;i<=n;i++)
			if(findd(i)%2==1) ans++;
      
		System.out.println(ans); 
	} 
} 


Measured memory_bytes: 21460
while True:
    m = sum(map(int, input().split()))
    if not m:
        break
    n = int(input())
    fixed = [2] * m
    failures = []
    for _ in range(n):
        i, j, k, r = map(int, input().split())
        i, j, k = (x - 1 for x in (i, j, k))
        if r:
            fixed[i] = fixed[j] = fixed[k] = 1
        else:
            failures.append((i, j, k))

    for i, j, k in failures:
        fi, fj, fk = (fixed[x] for x in (i, j, k))
        if fi == 1:
            if fj == 1:
                fixed[k] = 0
            elif fk == 1:
                fixed[j] = 0
        elif fj == 1 and fk == 1:
            fixed[i] = 0

    print('\n'.join(str(x) for x in fixed))

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

using namespace std;

int main(){
    long long int N;
    int res;
    scanf("%lld",&N);

    for(long long int i=sqrt(N);i>0;i--){
        if(N%i==0){
            res = max(log10(N/i),log10(i));
            break;
        }
    }

    printf("%d\n",res+1);
    return 0;
}

Measured memory_bytes: 512