akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define FOR(i,n) for(int i = 0; i < n; i++)
#define FORa(i,a,b) for(int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a,n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define UP(s) transform(s.begin(),s.end(),s.begin(),::toupper)

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

int main() {
	unsigned ll m = 1;
	int n;
	bool flag1 = false, flag2 = false;
	cin >> n;
	
	vector<unsigned ll> v(n);
	FOR(i, n) cin >> v[i];
	
	FOR(i,n) {
		if(v[i] == 0) flag1 = true;
	}
	
	for(int i = 0; i < n && !flag1; i++) {
		if(v[i] <= 1000000000000000000/m) m *= v[i];
		else {
			flag2 = true;
			break;
		}
	}
	
	if(flag1) cout << "0" << endl;
	else if(flag2) cout << "-1" << endl;
	else cout << m << endl;
	
	return 0;
}



Measured memory_bytes: 4028
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

#define int long long

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

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

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

template <typename T> T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T> T lcm(T m, T n) { return n * m / gcd(n, m); }

signed main(void)
{
  int num;
  int N, T; cin >> N >> T;
  vector<int> t(N);

  num = 0;
  for (int i = 0; i < N; ++i) {
    cin >> t[i];
    if (i != 0) {
      int d = t[i] - t[i - 1];
      if (d <= T) num += d;
      else num += T;
    }
  }
  num += T;

  cout << num << endl;
}


Measured memory_bytes: 1792
N , T = map(int, input().split())
l_c = []

for i in range(N):
    c, t = map(int, input().split())
    if t <= T:
        l_c.append(c)

for j in range(len(l_c)):
    if l_c[j] == min(l_c):
        print(l_c[j])
        exit()

print('TLE')

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int N, M;
vector<int> a(55), b(55);
vector<vector<bool>> G(55, vector<bool>(55, false));
vector<bool> visited(55, false);

void dfs(int v){
    visited[v] = true;
    rep(v2, N){
        if(visited[v2] || !G[v][v2]) continue; 
        dfs(v2);
    }
}

int main(){
    cin >> N >> M;
    rep(i, M){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        G[a[i]][b[i]] = G[b[i]][a[i]] = true;
    }

    int ans = 0;

    rep(i, M){
        G[a[i]][b[i]] = G[b[i]][a[i]] = false;
        rep(j, N) visited[j] = false;

        dfs(0);

        bool flag = false;
        rep(j, N){
            if(!visited[j]){
                flag = true;
                break;
            }
        }
        if(flag) ans++;

        G[a[i]][b[i]] = G[b[i]][a[i]] = true;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
public static void main(String[]srgs) {
	Scanner scan=new Scanner(System.in);
	String a=scan.next();
	String alfa[]= {"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"};
	int ans=0;
	for(int i=0;i!=alfa.length;i++) {
		if(a.indexOf(alfa[i])==-1) {
			System.out.println(alfa[i]);
			return;
		}
	}
	System.out.println("None");
	scan.close();
}
}

Measured memory_bytes: 25300
package main

import (
	"fmt"
	"os"
	"strings"
)

func main() {
	kisuu := map[string]int{
		"R": 1,
		"U": 1,
		"D": 1,
	}
	gusuu := map[string]int{
		"L": 1,
		"U": 1,
		"D": 1,
	}

	var a string
	fmt.Scan(&a)
	strs := strings.Split(a, "")
	for i := 0; i < len(strs); i++ {
		if i%2 == 1 {
			if _, ok := gusuu[strs[i]]; !ok {
				fmt.Printf("No")
				os.Exit(0)
			}
		} else {
			if _, ok := kisuu[strs[i]]; !ok {
				fmt.Printf("No")
				os.Exit(0)
			}
		}
	}
	fmt.Println("Yes")

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    int n;
    while(cin>>n){
      cout<<fixed<<setprecision(9)<<(n-n/2)/ld(n)<<endl;

    }
  return 0;
}




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

int main() {
    int n;
    cin >> n;
    vector<float> v(n);
    for(auto& e : v) cin >> e;
    sort(begin(v), end(v));
    float res = v[0];
    for(int i = 1;i < n;i++){
        res = (res + v[i]) / 2;
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

int n;
bool possible = false;

int main () {

    cin >> n;
    for (int i = 1; i <= 9; i++){
        if (n % i  == 0){
            int q = n / i;
            if (q < 10){
                possible = true;
                break;
            }
            else {
                possible = false;
            }
        }
        else {
            possible = false;
        }
    }

    if (possible == true){
        cout << "Yes" << "\n";
    }
    if (possible == false){
        cout << "No" << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n)cin >> a[i];
	sort(ALL(a));
	//rep(i,n)cout<<a[i]<<endl;
	vector<int> b(100005);
	rep(i,n)b[a[i]]++;
	rep(i,100005)
	{
		if(b[i]>2)
		{
			if(b[i]%2==1)
			{
				b[i]=1;
			}
			else
			{
				b[i]= 2;
			}
		}
	}
	int cnt = 0;
	rep(i,100005)
	{
		if(b[i]==2)cnt++;
	}
	int ans = 0;
	rep(i,100005)if(b[i])ans++;
	if(cnt%2==1)ans-=1;
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n;
	cin >> n;
	int p = 1;
	while(p*2 <= n) p*=2;
	cout << p << endl;
	return 0;
}

Measured memory_bytes: 256
<?php
$d=trim(fgets(STDIN));//365
$c=explode(" ",trim(fgets(STDIN)));
$i=0;
while($i<$d){
  $s[$i]=explode(" ",trim(fgets(STDIN)));
  //$v=max($s[$i]);
  //$k=array_keys($s[$i],$v);
  //echo $k[0]+1 . "\n";
  ++$i;
}
$i=1;
$l=array_fill(0,26,0);
$ans=0;
while($i<=$d){
  $t=trim(fgets(STDIN));
  $l[$t-1]=$i;
  $ans+=$s[$i-1][$t-1];
  $j=0;
  while($j<26){
    $ans-=$c[$j]*($i-$l[$j]);
    ++$j;
  }
  echo "$ans\n";
  ++$i;
}

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int n, m; cin >> n >> m;
        priority_queue<int> u, v;
        for (int i = 0; i < n; i++) {
               int x; cin >> x;
               u.emplace(x);
        }

        vector<pair<int,int>> b(m);
        for (int i = 0; i < m; i++) cin >> b[i].second >> b[i].first;
        sort(all(b), greater<>());
        for (int i = 0; i < m; i++) {
                for (int j = 0; j < b[i].second; j++) {
                        if (v.size() < n) v.emplace(b[i].first);
                        else break;
                }
        }


        while (v.size()) {
                u.emplace(v.top());
                v.pop();
        }

        ll ans = 0;
        while (n--) {
                ans += u.top();
                u.pop();
        }

        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 5440
#include <bits/stdc++.h>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int,int>pii;
string s,t;
int main(){
	cin>>s>>t;
	if(s.size()!=t.size()){
		cout<<"No\n";
		return 0;
	}
	if(s==t){
		cout<<"Yes\n";
		return 0;
	}
	for(int i=1;i<=s.size();i++){
		char ch=s.back();
		s.pop_back();
		s=ch+s;
		if(s==t){
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int[][] a=new int[n+1][3];
		for (int i=1;i<=n;++i)
			for (int j=0;j<3;++j)
				a[i][j]=in.nextInt();
		int[][] dp=new int[n+1][3];
		for (int i=1;i<=n;++i)
			for (int j=0;j<3;++j)
				for (int k=0;k<3;++k) if (k!=j)
					dp[i][j]=Math.max(dp[i][j],dp[i-1][k]+a[i][k]);
		int res=0;
		for (int i=0;i<3;++i) res=Math.max(res,dp[n][i]);
		System.out.println(res);
	}
}

Measured memory_bytes: 98164
N = int(input())
H = list(map(int,input().split()))
DP = [0]*(N+1)  #DP[i]に来るための最小コスト
def dH(i,j):
  return abs(H[i-1] - H[j-1])
DP[2] = dH(1,2)
for i in range(3,N+1):
  DP[i] = min( DP[i-2] + dH(i-2, i) , DP[i-1] + dH(i-1, i) )
print(DP[N])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  int N; cin >> N;
  vector<int> A(N),B(N);
  rep(i,N) cin >> A[i];

  ll ans = 1;

  rep(i,N) {
    if (A[i] == 0) {
      ans = ans * (3 - B[0]) % MOD;
      B[0]++;
    } else {
      ans = ans * (B[A[i]-1] - B[A[i]]) % MOD;
      B[A[i]]++;
    }
  }

  cout << ans << endl;
}

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

int main()
{
	   int a;
	   int b;
	   int c;
	   cin >> a;
	   cin >> b;
	   cin >> c;
	   
	   if (a < b && b < c){
		   cout << "Yes" << endl;
		   }
	   else{
		   cout << "No" << endl;
		   }
	  
	}

Measured memory_bytes: 3088
def check(x):
    a, b = 0, 0
    for ball in x:
        if a < ball:
             a = ball
        elif b < ball:
             b = ball
        else:
             return False
    return True

n = int(raw_input())
for i in range(n):
    all = map(int, raw_input().split())
    print "YES" if check(all) else "NO"

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

using LL = long long;
constexpr int N = 1e5 + 5;
constexpr int MOD = 1e9 + 7;

LL qpow(int x, int y){
    LL ans = 1;
    while (y){
        if (y & 1) ans = 1LL * ans * x % MOD;
        y >>= 1;
        x = 1LL * x * x % MOD;
    }
    return ans;
}

LL n, k, x[N];
int main(){
    cin >> n >> k;
    LL ans = 0;
    for (int i = k; i >= 1; -- i){
        x[i] = qpow(k / i, n);
        for (int j = 2 * i; j <= k; j += i) x[i] -= x[j];
        ans = (ans + (1LL * i * x[i]) % MOD)%MOD;
    }
    cout << (ans + MOD) % MOD << endl;
    return 0;
}


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

int main()
{
	int a,b;
	cin>>a>>b;
	if(a>=13)
		cout<<b<<endl;
	else if(a<13 && a>5)
		cout<<b/2<<endl;
	else
		cout<<"0"<<endl;

}			

Measured memory_bytes: 256
from collections import deque 
n = int(input())
d = deque()
l=[]
for i in range(n):
  a = int(input())
  l.append(a)
l.sort()
l = deque(l)
flag=0
flag1=0
q = l.popleft()
d.append(q)
while l:
  a =abs(d[0]-l[0])
  b = abs(d[0]-l[-1])
  c = abs(d[-1]-l[-1])
  d1 = abs(d[-1]-l[0])
  m = max(a,b,c,d1)
  if a==m:
    f = l.popleft()
    d.appendleft(f)
  elif b==m:
    f = l.pop()
    d.appendleft(f)
  elif c==m:
    f = l.pop()
    d.append(f)
  elif d1==m:
    f = l.popleft()
    d.append(f)
ans = 0
for i in range(n-1):
  ans+=abs(d[i+1]-d[i])
print(ans)

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

#define DEBUG 0
#define NINF -1
#define PINF 1E9+1

char s[256];

int main(void)
{
	int i,iy,im,id;
	char y[16],m[16],d[16];
	scanf("%s",s);

	snprintf(y,16,"%c%c%c%c",s[0],s[1],s[2],s[3]);
	snprintf(m,16,"%c%c",s[5],s[6]);
	snprintf(d,16,"%c%c",s[8],s[9]);
	
	iy = atoi(y);
	im = atoi(m);
	id = atoi(d);

	if (iy>=2020) {
		printf("TBD\n");
		return 0;
	 } else if (iy==2019 && im>=5) {
			printf("TBD\n");
			return 0;
		}
	
	printf("Heisei\n");
	
	return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 20:59:16 2019

@author: doppe
"""

N, M = map(int, input().split())
likeList = []

for i in range(0, N):
    L = [int(i) for i in input().split()]
    likeListTmp = []
    if (i == 0):
        likeList = L[1 : L[0] + 1]
    else:
        for j in range(1, L[0] + 1):
            if (L[j] in likeList):
                likeListTmp.append(L[j])
        likeList = likeListTmp

print(len(likeList))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i, ans = 0;
    cin >> n;
    map <string, ll> m;
    for(i = 0; i < n; i++)
    {
        string t;
        cin >> t;
        sort(all(t));
        m[t]++;
    }
    for(auto x : m)
        ans += x.S * (x.S - 1) / 2;
    cout << ans << endl;
    return 0;
}

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

int main(){
  ll n; cin>>n;
 double x,ans=0,bit=0;
  string u;
  rep(i,n){
  cin>>x>>u;
    if(u=="BTC") bit+=x;
    else ans+=x;
  }
  cout << fixed << setprecision(6);
  cout<<ans+bit*380000<<endl;
}

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

vector<int> divs(int n){
    vector<int> ret;
    for(int i = 1; i*i <= n; i++){
        if(!(n%i)){
            ret.push_back(i);
            if(n != i*i)
                ret.push_back(n/i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

int main()
{
    int x; cin >> x;
    int a, b;
    for(int y : divs(x)){
        a = (y+1)/2;
        b = a-y;

        while(pow(a, 5) - pow(b, 5) <= x){
            if(pow(a, 5) - pow(b, 5) == x){
                cout << a << " " << b << endl;
                return 0;
            }
            a++, b++;
        }
    }
    return 0;
}

Measured memory_bytes: 3964
N = int(input())
inputs = input().split()
p = [int(n) for n in inputs]
ans = [x for x in range(1, N+1)]
count = 0
result = 'YES'

for i in range(N):
    if p[i] != ans[i]:
        count += 1

if count > 2:
    result = 'NO'

print(result)

Measured memory_bytes: 3064
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	string s; cin >> s;
	REP(i,s.size()){
		if(i%2 == 0) cout << s[i];
	}
	cout << endl;

	return 0;

}


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

int main(){
  int x;
  int n;
  cin >> x >> n;
  if(n==0){
    cout << x << endl;
    return 0;
  }
  int p[n];
  int h[n];
  for(int i=0; i<n; i++){
    cin >> p[i];
    h[i]=x-p[i];
    if(h[i]<0){
      h[i]=h[i]*-1;
    }
  }
  int check;
  int m;
  int k;
  for(int i=0; i<=50; i++){
    check=0;
    for(int j=0; j<n; j++){
      if(i==h[j]){
	check++;
	k=p[j];
      }
    }
    if(check==0 && i==0){
      m=i;
      break;
    }
    if(check<=1 && i!=0){
      m=i;
      break;
    }
  }
  if(x-m!=k){
    cout << x-m << endl;
  } else {
    cout << x+m << endl;
  }
}


Measured memory_bytes: 3636
n, a, b, c = gets.chomp.split.map(&:to_i)
l = []
n.times do
  l.push(gets.chomp.to_i)
end

mp = 10 ** 9
['A', 'B', 'C', 'x'].repeated_permutation(n) do |arr|
  tmp = 0
  aa = 0
  bb = 0
  cc = 0
  arr.each_with_index do |type, index|
    case type
    when 'A'
      if aa != 0
        tmp += 10
      end
      aa += l[index]
    when 'B'
      if bb != 0
        tmp += 10
      end
      bb += l[index]
    when 'C'
      if cc != 0
        tmp += 10
      end
      cc += l[index]
    end
  end
  if aa == 0 || bb == 0 || cc == 0
    next
  end
  tmp += (a - aa).abs
  tmp += (b - bb).abs
  tmp += (c - cc).abs
  if tmp < mp
    mp = tmp
  end
end
p mp


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

int main() {
    int n,m;
    cin >> n >> m;
    
    vector<int> town(n);
    
    for(int i = 0; i < m * 2; i++)
    {
        int buf;
        cin >> buf;
        
        town.at(buf - 1)++;
    }
    
    for(int i = 0; i < n; i++)
    {
        cout << town.at(i) << endl;
    }
}


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

using namespace std;

int main()
{
    int h, w;

    cin >> h >> w;

    char cell[h][w];

    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)
        {
            cin >> cell[i][j];
        }
    }

    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)
        {
            cout << cell[i][j];
        }
        cout << endl;
        for(int j=0; j<w; j++)
        {
            cout << cell[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <queue>
#include <set>

using namespace std;

#define INF (1000000000000000000LL)

typedef pair<long long,int> PLLI;

int main()
{
    int N,M,K,S;
    cin >> N >> M >> K >> S;

    long long P,Q;
    cin >> P >> Q;

    vector<long long> town(N);
    for(int i=0; i<N; ++i) town[i]=P;

    town[N-1]=0;

    queue<PLLI> q;
    set<int> zom;
    for(int i=0; i<K; ++i) {
        int temp;
        cin >> temp;
        town[temp-1]=INF;
        q.push(PLLI(S,temp-1));
        zom.insert(temp-1);
    }

    vector<int> road[N];
    vector<int> temp_road[N];
    for(int i=0; i<M; ++i) {
        int a,b;
        cin >> a >> b;
        temp_road[a-1].push_back(b-1);
        temp_road[b-1].push_back(a-1);
        if(zom.count(a-1)==0 && zom.count(b-1)==0) {
            road[a-1].push_back(b-1);
            road[b-1].push_back(a-1);
        }
    }

    while(!q.empty()) {
        PLLI p=q.front(); q.pop();
        long long d = p.first;
        int t = p.second;
        --d;
        for(auto x : temp_road[t]) {
            if(town[x]==P) {
                town[x]=Q;
                if(d!=0) q.push(PLLI(d,x));
            }
        }
    }

    priority_queue<PLLI,vector<PLLI>,greater<PLLI> > pq;
    vector<long long> cost(N);

    for(int i=0; i<N; ++i) cost[i]=INF;

    cost[0]=0;
    pq.push(PLLI(0,0));

    while(!pq.empty()) {
        PLLI p=pq.top(); pq.pop();
        long long c=p.first;
        int t=p.second;

        if(t==N-1) break;
        if(cost[t]<c) continue;

        for(auto x : road[t]) {
            if(cost[x]<=c+town[x]) continue;
            cost[x]=c+town[x];
            pq.push(PLLI(cost[x],x));
        }
    }

    cout << cost[N-1] << endl;

    return 0;
}

Measured memory_bytes: 17536
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>

using namespace std;

#define ll long long

bool cmp(const ll a, const ll b)
{
    return a > b;
}

void solve()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }

    vector<ll> sa;
    sa.push_back(A.at(0));
    for (ll i = 1; i < N; i++)
    {
        auto iterL = upper_bound(sa.begin(), sa.end(), A.at(i), cmp);
        if (iterL == sa.end())
        {
            // 見つからなかったので色を追加
            sa.push_back(A.at(i));
        }
        else
        {
            // 見つかったので入れ替え
            *iterL = A.at(i);
        }
    }

    cout << sa.size() << endl;

    return;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 2168
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

bool isPrime(ll num) {

	bool flag = true;
	for (int i = 2; i <= sqrt(num); i++) {
		if (num%i == 0) {
			flag = false;
			break;
		}
	}

	return flag;
}


void solve() {

	ll N;
	cin >> N;
	vector<ll> B(N - 1);
	rep(i, N - 1) cin >> B[i];

	ll ans = 0;

	for (ll i = 0; i < N - 2; i++) {
		ans += min(B[i], B[i + 1]);
	}

	ans += B[0];
	ans += B[N - 2];

	cout << ans;

}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	return 0;
}


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

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

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

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

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する

struct BIT {
    vector<int> bit;
    int n;

    /*
     * 1 ~ nまでのBITを作る
     */
    BIT(int n) {
        bit.resize(n + 1, 0);
        this->n = n;
    }

    int sum(int i) {
        int s = 0;
        while (i > 0) {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    void add(int i, int x) {
        while (i <= n) {
            bit[i] += x;
            i += i & -i;
        }
    }
};

int N;
vector<int> a;

ll count(ll n) {
    vector<int> b(N + 1);
    BIT bit(2 * N + 5);
    int zero = N + 1;

    rep(i, 0, N) {
        if (a[i] > n) {
            b[i + 1] = -1;
        } else {
            b[i + 1] = 1;
        }
    }

    rep(i, 0, N) {
        b[i + 1] += b[i];
    }

    ll ret = 0ll;
    for (int i = 0; i <= N; ++i) {
        ret += bit.sum(b[i] + zero - 1);
        bit.add(b[i] + zero, 1);
    }

    return ret;


}

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

    cin >> N;

    a.resize(N);
    rep(i, 0, N) cin >> a[i];

    int lb = 0;
    int ub = 1 << 30;
//    int ub = (int) 1e2 + 1;

    ll thr = 1ll * N * (N + 1) / 4 + 1;
    while (true) {
        int mid = (lb + ub) / 2;
        ll x = count(mid);
        ll y = count(mid - 1);

        if (x < thr && y < thr) {
            lb = mid;
        } else if (x >= thr && y >= thr) {
            ub = mid;
        } else {
            cout << mid << endl;
            return 0;
        }
    }

    return 0;
}


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

#define scd second;
#define fst first;
#define mkp make_pair
#define pb push_back
#define pf push_front

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;

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

	int n;
	cin>>n;
	string str=to_string(n);
	bool f=false;
	for(auto x : str){
		if(x=='7'){
			f=true;
			break;
		}
	}
	if(f) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

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

int a[1011];

int main() {
	// your code goes here
	int i, j, n, ans=INT_MAX, k;
	cin>>n;
	for(i=0; i<n; ++i)
		cin>>a[i];
	for(i=-100; i<=100; ++i) {
		int cur=0;
		for(j=0; j<n; ++j)
			cur+=(a[j]-i)*(a[j]-i);
		ans=min(ans, cur);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
def theater(n , lt):

    ans = 0

    for i in range(n):
        ans += (lt[i][1] - lt[i][0]) + 1

    return ans

def main():
    n = int(input())
    lt = [list(map(int , input().split())) for i in range(n)]
    print(theater(n , lt))

if __name__ == '__main__':
    main()

Measured memory_bytes: 39280
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h> 
using namespace std;

typedef long long ll;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) 
#define rep(pp,nn) for (int ii = pp; ii < nn; ++ii)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

string int_to_string(int x) {
    stringstream ss;
	ss << x;
	string ni = ss.str();
	return ni;
}
int string_to_int(string x) {
	int n;
	stringstream s(x);
	s >> n;
	return n;
}

int64_t power_mod(ll a, ll b, ll mo) {
	ll ans = 1;
	while (b) {
		if(b & 1) {
			ans = (ans % mo * a % mo) % mo;
		}
		a = (a % mo * a % mo) % mo;
		b /= 2;
	}
	return ans;
}
int64_t POW(ll a, ll b) {
	ll ans = 1;
	while (b) {
		if(b & 1) {
			ans = ans * a;
		}
		a = a * a;
		b /= 2;
	}
	return ans;
}

vector<int64_t> INVERSE(int64_t nn, int64_t mo) {
	vector<int64_t> inv(nn + 1);
	vector<int64_t> mul(nn + 1);
	inv[0] = 1;
    inv[1] = 1;
	for (ll i = 2; i <= nn; ++i) {
		inv[i] = (mo - (mo / i) * inv[mo % i] % mo) % mo; 
	}
	mul[0] = 1;
	for (int i = 1; i <= nn; ++i) {
		mul[i] = (mul[i - 1] * inv[i]) % mo;
	}
	return mul;
}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


int main() {
	int n;
	cin >> n;
	int x = (n / 200) - 2 ;
	cout << 8 - x;
}














Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int ar[27];
    cin>>s;
    int i,j,k,l;
    for(i=0;i<27;i++)
        ar[i]=0;
    for(i=0;i<s.size();i++)
    {
        l=s[i]-' '-64;
        ar[l]++;
    }
    k=0;
    for(i=0;i<27;i++)
    {
        if(ar[i]>=2)
        {
            k=1;
            break;
        }
    }
    if(k==1)
        cout<<"no"<<endl;
    else
        cout<<"yes"<<endl;
}


Measured memory_bytes: 256
void main() {
	auto N = ri;
	auto a = readAs!(long[]);

	ulong res = ulong.max;
	long S = a.sum;
	long S_i;

	foreach(i; 0..N) {
		S_i += a[i];
		if(i+1 < N) res = min(res, abs(S - S_i * 2));
	}
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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

using namespace std;

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

    if (M - 2 * N >= 0) cout << N + (M - 2 * N) / 4 << endl;
    else cout << M / 2 << endl;

    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define inf 1e18
#define pi acos(-1.0)

string a,b,c;
int al,bl;
int dp[3005][3005];

void solve()
{
    int i,j;
    for(i=1;i<=al;i++)
    {
        for(j=1;j<=bl;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]);
        }
    }

    i=al;
    j=bl;
    while(i>0&&j>0)
    {
        if(a[i-1]==b[j-1])
        {
            c.push_back(a[i-1]);
            i--;
            j--;
        }
        else if(dp[i][j-1]>dp[i-1][j])j--;
        else i--;
    }

    reverse(c.begin(),c.end());
    cout << c;
}

int main()
{
    fastio;

    cin >> a >> b;
    al=a.size();
    bl=b.size();
    solve();

    return 0;
}


Measured memory_bytes: 38856
#include <bits/stdc++.h>
using namespace std;
int bunbun(string s){
    string t = s;
    reverse(t.begin(), t.end());
    return s == t;
}

int main() {
    string S;
    cin >> S;
    int N = S.size();

    bool a = true;

    //case 1
    if (!bunbun(S)) a = false;
    //case 2
    if (!bunbun(S.substr(0, S.size() / 2))) a = false;

    cout << (a ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3568
#include <stdio.h>

int main(void){
    long n;
    scanf("%ld",&n);
    long ans=0;
    for (int i = 1; i<=n; i++) {
        ans += (n/i*(2*i+(n/i-1)*i))/2;
    }
    printf("%ld\n",ans);
    return 0;
}

Measured memory_bytes: 1736
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main
{
    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;
        }
    }
    public static void main(String args[])
    {
        FastReader obj = new FastReader();
        int a = obj.nextInt();
        System.out.println((a)+(a*a)+(a*a*a));
    }
}


Measured memory_bytes: 32760
a, b, m = map(int, input().split())

a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))

minpay = min(a_l) + min(b_l)
for i in range(m):
    c_l = list(map(int, input().split()))
    if a_l[c_l[0] - 1] + b_l[c_l[1] - 1] - c_l[2] <= minpay:
        minpay = a_l[c_l[0] - 1] + b_l[c_l[1] - 1] - c_l[2]

print(minpay)


Measured memory_bytes: 18684
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1<<30;

int main(){
  int n;cin>>n;
  vector<vector<bool>> f(n, vector<bool>(10));
  for(int i=0;i<n;i++){
  	for(int j=0;j<10;j++){
      int t;cin>>t;f[i][j] = t==1;
    }
  }
  vector<vector<int>> p(n, vector<int>(11));
  for(int i=0;i<n;i++){
  	for(int j=0;j<11;j++){
      cin>>p[i][j];
    }
  }
  int ans = -INF;
  for(int t=1;t<(1<<10);t++){
  	int sum=0;
    for(int i=0;i<n;i++){
      int count=0;
      for(int j=0;j<10;j++){
      	if(f[i][j]&&(t>>j&1))count++;
      }
      sum += p[i][count];
    }
    ans = max(ans, sum);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
s = list(map(int, input().split()))
s.sort()

ax = (s[2] - s[0]) // 2
bx = (s[2] - s[1]) // 2

s[0] += ax * 2
s[1] += bx * 2

if s[0] == s[1] and s[0] != s[2]:
    print(ax + bx + 1)
if (s[0] != s[1] and s[0] == s[2]) or (s[0] != s[1] and s[1] == s[2]):
    print(ax + bx + 2)
if s[0] == s[1] and s[1] == s[2] and s[0] == s[1]:
    print(ax+bx)

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

using namespace std;

typedef long long ll;

int main () {
	string a,b;
	ll i, j, k;
	ll ret = 0;
    string s;
	
	cin >> a >> b;
    
    s = a + b;
    ret = atoi(s.c_str());

    for ( i = 1; i < ret / 2; i++ ) {
        if ( (ret % i == 0) && (i == (ret / i)) ) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" <<endl;
	
	return 0;
}


Measured memory_bytes: 3576
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        int[] x = new int[4];
        int[] y = new int[4];
        for (int i = 0; i < 2; i++) {
            x[i] = Integer.parseInt(sc.next());
            y[i] = Integer.parseInt(sc.next());
        }

        x[2] = x[1] - (y[1] - y[0]);
        y[2] = y[1] + x[1] - x[0];
        x[3] = x[2] - (x[1] - x[0]);
        y[3] = y[2] - (y[1] - y[0]);

        out.println(x[2] + " " + y[2] + " " + x[3] + " " + y[3]);
        
        out.flush();
    }
}

Measured memory_bytes: 21844
import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n, q;
    readf("%s %s", &n, &q);
    readln;
    
    auto g = new int[][] (n+1);
    foreach (i; 0 .. n-1) {
        int u, v;
        readf("%s %s", &u, &v);
        readln;
        
        g[u] ~= v;
        g[v] ~= u;
    }
    
    auto s = new int[] (n+1);
    foreach (_; 0 .. q) {
        int p, v;
        readf("%s %s", &p, &v);
        readln;
        
        s[p] += v;
    }
    
    debug { s.writeln; }
    
    auto ans = new int[] (n+1);
    
    void dfs(int v, int fr, int add) {
        ans[v] = s[v] + add;
        
        foreach (u; g[v]) {
            if (u == fr) { continue; }
            
            dfs(u, v, add + s[v]);
        }
    }
    
    dfs(1, -1, 0);
    
    for (int i = 1; i <= n; ++i) {
        if (i > 1) { write(' '); }
        write(ans[i]);
    }
    writeln();
}

Measured memory_bytes: 34556
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV
import qualified Data.Vector.Mutable as MV
import Data.Ix
import Data.Ord (Down(Down))
import qualified Data.Sequence as Seq
import Data.Foldable (toList)
-- import Control.Lens

debug = False

ts :: Show a => a -> a
ts a = if debug then traceShowId a else a


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)


readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

readIntV :: Int -> IO (UV.Vector Int)
readIntV n = GV.unfoldrN n (fmap (fmap BC.tail) . BC.readInt) <$> BC.getLine

readIntegersV :: Int -> IO (V.Vector Integer)
readIntegersV n = GV.unfoldrN n (fmap (fmap BC.tail) . BC.readInteger) <$> BC.getLine

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . BC.readInteger) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

m = 1000000000000000000

main :: IO ()
main = do
  n <- readInt
  as <- readIntegersV n
  if GV.elem 0 as then putStrLn "0"
  else do
    let prod = GV.foldM (\a acc -> case a * acc of
          a
            | a > m -> Nothing
            | otherwise -> Just a
          ) 1 as
    print $ fromMaybe (negate 1) prod





Measured memory_bytes: 22516
import { readFileSync } from 'fs'

const mod = 10 ** 9 + 7

function main(input: string) {
  const [, S] = input.split('\n')

  // 各文字の数を集計
  const counts = Array.from(S).reduce(
    (acc, v) => ({ ...acc, [v]: (acc[v] || 0) + 1 }),
    {} as Record<string, number>
  )

  // 組み合わせを計算
  const pattern = Object.keys(counts).reduce((acc, key) => {
    const result = acc * (counts[key] + 1)
    return result % mod
  }, 1)

  // 0文字選択のパターンを排除
  const result = (pattern - 1 + mod) % mod

  console.log(result)
}

main(readFileSync('/dev/stdin', 'utf8').trim())


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

bool isParallel(int* v1, int* v2)
{
    return (v1[0] * v2[1] - v2[0] * v1[1]) == 0;
}

bool isOrthogonal(int* v1, int* v2)
{
    return (v1[0] * v2[0] + v1[1] * v2[1]) == 0;
}

int main()
{
    int n;
    int v1[2], v2[2];
    int x, y;
    cin >> n;
    for(int i=0;i<n;++i){
        cin >> x >> y;
        cin >> v1[0] >> v1[1];
        v1[0] -= x;
        v1[1] -= y;
        cin >> x >> y;
        cin >> v2[0] >> v2[1];
        v2[0] -= x;
        v2[1] -= y;

        if(isParallel(v1, v2)) cout << 2;
        else if(isOrthogonal(v1, v2)) cout << 1;
        else cout << 0;
        cout << endl;
    }
}


Measured memory_bytes: 3104
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <climits>
#include <cmath>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define pb push_back
#define fst first
#define snd second

#ifdef QLEG_DEBUG
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << '{'; string sep; for (const auto& x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream& os, const pair<A, B>& p) { return os << '(' << p.first << ", " << p.second << ')'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
template<typename T> using min_queue=priority_queue<T,vector<T>,greater<T>>;

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

  int N; cin>>N;
  ll res = 0;
  for (int a=1;a<=N-1;a++) {
    res += (N-1)/a;
  }
  cout << res << '\n';
}


Measured memory_bytes: 3628
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll Mypow(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll gcd(ll a, ll b){//計算量はO(log(max(a,b))
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

ll kai(ll x){
  if(x == 1) return 1;
  return x * kai(x-1) % MOD;
}



int main(){
  ll a, b, x; cin >> a >> b >> x;
  if(a == 0){
    cout << 1 + b / x << endl;
    return 0;
  }
  cout << b / x - (a-1) / x << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
int main() {
ll n;
cin>>n;
ll f=0;
ll counter=0;
ll ca=0;
string a;
cin>>a;
for(ll i=0; i<n; i++){
if(a.at(i)==')'){
counter++;}
else{
ca++;}
if(counter>ca){
cout<<"(";
ca=0;
counter=0;}
}
f=ca-counter;
for(ll i=0; i<n; i++){
cout<<a.at(i);}
for(ll i=0; i<f; i++){
cout<<")";}
cout<<endl;}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <sstream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <chrono>
#include <unordered_map>



using namespace std;

typedef long long int ll;
typedef int h_int;

#define REP(i, n) for(int i = 0; i < ( n ); ++i )
#define REPR(i, n) for(int i = ( n ); i >= 0; --i)
#define FOR(i, a, n) for(int i = ( a ); i < ( n ); ++i )
#define FORR(i, a, n) for(int i = ( n ); i >= ( a ); --i)

#define DOUT(x) cerr << #x << " = " << x << "\n";
#define COUT(x) cout << ( x ) << "\n";


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

        int n; cin >> n;
        vector<ll> a;
        a.resize(n);
        ll sum = 0;
        REP(i, n)
        {
                cin >> a[i];
                sum += a[i];
        }
        ll x = a[0];
        ll y = sum - x;
        ll m = abs(x - y);
        FOR(i, 1, n - 1)
        {
                x += a[i];
                y = sum - x;
                m = min(m, abs(x - y) );
        }
        std::cout << m << '\n';

        return 0;
}


Measured memory_bytes: 1792