akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define pb push_back

typedef long long ll;

ll dist[101][101];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            if(i == j){
                dist[i][j] = 0;
            }
            else{
                dist[i][j] = 10e6;
                dist[j][i] = 10e6;
            }
        }
    }
    int arr[m][3];
    for(int i = 0; i < m; i++){
        cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
        dist[arr[i][0]-1][arr[i][1]-1] = arr[i][2];
        dist[arr[i][1]-1][arr[i][0]-1] = arr[i][2];
    }
    for(int k = 0; k < n; k++)
    {
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < n; j++)
            {
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < m; i++){
        if(dist[arr[i][0]-1][arr[i][1]-1] < arr[i][2]){
            ans++;
        }
    }
    cout << ans;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] arr = new int[n + 1];
		Arrays.fill(arr, 1);
		boolean[] hasRed = new boolean[n + 1];
		hasRed[1] = true;
		for (int i = 0; i < m; i++) {
		    int from = sc.nextInt();
		    int to = sc.nextInt();
		    if (hasRed[from]) {
		        hasRed[to] = true;
		    }
		    arr[from]--;
		    arr[to]++;
		    if (arr[from] == 0) {
		        hasRed[from] = false;
		    }
		}
		int count = 0;
		for (int i = 1; i <= n; i++) {
		    if (hasRed[i]) {
		        count++;
		    }
		}
		System.out.println(count);
   }
}




Measured memory_bytes: 66248
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int i = 0;
    int ok = 0, ng = n;
    bool even_is_male = false;
    while (1) {
        if (i == 0) {
            cout << 0 << endl;
            string s;
            cin >> s;
            if (s == "Male") even_is_male = true;
            else if (s == "Vacant") return 0;
            i++;
        } else {
            int mid = (ok + ng) / 2;
            cout << mid << endl;
            string s;
            cin >> s;
            bool even = (mid % 2 == 0);
            if (s == "Male") {
                if (even and even_is_male) ok = mid;
                else if (even and !even_is_male) ng = mid;
                else if (!even and even_is_male) ng = mid;
                else if (!even and !even_is_male) ok = mid;
            } else if (s == "Female") {
                if (even and even_is_male) ng = mid;
                else if (even and !even_is_male) ok = mid;
                else if (!even and even_is_male) ok = mid;
                else if (!even and !even_is_male) ng = mid;
            } else {
                return 0;
            }
            i++;
        }
    }
}

Measured memory_bytes: 852
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;

string s;
int main(void){
    cin >> s;
    int N = s.length();
    REP(i, N/2){
        if(s[i] != s[N-i-1]){
            //cout << i << " " << N - i << " " << s[i] << " " << s[N-i] << endl;
            cout << "No" << endl;
            return 0;
        }
    }
    REP(i, (N-1)/4){
        if(s[i] != s[(N-1)/2-i-1]){
            //cout << i << " " << N - i << " " << s[i] << " " << s[N-i] << endl;
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i=(N+3)/2-1;i<N;i++){
        if(s[i] != s[N-i-1]){
            //cout << i << " " << N - i << " " << s[i] << " " << s[N-i] << endl;
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
max_n=10**5

dp=[-1]*max_n #dp[i-1]が足場iまでのコストの最小値
dp[0]=0
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
    res1=dp[i-1]+abs(h[i]-h[i-1]) #1ジャンプして足場iの時の最小値
    res2=dp[i-2]+abs(h[i]-h[i-2]) #2ジャンプして足場iの時の最小値
    dp[i]=min(res1,res2)

print(dp[n-1])

Measured memory_bytes: 13924
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll  long long int
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define f first
#define mp make_pair
#define s second
#define pb push_back
#define mod 1000000007


int main(){

	//freopen("input.txt", "r", stdin);
	ll n,m,k;cin>>n>>m>>k;;
	     ll x=n*m,y=n*k ,z=m*k;
         if(x<=y and x<=z){
         	  if(k%2)cout<<x;
         	  else cout<<"0";
         	  return 0;
         }
         if(y<=x and y<=z){
         	  if(m%2)cout<<y;
         	  else cout<<"0";
         	  return 0;
         }
         if(z<=y and z<=x){
         	  if(n%2)cout<<z;
         	  else cout<<"0";
         	  return 0;
         }

	}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, c float64
	var k int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&k)
	ary := []float64{a, b, c}
	maxI := 0
	for i := 1; i < len(ary); i++ {
		if ary[i] > ary[i-1] {
			maxI = i
		}
	}

	for i := 0; i < k; i++ {
		ary[maxI] *= 2
	}

	fmt.Printf("%d\n", int(ary[0])+int(ary[1])+int(ary[2]))
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
static const int MAX = 200000;

int main()
{
	string s;
	cin >> s;
	(s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]) ? cout << "Yes" << endl : cout << "No" << endl;

    return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

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

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n, m, x;
	cin >> n >> m >> x;
	vi a(m);
	rep(i, m) cin >> a[i];

	vi map(n+1, 0);
	rep(i, m) map[a[i]] = 1;
	int start = min(n, x);
	int goal = max(n, x);
	int ans1 = 0;
	for(int i = start; i <= goal; i++)
	{
		cerr << i << endl;
		ans1 += map[i];
	}
	int ans2 = 0;
	for(int i = 0; i <= x; i++)
	{
		ans2 += map[i];
	}

	cout << min(ans1, ans2) << endl;
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Char8 as B
import qualified Data.Maybe as Maybe
import qualified Data.Char as Char

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

main :: IO ()
main = do
    input <- getInput
    print (solve input)

getInput :: IO (Char, Char, Char)
getInput =
    runParser parser <$> B.getContents
    where
        parser = (,,) <$> parseChar <*> parseChar <*> parseChar

solve :: (Char, Char, Char) -> Int
solve (a, b, c) =
    f a + f b + f c
    where
        f '1' = 1
        f _   = 0

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

newtype Parser a =
    Parser (B.ByteString -> (a, B.ByteString))

instance Functor Parser where
    fmap f (Parser parser) =
        Parser $ \input ->
            let (v, remainder) = parser input in
                (f v, remainder)

instance Applicative Parser where
    pure v =
        Parser $ \input ->
            (v, input)

    (Parser parser1) <*> (Parser parser2) =
        Parser $ \input ->
            let
                (f, remainder1) = parser1 input
                (v, remainder2) = parser2 remainder1
            in
                (f v, remainder2)

consumeSpace :: Parser ()
consumeSpace =
    Parser $ \input ->
        ((), B.dropWhile Char.isSpace input)

lexeme :: Parser a -> Parser a
lexeme parser =
    consumeSpace *> parser

parseInt_ :: Parser Int
parseInt_ =
    Parser $ \input ->
        Maybe.fromJust (B.readInt input)

parseInt :: Parser Int
parseInt =
    lexeme parseInt_

parseChar :: Parser Char
parseChar =
    Parser $ \input ->
        Maybe.fromJust (B.uncons input)

runParser :: Parser a -> B.ByteString -> a
runParser (Parser parser) input =
    fst $ parser input

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


Measured memory_bytes: 380
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>


int main() {
    int k, x; std::cin >> k >> x;
    std::cout << (500 * k >= x ? "Yes" : "No") << std::endl;
    return 0;
}


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

int main() 
{
     int n,w=0,x,y,i,j,p=-1,q=-1;
    string s,t;
    cin>>s;
    cin>>t;
    x=s.length();
    y=t.length();
    int dp[x+1][y+1];
    for(i=0;i<=x;i++) for(j=0;j<=y;j++) dp[i][j]=0;
    for(i=0;i<=x;i++)
    {
        for(j=0;j<=y;j++)
        {
            if(i==0 || j==0) dp[i][j]=0;
            else if(s[i-1]==t[j-1]) dp[i][j]= 1+ dp[i-1][j-1];
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
            w=max(w,dp[i][j]);
        }
    }
    for(i=0;i<=x;i++)
    {
        for(j=0;j<=y;j++)
        {
            if(dp[i][j]==w)
            {
                p=i;
                q=j;
                break;
            }
            if(p!=-1) break;
        }
    }
    
    string ans="";
    while(p>=0 && q>=0)
    {
        if(s[p-1]==t[q-1] && dp[p][q]!=0)
        {
            ans+= s[p];
            dp[p][q]*=-1;
            p-=1;
            q-=1;
        }
        else
        {
            if(dp[p-1][q]==dp[p][q])
            {
                p-=1;
            }
            else
            {
                q-=1;
            }
        }
       /* if(p==0)
        {
            ans+=s[p];
            break;
        }
        else if(q==0)
        {
            ans+=t[q];
            break;
        }*/
    }
      
    /*for(i=w;i>=0;i--)
    {
        cout<<ans[i];
    }*/
    int af=0;
    for(i=0;i<=x;i++)
    {
        for(j=0;j<=y;j++)
        {
            if(dp[i][j]<0)
            {
                af=1;
                cout<<s[i-1];
            }
        }
       // cout<<endl;
    }
    if(af==0) cout<<" ";
//cout<<ans;
}


Measured memory_bytes: 35456
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int k, x;

    cin >> k >> x;

    if (k * 500 >= x)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>  // std::greater<T>()

using namespace std;

// macro
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define DESCEND greater<int>()  // sort 降順
#define UNIQUE(vec) (vec).erase(unique(ALL((vec))), (vec).end());  // 必ずsortを行なってから

// func declaration
template <class T> void printVec(vector<T>);
template <class T> void calcVec(vector<T>&, int, char);
bool checkMultiple(vector<int>&, int);

// const
const int INF = 10000000;

/*MEMO
辞書順
abc < abcd, atcoder < atlas
*/

int main() {
    string str;
    cin >> str;
    REP(i, str.size()) {
        if ((i+1)%2 != 0) {
            cout << str.at(i);
        }
    }
    cout << endl;

    return 0;
}


// function
template <class T> void printVec(vector<T> vec) {
    // 1要素ずつ、空白・改行なしで出力
    REP(i, vec.size()) {
        cout << vec.at(i);
    }
    cout << endl;
}

template <class T> void calcVec(vector<T> &vec, int num, char ch) {
    // vec全体への演算
    if (ch == '+') {
        REP(i, vec.size()) {
            vec.at(i) += num;
        }
    } else if (ch == '-') {
        REP(i, vec.size()) {
            vec.at(i) -= num;
        }
    } else if (ch == '*') {
        REP(i, vec.size()) {
            vec.at(i) *= num;
        }
    } else if (ch == '/'){
        REP(i, vec.size()) {
            vec.at(i) /= num;
        }
    } else if (ch == '%') {
        REP(i, vec.size()) {
            vec.at(i) %= num;
        }
    }
}

bool checkMultiple(vector<int> &vec, int num) {
    // vecの中身が、numの倍数かどうかのチェック
    int count = 0;
    REP(i, vec.size()) {
        if (vec.at(i)%num != 0) count++;
    }
    return (count == 0);
}


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

int main(){
  string oddStr,evenStr;
  cin >> oddStr >> evenStr;
  for(int i = 0; i < oddStr.size(); i++){
    cout << oddStr[i];
    if(i < evenStr.size()){
      cout << evenStr[i];
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
using namespace std;



int main(){
  long long N;
  int ans = 12;
  cin >> N;

  for(long long i = 1; i <= sqrt(N)+1; i++){
    if(N%i==0){
      ans=min((int)floor(log10(max(i, N/i))+1),ans);
    }
  }

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



Measured memory_bytes: 256
import java.util.Scanner;

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

		int min = Integer.MAX_VALUE;
		int answer = 0;
		for (int i = 0; i < N; i++) {
			P[i] = sc.nextInt();
			if (P[i] <= min) answer++;
			if (P[i] < min) min = P[i];
		}

		System.out.println(answer);
	}
}

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

class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;

        int n = Integer.parseInt(br.readLine());
        int a[] = new int[n];
        st = new StringTokenizer(br.readLine());
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(st.nextToken());
        }

        Arrays.sort(a);

        double d = a[0];
        for (int i = 1; i < n; i++) {
            d = (d + a[i]) / 2;
        }

        System.out.println(d);
    }
}


Measured memory_bytes: 23124
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.HashMap;
import java.util.ArrayList;

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

    static class DigitsMultiplication {
        long diff = Long.MAX_VALUE;
        long ansA;
        long ansB;

        static HashMap<Long, Long> primeFactorize(long x) {
            HashMap<Long, Long> result = new HashMap<>();
            for (long i = 2; i * i <= x; i++) {
                if (x % i != 0) {
                    continue;
                }
                long ex = 0;
                while (x % i == 0) {
                    ex++;
                    x /= i;
                }
                result.put(i, ex);
            }
            if (x != 1) {
                result.put(x, 1L);
            }
            return result;
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();

            HashMap<Long, Long> map = primeFactorize(n);
            List<Long> list = new ArrayList<>(map.keySet());
            List<Long> primes = new ArrayList<>();
            for (long key : list) {
                int limit = map.get(key).intValue();
                for (int i = 0; i < limit; i++) {
                    primes.add(key);
                }
            }

            dfs(primes, 0, 1, 1);

            int result = Math.max(
                    String.valueOf(ansA).length(),
                    String.valueOf(ansB).length()
            );
            out.println(result);
        }

        public void dfs(List<Long> list, int index, long a, long b) {
            if (index == list.size()) {
                if (Math.abs(a - b) < diff) {
                    diff = Math.abs(a - b);
                    ansA = a;
                    ansB = b;
                }
            } else {
                dfs(list, index + 1, a * list.get(index), b);
                dfs(list, index + 1, a, b * list.get(index));
            }
        }

    }
}



Measured memory_bytes: 36992
n, y = map(int, input().split())
for i in range(n+1):
  for j in range(n+1-i):
    if i*10000 + j*5000 + (n-i-j)*1000 == y:
      print(i, j, n-i-j)
      exit()

print("-1 -1 -1")

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

int N,M,Q,L[200009],R[200009],X[509][509],C[509][509];

int main() {
    cin>>N>>M>>Q;
    for(int i=1;i<=M;i++){
        cin>>L[i]>>R[i];
        X[L[i]][R[i]]++;
    }
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            C[i][j]=C[i][j-1]+X[i][j];
        }
    }
    for(int i=1;i<=Q;i++){
        int p,q;
        cin>>p>>q;
        int sum=0;
        for(int j=p;j<=q;j++) sum+=C[j][q]-C[j][p-1];
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 4480
n = int(input())
t,a = map(int, input().split())
h = list(map(int, input().split()))

temp=[]
for i in range(n):
    at = t - h[i] * 0.006
    t2 = a - at
    if t2 < 0: t2 *= -1
    temp.append(t2)

ans = 0
diff = 10000.0
for i in range(n):
    if temp[i] < diff:
        ans = i + 1
        diff = temp[i]

print(ans)



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

int main() {
  int n;
  cin>>n;

  double ans=0;
  for(int i=0;i<n;i++){
    double m;
    string t;
    cin>>m>>t;
    if(t=="JPY") ans += m;
    else ans += m*380000.0;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		int all = 0;
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] c = new int[N-1];
		
		ArrayList<Integer> CN = new ArrayList<>();
		
		int check, checkB = 0;
		checkB = sc.nextInt();
		
		for(int i = 0; i < N-1; i++) {
			check = sc.nextInt();
			if(checkB == (check-1)) {
				CN.add(checkB);
			}
			checkB = check;
		}
		
		for(int j = 0; j < N; j++) {
			all = all + sc.nextInt();
		}
		
		Collections.sort(CN);
		for(int k = 0; k < N-1; k++) {
			c[k] = sc.nextInt();
		}
		
		for(int l = 0; l < CN.size(); l++) {
			all = all + c[CN.get(l)-1];
		}
		
		System.out.println(all);
	}
}

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

class Rolling_Hash{
private:
  ll n;
  static constexpr ll base1=1007,base2=2009;
  static constexpr ll mod1=(1e9+7),mod2=(1e9+9);
  vector<ll> hash1,hash2,mpow1,mpow2;
public:
  Rolling_Hash(const string& s){
    n=s.size();
    hash1.assign(n+1,0);
    hash2.assign(n+1,0);
    mpow1.assign(n+1,1);
    mpow2.assign(n+1,1);
    for(ll i=0;i<n;++i){
      hash1[i+1] = (hash1[i]*base1+s[i])%mod1;
      hash2[i+1] = (hash2[i]*base2+s[i])%mod2;
      mpow1[i+1] = (mpow1[i]*base1)%mod1;
      mpow2[i+1] = (mpow2[i]*base2)%mod2;
    }
  }
  auto get(ll l,ll r){
    ll lefval = hash1[r]-hash1[l]*mpow1[r-l]%mod1;
    ll rigval = hash2[r]-hash2[l]*mpow2[r-l]%mod2;
    if(lefval<0)lefval+=mod1;
    if(rigval<0)rigval+=mod2;
    return make_pair(lefval,rigval);
  }
  auto get_LCP(ll a,ll b){
    ll len = min( n-a+1,n-b+1 );
    unsigned long long low=0,high=len;
    while( high-low>1 ){
      unsigned long long mid=(high+low)/2;
      if(get(a,a+mid)!=get(b,b+mid))high=mid;
      else low=mid;
    }
    return low;
  }
};

main(){

  ll n;
  string s;
  cin>>n>>s;

  Rolling_Hash rh(s);
  ll ans=0;
  rep(i,n){
    for(ll j=i+1;j<n;++j){
      ll lcp=rh.get_LCP(i,j);
      ans=max(ans,min(lcp,j-i));
    }
  }
  cout<<(ans)<<endl;

}


Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf = 1e9+7;

/*==================================================*/
const int MAX_N = 100010;

struct UnionFind {
    int par[MAX_N];    // 親ノードの番号
    int deph[MAX_N];   // ノードの深さ

    /* 上以外に持っておくデータ
    // 例)木であるかどうか(bool値)を持つ場合
    // bool istree[MAX_N];
    */

    UnionFind(int n) {
        fill(par, par + MAX_N, -1);
        for (int i = 0; i<n; i++) {
            par[i] = i;
            deph[i] = 0;

            /* 持っておくデータにおいて初期化が必要な場合
            // istree[i] = true;
            */
        }
    }

    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            /* 同じグループに属しているときの処理
            // istree = false;
            */
            return;
        }
        if (deph[x] < deph[y]) {
            par[x] = par[y];
            /* ルートをyとする時の処理
            */
        } else {
            par[y] = par[x];
            if (deph[x] == deph[y]) deph[x]++;
            /* ルートをxとする時の処理
            */
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

/*==================================================*/
int N, M;
int P[100010];
int ans;
int main() {
    cin>>N>>M;
    REP(i,0,N){
        cin>>P[i];
        P[i]--;
    }
    UnionFind uf(N);
    REP(i,0,M){
        int x,y;
        cin>>x>>y;
        x--;y--;
        uf.unite(x, y);
    }
    REP(i,0,N){
        if(uf.same(P[i], i)){
            ans++;
        }
    }
    p(ans);
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define Imax 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}
int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  int n,m;
  cin>>n>>m;
  vector<ll int> a(n);
  int hoge;
  cin>>hoge;
  rep(i,0,n){
    if(i==hoge-1){
      a[i]=0;
      cin>>hoge;
    }else{
      a[i]=-1;
    }
  }
  if(a[0]!=0) a[0]=1;
  if(a[1]!=0) a[1]=a[0]+1;
  rep(i,2,n){
    if(a[i]!=0){
      a[i]=a[i-1]+a[i-2];
    }
    a[i]=a[i]%MOD;
  }

  cout<<a[n-1];
    
  
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


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

int main(){
	int n,s;
	while(1){
		cin >> n >> s;
		if(!n) break;
		long long int dp[101][10][1001] = {};
		dp[0][0][0] = 1;
		dp[0][1][0] = 1;
		for(int i = 1;i <= 100;i++){
			for(int j = 0;j <= n;j++){
				for(int k = 0;k <= s;k++){
					if(k - i >= 0 && j >= 1) dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - i];
					else dp[i][j][k] = dp[i - 1][j][k];
				}
			}
		}
		cout << dp[100][n][s] << endl;
	}
	return 0;
}

Measured memory_bytes: 10972
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int n;
    cin>>n;
    vector<long long int> v(n);
    long long int minus_num = 0, abs_sum = 0,abs_min=linf;

    REP(i,n){
        cin>>v[i];
        abs_sum += abs(v[i]);
        if(v[i]<0){
            minus_num++;
        }
        abs_min = min(abs_min, abs(v[i]));
    }
    if(minus_num%2){
        abs_sum -= 2 * abs_min;
        
    }
    cout << abs_sum << endl;

    return 0;
}


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

template <typename T> T gcd(T m, T n) {
  T temp = 0;
  while(m % n != 0) {
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

template <typename T> T lcm(T m, T n) { return m * n / gcd(m, n); }

using ll = long long;

int main() {
  ll A, B;
  cin >> A >> B;
  cout << lcm(A, B) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int t1=scn.nextInt();
		int t2=scn.nextInt();
		if(n*t1<t2) {
			System.out.println(n*t1);
		}else {
			System.out.println(t2);
		}
	}

}


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

int main(){
  int n,m;
  cin >> n >> m;
  int k,p;
  int answer=0;
  vector<int> data_s(n);
  for(int i=0; i<m; i++){
    cin >> k;
    for(int j=0; j<k; j++){
      int s;
      cin >> s;
      s--;
      data_s.at(s) |= 1<<i;
    }
  }
  for(int i=0; i<m; i++){
    int x;
    cin >> x;
    p |= x<<i;
  }
  
  for(int s=0; s<(1<<n); s++){
    int t=0;
    for(int i=0; i<n; i++){
      if(s>>i&1){
        t ^= data_s.at(i);
      }
    }
    
    if(t==p){
      answer++;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include  <stdio.h>

int main(void)
{
    int c=0;
    char a[5],b[5];
    
    scanf("%s %s",&a,&b);
    
    for(int i=0;i<3;i++)
    {
        if(a[i] == b[i])
           c++;
    }
    printf("%d",c);
 
   
        
    
    
    return 0;
}

Measured memory_bytes: 1684
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <stack>
#include <list>

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,b,n) for(int i=b;i<n;i++)
#define SORT(c) sort(c.begin(), c.end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

const float PI = 3.1415926;
static const int INFTY = (1<<30);

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
  vector<int> c;
  
  rep(i, 3) {
    int t;
    cin >> t;
    c.push_back(t);
  }
  SORT(c);
  
  if(c[0] + c[1] == c[2])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
n,x = map(int,input().split())
l = list(map(int,input().split()))

cnt = 1
d = 0

for _ in range(n):

    if d+l[cnt-1] <= x:
        d = d+l[cnt-1]
        cnt += 1
        # print(d)
    else:
        break

print(cnt)

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

for i in range(len(a)):
    if a[i] == 0:
        print(0)
        exit()

ans = 1
for i in range(len(a)):
  ans *= a[i]
  if ans > 10**18:
    print(-1)
    exit()

print(ans)


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

using namespace std;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;
	int c1 = min({4 * q, 2 * h, s});
	int c2 = min({8 * q, 4 * h, 2 * s, d});
	cout << n / 2LL * c2 + (n & 1) * c1;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b+1;i++)
#define Per(i,b,a) for(int i=b;i>=a;i--)

char alpha[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

void dfs(string S,int n,int pos){
    if(n==0) cout<<S<<endl;
    else{
        for(int i=0;i<pos;i++){
            dfs(S+alpha[i],n-1,pos);
        }
        dfs(S+alpha[pos],n-1,pos+1);
    }
}

int main(){
    int N;
    cin>>N;
    string S;
    dfs(S,N,0);
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include "boost/multiprecision/cpp_int.hpp"
#define rep(i , n) for(int (i) = 0; (i) < (n); (i)++)
namespace mp = boost::multiprecision;


int main(){

    std::string first_col , reversed_first; std::cin >> first_col;
    reversed_first = first_col;
    std::reverse(reversed_first.begin() , reversed_first.end());
    std::string second_col , reversed_second; std::cin >> second_col;
    reversed_second = second_col;
    std::reverse(reversed_second.begin() , reversed_second.end());

    if(first_col == reversed_second && second_col == reversed_first)std::cout << "YES";
    else std::cout << "NO";

    system("pause");

    return 0;

}

Measured memory_bytes: 504
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <10; i++) {
		for (int j = 1; j < 10; j++) {
			if ((i * j) == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> T;
int h,w;
int dx[5]={1,0,-1,0,0};
int dy[5]={0,-1,0,1,0};
bool fail[5001][200][200]; //iターン目で兵士のいる可能性のある場所
int mincost[200][200];
deque<T> q;

int main()
{
	vector<string> mp;
	cin>>h>>w;
	for(int i=0;i<h;i++)
	{
		string s;
		cin>>s;
		mp.push_back(s);
	}
	bool ans=false;
	fill(fail[0][0],fail[5001][0],false);
	fill(mincost[0],mincost[200],1e8-1);
	//初期配置を定める
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(mp[i][j]=='$')
				fail[0][i][j]=true;
			if(mp[i][j]=='@')
			{
				q.push_back(T(0,P(i,j)));
				mincost[i][j]=0;
			}
		}
	}
	//兵士の移動パターンをすべて調べる
	for(int k=1;k<1001;k++)
	{
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				if(fail[k-1][i][j])
				{
					for(int l=0;l<5;l++)
					{
						int nx=i+dx[l];
						int ny=j+dy[l];
						if(nx>=0 && nx<h && ny>=0 && ny<w && mp[nx][ny]!='#')
							fail[k][nx][ny]=true;
					}
				}
			}
		}
	}
	// for(int i=0;i<h;i++)
	// {
	// 	for(int j=0;j<w;j++)
	// 	{
	// 		if(fail[1000][i][j])
	// 			cout<<'$';
	// 		else
	// 			cout<<mp[i][j];
	// 	}
	// 	cout<<endl;
	// }
	//BFS
	while(!q.empty())
	{
		T t=q.front();q.pop_front();
		P p=t.second;
		if(t.first==1000)
			continue;
		if(mp[p.first][p.second]=='%')
		{
			ans=true;
			break;
		}
		for(int i=0;i<4;i++)
		{
			int nx=p.first+dx[i];
			int ny=p.second+dy[i];
			if(nx>=0 && nx<h && ny>=0 && ny<w && mp[nx][ny]!='#')
			{
				if(!fail[t.first+1][nx][ny] && mincost[nx][ny]==1e8-1)
				{
					q.push_back(T(t.first+1,P(nx,ny)));
					mincost[nx][ny]=t.first+1;
				}
			}
		}
	}
	if(ans)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 198716
#include <bits/stdc++.h>
using namespace std;
int dp[3001][3001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   string a,b;
   cin>>a>>b;
   int i,j,k,l;
      k=a.size();
  l=b.size();
  if(k<l)
  {
      swap(a,b);
      swap(k,l);
  }
   for(i=1;i<=a.size();i++)
   {
       for(j=1;j<=b.size();j++)
       {
           if(a[i-1]==b[j-1])
           dp[i][j]=dp[i-1][j-1]+1;
           else
           dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
       }
   }
 
   string p="";
   
  while(k>0 && l>0)
  {
      if(dp[k][l]==(dp[k-1][l-1]+1) && a[k-1]==b[l-1])
      {
          p=p+a[k-1];
          k--;
          l--;
      }
      else
      {
          if(dp[k-1][l]>dp[k][l-1])
          {
              k--;
          }
          else
          l--;
         
      }
      
  }
 reverse(p.begin(),p.end());
 cout<<p;
}

Measured memory_bytes: 35584
import sys
from operator import itemgetter

sys.setrecursionlimit(200000)


def dfs(u, prev):
    global post_order, pre_order

    pre_order.append((u, prev))
    for w, t in edges[u]:
        if t != prev:
            dfs(t, u)
    post_order.append(u)


n = int(input())
edges = [set() for _ in range(n)]

for _ in range(n - 1):
    s, t, w = map(int, input().split())
    edges[s].add((w, t))
    edges[t].add((w, s))

post_order, pre_order = [], []
farthest = [{} for _ in range(n)]
height = [0] * n

if n > 1:
    dfs(0, None)

for i in post_order:
    for w, t in edges[i]:
        farthest[i][t] = w + max((d for tt, d in farthest[t].items() if tt != i), default=0)
for i, parent in pre_order:
    sorted_farthest = sorted(farthest[i].items(), key=itemgetter(1))
    max_t, max_d = sorted_farthest.pop()
    height[i] = max_d
    for w, t in edges[i]:
        if t == parent:
            continue
        farthest[t][i] = w + ((max_d if t != max_t else sorted_farthest[-1][1]) if sorted_farthest else 0)
for h in height:
    print(h)

Measured memory_bytes: 25024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		
		int ans = a+a*a+a*a*a;
		
		System.out.print(ans);
	}

}


Measured memory_bytes: 35852
N = int(input())
A = [i for i in map(int, input().split())]

print(' '.join(map(str, A)))

for i in range(1, N):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(' '.join(map(str, A)))



Measured memory_bytes: 5608
N = input()
H = list(map(int, input().split() ) )

count = 0
step = [0]*len(H)

for i in range(len(H)-1):
    if H[i]>=H[i+1]:
        count += 1
    else:
        count = 0
    step[i+1] = count

print(max(step))

Measured memory_bytes: 63984
#include <iostream>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;

const long MOD = 1000000007;

// mのn乗を求める
long power(int m, int n){
    long ret = 1;
    long t = 0; 
    long p = m;
    while(n != 0){
        if((n >> t)&1 == 1){
            ret = ret * p % MOD;
            n ^= 1<<t;
        }
        t++;
        p = p * p % MOD;
    }
    return ret;
}

int main(){

    int N;
    cin >> N;

    long A[N];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    sort(A, A+N);

    map<int, int> m;
    map<int, int> p[N];
    for(int i=0; i<N; i++){
        int t = A[i];
        for(int j=2; j<=sqrt(A[i]); j++){
            int cnt = 0;
            while(t % j == 0){
                cnt++;
                t /= j;
            }
            if(cnt == 0) continue;
            if(m.count(j) == 0) m[j] = cnt;
            else m[j] = max(cnt, m[j]);
            p[i][j] = cnt;
            // cout << A[i] << " " <<  j << " " << cnt << endl;
        }
        if(t != 1){
            if(m.count(t) == 0) m[t] = 1;
            else m[t] = max(1, m[t]);
            p[i][t] = 1;
        }
    }

    long ans = 0;
    for(int i=0; i<N; i++){
        long add = 1;
        for(auto it=m.begin(); it!=m.end(); it++){
            int t = A[i];
            int div = it->first;
            int cnt = 0;
            if(p[i].count(div)) cnt = p[i][div];
            add = add*power(div, it->second-cnt)%MOD;
        }
        ans += add;
        ans = ans % MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for(int i = 0; i < (int)c; i++)

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

  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2,
               2, 1, 5, 1, 2, 1, 14, 1, 5,
               1, 5, 2, 2, 1, 15, 2, 2, 5,
               4, 1, 4, 1, 51};

  int n; cin >> n;
  cout << a[n - 1];






}


Measured memory_bytes: 256
from sys import stdin

Sp = stdin.readline().rstrip()
T =  stdin.readline().rstrip()


N = len(Sp)
M = len(T)

def check_feasibility(S, T, i):
    S_temp = S[i:i+M]
    index=0
    for j in range(M):
        if S_temp[j]=="?" or S_temp[j]==T[j]:
            index+=1
            continue
        else:
            break
    if index==len(T):
        return 1
    else:
        return 0

pos=-1
for i in range(N-M+1):
    is_ok = check_feasibility(Sp, T, i)
    if is_ok:
        pos=i
        
if pos==-1:
    print("UNRESTORABLE")
else:
    new_s = Sp[:pos] + T + Sp[pos+M:]
    new_s = new_s.replace("?","a")
    print(new_s)

Measured memory_bytes: 38384
package main

import (
	"fmt"
)

type Data struct {
	x int
	y int
}

func main(){
	var data Data
	var s[] Data
	
	for {
		fmt.Scan(&data.x, &data.y)
		s = append(s, data)
		if data.x == 0 && data.y == 0 {
			s = s[:len(s) - 1]
			break;
		} 
	}

	for _, v := range s {
		if v.x < v.y {
			fmt.Println(v.x, v.y)
		}else {
			fmt.Println(v.y, v.x)
		}
	}
}


Measured memory_bytes: 1376
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int a,b,c;
  cin >> a >> b;
  if(a%3==0 || b%3==0 || (a+b)%3==0){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

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

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

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

    llong N;
    cin >> N;

    vector<double> prob(N);
    FOR(i, N) {
        cin >> prob[i];
    }

    vector<vector<double>> dp(N + 1, vector<double>(N + 1, 0));  // dp[i][count]
    dp[0][0] = 1;

    FOR(i, N) {
        FOR(count, N + 1) {
            if(count == 0) {
                dp[i + 1][count] = dp[i][count] * (1 - prob[i]);
            } else {
                dp[i + 1][count] = dp[i][count] * (1 - prob[i]) + dp[i][count - 1] * prob[i];
            }
        }
    }

    double ans = 0;
    FORS(count, N / 2 + 1, N + 1) {
        ans += dp[N][count];
    }

    printf("%.16f\n", ans);

    return 0;
}

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template<typename T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template<typename... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}


int main() {
	int N; cin >> N;
	V<V<ll>> a(N,V<ll>(N));
	REP(i,N) REP(j,N) cin >> a[i][j];
	V<ll> cost(1<<N);
	for(int i = 0; i < (1<<N); ++i){
		for(int j = 0; j < N; ++j){
			for(int k = j + 1; k < N; ++k){
				if((i & (1<<j)) && (i & (1<<k))) cost[i] += a[j][k]; 
			}
		}
	}
	auto dp = cost;
	for(int i = 0; i < (1<<N) - 1; ++i){
      int j=0;
      for(int k=0;k<N;++k)if(!(i&(1<<k)))j^=(1<<k);
      for(int k=j;0<k;k=((k-1)&j)){
      
        chmax(dp[i ^ k], dp[i] + dp[k]);
	}
    }
	cout << dp[(1<<N) - 1] << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  if(100 <= N && N <= 111) cout << 111;
  else if(112 <= N && N <= 222) cout << 222;
  else if(223 <= N && N <= 333) cout << 333;
  else if(334 <= N && N <= 444) cout << 444;
  else if(445 <= N && N <= 555) cout << 555;
  else if(556 <= N && N <= 666) cout << 666;
  else if(667 <= N && N <= 777) cout << 777;
  else if(778 <= N && N <= 888) cout << 888;
  else cout << 999;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  double total=0;
  cin >> N;
  vector<double> x(N);
  vector<string> u(N);
  for(int i=0;i<N;i++){
    cin >> x.at(i);
    cin >> u.at(i);
  }
  for(int i=0;i<N;i++){
    if(u.at(i)=="JPY"){
      total+=x.at(i);
    }
    else{
      total+=x.at(i)*380000.0;
    }
  }
  cout << total <<endl;
}
  

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

int main(){
	int n, a, b, i, j, ans=0, sum;
	cin>>n>>a>>b;
	for(i=1; i<=n; i++){
		sum=0;
		j=i;
		for(;;){
			if(j==0) break;
			sum+=j%10;
			j/=10;
		}
		if(sum>=a && sum<=b) ans+=i;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
<?php
  fscanf(STDIN,"%d%d%d", $n,$m,$x);

  for($i=0; $i<$n; $i++){
    $ca[$i] = explode(" ",trim(fgets(STDIN)));
  }
  $f = false;
  $mon = 99999999999;
  for($i=0; $i< 1<<$n; $i++){
    $skill = array_fill(0, $m+1, 0);
    for($j=0; $j<$n; $j++){
      if($i>>$j & 1){
        foreach($ca[$j] as $key => $data){
          $skill[$key] += $data;
        }
      }
      $flag = true;
      //print_r($skill);
      for($k=1; $k<=$m; $k++){
        if($skill[$k] < $x){
          $flag = false;
        }
      }
      
      if($flag){
        $f = true;
        $mon = min($mon,$skill[0]);
      }
    }
  }

  echo $f ? $mon : "-1";

Measured memory_bytes: 16104