akhauriyash/Code-Regression huggingface dataset:
N, M, Q = map(int, input().split())
p = []
q = []

# 2次元累積和を使う(都市数 * 都市数)
# l で始まり、 j で終わる鉄道を CS[l - 1][r - 1]に入れる
# その後、累積和を取っていく
CS = [[0] * (N + 1) for _ in range(N + 1)]

for _ in range(M):
	l, r = map(int, input().split())
	CS[l][r] += 1

# N <= 500 だからできるやつ	
for i in range(N + 1):
	for j in range(N + 1):
		if j - 1 >= 0: # １つ左にあるマスからもらう
			CS[i][j] += CS[i][j - 1]
		if i - 1 >= 0: # 1つ上にあるマスからもらう
			CS[i][j] += CS[i - 1][j]
		if j - 1 >= 0 and i - 1 >= 0: # 包除原理
			CS[i][j] -= CS[i - 1][j - 1]
	
for _ in range(Q):
	a, b = map(int, input().split())
	p.append(a)
	q.append(b)
	
for i in range(Q):
	print(CS[q[i]][q[i]] - CS[p[i] - 1][q[i]] - CS[q[i]][p[i] - 1] + CS[p[i] - 1][p[i] - 1]) 

Measured memory_bytes: 72792
#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 ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}
int main(){
  int n;
  cin >> n;
  vector<ll> v(n);
  rep(i,n)
    cin >> v.at(i);
  ll sum=0;
  int right=0;
  ll ans=0;
  rep(left,n){
    while(right<n&&((sum+v.at(right))==(sum^v.at(right)))){
      sum+=v.at(right);
      right++;
    }
    ans+=right-left;
    if(left==right)right++;
    else sum-=v.at(left);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(){
	int A, B, C, X, cnt = 0;
	cin >> A >> B >> C >> X;

	int tmpI = X, tmpJ, tmpK;
	for(int i = 0; i <= A; ++i){
		tmpI -= 500 * i;
		if(tmpI < 0) continue;
		for(int j = 0; j <= B; ++j){
			tmpJ = tmpI;
			tmpJ -= 100 * j;
			if(tmpJ < 0) continue;
			for(int k = 0; k <= C; ++k){
				tmpK = tmpJ;
				tmpK -= 50 * k;
				if(tmpK < 0) continue;
				if(tmpK == 0){ cnt++; }
				tmpK = tmpJ;
			}
			tmpJ = tmpI;
		}
		tmpI = X;
	}

	cout << cnt << endl;
	
	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 y_n(ans) cout<<(ans?"YES":"NO")<<endl;

int main() {
    int n, t; cin >> n >> t;
    int ans = t;
    int prev;
    cin >> prev;
    rep(i, n-1) {
        int num; cin >> num;
        if (num - prev < t) {
            ans += num - prev;
        }
        else ans += t;
        prev = num;
    }
    cout << ans << endl;
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  llvec x(N);
  llvec y(N);
  llvec xinf(N);
  llvec yinf(N);
  llvec S;
  rep(i, N){
    cin >> x[i];
    cin >> y[i];
    xinf[i] = x[i]-y[i];
    yinf[i] = x[i]+y[i];
  }
  sort(ALL(xinf));
  sort(ALL(yinf));

  cout << max(xinf[N-1]-xinf[0], yinf[N-1]-yinf[0]);
  
  return 0;
}


Measured memory_bytes: 9588
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>
#include <unordered_map>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define all(s) s.begin(), s.end()
#define fo(i, start, finish) for(int i = start; i <= finish; i ++)
#define y1 kdfjsalsdkf

const long long MXN = 1e5 + 10;
const long long MNN = 5e3 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long long OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int n, m, used[MXN];
vector<int> q[MXN];
vector<pair<int, int> > ans;

int dfs(int x, int p){
    used[x] = 1;
    int num = 0;
    for(int i : q[x]){
        if(i == p) continue;
        if (used[i] == 0){
            num += dfs(i, x);
        } else if (used[i] == 1){
            ans.pb({x, i});
            num++;
        }
    }
    used[x] = 2;
    if(p != -1){
        if(num % 2 == 1){
            ans.pb({x, p});
            return 0;
        }else {
            ans.pb({p, x});
            return 1;
        }
    }
    return 0;
}

int main(){
    ios;
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        int u, v;
        cin >> u >> v;
        q[u].pb(v);
        q[v].pb(u);
    }
    if(m % 2 == 1){
        cout << -1;
        return 0;
    }
    dfs(1, -1);
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i].F << ' ' << ans[i].S << nl;
    }
    return 0;
}


//
//
//


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

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

    string S,T,U;
	int A,B;
	cin >> S >> T >> A >> B >> U;
	

	if(S==U) cout << (A-1) << " " << B <<"\n";
	else if(T==U) cout << A << " " << (B-1) << "\n";



}

Measured memory_bytes: 256
N,L = map(int,input().split(" "))
ans = 0
for i in range(N):
    ans += L+i

if(L < 0):
    if (L+N-1 < 0):
        print(ans-(L+N-1))
    else:
        print(ans)
if(L >= 0):
    print(ans-L)


Measured memory_bytes: 2940
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		
		BigDecimal l[] = new BigDecimal[88];
		l[0] = new BigDecimal(2);
		l[1] = new BigDecimal(1);
		int x = 0;
		
		for (int i = 0; i < n; i++){
			l[i+2] = l[i].add(l[i+1]);
		}
		
		System.out.println(l[n]);
		
		
		
	}

}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n,k;
  cin>>n>>k;
  ll sum=0;
  for(ll i=k;i<=n+1;i++){
    ll mini=i*(i-1)/2-1;
    ll maxi=(n*(n+1)/2)-((n-i)*(n-i+1)/2);
    sum+=maxi-mini;
    sum%=MOD;
  }
  print(sum);
}


Measured memory_bytes: 3560
Scanf.scanf "%d" @@ fun n ->
  let sps = Array.init n @@ fun i -> Scanf.scanf " %s %d" @@ fun s p -> i + 1, s, p in
  let cmp (i, s, p) (j, s1, p1) = if s < s1 then -1 else if s > s1 then 1 else p1 - p in
  Array.sort cmp sps;
  Array.iter (fun (i, s, p) -> Printf.printf "%d\n" i) sps

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
#include<iomanip>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int main(){
 string S;
 cin >> S;
 int L = S.size();
 string ans = "AC";
 if(S[0] != 'A'){
 ans = "WA";
 }
 int cnt = 0;
 for(int i = 1; i < L; ++i){
 if(isupper(S[i])){
 if(i == 1 || i == L - 1 || S[i] != 'C'){
 ans = "WA";
 }
 ++cnt;
 }
 }
 if(cnt != 1){
 ans = "WA";
 }
 cout << ans << endl;
}

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

int main() {

  int N;
  int l;
  int r;
  int sum;
  sum = 0;
  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    sum += r-l+1;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MAX_INT 2147483647
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[i][j] != a[j][i]) {
                cout << "-1\n";
                return 0;
            }
        }
    }

    vector<vector<bool>> z(n, vector<bool>(n));

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) if (i != j) {
            for (int k = 0; k < n; k++) if (j != k) {
                if (a[i][j] + a[j][k] < a[i][k]) {
                    cout << "-1\n";
                    return 0;
                }
                if (a[i][j] + a[j][k] == a[i][k]) {
                    z[i][k] = true;
                }
            }
        }
    }

    long res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) if (!z[i][j]){
            res += a[i][j];
        }
    }

    cout << res << "\n";


    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
struct glass
{
	ll times,val;
	bool operator < (glass &a)const{
		return this->val*this->times<a.val*a.times;
	}
}cup[4];
int n;
ll ans=0;
int main()
{
	scanf("%lld%lld%lld%lld%d",&cup[0].val,&cup[1].val,&cup[2].val,&cup[3].val,&n);
	cup[0].times=8,cup[1].times=4,cup[2].times=2,cup[3].times=1;
	sort(cup,cup+4);
	if(cup[0].times!=1) ans=cup[0].times*cup[0].val*n/2;
	else
	{
		ans+=(n/2)*cup[0].val;
		if(n%2)
		{
			ans+=cup[1].times/2*cup[1].val;
		}
	}
	printf("%lld",ans);
	return 0; 
}

Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) throws IOException{
		// 入力導入部
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		
		String strin=br.readLine();
		String[] str=strin.split("");
		
		
		
		for(int i=0;i<str.length;i++){
			if(str[i].equals(str[i].toLowerCase())){
				System.out.print(str[i].toUpperCase());
			}else System.out.print(str[i].toLowerCase());
		}br.close();
		System.out.println();
		}}

Measured memory_bytes: 19272
<?php
  $n = intVal(trim(fgets(STDIN)));
  $s = array_map("intVal", explode(" ", trim(fgets(STDIN))));
  $color = 0;
  $ans = 1;
  $MOD = 1000000007;
  $cur = [-1, -1, -1];

  if($s[0] != 0){
    echo 0 . PHP_EOL;
    exit();
  }
  foreach($s as $c){
    if($c == 0){
      if($color >= 3){
        echo 0 . PHP_EOL;
        exit;
      }
      $cur[$color] = 0;
      $color += 1;
      $ans %= $MOD;
    }else{
      $x = 0;
      foreach($cur as $curn){
        if($curn == $c-1){
          $x += 1;
        }
      }
      if($x == 0){
        echo 0 . PHP_EOL;
        exit();
      }
      $ans *= $x;
      $ans %= $MOD;
      $idx = array_search($c-1, $cur);
      $cur[$idx] += 1;
    }
  }

  if($color == 0){
    $ans *= 1;
  }elseif($color == 1){
    $ans *= 3;
  }else{
    $ans *= 6;
  }
  $ans %= $MOD;
  echo $ans . PHP_EOL;
?>

Measured memory_bytes: 16884
from bisect import bisect_left
n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
maxA = max(A)
cnt = [0] * (maxA * 2 + 2)
rui = [n] * (maxA * 2 + 2)

for a in A:
  cnt[a] += 1

accum = 0  
for i in range(maxA * 2 + 1):
  accum += cnt[i]
  rui[i + 1] -= accum 
  
# 左手を決めた時(left)に、幸福度がx 以上となる組み合わせの数を返す
def f(x):
  ret = 0
  for left in A:
    ret += rui[max(x - left, 0)]
  return ret
  
lo = 0
hi = maxA * 2 + 1
while hi - lo > 1:
  md = (lo + hi) // 2
  if f(md) >= m:
    lo = md
  else:
    hi = md 
# もとまる lo が m 通り以上握手ができる最小の数。
    
ruiA = [0] * (n + 1)
for i in range(n):
  ruiA[i + 1] = ruiA[i] + A[i]

ans = 0
cnt = 0
for i in range(n):
  pos = bisect_left(A, lo - A[i])
  cnt += n - pos
  ans += ruiA[-1] - ruiA[pos] + A[i] * (n - pos)
if cnt == m:
  print(ans)
else: # m個よりも多い分を引く
  rem = cnt - m
  print(ans - rem * lo)

Measured memory_bytes: 18500
n, d = map(int, input().split())
point = [[int(i) for i in input().split()] for j in range(n)]
count = 0
for i in range(n):
    for j in range(i + 1, n):
        norm = 0
        for pi, pj in zip(point[i], point[j]):
            norm += (pi - pj) ** 2
        if int(norm**0.5) == norm**0.5:
            count += 1

print(count)

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

int main() {
    string s;
    cin >> s;
    if (s == "SUN") {
        printf("%d\n", 7);
    }
    else if (s == "MON") {
        printf("%d\n" ,6);
    }
    else if (s == "TUE") {
        printf("%d\n", 5);
    }
    else if (s == "WED"){
        printf("%d\n", 4);
    }
    else if (s == "THU"){
        printf("%d\n", 3);
    }
    else if (s == "FRI"){
        printf("%d\n", 2);
    }
    else if (s == "SAT"){
        printf("%d\n", 1);
    }
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second

using namespace std;

const long long MOD = (long long)1e9 + 7;

int a, b, q;
vector<long long> vec[2];
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> a >> b >> q;
	long long tmp;
	for (int i = 0; i < a; i++) {
		cin >> tmp;
		vec[0].push_back(tmp);
	}
	for (int i = 0; i < b; i++) {
		cin >> tmp;
		vec[1].push_back(tmp);
	}
	sort(vec[0].begin(), vec[0].end());
	sort(vec[1].begin(), vec[1].end());
	int sz0 = (int)vec[0].size(), sz1 = (int)vec[1].size();
	while (q--) {
		cin >> tmp;
		long long t1, t2, v1, v2;
		int tp1 = lower_bound(vec[0].begin(), vec[0].end(), tmp) - vec[0].begin();
		if (tp1 == sz0) {
			t1 = vec[0][sz0 - 1];
			t2 = t1;
		}
		else if (tp1 == 0) {
			t1 = vec[0][0];
			t2 = t1;
		}
		else if (vec[0][tp1] == tmp) {
			t1 = vec[0][tp1];
			t2 = t1;
		}
		else {
			t1 = vec[0][tp1 - 1];
			t2 = vec[0][tp1];
		}
		tp1 = lower_bound(vec[1].begin(), vec[1].end(), tmp) - vec[1].begin();
		if (tp1 == sz1) {
			v1 = vec[1][sz1 - 1];
			v2 = v1;
		}
		else if (tp1 == 0) {
			v1 = vec[1][0];
			v2 = v1;
		}
		else if (vec[1][tp1] == tmp) {
			v1 = vec[1][tp1];
			v2 = v1;
		}
		else {
			v1 = vec[1][tp1 - 1];
			v2 = vec[1][tp1];
		}
		long long ans;
		if (min(t1, v1) <= tmp && tmp <= max(t1, v1))
			ans = min(abs(t1 - tmp), abs(v1 - tmp)) * 2 + max(abs(t1 - tmp), abs(v1 - tmp));
		else
			ans = max(abs(t1 - tmp), abs(v1 - tmp));
		if (min(t1, v2) <= tmp && tmp <= max(t1, v2))
			ans = min(ans, min(abs(t1 - tmp), abs(v2 - tmp)) * 2 + max(abs(t1 - tmp), abs(v2 - tmp)));
		else
			ans = min(ans, max(abs(t1 - tmp), abs(v2 - tmp)));
		if (min(t2, v1) <= tmp && tmp <= max(t2, v1))
			ans = min(ans, min(abs(t2 - tmp), abs(v1 - tmp)) * 2 + max(abs(t2 - tmp), abs(v1 - tmp)));
		else
			ans = min(ans, max(abs(t2 - tmp), abs(v1 - tmp)));
		if (min(t2, v2) <= tmp && tmp <= max(t2, v2))
			ans = min(ans, min(abs(t2 - tmp), abs(v2 - tmp)) * 2 + max(abs(t2 - tmp), abs(v2 - tmp)));
		else
			ans = min(ans, max(abs(t2 - tmp), abs(v2 - tmp)));
		cout << ans << "\n";
	}
	//system("pause");
	return 0;
}

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

const int DIM = 1e5 + 5;

int fth[DIM];
vector<int> edg[DIM];

int dfs( int x, int k, int &ans ) {
    int dep = 1;
    for( int y : edg[x] )
        dep = max( dep, dfs( y, k, ans ) + 1 );
    
    if( dep == k ) {
        if( fth[x] != 1 )
            ans ++;
        
        return 0;
    }
    
    return dep;
}

int main( void ) {
    
    int n, k;
    cin >> n >> k;
    
    int ans = 0;
    for( int i = 1; i <= n; i ++ ) {
        cin >> fth[i];
        
        if( i == 1 )
            ans += ( fth[i] != 1 );
        else
            edg[fth[i]].push_back( i );
    }
    
    for( int x : edg[1] )
        dfs( x, k, ans );
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 12288
H,W,M = map(int,input().split())

h_target = [0]*(H+1)
w_target = [0]*(W+1)
target = []

for _ in range(M):
    h,w = map(int,input().split())
    target.append((h,w))
    h_target[h] += 1
    w_target[w] += 1

max_h = max(h_target)
max_w = max(w_target)

num_max_h = 0
num_max_w = 0

for i in h_target:
    if i == max_h:
        num_max_h += 1

for i in w_target:
    if i == max_w:
        num_max_w += 1

total = num_max_h*num_max_w # 最適地点の組み合わせ個数
point = 0 # 最適地点のうち爆破対象地点の個数

for i,j in target:
    if h_target[i] == max_h and w_target[j] == max_w:
        point += 1

if point == total:
    print(max_h+max_w-1)
else:
    print(max_h+max_w)

Measured memory_bytes: 54200
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void){

    string S; cin>>S;
    bool ok = true;
    for (int i = 0; i < S.size(); ++i) {
        if(i%2==0){//奇数のとき
            if(S[i]=='L'){
                ok = false;
                break;
            }
        }else{
            if(S[i]=='R') {
                ok = false;
                break;
            }
        }
    }
    if(ok){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdlib>
#include<math.h>
using namespace std;
int main(void){
    long long N,cnt=0;
    cin >> N;
    long long a[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    for(int j=0;j<N;j++){
        while(a[j]%2==0){
            a[j]/=2;
            cnt++;
        }
    }
    printf("%lld",cnt);
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include <bits/stdc++.h>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;


int main(){
    int N;
    string S[200100];
    cin >> N;
    for(int i = 0; i < N; ++i){
        cin >> S[i];
    }
    unordered_map<string, int> mp;
    int count =0;
    for(int i = 0; i <N; ++i){
        if(mp.find(S[i]) == mp.end()){
            pair<string,int> p (S[i],count);
            mp.insert(p);
        }
    }
    cout << mp.size()<<endl;
    return 0;
}



Measured memory_bytes: 23856
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };


int main() {

	int n;
	cin >> n;
	vector<string> s(n);
	rep(i, n) {
		cin >> s.at(i);
		sort(s.at(i).begin(), s.at(i).end());
	}
	string ans;
	for (char c = 'a'; c <= 'z'; c++) {
		int num = mod;
		rep(i, n) {
			int cnt = 0;
			rep(j, s.at(i).size()) {
				if (s.at(i).at(j) == c) cnt++;
			}
			num = min(num, cnt);
		}
		rep(k, num) {
			ans += c;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define eps 1e-8
using namespace std;
typedef pair<int, int> pii;
int main(){
  int a, b, d;
  while(cin >> a >> b >> d, a){
    int x = 0, y = 0;
    pii ans = mp(1e9, 1e9);
    for(int i = -1e6; i < 1e6; i++){
      x = i;
      if((a*x + d) % b != 0)continue;
      y = (a*x + d) / b;
      if(ans.first + ans.second > abs(x) + abs(y)){
	ans = mp(abs(x), abs(y));
      }else if(ans.first + ans.second == abs(x) + abs(y)){
	if(a*ans.first + b*ans.second > a*abs(x) + b*abs(y))
	ans = mp(abs(x), abs(y));
      }
	
    }
    cout << ans.first << " " << ans.second << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;

//#define int ll

using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;



const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
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; }


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int h, w, a[111][111], d[111][111];
char D;
main() {
  file("threesum");
  ios;
  cin >> h >> w;
  fo(i, 1, h, 1) {
    fo(j, 1, w, 1) {
      cin >> D;
      a[i][j] = (D == '#');
      d[i][j] = INF1;
    }
  }
  queue < pair <pii, pii> > q;
  q.push({{1, 1}, {3, 3}});
  d[1][1] = a[1][1];
  auto valid = [&](int x, int y) {
    return (1 <= x and x <= h and 1 <= y and y <= w);
  };
  while (!q.empty()) {
    pair <pii, pii> p = q.front();
    q.pop();
    pii to1 = {p.F.F + 1, p.F.S};
    pii to2 = {p.F.F, p.F.S + 1};
//    cerr << "Ch " << p.F.F << " " << p.F.S << " " << d[p.F.F][p.F.S] << " " << p.S.F << " " << p.S.S << "\n";
    if (valid(to1.F, to1.S)) {
      int cost = d[p.F.F][p.F.S];
      if (a[to1.F][to1.S] and !a[p.F.F][p.F.S]) {
        ++cost;
      }
      if (cost < d[to1.F][to1.S]) {
        d[to1.F][to1.S] = cost;
        q.push({to1, p.F});
      }
    }
    swap(to1, to2);
    if (valid(to1.F, to1.S)) {
      int cost = d[p.F.F][p.F.S];
      if (a[to1.F][to1.S] and !a[p.F.F][p.F.S]) {
        ++cost;
      }
      if (cost < d[to1.F][to1.S]) {
        d[to1.F][to1.S] = cost;
        q.push({to1, p.F});
      }
    }
  }
  cout << d[h][w];
  return 0;
}
/**
3 3
###
###
###
*/


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    boolean[] isPrime = new boolean[100_001];
    for (int i = 0; i < isPrime.length; i++) isPrime[i] = true;
    isPrime[0] = false;
    isPrime[1] = false;
    for (int i = 2; i < (int) Math.sqrt(isPrime.length) + 1; i++) {
      if (isPrime[i]) {
        for (int j = 2; i * j < isPrime.length; j++) {
          isPrime[i * j] = false;
        }
      }
    }

    int[] acc = new int[isPrime.length];
    int sum = 0;
    for (int i = 3; i < isPrime.length; i++) {
      if (isPrime[i] && isPrime[(i + 1) / 2]) {
        sum++;
      }
      acc[i] = sum;
    }

    int Q = scanner.nextInt();
    for (int i = 0; i < Q; i++) {
      int l = scanner.nextInt();
      int r = scanner.nextInt();
      System.out.println(acc[r] - acc[l - 1]);
    }
  }
}


Measured memory_bytes: 70276
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;

int gcd(int x, int y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

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

    int pre = 0;
    int ans = 0;
    rep(i, s.size()) {
        if (i == 0) {
            pre = s[i];
            continue;
        }

        if (pre != s[i])
            ans++;

        pre = s[i];
    }

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 3712
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define inf 0x7fffffff
#define llinf 0x7fffffffffffffffll
using namespace std;
int main()
{
	int i,j,k,n,m;
	scanf("%d%d",&n,&k);
	if(n%k==0)
	{
		printf("0");
	}
	else
	{
		printf("1");
	}
	return 0;
}


Measured memory_bytes: 256
use proconio::input;
use num::integer::gcd;

fn main() {
    input! {
        k: u64,
    }

    let mut ans = 0;
    for i in 1..=k {
        for j in 1..=k {
            for k in 1..=k {
                ans += gcd(gcd(i, j), k)
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2156
S = input()
if S[0]==S[1]:
	if S[2]==S[3] and S[1]!=S[2]:
		print("Yes")
	else:
		print("No")
elif S[0]==S[2]:
	if S[1]==S[3] and S[0]!=S[1]:
		print("Yes")
	else:
		print("No")
elif S[0]==S[3]:
	if S[1]==S[2] and S[0]!=S[1]:
		print("Yes")
	else:
		print("No")
else:
	print("No")

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <stack>

typedef long long ll;

const double EPS = 1e-10;
const double PI  = acos(-1);
const ll     INF = LLONG_MAX /10;

ll gcd(ll a, ll b)
{
  while (b > 0) {
    a = a % b;
    std::swap(a, b);
  }
  return a;
}

ll lcm(ll a, ll b) {
  ll gcd_val = gcd(a, b);
  return a / gcd_val * b;   // over flow 防止のため、割り算を先にする
}

ll extgcd(ll a, ll b, ll& x, ll& y)
{
  ll d = a;
  if (b != 0) {
    ll x_dash;
    ll y_dash;
    d = extgcd(b, a % b, x_dash, y_dash);
    x = y_dash;
    y = x_dash - (a / b) * y_dash;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

int main(int argc, char* argv[])
{
  ll N, C;
  std::cin >> N >> C;

  std::vector< std::pair< ll, ll > > vp   (N, std::make_pair(0LL, 0LL));
  std::vector< std::pair< ll, ll > > vsum (N+1, std::make_pair(0LL, 0LL));
  std::vector< std::pair< ll, ll > > vrsum(N+1, std::make_pair(0LL, 0LL));
  std::vector< ll >::iterator it;

  for (ll i = 0; i < N; i++) {
    std::cin >> vp[i].first >> vp[i].second;
  }

  ll sum = 0;
  for (ll i = 0; i < N; i++) {
    sum += vp[i].second;
    vsum[i].first  = vp[i].first;
    vsum[i].second = sum - vsum[i].first;
    //std::cout << "s: " << i << " " << vsum[i].first << " " << vsum[i].second << std::endl;
  }

  ll rsum = 0;
  for (ll i = N-1; i >= 0; i--) {
    rsum += vp[i].second;
    vrsum[i].first  = C - vp[i].first;
    vrsum[i].second = rsum - vrsum[i].first;
    //std::cout << "r: " << i << " " << vrsum[i].first << " " << vrsum[i].second << std::endl;
  }

  std::vector< ll > vmax (N+1, 0LL);
  std::vector< ll > vrmax(N+1, 0LL);
  vmax[0] = vsum[0].second;
  for (ll i = 1; i < N; i++) {
    vmax[i]  = std::max(vmax[i-1], vsum[i].second);
    //std::cout << "vmax:" << i << " " << vmax[i] << std::endl;
  }

  vrmax[N] = 0;
  for (ll i = N-1; i >= 0; i--) {
    vrmax[i] = std::max(vrmax[i+1], vrsum[i].second);
    //std::cout << "vrmax:" << i << " " << vrmax[i] << std::endl;
  }

  ll ans = 0;
  std::vector< ll > vcal(2, 0LL);
  for (ll i = 0; i < N; i++) {
    vcal[0] = vsum[i].second;
    vcal[1] = vsum[i].second - vsum[i].first  + vrmax[i+1];
    ans = std::max(ans, *std::max_element(vcal.begin(), vcal.end()));
  }

  for (ll i = N-1; i >= 0; i--) {
    vcal[0] = vrsum[i].second;
    vcal[1] = vrsum[i].second - vrsum[i].first + (i == 0 ? 0 : vmax[i-1]);
    ans = std::max(ans, *std::max_element(vcal.begin(), vcal.end()));
  }
  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 6528
#include <stdio.h>

#define MAXN 200000
int a[MAXN];

int main(void)
{
    int n, m;
    scanf("%i %i", &n, &m);

    for (int i = 1; i <= m; i++)
    {
        int u, v;
        scanf("%i %i", &u, &v);
        a[u]++;
        a[v]++;
    }

    for (int i = 1; i <= m; i++)
    {
        if (a[i] % 2)
        {
            puts("NO");
            return 0;
        }
    }

    puts("YES");

    return 0;
}

Measured memory_bytes: 512
n = int(input())
h = list(map(int, input().split()))

ans = 0
while sum(h) > 0:
    prev = 0
    split = 0
    for v in h:
        if prev == 0 and v != 0:
            split += 1
        prev = v

    ans += split
    h = [v-1 if v > 0 else 0 for v in h]

print(ans)

Measured memory_bytes: 3064
#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 rEP(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 ll mod = 1e9+7;

int a, b, c, N,A,B;
string s;
int main() {
    cin>>N>>A>>B;
    p(min(N*A,B));
    return 0;
}

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

int main()
{
	int n,m,x,y;
	cin >> n >> m >> x >> y;
	int maxm = -101,minm = 200;
	for(int i = 0 ; i < n ; i++)
	{
		int temp;
		cin >> temp;
		maxm = max(temp,maxm);
	}
	for(int i = 0 ; i < m ; i++)
	{
		int temp;
		cin >> temp;
		minm = min(temp,minm);
	}
	//cout << minm - maxm << endl;
	if(minm > maxm && y > x && y > maxm && x < minm)
	cout << "No War\n";
	else
	cout << "War\n"; 
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    string s;
    cin >> s;
    int q;
    cin >> q;
    int t, f;
    char c;
    int cnt = 0;
    for (int i = 0; i < q; ++i) {
        cin >> t;
        if(t == 1) cnt++;
        else{
            cin >> f >> c;
            if(f == 1 && (cnt%2) == 0 || f == 2 && (cnt%2) == 1){
                s.insert(s.begin(), c);
            }
            else{
                s.push_back(c);
            }
        }
    }
    if(cnt % 2){
        reverse(s.begin(), s.end());
        cout << s << endl;
    }
    else cout << s << endl;
}

Measured memory_bytes: 900
#include <cstdio>
#define MAXN 105
int n, k, d, tot, snake;
bool vis[MAXN];

int main() {
	scanf ( "%d %d", &n, &k );
	for ( int i = 1;i <= k;i ++ ) {
		scanf ( "%d", &d );
		for ( int j = 1;j <= d;j ++ ) {
			scanf ( "%d", &snake );
			if ( ! vis[snake] ) ++ tot;
			vis[snake] = 1;
		}
	}
	printf ( "%d", n - tot );
	return 0;
} 

Measured memory_bytes: 3212
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
#define int long long
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
	int M,D; cin>>M>>D;
	int ans=0;
	for(int j=11;j<D+1;j++)if((j/10)*(j%10)<=M&&j/10>1&&j%10>1)ans++;
	cout<<ans<<endl;
}

Measured memory_bytes: 3596
//==========================================================================
//
//                   Bismillahir-Rahmanir-Rahim
//
// ==========================================================================
#include <bits/stdc++.h>
#define        ll                              long long int
#define        FOR(x,y,z)                      for(int x=y;x<z;x++)
#define        pii                             pair<int,int>
#define        pll                             pair<ll,ll>
#define        CLR(a)                          memset(a,0,sizeof(a))
#define        SET(a)                          memset(a,-1,sizeof(a))
#define        N                               100010
#define        M                               1000000007
#define        pi                              acos(-1.0)
#define        ff                              first
#define        ss                              second
#define        pb                              push_back
#define        inf                             (int)1e9
#define        eps                             1e-9
#define        debug(x)                        cerr << #x << " is " << x << endl;
#define        ALL(x)                          x.begin(),x.end()
using namespace std;
int dx[]={0,0,1,-1,-1,-1,1,1};
int dy[]={1,-1,0,0,-1,1,1,-1};
template < class T> inline T biton(T n,T pos){return n |((T)1<<pos);}
template < class T> inline T bitoff(T n,T pos){return n & ~((T)1<<pos);}
template < class T> inline T ison(T n,T pos){return (bool)(n & ((T)1<<pos));}
template < class T> inline T gcd(T a, T b){while(b){a%=b;swap(a,b);}return a;}
template <typename T> string NumberToString ( T Number ) { ostringstream ss; ss << Number; return ss.str(); }
inline int nxt(){int aaa;scanf("%d",&aaa);return aaa;}
inline ll lxt(){ll aaa;scanf("%lld",&aaa);return aaa;}
inline double dxt(){double aaa;scanf("%lf",&aaa);return aaa;}
template <class T> inline T bigmod(T p,T e,T m){T ret = 1;
for(; e > 0; e >>= 1){
    if(e & 1) ret = (ret * p) % m;p = (p * p) % m;
} return (T)ret;}
///******************************************START******************************************
int ar[N];
int main(){
     //freopen("out.txt","w",stdout);
    //ios_base::sync_with_stdio(false);
   //cin.tie(0);
   int n;
   cin>>n;
   for(int i=0;i<n;i++){
       int a=nxt();
       ar[a]++;
   }
   int tot=0;
   for(int i=1;i<N;i++){
      if(ar[i]){
        if(ar[i]%2==0) ar[i]=2;
        else ar[i]=1;
      }
       tot+=ar[i];
   }
   int c=0;
   for(int i=1;i<N;i++){
     if(ar[i]==2) c++;
   }
   tot-=((c+1)/2)*2;
   cout<<tot<<endl;

return 0;
}


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007;

int main(){

  int N;cin>>N;
    vector<ll> S(N+1,0);
    for(int i=0;i<N;i++){
        cin>>S[i+1];
        S[i+1]+=S[i];
    }
    ll ans=1LL<<60;
    for(int i=3;i<=N-1;i++){
        /*if(S[i-1]<S[N]-S[i-1]){*/
            ll mid1=S[i-1]/2,mid2=(S[N]-S[i-1])/2+S[i-1],a,b,c,d,e,f,g,h,diff1,diff2,diff3,diff4;
            auto pos1=lower_bound(S.begin()+1,S.begin()+i,mid1);
        if(*pos1==S[i-1]){
            a=c=*(pos1-1);
            b=d=S[i-1]-*(pos1-1);
        }else if(*pos1==S[1]){
            a=c=*pos1;
            b=d=S[i-1]-*pos1;
        }else{
                a=*pos1;
                b=S[i-1]-*pos1;
                c=*(pos1-1);
                d=S[i-1]-*(pos1-1);
            }
            auto pos2=lower_bound(S.begin()+i,S.end(),mid2);
        if(*pos2==S[N]){
            e=g=*(pos2-1)-S[i-1];
            f=h=S[N]-*(pos2-1);
        }else if(*pos2==S[i]){
            e=g=*pos2-S[i-1];
            f=h=S[N]-*pos2;
        }else{
                e=*pos2-S[i-1];
                f=S[N]-*pos2;
                g=*(pos2-1)-S[i-1];
                h=S[N]-*(pos2-1);
            }
        vector<ll> T1={a,b,e,f},T2={a,b,g,h},T3={c,d,e,f},T4={c,d,g,h};
            sort(all(T1));
        sort(all(T2));
        sort(all(T3));
        sort(all(T4));
            ans=min(ans,T1[3]-T1[0]);
        ans=min(ans,T2[3]-T2[0]);
        ans=min(ans,T3[3]-T3[0]);
        ans=min(ans,T4[3]-T4[0]);
        /*cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<*pos1<<" "<<*pos2<<endl;*/
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  long double a,b;
  cin >> a >> b;
  cout << ll(floorl(a * b)) << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 3804
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>

using namespace std;

int main(int argc, char* argv[]) {

	int N, ans = 1;

	cin >> N;

	vector<int>d(N);

	for (int i = 0; i < N; i++) {
		cin >> d[i];
	}

	sort(d.rbegin(), d.rend());

	for (int i = 1; i < N; i++) {
		if (d[i - 1] != d[i]) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}



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

const ll INF = 1e9;

template <typename C, C inf>
class Bellman_Ford {
	struct edge {
		int from, to;
		C cost;
		edge(int _from, int _to, int _cost) : from(_from), to(_to), cost(_cost) {}
	};
	vector<edge> es;
	bool isdir;
	vector<C> d;
	int V;
public:
	Bellman_Ford(int _V, bool _isdirected = true) : isdir(_isdirected), V(_V), d(_V) { }
	void add(int a, int b, C c) {
		es.emplace_back(a, b, c);
		if (!isdir) es.emplace_back(b, a, c);
	}
	bool calc(int s) {
		fill(d.begin(), d.end(), inf);
		d[s] = C();
		bool update;
		for (int i = 0; i < V; i++) {
			update = false;
			for (auto &e : es) {
				if (d[e.from] == inf || d[e.to] <= d[e.from] + e.cost) continue;
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		return update;
	}
	vector<C> dist() {
		return d;
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int V, E, r;
	cin >> V >> E >> r;
	Bellman_Ford<int, (int)1e9> bf(V);
	for (int i = 0; i < E; i++) {
		int s, t, d;
		cin >> s >> t >> d;
		bf.add(s, t, d);
	}
	if (bf.calc(r)) {
		puts("NEGATIVE CYCLE");
	}
	else {
		auto d = bf.dist();
		for (int i = 0; i < V; i++) {
			if (d[i] == INF)
				puts("INF");
			else
				printf("%d\n", d[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 3320
class UnionFind():
    def __init__(self, n):
        # 正==子: 根の頂点番号 / 負==根: 連結頂点数
        self.n = n
        self.parents = [-1] * n
 
    def find(self, x):
        #要素xが属するグループの根を返す
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def union(self, x, y):
        #要素xが属するグループと要素yが属するグループとを併合する
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if self.parents[x] > self.parents[y]:
            x, y = y, x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    def size(self, x):
        # 要素xが属するグループのサイズ（要素数）を返す
        return -self.parents[self.find(x)]
 
    def same(self, x, y):
        # 要素x, yが同じグループに属するかどうかを返す
        return self.find(x) == self.find(y)
 
    def members(self, x):
        # 要素xが属するグループに属する要素をリストで返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
 
    def roots(self):
        # すべての根の要素をリストで返す
        return [i for i, x in enumerate(self.parents) if x < 0]
 
    def group_count(self):
        # グループの数を返す
        return len(self.roots())
 
    def all_group_members(self):
        # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        return {r: self.members(r) for r in self.roots()}
 
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m = map(int,input().split())
u = UnionFind(n)

for i in range(m):
    x,y,z = map(int,input().split())
    u.union(x-1,y-1)

ans = u.group_count()
print(ans)

Measured memory_bytes: 13664
using System;

class Atcoder93
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int k = int.Parse(input[1]);

        if (n % k == 0)
            Console.WriteLine("0");
        else
            Console.WriteLine("1");
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PB push_back
#define PPB pop_back
#define MP make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define loop(i,start,end) for(ll i=start; i<end; i++)
#define rloop(j,start,end) for(ll j=start-1; j>=end; j--)

int main()
{   
    IOS;

    ll h,w;
    cin>>h>>w;
	
  	ll mod=1e9+7;
    char c[h+1][w+1];
  
    loop(i,1,h+1)
        loop(j,1,w+1)
            cin>>c[i][j];

    ll dp[1005][1005];
    memset(dp,0,sizeof(dp));
	
  	dp[1][1]=1;
    loop(i,1,h+1)
    {
      loop(j,1,w+1)
        {
            if(c[i][j]=='.' && (i!=1 || j!=1))
                dp[i][j] = (dp[i-1][j]+dp[i][j-1])%mod;
        }
    }

    d1(dp[h][w]);
}

Measured memory_bytes: 9088
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void ARC068();

#if 1
int main()
{
	ARC068();
	fflush(stdout);
	return 0;
}
#endif

static void ARC068()
{
	int N;
	getint(N);

	std::map<int, int> amap;
	for (int i = 0; i < N; i++) {
		int ai;
		getint(ai);
		amap[ai]++;
	}

	int kind = amap.size();
	int even = 0, odd = 0;
	for (auto it = amap.begin(); it != amap.end(); it++) {
		if (it->second > 1) {
			if (it->second % 2) odd++;
			else even++;
		}
	}
	if (even % 2) {
		kind--;
	}
	printf("%d\n", kind);
}


Measured memory_bytes: 4992
def resolve():
    int(input())
    A = [int(i) for i in input().split()]
    ans = A[0]
    mmax = 10**18
    if 0 in A:
        print(0)
        return
    for a in A[1:]:
        ans = ans * a
        if ans > mmax:
            print(-1)
            return
    print(ans)


resolve()


Measured memory_bytes: 21700