akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
   
// g++ -std=c++11 prac.cpp
        
int main(){
    ll n,m=-1,k,w,sum=1,ans=0,Max=-1e9,Min=1e9+1;
    string s,t,u;
    bool count=false,ok=true;
    cin >> n;
    VI a(n);
    VI b(n);
    rep(i,n){
        cin >> a[i];
        if(a[i]%2==0)
            b[i]=2;
        else
            b[i]=1;
    }
    rep(i,n){
        sum *= b[i];
    }
    cout << pow(3,n) - sum<< endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define speed ios_base::sync_with_stdio(0); cin.tie(0);
#define FL(i,a,n) for(ll i=a;i<n;i++)
#define even(x) (((x)%(2))==(0))
#define odd(x) (((x)%(2))==(1))
#define meme(x) memset(x, 0, sizeof(x))
#define mod 1000000007

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

int main()
{
    speed
    
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int cnt=0;
    
    while(a>=b)
    {
            b=b*2;
            cnt++;  
    }
    while(b>=c)
    {
            c=c*2;
            cnt++;
    }
    

    if(cnt<=k)
    {
         cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    
        
    
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define all(c) begin(c),end(c)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
//最大公約数
ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}
//最小公倍数
ll lcm(ll x, ll y) {
  return x/gcd(x, y)*y;
}
//素因数分解
vector<pair<ll,int>> factorize(ll n) {
  vector<pair<ll,int>> res;
  for (ll i = 2; i*i <= n; ++i) {
    if (n%i) continue;
    res.emplace_back(i,0);
    while (n%i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n,1);
  return res;
}
 
 
 ll mod=998244353;
 
int main() {
  char a;
  cin>>a;
  if((a>='a')&&(a<='z')){
    cout<<'a';
    return 0;
  }

  cout<<'A';



}



Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main(){
long int A,B,C,K;
cin>>A>>B>>C>>K;
if (abs(A-B)>1000000000000000000)
cout<<"Unfair"<<endl;
else if(K%2==0)
cout<<A-B<<endl;
else if(K%2==1)
cout<<B-A<<endl;
}

Measured memory_bytes: 256
while 0 != n = gets.to_i do
  map = Hash.new(0)
  n.times do
    id, cost, vol = gets.split.map(&:to_i)
    map[id] += cost * vol
  end
  map.sort{|a, b| b <=> a}
  z = map.select{|k, v| v >= 1000000}.each{|a, b| puts a}
  puts "NA" if z.empty?
end

Measured memory_bytes: 6116
n, m, k = map(int, input().split())
connect = [[] for _ in range(n)]
cCnt = [0 for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    connect[a - 1].append(b - 1)
    cCnt[a - 1] += 1
    connect[b - 1].append(a - 1)
    cCnt[b - 1] += 1

group = [0 for _ in range(n)]
gNum = 0
import queue
for i in range(n):
    if group[i]:
        continue
    gNum += 1
    next = queue.Queue()
    for j in connect[i]:
        group[j] = gNum
        next.put(j)
    group[i] = gNum

    while not next.empty():
        j = next.get()
        group[j] = gNum
        for l in connect[j]:
            if not group[l]:
                group[l] = gNum
                next.put(l)

hunaka = [0 for i in range(n)]
for i in range(k):
    c, d = map(int, input().split())
    if group[c - 1] != group[d - 1]:
        continue
    hunaka[c - 1] += 1
    hunaka[d - 1] += 1

groupCnt = [0 for _ in range(gNum + 1)]
for i in group:
    groupCnt[i] += 1

for i in range(n):
    tmp = groupCnt[group[i]]
    tmp -= cCnt[i]
    tmp -= hunaka[i]
    tmp -= 1
    print(tmp, end = " ")


Measured memory_bytes: 91164
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 100005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n,k;
   cin>>n>>k;
   set<pii>s;
   if(((n-1)*(n-2))/2 < k)
   {
       cout<<-1<<endl;
   }
   else
   {
       for(int i=1;i<n;i++)
       s.insert({i,n});
       int c= ((n-1)*(n-2))/2 ;
       for(int i=1;i<(n-1) && c>k;i++)
       {
           for(int j=(i+1);j<n && c>k;j++)
           {
               s.insert({i,j});
               c--;
           }
       }
       cout<<s.size()<<endl;
       for(auto x:s)
        cout<<x.F<<" "<<x.S<<endl;
   }
}



Measured memory_bytes: 640
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std ;

typedef long long ll ;
#define rep (i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	string A, B, C;
	
	cin >> A >> B >> C;

	cout << A[0] << B[0] << C[0] << endl;

	
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <string.h>
#include <math.h>
#include <map>
#include <time.h>
using namespace std;

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

	cout << a*b / 2 << endl;

	return 0;
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
    int N, K;
    cin >> N >> K;
    N--;
    K--;
    int ans;
    if(N % K == 0) ans = N / K;
    else ans = N / K + 1; 
print(ans);
}

Measured memory_bytes: 256
S = gets.chomp
black_first = '01' * 500000
white_first = '10' * 500000
diff_with_black_first, diff_with_white_first = 0, 0
0.upto(S.length - 1) do |i|
  s = S.slice(i, 1)
  diff_with_black_first += 1 if s != black_first.slice(i, 1)
  diff_with_white_first += 1 if s != white_first.slice(i, 1)
end
puts [diff_with_black_first, diff_with_white_first].min

Measured memory_bytes: 3964
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Control.Monad         (replicateM)
import qualified Data.ByteString.Char8 as BC
import           Data.Int              (Int64)
import           Data.List             (minimum, sort)
import           Data.Maybe            (fromJust)

type Point = (Int, Int)
type Rect = (Point, Point)

main :: IO ()
main = do
  [n, k] <- getInts
  ps <- getPoints
  print $ solve n k ps

solve :: Int -> Int -> [Point] -> Int64
solve n k ps = minimum $ map area rs' where
  rs' = filter isValid rs
  rs  = [((x1, y1), (x2, y2)) | x1 <- xs
                              , x2 <- xs
                              , x1 < x2
                              , y1 <- ys
                              , y2 <- ys
                              , y1 < y2
                              ]
  (xs, ys) = (sort (map fst ps), sort (map snd ps))
  isValid r = length (filter (isIncluded r) ps) >= k

isIncluded :: Rect -> Point -> Bool
isIncluded ((x1, y1), (x2, y2)) (a, b) = x1 <= a && a <= x2 && y1 <= b && b <= y2

area :: Rect -> Int64
area ((x1, y1), (x2, y2)) = (x2' - x1') * (y2' - y1') where
  x1' = fromIntegral x1
  y1' = fromIntegral y1
  x2' = fromIntegral x2
  y2' = fromIntegral y2

readInts :: BC.ByteString -> [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words

getInts :: IO [Int]
getInts = readInts <$> BC.getLine

getIntss :: IO [[Int]]
getIntss = map readInts . BC.lines <$> BC.getContents

getPoints :: IO [Point]
getPoints = map (\[x, y] -> (x, y)) <$> getIntss


Measured memory_bytes: 2300
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int res = 0;

        if (N < 10) {
            res = N;
        } else if (10 <= N && N < 100) {
            res = 9;
        } else if (100 <= N && N < 1000) {
            res = N - 99 + 9;
        } else if (1000 <= N && N < 10000) {
            res = 900 + 9;
        } else if (10000 <= N && N < 100000) {
            res = N - 9999 + 900 + 9;
        } else if (N == 100000) {
            res = 90909;
        }
        System.out.println(res);
        return;
    }
}



Measured memory_bytes: 21844
# coding: utf-8
def II(): return int(input())
def ILI(): return list(map(int, input().split()))


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def read():
    N = II()
    T = [II() for __ in range(N)]
    return N, T


def solve(N, T):
    ans = T[0]
    for i in range(1, N):
        ans = lcm(ans, T[i])
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
import sys
def main():
  input=sys.stdin.readline
  h,w=map(int,input().split())
  a=[list(map(int,input().split())) for _ in range(h)]
  b=[list(map(int,input().split())) for _ in range(h)]
  m=80*162
  flg=(1<<(m*2))-1
  dp=[[0]*w for j in range(h)]
  dp[0][0]|=1<<(a[0][0]-b[0][0]+m)
  dp[0][0]|=1<<(b[0][0]-a[0][0]+m)
  for i in range(h):
    for j in range(w):
      if i<h-1:
        ne=abs(a[i+1][j]-b[i+1][j])
        dp[i+1][j]|=(dp[i][j]<<ne)&flg
        dp[i+1][j]|=(dp[i][j]>>ne)&flg
      if j<w-1:
        ne=abs(a[i][j+1]-b[i][j+1])
        dp[i][j+1]|=(dp[i][j]<<ne)&flg
        dp[i][j+1]|=(dp[i][j]>>ne)&flg
  ans=10**10
  for i in range(160*162):
    if (dp[h-1][w-1]>>i)&1:
      ans=min(ans,abs(i-m)) 
  return print(ans)
if __name__=='__main__':
  main()


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

int main(void){
	int n ;
  	std::cin >> n;
 	int temp;
  	std::vector<int> read;
  	for(int i = 0; i < n; ++i){
    	std::cin >> temp;
      	read.push_back(temp);
    }
  	std::sort(read.begin(), read.end());
  	double sum = read[0];
  	for(int i = 1; i < read.size(); ++i){
    	sum = (sum + (double)read[i]) / 2;
    }
  	std::cout << sum;
  	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

ll dp[310][310];

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
  }
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      dp[i][j] = 1e18;
    }
  }
  dp[0][0] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      for (int k = 0; k <= i - 1; ++k) {
        dp[i][j] = min(dp[i][j], dp[k][j - 1] + max(0, h[i] - h[k]));
      }
    }
  }
  ll ans = 1e18;
  for (int i = 0; i <= n; ++i) {
    ans = min(ans, dp[i][n - k]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
import math
mod = int(1e9+7)

N = int(input())

factorial_of_n = math.factorial(N)

def countOfPrimeFactors(n):
    # when n > factorial(196), system may overflows
    # if then, try to replace 'int(n**0.5)+1' by 'n'
    count_of_prime_factors = {}
    if n > 1:
        count = 0
        while n % 2 == 0:
            n //= 2
            count += 1
        if count != 0:
            count_of_prime_factors.update({2: count})
        if n == 1: 
            return count_of_prime_factors 

        for i in range(3, n, 2):
            count = 0
            while n % i == 0:
                n //= i 
                count += 1
            if count != 0:
                count_of_prime_factors.update({i: count})
            if n == 1: 
                return count_of_prime_factors 
              
        count_of_prime_factors.update({n: 1})
        return count_of_prime_factors 
    else:
        return {}

ans = 1
for prime_factor, count in countOfPrimeFactors(factorial_of_n).items():
    ans *= count + 1

print(ans % mod)





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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
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<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
signed main(){
    gearup;
    string s;cin>>s;
    map<char,int> mp;
    rep(i,s.size())mp[s[i]]++;
    for(auto m:mp){
        if(m.second > 1){
            out("no");
            return 0;
        }
    }
    out("yes");
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define FAST ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define f(i,n) for(int i=0 ; i<n ; i++)
#define fll(i,n) for(ll i=0 ; i<n ; i++)
#define f1(a,b,i) for(ll i=a ; i<b ; i++)
#define fd(i,n) for(int i=n-1 ; i>=0 ; i--)
#define ll long long
#define ld long double
#define vi vector<int>
#define  pii pair<int,int>
#define vl vector<ll>
#define INF 1e9
#define epsn 1e-12

using namespace std ;
int M=1e9+7 ;
ll pow(ll a, ll b){
    if(b==0)return 1 ;
    else if(b%2)return a*pow(a,b-1) ;
    else return pow(a,b/2)*pow(a,b/2) ;
}

int main(){
    ll n,x,ans=1e9,temp,pos,M=0 ;
    cin>>n ;
    vector<ll>v(n),vis(n,0);
    fll(i,n){
        cin>>v[i] ;
        M=max(M,v[i]) ;
    }
    vector<ll>dp(M+1,0) ;
    
    sort(v.begin(),v.end()) ;
    fll(i,n){
        dp[v[i]]++ ;
        if(dp[v[i]]<2)for(ll j=2*v[i] ; j<=M ; j+=v[i])dp[j]++ ;
    }
    
    ll ctr=0 ;
    fll(i,n){
//cout<<dp[v[i]]<<" ";
        if(dp[v[i]]==1)ctr++ ;
    }
    cout<<ctr<<"\n" ;
    return 0 ;
}


Measured memory_bytes: 13588
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String s1 = s.substring(0, 4);
		String s2 = s.substring(4, 12);
		System.out.println(s1 + " " + s2);
	}

}


Measured memory_bytes: 9684
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main(){
	IOS;
	int n;
	cin >> n;
	int a[n], b[n];
	for(int i = 0; i < n; i++)
		cin >> a[i] >> b[i];

	sort(a, a+n);
	sort(b, b+n);
	if( n&1 ){
		int md = n/2;
		cout << b[md] - a[md]+1 << endl;
	}else{
		int m1 = n/2-1, m2 = n/2;
		cout << (b[m1]+b[m2])-(a[m1]+a[m2]) + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 6784
N = int(input())
p = list(map(int, input().split()))
count = 0
ans = []
for i in range(N):
    if p[i] == i+1:
        if i < N-1 and p[i+1] != i+1:
            p[i], p[i+1] = p[i+1], p[i]
            count += 1
        elif i > 0 and p[i-1] != i:
            p[i-1], p[i] = p[i], p[i-1]
            count += 1
print(count)
            


Measured memory_bytes: 20640
n = gets.to_i
a = Array.new(n)
cnt = Array.new(n,0)
answ = Array.new(n)
sub = Array.new(n)

a = gets.chomp.split(' ').map(&:to_i)
n.times do |i|
  cnt[a[i]-1] += 1
end

n.times do |i|
  answ[i] = cnt[i]*(cnt[i]-1)/2;
  sub[i] = (cnt[i]-1)*(cnt[i]-2)/2;
end

k = answ.inject(0, :+)
n.times do |i|
  puts(k - answ[a[i]-1] + sub[a[i]-1])
end

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

int main() {
  string str;
  int index = 0;
  int tmpi;
  bool chk = true;
  cin >> str;
  
  vector<char> vec(7);
  vec.at(0) ='k';
  vec.at(1) ='e';
  vec.at(2) ='y';
  vec.at(3) ='e';
  vec.at(4) ='n';
  vec.at(5) ='c';
  vec.at(6) ='e';

  for(int i = 0; i < str.size(); i++){
    index = 0;
    tmpi = i;
    chk = true;
    for(int j = index; j < 7; j++){
      if(vec.at(j) == str.at(tmpi)){
        tmpi++;
        index = j;
      }else{
        chk = false;
        index = j;
        break;
      }
    }
    
    if(index == 6){
      cout << "YES";
      return 0;
    }
    
    string tmpStr = str.substr(tmpi, str.size() - tmpi);
    string chkStr = "";
    for(int j = index; j < 7; j++){
      chkStr += vec.at(j);
    }
    
    if(tmpStr.find(chkStr) == string::npos){
    }else{
      if(tmpStr.find(chkStr) + chkStr.size() + index == str.size()){
        cout << "YES";
        return 0;
      }else{
        cout << "NO";  
        return 0;
      }
    }
    cout << "NO";  
    return 0;
  }
     
}


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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int a,b,c,d;
void test(){
  cin >> a >> b >> c >> d;
  int k = (a + b) / (min(a,b) + 1);
  if(k == 1){
    string res = (b>a) ^ (c&1) ? "A" : "B";
    R(i,d - c){
      res += 'A' + 'B' - res.back();
    }
    cout << res << "\n";
    return;
  }
  int bloki = max((a + b) / (k + 1) - 1, 0ll);
  int epre = (a - bloki) / (k-1);
  int epost = (b - bloki) / (k-1);
  for(int i = epre - 5; i < epre + 5; i++){
    for(int j = epost - 5; j < epost + 5; j++){
      if(i >= 0 && j >= 0){
        int y = a - i * k - j;
        int z = b - i - j * k;
        if(((y >= 1 && y <= k) || (y == 0 && i == 0)) &&
           ((z >= 1 && z <= k) || (z == 0 && j == 0))){
          string res;
          for(int ii = c - 1; ii < d; ii++){
            int ak = ii;
            if(ak < i * (k+1)){
              if(ak % (k+1) == k){
                res += 'B';
              }else{
                res += 'A';
              }
            }else{
              ak -= i * (k+1);
              if(ak < y){
                res += 'A';
              }else{
                ak -= y;
                if(ak < z){
                  res += 'B';
                }else{
                  ak -= z;
                  if(ak % (k+1) == 0){
                    res += 'A';
                  }else{
                    res += 'B';
                  }
                }
              }
            }
          }
          cout << res << "\n";
          return;
        }
      }
    }
  }
  debug(a,b,c,d,bloki,epre,epost,k);
  assert(0);
}


int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  int q;cin >> q;
  while(q--)test();
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
long long int A[10],B[10],ans;
int main() {
for (int i = 0; i < 5; ++i){
    cin >> A[i];
    if(A[i] % 10 == 0) B[i] = A[i] % 10;
    else B[i] = 10 - A[i] % 10;
    ans += A[i];
}
sort(B, B+5);
for (int i = 0; i < 4; ++i){
    ans += B[i];
}
cout << ans << endl;
return 0;

}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      String[] lines = in.readLine().split(" ");
      int[] arr = new int[lines.length];
      int k=0;
      for (String s : lines) {
        arr[k++] = Integer.parseInt(s); 
      }
      Arrays.sort(arr);
      int step=0;
      if(arr[2] - arr[1] > 4) {
        for(; arr[1]+2 < arr[2]; step++) {
          arr[1] += 2;
        }
      }
      if(arr[1] - arr[0] > 4) {
        for(; arr[0]+2 < arr[1]; step++) {
          arr[0] += 2;
        }
      }

      Tuple3 t = new Tuple3(arr[0], arr[1], arr[2]);
      t.step = step;

      bfs(t);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  private void bfs(Tuple3 t) {
    Deque<Tuple3> que = new ArrayDeque<>();

    que.offer(t);

    Tuple3 cur;
    while(!que.isEmpty()) {
      cur = que.poll();

      if(cur.isEq()) {
        System.out.println(cur.step);
        return;
      }

      que.offer(new Tuple3(cur.e[0]+2, cur.e[1], cur.e[2]));
      que.peekLast().step = cur.step + 1;
      que.offer(new Tuple3(cur.e[0], cur.e[1]+2, cur.e[2]));
      que.peekLast().step = cur.step + 1;
      que.offer(new Tuple3(cur.e[0], cur.e[1], cur.e[2]+2));
      que.peekLast().step = cur.step + 1;

      que.offer(new Tuple3(cur.e[0]+1, cur.e[1]+1, cur.e[2]));
      que.peekLast().step = cur.step + 1;
      que.offer(new Tuple3(cur.e[0], cur.e[1]+1, cur.e[2]+1));
      que.peekLast().step = cur.step + 1;
      que.offer(new Tuple3(cur.e[0]+1, cur.e[1], cur.e[2]+1));
      que.peekLast().step = cur.step + 1;
      
    }
  }

  class Tuple3 {
    int[] e;
    int state;
    int step;

    public Tuple3(int a, int b, int c) {
      e = new int[3];
      e[0] = a;
      e[1] = b;
      e[2] = c;
      state = (a*10000) + (b*100) + c;
      step = 0;
    }

    @Override
    public boolean equals(Object obj) {
      if(obj == this) return true;
      if(obj == null) return false;
      if(!(obj instanceof Tuple3)) return false;

      Tuple3 ref = (Tuple3) obj;

      return this.state == ref.state ? true : false;
    }

    public boolean isEq() {
      return (e[0] == e[1]) && (e[1] == e[2]);
    }
  }
}

Measured memory_bytes: 23124
#!/usr/bin/env python3
#ABC138 E

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
t = input()
n = len(s)
m = len(t)
f = [False]*26
f2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(n):
    f[alpha.index(s[i])] = True
for i in range(m):
    f2[alpha.index(t[i])] = True
for i in range(26):
    if not f[i] and f2[i]:
        print(-1)
        quit()
ans = 0
inde = s.index(t[0])
ans += inde+1
for i in range(1,m):
    s = s[inde+1:] + s[:inde+1]
    inde = s.index(t[i])
    ans += inde+1
print(ans)


Measured memory_bytes: 3976
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int a,b,c;
    cin >> a >> b >> c;
    if((a*a+b*b==c*c)||(b*b+c*c==a*a)||(c*c+a*a==b*b))
      cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

Measured memory_bytes: 3020
number = str(input())[::-1]
remainderDictionary = {0: 1}

digitDictionary = {'0':0, '1':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9}

sum = 0
x = 1
for i in number:
  x = (x * 10) % 2019
  sum = (sum + digitDictionary[i] * x) % 2019 
  remainderValue = remainderDictionary.get(sum,0) + 1
  remainderDictionary[sum] = remainderValue
     
ans = 0
for i in remainderDictionary:
  value = remainderDictionary[i]
  ans += value * (value - 1) // 2 # N C 2
print(ans)

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

int main(){
    int n;long k;cin>>n>>k;
    vector<long> a(n+1);
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }

    vector<bool>dp(k+1,false);
    for(int i=0;i<=k;i++){
        for(int j=1;j<=n;j++){
            if(i>=a[j] && !dp[i-a[j]]){
                dp[i]=true;
            }
        }
    }
    cout<<(dp[k]?"First":"Second");

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> D;
typedef map<ll,D> M;
typedef priority_queue<P,vector<P>,greater<P> > Q;
int main(){
  ll n,l,s,x,e;
  while(cin>>n,n){
    char c;
    M m;
    Q em;
    e=0;
    while(n--){
      D d;
      P p;
      cin >> c;
      if(c=='W'){
	cin >> l >> s;
	while(!em.empty()&&s>0){
	  p=em.top();em.pop();
	  x=p.second-p.first+1;
	  if(x<=s){
	    s-=x;
	    m[l].push_back(p);
	  }else{
	    m[l].push_back(P(p.first,p.first+s-1));
	    p.first+=s;
	    em.push(p);
	    s=0;
	  }
	}
	if(s>0){
	  p.first=e;p.second=p.first+s-1;
	  m[l].push_back(p);
	  e=p.second+1;
	}
      }
      if(c=='D'){
	cin>>l;
	for(int i=m[l].size()-1;i>=0;i--){
	  em.push(m[l][i]);
	}
	m[l].clear();
      }
      if(c=='R'){
	cin >> x;
	bool f=true;
	for(M::iterator it=m.begin();it!=m.end();++it){
	  l=it->first;d=it->second;
	  for(int i=0;i<d.size();i++){
	    p=d[i];
	    if(p.first<=x&&x<=p.second){
	      cout << l << endl;
	      f=false;
	      break;
	    }
	  }
	  if(!f) break;
	}
	if(f) cout << -1 << endl;
      }
    }
    cout << endl;
  }
  return 0;
}

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

int main(){
	int N,M,C;
	cin>>N>>M>>C;
	
	int B[M]={};
	for(int i=0;i<M;i++)	
		cin>>B[i];
	
	int A[N][M];
	for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
			cin>>A[i][j];
		}
	}
	
	int k=0;
	int ans=0;
	for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
			k+=A[i][j]*B[j];
		}
		if(k+C>0)
			ans++;
		k=0;
	}
	cout<<ans<<endl;
	return 0;
	
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	io_init;
	int N, T;
	cin >> N >> T;
	vector<pair<int, int>> M(N);
	for (int i = 0; i < N; i++) {
		cin >> M[i].first >> M[i].second;
	}
	sort(M.begin(), M.end());

	vector<vector<int>> dp(N + 1, vector<int>(T + 1, 0)), dp2(N + 1, vector<int>(T + 1, 0));
	for (int i = 0; i < N; i++)for (int j = 0; j < T; j++) {
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
		if (j + M[i].first >= T)continue;
		dp[i + 1][j + M[i].first] = max(dp[i + 1][j + M[i].first], dp[i][j] + M[i].second);
	}
	for (int i = N; i > 0; i--)for (int j = 0; j < T; j++) {
		dp2[i - 1][j] = max(dp2[i - 1][j], dp2[i][j]);
		if (j + M[i - 1].first >= T)continue;
		dp2[i - 1][j + M[i - 1].first] = max(dp2[i - 1][j + M[i - 1].first], dp2[i][j] + M[i - 1].second);
	}
	int ans = max(M[0].second + dp2[1][T - 1], M[N - 1].second + dp[N - 1][T - 1]);
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < T; j++) {
			int tmp = M[i].second;
			tmp += dp[i - 1][j] + dp2[i + 1][T - j - 1];
			ans = max(ans, tmp);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 70912
use strict;
use warnings;

chomp(my $abc = <>);
my($a, $b, $c) = split / /, $abc;

my $count = 0;

if ($a == $b){$count++;}
if ($b == $c){$count++;}
if ($a == $c){$count++;}

if ($count == 1){
  print "Yes\n";
} else {
  print "No\n";
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<algorithm>
#define m(a , b) memset(a , b , sizeof(a))
#define lowbit(x) (x & (-x))
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int maxn = 3e5 + 10;
const int inf = 1 << 30;
const int mod = 1e9 + 7;
priority_queue <LL , vector<LL> , less<LL> >q;
priority_queue <LL , vector<LL> , greater<LL> >p;
LL ma[maxn],ans;
LL num[maxn],mi[maxn];
int main(){
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= 3 * n ; i ++ )
		scanf("%lld", &num[i]);
	LL sum = 0;
	for(int i = 1; i <= 3 * n ; i ++){
		p.push(num[i]);
		sum += num[i];
		if(p.size() == n + 1){
			sum -= p.top();
			p.pop();
		}
		ma[i] = sum;
	}
	sum = 0;
	for(int i = 3 * n ; i > 0 ; i --){
		q.push(num[i]);
		sum += num[i];
		while(q.size() > n){
			sum -= q.top();
			q.pop();
		}
		mi[i] = sum;
	}
	ans = -1e16;
	for(int i = n; i <= 2 * n; i ++){
		//	printf("%lld %lld\n",ma[i],mi[i + 1]);
			ans = max(ans, ma[i] - mi[i + 1]);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 8948
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int result = 0;
		int[] d = new int[6];
		int[] counts = new int[] { 1, 1, 10, 100, 1000, 100000 };
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j < 6; j++) {
				d[j] = i / (int) (Math.pow(10, j)) % 10;
			}
			if (d[0] == 0) {
				continue;
			}
			int dn = String.valueOf(i).length();
			if (d[dn - 1] == d[0]) {
				for (int j = 0; j < dn - 1; j++) {
					result += 2 * counts[j];
				}
				for (int j = 1; j < dn - 1; j++) {
					result += 2 * d[j] * Math.pow(10, j - 1);
				}
				result++;
			} else if (d[dn - 1] > d[0]) {
				for (int j = 1; j < dn; j++) {
					result += 2 * counts[j];
				}
			} else {
				for (int j = 1; j < dn - 1; j++) {
					result += 2 * counts[j];
				}
			}
		}
		sc.close();

		System.out.println(result);
	}
}


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

class Main{
    boolean ans = false;
    public void check(Map<Integer, List<Integer>> maps, int now, int goal, int count){
        if(count > 2)
            ans = ans || false;
        else if(now == goal - 1) // goal
            ans = ans || true;
        else{
            if(maps.containsKey(now)){
                for(int s: maps.get(now)){
                    check(maps, s, goal, count + 1);
                }
            }
        }
    }

    public List<Integer> getAddElement(List<Integer> list, int num){
        list.add(num);
        return list;
    }

    public void run(){
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
            String[] nm = br.readLine().split(" ");
            int n = Integer.parseInt(nm[0]);
            int m = Integer.parseInt(nm[1]);
            Map<Integer, List<Integer>> maps = new HashMap<>();
            br.lines().map(j -> j.split(" "))
                .forEach(j -> maps.put(Integer.parseInt(j[0]) - 1, getAddElement(maps.getOrDefault(Integer.parseInt(j[0]) - 1, new ArrayList<Integer>()), Integer.parseInt(j[1]) - 1) ));
            check(maps, 0, n, 0);

            if(ans)
                System.out.println("POSSIBLE");
            else
                System.out.println("IMPOSSIBLE");
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    public static void main(String... args){
        new Main().run();
    }
}


Measured memory_bytes: 80512
#include<stdio.h>
#include<string.h>

#define M 1046527
#define NIL (-1)
#define L 14
char H[M][L];

int getChar(char ch){
    if(ch=='A') return 1;
    else if(ch =='C') return 2;
    else if(ch == 'G') return 3;
    else if(ch == 'T') return 4;
    else return 0;
}

long long getKey(char str[]){
    long long sum =0, p=1, i;
    for(i=0;i<strlen(str); i++){
        sum += p*(getChar(str[i]));
        p*=5;
    }
    return sum;
}

int h1(int key){return key%M;}
int h2(int key){return 1+(key%(M-1));}

int find(char str[]){
    long long key, i, h;
    key =getKey(str);
    for(i=0;;i++){
        h=(h1(key) + i*h2(key))%M;
        if(strcmp(H[h], str)==0) return 1;
        else if(strlen(H[h]) == 0) return 0;
    }
    return 0;
}

int insert(char str[]){
    long long key, i, h;
    key = getKey(str);
    for(i=0;;i++){
        h=(h1(key)+i*h2(key))%M;
        if(strcmp(H[h], str)==0) return 1;
        else if(strlen(H[h])==0){
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}

int main()
{
    int i, n;
    char str[L], com[9];
    for(i=0;i<M;i++) H[i][0] ='\0';
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%s %s", com, str);

        if(com[0]=='i'){
            insert(str);
        }else{
            if(find(str)){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }

    return 0;
}



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

using namespace std;
vector<long long> factors;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
int n;
struct node
{
	pll cc = {0, 0};
	vector<int> childs;
};
node tree[110000];

void dfs(int nd, int par)
{
	tree[nd].cc.first = 1;
	tree[nd].cc.second = 1;
	for (int i = 0; i < tree[nd].childs.size(); ++i)
	{
		if (par != tree[nd].childs[i])
		{
			dfs(tree[nd].childs[i], nd);
		}
	}
	if(tree[nd].childs.size() != 1 || par==-1)
	{
		for (int i = 0; i < tree[nd].childs.size(); ++i)
		{
			if (par != tree[nd].childs[i])
			{
				tree[nd].cc.first *= (tree[tree[nd].childs[i]].cc.first + tree[tree[nd].childs[i]].cc.second);
				tree[nd].cc.second *= tree[tree[nd].childs[i]].cc.first;
				tree[nd].cc.first%=MOD;
				tree[nd].cc.second%=MOD;
			}
		}
	}
}

int main()
{
	IOS
	cin >> n;
	for (int i = 0; i < n - 1; ++i)
	{
		int x, y;
		cin >> x >> y;
		tree[x].childs.push_back(y);
		tree[y].childs.push_back(x);
	}
	dfs(1, -1);

	cout << (tree[1].cc.first + tree[1].cc.second)%MOD;
	return 0;
}


Measured memory_bytes: 13312
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<tuple>
#include<bitset>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define req(i,n) for(ll i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
typedef long long int ll;
typedef long double ld;
const ll INF =  1e18;
int k, m, t;ll  sum = 0, ans = 0; string s;
const ld PI = acos(-1);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int main(void) {
    int n; cin >> n;
    vector<ll> a(n); ll sum = 1;
    rep(i, n) {
        cin >> a[i];
        if (a[i] == 0) sum = 0;
    }
    rep(i, n) {
        ld ch = log10(sum) + log10(a[i]);
        if (ch >= 18.0 && sum * a[i] != 1000000000000000000) {
            cout << -1 << endl;
            return 0;
        }
        sum *= a[i];
    }cout << sum <<endl;
}

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

int main(){
    int ans=0;
    int xi;
    int n,m;
    cin >> n;
    vector < pair<int,int> > koma;

    for (int i = 1; i <= n; i++){
        cin >>xi;
        koma.push_back(make_pair(i,xi));
    }
    cin >>m;

    for (int i = 0; i < m; i++){
        cin >>xi;xi--;

        if(xi==n-1){
            if(!(koma[xi].second==2019))koma[xi].second++;
        }else{
            if(!(koma[xi].second + 1 == koma[xi+1].second))koma[xi].second++;
        }
    }
    
    for (int i = 0; i < n; i++){
        cout <<koma[i].second<< '\n';
    }
    

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}



Measured memory_bytes: 3100
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    let mut n = io.read::<i64>();

    let mut ans = Vec::new();
    while n > 0 {
        n -= 1;
        ans.push(n % 26);
        n /= 26;
    }
    ans.reverse();
    for &c in ans.iter() {
        io.write((c as u8 + b'a') as char);
    }
}

static MX: usize = 1010101;
static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


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

using namespace std;

const int maxn = 105;

int b[maxn];

int main() {
	int n;
	ios::sync_with_stdio(0);
	cin >> n;
	int ans = 0;
	for(int i = 0 ; i < n - 1; i++) {
		cin >> b[i];
	}
	ans += b[0];
	for(int i = 1 ; i < n - 1; i++) {
		ans += min(b[i] , b[i - 1]);
	}
	ans += b[n - 2];
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
plist = [0 for _ in range(n)]
acornot = [0]*n
ans = 0
for i in range(m):
    p,s = input().split()
    p = int(p)
    p -= 1
    if s == "AC" and acornot[p] != 1:
        
        ans += 1
        acornot[p] = 1
    elif s == "AC" and acornot[p] ==1:
        continue
    elif s == "WA" and acornot[p] == 1:
        continue
    else:
        plist[p]+=1
print(ans)
ansp = 0
for i in range(n):
    if acornot[i] == 0:
        continue
    else:
        ansp+=plist[i]
print(ansp)
    

Measured memory_bytes: 4772
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
	char ch[4];
	cin >> ch;
	int a, b;
	for (int i = 0; i < 4; i++) {
		if (ch[i] == 'A') a++;
		if (ch[i] == 'B') b++;
	}
	if (a && b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d", $n);

const MOD = 1000000007;

$dp = array_fill(
    0,
    101,
    array_fill(0, 4, array_fill(0, 4, array_fill(0, 4, 0)))
);
$dp[0][3][3][3] = 1;

for ($len = 0; $len < $n; ++$len) {
    for ($i = 0; $i < 4; ++$i) {
        for ($j = 0; $j < 4; ++$j) {
            for ($k = 0; $k < 4; ++$k) {

                for ($new = 0; $new < 4; ++$new) {
                    if ($j === 0 && $k === 1 && $new === 2) continue;
                    if ($j === 0 && $k === 2 && $new === 1) continue;
                    if ($j === 1 && $k === 0 && $new === 2) continue;

                    if ($i === 0 && $k === 1 && $new === 2) continue;
                    if ($i === 0 && $j === 1 && $new === 2) continue;

                    $dp[$len + 1][$j][$k][$new] += $dp[$len][$i][$j][$k];
                    $dp[$len + 1][$j][$k][$new] %= MOD;
                }
            }
        }
    }
}

$ans = 0;
for ($i = 0; $i < 4; ++$i) {
    for ($j = 0; $j < 4; ++$j) {
        for ($k = 0; $k < 4; ++$k) {
            $ans += $dp[$n][$i][$j][$k];
            $ans %= MOD;
        }
    }
}

echo $ans;


Measured memory_bytes: 4604
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
#define PI 3.14159265358979323846264338327950288
 
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;
 
//const long long INF = 1e18 ;
//const long long NINF = -1e17 ;

int main(){
    FAST_IO ;
    bigint N ; cin >> N ;
    if( N % 2 != 0 ){
        cout << "0" << endl ;
        return 0 ;
    }
    bigint ans = 0 ;
    ans += N / 10 ;
    N /= 10 ;
    while( N ){
        ans = ans + (N / 5) ;
        N /= 5 ;
    }
    cout << ans << endl ;
    return 0 ;
}
 

Measured memory_bytes: 3572
N, C, K = list(map(int, input().split()))

passengers = sorted([int(input()) for i in range(N)])
res = 0
bus_time = passengers[0]
bus_count = C
for p in passengers:
    if bus_count == 0 or p - bus_time > K:
        res += 1
        bus_time = p
        bus_count = C - 1
    else:
        bus_count -= 1
if bus_count != C:
    res += 1
print(res)


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

typedef pair<int, int> P;
typedef stack<int> S;

bool pairCompare(const P& firstElem, const P& secomdElem)
{
	return firstElem.second < secomdElem.second;
}

int main(void)
{
	vector<P> v;
	for (int i = 0; i < 100; i++) v.push_back(P(i, 0));
	int num;
	while (cin >> num && num) v[num].second++;
	stable_sort(v.begin(), v.end(), pairCompare);
	int i = v.size() - 1;
	S s;
	while (v[v.size() - 1].second == v[i].second) {s.push(v[i].first); i--;}
	while (s.size()) {cout << s.top() << endl; s.pop();}
	
	return 0;
}

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

int main () {
  vector<string> vec{"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string in;
  cin >> in;
  
  for( int i = 0; i < 7; i++ ){
    if ( in == vec.at(i) ){
      cout  << 7 - i << endl;
    }
  }
}
      
  

Measured memory_bytes: 256