akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main implements Runnable {
	public static void main (String[] args) {new Thread(null, new Main(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		int n = fs.nextInt();
		int it = 0;
		for(int i = 1; i <= n; i++) {
			int x = fs.nextInt();
			if(x != i) it++;
		}
		if(it == 0 || it == 2) out.println("YES");
		else out.println("NO");
		
		out.close();
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}

Measured memory_bytes: 23380
#include <iostream>
using namespace std;
int n,a,b,ans=0;

int main(){
    scanf("%d", &n);
    bool is_yes = 0;
    while(n--){
        scanf("%d%d", &a, &b);
        if(a == b){
            if( 3 == ++ans)  is_yes=1;
        } else{
            ans =0;
        }
    }
    printf("%s",is_yes ? "Yes" : "No");
    return 0;
}

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

int main(){
  int N,K,n = 1;
  cin >> N >> K;
  
  for(int i = 0;i<N;i++){
  
  if(2*n<n+K)
    n*=2;
  
  else
    n+=K;
  }
  
  cout <<n<<endl;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
#define F first
#define S second
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){
    string s;
    cin >> s;
    if(s.size() == 2){
        cout << s << endl;
    }else{
        cout << s[2] << s[1] << s[0] << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=1e4+5;
int n,a[N],b[N];
set<int> ans;
inline int gcd(ri x,ri y){
	return !y?x:gcd(y,x%y); 
}
inline bool isprime(ri x){
	for(ri i=2;i*i<=x;++i)
		if(x%i==0)
			return false;
	return true;
}
inline bool check(ri p){ // $ x^p - x $
//	printf("check %d\n",p);
	ri i;
	for(i=n;i>=0;--i) b[i]=(a[i]%p+p)%p;
	for(i=n;i>=p;--i)
		b[i-p+1]=(b[i-p+1]+b[i]+p)%p;
	for(;i>=0;--i)
		if(b[i]) return false;
	return true;
}
int main(){
	ri i,d;
	gi(n);
	d=0;
	for(i=n;i>=0;--i)
		gi(a[i]),d=gcd(abs(a[i]),d);
//	printf("d = %d\n",d);
	for(i=2;i*i<=d;++i)
		if(d%i==0){
			ans.insert(i);
			d/=i;
			while(d%i==0)
				d/=i;
		}
	if(d>1) ans.insert(d);
	for(i=2;i<=n;++i)
		if(ans.find(i)==ans.end()&&isprime(i)&&check(i))
			ans.insert(i);
	for(auto o:ans) print(o),putc('\n');
	return 0;
}

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

struct Point {double x, y; };

void coch(Point p1, Point p2, int n) {
  double th = M_PI * 60.0 / 180.0;

  if (n == 0)
    return;

  Point s, t, u;

  s.x = (2 * p1.x + p2.x) / 3;
  s.y = (2 * p1.y + p2.y) / 3;

  t.x = (p1.x + 2 * p2.x) / 3;
  t.y = (p1.y + 2 * p2.y) / 3;

  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  coch(p1, s, n - 1);
  printf("%.8f %.8f\n", s.x, s.y);

  coch(s, u, n - 1);
  printf("%.8f %.8f\n", u.x, u.y);

  coch(u, t, n - 1);
  printf("%.8f %.8f\n", t.x, t.y);

  coch(t, p2, n - 1);

}

int main() {
  int n;
  Point a, b;

  a.x = 0;
  a.y = 0;

  b.x = 100;
  b.y = 0;

  cin >> n;

  printf("%.8f %.8f\n", a.x, a.y);
  coch(a, b, n);
  printf("%.8f %.8f\n", b.x, b.y);

  return 0;

}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){fastio
    ll n;cin>>n;
    string s;cin>>s;
    ll a[2*n];a[0]=0;
    ll b[2];rep(i,0,1)b[i]=0;
    b[0]++;
    rep(i,1,2*n-1){
        if(s[i]==s[i-1]){
            a[i]=1-a[i-1];
        }else{
            a[i]=a[i-1];
        }
        b[a[i]]++;
    }
    
    if(b[0]!=n || s[0]=='W' || s[2*n-1]=='W'){
        cout<<0<<endl;
        return 0;
    }
    
    ll sum=0;
    ll ans=1;
    rep(i,1,n){
        ans=mod(ans*i);
    }
    rep(i,0,2*n-1){
        //cout<<a[i];
        if(a[i]==0){
            sum++;
        }else{
            ans=mod(ans*sum);
            sum--;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}




Measured memory_bytes: 2196
N = int(input())
L = [tuple(map(int, input().split())) for _ in range(N)]

def get_H(Cx, Cy):
    for x, y, h in L:
        if h == 0:
            continue
        H = h + abs(x - Cx) + abs(y - Cy)
        if H >= 1:
            return H

def check(Cx, Cy, H):
    for x, y, h in L:
        if h != max(H - abs(x - Cx) - abs(y - Cy), 0):
            return False
    return True

for Cx in range(101):
    for Cy in range(101):
        H = get_H(Cx, Cy)
        if check(Cx, Cy, H):
            print(Cx, Cy, H)
            quit()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
inline void chmin(T &a, T b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, T b) { a = max(a, b); }
template <class T>
inline bool kbit(T &x, int k) { return ((x >> k) & 1LL); }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
void debug() { cerr << "ok" << endl; }
template <class T>
void printv(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void readv(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    V<ll> a(n);
    readv(a);
    map<ll, ll> mp;
    ll res = 0;
    for (ll i = 0; i < n; i++) {
        res += mp[a[i] - i];
        mp[-(i + a[i])]++;
    }
    cout << res << '\n';
}

Measured memory_bytes: 27432
n = int(input())
a = [int(s) for s in input().split()]
m = int(input())
b = [int(r) for r in input().split()]

for i in range(m):
    h = a[b[i]-1] + 1
    if a.count(h) == 0 and h != 2020:
        a[b[i]-1] = h
for t in a:
    print(t)


Measured memory_bytes: 5616
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using static System.Console;
using static System.Math;
class Simple
{
    int N;
    int[] A;
    void Solve() {
        //input
        N = io.Int;
        A = new int[N];
        for (int i = 0; i < N; ++i)
            A[i] = io.Int;
        var dic = new Dictionary<int, int>();
        foreach (var v in A) {
            if (!dic.ContainsKey(v)) dic[v] = 0;
            dic[v]++;
        }
        var twoOrMore = dic.Where(kp => kp.Value >= 2).
            Select(kp => kp.Key).OrderByDescending(v => v).ToArray();
        var fourOrMore = dic.Where(kp => kp.Value >= 4).
            Select(kp => kp.Key).OrderByDescending(v => v).ToArray();
        var ans = 0L;
        if (twoOrMore.Length >= 2 && fourOrMore.Length >= 1) {
            ans = Max((long)twoOrMore[0] * twoOrMore[1],
                      (long)fourOrMore[0] * fourOrMore[0]);
        } else if (twoOrMore.Length >= 2) {
            ans = (long)twoOrMore[0] * twoOrMore[1];
        } else if (fourOrMore.Length >= 1) {
            ans = (long)fourOrMore[0] + fourOrMore[0];
        }
        //ret
        WriteLine(ans);
    }

    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) => new Simple().Stream();
    private void Stream() {
        //var exStdIn = new System.IO.StreamReader("stdin.txt");
        //SetIn(exStdIn);
        Solve();
        io.Flush();
    }
}
class SimpleIO
{
    string[] _nextBuffer;
    int _bufferCnt;
    char[] cs = new char[] { ' ', '"', ',' };
    StreamWriter sw = new StreamWriter(OpenStandardOutput()) {
        AutoFlush = false
    };
    public SimpleIO() {
        _nextBuffer = new string[0];
        _bufferCnt = 0;
        SetOut(sw);
    }
    string Next() {
        if (_bufferCnt < _nextBuffer.Length)
            return _nextBuffer[_bufferCnt++];
        var st = ReadLine();
        while (st == "")
            st = ReadLine();
        if (st != null)
            _nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        else
            st = "";
        _bufferCnt = 0;
        return _nextBuffer[_bufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void Flush() => Out.Flush();
}


Measured memory_bytes: 24800
x = str(input())
r = set([])
r.add(x[0])
r.add(x[1])
r.add(x[2])
r.add(x[3])
if len(r) == 2:
    t = list(r)
    a = x.count(t[0])
    b = x.count(t[1])
    if a == 2 and b == 2:
        print("Yes")
    else:
        print("No")
else:
    print("No")


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;

// 𝑂(𝑁*log(log 𝑁))
vector<int> eratosthenes(int N)
{
    vector<int> res;
    vector<bool> prime(N + 1, 1);
    prime[0] = prime[1] = false;
    for (int i = 2; i * i <= N; ++i)
    {
        if (prime[i] == true)
        {
            for (int j = 2 * i; j <= N; j += i)
            {
                prime[j] = false;
            }
        }
    }
    for (int i = 0; i <= N; ++i)
    {
        if (prime[i] == true)
            res.push_back(i);
    }
    return res;
}

ll n;

int main()
{
    auto p = eratosthenes(100000000);
    while (cin >> n)
    {
        if (n == 0)
            return 0;
        ll ans = 0;
        for (int i = 0; i < n; i++)
        {
            ans += p[i];
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 47920
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    int z = sc.nextInt();
    int sum = x*100 + y*10 + z;
    if(sum % 4 == 0) System.out.println("YES");
    else System.out.println("NO");
 
  }
}

Measured memory_bytes: 21716
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
typedef struct E{
	int to;
	struct E *next;
}edge;
int N, M, ans;
bool d[1<<17];
edge G[1<<17], *nil;
void push(int i, int j){
	edge *X = (edge*)malloc(sizeof(edge));
	(*X).to = j;
	(*X).next = G[i].next;
	G[i].next = X;
	return;
}
void dfs(int i){
	d[i] = true;
	edge *x = G[i].next;
	while(x != nil){
		if(!d[(*x).to]){
			dfs((*x).to);
		}
		x = (*x).next;
	}
	return;
}
int main(){
	scanf("%d%d", &N, &M);
	for(int i=0; i<=N; i++){
		G[i].next = nil;
	}
	while(M--){
		int a, b;
		scanf("%d%d%*d", &a, &b);
		push(a, b);
		push(b, a);
	}
	for(int i=1; i<=N; i++){
		if(!d[i]){
			ans++;
			dfs(i);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 12712
s = input()
k = int(input())

tmp = '0'
count = 0
for x in s:
	if tmp == x:
		count += 1
		tmp = '0'
	else:
		tmp = x
if tmp == s[0]:
	start_count = 0
	for x in s:
		if tmp != x:
			break
		start_count += 1
	if start_count == len(s):
		print((len(s)*k)//2)
	else:
		print((count+start_count%2)*k-start_count%2)
else:
	print(count*k)

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

int main(void) {
	using namespace std;
	const long long INF = 1e15;
	int N;
	cin >> N;
	vector<int> a;
	priority_queue<int, vector<int>, greater<int>> former;
	priority_queue<int> latter;
	vector<long long> former_sums(N + 1, 0);
	vector<long long> latter_sums(N + 1, 0);
	for(int i = 0; i < N; ++i) {
		int t;
		cin >> t;
		a.push_back(t);
		former.push(t);
		former_sums[0] += t;
	}
	for(int i = 0; i < N; ++i) {
		int t;
		cin >> t;
		a.push_back(t);
	}
	for(int i = 0; i < N; ++i) {
		int t;
		cin >> t;
		a.push_back(t);
		latter.push(t);
		latter_sums[N] += t;
	}
	for(int k = 0; k < N; ++k) {
		former_sums[k + 1] = former_sums[k];
		former_sums[k + 1] += a[N + k];
		former.push(a[N + k]);
		former_sums[k + 1] -= former.top();
		former.pop();
		latter_sums[N - k - 1] = latter_sums[N - k];
		latter_sums[N - k - 1] += a[2 * N - k - 1];
		latter.push(a[2 * N - k - 1]);
		latter_sums[N - k - 1] -= latter.top();
		latter.pop();
	}
	long long result = -INF;
	for(int k = 0; k <= N; ++k) {
		if(result < former_sums[k] - latter_sums[k]) {
			result = former_sums[k] - latter_sums[k];
		}
	}
	cout << result << '\n';
	return 0;
}



Measured memory_bytes: 4976
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;
int main() {
	int n; cin >> n;
	vector<int>a(n);
	vector<int>b(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		b[i] = a[i];
	}

	sort(a.begin(), a.end());
	int max_e = a[n-1];

	for (int i = 0; i < n;++i) {
		if (b[i] == max_e)cout << a[n-2]<<endl;
		else cout << a[n-1] << endl;
	}

	return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
const int limit = 200050;

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

    int a[limit];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i] = a[i] - i - 1;
    }

    sort(a, a + n);

    int b = (n % 2 == 0) ? a[n / 2 - 1] : a[(n + 1) / 2 - 1];

    long long f = 0;
    for(int i = 0; i < n; i++) f += abs(a[i] - b);

    cout << f << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N; cin >> N;
    vector<int> A(N);

    for(auto &it : A){
        cin >> it;
    }

    vector<bool> chk(1e9+1);

    for(int i=0; i<N; i++){
        if(chk.at(A.at(i)) == true){
            cout << "NO" << endl;
            return 0;
        }else{
            chk.at(A.at(i)) = true;
        }
    }

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

Measured memory_bytes: 123136
import sys

# 前処理
N = int(input())
points = list(map(int, input().split()))

# 中央 -1 , +1のそれぞれの値x,yを求める
s_points = sorted(points)
x = s_points[int(N/2) - 1]
y = s_points[int(N/2)]

# 二つとも同じ数aなら、N回a出力して終わり
if x == y:
    for _ in range(N): 
        print(x)
    sys.exit()

# それ以外であれば、x<= であればyを、y>= であればxを出力する
for point in points:
    if x >= point:
        print(y)
    else:
        print(x)

Measured memory_bytes: 26772
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
using namespace std;
const int INF = 1e9;
typedef long long ll;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}


int main() {
	int a=0,b=0;
  for(int i=0;i<3;i++){
    int input;
    cin >> input;
    if(input==5)a++;
    if(input==7)b++;
  }
  if(a==2&&b==1)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};



int main(){
  string n;
  cin>>n;
  for(int t=0;t<3;t++){
    if(n[t]=='1'){
      n[t]='9';
      continue;
    }
    if(n[t]=='9'){
      n[t]='1';
    }
  }
  cout<<n<<"\n";

  return 0;
}


Measured memory_bytes: 764
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = sc.nextInt();
        long[] arr = new long[n];

        BigDecimal bd = new BigDecimal(1);

        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextLong();
            if (arr[i] == 0) {
                System.out.println(0);
                return;
            }
        }

        BigDecimal bdLimit = new BigDecimal(1e18);

        for (int i = 0; i < n; i++) {
            bd = bd.multiply(new BigDecimal(arr[i]));
            if (bd.compareTo(bdLimit) == 1) {
                System.out.println(-1);
                return;
            }
        }
        System.out.println(bd.longValue());

        // out.println("Hello World");
        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


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

int main()
{
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  for (int i = 0; i < h; i++)
  {
    cin >> v.at(i);
  }
  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      if(v.at(i).at(j) == '#') continue;
      int count = 0;
      for (int k = i-1; k < i+2; k++)
      {
        for (int l = j-1; l < j+2; l++)
        {
          if(k < 0 || l < 0 || k > h-1 || l > w-1 || (k == i && l == j)) continue;
          if(v.at(k).at(l) == '#') count++;
        }
      }
      v.at(i).at(j) = count + '0';
    }
  }
  for (int i = 0; i < h; i++)
  {
    cout << v.at(i) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
int n, cnt, ans, a[81][81], b[81][81], c, d, tmp, m, h, w, x, y, sum, k, q;
bool dp[81][81][640 * 80 + 1];

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

  cin >> h >> w;
  rep(i, h) rep(j, w) cin >> a[i][j];
  rep(i, h) rep(j, w) cin >> b[i][j];
  dp[1][1][abs(a[0][0] - b[0][0])] = true;

  rrep(i, 1, h + 1) {
    rrep(j, 1, w + 1) {
      rep(k, 640 * 80 + 1) {
        if (dp[i - 1][j][k + abs(a[i - 1][j - 1] - b[i - 1][j - 1])] ||
            dp[i - 1][j][abs(k - abs(a[i - 1][j - 1] - b[i - 1][j - 1]))] ||
            dp[i][j - 1][k + abs(a[i - 1][j - 1] - b[i - 1][j - 1])] ||
            dp[i][j - 1][abs(k - abs(a[i - 1][j - 1] - b[i - 1][j - 1]))] ||
            dp[i][j][k]) {
          dp[i][j][k] = true;
        }
      }
    }
  }

  rep(i, 640 * 80 + 1) {
    if (dp[h][w][i] == true) {
      Cout(i);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 324096
N = int(input())
a, b = [], []
for i in range(N):
    s, t = input().split()
    s = float(s)
    a.append(s)
    b.append(t)

ans = 0
for i in range(N):
    if b[i] == 'JPY':
        ans += a[i]
    else:
        ans += 380000.0 * a[i]
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const int maxc = 26;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-8;
inline int read(){
    int 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 - 48;ch = getchar();}
    return f * x;
}
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll qw(ll x,ll y){ll ans = 1;while(y){if(y&1) ans *= x;x *= x;y >>= 1;}return ans;}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool is_prime(ll x){if(x <= 1) return 0;for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;	}
ll n;
void solve(){
	cout << n * (n-1) / 2 << endl;
}
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;	
	solve();
	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
uint64_t gcd(uint64_t x,uint64_t y){
    uint64_t r;
    while(y>0){
        if(x<y) swap(x,y);
      	r=x%y, x=y, y=r;
    }
    return x;
}
int main(){
    int N;
    uint64_t T,ans=1;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>T;
        ans*=T/gcd(T,ans);
    }
    cout<<ans<<endl;
 }

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

int gcd(int a, int b)
{

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

int main() {
	

	int k,ans,gcd1,gcd2;
	cin >> k;
	
	ans = 0;

	for (int a = 1; a <= k; a++)
	{
		for (int b = 1; b <= k; b++)
		{
			for (int c = 1; c <= k; c++)
			{
				gcd1 = gcd(a, b);
				gcd2 = gcd(gcd1, c);

				ans += gcd2;
			}
		}
	}
	
	

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 3640
//
//  main.cpp
//  Atcoder1
//
//  Created by Hamske on 2020/09/17.
//  Copyright © 2020 Author. All rights reserved.
//

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>

using namespace std;

//#define pb push_back
//#define mp make_pair
//
//#define F first
//#define S second

typedef long long ll;

#define rept(_i,iv,n,type) for(type _i=(type)(iv);_i<(type)(n);++_i)
//#define repi(_i,iv,n) rept(_i,iv,n,int)
//#define repl(_i,iv,n) rept(_i,iv,n,ll)

#define rept0(_i,n,type) rept(_i,0,n,type)
#define repi0(_i,n) rept(_i,0,n,int)
#define repl0(_i,n) rept(_i,0,n,ll)

//#define repst(_i,iv,n,type) for(type _i=iv;_i<=(type)(n);++_i)
//#define repsi1(_i,n) repst(_i,1,n,int)

#define REPT(_i,iv,_l,n,type) for(type _i=(type)(iv),_l=(type)(n);_i<_l;++_i)
//#define REPI(_i,iv,_l,n) REPT(_i,iv,_l,n,int)
//#define REPL(_i,iv,_l,n) REPT(_i,iv,_l,n,ll)
//
#define REPT0(_i,_l,n,type) REPT(_i,0,_l,n,type)
#define REPI0(_i,_l,n) REPT(_i,0,_l,n,int)
#define REPL0(_i,_l,n) REPT(_i,0,_l,n,ll)


//#define rrept(_i,x,e,type) for(type _i=((type)(x)-1);_i>=e;--_i)
//
//#define rrept0(_i,x,type) rrept(_i,x,0,type)
//
//#define RREPT(_i,x,_e,e,type) for(type _i=((type)(x)-1),_e=(type)(e);_i>=_e;--_i)
//
//#define RREPT0(_i,x,_e,type) RREPT(_i,x,_e,0,type)
//
//#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

//#define all(x) (x).begin(),(x).end()
#define REPV(v,_itr,_end) for(auto _itr=(v).begin(),_end=(v).end();_itr!=_end;++_itr)
#define REPVC(v,_itr,_end) for(auto _itr=(v).cbegin(),_end=(v).cend();_itr!=_end;++_itr)

#define td typedef
//#define tds(stl,type,name) typedef stl<type > name;
#define tdv(type,name) typedef vector<type > name;


//typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vb > vvb;
typedef vector<int> vi;
typedef vector<vi > vvi;
//typedef vector<ll> vll;
//typedef vector<vll > vvll;

int main(int argc, const char * argv[]) {
    string S;
    cin>>S;
    int len=(int)S.length();
    if(S[len-1]=='s'){
        S+="es";
    }else{
        S+="s";
    }
    cout<<S<<endl;
    return 0;
}


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


int main() {
    
    int n;
    cin>>n;
    vector<int> vec(n,0);
    for(int i=0;i<n;i++)cin>>vec[i];
    vector<int> dp(n,0);
    dp[n-1]=0;
    if(n>=2)dp[n-2]=abs(vec[n-2]-vec[n-1]);
    for(int i=n-3;i>=0;i--){
        dp[i]=min(dp[i+1]+abs(vec[i+1]-vec[i]),dp[i+2]+abs(vec[i+2]-vec[i]));
    }
    
    cout <<dp[0]<<endl;
}

Measured memory_bytes: 1024
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Pattern;

public class Main {
public static void main(String[] args) throws IOException {
  InputStream is = System.in;
  Scanner in = new Scanner(is);
  Pattern pattern = Pattern.compile("[0|1]{12}");
  while (in.hasNext(pattern)) {
	int[][] before = new int[12][];
	int[][] line = new int[12][];
	int count = 0, num = 0;
	int[][] old = null;
	for (int col = 0; col < 12; col++) {
	  old = before;
	  before = line;
	  line = old;
	  char[] read = in.next(pattern).toCharArray();
	  // System.out.println(Arrays.toString(read));
	  for (int row = 0; row < 12; row++) {
		if (read[row] == '1') {
		  boolean upperHas = before[row] != null;
		  boolean leftHas = row != 0 && line[row - 1] != null;
		  if (!(upperHas || leftHas)) {
			line[row] = new int[] { num++ };
			count++;
		  } else if (leftHas) {
			line[row] = line[row - 1];
			if (upperHas && line[row][0] != before[row][0]) {
			  line[row][0] = before[row][0];
			  count--;
			}
		  } else if (upperHas) {
			line[row] = before[row];
		  }
		}
		else {
		  line[row] = null;
		}
	  }
	}
	System.out.println(count);
  }
}
}

Measured memory_bytes: 0
import bisect
from collections import deque

n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

sa, sb = [0], [0]
s = 0
for i in range(n):
    s += a[i]
    if s > k:
        break
    sa.append(s)

s = 0
for i in range(m):
    s += b[i]
    if s > k:
        break
    sb.append(s)

ans = 0

# sa, sbの組み合わせ中の最大合計となる値を取得
for i in range(len(sa)):
    l = k - sa[i]
    if l < 0:
        break

    num = bisect.bisect_right(sb, l) - 1
    ans = max (ans, num+i)

print(ans)


Measured memory_bytes: 42280
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>

using ll = long long;
typedef unsigned long long ull;
typedef std::pair<ll, ll>P;
struct edge { ll to, cost; };
std::vector<edge>v[100010], w[100010];
typedef std::vector<std::vector<int>>ma;

ll min(ll a, ll b) {
	if (a >= b)return b;
	else return a;
}
ll max(ll a, ll b) {
	if (a >= b)return a;
	else return b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool fl = true;
bool f = true;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
std::string abc = "abcdefghijklmnopqrstuvwxyz";

int main() {
	ll n, x, a[10000], d[10000], ans = INF2;
	std::cin >> n >> x;
	for (int i = 0;i < n;i++) {
		std::cin >> a[i];
		a[i + n] = a[i];
		d[i] = INF;
	}
	for (int i = 0;i < n;i++) {
		ll cost = x*i;
		for (int j = 0;j < n;j++) {
			d[j] = min(d[j], a[j + n - i]);
			cost += d[j];
		}
		ans = min(ans, cost);
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h> 
using namespace std; 
  
// All denominations of Indian Currency 
long long int deno[] = {  5, 500}; 
 long long int n = sizeof(deno) / sizeof(deno[0]); 
  
void findMin(long long int V) 
{ 
    // Initialize result 
    vector<long long int> ans; 
  
    // Traverse through all denomination 
    for (long long int i = n - 1; i >= 0; i--) { 
        // Find denominations 
        while (V >= deno[i]) { 
            V -= deno[i]; 
            ans.push_back(deno[i]); 
        } 
    } 
  
    // Print result 
    long long int sum=0;
    for (long long int i = 0; i < ans.size(); i++) 
        
        {
			if(ans[i]==500)
        {
				sum+=1000;
		} 
		if(ans[i]==5)
		{
			sum+=5;
		}
	}
	cout<<sum<<endl;
} 
  
// Driver program 
int main() 
{ 
    long long int n ;
    cin>>n; 
   // cout << "Following is minimal number of change for " << n << ": "; 
   if(n==0)
   {
	   cout<<"0"<<endl;
	   return 0;
   }
    findMin(n); 
    return 0; 
} 


Measured memory_bytes: 18664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <typeinfo>
#include <cmath>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
static const double pi = 3.141592653589793;

int main()
{
    ll a, b, h, m;
    double deg_h, deg_m, deg, ans;

    cin >> a >> b >> h >> m;
    deg_h = 0.5 * (60 * h + m);
    deg_m = 6 * m;
    deg = deg_h - deg_m;
    // cout << deg << endl;
    ans = sqrt(a * a + b * b - 2 * a * b * cos(pi * deg / 180));

    cout << std::fixed << std::setprecision(10) << ans << endl;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(ll i=0;i<(n);i++)

using namespace std;

int main(){
    ll s, c;
    cin >> s >> c;

    ll f = min(s, c/2);
    ll cnt = f;
    s -= f;
    c -= 2*f;

    if(s == 0){
        cnt += c/4;
        c -= 4*(c/4);
    }

    cout << cnt << endl;

    return 0;
}


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

int a[300][300];
int n, m;

bool solve(int k) {
  set<int> ban;
  vector<int> sel(n);
  for(int j = 0; j < m; j++) {
    vector<int> c(m);
    for(int i = 0; i < n; i++) {
      while(ban.count(a[i][sel[i]])) {
        sel[i]++;
        if(sel[i] >= m) return 0;
      }
      c[a[i][sel[i]]]++;
    }
    int ok = 1;
    for(int t = 0; t < m; t++) {
      if(c[t] > k) ban.emplace(t), ok = 0;
    }
    if(ok) return 1;
  }
  return 0;
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m;
  for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> a[i][j], a[i][j]--;
  int low = 1, high = n + 1;
  while(low + 1 < high) {
    int mid = (low + high - 1) / 2;
    if(solve(mid)) high = mid + 1;
    else low = mid + 1;
  }
  cout << low << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>

using namespace std;

int main(){

	int num,E,from,to,table[10000],tmp;
	vector<int> V[10000];
	queue<int> Q;

	for(int i = 0; i < 10000; i++)table[i] = 0;

	scanf("%d %d",&num,&E);

	for(int i = 0; i < E; i++){
		scanf("%d %d",&from,&to);
		V[from].push_back(to);
		table[to]++;
	}

	for(int i = 0; i < num; i++){
		if(table[i] == 0){
			Q.push(i);
		}
	}

	while(!Q.empty()){
		tmp = Q.front();
		Q.pop();
		printf("%d\n",tmp);
		for(int i = 0; i < V[tmp].size(); i++){
			table[V[tmp][i]]--;
			if(table[V[tmp][i]] == 0){
				Q.push(V[tmp][i]);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for (int i = 0; i < (n); i++)
typedef pair<int,int> P;
const int INF = 100000000;

int gcd(int a, int b) {

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

}

int main() {
    int K;
    cin >> K;
    int ans = 0;
    for (int i=1;i<=K;i++) {
        for (int j=i;j<=K;j++) {
            for (int k=j;k<=K;k++) {
                if (i==j && j==k) {
                    ans += gcd(i,gcd(j,k));
                }
                else if (i!=j && j!=k && k!=i) {
                    ans += gcd(i,gcd(j,k))*6;
                }
                else {
                    ans += gcd(i,gcd(j,k))*3;
                }
            }
        }
    }
    cout << ans << endl;}

Measured memory_bytes: 3648
#include<iostream>
#include<cstdint>
#include<vector>
#include<algorithm>
using namespace std; // 575

const int MAX = 1000;
int main() {
	int X, Y, Z, K;
	int64_t A[MAX], B[MAX], C[MAX];
	cin >> X >> Y >> Z >> K;
	for (int i = 0;i < X;++ i) cin >> A[i];
	for (int i = 0;i < Y;++ i) cin >> B[i];
	for (int i = 0;i < Z;++ i) cin >> C[i];
	vector<int64_t> v, v2;
	for (int i = 0;i < X;++ i) for (int j = 0;j < Y;++ j) v.push_back(A[i] + B[j]);
	sort(v.rbegin(), v.rend());
	for (int i = 0;i < min(X*Y, K);++ i) for (int j = 0;j < Z;++ j) v2.push_back(v[i] + C[j]);
	sort(v2.rbegin(), v2.rend());
	for (int i = 0;i < K;++ i) cout << v2[i] << endl;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

まずはソートしておく、どうせやっても損はない

さて、3個は面倒だからちょっと減らして2個で考えよう
x+yとzで分けるんだ
さて、この時高速に判定ができないか考える
まず、x+yのK番目以降は全部無視できる、それより大きいx+yを使えばいい
……お、個数がO(KZ)に減ったやん
よっしゃ全探索だ終わり
*/

Measured memory_bytes: 43364
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;cin>>s;
  int ans=0;
  for(int i=0;i<s.length();i++){
    if(i%2==0&(s[i]=='R'|s[i]=='U'|s[i]=='D'))ans++;
    else if(i%2==1&(s[i]=='L'|s[i]=='U'|s[i]=='D'))ans++;
  }
  if(ans==s.length())cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main(){
  double A,B,K;
  cin >> A >> B >> K;
  if((B-A+1)/2 <= K){
    for(int i=A;i<=B;i++)
      cout << i << endl;
  }
  else{
    for(int i=A;i<A+K;i++)
      cout << i << endl;
  	for(int j=B-K+1;j<=B;j++)
      cout << j << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
	int n;
	double x1,x2,x3,x4,y1,y2,y3,y4;
	cin>>n;
	for(int i=0;i<n;i++){
	    cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;


    double a,b;
    a=(y2-y1)/(x2-x1);
    b=(y4-y3)/(x4-x3);
    (a==b)? cout<<"YES"<<endl : cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
typedef long long ll;
using namespace std;

int main(void) {
    int N;cin>>N;
    map<ll, ll> mp;
    for (int i = 0; i < N; i++) {
        ll A;cin>>A;
        if (mp.find(A) != mp.end()) mp[A] += 1;
        else mp[A] = 1;
    }
    priority_queue<ll> que;
    for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); ++it) {
        ll num = it->second;
        while (num >= 2) {
            que.push(it->first);
            num /= 2;
        }
    }
    if (que.size() < 2) cout << 0 << endl;
    else {
        ll a = que.top();
        que.pop();
        ll b = que.top();
        cout << a * b << endl;
    }
    return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define LL long long 
struct Node{
	LL x,h;
	bool operator <(const Node &b)const{
		if(x!=b.x)return x<b.x;
		return h>b.h;
	}
}a[200005];
LL c[200005];int n;
int lowbit(int x){
    return x&(-x);
}
void add(int x,int num){
    while(x<=n){
        c[x]+=num;
        x+=lowbit(x);
    }
}
LL sum(int x){
    LL ans=0;
    while(x){
        ans+=c[x];
        x-=lowbit(x);//c[i]存储i-lowbit[i]+1到i的数组的值，所以求前缀和要不断去掉最后一位 
    }
    return ans;
}
int main(){
	int d,A;scanf("%d%d%d",&n,&d,&A);
	for(int i=0;i<n;i++)scanf("%d%d",&a[i].x,&a[i].h);
	sort(a,a+n);
	long long ans=0;
	add(1,a[0].h);
	for(int i=2;i<=n;i++){
		add(i,a[i-1].h-a[i-2].h);
	}
	for(int i=1;i<=n;i++){
		long long w=sum(i);
		if(w<=0)continue;
		w=(w-1)/A+1;
		int j=lower_bound(a,a+n,Node{a[i-1].x+2*d,0})-a;
		if(w<=0)continue;
		add(i,-w*A);ans+=w;
		add(j+1,w*A);
	}
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 4992
#include <stdio.h>
#include <set>
using namespace std;
int main(){
    int n,temp;
    set<int> s;
    scanf("%d",&n);
    while(n--){
        scanf("%d",&temp);
        s.insert(temp);
    }
    scanf("%d",&n);
    while(n--){
        scanf("%d",&temp);
        if(s.count(temp))printf("%d\n",temp);
    }
}


Measured memory_bytes: 12188
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率


def input(): return sys.stdin.readline()[:-1]
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列


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

    if A==B and B!=C:
        print('Yes')
    
    elif A==C and B!=C:
        print('Yes')
    
    elif C==B and A!=C:
        print('Yes')
    
    else: print('No')


if __name__ == "__main__":
    main()

Measured memory_bytes: 38256
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        HashSet<String> ab = new HashSet<>();
        for (int i = 0; i < n; i++) {
            ab.add(scan.next());
        }
        System.out.println(ab.size());
    }
}


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

typedef long long ll;
using namespace std;

int main(void) {
  ll H;
  cin >> H;
  ll a = 0;
  while (H != 0) {
    H /= 2;
    a++;
  }
  ll ans = ((ll)1 << a) - 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) REPI(i, 0, n)
#define REPI(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)

#define SZ(x) ((int)(x).size())


using ll = long long;
using ull = unsigned long long;
using namespace std;

int main()
{
    int K, strlength;
    string S;
    cin >> K >> S;
    strlength = S.length();
    if (strlength <= K)
    {
        cout << S << endl;
    }
    else
    {
        cout << S.substr(0, K) + "..." << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3632
A, B = map(int,input().split())

dp = [0] * 21
dp[0] = 1
if B == 1:
    print(0)
    exit()
for i in range(1, 21):
    dp[i] = dp[i-1] + (A-1)
    if dp[i] >= B:
        print(i)
        exit()


Measured memory_bytes: 2940
#include<stdio.h>

int main(){
  int n; scanf("%d",&n);
  int s1=0,s2=0,t[n];
  for(int i=0; i<n; i++){
    scanf("%d",&t[i]);
    s1+=t[i];
  }
  int p; 
  if(s1%n > (n-(s1%n))) p=1+s1/n;
  else p=s1/n;
  for(int i=0; i<n; i++){
    s2+=(p-t[i])*(p-t[i]); 
  }
  printf("%d\n",s2);
  return 0;
}

Measured memory_bytes: 128
N, M = list(map(int,input().split()))
H_list = list(map(int,input().split()))
xy = [map(int, input().split()) for _ in range(M)]
x, y = [list(i) for i in zip(*xy)]

result = [True] * N
for i in range(M):
  if(H_list[x[i]-1] > H_list[y[i]-1]):
    result[y[i]-1] = False
  elif(H_list[x[i]-1] < H_list[y[i]-1]):
    result[x[i]-1] = False
  else:
    result[x[i]-1] = False
    result[y[i]-1] = False
print(result.count(True))

Measured memory_bytes: 66836
import scala.annotation.tailrec
import scala.io.StdIn._
object Main extends App {
  val MOD = 1000000007L
  val L = readLine.trim
  println(
    cal(L.reverse.toList.map(_ == '1'))
  )
  @tailrec def cal(digits: List[Boolean], length: Int = 0, acc: Long = 1): Long = {
    digits match {
      case Nil ⇒ acc
      case true::rest ⇒ cal(rest, length + 1, (acc * 2 + power(3, length)) % MOD)
      case false::rest ⇒ cal(rest, length + 1, acc)
    }
  }
  def power(base: Long, exp: Int): Long = {
    exp match {
      case 0 ⇒ 1L
      case 1 ⇒ base % MOD
      case _ ⇒ power(base * base % MOD, exp >> 1) * power(base, exp & 1) % MOD
    }
  }
}


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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 200010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n;

vector<int> G[maxn],has[maxn];

int dep[maxn],fa[maxn];

void dfs(int u,int f){
	fa[u]=f;dep[u]=dep[f]+1;
	for(auto v:G[u])if(v!=f){
		dfs(v,u);
	}
}

ll solve(int x){
	dfs(x,0);
	int mx=0;
	REP(i,1,n)mx=max(mx,dep[i]);
	REP(i,0,mx)has[i].clear();
	REP(i,1,n)has[dep[i]].PB(i);
	ll ans=1;
	RREP(i,mx-1,0){
		int mx2=0;
		for(auto x:has[i]){
			int t=0;
			for(auto v:G[x])if(dep[v]==i+1)t++;
			mx2=max(mx2,t);
		}
		ans*=mx2;
	}
	return ans;
}

ll solve(int x,int y){
	dep[y]=-1;
	dfs(x,y);
	dep[x]=-1;
	dfs(y,x);
	dep[x]=0;
	int mx=0;
	REP(i,1,n)mx=max(mx,dep[i]);
	REP(i,0,mx)has[i].clear();
	REP(i,1,n)has[dep[i]].PB(i);
	ll ans=1;
	RREP(i,mx-1,0){
		int mx2=0;
		for(auto x:has[i]){
			int t=0;
			for(auto v:G[x])if(dep[v]==i+1)t++;
			mx2=max(mx2,t);
		}
		ans*=mx2;
	}
	return ans*2;
}

void Work(){
	dep[0]=-1;
	dfs(1,0);
	int l=0;
	REP(i,1,n)if(dep[i]>dep[l])l=i;
	dfs(l,0);
	int r=0;
	REP(i,1,n)if(dep[i]>dep[r])r=i;
	if(!(dep[r]&1)){
		int ans=(dep[r]>>1)+1;
		int x=r;
		while(dep[x]!=ans-1)x=fa[x];
		ll ans2=solve(x);
		for(auto v:G[x])ans2=min(ans2,solve(x,v));
		cout<<ans<<' '<<ans2<<endl;
	}
	else{
		int ans=dep[r]+1>>1;
		int x=r,y=r;
		while(dep[x]!=ans-1)x=fa[x];
		while(dep[y]!=ans)y=fa[y];
		cout<<ans<<' '<<solve(x,y)<<endl;
	}
}

void Init(){
	read(n);
	REP(i,2,n){
		int u,v;
		read(u,v);
		G[u].PB(v);G[v].PB(u);
	}
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int n;
  cin>>n;
  vector<int> vec(n);
  for(auto&& e: vec) 
  {
    cin>>e;
  }
  sort(vec.begin(), vec.end());
  cout<<vec[n-1]-vec[0];
}

Measured memory_bytes: 256