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

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var s = sc.next();
		var t = sc.next();
		sc.close();

		var result = Integer.MAX_VALUE;
		for (var i = 0; i < s.length() - t.length() + 1; i++) {
			var count = 0;
			for (var j = 0; j < t.length(); j++) {
				var s1 = s.substring(i + j, i + j + 1);
				var t1 = t.substring(j, j + 1);
				if (!s1.equals(t1)) {
					count++;
				}
			}
			result = Math.min(result, count);
		}

		System.out.println(result);
	}
}


Measured memory_bytes: 52724
#include <atcoder/all>
using namespace atcoder;

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cout << "ACL";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

int main() {
	int n,k;
	std::cin >> n >> k;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	std::sort(all(a));
	int sum=0;
	rep(i,k) sum+=a[i];
	print(sum);
}


Measured memory_bytes: 3612
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);
 
    private void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        _out.println((b - a == c - b ? "YES" : "NO"));
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

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

dic = [set() for _ in range(n)]

#print(dic)

for i in range(m) :
    s, c = map(int, input().split())
    dic[s-1].add(c)
#print(dic, list(dic[0])[0])
#print(dic)
for i in range(len(dic)) :
    if len(dic[i]) > 1 :
        print(-1)
        exit()
    if n != 1 and len(dic[i]) == 1 and i == 0:
        if list(dic[i])[0] == 0 :
            print(-1)
            exit()
    if len(dic[i]) == 0 :
        if i == 0 and m != 0:
            dic[i].add(1)
        elif m == 0 and n > 1 and i == 0:
            dic[i].add(1)
        else :
            dic[i].add(0)

ans = 0
mul = 10 ** (n-1)

for i in range(n) :
    ans += (list(dic[i])[0] * mul)
    mul /= 10

print(int(ans))


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();

		for(int i=0 ; i<100 ; i++) {
			C -= B;
			if(C <= 0) {
				System.out.println("Yes");
				break;
			}
			A -= D;
			if(A <= 0) {
				System.out.println("No");
				break;
			}
		}


		sc.close();

	}

}


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

#define DEBUG(x) cout << #x << ": " << x << endl

#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); --i)

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i =  (n) - 1; i >= 0; --i)

#define ALL(a) (a).begin(), (a).end()

using namespace std;

long solve(int n, int *as) {
  long total = 0, sum[n];

  REP(i, n) {
    int a = as[i];
    sum[i] = (i == 0 ? 0 : sum[i-1]) + a;
    total += a;
  }


  long min = numeric_limits<long>::max();
  REP(i, n - 1) {
    long diff = abs(total - sum[i] * 2);
    if (diff < min) {
      min = diff;
    }
    if (diff == 0) {
      break;
    }
  }
  return min;
}

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

  //
  /* int arr1[] = {1,2,3,4,5,6}; */
  /* cout << solve(6, arr1) << endl; */
  /* int arr2[] = {10, -10}; */
  /* cout << solve(2, arr2) << endl; */
  ///

  int n;
  cin >> n;
  int as[n];
  REP(i, n) {
    int a;
    cin >> a;
    as[i] = a;
  }

  cout << solve(n, as) << endl;
}



Measured memory_bytes: 2560
def insertionSort(A, g, count):
    N = len(A)
    for i in range(g, N):
        j = i - g
        temp = A[i]
        while j >= 0 and A[j] > temp:
            A[j + g] = A[j]
            j -= g
            count += 1
        A[j + g] = temp
    return A, count


def shellSort(A):
    n = len(A)
    count = 0
    h = 1
    G = []
    while (True):
        if h > n:
            break
        G.append(h)
        h = 3 * h + 1
    m = len(G)
    G.reverse()
    for i in range(m):
        A, count = insertionSort(A, G[i], count)
    return m, G, count, A


def listFromInput():
    N = int(input())
    numbers = []
    for i in range(N):
        numbers.append(int(input()))
    return numbers


A = listFromInput()
m, G, count, A = shellSort(A)
print(m)
print(" ".join(list(map(str, G))))
print(count)
for i in A:
    print(i)

Measured memory_bytes: 47608
def connected_components(graph):
    seen = set()
    def component(n):
        nodes = set([n])
        while nodes:
            n = nodes.pop()
            seen.add(n)
            nodes |= set(graph[n]) - seen
            yield n
    for n in graph:
        if n not in seen:
            yield component(n)

def print_gen(gen):
    print(len([list(x) for x in gen]) - 1)

n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)  # 有向グラフなら消す
graphA = {}
for i in range(n):
    graphA[i] = graph[i]

print_gen(connected_components(graphA))

Measured memory_bytes: 43480
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int k, x, y;
bool xm, ym, sw;
vector<P> ans;
signed main() {
	cin >> k >> x >> y;
	if (x < 0) {
		x = -x;
		xm = true;
	}
	if (y < 0) {
		y = -y;
		ym = true;
	}
	if (x < y) {
		swap(x, y);
		sw = true;
	}
	if (k % 2 == 0 && (x + y) % 2) {
		cout << -1 << endl;
		return 0;
	}
	if (x + y < k && (x + y) % 2) {
		ans.push_back(make_pair(x, x - k));
		ans.push_back(make_pair(x + (k + x - y) / 2, x - k + (k - x + y) / 2));
		ans.push_back(make_pair(x, y));
	}
	else {
		int r;
		if (x + y < k && (x + y) % 2 == 0)r = 2;
		else {
			int c = (k - (x + y) % k) % k;
			if (c % 2)r = (x + y + k - 1) / k + 1;
			else r = (x + y + k - 1) / k;
		}
		int nx = 0, ny = 0;
		while (true) {
			if (ny - k > -(k * r - x - y) / 2) {
				ny -= k;
				ans.push_back(make_pair(nx, ny));
			}
			else break;
		}
		if (ny != -(k * r - x - y) / 2) {
			nx = -(k * r - x - y) / 2 - (ny - k);
			ny = -(k * r - x - y) / 2;
			ans.push_back(make_pair(nx, ny));
		}
		while (true) {
			if (nx + k < x) {
				nx += k;
				ans.push_back(make_pair(nx, ny));
			}
			else break;
		}
		if (nx != x) {
			ny = ny + (nx + k - x);
			nx = x;
			ans.push_back(make_pair(nx, ny));
		}
		while (ny + k <= y) {
			ny += k;
			ans.push_back(make_pair(nx, ny));
		}
	}
	cout << ans.size() << endl;
	for (P p : ans) {
		if (sw)swap(p.first, p.second);
		if (xm)cout << -p.first << " ";
		else cout << p.first << " ";
		if (ym)cout << -p.second << endl;
		else cout << p.second << endl;
	}
}

Measured memory_bytes: 5488
#include <cctype>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define LL long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

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

	LL a[100005];
	REP(i, n){
		cin >> a[i];
	}
	
	LL num = 100000;
	LL nextnum = 1;
	LL cnt = 0;
	while(num--){
		if(a[nextnum - 1] == 2){
			++cnt;
			cout << cnt << endl;
			return 0;
		}
		nextnum = a[nextnum - 1];
		++cnt;

	}

	cout << -1 << endl;
	return 0;
}


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

#define INF (1LL << 31 - 1)
#define MOD int(1e9+7)
#define repi(i,j,n) for(int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define fi first
#define se second

inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

long long n, a[100002], ans, x;

int main() {
    init();
    cin >> n >> x;
    rep(i, n) {
        cin >> a[i];
    }

    rep(i, n - 1) {
        if (a[i] + a[i + 1] > x) {
            int dif = (a[i] + a[i + 1]) - x;
            if (a[i + 1] - dif >= 0) {
                a[i + 1] -= dif;
            }
            else {
                dif -= a[i + 1];
                ans += a[i + 1];
                a[i + 1] = 0;
                a[i] -= dif;
            }
            ans += dif;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

  vector<int> a(N);
  for (int i = 0; i < N; ++i)
    cin >> a[i];

  sort(a.begin(), a.end());

  int i = 0;
  int c = 1;
  if (N % 2 == 1) {
    if (a[0] != 0) {
      cout << 0 << endl;
      return 0;
    }
    i = 1;
    c = 2;
  }

  // check
  for (; i < N; i += 2) {
    if (a[i] != a[i + 1] || a[i] != c) {
      cout << 0 << endl;
      return 0;
    }
    c += 2;
  }

  long long ret = 1;
  for (int j = 0; j < N / 2; ++j) {
    ret *= 2;
    ret %= 1000000007;
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    string s;
    cin >> s;
    s.erase(unique(all(s)), s.end());
    if (s.size() != 4) {
        cout << "Bad" << endl;
    } else {
        cout << "Good" << endl;
    }
}

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


Measured memory_bytes: 3660
#include <iostream>

using namespace std;

int main()
{
  int N,cou=0;
 cin >> N ;
 int arr[N];
 for(int i = 0; i < N; i++) 
 cin >> arr[i];
  for(int i = 0; i < N; i++) {
     // cout << i+1 << " "<< arr[i];
      if (arr[i]%2!=0&&(i+1)%2!=0)
      cou++;
  }
  cout << cou << endl;

    return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define All(v) v.begin(), v.end()
using namespace std;

int V[55];

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N, K, ans = 0; cin >> N >> K;
    for(int i=0;i<N;i++) cin >> V[i];

    for(int i=0;i<=N;i++){
        for(int j=0;j<=N-i;j++){
            if(i+j>K) continue;
            int cur = 0;
            vector<int> A;
            for(int k=0;k<i;k++) A.push_back(V[k]), cur += V[k];
            for(int k=0;k<j;k++) A.push_back(V[N-k-1]), cur += V[N-k-1];
            sort(All(A));
            for(int k=0;k<min(i+j, K-i-j);k++) if(A[k]<0) cur -= A[k];
            ans = max(ans, cur);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int pallindrom(string s)
{
    string ss;
    ss=s;
    reverse(s.begin(),s.end());
    if(ss==s)
    {
        return 1;
    }
    else
        return -1;
}
int main()
{
    string ss;
    cin>>ss;
    int n=ss.size();
    int r=  pallindrom(ss);
    if(r==1)
    {
        int a=(n-1)/2;
        int b=(n+3)/2;
        string s1= ss.substr(0, a);

        string s2= ss.substr(b-1, n);
        // cout<<s1<<" " <<s2;
        int p1=  pallindrom(s1);
        int p2=  pallindrom(s2);
        if(p1==p2 && p1==1)
        {
            cout<<"Yes";
        }
        else
            cout<<"No";
    }
    else
        cout<<"No";





}





Measured memory_bytes: 256
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
  int i;
  int R;
  long cnt = 0;
  scanf("%d", &R);
  printf("%f\n", (double)R*2*3.141592);
  return 0;
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
int main(){
  #define int long long
  int N;
  cin>>N;
  vector<int> c(N,0);
  for(int i=0;i<N;i++){
    int a,b;
    cin>>a>>b;
    if(a==b){c.at(i)=1;}
  }
  for(int i=0;i<N-2;i++){
    if(c.at(i)==1 && c.at(i+1)==1 && c.at(i+2)==1){cout<<"Yes"<<endl;return 0;}
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3628
// JOI2013予選５　魚の生息範囲
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0580
// ｘ座標ｙ座標ｄ座標で出てくるそれぞれの座標値で空間を区切る
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int N,K;
    int X1[51],Y1[51],D1[51],X2[51],Y2[51],D2[51];
    vector<unsigned long long> x,y,d;
    cin >> N >> K;
    for(int i=1;i<=N;i++){
        cin >> X1[i] >> Y1[i] >> D1[i] >> X2[i] >> Y2[i] >> D2[i];
        x.push_back(X1[i]);
        x.push_back(X2[i]);
        y.push_back(Y1[i]);
        y.push_back(Y2[i]);
        d.push_back(D1[i]);
        d.push_back(D2[i]);
    }
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    sort(d.begin(),d.end());
    x.erase(unique(x.begin(), x.end()), x.end());
    y.erase(unique(y.begin(), y.end()), y.end());
    d.erase(unique(d.begin(), d.end()), d.end());
    unsigned long long vol=0;
    for(int i=0;i<x.size()-1;i++){
        for(int j=0;j<y.size()-1;j++){
            for(int k=0;k<d.size()-1;k++){
                int count=0;
                    for(int l=1;l<=N;l++){
                        if(X1[l]<=x[i] && x[i+1]<=X2[l] && Y1[l]<=y[j] && y[j+1]<=Y2[l] && D1[l]<=d[k] && d[k+1]<=D2[l]){
                            count++;
                        }
                    }
                if(count>=K){
                    vol=vol+(x[i+1]-x[i])*(y[j+1]-y[j])*(d[k+1]-d[k]);
                }
            }
        }
    }
    cout << vol << endl;
}



Measured memory_bytes: 3164
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  string S,A="CODEFESTIVAL2016";
  cin>>S;
  int ans=0;
  for(int i=0; i<16; ++i){
    if(S.at(i)!=A.at(i)) ans++;
  }
  cout<<ans<<endl;
}

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

from collections import Counter
d=Counter(a)
f={}
for k,v in d.items():
    f[k]=v*(v-1)/2

ans={}
s=sum(f.values())
for k in f.keys():
    ans[k]=(d[k]-1)*(d[k]-2)/2 + s- f[k]

for i in range(n):
    print(int(ans[a[i]]))


Measured memory_bytes: 44192
#include <stdio.h>
#define max(p,q)((p)>(q)?(p):(q))

int h[1510];
int tate[1510],yoko[1510],cnt;

int f(int n){
	cnt=1;
	int ans=0;
	for(int i=0;i<=n;i++){
		if(h[i]>tate[cnt-1]){
			tate[cnt]=h[i];
			yoko[cnt]=i;
			cnt++;
		}
		if(h[i]<tate[cnt-1]){
			while(tate[cnt-1]>h[i]){
				ans=max(ans,tate[cnt-1]*(i-yoko[cnt-1]));
				cnt--;
			}
			tate[cnt]=h[i];
			cnt++;
		}
	}
	return ans;
}

int main(){
	int hh,w;
	scanf("%d%d",&hh,&w);
	int ans=0;
	for(int i=0;i<hh;i++){
		int t;
		for(int j=0;j<w;j++){
			scanf("%d",&t);
			h[j]++;
			if(t)h[j]=0;
		}
		int temp=f(w);
		ans=max(ans,temp);
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans = max(max(a*c,a*d),max(b*c,b*d));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

#n,k,*a = map(int,read().split())

n, = map(int,readline().split())
vw = [[0,0]]+[list(map(int,readline().split())) for _ in range(n)]

def merge(av,aw,bv,bw):
    la,lb = len(aw),len(bw)
    rv = [0]*(la+lb)
    rw = [0]*(la+lb)
    ia = ib = 0
    for i in range(la+lb):
        if ib==lb or (ia < la and aw[ia] < bw[ib]):
            rv[i] = av[ia]
            rw[i] = aw[ia]
            ia += 1
        else:
            rv[i] = bv[ib]
            rw[i] = bw[ib]
            ib += 1
    return rv,rw

A = 10
N = min(1<<A,n+1)
memov = [[] for _ in range(N)]
memow = [[] for _ in range(N)]

memov[0] = [0]
memow[0] = [0]

#from itertools import acumulate
for i in range(1,N):
    v,w = vw[i]
    m2v = [v+v1 for v1 in memov[i>>1]]
    m2w = [w+w1 for w1 in memow[i>>1]]
    memov[i],memow[i] = merge(memov[i>>1],memow[i>>1],m2v,m2w)

    #memov[i] = list(accumulate(memov[i],max))
    for j in range(1,len(memov[i])):
        memov[i][j] = max(memov[i][j-1],memov[i][j])
    
def solve(lstv,lstw,dv,dw,l):
    ans = 0
    idx = len(lstw)-1
    #print(lstv,lstw,dv,dw,l)
    for v,w in zip(dv,dw):
        while idx >= 0 and lstw[idx] + w > l:
            idx -= 1
        if idx >= 0 and v+lstv[idx] > ans:
            ans = v+lstv[idx]
    print(ans)        
 
 

q, = map(int,readline().split())
for _ in range(q):
    u,l = map(int,readline().split())

    dv = [0]
    dw = [0]
    while u >= N:
        v,w = vw[u]
        m2v = [v+v1 for v1 in dv]
        m2w = [w+w1 for w1 in dw]
        dv,dw = merge(dv,dw,m2v,m2w)
        u >>= 1
    
    #for j in range(1,len(dv)):
    #    dv[j] = max(dv[j-1],dv[j])
    
    solve(memov[u],memow[u],dv,dw,l)

#print(memov)
#print(memow)



Measured memory_bytes: 140840
n, l = map(int, input().split())
dat_a = []

for i in range(n):
    dat_a.append(l + i)

total = sum(dat_a)
# print("total" + str(total))

res = 100000
m = 10000

for i in range(n):
    if abs(dat_a[i] < m):
        m = abs(dat_a[i])
        res = dat_a[i]

print(total - res)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int H, N;
  cin >> H >> N;
  int sum = 0;
  for (int i = 0; i < N; i++)
  {
    int num;
    cin >> num;
    sum += num;
  }
  cout << (sum >= H ? "Yes" : "No") << endl;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25

int main() {
    ll h, w;
    cin >> h >> w;
    if(h == 1 || w == 1){
        cout << 1 << endl;
    }else{
        cout << (h*w+1)/2 << endl;
    }
}




Measured memory_bytes: 256
N = int(input())
l = input().split()
line = [int(l[i]) for i in range(N)]

pos = N-1
n = 0
max_m = 0

while (pos>0) :
  if line[pos-1] >= line[pos]:
    n += 1
  else:
    if max_m < n:
    	max_m = n
    n = 0
  pos -= 1
if max_m < n:
  max_m = n
print(max_m)

Measured memory_bytes: 14252
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main()
{
    int n;
    cin >> n;
    n %= 10;
    if(n == 3)
    {
        cout << "bon\n";
    }
    else if(n == 0 || n == 1 || n == 6 || n == 8)
    {
        cout << "pon\n";
    }
    else
    {
        cout << "hon\n";
    }
    
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main() {
    int K, A, B;
    cin >> K;
    cin >> A >> B;

    int m = B / K;

    if (K * m >= A && K * m <= B) {
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }

    return 0;
}

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

int main() {
    int N , sum = 0 , max = 0;
    cin >> N;
    vector <int> H(N);
    for (int i = 0; i < N; ++i) {
        cin >> H[i];
        if(i > 0 && H[i] <= H[i - 1]){
            sum++;
        }
		else{
            sum = 0;
        }
		if(sum >= max){
            max = sum;
        }
    }
    cout << max << endl;
}


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

int main(){
    int n, p1 = 0, p2 = 0;
    string str1, str2;
    cin >> n;
    
    for(int i = 0; i < n; i++){
        cin >> str1 >> str2;
        
        if(str1 == str2){
            p1++;
            p2++;
        } else if(str1 > str2){
            p1 += 3;
        } else if(str1 < str2) {
            p2 += 3;
        }
    }
     cout << p1 << " " << p2 << endl;
     
     return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> a;
int N, S, W, Q;

int main(){
    while(cin >> N >> S >> W >> Q && N){
        a.resize(N);
        int g = S;
        //        cout << "A ";
        for(int i=0; i<N; i++) {
            a[i] = (g/7) % 10;
            if( g%2 == 0 ) { g = (g/2); }
            else           { g = (g/2) ^ W; }
            // cout << a[i] << ' ';
        }
        //        cout << endl;
        int ans = 0;
        if(Q != 2 && Q != 5){
            map<int,int> sumcnt;
            sumcnt[0] = 1;
            ll dig = 1;
            ll cur = 0;
            for(int i = N-1; i >= 0; --i) {
                cur = i == N-1 ? a[i] % Q : cur + a[i]*dig;
                cur %= Q;
                if(a[i] != 0) ans += sumcnt[cur];
                sumcnt[cur]++;
                dig *= 10;
                dig %= Q;
            }
        } else if(Q == 2 || Q == 5){
            int pos = 0;
            for(int i = 0; i < N; ++i){
                if(a[i] != 0) ++pos;
                if(a[i] % Q == 0) ans += pos;
            }
        } 
        cout << ans << endl;
    }
}

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

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a >= 13) {
        cout << b << endl;
    } else if (6 <= a && a <= 12) {
        cout << b / 2 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cerr << (*begin) << " ";
    *begin++;
  }
  cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cerr << " " << Array[i][j];
    }
    cerr << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

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

int Q, H, S, D;
int N;

signed main() {
  cin >> Q >> H >> S >> D;
  cin >> N;

  int yen2 = min({8*Q, 4*H, 2*S, D});
  int ans = 0;
  ans += (N / 2) * yen2;

  if (N % 2 != 0) {
    ans += min({4*Q, 2*H, S});
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Comparator;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        while ((line = reader.readLine()) != null) {
            if (line.isEmpty()) {
                continue;
            }
            int n = Integer.parseInt(line);
            if (n == 0) {
                break;
            }
            int m = Integer.parseInt(reader.readLine());
            int[][] graph = new int[m][3];
            for (int i = 0; i < m; i++) {
                String[] values = reader.readLine().split(",");
                graph[i][0] = Integer.parseInt(values[0]);
                graph[i][1] = Integer.parseInt(values[1]);
                graph[i][2] = Integer.parseInt(values[2]) / 100 - 1;
            }
            Arrays.sort(graph, new Comparator<int[]>() {
                @Override
                public int compare(int[] o1, int[] o2) {
                    return o1[2] - o2[2];
                }
            });
            int result = solve(n, graph);
            out.println(result);
        }
    }

    private static int solve(int n, int[][] graph) {
        int[] treeNumbers = new int[n];
        int lastTreeNumber = 0;
        int result = 0;
        for (int i = 0; i < graph.length; i++) {
            int[] edge = graph[i];
            int treeNumber0 = treeNumbers[edge[0]];
            int treeNumber1 = treeNumbers[edge[1]];
            if (treeNumber0 == 0) {
                if (treeNumber1 == 0) {
                    lastTreeNumber++;
                    treeNumbers[edge[0]] = lastTreeNumber;
                    treeNumbers[edge[1]] = lastTreeNumber;
                } else {
                    treeNumbers[edge[0]] = treeNumber1;
                }
            } else {
                if (treeNumber1 == 0) {
                    treeNumbers[edge[1]] = treeNumber0;
                } else if (treeNumber1 == treeNumber0) {
                    continue;
                } else {
                    for (int j = 0; j < n; j++) {
                        if (treeNumbers[j] == treeNumber1) {
                            treeNumbers[j] = treeNumber0;
                        }
                    }
                }
            }
            result += edge[2];
        }
        return result;
    }
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i = 0;i < n;i++)

using namespace std;
#define INF 1e16
typedef long long lint;

bool went[5]={0};   //全探索で、現在使用中かどうかのフラグ
lint tm[5];         //馬車の出発時間
lint S[5];
lint dist;
lint D[5];
int n,m;
lint answer = INF;  //答え
lint pre;           //適切な出発時間であるような、答えの候補

void judge(){   //tmが適切かどうかを判定する(ほそながいところとゴール以外で追いつかないか・ほそながいところで3つ以上の馬車が同時に追いつかないか)
    vector<pair<lint,lint> > meet;
    rep(i,n-1){
        for(int j = i + 1;j < n;j++){
            int hoge = 0;
            if(S[i] < S[j]||tm[j]-tm[i] >= (S[i]-S[j])*dist)
                continue;
            rep(k,m){
                if(tm[i]-tm[j] == (S[j]-S[i])*D[k]){
                    meet.push_back(make_pair(tm[j]+S[j]*D[k],k));
                    hoge = 1;
                    break;
                }
            }
            if(!hoge){
                return;
            }
        }
    }
    if(!meet.empty()){
        sort(meet.begin(),meet.end());
        rep(i,meet.size()-1){ //3つ以上の馬車が同時に細長いところで追いついている
            if(meet[i] == meet[i+1])
                return;
        }
    }
    pre = 0;
    rep(i,n){
        pre = max(pre,tm[i]+dist*S[i]);
    }
    answer = min(answer,pre);
}

void search(int p){ //全探索 pは探索の深さ
    if(p == 0){
        tm[0] = 0;
        went[0]=1;
        search(1);
        return;
    }
    rep(i,n-1){
        if(went[i] && went[i+1] && tm[i] >= tm[i+1])
            return;
    }
    if(p == n){
        judge();
        return;
    }
    rep(i,n-1){
        if(went[i] && !went[i+1]){
            tm[i+1] = tm[i]+1;
            went[i+1] = 1;
            search(p+1);
            went[i+1] = 0;
        }
        //!went[i] && went[i+1]の場合は探索しなくてよい(馬車iは必ずどこかで他の馬車に追いつくから)
    }
    rep(i,n){
        if(!went[i]){
            rep(j,n){
                if((i < j && S[i]<S[j])||(i > j && S[i]>S[j]))
                    continue;
                if(went[j]){
                    rep(k,m){   //iとjがkで追いつく
                        tm[i] = tm[j]+(S[j]-S[i])*D[k];
                        went[i] = 1;
                        search(p+1);
                        went[i] = 0;
                    }
                    tm[i] = tm[j]+(S[j]-S[i])*dist;
                    went[i] = 1;
                    search(p+1);
                    went[i] = 0;
                }
            }
        }
    }
}

int main(){
    cin  >> dist;
    cin >> n;
    rep(i,n){
        cin >> S[i];
    }
    cin >> m;
    rep(i,m){
        cin >> D[i];
    }
    search(0);
    cout << answer << endl;
}

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

#define max 200000
typedef long long ll;

int L[max / 2 + 1], R[max / 2 + 1];

ll inversion(int A[], int n, int left, int mid, int right)
{
	int i, j;
	ll cnt = 0;
	int n1 = mid - left;
	int n2 = right - mid;
	
	for (i = 0; i < n1; i++)L[i] = A[left + i];
	for (i = 0; i < n2; i++)R[i] = A[mid + i];
	L[n1] = R[n2]= INT_MAX;

	i = j = 0;
	for (int k = left; k < right; k++)
	{
		if (L[i] <= R[j])
			A[k] = L[i++];
		else {
			A[k] = R[j++];
			cnt += n1 - i;
		}
	}
	return cnt;
}

ll mergesort(int A[], int n, int left, int right)
{
	ll v1, v2, v3;
	if (left + 1 < right)
	{
		int mid = (left + right) / 2;
		v1 = mergesort(A, n, left, mid);
		v2 = mergesort(A, n, mid, right);
		v3 = inversion(A, n, left, mid, right);
		return v1 + v2 + v3;
	}
	else return 0;
}

int main()
{
	int n, A[max];
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> A[i];

	ll ans = mergesort(A, n, 0, n);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4632
#include <iostream>
#include <vector>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a == 7 && b == 5 && c == 5){
        cout << "YES" << endl;
    }
    else if(a == 5 && b == 7 && c == 5){
        cout << "YES" << endl;
    }
    else if(a == 5 && b == 5 && c == 7){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>

int main()
{
  
    int length, point;
    std::cin >> length >> point;
    int start = std::max(-1000000, point - length + 1);
  int end = std::min( 1000000, point + length - 1);
    
  std::string result = "";
  for (int i = start; i < end + 1; i++)
  {
    if ( i == end) { 
        result += std::to_string(i);
        break;
    }
    result += std::to_string(i) + " ";
  }
  std::cout << result << "\n";
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scanf("%d", &N)

	l := 0
	fmt.Println(l)
	var ls string
	fmt.Scanf("%s", &ls)
	if ls == "Vacant" {
		return
	}

	r := N - 1
	//fmt.Println(r)
	//var rs string
	//fmt.Scanf("%s", &rs)
	//if rs == "Vacant" {
	//	return
	//}

	query := func(i int) int {
		fmt.Println(i)
		var s string
		fmt.Scanf("%s", &s)
		if s == "Vacant" {
			return 0
		}
		if i%2 == 0 {
			if s == ls {
				return 1
			} else {
				return -1
			}
		} else {
			if s == ls {
				return -1
			} else {
				return 1
			}
		}
	}

	for {
		m := (l + r) / 2
		ans := query(m)
		if ans == 0 {
			return
		} else if ans < 0 {
			r = m - 1
		} else {
			l = m + 1
		}
	}
}


Measured memory_bytes: 1236
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
	int sa[3][3],c[3][3],i,j,f=0;
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
			cin>>c[i][j];
		}
	}
	sa[0][0]=c[0][1]-c[0][0];
	sa[0][1]=c[0][2]-c[0][1];
	sa[1][0]=c[1][1]-c[1][0];
	sa[1][1]=c[1][2]-c[1][1];
	sa[2][0]=c[2][1]-c[2][0];
	sa[2][1]=c[2][2]-c[2][1];
	if(sa[0][0]==sa[1][0]&&sa[0][0]==sa[2][0]&&sa[0][1]==sa[1][1]&&sa[0][1]==sa[2][1])f=1;
	sa[0][0]=c[1][0]-c[0][0];
	sa[0][1]=c[2][0]-c[1][0];
	sa[1][0]=c[1][1]-c[0][1];
	sa[1][1]=c[2][1]-c[1][1];
	sa[2][0]=c[1][2]-c[0][2];
	sa[2][1]=c[2][2]-c[1][2];
	if(sa[0][0]==sa[1][0]&&sa[0][0]==sa[2][0]&&sa[0][1]==sa[1][1]&&sa[0][1]==sa[2][1])f=1;
	else f=0;
	if(f)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


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

int main(){
    int n,r;
    for(;;){
        scanf("%d%d",&n,&r);
        if(n==0 && r==0) break;
        int p,c;
        vector<int> ca(n);
        for(int i=0;i<n;i++){
            ca[i]=n-i;
        }
        for(int i=0;i<r;i++){
            scanf("%d%d",&p,&c);
            rotate(begin(ca),begin(ca)+p-1,begin(ca)+p-1+c);
        }
        printf("%d\n",ca[0]);
    }
}

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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end() å
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

#define TENNINE 1000000005
#define TENFIVE 100005

int n;
string s;

int fun(vector<int> _r, vector<int> _b, vector<int> _g)
{
    int ansf = 0;

    for (int x : _r)
    {
        auto itr = upper_bound(_b.begin(), _b.end(), x);
        while (itr != _b.end())
        {
            int temp = *itr;
            auto itr2 = upper_bound(_g.begin(), _g.end(), temp);
            if (itr2 == _g.end())
            {
                break;
            }
            else
            {
                int p = temp - x;
                int k = temp + p;
                bool search = binary_search(itr2, _g.end(), k);
                if (search)
                {
                    ansf--;
                }
                ansf += _g.end() - itr2;
                itr++;

                continue;
            }
        }
    }

    return ansf;
}

signed main()
{
    cin >> n >> s;

    vector<int> r, b, g;
    int ans = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'R')
        {
            r.pb(i);
        }
        else if (s[i] == 'G')
        {
            g.pb(i);
        }
        else
        {
            b.pb(i);
        }
    }

    ans = fun(r, g, b) + fun(r, b, g) + fun(g, b, r) + fun(g, r, b) + fun(b, r, g) + fun(b, g, r);
    cout << ans << endl;

    return 0;
}


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

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

  int a; cin >> a;
  int b; cin >> b;
  int MIN = min(a, b);
  int MAX = max(a, b);
  for (int i = 0; i < MAX; i++) {
    cout << MIN;
  }
  cout << '\n';
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    string a,b,c;
    cin >> a >> b >> c;

    int ans = 0;

    for(int i=0;i<n;i++){
        if(a[i]==b[i] && a[i]==c[i]){
            ans += 0;
        }
        else if(a[i]==b[i] || a[i]==c[i] || b[i]==c[i]){
            ans += 1;
        }
        else{
            ans += 2;
        }
    }
    cout << ans << endl;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;

const ll MOD = 1e9+7;

// n^m%MOD を求める。O( log(m) )
ll modpow(ll n, int m){
	ll ret=1;
	for(int i=1; i<=m; i<<=1, (n*=n)%=MOD){
		if( m&i ) (ret *= n) %= MOD;
	}
	return ret;
}

// 逆元を求める
ll modinv(ll n){
	return modpow( n, MOD-2 );
}

// 階乗を求める。O(1)  準備O( n*log(n) )
// fact[n]     : nの階乗
// fact.inv[n] : nの階乗の逆元
class FACTORIAL{
public:
	vector<ll> fact, inv;
	FACTORIAL(int MAX_NUM): fact(MAX_NUM), inv(MAX_NUM) {
		fact[0] = inv[0] = 1;
		for(ll i=1; i<MAX_NUM; i++){
			fact[i] = (fact[i-1] * i) % MOD;
			inv[i] = modinv( fact[i] );
		}
	}
	const ll& operator [ ] ( const int i ) const {
		return fact[i];
	}
} fact(200006); // nの最大値を指定


// 組み合わせ(Combinationを求める) O(1)
ll cmb(unsigned int n, unsigned int r){
	if( n < r ) return 0;
	return fact[n] * fact.inv[r] % MOD * fact.inv[n-r] % MOD;
}


vector<int> edge[200005];
map<int,pll> memo[200005];
pll solve(int n, int b){
	if(memo[n].count(b)) return memo[n][b];
	if(b >= 0 && memo[b].count(n)){
		// b -> n が存在するとき、全体の結果を使って高速化する
		auto all = solve(n, -1);
		auto sub = solve(b, n);
		ll sum = all.X;
		sum = sum * modinv(sub.X) % MOD;
		sum = sum * modinv(cmb(all.Y - 1, sub.Y)) % MOD;
		ll cnt = all.Y - sub.Y;
		return memo[n][b] = pll(sum, cnt);
	}
	ll sum = 1, cnt = 1;
	for(auto t: edge[n]) if(t != b){
		auto ret = solve(t,n);
		cnt += ret.Y;
		sum = sum * cmb(cnt - 1, ret.Y) % MOD;
		sum = sum * ret.X % MOD;
	}
	return memo[n][b] = pll(sum, cnt);
}

int main(){
	ios_base::sync_with_stdio(false);
	int N;

	cin >> N;
	rep(i,N-1){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	vector<ll> ans;
	rep(i,N) ans.push_back(solve(i,-1).X);
	for(auto t: ans) cout << t << "\n";

	return 0;
}

Measured memory_bytes: 65520
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll n; cin>>n;
    vector<ll>a(n);
    rep(i,n){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    ll ans=1;
    ll aa=1e+18;
    rep(i,n-1){
        ans*=a[i];
        if(ans==0){
            cout<<0<<endl;
            return 0;
        }
        else if(aa/ans<a[i+1]){
            cout<<-1<<endl;
            return 0;
        }
    }
    ans*=a[n-1];
    cout<<ans<<endl;
}






















Measured memory_bytes: 4052
import sys
readline = sys.stdin.readline

H,W = map(int,readline().split())
grid = [readline().rstrip() for i in range(H)]

# 各マスについて、上下左右にそれぞれ照射できるマスがいくつあるか
L = [[0] * W for i in range(H)]
R = [[0] * W for i in range(H)]
U = [[0] * W for i in range(H)]
D = [[0] * W for i in range(H)]

for i in range(H):
  cur = 0
  for j in range(W):
    if grid[i][j] == "#":
      cur = 0
    else:
      cur += 1
    L[i][j] = cur
  cur = 0
  for j in range(W - 1,-1,-1):
    if grid[i][j] == "#":
      cur = 0
    else:
      cur += 1
    R[i][j] = cur
    
for j in range(W):
  cur = 0
  for i in range(H):
    if grid[i][j] == "#":
      cur = 0
    else:
      cur += 1
    U[i][j] = cur
  cur = 0
  for i in range(H - 1,-1,-1):
    if grid[i][j] == "#":
      cur = 0
    else:
      cur += 1
    D[i][j] = cur
    
ans = 0
for i in range(H):
  for j in range(W):
    if ans < L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3:
      ans = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
      
print(ans)

Measured memory_bytes: 177416
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N, K = map(int, input().split())
    N = N % K

    ans = min(N, abs(N - K))
    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9924
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    string s;
    cin >> s;
    bool nf = false;
    bool sf = false;
    bool ef = false;
    bool wf = false;
    REP(i, s.size()) {
        switch (s[i]) {
            case 'N':
                nf = true;
                break;
            case 'S':
                sf = true;
                break;
            case 'E':
                ef = true;
                break;
            case 'W':
                wf = true;
                break;
        }
    }
    if ((nf && !sf) || (!nf && sf) || (ef && !wf) || (!ef && wf)) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

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

int main(void){
    int H, W;
    while(1){
        cin >> H >> W;
        if(H == 0 && W == 0) break;
        
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                cout << "#";
            }
            cout << "\n";
        }
        cout << endl;
    }
    
    return 0;
}


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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ANS(ans) cout << ans << endl;


int
main()
{
  int A, B; cin >> A >> B;

  if (B % A) {
    ANS(B-A);
  }else{
    ANS(B+A);
  }

  return 0;
}


Measured memory_bytes: 384
n=int(input())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
if n==1:
    print(0)
else:
    ans=0
    l=factorization(n)
    for t in l:
        i=1
        while t[1]>=i:
            t[1]-=i
            ans+=1
            i+=1
    print(ans)

Measured memory_bytes: 9492