akhauriyash/Code-Regression huggingface dataset:
my $N = <>;
my @dat = split(/\s+/, <>);
my $ans = 1;
my $flag = 0; 
for(my $i=0;$i<$N;$i++){
    $ans = $ans * $dat[$i];
    if($ans>1000000000000000000){
        $flag = 1;
        $ans =1;
    }
    #print "$ans\n"; 
}
if($flag){
    if($ans ==0){
        print "0";
    }else{
        print "-1";exit;
    }
    exit;
}

print "$ans";


Measured memory_bytes: 17144
/*

*/
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((ll)(x).size())
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define cou(x) cout << x
#define cous(x) cout << x << " "
#define coul(x) cout << x << "\n"
#define ret(x) return x
#define MAX 5000001
#define start int main() {   fastio
#define finish ret(0); }
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cntv(v,a) count(v.begin(),v.end(),a)
typedef long long ll;
typedef vector<ll> VI;
typedef pair<ll,ll> PII;
typedef double db;
//mt19937 mrand(random_device{}());
const ll mod=1000000007;
//ll rnd(ll x) { return mrand() % x;}
const ll X[]= {+0,+0,+1,-1,-1,+1,-1,+1};
const ll Y[]= {-1,+1,+0,+0,+1,+1,-1,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}ret(res);}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll fact[13];
void factorial() {   fact[0]=1;  rep(i, 1, 12) fact[i]=(fact[i-1]*i);  }
vector <ll> sie; //for sieve function
ll spf[MAX+7];  //for sieve function
void sieve() {    rep(i, 2, MAX)  {  if (spf[i] == 0) {  spf[i] = i;   sie.pb(i);  }    for (ll j=0; j<SZ(sie) && i*sie[j] <= MAX && sie[j] <= spf[i]; j++)   spf[i * sie[j]] = sie[j]; }   }
// head collected

ll t, n, k, _, __,ans;
string str;

start;

    cin1(t);

    ll ok = 0, a, b, c;

    c = t % 10;
    t /= 10;
    a = t%10;
    b = t / 10;



     if( a == 7 || b == 7 || c ==  7 )
        coul("Yes");
     else
        coul( "No");



finish


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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000007
// cin.eof() 入力個数の問題
int main() {
    int n;
    cin >> n;
    unsigned long long a[n];
    rep(i, n) {
      unsigned long long t;
      cin>>t;
        a[i]=t;
        if(t==0){
          cout<<0<<endl;
          return 0;
        }
    }
    unsigned long long ans = 1;
    rep(i, n) {
if(1000000000000000000/ans<a[i]){
  cout<<-1<<endl;
  return 0;
}

        ans *= a[i];
       // cout<<ans<<endl;
        if (ans > 1000000000000000000) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define MAX 2000000000

int n, S[500000];
int L[500000/2+1], R[500000/2+1];
int cnt;

void merge(int left, int mid, int right) {
	int n1 = mid - left, n2 = right - mid;
	for (int i = 0; i < n1; i++)
		L[i] = S[left + i];
	for (int i = 0; i < n2; i++)
		R[i] = S[mid + i];
	L[n1] = MAX;
	R[n2] = MAX;
	int i = 0, j = 0;
	for (int k = left; k < right; k++) {
		if (L[i] <= R[j]) {
			S[k] = L[i];
			i++;
		} else {
			S[k] = R[j];
			j++;
		}
		cnt++;
	}
}

void mergesort(int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergesort(left, mid);
		mergesort(mid, right);
		merge(left, mid, right);
	}
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> S[i];
	cnt = 0;
	mergesort(0, n);
	for (int i = 0; i < n - 1; i++)
		cout << S[i] << " ";
	cout << S[n - 1] << endl;
	cout << cnt << endl;
	return 0;
}



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

int n,now;
char s[100010];

int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	if (s[1]=='0' || s[n]=='1') {printf("-1\n");return 0;}
	for (int i=1;i<=n/2;i++)
		if (s[i]!=s[n-i]) {printf("-1\n");return 0;}
	now=2;printf("1 2\n");
	for (int i=2;i<n;i++)
	{
		if (s[i]=='1') printf("%d %d\n",now,i+1),now=i+1;
		else printf("%d %d\n",now,i+1);
	}
}

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

int main(){
    int N; cin>>N;
    ll res = INF;
    rep(i,N){
        ll tmp = 0;
        ll a; cin>>a;
        while(a%2==0){
            a/=2;
            tmp++;
        }
        res = min(res,tmp);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3556
#include<stdio.h>
#include<math.h>
int main(){
  int i,num,count,j,sosunum;
  scanf("%d",&num);
  int a[num];
  double a2[num];
  for(i = 0 ; i< num ; i++){
    scanf("%d",&a[i]);
    if(a[i]< 2) count++;
    else if(a[i] ==2 ) {}
    else if(a[i]% 2 ==0 ) count++;
   else{
    
     for(j = 3 ; j<= sqrt(a[i]); j+=2){
      if(a[i] % j ==0){
      count++;
      break;
      }
    }
  }
  }
  sosunum = num - count;
  printf("%d\n",sosunum);
  return 0;
}



Measured memory_bytes: 2136
#include<stdio.h> 
long long fiboDP(int n) { 
    long long fibo_dp[200] = {0}; 
              fibo_dp[0] = 1;
              fibo_dp[1] = 1; 
              for(int i=2; i<=n; i++) {
                  fibo_dp[i] = fibo_dp[i-1] + fibo_dp[i-2];
                  } return fibo_dp[n]; 
    
}
int main(void){ 
    int n; scanf("%d\n", &n); 
    printf("%lld\n", fiboDP(n)); 
    return 0; } 


Measured memory_bytes: 2040
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << max(A * B, C * D) << endl;
    return 0;
};


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int[] A;
    A = new int[N+1];
    
    // ソートする
    for (int i= 1; i <= N; i++){
      A[i] = scan.nextInt();
    }
    Arrays.sort(A);
    float result=A[1];
    for (int j= 2; j <= N; j++){
      result=result/2+(float)A[j]/2;
    }
    System.out.println(result);
  
  }
 
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

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

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


int main() {
    int a, b; cin >> a >> b;

    if (b == 1) {
        cout << 0 << endl;
    } else {
        if (b <= a) {
            cout << 1 << endl;
        } else {
            cout << 1 + ((b - a) + (a - 2)) / (a - 1) << endl;
        }
    }

}

Measured memory_bytes: 384
H,W,D = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
Q = int(input())
LR = [list(map(int,input().split())) for _ in range(Q)]


numlist = [[0,0]] * (H*W+1)
for i in range(H):
    for j in range(W):
        numlist[A[i][j]] = [i,j]

ruisekiwa = [0] * (H*W+1)
for d in range(1,D+1):
    x,y = numlist[d]
    tmp = 0
    for i in range(d,H*W+1,D):
        x2,y2 = numlist[i]
        tmp += abs(x-x2)+abs(y-y2)
        x,y = x2,y2
        ruisekiwa[i] = tmp

for i in range(Q):
    start,goal = LR[i]
    ans = ruisekiwa[goal] - ruisekiwa[start]
    
    print(ans)
    
    

Measured memory_bytes: 42212
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{
    class Program
    {

        static void Main(string[] args)
        {
            String S = Console.ReadLine();
            long X = long.Parse(S);

            long ans = (X / 500) * 1000 + ((X % 500) / 5) * 5;
            Console.WriteLine(ans);

        }
    }
}

Measured memory_bytes: 13140
N,M = map(int,input().split())
H = list(map(int,input().split()))
lst = [ list(map(int,input().split())) for _ in range(M)]
hill = []
for i in range(N):
    hill.append([])

for i in range(M):
    hill[lst[i][0]-1].append(lst[i][1])
for j in range(M):
    hill[lst[j][1]-1].append(lst[j][0])


cnt = 0

for k in range(N):
    tmp = True
    for l in hill[k]:
        if H[k] <= H[l-1]:
            tmp = False
    if tmp:
        cnt += 1

print(cnt)


Measured memory_bytes: 41360
tmp = input().split()
K = int(tmp[0])

tmp = input().split()
A = int(tmp[0])
B = int(tmp[1])
flag = 0

if A == B:
    if A%K == 0:
        print('OK')
    else:
        print('NG')    
else:
    for i in range(B-A+1):
        if A%K == 0:
            print('OK')
            flag = 1
            break
        A = A + 1
    if flag == 0:
        print('NG')




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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

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

int main() {
    int n;cin >> n;
    vi x(n);
    vi y(n);
    rep(i,n)cin >> x[i] >> y[i];
    vi ord(n);
    iota(ALL(ord),0);

    double ans = 0;
    int cnt = 0;
    do{
        double length = 0;
        for(int i=0;i<n-1;i++){
            length += sqrt((ll)pow((x[ord[i]]-x[ord[i+1]]),2) + (ll)pow((y[ord[i]]-y[ord[i+1]]),2));
        }
        ans += length;
        cnt++;
    }while(next_permutation(ALL(ord)));
    cout << fixed << setprecision(10) <<  ans/(double)cnt << endl;
}


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

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << 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; }

int main(void){
    int A,B,C,X,Y; cin >> A >> B >> C >> X >> Y;
    int ans = 0;
    if(A+B < 2*C){
        ans = A*X + B*Y;
    }
    else{
        int mn = min(X,Y), mx = max(X,Y);
        ans = 2*C*mn;
        mx -= mn;
        if(X < Y){
            if(B < 2*C) ans += mx*B;
            else ans += 2*C*mx;
        }
        else{
            if(A < 2*C) ans += A*mx;
            else ans += 2*C*mx;
        }
    }
    cout << ans << endl;
    return 0;
}

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

ll dp[100005];
ll dpl[100005];
const ll MOD = 1e9+7;

int main(){
    string s;
    cin>>s;
    int n = s.size();
    dp[0]=1;
    dpl[0]=2;
    REP(i,n-1){
        if(s[i]-'0'==1){
            dp[i]=(dp[i-1]*3+dpl[i-1])%MOD;
            dpl[i]=(dpl[i-1]*2)%MOD;
        }else{
            dp[i]=(dp[i-1]*3)%MOD;
            dpl[i]=dpl[i-1];
        }
    }

    cout<<(dp[n-1]+dpl[n-1])%MOD<<endl;
    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans = 0;
    REP(i, N-2) {
        if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C') ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 1000

void insertionSort(int *, int);
  
int main(){
  int n,a[N];
  int i,j,k;
  int key;
  
 scanf("%d",&n);
  if(n <= 0 && n >= 100) return 0;

  for(i = 0 ; i <= n-1 ; i++) scanf("%d",&a[i]);
  insertionSort(a,n);
   for(k =0; k <= n-2; k++){
      printf("%d ",a[k]);
 }
   printf("%d",a[k]);
   printf("\n");
  return 0;
}
void insertionSort(int *a, int n){
  int i,j,k,key;
  
 for(i = 1 ; i <= n-1; i++){
    key = a[i];
    j = i - 1;
    for(k =0; k <= n-2; k++){
      printf("%d ",a[k]);
    }
    printf("%d",a[k]);
    printf("\n");
    while(j >= 0 && a[j] > key){
      a[j+1] = a[j];
      j--;
    a[j+1] = key;
    }
  }
}



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

graph = [[] for x in range(n)]

for i in range(n - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append((b, c))
    graph[b].append((a, c))

q, k = map(int, input().split())
k -= 1

costs = [0 for x in range(n)]
que = []
que.append((k, 0))
while que:
    now, cost = que.pop()
    costs[now] = cost
    for node in graph[now]:
        if graph[node[0]] is not None:
            que.append((node[0], cost + node[1]))
    graph[now] = None

result = ""
for i in range(q):
    x, y = map(int, input().split())
    result += str(costs[x - 1] + costs[y - 1])
    result += "\n"
print(result)


Measured memory_bytes: 45848
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

int mod = 2019;
int main()
{
    int l, r;
    cin >> l >> r;

    int min = mod + 1;
    if (r - l >= mod)
    {
        min = 0;
    }
    else
    {
        int im = l % mod;
        for (int i = l; i < r; i++)
        {
            int jm = (i + 1) % mod;
            for (int j = i + 1; j <= r; j++)
            {
                int tmp = (im * jm) % mod;
                if (min > tmp)
                {
                    min = tmp;
                }
                jm = (jm + 1) % mod;
            }
            im = (im + 1) % mod;
        }
    }
    cout << min << endl;

    return 0;
}


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

int n, a[300233], W = 0, B = 0;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    (i & 1 ? B : W) += a[i];
  }
  if (!(n & 1)) {
    printf("%d %d\n", max(B, W), min(B, W));
    return 0;
  }
  int l = 0, r = 300000001;
  while (l < r) {
    int mid = (l + r + 1) >> 1, sum = a[1];
    for (int i = 2; i <= n; i += 2) {
      if (sum >= mid) {
        sum = max(sum - a[i] + a[i + 1], a[i + 1]);
      } else {
        sum = sum - a[i] + a[i + 1];
      }
    }
    if (sum >= mid) {
      l = mid;
    } else {
      r = mid - 1;
    }
  }
  printf("%d %d\n", W + l, B - l);
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int N;
vector<int>v;
int dp[100000+1];
int culc(int i){
    if(i == N)return 0;
    if(i == 0){
        dp[i]  = 0;
    }else if(i == 1){
        dp[i] = abs(v[i]-v[i-1]);
    }
    else {
         dp[i] = min(abs(v[i]-v[i-1])+dp[i-1],
                        abs(v[i] - v[i-2])+dp[i-2]);
    }
    return culc(i+1);
}
int main(){
    cin>>N;
    v.resize(N);
    for(int i=0;i<N;i++)cin>>v[i];
    memset(dp,0,sizeof dp);
    culc(0);
    cout<<dp[N-1]<<endl;
	return 0 ;
}


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

using ll = long long;

void set_max(ll& a, ll b){
	if(b > a) a = b;
}

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	vector<ll> a(n+2, 0);
	for(int i = 1; i <= n; i++) cin >> a[i];
	int ops = 0;

	vector<ll> max_removal = {0, 0, 0};
	for(int i = 1; i <= n+1; i++){
		vector<ll> new_max_removal(5, -1);
		for(int q = 0; q <= 2; q++){
			ll r = max_removal[q];
			set_max(new_max_removal[q], min(r, a[i] - (a[i-1] - r)));
			set_max(new_max_removal[q + 1], r);
			set_max(new_max_removal[q + 1], a[i] - (a[i-1] - r));
			set_max(new_max_removal[q + 2], a[i]);
		}
		for(ll& v : new_max_removal){
			v = min(v, a[i]);
		}
		while(new_max_removal.front() == -1){
			new_max_removal.erase(new_max_removal.begin());
			ops++;
		}
		assert(new_max_removal.size() >= 3);
		new_max_removal.resize(3);
		max_removal = new_max_removal;
	}
	cout << ops << '\n';
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(){
    char s[1000];
    long sum=0;
    scanf("%s",s);
    for(;!(s[0]=='0'&&s[1]=='\0');scanf("%s",s),sum=0){
        for(int i=0;s[i]!='\0';i++){
            sum+=s[i]-'0';
        }
        printf("%d\n",sum);
    }
}


Measured memory_bytes: 2100
import sys


def resolve(in_):
    n = int(next(in_))
    c = next(in_).strip()

    # c = c.lstrip('R')
    # c = c.rstrip('W')
    # if c.count('R') == 0 or c.count('W') == 0:
    #     return 0

    wc = c.count('W')
    rc = c.count('R')
    ans = c[:rc].count('W')

    return min(wc, rc, ans)


def main():
    answer = resolve(sys.stdin)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9408
const { SSL_OP_SSLEAY_080_CLIENT_DH_BUG } = require("constants");

function Main(input) {
  input = input.split("\n");
  var ans =0;
  var X = parseInt(input[0].split(" ")[0]);
  var K = parseInt(input[0].split(" ")[1]);
  var D = parseInt(input[0].split(" ")[2]);
  if(X<0){
    X=-X;
  }
  if(X==0){
    if(D%2==0){
      ans=0;
    }else{
      ans=K;
    }
  }else if(X>K*D){
    ans=X-K*D;
  }else{
    var a = Math.floor(X/D);
    var b = X%D;
    if((K-a)%2==0){
      ans=b;
    }else{
      ans=D-b;
    }
  }


  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29620
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

ll lcm(ll a,ll b){
    return (a*b/gcd(a,b));
}

int MAX_N=200000;
int MAX_M=200000;

int main(){
    ios::sync_with_stdio(false);
    int n,m;
    int d[MAX_N],t[MAX_M];
    map<int,int> mpd,mpt;
    cin >> n;
    rep(i,n){
        cin >> d[i];
    }
    cin >> m;
    rep(i,m){
        cin >> t[i];
    }
    rep(i,n){
        mpd[d[i]]++;
    }
    rep(i,m){
        mpt[t[i]]++;
    }
    rep(i,m){
        int x=t[i];
        if(mpt[x]>mpd[x]){
            cout << "NO" <<endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    string c,d;
    cin>>c>>d;
    if(c[0]==d[2]&&c[1]==d[1]&&c[2]==d[0])
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<ctime>
#define rep(i,n) for (int i=0;i<n;i++)
//#include <bits/stdc++.h>
using namespace std;

int main(){
    int a;
    cin>>a;
    int b=a+a*a+a*a*a;
    cout<<b<<endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int h,w,maxi,dist[21][21];
bool wall[21][21];
int cx[]={0,0,1,-1};
int cy[]={1,-1,0,0};
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>h>>w;
    for (int i=1;i<=h;i++){
        for (int j=1;j<=w;j++){
            char x;
            cin>>x;
            if (x=='#') wall[i][j]=true;
        }
    }
    for (int i=1;i<=h;i++){
        for (int j=1;j<=w;j++){
            if (wall[i][j]) continue;
            memset(dist,-1,sizeof(dist));
            queue<pair<int,int> > q;
            dist[i][j]=0;
            q.push(mp(i,j));
            while (!q.empty()){
                pair<int,int> cur=q.front();
                q.pop();
                for (int k=0;k<4;k++){
                    int dx=cur.first+cx[k];
                    int dy=cur.second+cy[k];
                    if (dx<1 || dx>h || dy<1 || dy>w) continue;
                    if (wall[dx][dy]) continue;
                    if (dist[dx][dy]!=-1) continue;
                    dist[dx][dy]=dist[cur.first][cur.second]+1;
                    q.push(mp(dx,dy));
                }
            }
            for (int a=1;a<=h;a++){
                for (int b=1;b<=w;b++){
                    maxi=max(maxi,dist[a][b]);
                }
            }
        }
    }
    cout<<maxi;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;

// gcdも呼ぶ！！！
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a,   b) * b;}


int main() {
    
    ll x;
    cin>>x;
    ll l=lcm(x,360);
    fin(l/x);
    
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>
     
int main(void){
  char O[51], E[51], A[102];
  int i;
     
  scanf("%s", O);
  scanf("%s", E);
     
    for(i = 0; i < strlen(O)+1; i++){
      A[i * 2] = O[i];
      A[i * 2 + 1] = E[i];
    }
      
    printf("%s\n", A);
     
    return 0;
}

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

int main(){
	ll h, w;
	ll ans = 1001001001;
	ll yoko, tate;
	cin >> h >> w;
	if(h % 3 == 0 || w % 3 == 0){
		cout << 0 << endl;
		return 0;
	}else{
		ans = min(h, w);
	}
	
	if(h > w) swap(h, w);
	yoko = h/2;
	rep(i, w){
		if(i == 0)continue;
		ll temp1 = fabs(h*i - yoko*(w-i));
		ll temp2 = fabs(h*i - (h-yoko)*(w-i));
		ll temp3 = fabs((h-yoko)*(w-i) - yoko*(w-i));
		ll temp = max(temp1, temp2);
		temp = max(temp, temp3);
		
		ans = min(ans, temp);
	}
	
	tate = w/2;
	rep(i, h){
		if(i == 0)continue;
		ll temp1 = fabs(w*i - tate*(h-i));
		ll temp2 = fabs(w*i - (w-tate)*(h-i));
		ll temp3 = fabs((w-tate)*(h-i) - tate*(h-i));
		ll temp = max(temp1, temp2);
		temp = max(temp, temp3);
		ans = min(ans, temp);
	}
	
	cout << ans << endl;
	
	return 0;
}

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

int main(){
	int n; cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	ll ans=1e18;
	for(int i=0;i<2;i++){
		ll sum=0;
		ll cnt=0;
		ll T=(i==0)?1:-1;
		for(int j=0;j<n;j++){
			sum+=a[j];
			if(T==1){
				if(sum<T){
					cnt+=(T-sum);
					sum=T;
				}
			}
			else{
				if(sum>T){
					cnt+=(sum-T);
					sum=-1;
				}
			}
			T=-T;
		}
		ans=min(ans,cnt);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int main () {
    int x, y ,a[101][101] = {0};
    scanf("%d %d", &x , &y);
    for (int i = 0; i < x; i++)
    {
        for (int j = 0; j < y; j++)
        {
            scanf("%d", &a[i][j]);
        }
    }
    for (int i = 0; i < x; i++){
        for (int j = 0; j < y; j++){
            a[i][y] = a [i][y] + a[i][j];
            a[x][j] = a [x][j] + a[i][j];
        }
    }
    for (int i = 0; i < x; i++)
    {
        a[x][y] = a[x][y] + a[i][y];
    }
    
    
    for (int i = 0; i < x+1; i++)
    {
        for (int j = 0; j < y+1; j++)
        { 
            if (j == 0)
            printf("%d", a[i][j]);
          else
            printf(" %d", a[i][j]);
        }
        printf("\n");
        
    }
    return 0;
}


Measured memory_bytes: 2044
use std::fmt;
use std::io::stdin;
use std::io::BufRead;
use std::str;
use std::str::FromStr;

fn main() {
    let stdin = stdin();
    let mut scan = InputScanner::new(stdin.lock(),256);

    let n:usize = scan.next();
    let p:Vec<usize> = (0..(n-1)).map(|_| scan.next::<usize>()-1).collect();
    let x:Vec<usize> = (0..n).map(|_| scan.next()).collect();

    let mut tree:Vec<Vec<usize>> = Vec::with_capacity(n);
    tree.resize(n,Vec::new());

    for i in 0..(n-1) {
        tree[p[i]].push(i+1);
    }

    if search(0,n,&tree,&x).is_some() {
        println!("POSSIBLE");
    } else {
        println!("IMPOSSIBLE");
    }
}
fn search(i:usize,n:usize,tree:&Vec<Vec<usize>>,x:&Vec<usize>) -> Option<(usize,usize)> {
    let sub_tree = &tree[i];

    if sub_tree.is_empty() {
        Some((x[i],0))
    } else {
        let mut children = Vec::with_capacity(sub_tree.len());

        let mut sw = 0;
        let mut sb = 0;

        for &j in sub_tree {
            let child = search(j,n,tree,x)?;
            let &(w,b) = &child;
            children.push(child);
            sw += w;
            sb += b;
        }

        let sum = sw + sb;

        if x[i] == 0 {
            if sw == 0 {
                return Some((0, sb));
            } else {
                return Some((0, sw));
            }
        }

        let mut dp:Vec<bool> = (0..(x[i]+1)).map(|_| false).collect();

        dp[0] = true;

        for child in &children {
            let prev = dp;
            dp = (0..(x[i]+1)).map(|_| false).collect();

            let &(w,b) = child;

            for j in 0..(x[i]+1) {
                if w <= j {
                    dp[j] |= prev[j-w];
                }

                if b <= j {
                    dp[j] |= prev[j-b];
                }
            }
        }

        for j in (0..(x[i] + 1)).rev() {
            if dp[j] {
                return Some((x[i],sum - j))
            }
        }

        None
    }
}
struct InputScanner<R: BufRead> {
	reader: R,
	buf: Vec<u8>, // Should never be empty
	pos: usize,   // Should never be out of bounds as long as the input ends with '\n'
}
impl<R: BufRead> InputScanner<R> {
	fn new(reader: R, capacity: usize) -> Self {
		InputScanner {
			reader: reader,
			buf: Vec::with_capacity(capacity),
			pos: 0,
		}
	}

	#[inline]
	fn next<T: FromStr>(&mut self) -> T
	where
		T::Err: fmt::Debug,
	{
		if self.buf.is_empty() {
			self._read_next_line();
		}
		let mut start = None;
		loop {
			match (self.buf[self.pos], start.is_some()) {
				(b' ', true) | (b'\n', true) | (b'\r', true) => break,
				(_, true) | (b' ', false) => self.pos += 1,
				(b'\n', false) | (b'\r', false) => self._read_next_line(),
				(_, false) => start = Some(self.pos),
			}
		}
		let target = &self.buf[start.unwrap()..self.pos];
		unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
	}

	#[inline]
	fn _read_next_line(&mut self) {
		self.pos = 0;
		self.buf.clear();
		if self.reader.read_until(b'\n', &mut self.buf).unwrap() == 0 {
			panic!("Reached EOF");
		}
	}
}


Measured memory_bytes: 2392
ABCD=input()
dic={}
dic[1]="+"
dic[0]="-"
for i in range(8):
  result=int(ABCD[0])
  kigou=[]
  for j in range(3):
    if ((i >> j) & 1):
      kigou+=[dic[1]]
      result+=int(ABCD[3-j])
    else:
      kigou+=[dic[0]]
      result-=int(ABCD[3-j])
  if result==7:
    print(ABCD[0]+kigou[2]+ABCD[1]+kigou[1]+ABCD[2]+kigou[0]+ABCD[3]+"=7")
    break

Measured memory_bytes: 3064
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    cin >> N;
    vector<ll> L(N);
    for (ll i = 0; i < N; i++) {
        cin >> L[i];
    }
    sort(L.begin(), L.end());

    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        for (ll j = i + 1; j < N; j++) {
            //L[i], L[j]と組にして三角形ができるのは
            //L[i] + L[j]未満かつL[j] - L[i]超過かつiでもjでもない
            ll left = upper_bound(L.begin(), L.end(), L[j] - L[i]) - L.begin();
            ll right = lower_bound(L.begin(), L.end(), L[i] + L[j]) - L.begin();

            ll num = right - left;

            //i, jが含まれていたら除く
            if (left <= i && i < right) {
                num--;
            }
            if (left <= j && j < right) {
                num--;
            }

            ans += num;
        }
    }

    //同じものを3回数えているので割る
    cout << ans / 3 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int n;
  cin>>n;
  P memo[n];
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    memo[i]=make_pair(b,a);
  }
  sort(memo,memo+n);
  int ans=true;
  ll sum=0;
  for(int i=0;i<n;i++){
    sum+=memo[i].second;
    if(sum>memo[i].first) ans=false;
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, k, l; cin >> n >> k >> l;
	vector<vector<int>> g1(n);
	vector<vector<int>> g2(n);
	for (int i = 0; i < k; i++) {
		int p, q; cin >> p >>q;
		p--; q--;
		g1[p].push_back(q);
		g1[q].push_back(p);
	}
	vector<int> vis1(n, 0);
	int cnt = 0;
	function<void(int)> dfs1 = [&](int u) {
		if (vis1[u]) return;
		vis1[u] = cnt;
		for (auto v : g1[u]) dfs1(v);
	};
	for (int i = 0; i < n; i++) {
		if (!vis1[i]) {
			cnt++;
			dfs1(i);
		}
	}
	for (int i = 0; i < l; i++) {
		int r, s; cin >> r >> s;
		r--; s--;
		g2[r].push_back(s);
		g2[s].push_back(r);
	}
	vector<int> vis2(n, 0);
	vector<pair<int, int>> ccc;
	cnt = 0;
	function<void(int)> dfs2 = [&](int u) {
		if (vis2[u]) return;
		vis2[u] = cnt;
		ccc.emplace_back(vis1[u], u);
		for (auto v : g2[u]) dfs2(v);
	};
	vector<int> ans(n, 0);
	for (int i = 0; i < n; i++) {
		if (!vis2[i]) {
			cnt++;
			ccc.clear();
			dfs2(i);
			sort(ccc.begin(), ccc.end());
			for (int i = 0; i < ccc.size(); ) {
				int k;
				for (k = i; k < ccc.size() && ccc[k].first == ccc[i].first; k++);
				for (int j = i; j < k; j++) ans[ccc[j].second] = k - i;
				i = k;
			}
		}
	}
	for (int i = 0; i < n; i++) cout << ans[i] << " \n"[i == n - 1];
	return 0;
}


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

int n,k,d[12];
bool abandoned[10];
vector<int> nonAbandonedDigits;
string str;

int largerDigit(int digit) {

    for(int v: nonAbandonedDigits)
        if(v>digit)
            return v;

    return 0;
}

void finalPrint(int forbiddenIndex,int greaterNonAbandoned) {


    for(int j=0; j<forbiddenIndex; j++)
        printf("%c",str[j]);

    printf("%d",greaterNonAbandoned);

    for(int j=forbiddenIndex+1; j<str.size(); j++)
        printf("%d",nonAbandonedDigits[0]);

    puts("");

}

int main() {

    while(cin>>n>>k) {

        memset(abandoned,0,sizeof(abandoned));
        nonAbandonedDigits.clear();
        str="";

        for(int i=0; i<k; i++) {
            scanf("%d",d+i);
            abandoned[d[i]]=1;
        }


        for(int i=0; i<10; i++)
            if(!abandoned[i]) {
                nonAbandonedDigits.push_back(i);
            }

        stringstream ss;

        ss<<n;
        ss>>str;
        int i;
        for(i=0; i<str.size(); i++)
            if(abandoned[str[i]-'0'])
                break;

//        printf("leftmost abandoned position %d\n",i);

        if(i>0 && i<str.size()) {

            int greaterNonAbandoned=largerDigit(str[i]-'0');

            if(greaterNonAbandoned) {

                finalPrint(i,greaterNonAbandoned);

            } else {

                int j,v;

                for(j=i-1; j>=0; j--) {
                    v=largerDigit(str[j]-'0');
                    if(v)
                        break;
                }

//                printf("j=%d\n",j);
                if(j==-1) {
                    int v;

                    for(int x: nonAbandonedDigits)
                        if(x!=0) {
                            v=x;
                            break;
                        }

                    printf("%d",v);
                    for(int i=0; i<str.size(); i++)
                        printf("%d",nonAbandonedDigits[0]);

                    puts("");

                }else
                 finalPrint(j,v);

            }


        } else if(i==0) {

            int big=largerDigit(str[0]-'0');
            if(big)
                finalPrint(0,big);
            else {

                int v;

                for(int x: nonAbandonedDigits)
                    if(x!=0) {
                        v=x;
                        break;
                    }

                printf("%d",v);
                for(int i=0; i<str.size(); i++)
                    printf("%d",nonAbandonedDigits[0]);

                puts("");

            }


        } else {

            printf("%s\n",str.c_str());
        }

    }

    return 0;
}

/*
case 1(i):
20714 3
4 7 3

ans: 20800

case 1(ii):

29714 4
4 7 3 9
ans: 50000

2334520 5
5 6 7 8 9
ans: 2340000

8889 9
0 1 2 3 4 5 6 7 9
ans: 88888

case 2(i):
6012590 2
6 5
ans: 7000000

case 2(ii):
9714 4
4 7 3 9
ans: 10000

9714 7
4 7 3 9 1 0 2
ans: 55555


*/



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

int main() {
  int N;
  cin>>N;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin>>p[i];
  }
  sort(p.begin(), p.end());
  if(p[N-1]==0){
    cout<<"Yes"<<endl;
  }
  else if(N%3!=0){
    cout<<"No"<<endl;
  }
  else{
    int Z=0;
    int M=N/3;
    for(int i=1;i<N;i++){
      if(i==M||i==2*M){
        if(i==2*M&&p[0]==0&&p[i]==p[i-1]){
          continue;
        }
        else if(p[i]==p[i-1]){
          Z++;
          break;
        }
      }
      else{
        if(p[i]!=p[i-1]){
          Z++;
          break;
        }
      }
    }
    if(Z==0&&p[0]==(p[M]^p[M*2])){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
      
}

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int main(){
  string s,t;
  cin >> s >> t;
  ll ans = 0;
  rep(i, s.size()){
    if(s[i]!=t[i]) ans ++;
  }

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



Measured memory_bytes: 3844
class Main
{
	public static void main(String[] av)
	{
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int [] vec = new int[10];
		int j = 0;
		while( sc.hasNextInt() && j < 10 )
		{
			vec[j++] = ( sc.nextInt() );	
		}
		java.util.Arrays.sort( vec );
		for ( int i = 0; i < 3; ++i )
		{
			System.out.println( vec[9-i] );
		}
	}
}

Measured memory_bytes: 17192
N = int(input())
ans = str(N%2)
N -= N%2
i=2
while N !=0:
    if N%((-2)**i) == 0:
        ans = '0'+ans
        i += 1
    else:
        ans = '1'+ans
        N -= (-2)**(i-1)
        i += 1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
int f[35][305];
int n,C,a[15],tr[305];
int vis[15],ord[15];
double ans;
void solve(){
	memset(f,0,sizeof(f));
	f[0][a[n]*n]=1;
	int all=(1<<(n-1))-1;
	For(i,0,C*n-1){
		int id=ord[i%n];
		For(k,i,C*n) tr[k]=min(C*n,max(k,i+a[id]*n));
		if (id)
			For(j,0,all) if (!(j&(1<<(id-1))))
				For(k,i,C*n) f[j|(1<<(id-1))][tr[k]]+=f[j][k];
		For(j,0,all) f[j][i]=0;
	}
	double res=f[all][C*n];
	For(i,1,n-1) res/=C;
	ans+=res;
}
void getans(int x){
	if (x==n) return solve();
	For(i,1,n-1) if (!vis[i]){
		ord[x]=i; vis[i]=1;
		getans(x+1);
		ord[x]=0; vis[i]=0;
	}
}
int main(){
	scanf("%d%d",&n,&C);
	For(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	getans(1);
	For(i,1,n-1) ans/=i;
	printf("%.15lf\n",ans);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define int long long
const int mod = 1e9 + 7;

inline void chmax(int &a, int b) { a = max(a, b); }

signed main()
{
  int N;
  int sum = 1;
  int cnt[1005] = {0};

  cin >> N;
  for(int i = 2; i <= N; i++) {
    int now = i;
    for(int j = 2; j <= now; j++) {
      while(!(now % j)) cnt[j]++, now /= j;
    }
    cnt[now]++;
  }

  for(int i = 2; i <= N; i++) {
    sum = ((cnt[i] + 1) * sum) % mod;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	x, _ := strconv.Atoi(input())

	if x >= 30 {
		fmt.Println("Yes")
		return
	}

	fmt.Println("No")
}


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

//ACL

#include <atcoder/all>
using namespace atcoder;

//ACL END

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;

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

using bint = boost::multiprecision::cpp_int;


template<typename T, typename U>
std::istream& operator>>(std::istream& in, std::pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

const int MOD = 998244353;

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int n,m;
    cin>>n>>m;
    vector<int> a(n),b(m);
    rep(i,n)cin>>a[i];
    rep(i,m)cin>>b[i];
    vector<int> c=convolution(a,b);
    for(int it:c)cout<<it<<" ";
    cout<<endl;
}


Measured memory_bytes: 27280
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <functional>
using namespace std;

#define INF (1 << 29);
typedef long long ll;
int main(){
  int n;
  ll p[101][101];
  bool row[101][101], column[101][101];
  
  while(cin >> n, n){
    memset(p, 0, sizeof(p));
    memset(row, 0, sizeof(row));
    memset(column, 0, sizeof(column));
    
    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < n ; j++){
	cin >> p[i][j];
      }
    }

    int flag[101][101];
    memset(flag, 0, sizeof(flag));
    
    for(int i = 0 ; i < n ; i++){
      ll Min = INF;
      ll Max = -1;
      for(int j = 0 ; j < n ; j++){
	Min = min(Min, p[i][j]);
	Max = max(Max, p[j][i]);
      }
      for(int j = 0 ; j < n ; j++){
	if(p[i][j] == Min) row[i][j] = true;
	if(p[j][i] == Max) column[j][i] = true;
      }
    }   
    /*
    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < n ; j++){
	cout << flag[i][j] << ' ';
      }
      cout << endl;
    }*/
    
    ll ans = 0;
    for(int i = 0 ; i < n ; i++)
      for(int j = 0 ; j < n ; j++) if(row[i][j] && column[i][j]) ans = p[i][j]; 
    cout << ans << endl;
  }
  return 0;
}


    

Measured memory_bytes: 0
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

#if __has_include(<string_view>)
#include <string_view>
#endif
#if __has_include(<optional>)
#include <optional>

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

using namespace std;

template <class T>
constexpr const T& max(const T& a, const std::optional<T>& b)
{
    return b ? max(a, *b) : a;
}

template <class T>
constexpr const T& max(const std::optional<T>& a, const T& b)
{
    return a ? max(*a, b) : b;
}

template <class T>
constexpr const std::optional<T>& max(const std::optional<T>& a, const std::optional<T>& b)
{
    if (a && b)
        return *a > *b ? a : b;
    else if (a)
        return a;
    else
        return b;
}

template <class T>
constexpr const T& min(const T& a, const std::optional<T>& b)
{
    return b ? min(a, *b) : a;
}

template <class T>
constexpr const T& min(const std::optional<T>& a, const T& b)
{
    return a ? min(*a, b) : b;
}

template <class T>
constexpr const std::optional<T>& min(const std::optional<T>& a, const std::optional<T>& b)
{
    if (a && b)
        return *a < *b ? a : b;
    else if (a)
        return a;
    else
        return b;
}

#endif
#if __has_include(<any>)
#include <any>
#endif

template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& pair)
{
    is >> pair.first >> pair.second;
    return is;
}

template <class T>
istream& operator>>(istream& is, vector<T>& collection)
{
    for (auto& item : collection)
        is >> item;
    return is;
}

template <class T>
istream& operator>>(istream& is, valarray<T>& collection)
{
    for (auto& item : collection)
        is >> item;
    return is;
}

template <class T>
T peak_and_pop(std::queue<T>& q)
{
    assert(!q.empty());
    T t = move(q.front());
    q.pop();
    return t;
}

template <class T>
T peak_and_pop(std::priority_queue<T>& q)
{
    assert(!q.empty());
    T t = move(q.top());
    q.pop();
    return t;
}

template <class T>
T peak_and_pop(std::stack<T>& q)
{
    assert(!q.empty());
    T t = move(q.top());
    q.pop();
    return t;
}

void solution()
{
    int n;
    cin >> n;
    vector<int64_t> ls(n);
    cin >> ls;
    int count = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            for(int k = j + 1; k < n; ++k){
                if(ls[i] != ls[j] && ls[j] != ls[k] && ls[k] != ls[i] && ls[i] + ls[j] > ls[k] && ls[j] + ls[k] > ls[i] && ls[k] + ls[i] > ls[j]){
                    count++;
                }
            }
        }
    }
    cout << count << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solution();
    return 0;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

void nope() {
    cout << -1 << endl;
    exit(0);
}

int32_t main() {

    string s, t; cin >> s >> t;

    int n = s.length(), m = t.length();
    
    vector<vector<int>> inds(26);
    for(int i = 0; i < n; ++i) {
        int cur = s[i] - 'a';
        inds[cur].push_back(i+1);
    }
    
    int ans = 0;
    int times = 0;
    for(int i = 0; i < m; ++i) {
        int cur = t[i] -'a';
        vector<int>& ind = inds[cur];
        int round = ans;
        if(ind.empty()) nope();
        auto it = upper_bound(ind.begin(), ind.end(), round);
        if(it == ind.end()) {
            it = ind.begin();
            times++;
        }
        ans = *it;
    }

    cout << times*n + ans << endl;
    
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
using LL = long long;
using ULL = unsigned long long;

void coutbits(unsigned n) {
	for (int i = 31; i >= 0; i--) {
		cout << (((n >> i) & 1) ? 1 : 0);
	}
}

void solve() {
	unsigned x; cin >> x;
	coutbits(x); cout << endl;
	coutbits(~x); cout << endl;
	coutbits(x << 1); cout << endl;
	coutbits(x >> 1); cout << endl;
}

int main() {

	solve();

	return 0;
}



Measured memory_bytes: 3076