akhauriyash/Code-Regression huggingface dataset:
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var M = one[1];
  var dp = new Array(1 << N);
  dp[0] = 0;
  for(var i = 0; i < M; i++){
  	var tmp = nextIntArray();
  	var cost = tmp[0];
  	var size = tmp[1];
  	var keys = nextIntArray();
  	var sumKeys = 0;
  	for(var j = 0; j < size; j++){
  		sumKeys += Math.pow(2, keys[j] - 1);
  	}
  	var ato = makeClone(dp);
  	for(var j = 0; j < (1 << N); j++){
  		if(dp[j] != null){
  			if(ato[j | sumKeys] == null){
  				ato[j | sumKeys] = dp[j] + cost;
  			}else{
  				ato[j | sumKeys] = Math.min((dp[j] + cost), ato[j | sumKeys]);
  			}
  		}
  	}
  	dp = ato;
  }
  myout((dp[(1 << N) - 1] == null) ? "-1" : dp[(1 << N) - 1]);
}


Measured memory_bytes: 39424
// Problem : C - H and V
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_c
// Memory Limit : 1024 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}
bool check(int x,int y,vs &v,int k)
{
	vs vt=v;
	int cnt=0;
	for(int i=0;i<size(v);i++)
	{
		for(int j=0;j<size(v[i]);j++)
		{
			if((x&(1<<i)) or (y&(1<<j)))
			vt[i][j]='R';
		}
	}
	for(int i=0;i<size(v);i++)
	{
		for(int j=0;j<size(v[i]);j++)
		{
			if(vt[i][j]=='#')
			cnt++;
		}
	}
	return cnt==k;
}
void solve()
{
	int n,m,k;
	cin>>n>>m>>k;
	vs v(n);cin>>v;
	int ans=0;
	for(int i=0;i<(1<<n);i++)
	{
		for(int j=0;j<(1<<m);j++)
		{
			//cout<<bitset<5>(i)<<" "<<bitset<5>(j)<<"\n";
			if(check(i,j,v,k))
			ans++;
		}
	}
	cout<<ans;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 3652
//21, 07, 2018, 10:01:47 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;

typedef unsigned long long ull;

const int M = 2e8, N = 3010;
int a[N];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n;

    cin >> n;

    int ans = 0;

    for(int i = 0 ; i < n ; i++){
        cin >> a[i];
        ans += a[i] - 1;
    }    

    cout << ans << endl;

    return 0;
}

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


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define lint long long

using namespace std;
string s;
int k;

int main(){
  cin >> s >> k;
  REP(i,k){
    if(s[i]=='1') continue;
    else{
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
  return 0;
}


Measured memory_bytes: 256
/*      ...वहां तूफान भी हार जाते हैं जहां कश्तियां जिद पर होती हैं !...        */
#include <bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define fl(i,a,n) for(int i=a; i<n; i++)
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define test()  int tt;  cin>>tt;  while(tt--)
#define nl  cout<<"\n"
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)    {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}
const int mod=1e9+7;

vector<int> adj[100005];
vector<int> dp(100005,-1);
int longest_path(int node)  {
    if(dp[node]!=-1)    return dp[node];
    int ans=0;
    for(auto i:adj[node])   {
        ans=max(ans,1+longest_path(i));
    }
    return dp[node]=ans;
}
int main()  {
    fast;
    int n,m;    cin>>n>>m;
    int a,b;
    fl(i,0,m)   {
        cin>>a>>b;
        adj[a].pb(b);
    }
    int ans=0;
    fl(i,1,n+1)   {
        ans=max(ans,longest_path(i));
    }
    cout<<ans;
    
}

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

int main() {
  int n, k; cin >> n >> k;
  vector<int> h(n);
  rep(i,n) {
    cin >> h[i];
  }
  sort(h.begin(),h.end());
  int dh = 0, cnt = 0, ans = 1e9+5;
  rep(i,n-k+1) {
    dh = h[i+k-1] - h[i];
    ans = min(ans, dh);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin>>n;
    int ans=0;
    for(int a=1;a<=n;a++){
        for(int b=1;b<=a;b++){
            if(a*b<n){
                if(a==b)ans++;
                else ans+=2;
            }
            else break;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3648
n = int(input())
s = [list(input()) for _ in range(n)]

s_dict = dict([])

for i in s:
    key = ''.join(sorted(i))
    s_dict.setdefault(key, 0)
    s_dict[key] += 1

ans = 0
for v in s_dict.values():
    ans += v * (v - 1) // 2
print(ans)

Measured memory_bytes: 37080
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/

/////////////////////////////////


int main(){
    int n;cin>>n;
    char s[2][n+1];cin>>s[0]>>s[1];
    int a[n];
    for(int i=0;i<=n-1;i++){
        if(s[0][i]==s[1][i])a[i]=0;
        else a[i]=1;
    }
    int pos;ll ans;int last;
    if(a[0]==0){
        ans=3;
        pos=1;
        last=0;
    }else{
        ans=6;
        pos=2;
        last=1;
    }
    while(pos<=n-1){
        if(a[pos]==0){
            if(last==0){
                ans=mod(ans*2);
            }
            last=0;
            pos+=1;
        }else{
            if(last==0){
                ans=mod(ans*2);
            }else{
                ans=mod(ans*3);
            }
            last=1;
            pos+=2;
        }
    }
    
    cout<<ans<<endl;
    return 0;
}


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

int main(void){

  int x1,y1,x2,y2;
  scanf("%d %d %d %d\n", &x1, &y1, &x2, &y2);

  int x3,y3,x4,y4;

  x3 = x2 - y2 + y1;
  y3 = y2 + x2 - x1;
  x4 = x3 - x2 + x1;
  y4 = y3 - y2 + y1;

  printf("%d %d %d %d\n", x3, y3, x4, y4);
  return 0;
}


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

#define vt          vector
#define sz(x)       int((x).size())
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

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

void solve() {
    int a, b;
    cin >> a >> b;
    if (a < b) cout << string(b, char('0' + a));
    else cout << string(a, char('0' + b));
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);

    int tcs = 1;
    for (int tc = 1; tc <= tcs; tc++) {
        // cout << "Case " << tc << ": ";
        solve();
    }
}


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

int64_t N, A, B;
vector<int64_t> hs;

/// Returns ceil(x / y).
int64_t ceilDiv(int64_t x, int64_t y) { return (x + y - 1) / y; };

bool enough(int64_t T) {
  int64_t n_needs = 0;
  for (auto& h : hs) {
    if (h > B * T) {
      n_needs += ceilDiv(h - B * T, A - B);
    }
  }
  return n_needs <= T;
}

int main() {
  cin >> N >> A >> B;
  hs = vector<int64_t>(N);
  for (auto& h : hs) cin >> h;
  int64_t left = 0;
  //int64_t right = *max_element(hs.begin(), hs.end()) + 1;
  int64_t right = numeric_limits<int>::max();
  int64_t mid;
  while (right - left > 1) {
    mid = (left + right) / 2;
    if (enough(mid))
      right = mid;
    else
      left = mid;
  }
  cout << right << endl;
}


Measured memory_bytes: 1024
L, R = map(int, input().split())
L_resi = L % 2019
R_resi = R % 2019
if R - L >= 2018:
    ans = 0
else:
    residue = []
    if L_resi < R_resi:
        residue = [i for i in range(L_resi, R_resi+1)]
    else:
        residue = [i for i in range(0, R_resi+1)] + [i for i in range(L_resi, 2019)]
    ans = 10**100
    for i in residue:
        for j in residue:
            if i < j:
                ans = min(ans, (i*j) % 2019)
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

void func(int *x, int *y) {
	int *temp;
	
	if(y > x) {
		temp = y;
		y = x;
		x = temp;
	}
}

int max_kouyakusu(int a, int b) {
	int r;
	int temp;

	func(&a, &b);
	r = a % b;

	if(r == 0) return b;

	while(r) {
		r = a % b;
		a = b;
		b = r;
	}
	

	return a;
}

int min_koubaisu(int a, int b) {
	int max_kouyaku = max_kouyakusu(a, b);
	int x = a / max_kouyaku;
	int y = b / max_kouyaku;

	int ans = x * y * max_kouyaku;

	return ans;
}

int main() {
	int a, b;

	while(scanf("%d %d", &a, &b) != EOF) {
		printf("%d %d\n", max_kouyakusu(a, b), min_koubaisu(a, b));
	}

	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define dump(x) cerr << #x << " : " << x << '\n'
#define MOD(x, y) (((y) + (x) % (y)) % (y))

int N, Y;

int main(int argc, char* argv[])
{
	scanf("%d%d", &N, &Y);
	/*
	for (int i = 0; i <= 2000; i++) {
		for (int j = 0; j <= 2000; j++) {
			int k = N - i - j;
			if (i < 0 || j < 0 || k < 0) continue;
			if (10000 * i + 5000 * j + 1000 * k == Y) {
				printf("%d %d %d\n", i, j, k);
				return 0;
			}
		}
	}
	printf("-1 -1 -1\n");
	*/

	Y /= 1000;
	int K = Y - N;
	for (int x = K / 9; x >= max(K / 9 - 4, 0); x--) {
		int A = K - 9 * x;
		if (A % 4 != 0) continue;
		int y = A / 4;
		int z = N - x - y;
		if (z < 0) continue;
		printf("%d %d %d\n", x, y, z);
		return 0;
	}
	printf("-1 -1 -1\n");

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  lint n, k; cin >> n >> k;
  vector<lint> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  vector<lint> c(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }

  lint ans = -INF;
  for (int i = 0; i < n; i++) {
    lint start = i;
    lint step = 0;
    lint score = 0;

    lint cur = start;
    while (1) {
      cur = p[cur];
      step++;
      score += c[cur];
      if (cur == start) break;
    }

    if (score < 0) {
      // 一番ええところでやめる
      lint tmp = 0;
      step = 0;
      cur = start;
      while (step < k) {
        cur = p[cur];
        step++;
        tmp += c[cur];
        ans = max(ans, tmp);
        if (cur == start) break;
      }
    } else {

      // 回れるだけ回った後，一番ええところでやめる
      lint cnt = k / step;
      cnt = cnt - 1;
      if (cnt < 0) cnt = 0;

      lint tmp = cnt * score;
      lint rest = k - cnt * step;
      cur = start;
      step = 0;
      int hoge = 0;
      while (step < rest) {
        cur = p[cur];
        step++;
        tmp += c[cur];
        ans = max(ans, tmp);
        if (cur == start) {
          hoge++;
          if (hoge > 5) break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3688
{-# LANGUAGE BangPatterns, OverloadedStrings #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import qualified Data.Set as S
import System.IO.Unsafe
import Debug.Trace

unew :: VUM.Unbox a => Int -> VUM.IOVector a
unew !n = accursedUnutterablePerformIO $ VUM.unsafeNew n

uread :: VUM.Unbox a => Int -> VUM.IOVector a -> a
uread !i !v = accursedUnutterablePerformIO $ VUM.unsafeRead v i

uwrite :: VUM.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite !i !a !v =
  accursedUnutterablePerformIO $ VUM.unsafeWrite v i a >> return v

uthaw :: VUM.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw !v = accursedUnutterablePerformIO $ VU.unsafeThaw v

ufreeze :: VUM.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze !v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

solve :: B.ByteString -> B.ByteString -> String
solve !s !t = walk
 where
  toIndex !i !j = j * succ (B.length s) + i
  fromIndex !n = (n `mod` succ (B.length s), n `div` succ (B.length s))

  dp :: VU.Vector Int16
  dp = ufreeze $ foldl'
    ( \(!dp) (!n) ->
      let (!i, !j) = fromIndex n
      in  uwrite
            n
            ( if i == 0 || j == 0
              then 0
              else
                let dpij  = uread (toIndex (i - 1) (j - 1)) dp
                    dpisj = uread (toIndex i (j - 1)) dp
                    dpsij = uread (toIndex (i - 1) j) dp
                    si    = s `B.index` (i - 1)
                    tj    = t `B.index` (j - 1)
                in  if si == tj then dpij + 1 else max dpisj dpsij
            )
            dp
    )
    (unew $ succ (B.length s) * succ (B.length t))
    [0 .. succ (B.length s) * succ (B.length t) - 1]

  walk = fst $ fix
    ( \(!f) (!acc, (!i, !j)) -> if i == 0 || j == 0
      then (acc, (i, j))
      else if s `B.index` (i - 1) == t `B.index` (j - 1)
        then f (s `B.index` (i - 1) : acc, (i - 1, j - 1))
        else if dp VU.! toIndex (i - 1) j < dp VU.! toIndex i (j - 1)
          then f (acc, (i, j - 1))
          else f (acc, (i - 1, j))
    )
    ([], (B.length s, B.length t))

main = do
  s <- B.getLine
  t <- B.getLine
  putStrLn $ solve s t


Measured memory_bytes: 19068
n = int(input())
a  = list(map(int, input().split()))

odd_ans = 0
odd_sum = 0
odd = []
for i in range(n):
	odd_sum += a[i]
	if i%2 == 1:
		if odd_sum <= 0:
			odd_ans += 1-odd_sum
			odd_sum = 1
	else:
		if odd_sum >= 0:
			odd_ans += odd_sum +1
			odd_sum = -1

			
even_ans = 0
even_sum = 0

for i in range(n):
	even_sum += a[i]
	if i%2 == 0:
		if even_sum <= 0:
			even_ans += 1-even_sum
			even_sum = 1
	else:
		if even_sum >= 0:
			even_ans += even_sum+1
			even_sum = -1
print(min(odd_ans, even_ans))

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

int n;
long long a[100000], ans = 1, t = 1000000000000000000;
double l = 0;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (!a[i]) {
			cout << 0 << endl;
			return 0;
		}
	}
	for (int i = 0; i < n; i++) {
		ans *= a[i];
		l += log(a[i]);
	}
	l /= log(10);
	cout << (l <= 18 && ans <= t ? ans : -1) << endl;
}


Measured memory_bytes: 4548
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <queue>
using namespace std;
typedef long long ll;

int main(){
	ll n, a, b, c, d;
	scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &c, &d);
//	cerr<<b - a<<endl;
	if(n == 1){
		if(a ^ b)puts("NO");
		else puts("YES");
	}
	else{
		n--;
		for(ll i = 0, j;i <= n;++i){
			j = n - i;
			ll l1 = i * c, r1 = i * d;
			ll l2 = j * c + b - a, r2 = j * d + b - a;
			if(r1 < l2)continue;
			if(r2 < l1)continue;
			puts("YES");
			return 0;
		}
		puts("NO");
	}
	return 0;
}
/*
491995 412925347 825318103 59999126 59999339
4 7 6 4 5
*/


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

int main () {
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
	}
	sort(arr, arr+n);
	double sum = arr[0];
	for (int i = 1; i < n; ++i) {
		sum = (sum + arr[i]) / 2;
	}
	cout << sum << endl;
	return 0;
}

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

int main(int argc,char** argv)
{
	int count = 0;
	char s[4];
	scanf("%s",s);

	for(int i = 0; i < 3; i++){
		if(s[i]=='1') count++;
	}

	printf("%d\n",count );
	return(0);

}

Measured memory_bytes: 128
def main():
    A, B = map(int, input().split())
    while B!= 0: A, B = B, A % B 
    print(num_prime_factor(A))

def num_prime_factor(n):
    
    if n == 1: return 1
    
    ret = 1
    cursor = 2
    if n % cursor == 0: ret += 1
    while n % cursor == 0: n = n // cursor
    
    cursor = 3
    while cursor**2 <= n:
        if n == 1: return ret
        if n % cursor == 0: ret += 1
        while n % cursor == 0: n = n // cursor
        cursor += 2

    if n != 1: ret += 1
        
    return ret

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
from collections import deque

N = int(input())
A = list(map(int, input().split()))

check = [0] * N

for i in reversed(range(1, N + 1)):
    if sum(check[i - 1::i]) % 2 != A[i - 1]:
        check[i - 1] = 1

M = sum(check)
ans = deque()

for index, value in enumerate(check):
    if value == 1:
        ans.append(index + 1)

print(M)
if M > 0:
    print(*ans)


Measured memory_bytes: 14484
#include<bits/stdc++.h>
using namespace std;
int n,in;
map<int,bool> a;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&in);
		if(!a[in])
			a[in]=true;
		else
		{
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int numofbits(unsigned long long bits) {
    bits = (bits & 0x5555555555555555) + (bits >> 1 & 0x5555555555555555);
    bits = (bits & 0x3333333333333333) + (bits >> 2 & 0x3333333333333333);
    bits = (bits & 0x0f0f0f0f0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f0f0f0f0f);
    bits = (bits & 0x00ff00ff00ff00ff) + (bits >> 8 & 0x00ff00ff00ff00ff);
    bits = (bits & 0x0000ffff0000ffff) + (bits >> 16 & 0x0000ffff0000ffff);
    return (bits & 0x00000000ffffffff) + (bits >> 32 & 0x00000000ffffffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n;
    int N = pow(2, n);
    rep(i, N) {
        cout << i << ":";
        m = i;
        for(int j = 0; m > 0; j++) {
            if(m & 1) cout << " " << j;
            m /= 2;
        }
        cout << "\n";
    }
}



Measured memory_bytes: 3312
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
using namespace std;
using ll = unsigned long long;
using p = pair<int, int>;

int main()
{
    auto x = vector<int>(5);
    cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];

    rep(i, 0, 5)
    {
        if (x[i] == 0)
        {
            cout << i + 1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3584
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; fori (i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; fori (i, 1, n) {fori (j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) fori (i, 1, n) {fori (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(s) (int)(s.size())
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define sort1(v) sort(v.begin(), v.end()) 
#define endl '\n'
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 
     
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);


    //start from here

    string s; cin >> s;

    if(s[2] == s[3] && s[4] == s[5]) cout << "Yes";
    else cout << "No";

    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct node
{
    long long x;
    long long h;
    long long delta;
};
node nodes[200007];
long long index = 0;
long long n, d, a, ans;
bool cmp(node x, node y)
{
    return x.x < y.x;
}
int find(long long x)
{
    int l = 0, r = n, mid;
    while (r - l > 0)
    {
        mid = (r + l) / 2;
        if (nodes[mid].x > x)
            r = mid;
        else
            l = mid;
        if (r - l == 1)
            return l;
    }
    return -1; //ERROR
}
int main()
{
//    freopen("in.txt", "r", stdin);
    long long _, __;
    long long l, r, times;
    scanf("%lld%lld%lld", &n, &d, &a);
    for (long long i = 0; i < n; i++)
    {
        scanf("%lld%lld", &nodes[index].x, &nodes[index].h);
        index++;
    }
    sort(nodes, nodes + n, cmp);
    for (long long i = 0; i < n; i++)
    {
        nodes[i].delta = nodes[i].h - ((index) ? (nodes[i - 1].h) : (0));
    }
    //Input End
    index = 0;
    while (index < n)
    {
        if (nodes[index].delta > 0)
        {
            l = index;
            r = find(nodes[index].x + d + d) + 1;
            times = (nodes[l].delta + a - 1) / a;
            ans += times;
            nodes[r].delta += times * a;
            nodes[l].delta -= times * a;
        }
        index++;
        if (index < n)
        {
            nodes[index].delta += nodes[index - 1].delta;
        }
    }
    cout << ans << endl;
}
/*

5 4 3 2 1
5-1-1-1-1
5-1-1-1-1
0-1-1 4-1




*/

Measured memory_bytes: 4992
package main
 
import "fmt"

func main() {
  var s string
  a := 0
  b := 0
  
  fmt.Scan(&s)
  
  for i:=0; i<len(s); i++{
    if s[i] == 48 {
      a++
    } else {
      b++
    }
  }
  
  if a<b {
    fmt.Println(a*2)
  } else {
    fmt.Println(b*2)
  }
  
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

     auto f = [&](int length) -> bool {
        int cnt = 0;
        for(const auto& logs: a) {
            cnt += (logs+length-1)/length - 1;
        }
        if (cnt>k) return false;
        else return true;
    };

    int left = 0; int right = *max_element(all(a)); // 下限を-1（0もありうるので）、上限を1e12+10にする（1e12ちょうどもありえるので）
    int mid; // 上限がllなのでmidもllにする
    while (right-left>1) {
        mid = (left+right)/2; // 上限＋下限を2で割って中間点を求める
        if (f(mid)) right = mid; // 中間点で条件を満たすなら、上限を中間点に変える
        else left = mid; // そうでなければ下限を中間点に変える（※どちらに狭めるかは求めたいもの次第）
    }

    cout << right << endl;
}

Measured memory_bytes: 3984
#include<stdio.h>
int main(){
  double w;
  int f;
  char *p[11]={"light fly","fly","bantam","feather","light","light welter",
	       "welter","light middle","middle","light heavy","heavy"};

  while(scanf("%lf",&w)!=EOF){
    if(w<=48)f=0;
    else if(w<=51)f=1;
    else if(w<=54)f=2;
    else if(w<=57)f=3;
    else if(w<=60)f=4;
    else if(w<=64)f=5;
    else if(w<=69)f=6;
    else if(w<=75)f=7;
    else if(w<=81)f=8;
    else if(w<=91)f=9;
    else f=10;
    printf("%s\n",p[f]);
  }
  return 0;
}

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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int a,b,c;

main() {
    cin >> a >> b >> c;
    if (a+b < c) ct("No")
    else ct("Yes")
}






Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
int main()
{
	std::stack<double> s;
	double a, b;
	char c[80], bf;
	while (std::cin >> c)
	{
		if (c[0] == '+')
		{
			b = s.top(), s.pop();
			a = s.top(), s.pop();
			s.push(a+b);
		}
		else if (c[0] == '-' && c[1] == 0)
		{
			b = s.top(), s.pop();
			a = s.top(), s.pop();
			s.push(a-b);
		}
		else if (c[0] == '*')
		{
			b = s.top(), s.pop();
			a = s.top(), s.pop();
			s.push(a*b);
		}
		else if (c[0] == '/')
		{
			b = s.top(), s.pop();
			a = s.top(), s.pop();
			s.push(a/b);
		}
		else
		{
			s.push(atof(c));
		}
		if ((bf = getchar()) == '\n')
			printf("%.6f\n", s.top());
		if (bf == -1)
			return 0;
	}
}

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

vector<ll> f(string s) {
  int n = s.size();
  vector<ll> v;
  ll INF = 1LL << 32;
  ll acc = 0;

  for (int i = 0; i < n; i++) {
    if (s[i] >= 'a' && s[i] <= 'z') {
      if (acc) {
        v.push_back(acc);
        acc = 0;
      }
      v.push_back(INF + s[i]);
    } else if (s[i] >= 'A' && s[i] <= 'Z') {
      if (acc) {
        v.push_back(acc);
        acc = 0;
      }
      v.push_back(INF + s[i]);
    } else {
      acc *= 10;
      acc += s[i] - '0';
    }
  }
  if (acc) {
    v.push_back(acc);
  }
  v.push_back(0);
  return v;
}

bool g(vector<ll> l, vector<ll> r) {
  int n = l.size();
  int m = r.size();
  for (int i = 0; i < n && i < m; i++) {
    if (l[i] < r[i]) {
      return true;
    } else if (l[i] > r[i]) {
      return false;
    }
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  n++;
  vector<string> s(n);
  vector<vector<ll>> v(n);
  for (int i = 0; i < n; i++)
    cin >> s[i];
  for (int i = 0; i < n; i++) {
    v[i] = f(s[i]);
  }
  for (int i = 1; i < n; i++) {
    if (g(v[0], v[i])) {
      cout << "+" << endl;
    } else {
      cout << "-" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3396
#include <bits/stdc++.h>
using namespace std;
#define int long long
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int N; cin>>N;
    string line; cin>>line;

    int red=0;
    int white=0;
    rep(i,line.size()){
        if(line.at(i)=='R'){
            red++;
        }else{
            white++;
        }
    }
    // 左端からred個の間にいくつRがあるかを数える
    int red2=0;
    for(int i=0;i<red;i++){
         if(line.at(i)=='R'){
            red2++;
        }
    }
    cout<<red-red2<<endl;

    return 0;
}

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

A,color=[x],["white" for _ in range(m)]
color[x]="black"
while 1:
    num=A[-1]**2%m
    if color[num]=="black":
        A.append(num)
        break
    else:
        color[num]="black"
        A.append(num)

fixed,loop=[],[]
point=A[-1]
flag=0
for i in A[:-1]:
    if i==point:flag=1

    if flag:loop.append(i)
    else:fixed.append(i)

ans=0
if n<=len(fixed):print(sum(fixed[:n]))
else:
    ans +=sum(fixed)
    div,mod=divmod(n-len(fixed),len(loop))
    ans +=div*sum(loop)
    ans +=sum(loop[:mod])
    print(ans)

Measured memory_bytes: 80992
#include <bits/stdc++.h>
#define pb(a) push_back(a)
#define loop(i,a,b) for(i=a;i<b;i++)

using namespace std;

typedef vector<long> vi;
int main(){
    vi numbers;
    long n,i,r;
    scanf("%ld",&n);
    loop(i,0,n){
        scanf("%ld",&r);
        numbers.pb(r);
    }
    int cont=0;
    long long res = 0;
    r=0;
    loop(i,0,n){
        //printf("Primera: %lld %d %ld\n",res,cont,numbers[i]);
        if(r==2){cont=0; r=0;}
        if(numbers[i]>0){
            if (numbers[i]%2!=0 && cont ==0){
                cont=1;
                res +=(numbers[i]/2);
                //printf("%d %d",numbers[i],res);
            }
            else if (numbers[i]%2!=0 && cont==1){
                cont=0;
                r=0;
                res +=(numbers[i]+1)/2;
                //printf("aca \n");
            }
            else if (numbers[i]%2==0 && cont==0){
                res +=numbers[i]/2;
            }else if(numbers[i]%2 == 0 && cont==1){
                res  +=(numbers[i]+1)/2;
                r=0;
            }
        }
        if (cont==1)r+=1;
        //printf("Segunda: %lld %d %ld %ld\n",res,cont,numbers[i],r);

    }
    printf("%lld",res);

    return 0;

}


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

int main(){
  char x;
  cin >> x;
  if(x == 'a' || x=='b' || x=='c' || x =='d' || x =='e' || x=='f' || x=='g' || x=='h' || x=='i' || x=='j' || x=='k' || x=='l' || x=='m' || x=='n' || x=='o' || x=='p' || x=='q' || x=='r' || x=='s' || x=='t' || x=='u' || x=='v' || x=='w' || x=='x' || x=='y' || x=='z')
    cout << 'a' << endl;
  else
    cout << 'A' << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(void){
    vector<int>v(55556,1);vector<int>prime;
    v.at(0)=0;v.at(1)=0;
    int count;
    for(int i=2;i*i<=55555;i++){
        if(v.at(i)==1){
            for(int j=2;i*j<=55555;j++){
                v.at(i*j)=0;
            }
        }
    }
    vector<int>ans;
    rep(i,55556){
        if(v.at(i)==1&&i%5==1)ans.push_back(i);
    }
    int n;cin>>n;
    rep(i,n)cout<<ans.at(i)<<' ';
}

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

using namespace std;
#define rep(i,n) for (int i =0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;

int main() {
	int L;
	int ans = 0;
	cin >> L;
	if(L*L*L>1000000)	cout << L * L * L / 27;
	else   cout << double(L*L*L)/27;
	
}

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

template<typename T> inline T read() {
	T x(0), f(1);
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x*10)+(ch^48);
	return x * f;
}

long long ans;

int main() {
	long long ai = read<int>();
	ans += read<int>();
	read<int>();
	long long p = read<int>(), q = read<int>();
	long long res = ((ai>>1)<<1)+((p>>1)<<1)+((q>>1)<<1);
	if(ai > 0 && p > 0 && q > 0) {
		p--, q--, ai--;
		res = max(res, 3+((ai>>1)<<1)+((p>>1)<<1)+((q>>1)<<1));
	}
	ans += res;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while (n != 0) {
            int y = sc.nextInt();
            int m = sc.nextInt();
            int d = sc.nextInt();
            if ((m | y | d) == 0)
                break;
            int c = 0;
            while (y != 1000 || m != 1 || d != 1) {
                c++;
                if (y % 3 == 0) {
                    d++;
                    if (d == 21) {
                        d = 1;
                        m++;
                        if (m == 11) {
                            y++;
                            m = 1;
                        }
                    }
                } else {
                    if (m % 2 != 0) {
                        d++;
                        if (d == 21) {
                            d = 1;
                            m++;
                            if (m == 11) {
                                y++;
                                m = 1;
                            }
                        }
                    } else {
                        d++;
                        if (d == 20) {
                            d = 1;
                            m++;
                            if (m == 11) {
                                y++;
                                m = 1;
                            }
                        }

                    }
                }
            }
            System.out.println(c);
            n--;
        }
    }
}

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

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

	if (s[0]!=s[1] && s[1]!=s[2] && s[2]!=s[3]) {
		cout << "Good" << endl;
	
	}
	else {
		cout << "Bad" << endl;
	}
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {  
  		Scanner sc = new Scanner(System.in);
      	int[] ary = new int[3];
      	for(int i = 0; i < ary.length; i++) {
        	ary[i] = sc.nextInt();
        }
      	Arrays.sort(ary);
      	System.out.println(
          (ary[1] - ary[0]) + (ary[2] - ary[1]));
    }
}

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

int main() {
   string s, t, u;
   int a, b;
   cin >> s >> t >> a >> b >> u;
   
   if (0 == u.compare(s)) {
     cout << a - 1 << " " << b << endl;
   } else {
     cout << a << " " << b - 1 << endl;
   }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i= 0; i <(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main()
{
    int k;
    cin >>k;
    int x = 7%k;
    set<int> s;
    int i=1;
    for (int i=1;i<=k;++i)
    {
        if (x==0){
            cout << i <<endl;
            return 0;
        }
        x = (x*10+7)%k;
    }
    cout << -1 << endl;
       return 0;
}

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

int main() {
	string w;
	for (int k = 0; k < 10; k++) {
	    cin >> w;

		if (w == "-") break;

		else {
			int m = 0, h = 0;
			cin >> m;
			int A = w.size();
			for (int i = 0; i < m; i++) {
				cin >> h;
				string w_tmp;
				w_tmp = w;
				w.erase(w.begin() + 0, w.begin() + h);
				w_tmp.erase(w_tmp.begin() + h, w_tmp.begin() + A);
				w = w + w_tmp;
			}
			cout << w << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3160
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
int cnt[MAXN], a[MAXN];

int main() {
	int n, mx = 0; ni(n);
	for (int i = 1; i <= n; i++) {
		ni(a[i]);
		cnt[a[i]]++;
		mx = max(mx, a[i]);
	}
	for (int i = (mx+1)/2; i <= mx; i++) {
		if (mx & 1) {
			if (cnt[i] < 2)
				return !printf("Impossible\n");
		} else {
			if (cnt[i] < 2 && i != mx/2)
				return !printf("Impossible\n");
			if (cnt[i] < 1 && i == mx/2)
				return !printf("Impossible\n");
		}
		cnt[i] -= 2;
		if (i == (mx+1) / 2 && !(mx & 1))
			cnt[i]++;
	}
	for (int i = 0; i <= (mx+1) / 2; i++)
		if (cnt[i])
			return !printf("Impossible\n");
	return !printf("Possible\n");
}


Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;


int main(){
    ll S, W;

    //input
    cin >> S >> W;

    if(S <= W){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }

    return 0;
}


Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
from itertools import accumulate

n, m = map(int, input().split())
A = list(map(int, input().split()))
L = [0]*(2*m)
B = []
cnt = 0
for i in range(n-1):
  a, b = A[i], A[i+1]
  a -= 1
  b -= 1
  if a < b:
    cnt += b-a
    if b-a == 1:
      continue
    L[a+2] += 1
    L[b+1] += -1
    B.append((b+1, -(b-a-1)))
  else:
    b += m
    cnt += b-a
    if b-a == 1:
      continue
    L[a+2] += 1
    L[b+1] += -1
    B.append((b+1, -(b-a-1)))
L = list(accumulate(L))
for i, b in B:
  L[i] += b
L = list(accumulate(L))
c = 0
for i in range(m):
  c = max(c, L[i]+L[m+i])
ans = cnt - c
print(ans)

Measured memory_bytes: 37316
#include<bits/stdc++.h>
using namespace std;
//#include<stdio.h>
//#include<string.h>
typedef long long ll;
ll h,a[100005]={0},t,sum=0,su=0;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&t);
		a[i]=t;
		if(a[i-1]>=a[i])
		{
			sum+=1;
		}
		else
		{
			if(sum>su)
			{
				su=sum;
				sum=0;
			}
			else
			{
				sum=0;
			}
		}
	}
	if(sum>su)
	{
		su=sum;
	}
	printf("%lld",su);
}

Measured memory_bytes: 1024
#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-1); i >= 0; --i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    vector<vector<int>> D(C, vector<int>(C));
    rep(i, C)rep(j, C) cin >> D[i][j];

    vector<vector<int>> A(N, vector<int>(N));
    rep(i, N)rep(j, N) {
        cin >> A[i][j];
        A[i][j]--;
    }

    vector<vector<int>> cnt(3, vector<int>(C));
    rep(i, N)rep(j, N) {
        int g = (i + j) % 3;
        int c = A[i][j];
        cnt[g][c]++;
    }

    int ans = INF;
    rep(i, C) {
        rep(j, C) {
            rep(k, C) {
                if (i == j || i == k || j == k) continue;
                int res = 0;
                rep(c, C) {
                    res += cnt[0][c] * D[c][i];
                    res += cnt[1][c] * D[c][j];
                    res += cnt[2][c] * D[c][k];
                }
                chmin(ans, res);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
using namespace std;


int main() {
    ll n, time = 0;
    string s = "Yes";
    cin>>n;
    
    vector<ll> a(n);
    vector<ll> b(n);
    
    rep(i, n) cin>>a[i]>>b[i];
    
    vector<pair<int, int>> p(n);
    
    rep(i, n) p[i] = make_pair(b[i], a[i]);
    
    Sort(p);
    
    //rep(i, n) cout<<p[i].first<<" "<<p[i].second<<endl;
    
    rep(i, n){
        time += p[i].second;
        if(p[i].first<time){
            s = "No";
            break;
        }
    }
    
    cout<<s<<endl;
    
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long LL;
const LL MOD = 998244353;
const int N = 5e5;

int n,m;
LL fac[N+5],ifac[N+5],pwn1[N+5],pwm1[N+5];

LL pw(LL x,int n){
	LL res=1;
	for(int y=1;y<=n;y<<=1,x=x*x%MOD) if(n&y) res=res*x%MOD;
	return res;
}

int main(){
	cin>>n>>m;
	fac[0]=1;
	rep(i,1,N)fac[i]=fac[i-1]*i%MOD;
	ifac[N]=pw(fac[N],MOD-2);
	rrep(i,N-1,0)ifac[i]=ifac[i+1]*(i+1)%MOD;
	pwn1[0] = pwm1[0] = 1;
	rep(i,1,N) pwn1[i]=pwn1[i-1]*(n+1)%MOD, pwm1[i]=pwm1[i-1]*(m+1)%MOD;
	
	LL ans = 0;
	rep(i,0,min(m,n)){
		LL tmp = fac[m] * ifac[i] % MOD * ifac[m-i] % MOD * fac[n] % MOD * ifac[n-i] % MOD * pwn1[m-i] % MOD * pwm1[n-i] % MOD;
		ans = (i % 2 == 0) ? (ans + tmp) % MOD : (ans - tmp + MOD) % MOD;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 16000
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

s = rr()
left = s.index('A')
right = s.rindex('Z')
print(right-left+1)















Measured memory_bytes: 27124
import sys
from math import factorial
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N = INT()
N = str(N)
for i in range(len(N)):
    if N[i] == '7':
        print('Yes')
        sys.exit()
print('No')

Measured memory_bytes: 72700
import math,itertools

N = int(input())
x = [0]*N
y = [0]*N
for i in range(N):
    x[i], y[i] = map(int, input().split())

dis = [[0.0 for i in range(N)] for j in range(N)]
for i in range(N):
    for j in range(i+1,N):
        dis[i][j] = math.sqrt( (x[i]-x[j])**2 + (y[i]-y[j])**2 )
        dis[j][i] = dis[i][j]

sum = 0
for n in itertools.permutations(range(N)):
    for i in range(N-1):
        sum += dis[n[i]][n[i+1]]

print(sum/math.factorial(N))


Measured memory_bytes: 3064
using System;
class p
{
  static void Main()
  {
    string S = Console.ReadLine();
    string T = Console.ReadLine();
    string s = T.Substring(0, S.Length);
    string diff = T.Remove(0, S.Length);
    Console.WriteLine((diff.Length == 1 && S == s) ? "Yes" : "No");
  }
}

Measured memory_bytes: 25884