akhauriyash/Code-Regression huggingface dataset:
# 前提条件
# ・最終的な石の状態は赤い石は左に、白い石は右に集まった状態
# ・色変えは行う必要はなく、入れ替えだけ行う
# ・入れ替え前後で赤い石と白い石の総数は変わらない
# ・最終的には赤い石の総数が左に並び、白い石の総数が右に並ぶ
# ・一度の操作で、左側に並んだ赤い石の総数から右にある赤い石は一つずつしか減らせない
# ・最小回数は、左側に並んだ赤い石の総数より右にある赤い石の数、もしくは左側に並んだ赤い石の総数のなかにある白い石の数

n = int(input())
c = input()

r_cnt = c.count("R")

min_cnt = 0
for i in range(r_cnt):
    if c[i] == "W":
        min_cnt += 1
    
print(min_cnt)

Measured memory_bytes: 64912
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, t, a;
vector<i64> h;
int main() {
    cin >> n >> t >> a;
    read_n(h, n);

    i64 ans = 0, dif = 1e15;
    for (int i = 0; i < n; ++i) {
        i64 x = h[i];
        i64 k = 1000 * t - 6 * x;
        i64 d = abs(k - 1000 * a);
        if (d < dif) {
            dif = d;
            ans = i + 1;
        }
    } 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from heapq import *
from collections import *
import os
import sys
sys.setrecursionlimit(1<<30)
from io import BytesIO, IOBase
import math
import bisect
from math import inf

 
ins = lambda: [int(x) for x in input()]
inp = lambda: int(input())
inps = lambda: [int(x) for x in input().split()]
 
from fractions import Fraction as F
def main():
    
    l,r,a=inps()
    b=(l+a-1)//a
    e=(r)//a
    
    print(e-b+1)




  
 
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# endregion
 
if __name__ == "__main__":
    main()
# import threading,sys
# sys.setrecursionlimit(1000000)
# threading.stack_size(1024000)
# thread=threading.Thread(target=main)
# thread.start()

Measured memory_bytes: 72552
#include <vector>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#ifdef WIN32
#define I64 "%I64d"
#else
#define I64 "%lld"
#endif
#define speed() ios_base::sync_with_stdio(0), cin.tie()
#define pb push_back
#define mp make_pair
#define y1 y1asd
#define f first
#define s second
#define sz(s) ((int)s.size())
#define all(s) (s).begin(), (s).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
const int inf = (1 << 30) - 1;
const int N = (int)1e6 + 5;

string s;
int f[100000];
int main() {
    cin >> s;
    if (s == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1;
        return 0;
    }
    if (s.length() != 26) {
        for (int j = 0; j < s.length(); j++) {
            f[s[j]] = 1;
        }

        for (int j = 'a'; j <= 'z'; j++) {
            if (!f[j]) {
                cout << s + char(j);
                return 0;
            }
        }
    }
    int p = s.length() - 2;
    set <char> g;
    g.insert(s[p + 1]);
    while (s[p] > s[p + 1]) g.insert(s[p]), p--;
    cout << s.substr(0, p) + *g.lower_bound(s[p]);
}

Measured memory_bytes: 256
#include<cstdio>

int main() {
	int a, b;
	scanf("%d %d", &a, &b);

	int d, r;
	d = a / b;
	r = a % b;

	double f = (double)a / (double)b;

	printf("%d %d %f", d, r, f);

	return 0;
}



Measured memory_bytes: 2724
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const ld pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld radian(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int n, k, a[50], sum = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	reverse(a, a + n);
	for (int i = 0; i < k; i++) 
		sum += a[i];
	cout << sum << endl;
	getchar(); getchar();
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  int cnt;
  
  cnt = scanf("%lld %lld", n, k);

  return;
}

void get_N1234 (int64 *n1, int64 *n2, int64 *n3, int64 *n4)
{
  int cnt;

  if (n2 == NULL) {
    cnt = scanf("%lld", n1);
    return;
  }
  if (n3 == NULL) {
    cnt = scanf("%lld %lld", n1, n2);
    return;
  }
  if (n4 == NULL) {
    cnt = scanf("%lld %lld %lld", n1, n2, n3);
    return;
  }
  cnt = scanf("%lld %lld %lld %lld", n1, n2, n3, n4);
  return;
}

void omit_LF (void)
{
  char c;
  int  cnt;
  
  cnt = scanf("%c", &c);
  return;
}

char *get_S (int64 n)
{
  char *buf;
  int  i;
  int  cnt;

  buf = malloc((size_t)(n * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  cnt = scanf("%s", buf);

  return buf;
}

char *get_SN (int64 max, int64 *size)
{
  char *buf;
  int  i;
  int  n;
  int  cnt;

  buf = malloc((size_t)(max * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  cnt = scanf("%s", buf);

  n = strlen(buf);

  *size = n;
  
  return buf;
}

int64 *get_NSeq (int64 n)
{
  int64 *buf;
  int64 i;

  buf = malloc((size_t)(n * sizeof(int64)));
  for (i=0; i<n; i++) {
    get_N(&buf[i]);
  }

  return buf;
}

typedef struct _tmp_t {
  int64    a;
  int64    b;
} tmp_t;


int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}

int main()
{
  int64 a,b,c;
  unsigned long long int ua,ub,uc, ur;
  
  get_N1234(&a, &b, &c, NULL);
  
  if (c - a - b <= 0) {
    printf("No");
    return 0;
  }

  if ((4*a*b) < (c-a-b)*(c-a-b)) {
    printf("Yes");
    return 0;
  } else {
    printf("No");
    return 0;
  }

  return 0;
}



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

const int MAXN = 2e5+5 ;

typedef long long ll ;
ll as[MAXN] ;
ll bs[MAXN] ;
#define f(i,s,n) for(int i=s;i<n;i++)
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
    int n,m,k;cin>>n>>m>>k ;
    f(i,0,n) 
    {
        ll x;cin>>x ;
        if(i) as[i] = as[i-1]+x; 
        else as[i] = x ;
        
    }
    f(i,0,m)
    {
        ll x;cin>>x ;
        if(i) bs[i] = bs[i-1]+x ;
        else bs[i] = x ;
    }
    ll ans = upper_bound(as,as+n,k)-as ;
    ans = max(ans,(ll)(upper_bound(bs,bs+m,k)-bs))     ;
    f(i,0,n)
    {
        int rem = k-as[i] ;
        if(rem<=0) break ;
        int pos = upper_bound(bs,bs+m,rem)-bs ;
        ans = max(ans,(ll)(i+pos+1)) ;
    }
    cout<<ans<<"\n" ;
}


Measured memory_bytes: 6828
/*2019/09/13 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
#define MIN 999999999
#define MAX -999999999
typedef long long int ll;
typedef unsigned long long int ull;
void llswap(ll *x,ll *y){ll tmp;tmp=*x;*x=*y;*y=tmp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}
int llasc(const void *a,const void *b){return *(ll*)a-*(ll*)b;}
int lldesc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
int gcd(int x,int y){if(y==0)return x;return gcd(y,x%y);}
/*
int asc_t(const void *a,const void *b){return ((struct_t*)a)->member - ((struct_t*)b)->member;}
int desc_t(const void *a,const void *b){return ((struct_t*)b)->member - ((struct_t*)a)->member;}
*/
int main(){
    int n,k;
    int h[200000];
    int cnt=0;

    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%d",&h[i]);
        if(k<=h[i]){
            cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <algorithm>
//#include <DEBUG.h>
#define LL long long
#define NNNN 1000000
long eh[NNNN],ev[NNNN],en[NNNN];
long num[NNNN],s1[NNNN],s2[NNNN],label[NNNN];
void DFS(long root)
{
	long i,j;
	label[root]=*label;
	s1[++(*s1)]=root;
	for (i=eh[root];i>0;i=en[i])
	{
		j=ev[i];
		if (label[j]==0)
		{
			DFS(j);
		}
	}
}
int main()
{
	//freopen("in.in","r",stdin);
	long i,j,k,a,b,c,n,m,ans;
	scanf("%ld%ld",&n,&m);
	for (i=1;i<=n;i++)
	{
		scanf("%ld",&num[i]);
	}
	memset(eh,0,sizeof(*eh)*(n+1));*ev=1;
	for (i=1;i<=m;i++)
	{
		scanf("%ld%ld",&a,&b);
		ev[++(*ev)]=b;en[*ev]=eh[a];eh[a]=*ev;
		ev[++(*ev)]=a;en[*ev]=eh[b];eh[b]=*ev;
	}
	memset(label,0,sizeof(*label)*(n+1));
	ans=0;
	for (i=1;i<=n;i++)
	{
		if (label[i]==0)
		{
			*s1=0;
			*label+=1;DFS(i);
			for (j=1;j<=*s1;j++)
			{
				s2[j]=num[s1[j]];
			}
			std::sort(s1+1,s1+*s1+1);
			std::sort(s2+1,s2+*s1+1);
			//print(s1,*s1);
			//print(s2,*s1);
			for (j=1,k=1;(j<=*s1)&&(k<=*s1);)
			{
				if (s1[j]!=s2[k])
				{
					if (s1[j]<s2[k]) {j++;} else {k++;}
				}
				else
				{
					j++;k++;
					ans+=1;
				}
			}
		}
	}
	printf("%ld\n",ans);
	return 0;
}

Measured memory_bytes: 22400
#include <stdio.h>

int main(){
    int H,W,i,j;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0&&W==0){
            break;
        }
        for(i=1; i<=H; i++){
            for(j=1; j<=W; j++){
                if(i>1&&i<H&&j<W&&j>1)printf(".");
                else printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


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

int main() {
    char X, Y;
    cin >> X >> Y;
    if (X < Y) {
        cout << "<" << endl;
    }
    else if (X > Y) {
        cout << ">" << endl;
    }
    else {
        cout << "=" << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<P> p(n); // pair of <x,y>
  rep(i,n) {
    cin >> p[i].first >> p[i].second;
  }
  vector<pair<double,ll>> v(n); // pair of <angle, idx>
  rep(i,n) {
    double ang = atan2(p[i].first, p[i].second);
    v[i] = pair<double,ll>(ang, i);
  }
  sort(all(v)); // sort by angle

  double ans = 0;
  rep(i,n) { // try all starting node
    ll ang = v[i].first;
    double x = 0;
    double y = 0;
    rep(j,n) {
      ll ang2 = v[(i+j)%n].first;
      if (ang2 > ang + M_PI) { break; } // reached to theta+180

      ll idx = v[(i+j)%n].second;
      x += p[idx].first;
      y += p[idx].second;
      chmax(ans, sqrt(x*x+y*y));
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>

using namespace std;

template<class T>
struct SkewHeap {

private:

  struct node{
    node *lch,*rch;
    T val;
    node(T val):val(val){ lch=rch=NULL; }
  } *root;

public:

  SkewHeap(){root=NULL;}

  node *meld(node *a,node *b){
    if(!a || !b)return a?a:b;
    if(a->val < b->val)swap(a,b);
    a->rch=meld(a->rch,b);
    swap(a->lch,a->rch);
    return a;
  }

  void push(T x){ root=meld(root,new node(x)); }
  
  void pop(){
    node *tmp=root;
    root=meld(root->rch,root->lch);
    delete tmp;
  }

  T top(){ return root->val; }
  bool empty(){ return !root; }
  void clear(){ while(!empty())pop(); }
};

int main(void){

  SkewHeap<int> que;
  char ch[10];
  int k;

  while(true){
    scanf(" %s",ch);
    if(ch[2]=='d')break;
    if(ch[0]=='i'){
      scanf("%d",&k);
      que.push(k);
    } else {
      printf("%d\n",que.top());
      que.pop();
    }
  }

  return 0;
}

Measured memory_bytes: 32436
#include<bits/stdc++.h>
using namespace std;
#define    For(i,n) for(int i=0;i<n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    forn(i,n) for(int i=1;i<=n;i++)
#define    nl     "\n"
#define    test   int t;cin>>t;for(int l=0;l<t;l++)
#define    End    return 0
#define    gt     greater<int>()
#define    ll     long long int

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

    //test
    {
        string s;
        cin>>s;
        int x=s.size();
        if(s[x-1]=='s')cout<<s+"es";
        else cout<<s+'s';
    }
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define Check system("pause")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)



int main()
{
	ios::sync_with_stdio(false);
	ll x,k,now=100,t=0;
	cin>>x;
	while(now<x)
	{
		t++;
		k=now/100;
		now+=k;
	}
	cout<<t;
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;

int power(int N, int M) {return M ? power(N * N, M / 2) * (M % 2 ? N : 1) : 1;}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int N;
    cin >> N;
    vector<int> A(N);
    REP (i, N) {
        cin >> A[i];
        
    }
    REP(i,N) {
        if (A[i] == 0) {
            p(0);
            return 0;
        }
    }


    int ans = 1;
    REP(i,N) {
        if (A[i] > power(10,18)){
            p(-1);
            return 0;
        }
        if (ans > power(10,18)/A[i]) {
            p(-1);
            return 0;
        }
        ans *= A[i];
    }
    pa;
    

    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_b && sh test.sh
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_b && sh etest.sh
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_b && sh submit.sh
*/


Measured memory_bytes: 3980
<?php
fscanf(STDIN, "%d %d", $n, $l);
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, '%s', $s[]);
}
sort($s);
$m = "";

for($i = 0; $i < $n; $i++) {
	$m .= $s[$i];
}

echo $m."\n";

Measured memory_bytes: 4604
#include<bits/stdc++.h>
#define Rint register int
#define mem(a,b) memset(a,(b),sizeof(a))
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
#define For(i,j,k) for(Rint i=(j);i<=(k);i++)
#define Fordown(i,j,k) for(Rint i=(j);i>=(k);i--)

using namespace std;
typedef long long LL;

template<typename T>inline void read(T &x){
	x=0;T w=1,ch=getchar();
	while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^'0'),ch=getchar();
	x=x*w;
}

const LL INF=0x7f7f7f7f7f7f7f7f;
const int N=2e5+10;
int n,m;
int a[N];
LL Ans=INF,sum[N];

int main(){
	read(n);read(m);
	For(i,1,n)read(a[i]),sum[i]=a[i]+sum[i-1];
	For(i,1,n){
		int pos=n;LL res=0;
		For(j,1,n/i+1){
			int p=max(0,pos-i);
			res+=1LL*max(5,2*j+1)*(sum[pos]-sum[p]);
			if(res>Ans)break;
			pos=p;
		}
		if(res>Ans)continue;
		res+=1LL*(i+n)*m;
		Ans=min(Ans,res);
	}
	printf("%lld\n",Ans);
	return 0;
}

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

 
int main() {
  int a,b,k,ans=0,i;
  cin >> k;
  cin >> a;
  cin >> b;
  for(i=1;i*k<=b;i++){
    if(i*k>=a)
      ans=1;
  }
  if(ans==1){
    cout << "OK" << endl;
  }else{
    cout << "NG" << endl;
  }
}

Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, a[20], x, y, dat[20];
vector<pair<int, int> > vec[20];

int fun(int cur)
{
	int ret = 0, ui = 1;
	while (ui <= cur) {
		if (ui & cur) ret++;
		ui = ui << 1;
	}
	for (int i = 1; i <= n; i++) {
		dat[i] = -1;
	}
	for (int i = 1; i <= n; i++) {
		int tmp = 1 << (i - 1);
		if (tmp & cur) {
			if (dat[i] == 0) return 0;
			if (dat[i] == -1) dat[i] = 1;
			for (int j = 0; j < a[i]; j++) {
				if (vec[i][j].se == 0) {
					if (dat[vec[i][j].fi] == -1) dat[vec[i][j].fi] = 0;
					if (dat[vec[i][j].fi] == 1) return 0;
				}
				else {
					if (dat[vec[i][j].fi] == -1) dat[vec[i][j].fi] = 1;
					if (dat[vec[i][j].fi] == 0) return 0;
				}
			}
		}
		else {
			if (dat[i] == 1) return 0;
			if (dat[i] == -1) dat[i] = 0;
		}
	}
	return ret;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		for (int j = 0; j < a[i]; j++) {
			cin >> x >> y;
			vec[i].pb({ x, y });
		}
	}
	int ans = 0, U = 1 << n;

	for (int i = 0; i < U; i++) {
		ans = max(ans, fun(i));
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

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

using ll=long long;
const int inf=100000000;

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//(x,y) int型配列x[y]の受け取り

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) xの絶対値

int fact(int x){
  if (x == 1) return 1;
  return x*fact(x-1);
}//(x) x!

int fib(int x){
  if (x <= 2) return x;
  int a[x];
  a[0]=1;
  a[1]=2;
  for (int i=2;i<x;i++){
    a[i]=a[i-1]+a[i-2];
  }
  return a[x-1];
}//(x) フィボナッチ数列のx番目

int div1(ll x){
  return x%1000000007;
}

main(){
    int n=in();
    double turn=0,a[n];
    for (int i=0;i<n;i++) cin >> a[i];
    for (int i=0;i<n;i++) turn+=(1/a[i]);
    printf("%.10f",1/turn);
}

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

int main(){
  int n;
  cin>>n;
  ll vec[n];
  int vecb[30]={};
  for(int i=0;i<n;i++){
    cin>>vec[i];
    for(int x=0;x<30;x++){
      if(vec[i]&(1<<x)){
        vecb[x]++;
      }
    }
  }
  int ans[n]={};
  for(int x=0;x<30;x++){
    ll t=pow(2,x);
    if(vecb[x]%2==0&&n%2==0){
      for(int i=0;i<n;i++){
        if(vec[i]&(1<<x)){
          ans[i]+=t;
        }
      }
    }
    if(vecb[x]%2==1&&n%2==0){
      for(int i=0;i<n;i++){
        if(vec[i]&(1<<x)){
        }
        else{
          ans[i]+=t;
        }
      }
    }
    if(vecb[x]%2==1&&n%2==1){
      for(int i=0;i<n;i++){
        if(vec[i]&(1<<x)){
        }
        else{
          ans[i]+=t;
        }
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<ans[i]<<" ";
  }
}

Measured memory_bytes: 6344
n,m=map(int,input().split())
x = [list(map(int,input().split())) for i in range(m)]
eo = list(map(int,input().split()))
ans = 0
for i in range(2**n):
  sw = [0]*n
  binstr = format(i,"b").zfill(n)
  for j in range(n):
    if binstr[j] == "1":
      sw[j] = 1
  light = 0
  for k,y in enumerate(x):
    numsw = 0
    for z in range(1,y[0]+1):
      if sw[y[z]-1] == 1:
        numsw += 1  
    if numsw%2 == eo[k]:
      light += 1
  if light == m:
    ans += 1
print(ans)

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

int main(){
	int n;
	cin >> n;
	vector<pair<ll, ll>> t;
	ll a,b;
	rep(i,n){
		cin >> a >> b;
		t.push_back(make_pair(b,a));
	}
	sort(t.begin(),t.end());
	int now(0);
	rep(i,n){
		now += t[i].second;
		if(now > t[i].first){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 6128
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
 
using namespace std;
int MOD = 1000000007;
ll pow(ll x,ll n){
    ll ans = 1;
    while(n > 0){
        if(n%2 == 1) ans = ans * x;
        x = x * x;
        n = n >> 1;
    }
    return ans;
}
signed main(){

    int l;
    cin >> l;

    int cnt = 0;
    int n,m;
    n = m = 0;
    for(int bit = 20;bit >= 0;bit--){
        if((1<<bit)&l){
            if(cnt == 0){
                n = bit + 1;
                m = bit*2;
                cnt++;
            }else{
                m++;
                cnt++;
            }
        }
    }
    cout << n << " " << m << endl;
    rep(i,n-1){
        cout << i+1 << " " << i+2 << " " << 0 << endl;
        cout << i+1 << " " << i+2 << " " << pow(2,i) << endl;
    }
    int s = pow(2,n-1);
    for(int bit = n-2;bit >= 0;bit--){
        if((1<<bit)&l){
            cout << bit+1 << " " << n << " " << s << endl;
            s += pow(2,bit);
        }
    }

    return 0;   
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://abc108.contest.atcoder.jp/tasks/arc102_b
// rm -r -f test;oj dl http://yahoo-procon2017-qual.contest.atcoder.jp/tasks/yahoo_procon2017_qual_c

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define INF 0X3F3F3F3F
#define N 300005
#define M 200005
#define LL long long
#define ULL unsigned long long
#define FF(i, a, b) for(int i = a; i <= b; ++i)
#define RR(i, a, b) for(int i = a; i >= b; --i)
#define FJ(i, a, b) for(int i = a; i < b; ++i)
#define SC(x) scanf("%d", &x)
#define SCC(x, y) scanf("%d%d", &x, &y)
#define SCCC(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define SS(x) scanf("%s", x)
#define PR(x) printf("%d\n", x)
#define CL(a, x) memset(a, x, sizeof(a))
#define _P fd[rt]
#define _L fd[rt << 1]
#define _R fd[rt << 1 | 1]
#define MID int mid = ((l + r) >> 1)
#define lson rt<<1 ,l, mid
#define rson rt<<1 | 1, mid + 1, r
#define VI vector<int>
#define db double
#define PII pair<int, int>
#define PLL pair<unsigned long long, unsigned long long>
#define MP make_pair
#define PB push_back
#define IN freopen("in.txt", "r", stdin)
#define OUT freopen("out.txt", "w", stdout)
using namespace std;
const int MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-8;
inline void II(int &n){char ch = getchar(); n = 0; bool t = 0;
for(; ch < '0'; ch = getchar()) if(ch == '-') t = 1;
for(; ch >= '0'; n = n * 10 + ch - '0', ch = getchar()); if(t) n =- n;}
inline void OO(int a){if(a < 0) {putchar('-'); a = -a;}
if(a >= 10) OO(a / 10); putchar(a % 10 + '0');}
inline int sgn(double x){return (x > EPS) - (x < -EPS);}
struct EE{int v, nx;}E[M * 2 + N * 2]; int hd[N], EN;
void init_edge(int num){EN = 0; memset(hd, -1, (num + 2) << 2);}
void add_edge(int u, int v){
    E[EN].v = v; E[EN].nx = hd[u]; hd[u] = EN++;
    E[EN].v = u; E[EN].nx = hd[v]; hd[v] = EN++;
}
int col[N], n, m;
bool ok = 1;
void dfs(int u){
    for(int k = hd[u]; ~k; k = E[k].nx){
        int v = E[k].v;
        if(!col[v]){
            col[v] = 3 - col[u];
            dfs(v);
        }else {
            if(col[v] == col[u]){
                ok = 0;
                return ;
            }
        }
        if(ok == 0) return ;
    }
}
int main(){
    //IN;
    SCC(n, m);
    int u, v;
    init_edge(n);
    FF(i, 1, m){
        SCC(u, v);
        add_edge(u, v);
    }
    col[1] = 1;
    dfs(1);
    if(!ok) printf("%lld\n", 1LL * n * (n - 1) / 2 - m);
    else {
        LL a = 0, b = 0;
        for(int i = 1; i <= n; ++i){
            if(col[i] == 1) ++a;
            else ++b;
        }
        printf("%lld\n", a * b - m);
    }
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <cmath>
using std::cout;
using std::endl;
using std::cin;

bool is_prime(unsigned i){
  if(i==2)return true;
  if(i==1||!(i%2))return false;
  for(unsigned j=3;j<=sqrt(i);j+=2){
    if(!(i%j))return false;
  }
  return true;
}

int main(){
  int n,t,c=0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> t;
    if(is_prime(t))c++;
  }
  cout << c << endl;
}

Measured memory_bytes: 1160
from itertools import product
from collections import Counter

H, W, N = map(int, input().split())
V = set([tuple(map(int, input().split())) for _ in range(N)])
D = tuple(product((-1, 0, 1), repeat=2))

A = set()
cnt = Counter()
for a, b in V:
    for h, w in D:
        if 2 <= a + h <= H - 1 and 2 <= b + w <= W - 1:
            cnt[(a + h, b + w)] += 1

ans = [0] * 10
for c in cnt.values():
    ans[c] += 1

ans[0] = (H - 2) * (W - 2) - sum(ans)
print(*ans, sep='\n')


Measured memory_bytes: 186588
/* long long or int */
/* xx 396 */

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MAX_N=1e5+10;
const int MAX_M=1e5+10;

int a[MAX_N],f[MAX_N];
vector <int> V[MAX_N],other;
int n,m,cnt=0;
ll ans=0;

int findset(int x){
	if(f[x]==x) return x;
	else return f[x]=findset(f[x]); 
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	for(int i=0;i<MAX_N;i++) f[i]=i;
	cin>>n>>m;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<m;i++){
		int x,y; cin>>x>>y;
		int root_x=findset(x),root_y=findset(y);
		if(root_x!=root_y) f[root_x]=root_y;
	}
	for(int i=0;i<n;i++) if(f[i]==i) cnt++;
	if(cnt==1){
		cout<<0<<endl;
		return 0;
	}
	for(int i=0;i<n;i++){
		V[findset(i)].push_back(a[i]);
	}
	cnt=(cnt-1)*2;
	for(int i=0;i<n;i++){
		if(V[i].size()){
			sort(V[i].begin(),V[i].end());
			ans+=V[i][0]; cnt--;
			for(int j=1;j<V[i].size();j++) other.push_back(V[i][j]);
		}
	}
	if(cnt>other.size()){
		cout<<"Impossible"<<endl;
		return 0;
	}
	sort(other.begin(),other.end());
	for(int i=0;i<cnt;i++){
		ans+=other[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define fastio 	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long int
using namespace std;
int mod = 1e9 + 7;

int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio;

	int x, k, d;
	cin >> x >> k >> d;
	x = abs(x);
	int st = min(k, x / d);
	k -= st;
	x -= st * d;
	if (k & 1)
		cout << d - x;
	else
		cout << x;
	return 0;
}

Measured memory_bytes: 3684
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll a[100001];

int main(void){
	scanf("%d",&n);
	ll sum=0;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	sort(a,a+n);
	ll prev=0;
	int res=1;
	sum-=a[n-1];
	for(int i=n-2;i>=0;i--){
		if(sum*2LL>=a[i+1])res++;
		else break;
		sum-=a[i];
	}
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << ele << endl
#define print10(ele) cout << fixed << setprecision(10) << ele << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  int a, b;
  cin >> a >> b;
  int ans = a + b;
  if (ans >= 24) ans -= 24;
  print(ans);
  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define VI vector<int>
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
const int INF=1<<30; const ll LINF=1LL<<60 ; const ll MOD=1e9+7 ;
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 MX = 100000 + 7;
//int A[MX];
int n,m;

int main(){
	cin >> n >> m;
	int mxl=1;
	int mnr=n;
	FOR(i,1,m){
		int l,r; cin >> l >> r;			
		chmax(mxl, l);
		chmin(mnr, r);
	}
	if(mnr<mxl) cout << 0;
	else cout << mnr-mxl+1;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#define ll long long int
using namespace std;

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll x;
	cin >> x;
	int flag = 0;
	ll a, b, y;
	for (a = -120; a <= 120; a++)
	{
		for (b = -120; b <= 120; b++)
		{
			y = pow(a, 5) - pow(b, 5);
			if (y == x)
			{
				flag = 1;
				break;
			}
		}
		if (flag)
			break;
	}
	cout << a << " " << b;
	return 0;

}

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


int main(){
	int N,Q;
	cin>>N>>Q;
	string S;
	cin>>S;
	
	vector<pair<char,char>> pa(Q);
	
	for(int i=0;i<Q;i++){
		char t,d;
		cin>>t>>d;
		pa[i]=make_pair(t,d);
	}
	reverse(pa.begin(),pa.end());
	int out_zone_f = -1;
	int out_zone_e = N;
	for(int i=0;i<Q;i++){
		char t=pa[i].first;
		char d=pa[i].second;
		if(d=='L'){
			if(S[out_zone_f+1]==t)out_zone_f++;
			if(out_zone_e!=N){
				if(S[out_zone_e]==t)out_zone_e++;
			}
		}
		else{
			if(S[out_zone_e-1]==t)out_zone_e--;
			if(out_zone_f!=-1){
				if(S[out_zone_f]==t)out_zone_f--;
			}
		}
	}
	int out = (out_zone_f+1)+(N-out_zone_e);
	cout<<N-out<<endl;
	
	return 0;
}


Measured memory_bytes: 900
from collections import defaultdict
from itertools import groupby
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
alone = defaultdict(int)
pairs = defaultdict(int)
for k, g in groupby(X):
    l = len(list(g))
    alone[k % M] += l % 2
    pairs[k % M] += l // 2
ans = 0
for i in range(M):
    if i == 0:
        ans += alone[i] // 2
        ans += pairs[i]
    else:
        a = alone[i]
        b = alone[M - i]
        c = min(a, b)
        ans += c
        alone[i] -= c
        alone[M - i] -= c

        a = alone[i]
        b = pairs[M - i] * 2
        c = min(a, b)
        ans += c
        alone[i] -= c
        pairs[M - i] -= (c + 1) // 2

        ans += pairs[M - i]
print(ans)

Measured memory_bytes: 82448
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

char s[]="qwertasdfgzxcvb";
char in[99];

int main(){
	while(scanf(" %s",in),*in!='#'){
		int pre=-1,ans=-1;
		ll n=strlen(in);
		rep(i,0,n){
			int crr=!!strchr(s,in[i]);
			ans+=pre!=crr;
			pre=crr;
		}
		printf("%lld\n",ans);
	}
}


Measured memory_bytes: 2040
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    int r, d, x;
    cin >> r >> d >> x;
    for (int i = 0; i < 10; i++) {
        x = r * x - d;
        cout << x << endl;
    }
}

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

struct e {
	int to, co;
	e() {}
	e(int t, int c) {
		to = t; co = c;
	}
};

int N;
vector<vector<e> > edge;
const int INF = 1e9;
vector<int> path;

int cost(int n, int p) {
	int res = 0;
	if(edge[n].size() == 1)
		return 0;
	for(int i = 0; i < edge[n].size(); i++) {
		if(edge[n][i].to != p)
			res += cost(edge[n][i].to, n);
		else
			res += edge[n][i].co * 2;
	}
	return res;
}

bool search_path(int n, int p, int g) {
	if(n == g) {
		path.push_back(n);
		return true;
	}
	for(int i = 0; i < edge[n].size(); i++) {
		if(edge[n][i].to != p && search_path(edge[n][i].to, n, g)) {
			path.push_back(n);
			return true;
		}
	}
	return false;
}

int main() {
	while(cin >> N, N) {
		edge.clear();
		edge.resize(N);

		for(int i = 0; i < N-1; i++) {
			int a, b, t;
			cin >> a >> b >> t;
			a--; b--;
			edge[a].push_back(e(b, t));
			edge[b].push_back(e(a, t));
		}

		int ans = INF;
		for(int i = 0; i < N; i++) {
			path.clear();
			search_path(0, -1, i);
			int tmp = 0;
			for(int i = 0; i < path.size(); i++) {
				for(int j = 0; j < edge[path[i]].size(); j++) {
					if((i-1 < 0 || edge[path[i]][j].to != path[i-1]) &&
							(i+1 >= path.size() || edge[path[i]][j].to != path[i+1]))
						tmp += cost(edge[path[i]][j].to, path[i]);
					if(i > 0  && edge[path[i]][j].to == path[i-1]) {
						tmp += edge[path[i]][j].co;
					}
				}
			}
			ans = min(ans, tmp);
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 1224
import java.util.*;
import java.util.stream.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt(), p = scanner.nextInt();
        System.out.println(IntStream.range(0, n).allMatch(i -> scanner.nextInt() % 2 == 0) ? p == 1 ? 0 : 1L << n : 1L << n - 1);
    }
}

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

using namespace std;

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (register int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
#define DOWNTO(var, from, to) for (register int var = (from); var >= ((int)to); var--)
#define FOR(var, to)          UPTO(var, 0, (to)-1)
#define DOWN(var, from)       DOWNTO(var, (from)-1, 0)

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

#define MOD 1000000007
#define INF ((1 << 30)-1)
#define LINF ((1LL << 62)-1)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

struct Comb {
    vector<vector<s64> > data;
    Comb(int n) { // O(n^2)
        data = vector<vector<s64> >(n+1,vector<s64>(n+1,1));
        UPTO(i,1,n) {
            FOR(j,i+1) {
                if (!j || j == i) data[i][j] = 1;
                else data[i][j] = data[i-1][j-1] + data[i-1][j];
            }
        }
    }

    s64 ncr(int n, int r) {
        return data[n][r];
    }
};

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
	int n = ri();
	double a[n];
	bool b[n];
	FOR(i,n) {
		cin >> a[i];
		string s; cin >> s;
		b[i] = s == "BTC";
	}

	double res = 0;
	FOR(i,n) {
		if (b[i]) res += a[i] * 380000.0;
		else res += a[i];
	}

	printf("%.9f", res);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    Cin(int, a, b, k);
  	for(int i = 100; i > 0; i --){
		if(a % i == 0 && b % i == 0){
          k --;
          if(k == 0){
            Cout(i); return 0;
          }
        }
    }
    Cout();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,k,ba=0;
	cin>>a>>b>>k;
	for(int t=min(a,b);t>0;t--)
	{
		if(a%t==0&&b%t==0)
		{
			ba++;
			//cout<<t<<" ";
		}
		if(ba==k)
		{
			cout<<t;
			return 0;
		}
	}
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,ans = 13;
  cin >> n;
  for (int i=1;i<=sqrt(n);i++){
    if (n % i == 0){
      ans = min(ans,(long long)to_string(n/i).size());
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rng(a) a.begin(),a.end()
#define pb push_back
#define descend greater<int>()
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
 
int main() {
  int n, k; cin >> n >> k;
  vi v[n];
  for (int i=0; i<n; i++){
    int t; ll d; cin >> t >> d; t--;
    v[t].pb(d);
  }
  vp p;
  for (int i=0; i<n; i++){
    if (sz(v[i])>0){
      sort(rng(v[i]), descend);
      for (int j=0; j<sz(v[i]); j++){
        if (j==0){
          p.pb(P(v[i][j], 1));
        }
        else p.pb(P(v[i][j], 0));
      }
    }
  }
  sort(rng(p));
  reverse(rng(p));
  
  ll point;
  ll x=0;
  ll y=0;
  stack<ll> st;
  for (int i=0; i<k; i++){
    x += p[i].first;
    if (p[i].second ==1){
      y ++;
    }
    else st.push(p[i].first);
  }
  point = x + y*y;
  
  ll ans = point;
  ll point_ch;
  
  for (int i=k; i<n; i++){
    if (!st.empty()){
    if (p[i].second == 1){
      y ++;
      x = x + p[i].first -st.top(); st.pop();
      point_ch = x + y*y;
      ans = max(ans, point_ch);
    }
    }
  }
      cout << ans << endl;
      return 0;
}

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

int main()
{
	int n,m;
	cin >> n >> m;
	vector<vector<ll>> dis(n,vector<ll>(n,1e9));
	for(int i = 0;i<n;i++)dis[i][i]=0;

	vector<pair<pair<ll,ll>,ll>> input(m);
	for(int i = 0;i<m;i++)
	{
		cin >> input[i].first.first >> input[i].first.second >> input[i].second;
		input[i].first.first --;
		input[i].first.second--;
		dis[input[i].first.first][input[i].first.second] = input[i].second;
		dis[input[i].first.second][input[i].first.first] = input[i].second;
	}
	for(int k = 0;k<n;k++)
	{
		for(int i = 0;i<n;i++)
		{
			for(int j = 0;j<n;j++)
			{
				dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]);
			}
		}
	}
	int cnt = 0;
	for(int i =0;i<m;i++)
	{
		int x = input[i].first.first;
		int y = input[i].first.second;
		int c = input[i].second;
		if(dis[x][y] != c) cnt++;
	}
	cout << cnt << endl;
	


}


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

int main()
{
  int result, N;
  cin >> N;
  
  for (int i = 0; i < N; i++)
  {
    int sum, A;
    cin >> A;
    
    for (sum = 0; A % 2 == 0; sum++)
      A /= 2;
    if (result > sum || i == 0)
      result = sum;
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
using namespace std;

int main(void)
{
    int a, b;
    int i, o;

    cin >> a >> b;
    for(i = 1, o = 0; i < b; i = i - 1 + a, o ++)
        ;
    cout << o << endl;

    return 0;
}


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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long

static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const ll INF = 1e18;

int main() {

    ll A;
    double B;
    cin >> A >> B;
    int B_ = B * 100 + 0.9;
    // cout << B_;
    ll ans = A * B_ / 100;

    cout << ans << endl;

}

/*
みんな、くるくるぱーにな〜れ
　∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/



Measured memory_bytes: 3752