akhauriyash/Code-Regression huggingface dataset:
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE BangPatterns      #-}
{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    [x, y] <- map read.words <$> getLine :: IO [Integer]
    print $ solve x y

solve :: Integer -> Integer -> Integer
solve a b
  | mod a b == 0 = -1
  | otherwise = head.filter (\x -> rem x b /= 0 && x <= 1000000000000000000)$ map ((a*).toInteger) xor128

-------------------------------------------------------------------------------

xor128 :: [Word32]
xor128 = go 123456789 362436069 521288629 88675123
  where
    go !x !y !z !w = neww : go y z w neww
      where
        !t = x `xor` unsafeShiftL x 11
        !neww = (w `xor` unsafeShiftR w 19) `xor` (t `xor` unsafeShiftR t 8)


Measured memory_bytes: 508
import sys
from functools import lru_cache
sys.setrecursionlimit(1000000)

@lru_cache(maxsize=None)
def main():

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

    def cul(n,x):
        l=len(x)
        b=[x[i] for i in range(l)]
        b.pop(n)
        tmp=b[0]
        for i in range(1,l-1):
            tmp=gcd(tmp,b[i])
        return tmp

    N, *a = map(int, sys.stdin.read().split())
    p=50
    if p>N: p=N

    ans=0
    for i in range(p):
        s=cul(i,a[:p])
        if s>ans: ans=s
    print(ans)

if __name__=='__main__':
  main()

Measured memory_bytes: 14648
#AC済み
x,y,z,k=map(int,input().split())
a=sorted([int(i) for i in input().split()])
b=sorted([int(i) for i in input().split()])
c=sorted([int(i) for i in input().split()])
ab=sorted([a[i]+b[j] for j in range(y) for i in range(x)],reverse=True)
ab=ab[:k]
l=len(ab)
abc=sorted([ab[i]+c[j] for j in range(z) for i in range(l)],reverse=True)
for i in range(k):
    print(abc[i])


Measured memory_bytes: 184680
#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <string>
using namespace std;


int n;
int key[1000];
string str;

char x[60];

int main(){
  
  while(1){
    cin >> n;
    if(n == 0) break;



    for(int i= 0; i < n ; i++)
      cin >> key[i];

    cin >> str;

    int size = str.size();
    //  cout << size <<" ";
    for(int i = 0,j = 0; i < size; i++,j++){
      if(i % n == 0){
	j = 0;
      }      
   
      for(int k = 0; k < key[j] ; k++){
	str[i]--;
	if(str[i]  < 'a' && str[i] > 'Z') str[i] -= 6;
	if(str[i] < 'A' ) str[i] += 52 + 6;

      }
      /*

	if(str[i] - key[j] < 'A' && str[i] <= 'Z' && ){
	str[i] += 52 + 6;
	}else  if(str[i] - key[j] < 'A' && str[i] >= 'a' ){
	str[i] += 52;
	}
	if(str[i] >= 'a' && str[i] - key[j] < 'a' && str[i] - key[j] > 'Z') str[i] -= 6;
	str[i] -= key[j];
	}

      */
    }
    cout << str << endl;
    
  }
    return 0;
  
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
 
#define int long long int
#define ff first
#define ss second
#define pb push_back
 
int bexp(int a, int b, int mod)
{
    int res = 1;
    if (mod <= 0)
        return 0;
 
    while (b)
    {
        if (b & 1) res = (res * a) % mod;
 
        a = (a * a) % mod; 
        b >>= 1;
    }
    return res;
}
 
#define N 300010
#define MOD 1000000007
 
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

struct comp {
    bool operator() (const pair<int, int> a, const pair<int, int> b) const
    {
        return a.ss * (a.ff - a.ff / 2) > b.ss * (b.ff - b.ff / 2);
    }
};
int n, m;
vector<int> visi;
vector<vector<int>> g;
int cnt = 0;
void dfs(int v)
{
    visi[v] = 1;
    cnt++;
    for (int ne : g[v])
    {
        if (!visi[ne])
            dfs(ne);
    }
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    cin >> n >> m;

    visi = vector<int> (n + 1, 0);
    g = vector<vector<int>> (n + 1, vector<int>());
    int u, v;
    for (int i = 0; i < m; ++i)
    {
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int ans = 0;
    for (int i = 1; i < n + 1; ++i)
    {
        cnt = 0;
        if (!visi[i])
            dfs(i);

        ans = max(ans, cnt);
    }

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

Measured memory_bytes: 21916
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
	int a,b;
	int j,m,s,e;
	cin>>j>>m>>s>>e;
	a=j+m+s+e;
	cin>>j>>m>>s>>e;
	b=j+m+s+e;
	if(a>=b) cout<<a<<endl;
	else cout<<b<<endl;
    return 0;
}


Measured memory_bytes: 5444
A = int(input())
B = int(input())
C = int(input())
X = int(input())

tmp = X
ans = 0
for i in range(min(A+1, X//500+1)):
    X -= 500*i
    if X == 0:
        ans += 1
        break
    tmp_2 = X
    for j in range(min(B+1, X//100+1)):
        X -= 100*j
        if X == 0:
            ans += 1
            break
        else:
            if 50*C >= X:
                ans += 1
        X = tmp_2
    X = tmp

print(ans)


Measured memory_bytes: 3064
# input the number for array of a[]
n = int(input())
a = list(map(int, input().split()))

# input the number for array of b[]
m = int(input())
b = list(map(int, input().split()))

# do the linear search
count = 0
for i in range(m):
    for j in range(n):
        if(b[i] == a[j]):
            count += 1
            break

print(count)



Measured memory_bytes: 6324
from collections import defaultdict

n = int(input())

m = defaultdict(lambda: 99999)

s = input()
co = set(s)
for c in co:
    m[c] = min(m[c], s.count(c))

for _ in range(1, n):
    s = input()
    co &= set(s)
    for c in co:
        m[c] = min(m[c], s.count(c))

ret = sum([[k]*v for k, v in m.items() if k in co], [])

print(''.join(sorted(ret)))

Measured memory_bytes: 3444
/*
 *
 * Author: r3gz3n
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T=int> using order_statistics = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

const int MAX = 1e5 + 5;
const int INF = 1e9 + 5;

long long dp[105][100005];
int w[105], v[105];

int main(int argc, char* argv[]) {
    if(argc == 2 or argc == 3) freopen(argv[1], "r", stdin);
    if(argc == 3) freopen(argv[2], "w", stdout);
    int n, W, s = 0;
    cin >> n >> W;
    for (int i = 1;i <= n;++i) {
        cin >> w[i] >> v[i];
        s += v[i];
    }
    for (int i = 0;i <= n;++i) for (int j = 0;j < MAX;++j) dp[i][j] = INF;
    dp[0][0] = 0;
    for (int i = 1;i <= n;++i) {
        for (int j = 0;j <= s;++j) {
            if (j == 0) dp[i][j] = 0;
            else if (j - v[i] >= 0) dp[i][j] = min(dp[i][j], min(dp[i-1][j], dp[i-1][j-v[i]] + w[i]));
            else dp[i][j] = dp[i-1][j];
        }
    }
    int ans= 0 ;
    for (int i = 1;i <= s;++i) {
        if (dp[n][i] <= W) ans = i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 80128
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
using namespace atcoder;
using LL = long long;

int main(){
  int N, M;
  cin >> N >> M;
  vector<LL> a(N), b(M);
  rep(i,N) cin >> a[i];
  rep(i,M) cin >> b[i];
  vector<LL> c = convolution(a,b);
  rep(i,N+M-1) cout << c[i] << " ";
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 27188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int n,w;
		Scanner sc=new Scanner(System.in);
		w=sc.nextInt();
		n=sc.nextInt();
		int[] values = new int[w];
		for(int i=0;i<w;i++){
			values[i] = i+ 1;

		}
		for(int i= 0; i< n; i++) {
			String str= sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) -1;
			int b = Integer.parseInt(ab[1]) -1;
			int temp;
			temp=values[a];
			values[a]=values[b];
			values[b]=temp;
		}
		for(int i=0;i<w;i++)
			System.out.println(values[i]);
			}
	}

Measured memory_bytes: 17204
#include<bits/stdc++.h>
using namespace std;
int n,m[3][101],ans[2][101];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&m[1][i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&m[2][i]);
	for(int i=1;i<=2;i++)
		for(int j=1;j<=n;j++)
			ans[i][j]=max(ans[i-1][j],ans[i][j-1])+m[i][j];
	cout<<ans[2][n]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+99;
int n,m,p[N],id[N],fa[N],ans;
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&p[i]),id[p[i]]=i;
	for(int i=1;i<=n;i++)fa[i]=i;
	int x,y,u,v;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&x,&y);
		u=find(x);v=find(y);
		if(u!=v)fa[u]=v;
	}
	for(int i=1;i<=n;i++)ans+=(find(id[i])==find(i));
	printf("%d\n",ans);
}

Measured memory_bytes: 1408
#include <stdio.h>
int test(int x){

  if(x%2 == 0) x /= 2;
  else x=x*3+1;

  return x;

}

int main(){

  int n,result;

  while(1){

    scanf("%d",&n);
    if(n == 0) break;
    result=0;

    while(1){

      if(n == 1) break;

      n=test(n);

      result++;

    }

    printf("%d\n",result);

  }

  return 0;

}

Measured memory_bytes: 600
#include <stdio.h>
int main(){
  int n, a;
  int f = 0, e = 0, o = 0;

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
      scanf("%d", &a);
      if (a % 4 == 0) f++;
      else if(a % 2 == 0) e++;
  }

  if(f*2 + 1 >= n)  printf("Yes\n");
  else if(f*2 + e >= n) printf("Yes\n");
  else  printf("No\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
int64_t N, K;
vector<int64_t> A(MAXN);

bool ok(int64_t l) // 全てがl以下に収まるように切る
{
  int64_t cnt = 0;
  for (int i = 0; i < N; i++)
  {
    if (l > A[i])
      continue;
    if (A[i] % l == 0)
    {
      cnt += (A[i] / l) - 1;
    }
    else
    {
      cnt += (A[i] / l);
    }
  }
  return cnt <= K;
}

int main()
{
  int64_t ma = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
    ma = max(ma, A[i]);
  }
  int64_t l = 0, r = ma + 1;
  while (r - l > 1)
  {
    int64_t m = (l + r) / 2;
    if (ok(m))
      r = m;
    else
      l = m;
  }
  cout << l + 1 << endl;
}

Measured memory_bytes: 4704
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int X, Y; cin >> X >> Y;
    for (int a = 0; a < 100; a++) {
        for (int b = 0; b < 100; b++) {
            if (a + b == X && 2 * a + 4 * b == Y) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3628
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
  N = parseInt(readline())
  a = parseMap(split(readline()))

  num = 0
  for i in 1:2:N
    if a[i] % 2 == 1
      num += 1
    end
    #println("$i")
  end


  println("$num")

#  if mod(a,1000) != 0
#    println(1000-mod(a,1000))
#  else
#    println(0)
#  end
end
main()

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  LL n,p;
  cin >> n >> p;
  if(n==1){
    cout << p << endl;
    return 0;
  }
  LL ans=1;
  int count=0;
  for(int i=2;i<=sqrt(p);i++){
    if(p%i==0){
      count=0;
      while(p%i==0){
        p/=i;
        count++;
      }
      for(int j=0;j<count/n;j++){
        ans*=i;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long[] a = new long[200000];
        for (int i = 1; i < 200000; i++) {
            a[i] = i + a[i-1];
        }
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] p = new int[n];
        int[] s = new int[n];
        int t = 0;
        for (int i = 0; i < n; i++) {
            s[i] = sc.nextInt();
            t += s[i];
            p[i] = t;
        }
        int max = p[k-1];
        int idx = 0;
        for (int i = k; i < n; i++) {
            int tmp = p[i] - p[i - k];
            if(max < tmp){
                max = tmp;
                idx = i -(k-1);
            }
        }
        double ans = 0.0;
        for (int i = idx; i < idx+k; i++) {
            ans += (double)a[s[i]] / s[i];
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 80404
#include<cstdio>

int main()
{
	int n; scanf("%d", &n);
	int now = 0;
	
	for(int i = 0; i < n; i++){
		int inp; scanf("%d", &inp);
		if(inp == now + 1) now++;
	}
	if(now == 0) printf("-1\n");
	else printf("%d\n", n - now);
}

Measured memory_bytes: 1700
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m,f[2][190][190][190],g[2][190][190][190],tmp[190];
char a[190][190];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%s",a[i]+1);
	for(int l=1;l<=n;l++)
	{
		for(int r=l;r<=n;r++)
		{
			for(int k=1;k<=m;k++)
			{
				if(l==r)tmp[k]=(a[r][k]=='#');
				else if(tmp[k]!=(a[r][k]=='#'))tmp[k]=-1;
			}
			f[0][l][r][m+1]=m+1;
			tmp[m+1]=tmp[m];
			for(int k=m;k>=1;k--)
			{
				if(tmp[k]!=-1&&tmp[k]==tmp[k+1])f[0][l][r][k]=f[0][l][r][k+1];
				else if(tmp[k]!=-1)f[0][l][r][k]=k+1;
				else f[0][l][r][k]=k;
			}
		}
	}
	for(int l=1;l<=m;l++)
	{
		for(int r=l;r<=m;r++)
		{
			for(int k=1;k<=n;k++)
			{
				if(l==r)tmp[k]=(a[k][r]=='#');
				else if(tmp[k]!=(a[k][r]=='#'))tmp[k]=-1;
			}
			g[0][l][r][n+1]=n+1;
			tmp[n+1]=tmp[n];
			for(int k=n;k>=1;k--)
			{
				if(tmp[k]!=-1&&tmp[k]==tmp[k+1])g[0][l][r][k]=g[0][l][r][k+1];
				else if(tmp[k]!=-1)g[0][l][r][k]=k+1;
				else g[0][l][r][k]=k;
			}
		}
	}
	for(int i=1;;i++)
	{
		int flag=i&1;
		if(f[!flag][1][n][1]>m)
		{
			printf("%d\n",i-1);
			return 0;
		}
		for(int l=1;l<=n;l++)
		  for(int r=l;r<=n;r++)
		    for(int k=1;k<=m+1;k++)
		      f[flag][l][r][k]=k;
		for(int l=1;l<=m;l++)
		  for(int r=l;r<=m;r++)
		    for(int k=1;k<=n+1;k++)
		      g[flag][l][r][k]=k;
		for(int l=1;l<=n;l++)
		  for(int r=l;r<=n;r++)
		    for(int k=1;k<=m+1;k++)
		      f[flag][l][r][k]=max(f[flag][l][r][k],f[!flag][l][r][f[!flag][l][r][k]]),
			  g[flag][k][f[!flag][l][r][f[!flag][l][r][k]]-1][l]=max(g[flag][k][f[!flag][l][r][f[!flag][l][r][k]]-1][l],r+1);
		for(int l=1;l<=m;l++)
		  for(int r=l;r<=m;r++)
		    for(int k=1;k<=n+1;k++)
		      g[flag][l][r][k]=max(g[flag][l][r][k],g[!flag][l][r][g[!flag][l][r][k]]),
			  f[flag][k][g[!flag][l][r][g[!flag][l][r][k]]-1][l]=max(f[flag][k][g[!flag][l][r][g[!flag][l][r][k]]-1][l],r+1);
		for(int k=1;k<=m+1;k++)
		  for(int len=n;len>=1;len--)
		    for(int l=1;l+len-1<=n;l++)
		      f[flag][l][l+len-1][k]=max(f[flag][l][l+len-1][k],max(f[flag][l-1][l+len-1][k],f[flag][l][l+len][k]));
		for(int k=1;k<=n+1;k++)
		  for(int len=m;len>=1;len--)
		    for(int l=1;l+len-1<=m;l++)
		      g[flag][l][l+len-1][k]=max(g[flag][l][l+len-1][k],max(g[flag][l-1][l+len-1][k],g[flag][l][l+len][k]));
	}
	return 0;
}

Measured memory_bytes: 106496
<?php
$n = (int) fgets(STDIN);
$probabilities = explode(" ", trim(fgets(STDIN)));
foreach ($probabilities as $k => $v) {
	$probabilities[$k] = (float) $v;
}
getHeadsSuperior($probabilities, $n);

function getHeadsSuperior($probabilities, $n) {
    $dp = [];
    for ($i = 0; $i <= $n; $i++){
        $dp[$i] = array_fill(0, $n + 1, 0.0);
    }
    $dp[0][0] = 1.0;
    for ($i = 1; $i < $n + 1; $i++) {
        for ($j = 0; $j < $n + 1; $j++) {
            $dp[$i][$j] = $dp[$i - 1][$j] * (1 - $probabilities[$i - 1]);
            if ($j > 0) {
                $dp[$i][$j] += $dp[$i - 1][$j - 1] * $probabilities[$i - 1];
            }
        }
    }
    $result = 0.0;
    for ($i = (int) ceil(($n + 1) / 2); $i <= $n; $i++) {
      $result += $dp[$n][$i];
    }
    echo $result;
}

?>

Measured memory_bytes: 414200
def s()
  gets().chomp
end
def i()
  gets.to_i
end
def li()
  gets.split.map(&:to_i)
end
def ili()
  n = gets.to_i
  as = gets.split.map(&:to_i)
  [n, as]
end
class Array
  def sum
    total = 0
    self.each do |item|
      total += item
    end
    total
  end
end

n= i()
a = []
n.times{
  a<<gets.split()
}
sum = 0
a.each{|x, u|
  if u == "JPY"
    sum += x.to_f
  else
    sum += x.to_f*380000.0
  end
}

puts sum


Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)
int kai(int a){
    if(a == 0)return 0;
    int ans = 1;
    while(a > 1){
        ans *= a;
        a -= 1;
    }
    return ans;
}

int main(){
    int n;
    cin >> n;
    int a[n+1], b[n+1], c, p, q;
    p = q = 0;
    rep1(i,n+1){
        cin >> a[i];
        int c = a[i]-1;
        rep1(j,i+1){
            if(a[j] < a[i]) c -= 1;
        }
        p += c * kai(n-i);
    }
    rep1(i,n+1){
        cin >> b[i];
        int c = b[i]-1;
        rep1(j,i+1){
            if(b[j] < b[i]) c -= 1;
        }
        q += c * kai(n-i);
    }
    int ans = p-q;
    if(ans < 0)ans *= -1;
    cout << ans << endl;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Data.List
import Data.Maybe
import Data.Function (fix)
import Data.Array (Array, array, (!))
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8

modular :: Int
modular = 1000000007
 
getInts :: IO [Int]
getInts = (map parseInt . BS8.words) <$> BS.getLine 
    where parseInt = fst . fromJust . BS8.readInt

odds :: [Int]
odds = 0 : map (\x -> (x+1) - (x+1) `mod` 2) [1..]

evens :: [Int]
evens = map (\x -> x - (x+1) `mod` 2) [1..]

two :: Int -> Int
two 0 = 1
two n = ((two (n-1)) * 2) `mod` modular

solve :: [Int] -> Int
solve arr = if (n `mod` 2 == 0 && take n evens /= sorted) || (n `mod` 2 == 1 && take n odds /= sorted) then 0
            else two (n `div` 2)
    where n = length arr
          sorted = sort arr

main :: IO ()
main = do
    [n] <- getInts
    arr <- getInts
    print $ solve arr

Measured memory_bytes: 19836
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  ll x, y; cin >> x >> y;

  int ans = 0;
  if (abs(x) == abs(y)) {
    if (x*y<0) ans++;
  } else if (x < y) {
    ans += abs(min(abs(y-x), abs(y)-abs(x)));
    if (x*y<0) ans++;
  } else if (x > y) {
    ans++;
    ans += abs(min(abs(x-y), abs(x)-abs(y)));
    if (x*y>0) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int mod = 1000000007ll;

template <int mod>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const {
    return ModInt(*this) += p;
  }
  ModInt operator-(const ModInt &p) const {
    return ModInt(*this) -= p;
  }
  ModInt operator*(const ModInt &p) const {
    return ModInt(*this) *= p;
  }
  ModInt operator/(const ModInt &p) const {
    return ModInt(*this) /= p;
  }
  bool operator==(const ModInt &p) const {
    return x == p.x;
  }
  bool operator!=(const ModInt &p) const {
    return x != p.x;
  }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ans(1), mul(x);
    while(n) {
      if(n & 1) ans *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ans;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};

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

map<LL,LL> prime_fact(LL x){
	map<LL,LL> ret;
	for(LL i=2;i*i<=x;i++){
		if(x%i==0){
			LL counter = 0;
			while(1){
				if(x%i!=0) break;
				x /= i;
				counter++;
			}
			ret[i] = counter;
		}
	}
	if(x!=1) ret[x] = 1;
	return ret;
}

int N;
LL A[10000];

ModInt<mod> ans = 0;
 
void solve(){
	map<LL,LL> lcm;//A[0]~A[N-1]の最小公倍数に約数jがk個含まれているときlcm[j] = kとする
	for(int i=0;i<N;i++){
		map<LL,LL> divisor = prime_fact(A[i]);
		for(auto a : divisor){
			lcm[a.first] = max(lcm[a.first],a.second);
		}
	}
	//mod=10e9+7におけるlcmを求める
	ModInt<mod> lcm_mod = 1;
	for(auto a : lcm){//lcmのそれぞれの要素 <約数、それが何個あるか> を見ていく
		ModInt<mod> base = a.first;
		lcm_mod *= base.pow(lcm[a.first]);
	}
	//ansを求める
	for(int i=0;i<N;i++){
		ans += lcm_mod/A[i];
	}
}
 
int main(){
	cin >> N;
	for(int i=0;i<N;i++) cin >> A[i];
 
	solve();

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

Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
using namespace std;
typedef long long ll;
#define mp make_pair;
#define pb push_back;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

const int mod=1e9+7;
int mu(int a,int b){
  return (long long)a*b%mod;
}
int ad(int a,int b){
  if((a+=b)>=mod)a-=mod;
  return a;
}
int pw(int a,int b,int c=1){
  for(;b;b>>=1,a=mu(a,a))if(b&1)c=mu(c,a);
  return c;
}
int dv(int a,int b){
  return mu(a,pw(b,mod-2));
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int s[n],t[m];
  
  int sum[n+1][m+1];
  int dp[n+1][m+1];

  rep(i, n) cin >> s[i];
  rep(i, m) cin >> t[i];
  dp[0][0] = 1;
  sum[0][0] = 1;
  rep1(i, n){
    dp[i][0] = 0;
    sum[i][0] = 1;
  }
  rep1(j, m){
    dp[0][j] = 0;
    sum[0][j] = 1;
  }
  rep1(i,n)rep1(j,m){    
    if(s[i-1] == t[j-1]) dp[i][j] = sum[i-1][j-1];
    else dp[i][j]=0;
    sum[i][j] = ad(ad(dp[i][j],sum[i][j-1]),ad(sum[i-1][j],mod-sum[i-1][j-1]));
  }
  cout << sum[n][m] << endl;
  return 0;
    

}


Measured memory_bytes: 31616
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct pairingHeapNode{
  struct pairingHeapNode *next;
  struct pairingHeapNode *child;
  unsigned char val[];
} heapNode;

typedef struct pairingHeap{
  heapNode *root;
  int heapSize;
  size_t size;
  int (*cmp)(const void *,const void *);
} heap;

heapNode* newHeapNode(const void *v,const size_t size){
  heapNode *res=(heapNode *)malloc(sizeof(heapNode)+size);
  memcpy(res->val,v,size);
  res->next=NULL;
  res->child=NULL;
  return res;
}

void freeOneNode(heapNode *t){
  free(t);
  return;
}

void freeAllNode(heapNode *t){
  if(t==NULL) return;
  freeAllNode(t->next);
  freeAllNode(t->child);
  freeOneNode(t);
  return;
}

heap* newHeap(const size_t size,int (*cmp)(const void *,const void *)){
  heap *res=(heap *)malloc(sizeof(heap));
  res->root=NULL;
  res->heapSize=0;
  res->size=size;
  res->cmp=cmp;
  return res;
}

void clearHeap(heap *h){
  freeAllNode(h->root);
  h->root=NULL;
  h->heapSize=0;
}

int getSize(const heap *h){
  return h->heapSize;
}

int isEmpty(const heap *h){
  return getSize(h)==0;
}

void top(const heap *h,void *res){
  memcpy(res,h->root->val,h->size);
}

heapNode* meld(heapNode *a,heapNode *b,int (*cmp)(const void *a,const void *b)){
  if(a==NULL) return b;
  if(b==NULL) return a;
  if(cmp(a->val,b->val)<=0){
    b->next=a->child;
    a->child=b;
    return a;
  } else {
    a->next=b->child;
    b->child=a;
    return b;
  }
}

void push(heap *h,const void *v){
  heapNode *p=newHeapNode(v,h->size);
  h->heapSize++;
  h->root=meld(h->root,p,h->cmp);
  return;
}

void pop(heap *h,void *v){
  memcpy(v,h->root->val,h->size);
  heapNode *lst=h->root->child;
  int (*cmp)(const void *a,const void *b)=h->cmp;
  freeOneNode(h->root);
  h->heapSize--;
  heapNode *r=NULL;
  while(lst!=NULL && lst->next!=NULL){
    heapNode *a=lst;
    heapNode *b=lst->next;
    heapNode *next=lst->next->next;
    a->next=b->next=NULL;
    r=meld(r,meld(a,b,cmp),cmp);
    lst=next;
  }
  if(lst!=NULL) r=meld(r,lst,cmp);
  h->root=r;
  return;
}

typedef long long int int64;

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

void run(void){
  int n;
  scanf("%d",&n);
  int *a=(int *)calloc(3*n,sizeof(int));
  int i;
  for(i=0;i<3*n;i++) scanf("%d",a+i);
  int64 *front=(int64 *)calloc(n+1,sizeof(int64));
  heap *h=newHeap(sizeof(int),cmp);
  int64 sum=0;
  for(i=0;i<n;i++){
    sum+=a[i];
    push(h,a+i);
  }
  front[0]=sum;
  for(i=n;i<2*n;i++){
    sum+=a[i];
    push(h,a+i);
    int v;
    pop(h,&v);
    sum-=v;
    front[i-n+1]=sum;
  }
  clearHeap(h);
  int64 *back=(int64 *)calloc(n+1,sizeof(int64));
  sum=0;
  for(i=3*n-1;i>=2*n;i--){
    sum+=a[i];
    int v=-a[i];
    push(h,&v);
  }
  back[n]=sum;
  for(i=2*n-1;i>=n;i--){
    sum+=a[i];
    int v=-a[i];
    push(h,&v);
    pop(h,&v);
    sum+=v;
    back[i-n]=sum;
  }
  int64 max=front[0]-back[0];
  for(i=1;i<=n;i++) if(max<front[i]-back[i]) max=front[i]-back[i];
  printf("%lld\n",max);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 7552
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int i,j,Co=0,C1=0,C2=0,C3=0;
    string n;
    cin>>j;
    for(i=1; i<=j; i++)
    {
        cin>>n;
        if(n=="AC")
            Co++;
        else if(n=="WA")
            C1++;
        else if(n=="TLE")
            C2++;
        else if(n=="RE")
            C3++;
    }
    cout<<"AC x "<<Co<<endl;
    cout<<"WA x "<<C1<<endl;
    cout<<"TLE x "<<C2<<endl;
    cout<<"RE x "<<C3<<endl;
    return 0;
}



Measured memory_bytes: 3632
import java.util.Scanner



object Main {

  def read(): (Int, Int) = {
    val sc: Scanner = new Scanner(System.in)
    val a, b= sc.nextInt
    sc.close()
    (a, b)
  }


  def solve(a: Int, b: Int): Int = {
    if(b <= 1) return 0
    var cnt = 0
    while(b > a * cnt - Math.max(cnt-1, 0)) {
      cnt += 1
    }
    cnt
  }


  def main(args: Array[String]): Unit = {
    val (a, b) = read()
    println(solve(a, b))
  }

}


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

int main() {
    int n, m;
    cin >> n >> m;
    priority_queue<int> q;
    rep (i, n) {
        int a;
        cin >> a;
        q.push(a);
    }
    rep (i, m) {
        int a = q.top(); q.pop();
        q.push(a/2);
    }
    ll ans = 0;
    rep (i, n) {
        ans += q.top(); q.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 892
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedHashMap;
import java.util.Map;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String line = "";
		StringBuilder result = new StringBuilder();

		Map<Integer, Long> ds = null;

		while ((line = br.readLine()) != null) {

			//
			if (line.indexOf(" ") == -1) {
				if (ds != null) {
					int count = 0;
					for (Integer k : ds.keySet()) {
						if (ds.get(k) >= 1000000) {
							result.append(k + "\n");
							count++;
						}
					}
					if (count == 0) {
						result.append("NA\n");
					}
				}

				// init dataset.
				int n = Integer.parseInt(line);
				if (n == 0) {
					break;
				}
				ds = new LinkedHashMap<Integer, Long>();

				// read data.
				for (int i = 0; i < n; i++) {
					line = br.readLine();
					Integer c = Integer.parseInt(line.split(" ")[0]);
					Long p = Long.parseLong(line.split(" ")[1]);
					Long q = Long.parseLong(line.split(" ")[2]);
					if (ds.containsKey(c)) {
						ds.put(c, (ds.get(c) + p * q));
					} else {
						ds.put(c, p * q);
					}
				}
			}
		}
		System.out.print(result.toString());
	}
}

Measured memory_bytes: 25412
#include <stdio.h>
#include <math.h>

int main(void) {
	double x, q, k;
	while(1){
		scanf("%lf",&q);
		if(q == -1) break;
		x = q/2;
		k=fabs(x*x*x-q);
		while(1){
		x = x - ((x*x*x - q) / (3*x*x));
		k=fabs(x*x*x-q);
		if(k<0.00001*q) break;
		}
		printf("%f\n",x);
		
	}
	return 0;
}

Measured memory_bytes: 648
import java.util.Scanner;

public class Main
{
	public static void main ( String[] args )
	{
		Scanner sc = new Scanner ( System.in );
		int n, five = 0, seven = 0;
		for ( int i = 0; i < 3; i++ )
		{
			n = sc.nextInt ();
			if ( n == 5 )
			{
				five++;
			}
			else if ( n == 7 )
			{
				seven++;
			}
		}

		if ( five == 2 && seven == 1 )
		{
			System.out.println ( "YES" );
		}
		else
		{
			System.out.println ( "NO" );
		}
	}

}


Measured memory_bytes: 21716
#include<stdio.h>

int main(){
	int l,r,n,x=0;
	scanf("%d%d%d", &l, &r, &n);
	for (int i=l ; i<=r ; i++){
		if (i%n==0){
			x++;
		}
	}
	printf("%d\n", x);
	return 0;
}

Measured memory_bytes: 1704
// {{{ Templates
#include <bits/stdc++.h>

#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

// }}}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string A;
    cin >> A;
    vector<ll> nums(26, 0);
    for (int i = 0; i < A.size(); i++) {
        nums[A[i] - 'a']++;
    }
    ll sum = 0;
    for (int i = 0; i < 26; i++) {
        sum += nums[i] * nums[i];
    }
    cout << ((A.size() * A.size()) - sum) / 2 + 1 << endl;
    return 0;
}


Measured memory_bytes: 720
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
const int inf=1e9+7;
const int mod=1e9+7;
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
int main(){
	int N;
	int x[100],y[100],h[100];
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>x[i]>>y[i]>>h[i];
	}
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			int H=-1;
			for(int k=0;k<N;k++){
				if(h[k]!=0){
					H=h[k]+abs(x[k]-i)+abs(y[k]-j);
					break;
				}
			}
			bool f=true;
			for(int k=0;k<N;k++){
				if(max(H-abs(x[k]-i)-abs(y[k]-j),0)!=h[k]){
					f=false;
					break;
				}
			}
			if(f){
				cout<<i<<" "<<j<<" "<<H<<endl;
				return 0;
			}
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
	int n, k;
	int ball;
	int i, j;
	int val = 0;
	vector<int> baketu(200001);
	int kai = 0;
	int sum = 0;
	
	cin >> n >> k;
	
	for (i = 0; i < n; i++){
		cin >> ball;
		baketu[ball]++;
	}
		
	for (i = 1; i <= n; i++){
		if (baketu[i] > 0){
			val++;
		}
	}
	sort(baketu.begin(), baketu.end());
	reverse(baketu.begin(),baketu.end());
		
	for (i = 0; i < k; i++){
		sum += baketu[i];
	}
	
	cout << n - sum << "\n";
		
	
	return (0);
}


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

using namespace std;

int main() {
    // a = 2 * x - 0.5 * y
    // b = -x + 0.5 * y
    int x, y;
    cin >> x >> y;
    if (y % 2 != 0) {
        cout << "No" << endl;
        return 0;
    }
    if (2 * x - y / 2 < 0) {
        cout << "No" << endl;
        return 0;
    }
    if (-1 * x + y / 2 < 0) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}


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


int main() {long a, b, x;
cin >> a >> b >> x;
long ans;
if(a != 0){
  ans = b / x - (a - 1) / x;
}
else{
  ans = b / x + 1;
}



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



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

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

	int a = stoi(s.substr(0, 1));
	int b = stoi(s.substr(1, 1));
	int c = stoi(s.substr(2, 1));
	int d = stoi(s.substr(3, 1));

	if (a + b + c + d == 7)
	{
		cout << a << "+" << b << "+" << c << "+" << d;
	}
	else if (a - b + c + d == 7)
	{
		cout << a << "-" << b << "+" << c << "+" << d;
	}
	else if (a + b - c + d == 7)
	{
		cout << a << "+" << b << "-" << c << "+" << d;
	}
	else if (a + b + c - d == 7)
	{
		cout << a << "+" << b << "+" << c << "-" << d;
	}
	else if (a - b - c + d == 7)
	{
		cout << a << "-" << b << "-" << c << "+" << d;
	}
	else if (a + b - c - d == 7)
	{
		cout << a << "+" << b << "-" << c << "-" << d;
	}
	else if (a - b + c - d == 7)
	{
		cout << a << "-" << b << "+" << c << "-" << d;
	}
	else if (a - b - c - d == 7)
	{
		cout << a << "-" << b << "-" << c << "-" << d;
	}

	cout << "=7" << endl;
}


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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    string s;
    cin >> s;

    string t = s;
    reverse(t.begin(), t.end());
    ll cnt = 0;
    for(i=0;i<(1+s.size())/2;i++){
        if(s[i]!=t[i])cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

int main(){
    int N; cin>>N;
    vector<int>H(N);
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    int ans=0;
    int now=H[0];
    for(int i=0;i<N;i++){
        if(H[i]>=now){
            ans++;
            now=H[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define INF 1000000000

typedef long double Real;
#define EPS 1e-11
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

bool inRect(Real ax,Real ay,Real bx,Real by,Real tx,Real ty){
  return (ax<=tx && tx<=bx && ay<=ty && ty<=by);
}

int main(){
  Real ax,ay,bx,by,cx,cy,dx,dy;
  while(~scanf("%Lf%Lf%Lf%Lf%Lf%Lf%Lf%Lf",&ax,&ay,&bx,&by,&cx,&cy,&dx,&dy)){
    bool flag = false;
    flag |= inRect(ax,ay,bx,by,cx,cy);
    flag |= inRect(ax,ay,bx,by,cx,dy);
    flag |= inRect(ax,ay,bx,by,dx,cy);
    flag |= inRect(ax,ay,bx,by,dx,dy);
    flag |= inRect(cx,cy,dx,dy,ax,ay);
    flag |= inRect(cx,cy,dx,dy,ax,by);
    flag |= inRect(cx,cy,dx,dy,bx,ay);
    flag |= inRect(cx,cy,dx,dy,bx,by);
    flag |= (ax<=cx && dx<=bx && ay>=cy && dy>=by);
    flag |= (ax>=cx && dx>=bx && ay<=cy && dy<=by);
    if(flag)printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

int		main(void)
{
	int n, m, k;
	cin >> n >> m >> k;

	vector<ll> A(n+1);
	vector<ll> B(m+1);
	for (int i = 1; i < n+1; ++i)
		cin >> A[i];
	for (int i = 1; i < m+1; ++i)
		cin >> B[i];
	
	vector<ll> AA(n+1);
	vector<ll> BB(m+1);
	AA[0] = A[0];
	for (int i = 1; i < n+1; ++i)
		AA[i] = AA[i-1] + A[i];
	BB[0] = B[0];
	for (int i = 1; i < m+1; ++i)
		BB[i] = BB[i-1] + B[i];
	
	ll ans = 0, j;
	for (j = 0; j < m+1; ++j)
	{
		if (BB[j] > k)
			break ;
	}
	--j;
	for (ll i = 0; i < n+1; ++i)
	{
		if (AA[i] > k)
			break ;
		while (BB[j] > k - AA[i])
			--j; 
		ans = max(ans, i + j);
	}
	cout << ans << endl;
}



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


int main()
{
    double n,m,d;
    cin >> n >> m >> d;
    double res = (n-d)*(m-1)*(d>0.5?2:1)/(n*n);
    cout << fixed << setprecision(10) << res << endl;
    return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;

  int count = 0;
  for (int i = 0; i < N - 2; i++) {
    if (S.at(i) == 'A' && S.at(i+1) == 'B' && S.at(i+2) == 'C') {
      count++;
    }
  }

  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#define maxd 400500
using std::string;
using std::cout;
using std::cin;
using std::endl;
using std::sort;
using std::map;
int main()
{
    long int n,l,ans=1;
    cin>>n>>l;
    while(n/l)
        n/=l,ans++;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
N,D=map(int,input().split())
A=[0]*N
i=0
while i<N:
    A[i]=list(map(int,input().split()))
    i+=1

i=0
ans=0
while i<N:
    j=i+1
    while j<N:
        k=0
        d1=0
        while k<D:
            d1+=(A[i][k]-A[j][k])**2
            k+=1
        d2=d1**0.5
        ans+=1*d2.is_integer()
        j+=1
    i+=1
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;
class Main
{
   public static void main(String[] args)
      {
      Scanner sc1 = new Scanner(System.in);
        while(true){
        int H = sc1.nextInt();
        int W = sc1.nextInt();
        if(H==0 && W==0)break;
       
        for(int i = 0; i<H; i++){

           for(int j = 0; j<W; j++)

            if(i==0||i==H-1)System.out.print("#");
            else {
              if(j==0||j==W-1)System.out.print("#");
              else System.out.print(".");
                 }
           System.out.println();
        }
        System.out.println();
}
}
}


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

using namespace std;

typedef long long int li;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

vi par,sz,vis;
vector<vi> graph;

void init(li n)
{
    par.resize(n);
    sz.resize(n);
    vis.resize(n);
    graph.resize(n);

    f(i,0,n-1)
    {
        par[i]=i;
        sz[i]=1;
    }
}

li root(li a)
{
    while(a!=par[a])
    {
        par[a]=par[par[a]];
        a=par[a];
    }

    return a;
}

void unio(li a,li b)
{
    li r_a=root(a);
    li r_b=root(b);

    if(par[r_a]!=r_b)
    { 
        if(sz[r_a]<sz[r_b])
        {
            par[r_a]=par[r_b];
            sz[r_b]+=sz[r_a];
            sz[r_a]=0;
        }
        else
        {
            par[r_b]=par[r_a];
            sz[r_a]+=sz[r_b];
            sz[r_b]=0;
        }
    }
}

int main()
{    
    

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li n;

    cin>>n;

    map<pair<li,li>,li> m;

    f(i,1,n)
    {
        if(i%10>0)
        {
            li len=to_string(i).length();

            string s=to_string(i);

            li t1=i%10;
            li t2=s[0]-'0';

            m[{t2,t1}]++;
        }
    }

    li ans=0;

    for(auto it:m)
    {
        ans += it.S * m[{it.F.S,it.F.F}];
    }

    cout<<ans;

    return 0;
}

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

typedef long long int ll;
typedef unsigned long long int ull;

#define test(t)		int t; cin>>t; while(t--)
#define all(a)		a.begin(), a.end()
#define f(i, a, b)	for(int i = a; i < b; ++i)
#define endl 		"\n"
#define deb(x)		cout << #x << "--" << x << "--" << endl;
#define deb2(x,y)	cout << #x << "--" << x << "--" << endl <<  #y << "--" << y << "--" << endl;
#define fast 		ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define mx9		1000000007
#define mx7		10000007
#define mx6		1000006
#define mx5		200005
#define inf		1<<30                                 
#define eps		1e-9
#define mod		1000000007

void solve()
{
  string s, t;
  cin >> s;
  cin >> t;
  if(t.substr(0, s.length()) == s)
	cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
int main()
{
     fast;
     //test(t)
          solve();
     return 0;
}


Measured memory_bytes: 2976
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include "bits/stdc++.h"
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int A,P;
	scan(A>>P);
	prin((A*3+P)/2);
	return 0;
}


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

using namespace::std;

const int SIZE = 3e3 + 1;
double DP[SIZE][SIZE];

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

	int N;
	cin >> N;

	vector<double> P(N + 1);
	for(int i = 1;i <= N;i++)
		cin >> P[i];

	DP[1][1] = P[1];
	DP[1][0] = 1.0 - P[1];
	for(int i = 2;i <= N;i++){
		for(int j = 0;j <= i;j++){
			DP[i][j] = DP[i - 1][j - 1] * P[i] + DP[i - 1][j] * (1 - P[i]);
		}
	}

	double sol = 0;
	for(int i = 0;i <= N;i++){
		if(i > N - i)
			sol += DP[N][i];
	}

	cout << setprecision(10) << fixed << sol << '\n';

	return 0;
}


Measured memory_bytes: 68992
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int input = scan.nextInt();
		scan.close();
		int even = 0;
		int odd = 0;

		if(input % 2 == 1) {
          int a = input;
			while (a != 1) {
				a = a - 2;
				odd++;
			}
			even = input - odd;
		}else {
          int a = input;
			while (a != 0) {
				a = a - 2;
				even++;
			}
			odd = input - even;
		}
		System.out.println(odd * even);
	}
}

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

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

    margin = a - b;
    if (c < margin) cout << 0 << endl;
    else cout << c - margin << endl;

    return 0;
}

Measured memory_bytes: 256
A = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]

for b in B:
  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        A[i][j] = -100

f = False
for i in range(3):
  s = 0
  for j in range(3):
    s += A[i][j]
  if s == -300:
    f = True
for i in range(3):
  s = 0
  for j in range(3):
    s += A[j][i]
  if s == -300:
    f = True
s = 0
for i in range(3):
  s += A[i][i]
  if s == -300:
    f = True
s = 0
for i in range(3):
  s += A[i][2-i]
  if s == -300:
    f = True
print('Yes' if f else 'No')


Measured memory_bytes: 38384
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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

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

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using uInt = long long unsigned int;
using Double = long double;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int X, Y, Z;
        cin >> X >> Y >> Z;


        swap(X, Y);
        swap(X, Z);
        cout << X << " " << Y << " " << Z << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
# -*- coding: utf-8 -*-
import numpy as np
import math
from functools import reduce


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

num_buka = np.zeros(n)
for _a in a:
    num_buka[_a-1] += 1

for e in num_buka:
    print(int(e))


Measured memory_bytes: 51056