akhauriyash/Code-Regression huggingface dataset:
module Main where

import Data.Functor
import Data.List

main :: IO ()
main = do
  { [ss] <- getInts
  ; let (mm,s) = divMod ss 60
  ; let (h,m) = divMod mm 60
  ; putStrLn (intercalate ":" (map show [h, m, s]))
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

Measured memory_bytes: 3612
#include <iostream>

int main() {
  int W, H, x, y, r;
  std::cin >> W >> H >> x >> y >> r;
  if (x < r || y < r || W < (x + r) || H < (y + r)) {
    std::cout << "No" << std::endl;
  } else {
    std::cout << "Yes" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 3124
///Thu Thaoo

#include <bits/stdc++.h>

#define ll long long
#define int ll

using namespace std;


int n;
float x;

main()
{
    cin>>n;
    x = n / 1.08;
    int x2 = (int)x;
    if ((int)(x2 * 1.08) == n) cout<<x2;
    else if ((int)((x2+1) * 1.08) == n) cout<<x2+1;
    else cout<<":(";
}


Measured memory_bytes: 256
#include<cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
int main(){
  string  a,b;
  cin>>a>>b;
  int al=a.size();
  int bl=b.size();
  if (al>bl) printf("GREATER\n");
  else if (al<bl) printf ("LESS\n");
  else {
    for (int i=0;i<al;i++){
      if (a[i]>b[i]){
	printf("GREATER\n");
	break;}
      else if  (a[i]<b[i]){
	printf ("LESS\n");
	break;}
      if (i==al-1 and a[al-1]==b[al-1]) printf ("EQUAL\n");
    }
    
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2010,p=1e9+7;
int mpow(int a,int n){
    int ret=1;
    while(n){
        if(n&1)ret=1ll*ret*a%p;
        a=1ll*a*a%p;
        n/=2;
	}
	return ret;
}
int fac[N*N],inv[N*N];
int C(int n,int m){
    return 1ll*fac[n]*inv[m]%p*inv[n-m]%p;
}
int n,m;
int f[2010][2010];
int main(){
    fac[0]=1;
    for(int i=1;i<N*N;++i)fac[i]=1ll*fac[i-1]*i%p;
    inv[N*N-1]=mpow(fac[N*N-1],p-2);
    for(int i=N*N-2;i;--i)inv[i]=1ll*inv[i+1]*(i+1)%p;
    inv[0]=1;
    cin>>n>>m;
    if(m==1){
        cout<<1<<endl;
        return 0;
	}
    f[0][0]=1;
    for(int i=1;i<=n;++i){
    	for(int j=n;j>=0;--j){
    	    if(j<=i&&j){
    	        f[i][j]=(f[i][j]+1ll*f[i-1][j-1]*C(m*i-j-1,m-2)%p)%p;
			}
			f[i][j]+=f[i][j+1];
			f[i][j]%=p;
		}
	}
	f[n][0]=1ll*f[n][0]*fac[n]%p;
	cout<<f[n][0];
}

Measured memory_bytes: 47616
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    ll N,A,B;
    cin >> N >> A >> B;
    vector<ll> X(N);
    for(int i = 0;i < N;i++)cin >> X[i];
    ll sum = 0;
    ll s = X[0];
    sort(X.begin(),X.end());
    for(int i = 1;i < N;i++){
        sum += min((X[i] - X[i-1])*A,B);
    }
    sum += min({(s - X[0])*A, (X[N-1] - s)*A, B});
    cout << sum << endl;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>

using namespace std;


int main(){
	string s;
	while(getline(cin,s)){
		for (int i = 0; i < (int)s.size(); i++)
		{
			if('a' <= s[i] && s[i] <= 'z')
				s[i] += ('A' - 'a');
		}
		cout << s<< endl;
	}
	return 0;
}

Measured memory_bytes: 0
import functools

N,M = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*N

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)

def multiple(a, b):
    return a*b // euclid(a, b)

def lcm(nums):
        return functools.reduce(multiple, nums)

def count_two(n):
    c = 0
    while n%2 ==0:
        c += 1
        n //= 2
    return c

l = [0]*N
for i in range(N):
    l[i] = count_two(a[i])

if len(set(l)) != 1:
    print(0)
else:
    p_2 = l[0] #2で何回割れるか
    for i in range(N):
        b[i] = a[i] // (2**p_2)
    
    X = lcm(b)*(2**(p_2-1))
    nax = M // X

    print((nax+1)//2)

Measured memory_bytes: 63984
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int a,b,c;
  cin>>a>>b>>c;
  int cnt=0;
  if(a%2==1)cnt++;
  if(b%2==1)cnt++;
  if(c%2==1)cnt++;
  if(cnt>1) cout<<"Hom"<<endl;
  else cout<<"Tem"<<endl;
  return 0;
}



Measured memory_bytes: 3232
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<n;i++)
#define rf(i,n) for(int i=n-1;i>=0;i--)
#define PI 3.1415926535897932384626433832795
#define fi first
#define se second
#define mp(x,y) make_pair
#define BIN(n,x) bitset<n>(x)  
using namespace std;

vector<vector<int>> adj(200001);
vector<bool> visited(200001);
vector<bool> vis1(200001);
vector<int> par(200001);
vector<int> level(200001);

int connected =0 ;
void dfs(int s){
    visited[s]=1;
    f(i,adj[s].size()){
        if(!visited[adj[s][i]]){
            dfs(adj[s][i]);
        }
    }
}
void bfs(int s){
    queue<int> Q;
    
    Q.push(s);
    vis1[s]=1;
    level[s]=0;
    while(!Q.empty()){
        int v=Q.front();
        f(i,adj[v].size()){
            if(!vis1[adj[v][i]]){
                Q.push(adj[v][i]);
                vis1[adj[v][i]]=1;
                level[adj[v][i]]=level[v]+1;
                par[adj[v][i]]=v;
            }
        }
        Q.pop();
    }
}

int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    int x,y;
    f(i,m){
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }  
    bfs(1); 
    f1(i,n+1){
        if(!visited[i]){
            dfs(i);
            connected++;
        }
    }
    if(n==1){
        cout<<"Yes"<<endl;
        return 0;
    }
    if(connected==1){
        cout<<"Yes"<<endl;
        for(int i=2;i<=n;i++){
            cout<<par[i]<<endl;
        }
    }
    else{
        cout<<"No"<<endl;
    }

    return 0;
}



Measured memory_bytes: 17440
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;


#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod
#define MUL(a,b) a=(a*b)%mod

ll dp[3001][3001][4];
ll m[3001][3001];
int main(){
    ll R,C,K; cin>>R>>C>>K;
    rep(i,K){
        ll r,c,v; cin>>r>>c>>v;
        r--; c--;
        m[r][c]=v;
    }
    
    rep(i,R) rep(j,C) {
        //cout<<"Arrived"<<i<<' '<<j<<endl;
        ll X=0;
        if(i){
            X=max(dp[i-1][j][0],dp[i-1][j][1]);
            X=max(dp[i-1][j][2],X);
            X=max(dp[i-1][j][3],X);
        }
        dp[i][j][0]=X;
        if(j){
            dp[i][j][0]=max(dp[i][j][0],dp[i][j-1][0]);
            dp[i][j][1]=max(dp[i][j][0]+m[i][j],dp[i][j-1][1]);
            dp[i][j][2]=max(dp[i][j-1][1]+m[i][j],dp[i][j-1][2]);
            dp[i][j][3]=max(dp[i][j-1][2]+m[i][j],dp[i][j-1][3]);
        }
        else dp[i][j][1]=dp[i][j][0]+m[i][j];
    }
    ll ans=max(dp[R-1][C-1][3],dp[R-1][C-1][2]);
    ans=max(dp[R-1][C-1][1],ans);
    ans=max(dp[R-1][C-1][0],ans);
    cout<<ans<<endl;

}

Measured memory_bytes: 355284
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AEoui
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskBAtCoder solver = new TaskBAtCoder();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskBAtCoder {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();

            int ans = 0;
            for (int i = 1; i <= n; i += 2) {
                int cnt = divisors(i);
                if (cnt == 8) {
                    ++ans;
                    //out.println(i + " " + cnt);
                }
            }

            out.println(ans);
        }

        private int divisors(int n) {
            int cnt = 0;
            for (int i = 1; i <= n; ++i) {
                if (n % i == 0)
                    ++cnt;
            }

            return cnt;
        }

    }
}



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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template<class T>
struct UnionFind {
  vector<T> parent, siz;

  UnionFind(int n) : parent(n), siz(n) {
    for (int i = 0; i < n; ++i) {
      parent[i] = i;
      siz[i] = 1;
    }
  }

  T root(T x) {
    if (parent[x] == x) return x;
    return parent[x] = root(parent[x]);
  }

  bool unite(T x, T y) {
    x = root(x);
    y = root(y);

    if (x == y) return false;

    if (siz[x] < siz[y]) swap(x, y);
    parent[y] = x;
    siz[x] += siz[y];

    return true;
  }

  bool same(T x, T y) {
    return root(x) == root(y);
  }

  T size(T x) {
    return siz[root(x)];
  }
};


signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int n, m, k; cin >> n >> m >> k;
  vector<vi> fri(n), brock(n);
  UnionFind<int> uf(n);

  rep(i, m) {
    int a, b; cin >> a >> b;
    fri[a-1].eb(b-1);
    fri[b-1].eb(a-1);
    uf.unite(a-1, b-1);
  }

  rep(i, k) {
    int a, b; cin >> a >> b;
    brock[a-1].eb(b-1);
    brock[b-1].eb(a-1);
  }

  rep(i, n) {
    if (i) cout << " ";

    int ans = uf.size(i) - si(fri[i]);
    rep(j, si(brock[i])) if (uf.same(i, brock[i][j])) --ans;

    cout << ans - 1;
  }
  cout << endl;
}


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

int main() {
  int N;
  long sum, part;
  string s[100001];
  cin >> N;
  for(int i=0; i<N; ++i) cin >> s[i];
  for(int i=0; i<N; ++i)
    sort(s[i].begin(), s[i].end());
  sort(s, s+N);
  sum = 0;
  {int i=1;
  while(i<N) {
    if(s[i-1]==s[i]) {
      part = 1;
      ++i;
      for(int j=2; s[i-1]==s[i] && i<N;) {
        part += j;
        ++i, ++j;
      }
      sum += part;
    } else ++i;
  }}
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 7296
import java.util.Scanner;

public class Main {
	private void calc(){
		Scanner scanner = new Scanner(System.in);
		int W =scanner.nextInt();
		int H =scanner.nextInt();
		int x =scanner.nextInt();
		int y =scanner.nextInt();
		int r =scanner.nextInt();
		
		if(r<=x && x<=W-r){
			if(r<=y && y<=H-r){
				System.out.println("Yes");
			}else System.out.println("No");
		}else System.out.println("No");
	}
	
	public static void main(String[] args) {
		Main run =new Main();
		run.calc();

	}
}

Measured memory_bytes: 17308
#include <stdio.h>
int main(void){
 int a,b,c;
 scanf("%d %d",&a,&b);
 c=a+b;
 if(c<a-b){
  c=a-b;
 }
 if(c<a*b){
  c=a*b;
 }
 printf("%d\n",c);
 return 0;
}

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

int main(){
  int n,T,t[200000],ans=0;
  cin>>n>>T;
  for(int i=0;i<n;i++){
    cin>>t[i];
  }
  for(int i=0;i<n-1;i++){
    if(t[i]+T<=t[i+1]){
      ans+=T;
    }else{
      ans+=(t[i+1]-t[i]);
    }
  }
  ans+=T;
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

from decimal import Decimal

A, B, N = input_int()



X = B-1 if N >=B-1 else N

print(int(Decimal(A)*Decimal(X)/Decimal(B)))

Measured memory_bytes: 10008
from functools import reduce

# 入力
N = int(input())
gA, sA, bA = map(int, input().split())
gB, sB, bB = map(int, input().split())

A = (gA, sA, bA)
B = (gB, sB, bB)


# 各貴金属について、買う／売る可能性のある取引所は一意に定まることを用いて
# 全探索により解を求める
def f(n, r):
    R = len(r)
    return (
        n if R == 0 else
        n + (r[-1][1] - r[-1][0]) * (n // r[-1][0]) if R == 1 else
        reduce(
            max,
            (
                n + (r[0][1] - r[0][0]) * x +
                (r[-1][1] - r[-1][0]) * ((n - r[0][0] * x) // r[-1][0])
                for x in range(n // r[0][0] + 1)
            ),
            n
        ) if R == 2 else
        reduce(
            max,
            (
                n + (r[0][1] - r[0][0]) * x + (r[1][1] - r[1][0]) * y +
                (r[-1][1] - r[-1][0]) *
                ((n - r[0][0] * x - r[1][0] * y) // r[-1][0])
                for x in range(n // r[0][0] + 1)
                for y in range((n - r[0][0] * x) // r[1][0] + 1)
            ),
            n
        )
    )


ans = f(
    f(
        N,
        [
            (a, b)
            for a, b in zip(A, B)
            if a < b
        ]
    ),
    [
        (b, a)
        for b, a in zip(B, A)
        if a > b
    ]
)

# 出力
print(ans)


Measured memory_bytes: 41052
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

#include <queue>
#include <tuple>
using T = tuple<int, int>;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> G(n);
    REP(i, 0, m) {
        int a, b;
        cin >> a >> b;
        G[a - 1].push_back(b - 1);
    }

    auto solve = [&](int start) {
        queue<T> q;
        q.emplace(start, -1);
        vector<int> prev(n, -1);
        vector<bool> used(n, false);
        int g = -1;
        while (q.size()) {
            int v, p;
            tie(v, p) = q.front();
            q.pop();
            if (used[v] && v == start) {
                g = p;
                break;
            }
            if (used[v]) continue;
            used[v] = true;
            prev[v] = p;
            for (auto &vv : G[v]) {
                q.emplace(vv, v);
            }
        }
        if (g != -1) {
            vector<int> st;
            while (g != -1) {
                st.push_back(g);
                g = prev[g];
            }
            return st;
        } else {
            return vector<int>();
        }
    };

    vector<int> ans;
    REP(i, 0, n) {
        auto res = solve(i);
        if (res.size() != 0) {
            if (ans.size() == 0 || ans.size() > res.size()) {
                ans = res;
            }
        }
    }

    if (ans.size() == 0) {
        cout << -1 << endl;
    } else {
        cout << ans.size() << endl;
        for (auto v : ans) {
            cout << v + 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        
        int zeroCount = 0;
        int oneCount = 0;
        
        char[] chars = s.toCharArray();
        for (char c : chars) {
            if (c == '1') {
                oneCount++;
            } else {
                zeroCount++;
            }
        }
        int count = (Math.min(oneCount, zeroCount)) * 2;
        
        System.out.println(count);

    }

}

Measured memory_bytes: 26308
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
module Main where

import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
    n <- readLn
    replicateM_ n $ do
        [a,b,c] <- sort . map read . words <$> getLine
        putStrLn $ if c^2 == a^2 + b^2 then "YES" else "NO"

Measured memory_bytes: 4076
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;

int main(void)
{
	string s; cin >> s;
	string ans;
	ans.push_back(s[0]);
	ans += (to_string(s.length() - 2));
	ans.push_back(s[s.length() - 1]);
	
	cout << ans << endl;

	return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	int A;
	map<int, int> vmap;
	cin >> N;
	rep(i, 0, N)
	{
		cin >> A;
		vmap[A]++;
	}

	int ans = 0;
	for (auto p : vmap)
	{
		if (p.second % 2 == 1)ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6528
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
d = set(map(int, input().split()))
for x in range(N, 10 ** 6):
  f = 1
  for y in str(x):
    if int(y) in d:
      f = 0
      break
  if f:
    print(x)
    exit(0)

Measured memory_bytes: 40668
def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    ans = A[0]
    if 0 in A:
        print(0)
        return

    for i in range(1, N):
        ans = ans * A[i]

        if ans > (10 ** 18):
            ans = -1
            break

    print(ans)


resolve()

Measured memory_bytes: 21660
n=int(input())
num=[]
for _ in range(n):
    s=input()
    s=s.replace(" ","")
    #print(s)
    num.append(int(s,2))
    #print(num)
p=[]
for _ in range(n):
    l=[int(x) for x in input().split()]
    p.append(l)
ans=-10**20
for i in range(1,1024):
    tot=0
    ind=0
    for ele in num:
        var=ele&i 
        tot+=p[ind][bin(var).count('1')]
        ind+=1 
    ans=max(ans,tot)
print(ans)
    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll cnt[(1<<20)+5],m,num[25];
int n;
double p[25];
int main(){
	cin >> n >> m;
	for(int i=0;i<n;i++) cin >> num[i];
	for(int i=0;i<n;i++){
		scanf("%lf",&p[i]); p[i]/=100.;
	}
	for(int i=1;i<(1<<n);i++){
		ll N = 1LL; int B = __builtin_popcount(i);
		for(int j=0;j<n;j++){
			if(!((i>>j)&1)) continue;
			if(8000000000000000000LL/N < num[j]/__gcd(N,num[j])) goto fail;
			N = N/__gcd(N,num[j])*num[j];
		}
		if(B%2==1) cnt[i] = m/N;
		else cnt[i] = -1*(m/N); fail:;
	}
	for(int i=0;i<n;i++) for(int j=0;j<(1<<n);j++){
		if(((j>>i)&1)) cnt[j] += cnt[j^(1<<i)];
	}
	double ans = 0.0;
	for(int i=1;i<(1<<n);i++){
		double prob = 1.0;
		for(int j=0;j<n;j++){
			if(((i>>j)&1)) prob *= p[j];
			else prob *= 1.0-p[j];
		}
		ans += prob * (double)cnt[i]; //cout << cnt[i] << " " << i << endl;
	}
	printf("%.12f\n",ans);
}

Measured memory_bytes: 11380
import java.util.*;
import java.util.TreeMap;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int D = sc.nextInt();
    int X = sc.nextInt();
    int cnt = N;
    for (int i = 0; i < N; i++) {
      int j = 1;
      int val = 0;
      int num = sc.nextInt();
      val = j * num + 1;
      while (val <= D) {
        cnt++;
        j++;
        val = j * num + 1;
      }
    }
    System.out.println(cnt + X);
  }
}


Measured memory_bytes: 21972
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }

    static Scanner cin;

    void calc()
    {
        var n = cin.nextInt();
        var a = cin.ArrayLong(n);
        Array.Sort(a);
        var ret = a[a.Length - 1] - a[0];
        Console.WriteLine(ret);
    }


    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}

Measured memory_bytes: 13268
# 整数の数の入力
N = int(input())

# 数列の入力
A = list(map(int, input().split()))

# 数列長が2の場合
# 2つの要素の和を2で割った値を出力
if N == 2:
	print(sum(A) / 2)

# 数列長が2以外の場合
# 数列をソートし小さい値2つを合成対象にする
else:
	while len(A) != 2:
		A.sort()
		A = [(A[0] + A[1]) / 2] + A[2:]
	print(sum(A) / 2)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,-1,sizeof(x))
const int INF = 1000000001;

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(abs(c-a)<=d || (abs(a-b)<=d&&abs(c-b)<=d)) cout << "Yes" <<endl;
  else cout << "No" <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    string T;
    cin >> S;
    cin >> T;
    map<char, char> map_a; 
    map<char, char> map_b; 
    for (int i=0;i<S.size();i++){
        auto itr = map_a.find(S[i]);  
        if( itr != map_a.end() && itr->second!=T[i]) {
            cout << "No" << endl;
            return 0;
        } else {
            map_a[S[i]] = T[i];
        }
        itr = map_b.find(T[i]);   
        if( itr != map_b.end() && itr->second!=S[i]) {
            cout << "No" << endl;
            return 0;
        } else {
            map_b[T[i]] = S[i];
        }
    }
    cout << "Yes" << endl;
}

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

int main() {
  long long A, B, C, K, M;
  cin >> A >> B >> C >> K;
  if (K <= A) {
    M = K;
  }
  else if (K <= A+B) {
    M = A;
  }
  else {
    M = A -(K-(A+B));
  }
  cout << M << endl;
}

Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n, z, w= map(int, input().split())
a = list( map(int, input().split()))

last = a[-1]

if n == 1:
    print(abs(w-last))
    exit()

last2 = a[-2]

print(max(abs(last2-last), abs(last-w)))


Measured memory_bytes: 3188
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=2e5+4;

int main()
{
	ll cur=100,x,days=0;

	lscn(x);

	while(cur<x)
	{
		cur=cur+(cur/100);

		days++;
	}

	lpri(days);

    return 0;
}

Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,l,j;
    string s;
    vector<string>v;
    while(cin>>n>>l)
    {
        for(i=0;i<n;i++)
        {
            cin>>s;
            v.push_back(s);

        }
        sort(v.begin(),v.end());
        for(i=0;i<n;i++)
        {
            cout<<v[i];
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
def solve():
    N = int(input())
    S = input()
    dict = {}
    for cand in range(1000):
        cand_zero = str(cand).zfill(3)
        if cand_zero[0] in S:
            i = S.index(cand_zero[0])
            if cand_zero[1] in S[i+1:]:
                j = len(S[:i+1]) + S[i+1:].index(cand_zero[1])
                if cand_zero[2] in S[j+1:]:
                    k = len(S[:j+1]) + S[j+1:].index(cand_zero[2])
                    if cand_zero not in dict.keys():
                        dict[cand_zero] = 1
    print(len(dict.keys()))



if __name__ == "__main__":
    solve()


Measured memory_bytes: 38768
n,a,b=map(int,input().split())
c=[i+1 for i in range(n)]
d=[i+1 for i in range(n)]
e=0
for i in range(n):
    d[i]=c[i]%10+(c[i]//10)%10+(c[i]//100)%10+(c[i]//1000)%10+(c[i]//10000)%10
    if d[i]>=a and d[i]<=b:
        e+=c[i]
print(e)


Measured memory_bytes: 3700
N = int(input())
A = [int(input()) for i in range(N)]
b = set()
x = 0
n = 1
while True:
    if A[x] == 2:
        print(n)
        break
    x = A[x] - 1
    if x in b:
        print(-1)
        break
    n += 1
    b.add(x)

Measured memory_bytes: 15988
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int f=0, s=0;
  for (int i = 0; i < 3; ++i) {
    int a;
    cin >> a;
    if (a == 5) f++;
    else if (a == 7) s++;
  }
  if (f == 2 && s == 1) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


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

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    int n; cin>>n; int ans=0;
    ans+=min(n,9);
    if(n>=100)ans+=min(n-99,900);
    if(n>=10000)ans+=min(n-9999,90000);
    cout<<ans<<'\n';
}

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

using namespace std;

int main() {
    int k, a, b;

    cin >> k >> a >> b;

    for(int i = a; i <= b; ++i) {
        if(i % k == 0) {
            printf("OK\n");
            return 0;
        }
    }

    printf("NG\n");

    return 0;
}

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

int main(int argc, char** argv) {
    int length;
    
    scanf("%d", &length );
    
    int i;
    int A[100];
    
    for(i=0;i<length;i++)
    {
        scanf("%d", &A[i]);
    }
    
    int key;
    int j;
    
    for(i=0; i<length; i++){
        key = A[i];
        
        for(j=i; j>0 && A[j-1]>key; j--){
            A[j]=A[j-1];
        }
        A[j]=key;
        
        for(int n=0; n<length; n++){
            printf("%d", A[n]);
            if(n!=length-1)
                printf(" ");
            else
                printf("\n");
        }
    } 
    return 0;
}


Measured memory_bytes: 2084
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        String[] sl = s.split("");
        int n = s.length();
        StringBuilder sb = new StringBuilder();
        for (String si: sl) {
            sb.append(si);
        }
        String sr = sb.reverse().toString();
        if (s.equals(sr) && s.substring(0, n/2).equals(sr.substring((n+1)/2, n))) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
	int n,t;
	cin>>n>>t;
	if(n>=t)
	{
		cout<<n-t<<endl;
	}
	else
	{
		cout<<'0'<<endl;
	}
	return 0;
}

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

int main() {

  #define int long long
  int a,b,c,x,y,k;
  
  vector <int> v,w,f;

  cin >> x >> y >> a >> b >> c;
  while (a--) {
    cin >> k;
    v.push_back(k);
  }
  while (b--) {
    cin >> k;
    w.push_back(k);
  }
  while (c--) {
    cin >> k;
    f.push_back(k);
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  sort(w.begin(),w.end());
  reverse(w.begin(),w.end());

  for (int i = 0; i < x; i++) {
    f.push_back(v[i]);
  }
  for (int i = 0; i < y; i++) {
    f.push_back(w[i]);
  }
  sort(f.begin(),f.end());
  reverse(f.begin(),f.end());
  int ans = 0;
  for (int i = 0; i < x+y; i++) {
    ans+=f[i];
  }

  cout << ans << endl;
  
  
}

Measured memory_bytes: 7536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    int i,N; cin>>N;
    int a,b,m=0;
    rep(i,N){
        cin>>a>>b;
        if(a==b){m++;}
        else m=0;
        if(m==3){
            A2;
            return 0;
        }
    }
    A1;
    return 0;
}

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

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

  for(int i = 1; i < 4; i++){
    if(s[i - 1] == s[i]){
      cout << "Bad" << endl;
      return 0;
    }
  }

  cout << "Good" << endl;

  return 0;

}


Measured memory_bytes: 256
import math
N = int(input())
x = []
y = []
for i in range(N):
  tmp = input().split(" ")
  x.append(int(tmp[0]))
  y.append(int(tmp[1]))

d = 0
for i in range(N):
  for j in range(N):
    d += math.sqrt((x[j]-x[i]) ** 2 + (y[j]-y[i]) ** 2)

print(d/N)

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

string a,b;

int main(){
  cin >> a >> b;
  int ans = 0;
  for(int i=0;i<a.size();i++){
    if(a[i] == b[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <deque>
using namespace std;
using Graph = vector<vector<int>>;

long long larger(long long a, long long b){
  if(a >= b){
    return a;
  }else{
    return b;
  }
}

long long smaller(long long a, long long b){
  if(a <= b){
    return a;
  }else{
    return b;
  }
}

int main() {
    //input
    int n; cin >> n;
    long long counter = 0;
    vector<long long> a(n + 2, 0);
    vector<long long> b(n + 2, 0);
    for(int i = 1; i < n + 2; i++) cin >> a[i];
    for(int i = 1; i < n + 1; i++) cin >> b[i];

    //compute
    for(int i = 1; i < n + 2; i++){
        counter += smaller(a[i] + a[i + 1],b[i]);
        a[i + 1] = larger(0 , a[i + 1] - larger(0, b[i] - a[i]));
    } 

    //output
    cout << counter << endl;
}


Measured memory_bytes: 4724
#define f first
#define s second
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    int h, w; cin >> h >> w;
    vector <vector<char> > a(h,vector <char> (w));
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            cin >> a[i][j];
    queue <pair<int,int> > q;
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            if (a[i][j] == '#')
                q.push(make_pair(i,j));
    int dx[4] = {1,-1,0,0}, dy[4] = {0,0,1,-1}, cnt = 0;
    pair <int, int> eoq = q.back();
    while (q.size())
    {
        pair <int,int> p = q.front();
        for (int i = 0; i < 4; i++)
            if (p.f + dx[i] < h && p.f + dx[i] >= 0 && p.s + dy[i] >= 0 && p.s + dy[i] < w && a[p.f+dx[i]][p.s+dy[i]] == '.')
            {
                a[p.f+dx[i]][p.s+dy[i]] = '#';
                q.push(make_pair(p.f+dx[i],p.s+dy[i]));
            }
        q.pop();
        if (p.f == eoq.f && p.s == eoq.s)
        {
            ++cnt;
            eoq = q.back();
        }
    }
    cout << cnt -  1;
    return 0;
}


Measured memory_bytes: 9488
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 1000005
#define mod 1000000007
using namespace std;
inline int in(){
    int x=0;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
int f[MN],sum[(MN<<1)+5],n,res;
int main()
{
	n=in();f[n+1]=1;
	for (int i=(n<<1)+10;i>n;--i) sum[i]=(sum[i+1]+1)%mod;
	for (int i=n;i;--i){
		f[i]=(sum[i+3]+mod-sum[i+n+2])%mod;
		f[i]=(f[i]+f[i+1])%mod;
		if (i!=n) f[i]=(f[i]+(1ll*(n-1)*(n+mod-1)))%mod;
		sum[i]=(sum[i+1]+f[i])%mod; 
	}printf("%d",f[1]);return 0;
}

Measured memory_bytes: 11904
def bubbleSort(a, n):
    flag = 1
    cnt = 0
    i = 0
    while flag:
        flag = 0
        for j in reversed(range(i+1, n)):
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                flag = 1
                cnt += 1
        i += 1
    print(' '.join(map(str, a)))
    print(cnt)

n = int(input())
a = list(map(int, input().split()))

bubbleSort(a, n)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 


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

i64 N, D, A; cin>> N >> D >> A;
VP XH(N); rep(i, 0, N) cin >> XH[i].first >> XH[i].second;
sort(ALL(XH));
VI X, H; 
for(PII p: XH){
    X.push_back(p.first);
    H.push_back(p.second);
}

VI d(N+1, 0); // imosでダメージ記録
i64 ans = 0;
rep(i, 0, N){
    if (H[i] - d[i] > 0){
        int att = ((H[i] - d[i]) + A - 1) / A;//iを倒す攻撃回数
        ans += att;
        d[i] += A * att;
        d[upper_bound(RANGE(X, i, N), X[i] + 2*D) - X.begin()] -= A * att;
    }
    d[i+1] += d[i];
}

cout << ans << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



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

int main(){
    int n;
    cin>>n;
    vector<int> v;
    vector<int> dp(n,0);
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        v.push_back(a);
    }
    for(int i=1;i<n;i++){
        if(i==1){
          dp[i]=abs(v[1]-v[0]);
        }
        else{
            dp[i]=min(abs(v[i]-v[i-1])+dp[i-1],abs(v[i]-v[i-2])+dp[i-2]);
        }
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1276
from collections import deque
n,m = map(int, input().split())
G = [[] for i in range(n)] #Noneでなくて[]でも可
for i in range(m):
    a,b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
oya = [-1]*n
oya[0] = 0
que = deque([0])
while que:
    v = que.popleft()
    for w in G[v]:
        if oya[w] > -1:
            continue
        oya[w] = v
        que.append(w)
if -1 in oya:
    print('No')
else:
    print('Yes')
    for i in range(1, n):
        print(oya[i]+1)


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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)

const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

int power(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

bool check_prime(int n)
{
    if(n<2)
        return false;
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}

int setbits(int n)
{
    int count=0;
    while(n)
    {
        if(n%2==1)
            count++;
        n>>=1;
    }
    return count;
}

int lcm(int a,int b)
{
    return (a*b)/__gcd(a,b);
}

bool vowel(char c)
{
    return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='A' or c=='E' or c=='I' or c=='U' or c=='O');
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int n;
    cin>>n;
    vector <int> a(n),b(n);
    string sa,sb;
    vector <int> v(n);
    loop(i,0,n)
    {
        cin>>a[i];
        v[i]=i+1;
        sa+=to_string(a[i]);
    }
    loop(i,0,n)
    {
        cin>>b[i];
        sb+=to_string(b[i]);
    }
    int x=0,y=0;
    int c=0;
    do
    {
        c++;
        string str;
        for(auto x:v)
            str+=to_string(x);

        if(str==sa)
            x=c;
        if(str==sb)
            y=c;
    }
    while(next_permutation(all(v)));

    cout<<abs(x-y);


    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
import java.util.TreeSet;

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

		Scanner scan = new Scanner (System.in);
		
		//list作成
		TreeSet<Integer> set = new TreeSet<>();
		
		int a = scan.nextInt();
		for(int i=0; i<a; i++) {
			int num = scan.nextInt();
			set.add(num);
		}
		
		//list2作成
		TreeSet<Integer> set2 = new TreeSet<>();
		
		int b = scan.nextInt();
		for(int i=0; i<b; i++) {
			int num = scan.nextInt();
			set.add(num);
		}
		
		//和集合
		TreeSet<Integer> union = new TreeSet<>(set);
//		Iterator ite = union.iterator();
		union.addAll(set2);
		
		for(int j : union) {
			System.out.println(j);
		}

	}
}




Measured memory_bytes: 205728
def eratosthenes(limit):
  E = [1] * (limit + 1)
  E[0], E[1] = 0, 0
  prime_list = []
  for i, e in enumerate(E):
    if e:
      prime_list.append(i)
      for j in range(i, limit + 1, i):
        E[j] = 0
  return prime_list
N = int(input())
prime_list = eratosthenes(55555)
prime5 = [[] for i in range(5)]
for p in prime_list:
  prime5[p % 5].append(p)
ans = prime5[0]
for p5 in prime5:
  ans = p5 if len(p5) > len(ans) else ans
print(' '.join([str(x) for x in ans[:N]]))

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

using namespace std;

typedef long long ll;

ll C;

// Adapting this linecontainer code (from kactl of course)
// to be for quadratics instead :O
// it should work for any convex (monotonic?) function

// The cost of going from i to j is dp[i] + (h_j - h_i)^2 + C
// So we need a structure where we can insert (dp[i], h_i)
// pairs and query min (in structure) of cost(, h_j)
struct Line {
	mutable ll h, dp, p;
	bool operator<(const Line& o) const { return h < o.h; }
	bool operator<(ll x) const { return p < x; }
};

struct LineContainer : multiset<Line, less<>> {
	// (for doubles, use inf = 1/.0, div(a,b) = a/b)
	const ll inf = LLONG_MAX;
	ll div(ll a, ll b) { // floored division
		return a / b - ((a ^ b) < 0 && a % b); }
	bool isect(iterator x, iterator y) {
		if (y == end()) { x->p = inf; return false; }
		if (x->h == y->h) x->p = x->dp > y->dp ? inf : -inf;
		else {
      // where do x and y intersect?
      // we have x.dp + (H - x.h)^2 = y.dp + (H - y.h)^2
      // so x.dp + H^2 - 2H x.h + x.h^2 = y.dp + H^2 - 2H y.h + y.h^2
      // so x.dp - y.dp + x.h^2 - y.h^2 = 2(x.h-y.h)H
      x->p = div(x->dp - y->dp + x->h*x->h - y->h*y->h, 2*(x->h - y->h));
    }
		return x->p >= y->p;
	}
	void add(ll dp, ll h) {
		auto z = insert({h, dp, 0}), y = z++, x = y;
		while (isect(y, z)) z = erase(z);
		if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
		while ((y = x) != begin() && (--x)->p >= y->p)
			isect(x, erase(y));
	}
	ll query(ll x) {
		assert(!empty());
		auto l = *lower_bound(x);
		return (x-l.h) * (x-l.h) + l.dp + C;
	}
};

int main() {
  // Z: the N^2 DP is pretty straightforward, but you need
  // the convex hull trick to find a minimum quickly.
  //
  // DP states: dp[i] = min cost to get from 0 to i
  // dp[i] = min over j<i of dp[j] + (h_j - h_i)^2 + C

  cin.tie(0);
  cin.sync_with_stdio(0);

  long long n; cin >> n >> C;
  long long h[n];
  for(int i = 0; i<n; ++i) {
    cin >> h[i];
  }

  long long dp[n];
  for(int i = 0; i<n; ++i) {
    dp[i] = LLONG_MAX;
  }
  dp[0] = 0;
  LineContainer lc;
  lc.add(0, h[0]);

  for(int i = 1; i<n; ++i) {
    dp[i] = lc.query(h[i]);
    lc.add(dp[i], h[i]);
  }
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 15872
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(Math.max(a - 2 * b, 0));

        sc.close();
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end()
using namespace std;

vector<int> V;

void f(long long int N){
long long int M;
M = N;
int i = 0;

while(pow(26, i) <= N){
V.push_back(M%26);
M /= 26;
i++;}

return;}


int main() {
long long int N, n;cin >> N;

for(int i = 1; i < 12; i++){
if((pow(26, i) - 1)/25 <= N &&
   N < (pow(26, i + 1) - 1)/25){
n = i;break;}}

f(N - (pow(26, n) - 1)/25);
V.resize(n); reverse(ALL(V));

for(long long int i = 0; i < n; i++){

if(V[i] == 0)cout << 'a';
if(V[i] == 1)cout << 'b';
if(V[i] == 2)cout << 'c';
if(V[i] == 3)cout << 'd';
if(V[i] == 4)cout << 'e';
if(V[i] == 5)cout << 'f';
if(V[i] == 6)cout << 'g';
if(V[i] == 7)cout << 'h';
if(V[i] == 8)cout << 'i';
if(V[i] == 9)cout << 'j';
if(V[i] == 10)cout << 'k';
if(V[i] == 11)cout << 'l';
if(V[i] == 12)cout << 'm';
if(V[i] == 13)cout << 'n';
if(V[i] == 14)cout << 'o';
if(V[i] == 15)cout << 'p';
if(V[i] == 16)cout << 'q';
if(V[i] == 17)cout << 'r';
if(V[i] == 18)cout << 's';
if(V[i] == 19)cout << 't';
if(V[i] == 20)cout << 'u';
if(V[i] == 21)cout << 'v';
if(V[i] == 22)cout << 'w';
if(V[i] == 23)cout << 'x';
if(V[i] == 24)cout << 'y';
if(V[i] == 25)cout << 'z';

}
}

Measured memory_bytes: 3932
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;

	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A.begin(), A.end());
	vector<pair<int, int>> BC(M);
	for (int i = 0; i < M; i++) cin >> BC[i].second >> BC[i].first;
	sort(BC.begin(), BC.end(), greater<pair<int, int>>());

	int cnt = 0;
	for (int i = 0; i < M; i++) {

		for (int j = 0; j < BC[i].second; j++) {

			if (BC[i].first > A[cnt]) {
				A[cnt] = BC[i].first;
				cnt++;
			}
			else {
				i = M - 1;
				break;
			}

		}

	}

	lint ans = 0;
	for (const auto &elem : A) {

		ans += elem;
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1408