akhauriyash/Code-Regression huggingface dataset:
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.{ArrayList, Collections, Comparator, List => JList}
import scala.math._

import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val a = input.split(" ").head.toLong - 1
    val b = input.split(" ").tail.head.toLong
    val c = input.split(" ").tail.tail.head.toLong
    val d = input.split(" ").tail.tail.tail.head.toLong
    val nc = b / c - a / c
    val nd = b / d - a / d
    val ncd = b / lcm(c, d) - a / lcm(c, d)

    (b - a - (nc + nd - ncd)).toString
  }

  def gcd(m: Long, n: Long): Long = n match {
    case 0 => m
    case _ => gcd(n, m % n)
  }
  def lcm(a: Long, b: Long): Long = a * b / gcd(a, b)

  val tests=List(
    """4 9 2 3""".stripMargin -> """2
                                   |""".stripMargin,
    """10 40 6 8""".stripMargin -> """23""".stripMargin,
    """314159265358979323 846264338327950288 419716939 937510582""" -> "532105071133627368"
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

Measured memory_bytes: 25532
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    long long int a,b,c,d; cin>>a>>b>>c>>d;
    long long int x[4];
    x[0] = a*c;
    x[1] = a*d;
    x[2] = b*c;
    x[3] = b*d;
    sort(x, x+4);
    cout<<x[3];
}

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

int main() {
  int X;
  cin >> X;
  int ans;
  const int N = 1000;
  vector<int> exp(N);
  exp.at(0) = 1;
  for (int b=2; b<32; b++) {
    for (int p=2; pow(b, p)<=X; p++) {
      exp.push_back(pow(b, p));
    }
  }
  sort(exp.begin(), exp.end());
  ans = exp.back();
  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))

iseq = [False] * (N+1)
for i in range(N):
  if P[i] == i+1: iseq[i] = True
iseq[N] = False
#print(iseq)

ans = 0
for i in range(N):
  if iseq[i] and iseq[i+1]:
    ans += 1
    iseq[i] = iseq[i+1] = False
  elif iseq[i]:
    ans += 1
    iseq[i] = False
#print(iseq)
print(ans)

Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

Int n, ans;
vector<Int> a;

Int solve(){
	if(a[0] != 0) return -1;
	Int res = 0;
	for(size_t i=1; i<a.size(); ++i){
//		cerr << i << " " << res << "\n";
		if(a[i] == 0) continue;
		if(a[i-1] + 1 < a[i]) return -1;
		size_t j=a[i];
		while(i+j-a[i]+1 < a.size() && a[i+j-a[i]+1] == (Int)j+1) ++j;
		res += j;
		i += j-a[i];
	}
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	a.resize(n);
	for(auto &i:a) cin >> i;
	cout << solve() << "\n";
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
string S; 
string temp;
long sum = 0;

void bits(int i,string x){
    if(i == S.size()-1){
        temp = "";
        temp += S[0];
        for(int j = 0; j < x.size(); j++){
            if(x[j] == '1'){
                sum += stol(temp);
                temp = "";
            }
            temp += S[j+1];                                                                                 
        }
        
        sum += stol(temp);
        
        return;
    }
    
    bits(i+1,x+"0");
    bits(i+1,x+"1");
}

int main(){
    cin >> S;
    bits(0,"");
    cout << sum << endl;
}

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

int main(){
  int n,count;
  cin >> n;
  vector<int> v(n);
  for(int i =0; i <n ; i++) {
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  count = 1;
  for(int i=0;i<n-1;i++){
    if(v.at(i) != v.at(i+1)){
      count++;
    }
  }
  
  cout << count << endl;
}


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif

bool func(int x){
    ostringstream oss;
    oss<<x;
    string s = oss.str();
    bool ret=true;
    rep(i,s.size()){
        if(s[i]!=s[s.size()-i-1])ret=false;
    }
    return ret;
}

signed main() {

    int a, b;
    cin >> a>>b;

    int ans=0;
    for(int i=a;i<=b;i++)
        if(func(i))ans++;
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)
//typedef pair < int, int> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
int digiter(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}
vector<int> convertstring(string s) {
	vector<int> d;
	ll n = s.size();
	rep(i, n) {
		d.push_back(s[i] - '0');
	}
	return d;
}
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;
}
vector<ll> divisor(ll n) {
	vector<ll>res;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i != 0)continue;
		res.push_back(i);
		if (i * i != n)res.push_back(n / i);
	}
	return res;
}

int N; string S;
ll sz[3];
int main()
{
	cin >> N >> S;
	ll res = 0;
	for (int pos = 0; pos < N; pos++) {
		for (int inter = 1; inter < N; inter++) {
			if (pos - inter < 0 || pos + inter >= N) { continue; };
			if (S[pos] != S[pos - inter] && S[pos] != S[pos + inter] && S[pos + inter] != S[pos - inter]) {
				res++;
			}
		}

	}
	rep(i, N) {
		if (S[i] == 'R')sz[0]++;
		else if (S[i] == 'G')sz[1]++;
		else if (S[i] == 'B')sz[2]++;
	}
	ll ans = sz[0] * sz[1] * sz[2];
	cout << ans - res << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

int N;
int a[10010];

int chain(int x, int c) {
	int l = x - 1, r = x + 1;
	while(1) {
		if(l == -1 && r == N) break;
		int ch_l = 0, ch_r = 0;
		int color;
		bool is_fir = 0; // 初回のみの判定

		// 初回
		if(l == x - 1 && r == x + 1) {
			color = c;
			is_fir = 1;
		}
		else if(l != -1) color = a[l];
		else color = a[r];

		// 初回でないとき　
		if(0 <= l && r < N && !is_fir && a[l] != a[r]) break;
		for(int i = l; i >= 0; i--) {
			if(color == a[i]) ch_l++;
			else break;
		}
		for(int i = r; i < N; i++) {
			if(color == a[i]) ch_r++;
			else break;
		}

		// 連鎖判定
		if(ch_l + ch_r >= 4 || (ch_l + ch_r >= 3 && is_fir)) {
			l -= ch_l;
			r += ch_r;
		} else {
			break;
		}
	}

	// 個数の計算
	if(l == x - 1 && r == x + 1) return N;
	return N - (r - l - 1);
}

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

    while(cin >> N, N) {
        rep(i, N) cin >> a[i];
	int ans = INF;
	rep(i, N) {
		rep(j, 3) chmin(ans, chain(i, j));
	}

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



Measured memory_bytes: 3300
from collections import Counter
n=int(input())
a=Counter(list(map(int,input().split())))
b=[i for i,j in a.items() if j>=2]+[0,0]
c=[i for i,j in a.items() if j>=4]+[0]
b.sort(reverse=True)
c.sort(reverse=True)
print(max(b[0]*b[1],c[0]**2))

Measured memory_bytes: 18600
n, x, m = map(int,input().split())

amari = [0]*m
v = [x]

cnt = 0
while True:
    xn_1 = x**2%m
    cnt += 1
    if x == 0:
        break
    amari[x] = xn_1
    if amari[xn_1]:
        break
    v.append(xn_1)
    x = xn_1

#print(v)

if 0 in v:
    ans = sum(v)
else:
    ind = v.index(xn_1)
    rooplen = len(v) - ind
    ans = sum(v[0:ind])
    l = n-ind
    if rooplen:
        ans += (l//rooplen)*sum(v[ind:])
        nokori = l - rooplen*(l//rooplen)
        ans += sum(v[ind:ind+nokori])
    
#print(v)
print(ans)

Measured memory_bytes: 69556
import sys
input = sys.stdin.readline

mod = 998244353
A, B, C, D = map(int, input().split())

dp = [[0] * (D+1) for _ in range(C+1)]
dp[A][B] = 1
for i in range(A, C+1):
    if i > A:
        dp[i][B] = dp[i-1][B] * B % mod
    for j in range(B+1, D+1):
        dp[i][j] = dp[i][j-1] * i + dp[i-1][j] * j - dp[i-1][j-1] * (i - 1) * (j - 1)
        dp[i][j] %= mod
print(dp[C][D])

Measured memory_bytes: 136756
use std::str::FromStr;
use std::io::stdin;

fn main() {
    let n = read::<i32>();
    let mut vec = read_vec::<i32>();
    vec.sort();
    let mut result = vec[0] as f64;
    for i in 1..n {
        result += vec[i as usize] as f64;
        result /= 2.0;
    }
    println!("{}", result);
}

fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).ok();
    line.trim().parse().ok().unwrap()
}

fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).ok();
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
n=int(input())
a=list(map(int,input().split()))
l=[0]*n
for i in range(n):
    l[a[i]]+=1
#print(l)
if n%2==1:
    if l[0]!=1:
        print(0)
        exit()
ans=1
for i in range(n):
    if n%2==0:
        if i%2==0:
            if l[i]!=0:
                print(0)
                exit()
    else:
        if i%2==1:
            if l[i]!=0:
                print(0)
                exit()
    
    if l[i]==2:
        ans*=2
    elif l[i]>2:
        print(0)
        exit()
    ans%=(10**9 +7)
print(ans)

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

int main(){
	unsigned n, a[100001];
	while( cin >> n , n ){
		for(int i=0 ; i < n ; i++ ){
			cin >> a[i];
		}
		sort( a , a+n );
		unsigned ans = 0;
		for(int i=0 ; i < n-1 ; i++ ){
			ans += a[i]*(n-i-1);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
import java.io.*;
import java.util.Scanner;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		char[] s = sc.next().toCharArray();
		
		int s1 = (s[0] - '0') * 10 + s[1] - '0';
		int s2 = (s[2] - '0') * 10 + s[3] - '0';

		boolean f1 = s2 <= 12 && s2 > 0;
		boolean f2 = s1 <= 12 && s1 > 0;
		if (f1 && f2) {
			pr.println("AMBIGUOUS");
		} else if (f1) {
			pr.println("YYMM");
		} else if (f2) {
			pr.println("MMYY");
		} else {
			pr.println("NA");
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }

//各桁の数の和を求める
template <typename T>
T digitsum(T n){
    int ketasuu=to_string(n).length();
    T sum=0;
    T d=1;
    for(T e=0;e<ketasuu;e++){
        sum+=(n/d)%10;d*=10;
    }
    return sum;
}

int main(){
    LL(a,n,m);
    ll e;
    int ans=0;
    for(ll i=1;i<=64;i++){
        e=intpow(i+a,n);
        if(e>m)break;
        if(digitsum(e)==i){
            ans++;
        }
    }
    out(ans);
}


Measured memory_bytes: 3308
# -*- coding:utf-8 -*-

N = int(input())
a = input().split()

gray = 0
brown = 0
green = 0
sky = 0
blue = 0
yellow = 0
orange = 0
red = 0
other = 0
for i in range(N):
	a[i] = int(a[i])

	if 1 <= a[i] and a[i] <= 399:
		gray = 1
	elif 400 <= a[i] and a[i] <= 799:
		brown = 1
	elif 800 <= a[i] and a[i] <= 1199:
		green = 1
	elif 1200 <= a[i] and a[i] <= 1599:
		sky = 1
	elif 1600 <= a[i] and a[i] <= 1999:
		blue = 1
	elif 2000 <= a[i] and a[i] <= 2399:
		yellow = 1
	elif 2400 <= a[i] and a[i] <= 2799:
		orange = 1
	elif 2800 <= a[i] and a[i] <= 3199:
		red = 1
	elif 3200 <= a[i]:
		other = other + 1

sum = gray + brown + green + sky + blue + yellow + orange + red

if sum > 1:
	min = sum
else:
	min = 1

max = sum + other

print(str(min) + " " + str(max))
		

Measured memory_bytes: 3064
//include
//------------------------------------------
#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 <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include<bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#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)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

    ll A[N];
    REP(i,N) cin >> A[i];
    priority_queue<ll> arr;
    REP(i,N) arr.push(A[i]);

    REP(i,M){
        int Am = arr.top();
        Am >>= 1;
        arr.pop();
        arr.push(Am);
    }

    ll ans = 0;
    REP(i,N){
        ans += arr.top();
        arr.pop();
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2168
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
using namespace std;

int main(void)
{
  int n, tmp;
  cin >> n;
  vector<int> w;
  while (cin >> tmp) {
    w.push_back(tmp);
  }
  int res = 0x7fffffff;
  for (int t = 2; t <= n; t++) {
    int mae = 0, usiro = 0;
    for (int j = 0; j < w.size(); j++) {
      if (j <= t - 1) {
        mae += w[j];
      } else {
        usiro += w[j];
      }
    }
    res = min(res, abs(mae - usiro));
  }
  cout << res << endl;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

K, A, B = MAP()

if A+1 >= B or A >= K:
	print(1 + K)
else:
	ans = A
	K -= A-1
	n, left = divmod(K, 2)
	ans += n*(B-A) + left
	print(ans)

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

int main(){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    if((s.at(0) == s.at(1))&&(s.at(2) == s.at(3))&&(s.at(0) != s.at(2))){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
k = int(input())

if k % 2 == 0:
    print('-1')
elif k % 5 == 0:
    print('-1')
else:
    n = 7
    ans = 1
    while n % k != 0:
        n = n * 10 + 7
        n %= k
        ans += 1
    
    print(ans)


Measured memory_bytes: 9168
k,x = map(int, input().split())
# 求める座標の数式は x - k + 1 <= 範囲 <= x + k - 1を満たす。
minP = x - k + 1
maxP = x + k - 1
numlist = list(range(minP, maxP + 1))
strlist = [str(letter) for letter in numlist]
print(" ".join(strlist))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
//#include<iostream>
using namespace std;
#define int long long

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};


int n;
string s[333];


signed main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
    cin>>n;
    rep(i,0,n){
        cin>>s[i];
    }
    int cnt=0;
   rep(k,0,n){
       bool can=true;
    rep(i,0,n){
        rep(j,0,n){
            
             
    
            if(s[(i+k)%n][j%n]!=s[(j+k)%n][i%n])can=false;
            
        }
       
    }
     if(can)cnt++;
    }
    cout<<cnt*n<<endl;
    
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long int
#define db double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define endl "\n"
#define mp make_pair
#define f first
#define s second
ll power(ll x, ll y){ ll ans = 1;x %= MOD;while(y){if(y&1)ans = (x * ans) % MOD;x = (x * x) % MOD;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;}
using namespace std;


int main() {
    fastio;
    string s, t;
    cin >> s >> t;
    
    for(int i = 0; i < s.length(); i++) {
        //cout << s[i] << " " << t[i] << endl;
        if(s[i] != t[i]) {
            cout << "No\n";
            return 0;
        } 
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 3656
n, k = map(int, input().split())
sunuke = [0] * n
ans = 0

for i in range(k):
    d = int(input())
    a_list = list(map(int, input().split()))
    for a in a_list:
        sunuke[a - 1] += 1

for s in sunuke:
    if s == 0:
        ans += 1

print(ans)


Measured memory_bytes: 9184
#include <bits/stdc++.h>  // ver1.9.5
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define Pii pair<int,int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a[a.size()-1]<<endl
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(8);
  int n,maxx,sum = 0,memo;
  cin >> n;
  Vi a(n);
  rep(i,0,n) {
    cin >> memo;
    sum += memo;
    a[i] = memo;
  }
  
  sort(ALL(a));
  reverse(ALL(a));
  
  int ans = 1;
  rep(i,0,n){
    maxx = a[i];
    sum -= a[i];
    if(maxx <= sum*2) ans++;
    else break;
  }
  cout << ans << endl;
  
  return 0;
}

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

int main()
{
    int n, d,x;cin>>n>>d>>x;
    
    int sum =0;
    for(int i =0;i <n;i++){
        int a;cin>>a;
        sum += (d - 1)/a+1;
    }
    cout << sum+x<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
li = [0]*2
cnt = 0
i = 0
prev = 0
A.sort(reverse=True)
while(i<N):
    if(prev == A[i]):
        if(li[0] != 0):
            li[1] = A[i]
            break
        else:
            li[0] = A[i]
            if(i+1>=N):
                break
            prev = A[i+1]
            i += 2
    else:
        prev = A[i]
        i += 1
print(li[0]*li[1])


Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define debug(args...) fprintf(stderr, args)
using namespace std;

const int MOD = 1e9 + 7;

typedef long long lint;

int main() {
    int n;
    vector<int> ps;
    cin >> n;
    for (int i = 2; i <= n; i++) {
        bool prime = true;
        for (int j = 2; prime && j * j <= i; j++) {
            if (!(i % j)) prime = false;
        }
        if (prime) ps.push_back(i);
    }
    lint ans = 1;
    for (int p : ps) {
        lint cnt = 0;
        for (int i = 2; i <= n; i++) {
            int j = i;
            while (!(j % p)) {
                cnt++;
                j /= p;
            }
        }
        ans = (ans * (1 + cnt)) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <sstream>
#include <set>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

int main() {
  ll n, s;
  while (cin >> n >> s) {
    ll d = n - s;

    // brute force
    for (ll b = 2; b <= 1000000; ++b) {
      ll sum = 0, now = n;
      while (now > 0) {
        sum += now % b;
        now /= b;
      }
      if (sum == s) {
        cout << b << endl;
        goto NEXT;
      }
    }

    // b is big value
    if (d >= 1) {
      vector<ll> cands;
      for (ll i = 1; i * i <= d; ++i) {
        if (d % i == 0) {
          cands.push_back(i + 1);
          cands.push_back(d / i + 1);
        }
      }
      ll ret = 1LL << 60;
      for (auto cand : cands) {
        if (cand < 1000000) continue;
        ll sum = n / cand + n % cand;
        if (sum == s) ret = min(ret, cand);
      }
      cout << ((ret == (1LL << 60)) ? -1 : ret) << endl;
    } else if (d == 0) {
      cout << n + 1 << endl;
    } else {
      cout << -1 << endl;
    }

NEXT:;
  }
}


Measured memory_bytes: 256
def main():
    n = list(map(int, input()[::-1])) + [0]
    s = 0
    res = 0
    for i, ni in enumerate(n[:-1]):
        k = ni + s
        if k < 5 or (k == 5 and n[i + 1] < 5):
            res += k
            s = 0
        else:
            res += 10 - k
            s = 1
    res += s
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18764
n = int(input())

x = 0

for i in range(1, n+1):
    if i%3 == 0:
        print(" {}".format(i), end ="")
    else:
        x = i
        while(x):
            if x%10 == 3:
                print(" {}".format(i), end = "")
                break
            x //= 10

print()




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

int main()
{
    int n,i,out=0,in;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>in;
        if((i%2!=0)&&(in%2!=0))
            out++;
    }
    cout<<out<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

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

    string s; cin >> s;
    int n = s.size();
    s = '0' + s + '0';

    vector<int> left(n+5, 0), right(n+5, 0);


    for(int i=2; i<=n; ++i){
        if(s[i] == 'L') left[i] = left[i-1]+1;
        else left[i] = 0;
    }

    for(int i=n-1; i>=1; --i){
        if(s[i] == 'R') right[i] = right[i+1]+1;
        else right[i] = 0;
    }

    vector<int> ans(n+1, 0);
    for(int i=1; i<=n; ++i){
        if(s[i] == 'R'){
            int cnt = right[i];
            if(cnt%2 == 0) ++ans[i+cnt];
            else ++ans[i+cnt-1];
        }
        else if(s[i] == 'L'){
            int cnt = left[i];
            if(cnt%2 == 0) ++ans[i-cnt];
            else ++ans[i-cnt+1];
        }
    }

    for(int i=1; i<=n; ++i){
        if(i != 1) cout << " ";
        cout << ans[i]; 
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1772
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vv vector<ll>
#define pp pair<ll,ll>
#define ff first
#define ss second
#define vp vector<pp>
#define ld long double
#define pb push_back
#define mp make_pair

int main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    vector<ll> p[n+1];
    for(ll i=0;i<m;i++)
    {
    	ll x,y,w;
    	cin>>x>>y>>w;
    	p[x].pb(y);
    	p[y].pb(x);
	}
	ll ans[n+1];
	memset(ans,-1,sizeof(ans));
	ll k=0;
	for(ll j=1;j<=n;j++)
	{
		if(ans[j]==-1)
		{
		  k++;
	     ans[j]=1;
	     queue<ll> q;
	     q.push(j);
	     while(!q.empty())
	     {
		   ll x=q.front();
		   q.pop();
		//cout<<x<<endl;
		for(ll i=0;i<p[x].size();i++)
		{
			if(ans[p[x][i]]==-1)
			{
				ans[p[x][i]]=1;
				q.push(p[x][i]);
			}
		}
	    }
       }
}
	cout<<k;
    return 0;
}

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


int main(){
    string s , t;
    cin >> s >> t;
    t.pop_back();
    if(s == t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main() {
  int A[1000010];
  int n, L;
  cin >> n >> L;
  for (int i = 0; i < n; ++i)
    cin >> A[i];
  deque<int> q;
  int f = 0, b = 0;
  for (; f < L - 1; ++f) {
    while (!q.empty() and A[f] < q.back())
      q.pop_back();
    q.push_back(A[f]);
  }
  for (; f < n; ++f, ++b) {
    while (!q.empty() and A[f] < q.back())
      q.pop_back();
    q.push_back(A[f]);
    if (b)
      cout << " ";
    cout << q.front();
    if (A[b] == q.front())
      q.pop_front();
  }
  cout << endl;
}


Measured memory_bytes: 7164
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <random>
using namespace std;
int main() {
  string s;
  cin >> s;
  for (int i = 0; i < 15; i++) {
	  s += 'o';
	}
  int w = 0;
  for (int i = 0; i < 15; i++) {
	  if (s[i] == 'o') {
		  w++;
		}
	}
  if (w >= 8) {
	  cout << "YES\n";
	} else {
	  cout << "NO\n";
	}
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

int n, a[100005];
unordered_map<int, int> counts;

int main(){
    scanf("%i", &n);
    for(int i = 0; i < n; i++){
        scanf("%i", a+i);
        if(counts.find(a[i])==counts.end()){
            counts[a[i]] = 1;
        }else{
            counts[a[i]]++;
        }
    }
    sort(a, a+n, greater<int>());
    long long res, longest=-1;
    for(int i = 0; i < n; i++){
        if(counts[a[i]]>1){
            if(longest==-1){
                longest = a[i];
                counts[a[i]] -= 2;
            }
            else{
                res = longest*a[i];
                printf("%lli", res);
                return 0;
            }
        }
    }
    printf("0");
}

Measured memory_bytes: 4772
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

//素因数分解
template<typename T>
map<T, T>prime_fact(T n) {
	map<T, T>mp;
	for (unsigned long long i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			mp[i]++;
		}
	}
	if (n != 1) {//sqrt(n)を超えた素数を処理(あっても1つ)
		mp[n]++;
	}
	return mp;
}

int main(){
    ll n,p;
    cin>>n>>p;
    map<ll,ll>mp=prime_fact<ll>(p);
    ll maxv=1;
    for(auto x:mp){
        if((ll)x.second>=n){
            maxv*=(ll)pow(x.first,x.second/n);
        }
    }
    cout<<maxv<<endl;
    return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
import re
from collections import deque
import sys
import math
input = sys.stdin.readline


def int_raw():
    return int(input())

def str_in():
    return input().strip("\n")

def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.mini = [i for i in range(n+1)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
        mini = min(self.mini[x],self.mini[y])
        self.mini[x]=mini
        self.mini[y]=mini
    
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

def main():
    a = int_raw()
    s = input().strip("\n")
    return s if a >=3200 else "red"

    
print(main())


Measured memory_bytes: 38256
#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;

struct ge
{
	int x;
	int y;
};

int h,w,n,sx,sy,ex,ey,ans;
int a[1010][1010];
int b[1010][1010];
int xx[]={-1,1,0,0};
int yy[]={0,0,-1,1};
int x[11];            //奶酪厂的横坐标数组 
int y[11];            //奶酪厂的纵坐标数组 

int main()
{
	cin>>h>>w>>n;
	memset(a,0,sizeof(a));
	queue<ge> q;
	bool flag = false;
	ans = 0;
	for(int i = 1;i <= h;i++)
	{
		for(int j = 1;j <= w;j++)
		{
			char c;
			cin>>c;
			if(c == 'S')
			{
				a[i][j] = 1;
				x[0] = i;y[0] = j;
			}
			else if(c >= '1'&&c <= '9')
			{
				a[i][j] = 1;
				x[c-'0'] = i;
				y[c-'0'] = j;
			}
			else if(c == '.')
			{
				a[i][j] = 1;
			}
			else
			    ;
		}
	}
	for(int i = 1;i <= n;i++)
	{
		flag = false;
		memset(b,-1,sizeof(b));
		while(!q.empty())
		{
			q.pop();
		}
		sx = x[i-1];sy = y[i-1];
		b[sx][sy] = 0;
		ex = x[i];ey = y[i];
		ge g;
		g.x = sx;g.y = sy;
		q.push(g); 
		while(!q.empty()&&flag == false)
		{
			ge now = q.front();
			q.pop();
			for(int i = 0;i < 4;i++)
			{
				int dx,dy;
				dx = now.x + xx[i];
				dy = now.y + yy[i];
				if(dx >= 1&&dx <= h&&dy >= 1&&dy <= w&&a[dx][dy] == 1)  //可以通过 
				{
					if(b[dx][dy] != -1)     //已经访问过 
					{
						continue;
					}
					else
					{
						b[dx][dy] = b[now.x][now.y] + 1;
						if(dx == ex&&dy == ey)
						{
							flag = true;
							ans = ans + b[dx][dy];
							break;
						}
						else
						{
							g.x = dx;g.y = dy;
							q.push(g); 
						}
					}
				}
			}
		}
		
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 11124
N = int(input())
A = list(map(int, input().split()))  #数字

for i in range(N):
    if A[i] % 2 == 0:
        if A[i] % 3 != 0 and A[i] % 5 != 0:
            print("DENIED")
            exit()

print("APPROVED")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


int main() {
//    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


   int n, m;
   cin >> n >> m;
   string a[n];
   for (int i = 0; i < n; i++) cin >> a[i];

   int ans = 0;
   vector<int> row[n], col[m];
   for (int i = 0; i < n; i++) {
       for (int j = 0; j < m; j++) {
           if (a[i][j] == '#') {
               row[i].pb(j);
               col[j].pb(i);
           }
       }
   }

   int left, right, up, down;
   int ans1, ans2;
   for (int i = 0; i < n; i++) {
       for (int j = 0; j < m; j++) {
           if (a[i][j] == '#') continue;

           if (row[i].empty()) {
               ans1 = m;
           }

           else {
               if (j < row[i][0]) {
                   ans1 = row[i][0];
               }

               else if (row[i].back() < j) {
                   ans1 = m - 1 - row[i].back();
               }

               else {
                   auto it = upper_bound(row[i].begin(), row[i].end(), j);
                   right = *it;
                   it--;
                   left = *it;
                   ans1 = right - left - 1;
               }
           }



           if (col[j].empty()) {
               ans2 = n;
           }

           else {
               if (i < col[j][0]) {
                   ans2 = col[j][0];
               }

               else if (col[j].back() < i) {
                   ans2 = n - 1 - col[j].back();
               }

               else {
                   auto it = upper_bound(col[j].begin(), col[j].end(), i);
                   up = *it;
                   it--;
                   down = *it;
                   ans2 = up - down - 1;
               }
           }

           ans = max(ans, ans1 + ans2 - 1);


       }
   }

   cout << ans;



}




Measured memory_bytes: 38656
#include <bits/stdc++.h>
struct UnionFind {
public:
  int n;
  std::vector<int> par;
  UnionFind(int n): n(n) {
    par.resize(n, -1);
  }
  int root(int x) {
    return par[x] < 0 ? x : par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    int rx = root(x), ry = root(y);
    if(rx == ry) return;
    if(par[rx] < par[ry]) {
      std::swap(x, y);
      rx = root(x), ry = root(y);
    }
    par[rx] += par[ry];
    par[ry] = rx;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return -par[root(x)];
  }
};
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template<typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template<typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(int i=0;i<((int)(v.size()));++i) {
    if (i) os << " ";
    os << v[i];
  }
  return os;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, m;
  cin >> n >> m;
  vvi g(n, vi(n)), compg(n, vi(n));
  for(int i=0;i<(m);++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a][b] = 1;
    g[b][a] = 1;
  }
  UnionFind uf(n);
  for(int i=0;i<(n);++i) {
    for(int j=0;j<(n);++j) {
      if (i != j && !g[i][j]) {
        compg[i][j] = 1;
        uf.unite(i, j);
      }
    }
  }
  vi col(n, -1);
  bool bipartite = true;
  queue<int> que;
  for(int i=0;i<(n);++i) {
    if(col[i] != -1) continue;
    que.push(i);
    col[i] = 0;
    while (!que.empty()) {
      if (!bipartite) break;
      int now = que.front();
      que.pop();
      for(int j=0;j<(n);++j) {
        if (compg[now][j]) {
          if (col[j] == -1) {
            col[j] = !col[now];
            que.push(j);
          } else if (col[now] == col[j]) {
            bipartite = false;
            break;
          }
        }
      }
    }
  }
  if (!bipartite) {
    cout << -1 << endl;
    return 0;
  }
  map<int, P> mp;
  for(int i=0;i<(n);++i) {
    int r = uf.root(i);
    if (col[i]) mp[r].first++;
    else mp[r].second++;
  }
  vector<set<int>> dp((int)(mp.size()) + 1);
  dp[0].insert(0);
  int idx = 0;
  for (auto &e1: mp) {
    for (auto &e2: dp[idx]) {
      dp[idx + 1].insert(e1.second.first + e2);
      dp[idx + 1].insert(e1.second.second + e2);
    }
    idx++;
  }
  ll mi = LINF;
  for (auto &e: dp[idx]) {
    chmin(mi, e * (e - 1) / 2 + (n - e) * (n - e - 1) / 2);
  }
  cout << mi << endl;
}


Measured memory_bytes: 15744
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=505;
int mp[MAXN][MAXN],n;
void solve(int l,int r,int dep)
{
	if(l>=r)return ;
	int mid=(l+r)/2;
	for(int i=l;i<=mid;i++)for(int j=mid+1;j<=r;j++)
		mp[i][j]=dep;
	solve(l,mid,dep+1);solve(mid+1,r,dep+1);
}
int main()
{
	n=read();
	solve(1,n,1);
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)pr1(mp[i][j]);
		puts("");
	}
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<62;
constexpr double eps = (1e-9);

bool isGood(ll& N, ll& M, ll& V, ll& P, vector<ll>& A, ll& x) {
     if (x < P) return true;
     ll now = A[x] + M;
     if (A[P - 1] > now) return false;
     ll score = 0;
     score += (P - 1) * M;
     score += (N - x) * M;
     for (ll i = P - 1; i < x ; i++) {
         score += min(M, max(0LL, now - A[i]));
     }
     return score >= M * V;
 }

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

  ll n, m, v, p;
  cin >> n >> m >> v >> p;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.rbegin(), a.rend());

  ll lb = p-1;
  ll ub = n;

  while (ub - lb > 1) {
    ll mid = lb + (ub - lb) / 2;
    if (isGood(n, m, v, p, a, mid)) lb = mid;
    else ub = mid;
  }

  cout << lb + 1 << endl;

  return 0;
}


Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	for(int i=0;i<101;i++){
		for(int j=0;j<101;j++){
			if(4*i+7*j==n){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import math
from functools import reduce
from operator import mul
sys.setrecursionlimit(10**6)

def InMap(): return list(map(int, sys.stdin.readline().split(' ')))
def In(): return int(sys.stdin.readline())
def InS(): return sys.stdin.readline()

N = In()
A = InMap()

A.sort()
if A[0] == 0:
    print(0)
    sys.exit()
res = 1
for i in A:
    res *= i
    if res > 1000000000000000000:
        print(-1)
        sys.exit()
print(res)

Measured memory_bytes: 22624