akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        for (int a = 0; a <= x; a++) { // 鶴
            for (int b = 0; b <= x - a; b++) { // 亀
                if (a + b == x && a * 2 + b * 4 == y) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 32560
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

mat memo(100,vec(100,-1));

ll comb(int i,int j){
    if(j==0)return 1;
    if(i==j)return 1;
    if(memo[i][j]!=-1)return memo[i][j];

    return memo[i][j]=comb(i-1,j)+comb(i-1,j-1);
}

int main(){
    int N,A,B;cin>>N>>A>>B;
    ll v[60],S[60];
    S[0]=0;
    map<ll,int> mp;
    for(int i=0;i<N;i++){
        cin>>v[i];
        mp[v[i]]++;
    }
    sort(v,v+N,greater<ll>());
    for(int i=0;i<N;i++)
        S[i+1]=S[i]+v[i];

    if(v[0]!=v[A-1]){
        int c=0,k=A-1;
        while(v[k]==v[A-1]){
            c++;
            k--;
        }
        double ans=(double)S[A]/(double)A;
        printf("%.8lf\n",ans);
        cout<<comb(mp[v[A-1]],c)<<endl;     
        return 0;
    }
    else{
        ll count=0;
        int c=A;
        for(int i=A;i<=B;i++){
            count+=comb(mp[v[0]],c);
            if(v[i]==v[0])c++;
            else break;
        }
        cout<<v[0]<<endl;
        cout<<count<<endl;
        return 0;
    }
    return 0;   
}

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


ll dp[101][100001];
ll maxVal(ll *wts,ll * val,ll W,ll n)
{
	if(n==0||W==0)
	return 0;
	
	if(dp[n][W]!=-1)
	return dp[n][W];
	
	ll ans;
	if(wts[n-1]<=W)
	{
		ans=max(val[n-1]+maxVal(wts,val,W-wts[n-1],n-1),maxVal(wts,val,W,n-1));
	}
	else
	{
		ans=maxVal(wts,val,W,n-1);
	}
	
	dp[n][W]=ans;
	return ans;
	
}

int main()
{
	ll n,W;
	cin>>n>>W;
	ll wts[n];
	ll val[n];
	
	for(ll i=0;i<n;i++)
	{
		cin>>wts[i];
		cin>>val[i];
	}
	memset(dp,-1,sizeof(dp));
	cout<<maxVal(wts,val,W,n);
}


Measured memory_bytes: 82508
import java.util.*;

class Main{

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

		int sum = 0;
		int N2 = N;
		int valLen = String.valueOf( N ).length();

		for(int i = 0; i<valLen; i++){
			sum += (N2%10);

			N2 /=10;
		}

		if(N%sum == 0)
			System.out.println("Yes");
		else
			System.out.println("No");
	}

}

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

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    vector<int> cnt(N+1);
    for (int i = 0; i < N; i++) {
        cnt[A[i]]++;
    }

    long long sum = 0;
    for (int i = 1; i <= N; i++) {
        long long n = cnt[i];
        sum += n * (n-1) / 2;
    }
    
    for (int i = 0; i < N; i++) {
        long long ans = sum - cnt[A[i]] + 1;
        cout << ans << endl;
    }
}

Measured memory_bytes: 4776
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var input_string = Console.ReadLine();
            if (N%2 == 0 && (input_string.Substring(0,N/2) == input_string.Substring(N/2)))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
const int INF = 1001001001;
signed main(){
	int n;cin >> n;
	vector<int> a(n);
	rep(i,n)cin >> a[i];
	reverse(a.begin(),a.end());
	vector<int> dp(n,INF);
	rep(i,n){
		*upper_bound(dp.begin(),dp.end(),a[i]) = a[i];
	}
	
	cout << lower_bound(dp.begin(),dp.end(),INF) - dp.begin() << endl;
	return 0;
}

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

int main(){
    int n, m; cin >> n >> m;
    vector<int> a(m), b(m);
    vector<ll> c(m,0);
    //cにbitとして宝箱の情報を入力
    int tmp;
    rep(i,m){
        cin >> a[i] >> b[i];
        rep(j,b[i]){
            cin >> tmp;
            tmp = (1<<(tmp-1));
            c[i] |= tmp;
        }
    }

    //dp初期化
    vector<ll> dp((1<<n),10000000);
    dp[0] = 0;
    rep(i,m) dp[c[i]] = a[i];

    //配るdp
    rep(i,(1<<n)) rep(j,m) dp[i|c[j]] = min(dp[i|c[j]], dp[i] + a[j]);

    //出力
    if(dp[dp.size()-1] == 10000000) cout << -1 << endl;
    else cout << dp[dp.size()-1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;
	cin>>t;
	map<char,int> x;
	for(char c='a';c<='z';++c)
		x[c];
	string s;
	vector<string> y;
	while(t--){
		cin>>s;
		y.push_back(s);
	}
	for(auto i:x){
		bool find=true;
		int ma=100;
		for(auto j:y){
			int cnt=0;
			for(auto k:j){
				if(k==i.first)
					++cnt;
			}
			if(cnt==0)
				find=false;
			else
				ma=min(ma,cnt);
		}
		if(find)
			x[i.first]=ma;
	}
	string ans;
	for(auto i:x){
		if(i.second)
			ans+=string(i.second,i.first);
	}
	cout<<ans;

}

Measured memory_bytes: 256
// OURL: https://atcoder.jp/contests/abc165/tasks/abc165_a
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define RREP(i,a,n) for(int i=(a),i##_len=(n);i<i##_len;++i)
#define MAT1D(V,T,a) vector<T> V (a)
#define MAT2D(V,T,a,b) vector<vector<T>> V (a, vector<T>(b))
#define MAT3D(V,T,a,b,c) vector<vector<vector<T>>> V (a, vector<vector<T>>(b, vector<T>(c)))

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));  }

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v);  }

template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", ";  } first = false; res += to_string(x);  } res += "}"; return res;  }

string to_string(string s) { return '"' + s + '"';  }
string to_string(const char* s) { return to_string((string) s);  }
string to_string(bool b) { return (b ? "true" : "false");  }
string to_string(vector<bool>::reference b) { return to_string(bool(b));  }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";  }
template <typename A>
string to_string(vector<vector<A>> v) { string res; for(const auto &x : v) {res+="\n ";res += to_string(x);} return res; }

void debug_out() { cerr << endl;  }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...);  }

#ifdef LOCAL
#define debug(...) cerr << "[L" << to_string(__LINE__) << ":" <<#__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

  int a,b,k;
  cin >> k >> a>> b;
  for (int i = a; i <= b; ++i) {
    if (i % k == 0) {
    cout << "OK" << endl;
    return 0;
    }
  }
    cout << "NG" << endl;

  return 0;
}


Measured memory_bytes: 3656
def sumitb2019_b
    n = gets.chomp.to_i
    m = n / 1.08

    if (m.floor*1.08).floor == n
        puts m.floor
    elsif (m.ceil*1.08).floor == n
        puts m.ceil
    else
        puts ':('
    end
end

sumitb2019_b

Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	ll n,a,b;cin >> n >> a >> b;
	vector<ll> v;
	REP(i,n)
	{
		ll tmp;cin >> tmp;v.PB(tmp);
	}
	
	ll ans = 0;
	REP(i,n-1)
	{
		ans += min(a*(v[i+1]-v[i]),b);
	}
	
	cout << ans << endl;
	
	
	return 0;
}


Measured memory_bytes: 1400
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = getLine >> getContents >>= print . length . group . sort . map ( read :: String -> Int ) . lines


Measured memory_bytes: 1020
import java.lang.Math

fun main(args: Array<String>)
{
    val (n) = readInts()
    val h = readInts()

    val a: MutableList<Int> = mutableListOf<Int>()
    for (i in n-1 downTo 1) {
        a.add(if (h[i-1] >= h[i]) 1 else 0)
    }
    a.add(0)

    val csum: MutableList<Int> = mutableListOf<Int>()
    csum.add(a[0])
    for (i in 0..n-2) {
        if (a[i+1] == 0) csum.add(0)
        else csum.add(csum[i] + a[i+1])
    }

    println(csum.max())
}

fun readInts(): List<Int> = readLine()!!.split(" ").map(String::toInt)
fun readLongs(): List<Long> = readLine()!!.split(" ").map(String::toLong)

fun readIntArr(): IntArray = readLine()!!.split(" ").map(String::toInt).toIntArray()
fun readLongArr(): LongArray = readLine()!!.split(" ").map(String::toLong).toLongArray()

fun readIntArrS(): IntArray = readLine()!!.split(" ").map(String::toInt).toIntArray().sortedArray()
fun readLongArrS(): LongArray = readLine()!!.split(" ").map(String::toLong).toLongArray().sortedArray()

fun readIntArrSD(): IntArray = readLine()!!.split(" ").map(String::toInt).toIntArray().sortedArrayDescending()
fun readLongArrSD(): LongArray = readLine()!!.split(" ").map(String::toLong).toLongArray().sortedArrayDescending()

fun readString() = readLine()!!


Measured memory_bytes: 72128
(* quite naive implementation *)
let rec dikjstra ( +. ) ( < ) q edge d =
  match q with
  | [] -> ()
  | u :: q ->
      let u, q = 
        List.fold_left (fun (u, q') u' ->
          if d.(u) < d.(u') then (u, u' :: q')
          else (u', u :: q')) (u, []) q in
      List.iter (fun (v, c) ->
        if c +. d.(u) < d.(v) then
          d.(v) <- c +. d.(u)) (edge u);
      dikjstra ( +. ) ( < ) q edge d

let array_of_string s = Array.init (String.length s) (fun i -> s.[i])

let () =
  let h, w = Scanf.scanf "%d %d\n" (fun h w -> h, w) in
  let ss = Array.init h (fun _ -> Scanf.scanf "%s\n" (fun s -> s)) in
  let dp = Array.make (h * w) infinity in
  dp.(0) <- 0.;
  dikjstra ( +. ) ( < )
    (Array.init (h * w) (fun i -> i)
      |> Array.to_list
      |> List.filter (fun i ->
        let x = i mod w in
        let y = i / w in
        ss.(y).[x] = '.'))
    (fun i ->
      let x = i mod w in
      let y = i / w in
      [(x + 1, y); (x - 1, y); (x, y + 1); (x, y - 1)]
      |> List.filter (fun (x, y) -> 0 <= x && x < w && 0 <= y && y < h)
      |> List.filter (fun (x, y) -> ss.(y).[x] = '.')
      |> List.map (fun (x, y) -> (y * w + x, 1.))) dp;
  if dp.(h * w - 1) = infinity then print_endline "-1"
  else begin
    Array.map array_of_string ss
    |> Array.map Array.to_list
    |> Array.map (List.filter (( = ) '.'))
    |> Array.map List.length
    |> Array.fold_left ( + ) 0
    |> (fun i -> i - int_of_float dp.(h * w - 1) - 1)
    |> Printf.printf "%d\n"
  end

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll a,b,c;
  cin>>a>>b>>c;
  if(a==b&&b==c){
    cout<<"No"<<endl;
    return 0;
  }
 if(a!=b&&b!=c&&a!=c){
   cout<<"No"<<endl;
   return 0;
 }
  cout<<"Yes"<<endl;
} 


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
int main(){
FASTIO	
int m,d;
cin>>m>>d;
int l=0;
for(int i=1;i<=m;i++){
	for(int j=22;j<=d;j++){
		int a=j/10;
		int b=j%10;
		if((a<2)||(b<2))
		  continue;
		if(a*b==i)
		  l++;
	}
}
cout<<l;
}

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

int main(){
    int n, k; cin >> n >> k;
    int c = (n-1)*(n-2)/2-k;
    if(c < 0) cout <<  -1 << endl;
    else{
        cout << c+(n-1) << endl;
        rep(i,n-1) cout << i << " " << n << endl; if(!c) return 0;
        for(int i=1; i<=n-1; i++) for(int j=i+1; j<=n-1; j++){
            cout << i << " " << j << endl;
            c--; if(!c) return 0;
        }
    }
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
using namespace std;
const int MAX_N = 60;

int main()
{
  int N,M;
  cin >> N >> M;
  // matrix
  // initialize with 0
  int A[MAX_N][MAX_N] = {};

  REP(i,0,M) {
    int a,b;
    cin >> a >> b;
    --a; --b;
    A[a][b]++;
    A[b][a]++;
  }

  // A の行和を出力
  REP(i,0,N) {
    int s = 0;
    REP(j,0,N) s += A[i][j];
    cout << s << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(input())

    if N == 0:
        print(0)
        return 

    res = ""
    T = 1
    t = 0
    while N != 0:
        if N % 2 == 1:
            res += "1"
            N -= 1
        else:
            res += "0"
        T *= -2
        N //= -2
        t += 1

    print(res[::-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 69124
#include <bits/stdc++.h>
using namespace std;
bool bigS(int a, int b)
{
	return a > b;
}
 
int main() {
  int M, N;
  cin >> N >> M;
  vector<int> data(N);
  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  sort(data.begin(), data.end(), bigS);
  

  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += data.at(i);
  }
  
  if (data.at(M - 1)*4*M < sum) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

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

int main() {
  int64_t N;
  cin >> N;
  int64_t min=N;
  for(int i=1; i<=sqrt(N); i++){
    if(N%i==0){
      if((N/i)+i-2 < min){
        min = (N/i)+i-2;
      }
    }
  }
  cout << min << endl;
}

// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));
 
  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
   // }
  //}


Measured memory_bytes: 256
#include <stdio.h>

void bubbleSort(double numbers[], int array_size)
{
  int i, j;double temp;

  for (i = 0; i < (array_size - 1); i++) {
    for (j = (array_size - 1); j > i; j--) {
      if (numbers[j-1] > numbers[j]) {
        temp = numbers[j-1];
        numbers[j-1] = numbers[j];
        numbers[j] = temp;
      }
    }
  }
}

int main()
{
    int n;
    double v[50];

    scanf("%d",&n);
    for (int i = 0; i < n; i++)
    {
        scanf("%lf",&v[i]);
    }

    bubbleSort(v,n);
    double r = v[0],ans = 0;
    for (int i = 1; i < n; i++)
    {
        r = (r + v[i]) / 2;
    }
    printf("%lf",r);
}


Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextLineValue() int {
  sc.Scan()
  return getInt(sc.Text())
}

func nextLineValues() []int {
  sc.Scan()
  return getIntArray(sc.Text())
}

func getInt(s string) int {
  v, _ := strconv.Atoi(s)
  return v
}

func getIntArray(s string) []int {
  var v []int
  valstr := strings.Split(s, " ")
  for _, c := range valstr {
    va, _ := strconv.Atoi(c)
    v = append(v, va)
  }
  return v
}

func digitTotal(v int) int {
  total := 0
  d := strings.Split(strconv.Itoa(v), "")
  for _, c := range d {
    dv, _ := strconv.Atoi(c)
    total += dv
  }
  return total
}

func sortDesc(v *[]int) {
  sort.Sort(sort.Reverse(sort.IntSlice(*v)))
}

func removeDupIntSlice(values *[]int) []int {
  m := make(map[int]bool)
  uniq := []int{}
  for _, v := range *values {
    if !m[v] {
      uniq = append(uniq, v)
      m[v] = true
    }
  }
  return uniq
}



func main() {
  nm := nextLineValues()

  answerString := make([]string, nm[0])
  for i:=0; i<nm[0]; i++ {
    answerString[i] = "*"
  }

  for i:=0; i<nm[1]; i++ {
    sc := nextLineValues()
    vstr := strconv.Itoa(sc[1])

    if answerString[sc[0]-1] != "*" && answerString[sc[0]-1] != vstr {
      fmt.Println("-1")
      return
    }
    answerString[sc[0]-1] = vstr
  }

  if len(answerString) > 1 && answerString[0] == "*" {
    answerString[0] = "1"
  } else if len(answerString) == 1 && answerString[0] == "*" {
    answerString[0] = "0"
  }

  for i:=1; i<nm[0]; i++ {
    if answerString[i] == "*" {
      answerString[i] = "0"
    }
  }

  if len(answerString) > 1 && answerString[0] == "0" {
    fmt.Println("-1")
    return
  }

  fmt.Println(strings.Join(answerString, ""))
}


Measured memory_bytes: 640
n = int(input())
nums = list(map(int, input().split()))
dp = [[0 for _ in range(n)] for _ in range(n)]

for i in range(n):
  dp[i][i] = nums[i]
  
for k in range(2, n+1):
  for l in range(n-k+1):
    r = l+k-1
    dp[l][r] = max(nums[l]-dp[l+1][r], nums[r] - dp[l][r-1])
    
print(dp[0][-1])

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

int main(){
  long long n;
  cin >> n;
  
  long long ans = 0;
  for(long long i = 1; i <= n; ++i){
    if(i % 3 == 0) continue;
    if(i % 5 == 0) continue;
    ans += i;
  }
   
  cout << ans << endl;
}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

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

lint dp[100005];

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

  int n, m;
  cin >> n >> m;
  vector<bool> a(n + 1, true);
  rep(i, m) {
    int x;
    cin >> x;
    a[x] = false;
  }

  vector<lint> dp(n + 1);
  dp[0] = 1;
  for (int now = 0; now < n; now++) {
    for (int next = now + 1; next <= min(n, now + 2); next++) {
      if (a[next]) {
        dp[next] += dp[now];
        dp[next] %= MOD;
      }
    }
  }
  cout << dp[n] << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	while(1){
		int n,m,ans=0,MAX=0;
		cin>>n>>m;
		vi d(n+1),w;
		if(n==0 && m==0) break;
		d[0]=0;
		rep(i,1,n+1) cin>>d[i];
		rep(i,0,n+1){
			rep(j,0,n+1){
				w.pb(d[i]+d[j]);
			}
		}
		sort(all(w));
		rep(i,0,w.size()){
			//vector<int>::iteratar it=upper_bound(all(w),m-w[i]);
			int p=upper_bound(all(w),m-w[i])-w.begin();
			if(p==0) continue;
			MAX=max(MAX,w[i]+w[p-1]);
		}
		o(MAX);
	}
}

Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n;cin>>n;
  vector<long long> a(n);
  for(int i=0; i<n; ++i) cin>>a[i];
  long long sum=0,cnt=0;
  for(int i=1; i<n; ++i) sum+=a[i];
  cnt+=a[0]%1000000007*(sum%1000000007);
  for(int i=1; i<n; ++i){
    sum-=a[i];
    cnt+=a[i]%1000000007*(sum%1000000007);
    cnt%=1000000007;
  }
  cnt%=1000000007;
  cout<<cnt<<endl;
  return 0;
}

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

int main() {
    ll n, allxor = 0;
    cin >> n;
    vector<ll> a(n);
    vector<vector<ll> > ls(62);
    for(int i=0;i<n;i++){
        cin >> a[i];
        allxor ^= a[i];
    }
    // bitの立っているa[i]の個数が奇数であるようなbitをおろす
    // そのようなbitは全体のxorでbitが立っている
    for(int i=0;i<n;i++){
        a[i] &= ~allxor;
    }
    // 掃き出し法
    // 独立なbitは自由にそのbitを上げ下げできる
    int rank = 0;
    for(int i=60;i>=0;i--){
        int k = -1;
        for(int j=rank;j<n;j++){
            if((a[j]>>i)&1){
                k = j;
                break;
            }
        }
        if(k == -1) continue;
        if(k != rank) a[rank] ^= a[k];
        for(int j=0;j<n;j++){
            if(j == rank) continue;
            a[j] = min(a[j], a[j]^a[rank]);
        }
        rank++;
    }
    ll ans = 0;
    // 上から立てられるbitを立てる
    for(int i=0;i<n;i++){
        ans = max(ans, ans^a[i]);
    }
    ans *= 2;
    ans += allxor;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

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

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

// Required random number generators

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    ll ans=-1;
    ll tot=7%N;
    FORI(i,1,INIT)
    {
        if(tot==0)
        {
            ans=i;
            break;
        }
        tot=((10*tot)+7)%N;
    }
    cout<<ans<<endl;

//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 3788
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
dxy = [abs(a - b) for a, b in zip(x, y)]
D = [sum([n ** p for n in dxy]) ** (1 / p) for p in range(1, 4)]
D.append(max(dxy))
for d in D:
    print("{:.5f}".format(d))


Measured memory_bytes: 5652
#include<bits/stdc++.h>
#define fread freopen("in.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)
#define PI acos(-1.0)
#define Mx 100005
#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
ios::sync_with_stdio(false);
cin.tie(0);
 int n, m, x;
 cin >> n >> m >> x;
 int mx = max(n, m);
 int ans = 0;
 ans = x /  mx;
 if(x % mx != 0) ans++;
 cout << ans << '\n';

   return 0;
 }





Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
    
        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M = map(int,input().split())
L = [[] for i in range(M)]
for i in range(M):
  L[i]=list(map(int,input().split()))

def chk(LL):
  uf = UnionFind(N)
  for l in LL:
    uf.union(l[0]-1, l[1]-1)
  return uf.group_count()

ret = 0
for i in range(M):
  LL = L[:]
  LL.pop(i)
  if chk(LL)>1:
    ret+=1
print(ret)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;


int main(){
    fast_io

    string s;
    cin>>s;
    string key = "keyence";
	if(s == key){
		puts("YES");
		return 0;
	}
	int n = s.size();
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			//delete [i,j]
			string S = "";
			for(int k=0;k<n;k++){
				if(i<=k && k<=j){
					continue;
				}
				else S.push_back(s[k]);
			}
			if(S == key){
				puts("YES");
				return 0;
			}
		}
	}
	puts("NO");
    
    return 0;
}


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

bool in(vector<int> p, int x){
    bool ans=false;
    for(int i=0;i<p.size();i++){
        if(x==p[i]) ans=true;
    }
    return ans;
}
int main(){
    int x,n;
    cin>>x>>n;
    if(n==0){
        cout<<x<<endl;
        return 0;
    }
    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    int k=0;
    while(true){
        if(!in(p,x-k)){
            cout<<x-k<<endl;
            return 0;
        }
        else if(!in(p,x+k)){
            cout<<x+k<<endl;
            return 0;
        }
        else k++;
    }
    
}

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

const int INF = 1<<30;

int dp[100010];
int h[100010];

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

	for(int i=0;i<100010;i++) dp[i]=INF;
	dp[0]=0;


	for(int i=0;i<n;i++){
		dp[i+1] = min(dp[i+1], dp[i]+abs(h[i+1]-h[i]));
		dp[i+2] = min(dp[i+2], dp[i]+abs(h[i+2]-h[i]));
	}

	cout<<dp[n-1]<<endl;


	return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
  public static void main(String[] args) {
	  FastReader sc = new FastReader();
	  String s = sc.next();
	  String t = sc.next();
	  long[] sCharCnt = new long[26];
	  long[] tCharCnt = new long[26];
	  
	  for (int i = 0; i < s.length(); i++) {
		  sCharCnt[s.charAt(i) - 'a']++;
		  tCharCnt[t.charAt(i) - 'a']++;
	  }
	  
	  Arrays.sort(sCharCnt);
	  Arrays.sort(tCharCnt);
	  
	  List<Long> sl = new ArrayList();
	  List<Long> tl = new ArrayList();
	  
	  for (int i = 0; i < sCharCnt.length; i++) {
		  if (sCharCnt[i] != 0) { sl.add(sCharCnt[i]); }
		  if (tCharCnt[i] != 0) { tl.add(tCharCnt[i]); }
	  }
	  
	  if (sl.size() != tl.size()) {
		  System.out.println("No");
		  System.exit(0);
	  } else {
		  for (int i = 0; i < sl.size(); i++) {
			  if (sl.get(i).intValue() != tl.get(i).intValue()) {
				  System.out.println("No");
				  System.exit(0);
			  }
		  }
	  }
	  System.out.println("Yes");
	  System.exit(0);
  }
  
  static class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }
  
    String next() { 
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException  e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() { 
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
        try{
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
      }
  }
}


Measured memory_bytes: 26120
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = []
    r = 0
    for i in range(N):
        r = A[i]
        B.append(r)
        for j in range(i+1, N):
            r += A[j]
            B.append(r)
    for i in range(40, -1, -1):
        n = []
        for k in B:
            if k & 2**i == 2**i:
                n.append(k)
        if len(n) >= K:
                break
    else:
        return 0
    c = n
    r = [i]
    for j in range(i-1, -1, -1):
        n = []
        for i in c:
            if i & 2**j == 2**j:
                n.append(i)
        if len(n) >= K:
            r.append(j)
            c = n
    return sum([2**i for i in r])
print(main())

        


Measured memory_bytes: 37788
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
#include<map>
#include<set>
using namespace std;

bool match(string s, string t) {
	if (s.length() != t.length()) return false;
	for (int i = 0; i < s.length(); i++) {
		if (!(s[i] == t[i] || s[i] == '?')) return false;
	}
	return true;
}
int main() {
	string s;
	string t;
	cin >> s >> t;
	string ans = s;
	bool rep = false;
	for (int i = s.length()-1; i >= 0; i--) {
		string sub = s.substr(i, t.length());
		if (match(sub, t)) {
			for (int j = 0; j < s.length(); j++) {
				if (j < i) {
					if (s[j] == '?') ans[j] = 'a';
					else ans[j] = s[j];
				}
				else if (j < i + t.length()) {
					ans[j] = t[j-i];
				}
				else {
					if (s[j] == '?') ans[j] = 'a';
				}
			}
			rep = true;
			break;
		}
	
	
	}
	if(rep)	cout << ans;
	else cout << "UNRESTORABLE";
	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
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 (a>b) { a=b; return true; } return false; }

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for(int i = 1; i < n; i++){
        set<char> s1, s2;
        for(int j = 0; j < i; j++){
            s1.insert(s[j]);
        }
        for(int k = i; k < n; k++){
            s2.insert(s[k]);
        }
        int sum = 0;
        for(auto ss : s1){
            if (s2.find(ss) != s2.end()) sum++;
        }
        ans = max(ans, sum);
    }
    cout << ans  << endl;
}

Measured memory_bytes: 3588
#include<stdio.h>

int main(void)
{
  double a, b;

  scanf("%lf", &a);
  scanf("%lf", &b);

  if(a > b){
    printf("GREATER\n");
  }else if(a < b){
    printf("LESS\n");
  }else{
    printf("EQUAL\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n); i >= 0; i--)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define REVSORT(c) SORT(c);REVERSE(c)
#define ALL(x) (x).begin(),(x).end()
const long long MOD = 1000000007;
typedef long long ll;

int string_count(string S, char a){
	int cnt = 0;
	for(int i = 0; i < S.length(); i++){
		if(S.at(i) == a)cnt++;
	}
	return cnt;
}

int main(){
	int N;
	cin >> N;
	vector<string> S(N);
	rep(i, N)cin >> S[i];
	
	vector<int> C(26, 100);
	
	for(int i = 0; i < N; i++){
		char Alp = 'a';
		for(int j = 0; j < 26; j++){
			int cnt = string_count(S[i], Alp);
			C[j] = min(C[j], cnt);
			Alp++;
		}
	}
	
	char A = 'a';
	for(int i = 0; i < 26; i++){
		for(int j = 0; j < C[i]; j++){
			cout << A;
		}
		A++;
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    int N, K;
    cin >> N;
    vector<int> A(N);
    cin >> K;
    REP (i, N) {
        cin >> A[i];
    }
    int prod = 1;
    FOR(i,K,N) {
        if (A[i-K] < A[i]) yes;
        else no;
    }
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/m-solutions2020/m_solutions2020_c && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/m-solutions2020/m_solutions2020_c && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/m-solutions2020/m_solutions2020_c && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 4780
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

int H, W, N;

int dfs(const int now, const int from,int dep,
	const vector<vector<int>>&edges, vector<int>&depths,
	vector<int>&lens) {
	depths[now]=dep;
	int alen=0;
	for (auto e : edges[now]) {
		if(e==from)continue;
		else {
			alen=max(alen,1+dfs(e,now,dep+1,edges,depths,lens));
		}
	}
	lens[now]=alen;
	return alen;
}

void dfs2(const int now, const int from, int pre,
	const vector<vector<int>>&edges, const vector<int>&lens,
	vector<int>&anss) {
	int ans=pre;
	map<int,int>mp;
	for (auto e : edges[now]) {
		if(e==from)continue;
		else {
			mp[lens[e]]++;
			ans=max(ans,lens[now]);
		}
	}
	anss[now]=ans;
	for (auto e : edges[now]) {
		if(e==from)continue;
		else {
			mp[lens[e]]--;
			if (mp[lens[e]]==0) {
				mp.erase(lens[e]);
			}
			auto it=max_element(mp.begin(),mp.end());
			int next_pre=(it!=mp.end())?(max(pre,it->first+1)+1):pre+1;
			dfs2(e,now,next_pre,edges,lens,anss);
			mp[lens[e]]++;
		}
	}
}
int main() {
	int N;cin>>N;
	vector<vector<int>>edges(N);
	vector<int>depths(N);
	vector<int>lens(N);
	for (int i = 0; i < N-1; ++i) {
		int a,b;cin>>a>>b;
		a--;b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	dfs(0,-1,0,edges,depths,lens);

	vector<int>anss(N);
	dfs2(0,-1,0,edges,lens,anss);
	for (int i = 0; i < N; ++i) {
		cout<<2*(N-1)-anss[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 34468
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
struct B
{
    int score;
    string city;
    int index;
    B(int a,const string &b, int c):score(a), city(b), index(c)
    {
        
    }
    B(){

    }
};
     bool customSort( B a, B b){
        if(a.city==b.city){
            return a.score>b.score;
        }
        return a.city.compare(b.city)<0;
        
    }


int main(){
    B* in;
    int max;
    scanf("%d", &max);
    in=new B[max];
    // printf("done");
    B test(0,"hi", 0);
    for(int count=0;count<max;count++){
        int a;
        char raw[11];
        scanf("%s %d", raw,&a);
        string b=raw;
        in[count]=B(a,b,count);
        // printf("done2");
    }
    sort(in, in+max, customSort);
    for(int count=0;count<max;count++){
        printf("%d\n", in[count].index+1);
    }
}

Measured memory_bytes: 256
solve :: Int -> Int -> Int
solve h w 
  | h == 1 || w == 1 = 1
  | otherwise =
    case (h `mod` 2 == 0, w `mod` 2 == 0) of
      (False, False) -> 
        let h1 = h `div` 2
            h2 = (h + 1) `div` 2
            w1 = w `div` 2
            w2 = (w + 1) `div` 2
        in
          h1 * w1 + h2 * w2
      (False, True) -> 
        (w `div` 2) * h
      (True, False) -> 
        (h `div` 2) * w
      (True, True) -> 
        (h `div` 2) * w


test :: IO ()
test = do
  print $ solve 7 11 == 4 * 6 + 3 * 5
  print $ solve 6 7 == 3 * 7
  print $ solve 7 6 == 3 * 7
  print $ solve 6 8 == 3 * 8
  print $ solve 1 1 == 1
  print $ solve 1 10 == 1
  print $ solve 3 1 == 1


main = do
  [h, w] <- map read . words <$> getLine
  print $ solve h w


Measured memory_bytes: 508
import heapq
N, K, C = map(int, input().split())
S=list(input())
cnt=0
index=0
dp=[0 for i in range(N)]
while index<N:
    if S[index]=="o":
        cnt+=1
        dp[index]=cnt
        index+=C+1
    else:
        index+=1
for i in range(1,N):
    dp[i]=max(dp[i],dp[i-1])
S=S[::-1]
dp_r=[0 for i in range(N)]
cnt=0
index=0
while index<N:
    if S[index]=="o":
        cnt+=1
        dp_r[index]=cnt
        index+=C+1
    else:
        index+=1
for i in range(1,N):
    dp_r[i]=max(dp_r[i],dp_r[i-1])
dp_r=dp_r[::-1]

ans=[]
S=S[::-1]
for i in range(N):
    if S[i]=="o":
        left=0
        if i-1>=0:
            left=dp[i-1]
        right=0
        if i+1<=N-1:
            right=dp_r[i+1]
        if left+right<K:
            print(i+1)
     
            

Measured memory_bytes: 114736
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
ll n,two[N],five[N],num[20][20],ans=0;
string s;
int main(){
	ll i,j,k;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>s;
		for(k=0;k<s.size();k++)
		{
			if(s[k]=='.')
			{
				break;
			}
		}
		if(k==s.size())
		{
			for(k=0;k<9;k++)
			{
				s+='0';
			}
		}
		else
		{
			for(k=s.size()-1-k;k<9;k++)
			{
				s+='0';
			}
		}
		j=0;
		for(k=0;k<s.size();k++)
		{
			if(s[k]!='.')
			{
				j=j*10+(s[k]-'0');
			}
		}
		//cout<<j<<endl;
		while(j%2==0)
		{
			j/=2;
			two[i]++;
		}
		while(j%5==0)
		{
			j/=5;
			five[i]++;
		}
		two[i]=min(two[i],(ll)18);
		five[i]=min(five[i],(ll)18);
	}
	for(i=0;i<n;i++)
	{
		num[two[i]][five[i]]++;
		//cout<<two[i]<<" "<<five[i]<<endl;
	}
	for(i=0;i<n;i++)
	{
		for(j=18-two[i];j<20;j++)
		{
			for(k=18-five[i];k<20;k++)
			{
				ans+=num[j][k];
			}
		}
		if(two[i]>=9&&five[i]>=9)
		{
			ans--;
		}
	}
	printf("%lld\n",ans/2);
	return 0;
}

Measured memory_bytes: 6844