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

public class Main {
    void run() {
        while (true) {
            int N = readInt();
            int M = readInt();
            if(N == 0 && M == 0) break;
            int[] T = new int[N];
            int[] S = new int[N];
            for (int i = 0; i < N; i++) {
                T[i] = readInt();
                S[i] = T[i] * (M / T[i]);
            }
            int minArg = 0;
            for (int i = 0; i < N; i++) {
                if (S[i] < S[minArg]) {
                    minArg = i;
                }
                else if (S[i] == S[minArg] && T[i] < T[minArg]) {
                    minArg = i;
                }
            }

            int hope = 0;
            for (int i = 0; i < N; i++) {
                if(S[i] == S[minArg] && T[i] == T[minArg]) {
                    hope++;
                }
            }
            if(hope >= 2) {
                sysout.println(N);
            }
            else {
                sysout.println(minArg + 1);
            }
        }
    }

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

    // flush automatically iff you call `println` or `printf` or `format`.
    PrintWriter sysout = new PrintWriter(System.out, true);

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer buffer = new StringTokenizer("");

    String read() {
        if (!buffer.hasMoreTokens()) {
            try {
                buffer = new StringTokenizer(in.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return buffer.nextToken();
    }

    int readInt() {
        return Integer.parseInt(read());
    }

    long readLong() {
        return Long.parseLong(read());
    }

    double readDouble() {
        return Double.parseDouble(read());
    }

    String readLine() {
        buffer = new StringTokenizer("");
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define hash dhsjakhd
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

ll n,m,T,k,q;
const ll big = 1000000007;
const ll big2 = 998244353;

ll MX[1001] = {0};
ll MY[1001] = {0};

ll F[1000001] = {0};

ll FX[1000001] = {0};
ll FY[1000001] = {0};

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,e;


    cin >> n >> m;
    ll ans = 1;
    for(int c1 = 0; c1 < n; c1++){
        cin >> a;
        MX[c1] = a;
        FX[a]++;
    }
    for(int c1 = 0; c1 < m; c1++){
        cin >> a;
        MY[c1] = a;
        FY[a]++;
    }
    for(int c1 = 0; c1 < n; c1++){
        for(int c2 = 0; c2 < m; c2++){
            F[min(MX[c1],MY[c2])]++;
        }
    }
    ll sum = 0;
    for(ll c1 = 1; c1 <= n*m; c1++){
        a = n*m-c1+1;
        sum += F[a];
        ll choices = sum-c1+1;
        if(FX[a] > 1 || FY[a] > 1)ans = 0;
        if(FX[a] == 1 || FY[a] == 1)choices = F[a];
        if(FX[a] == 1 && FY[a] == 1)choices = 1;
        if(choices <= 0)ans = 0;
        ans *= choices;
        ans %= big;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int left = 0, right = 0;
    rep(i, n){
        if(s.at(i) == ')' && right == 0){
            left++;
        }
        else if(s.at(i) == ')'){
            right--;
        }
        else {
            right++;
        }
    }
    rep(i, left){
        s = '('+s;
    }
    rep(i, right){
        s = s+')';
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stack>

using namespace std;
   
#define INF 1000000
#define WALL -1

struct S{
	int x,y,t;
};

int main(void){
      
    int fi[122][122]; ///-60~60 -> 1~121 //
	int t,n;
	int x,y;
	int dy[]={ 1, 1, 0,-1,-1, 0};
	int dx[]={ 0, 1, 1, 0,-1,-1};
	int cnt;
	stack<S> s;
	S s1,s2;

	while(1){
		cin>>t>>n;
		if(t==0&&n==0) break;
		for(int i=0;i<122;i++){
			for(int j=0;j<122;j++){
				fi[i][j]=INF;
			}
		}
		for(int i=0;i<n;i++){
			cin>>x>>y;
			fi[y+61][x+61]=WALL;
		}
		cin>>x>>y;
		s1.x=x+61,s1.y=y+61,s1.t=0;
		fi[y+61][x+61]=0;
		cnt=1;
		s.push(s1);
		while(!s.empty()){
			s1=s.top();
			s.pop();
			for(int i=0;i<6;i++){
				if(fi[s1.y][s1.x]+1<fi[s1.y+dy[i]][s1.x+dx[i]]){
					if(fi[s1.y+dy[i]][s1.x+dx[i]]==INF) cnt++;
					fi[s1.y+dy[i]][s1.x+dx[i]]=fi[s1.y][s1.x]+1;
					s2.x=s1.x+dx[i],s2.y=s1.y+dy[i],s2.t=fi[s1.y][s1.x]+1;
					if(s2.t!=t) s.push(s2);
				}
			}
		}
		cout<<cnt<<endl;
	}

    return 0;
}

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

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

    int num = a + b;
    int kai = 0;
    int so = 0;
    for(int i = 0;i < n;i++){
        if(s[i] == 'c'){
            cout << "No" << endl;
        }else if(s[i] == 'a'){
            if(so < num){
                so++;
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
        }else{
            if(so < num && kai < b){
                so++;
                kai++;
                cout << "Yes" << endl;
            }else{
                cout << "No" << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 896
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) (a).begin(), (a).end()

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }

int main() {
    int n;
    char c;
    set<char> st;
    cin >> n;
    while (n--) {
        cin >> c;
        st.insert(c);
    }

    if (st.size() == 3) {
        cout << "Three" << endl;
    }
    else {
        cout << "Four" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
MOD = 10**9 + 7
 
D = [[0]*(K+1) for i in range(N+1)]
for n in range(0, N+1):
    D[n][1] = 1
for k in range(1, K+1):
    D[0][k] = 1
for n in range(1, N+1):
    for k in range(1, K+1):
        if n >= k:
            D[n][k] = (D[n-k][k] + D[n][k-1]) % MOD
        else:
            D[n][k] = D[n][n]
print(D[N][K])


Measured memory_bytes: 29348
#include<stdio.h>
int main(){
  int h,w,i,j,k;
  char s[110][110];
  scanf("%d %d",&h,&w);
  for(i=0;i<h;i++)scanf("%s",s[i]);
  for(i=0;i<h;i++){
    for(j=k=0;j<w;j++){
      if(s[i][j]=='#')k=1;
    }
    if(k==0){
      for(j=0;j<w;j++)s[i][j]='*';
    }
  }
  for(j=0;j<w;j++){
    for(i=k=0;i<h;i++){
      if(s[i][j]=='#')k=1;
    }
    if(k==0){
      for(i=0;i<h;i++)s[i][j]='*';
    }
  }//*/
  for(i=0;i<h;i++){
    for(j=k=0;j<w;j++){
      if(s[i][j]-'*'){
	k=1;
	printf("%c",s[i][j]);
      }
    }
    if(k)printf("\n");
  }
  return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**6)
N = (int)(input())
edges = []
for _ in range(N-1):
    edges.append((list)(map(int, input().split())))

Q, K = (list)(map(int, input().split()))
querys = []
for _ in range(Q):
    querys.append((list)(map(int, input().split())))

'''
 N:num of nodes
 Q: num of query
 K: node must passed in query

'''
dist = [-1]*(N+1)
for e in edges:
    if dist[e[0]] == -1:
        dist[e[0]] = [[e[1], e[2]]]
    else:
        dist[e[0]].append([e[1], e[2]])

    if dist[e[1]] == -1:
        dist[e[1]] = [[e[0], e[2]]]
    else:
        dist[e[1]].append([e[0], e[2]])

dist_from_k = [-1]*(N+1)


def dfs(v, cost):
    if dist_from_k[v] != -1:
        return

    dist_from_k[v] = cost
    for e in dist[v]:
        dfs(e[0], cost+e[1])


dfs(K, 0)

for q in querys:
    print(dist_from_k[q[0]] + dist_from_k[q[1]])


Measured memory_bytes: 171292
#include<iostream>
#include <math.h>
using namespace std;

int main(){
	typedef long long int ll;
	ll N;
	cin>>N;
	ll S=0;
	for(int i=1;i<=N;i++){
		S+=i;
	}
	ll W=N/3;
	ll E=3*W;
	ll T=(3+E)*W/2;

	ll A=N/5;
	ll Q=5*A;
	ll O=(5+Q)*A/2;

	ll H=N/15;
	ll D=15*H;
	ll P=(15+D)*H/2;

	cout<<S-T-O+P<<endl;

	return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<int> arr;
  map<int, ll> amap;
  int tmp;
  for(int i=1;i<=N;++i) {
    tmp = i;
    for(int j=2;j*j<=tmp;++j) {
      if(tmp%j==0) {
        if(amap[j]==0) arr.push_back(j);
        while(tmp%j==0) {
          amap[j]++;
          tmp /= j;
        }
      }
    }
    if(tmp>1) {
      if(amap[tmp]==0) arr.push_back(tmp);
      amap[tmp]++;
    }
  }
  ll ans = 1;
  for(int i=0;i<arr.size();++i) {
    ans *= amap[arr[i]]+1;
    ans %= mod;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3580
#include<cmath>
#include<cstdio>
using namespace std;
const int N=5e5+5;
int n,q,x,d[N],a[N],f[N];
void read(int &n)
{
   	int x=0;
    	char ch=getchar();
    	while (ch<'0' || ch>'9') ch=getchar();
    	while (ch<='9' && ch>='0') x=(x<<1)+(x<<3)+ch-48,ch=getchar();
    	n=x;
}
int min(int a,int b){return a<b?a:b;}
int main()
{
	read(n),read(a[0]);
	for (int i=1;i<=n;i++)
	{
		read(d[i]);
		a[i]=min(a[i-1],abs(a[i-1]-d[i]));
	}
	f[n+1]=1;
	for (int i=n;i;i--) f[i]=d[i]>=2*f[i+1]?f[i+1]:f[i+1]+d[i];
	for (read(q);q;q--)
	{
		read(x);
		printf(a[x-1]>=f[x+1]?"YES\n":"NO\n"); 
	}
	return 0;
}


Measured memory_bytes: 7680
#include <stdio.h>

int rot[24][7] = {
	{ 0,1,2,3,4,5,6 },{ 0,1,3,5,2,4,6 },{ 0,1,4,2,5,3,6 },{ 0,1,5,4,3,2,6 },
	{ 0,2,6,3,4,1,5 },{ 0,2,3,1,6,4,5 },{ 0,2,1,4,3,6,5 },{ 0,2,4,6,1,3,5 },
	{ 0,3,1,2,5,6,4 },{ 0,3,2,6,1,5,4 },{ 0,3,5,1,6,2,4 },{ 0,3,6,5,2,1,4 },
	{ 0,4,1,5,2,6,3 },{ 0,4,2,1,6,5,3 },{ 0,4,5,6,1,2,3 },{ 0,4,6,2,5,1,3 },
	{ 0,5,1,3,4,6,2 },{ 0,5,3,6,1,4,2 },{ 0,5,4,1,6,3,2 },{ 0,5,6,4,3,1,2 },
	{ 0,6,2,4,3,5,1 },{ 0,6,3,2,5,4,1 },{ 0,6,5,3,4,2,1 },{ 0,6,4,5,2,3,1 } };
int assign[7];

int main()
{
	int i, j;
	int a[7], b[7], dice[7];

	for (i = 1; i <= 6; i++) scanf("%d", assign+i);
	for (i = 1; i <= 6; i++) scanf("%d", a+i);
	for (j = 0; j < 24; j++) {
		for (i = 1; i <= 6; i++) dice[i] = rot[j][i];
		for (i = 1; i <= 6; i++) b[i] = assign[dice[i]];
		for (i = 1; ; i++) {
			if (i > 6) { puts("Yes"); return 0; }
			if (a[i] != b[i]) break;
		}
	}
	puts("No");
	return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  int t = 1900 * M + 100 * (N - M);
  for (int i = 0; i < M; i++){
    t *= 2;
  }
  cout << t << endl;
}

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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val,typename Number>
//use ll or int for gcd
Val gcd(Val a, Val b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
//count vector and return pair (count,vector item)
template <typename Val,typename Number>
void count_vector(vector<Val>* A,vector<pair<Number,Val>>*R){
  sort(A->begin(),A->end());
  int count = 1;
  rep(i,A->size()){
    if(i<A->size()-1){
      if(A->at(i)==A->at(i+1))count++;
      else{
        R->push_back(make_pair(count,A->at(i)));
        count = 1;
      }
    }else{
      R->push_back(make_pair(count,A->at(i)));
      count = 1;
    }
  }
}

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

int main(){
  int N,K;
  string ans = "No";

  cin>>N;
  int e2,e4,odd;
  e2=e4=odd=0;
  rep(i,N){
    ll A;
    cin>>A;
    if(A%4==0)e4++;
    else if(A%2==0)e2++;
    else odd++;
  }
  if(odd<e4+1){
    ans = "Yes";
  }else if(e2 == 0&&odd==e4+1){
    ans ="Yes";
  }else if(odd == 0){
    ans ="Yes";
  }


  cout<<ans<<endl;
}


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

using namespace std;

#define int long long

const int N=300005,mod=998244353;

int fact[N],_fact[N];

int poww(int a,int m){
    int res=1,now=a;
    for(;m;m>>=1,now=(now*now)%mod) if(m&1) res=(res*now)%mod;
    return res;
}

int C(int k,int n){
    return (fact[n]*((_fact[k]*_fact[n-k])%mod))%mod;
}

int n,a,b,K,ans;

signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    fact[0] = 1; for(int i = 1; i < N; ++i) fact[i] = (fact[i-1] * i)%mod;
    for(int i = 0; i < N; ++i) _fact[i] = poww(fact[i], mod - 2);
    cin >> n >> a >> b >> K;

    for(int i = 0; i <= n; ++i){
        if( (K - (i*a)) % b == 0 ){
            int j = ( K - ( i * a ) ) / b;
            if(j >=0 && j<= n){;
                ans += ( C(i, n) * C(j, n) ) % mod; ans %= mod;
            }
        }
    }

    cout << ans;

    return 0;
}


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

int main() {
  int64_t N;
  cin >> N;
  int64_t a, b, c;
  int64_t s;
  a = N / 3;
  b = N / 5;
  c = N / 15;
  s = N*(N+1)/2-a*(a+1)/2*3-b*(b+1)/2*5+c*(c+1)/2*15;
  cout << s << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

signed main() {
  string C;
  cin >> C;
  ll Cll = C[0];
  Cll++;
  char ans = (char)Cll;
  COUT(ans);
  return 0;
}

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

using namespace std;

int main(void){
  int N;
  cin >> N;
  vector<long long> A(N);
  map<long long, long long> c;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    c[A[i]]++;
  }
  long long total = 0;
  for(auto itr = c.begin(); itr != c.end(); itr++){
    total += itr -> second * (itr -> second - 1) / 2;
  }
  for(int i = 0; i < N; i++){
    cout << total - c[A[i]] + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 11008
N, M, Q = map(int, input().split())
X = []
for m in range(M):
    li, ri = map(int, input().split())
    li, ri = li-1, ri-1
    X.append([li, ri])


class Ruisekiwa2D:
    def __init__(self, h, w):
        self.H = h
        self.W = w
        self.G = [[0] * w for _ in range(h)]

    def load(self, points):
        # 問題によってイメージしやすいよう書き換えてください
        for x, y in points:
            self.G[x][y] += 1

        self.calc()

    def calc(self):
        for y in range(self.W):
            for x in range(1, self.H):
                self.G[x][y] += self.G[x-1][y]

        for x in range(self.H):
            for y in range(1, self.W):
                self.G[x][y] += self.G[x][y-1]

    def get(self, i1, j1, i2, j2):
        if i1 > 0 and j1 > 0:
            return self.G[i2][j2] - self.G[i1-1][j2] - self.G[i2][j1-1] + self.G[i1-1][j1-1]

        elif i1 <= 0 < j1:
            return self.G[i2][j2] - self.G[i2][j1-1]

        elif j1 <= 0 < i1:
            self.G[i2][j2] - self.G[i1 - 1][j2]

        else:
            return self.G[i2][j2]


R2D = Ruisekiwa2D(N, N)
R2D.load(X)
for i in range(Q):
    p, q = map(int, input().split())
    p, q = p-1, q-1
    print(R2D.get(p, p, q, q))


Measured memory_bytes: 40040
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;

#define int           long long 
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define ub            upper_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (int)(4e18)
// #define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>
#define ordered_set   tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v){
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}


void solve() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max({b*d, a*c, a*d, b*c}) << endl;
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   
    start = clock(); 

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin); 
    // freopen("output.txt", "w", stdout);
    // freopen("error.txt", "w", stderr);
    // #endif

    int test = 1;
    // cin >> test;
    
    cout << fixed << setprecision(2);
     
    for(int i = 1; i <= test; ++i){
    	solve();
    }

    cerr << time(start);
    return 0;
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int n; cin >> n;
    int l; cin >> l;
    int all_taste = 0;
    FOR(i,1,n){
        all_taste+=l+i-1;
    }
    int cur=INF;
    FOR(i,1,n){
        if (abs(cur) > abs(l+i-1)){
            cur = l+i-1;
        }
    }
    cout << all_taste-cur << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define F  first
#define S  second
#define ff(i,n) for(i=0;i<n;i++)
ll bg = 10000020930000;
int main()
{ 
	ll t;
	t=1;
	while(t--)
	{
		ll i,x,n;
		cin>>x>>n;
		ll arr[n];
		set<ll> set1;
		vector<pair<ll,ll> >vec;
		ff(i,n)
		{		
			cin>>arr[i];
			set1.insert(arr[i]);
		}
		for(i=-1000;i<=1000;i++)
		{
			if(set1.find(i)==set1.end())
				vec.pb(mp(abs(i-x),i));
		}
		sort(vec.begin(),vec.end());
		cout<<vec[0].second;
	}
	return 0;
}

Measured memory_bytes: 3692
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

#define MAX_N 2001
using namespace std;
typedef long long ll;
ll L[MAX_N];

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

    ll N; cin >> N;
    for(ll i = 0; i < N; i++) cin >> L[i];
    sort(L, L + N);

    ll a, b, cmin, cmax, target;
    ll ans = 0;
    
    for(ll i = 0; i < N - 1; i++) {
      for(ll j = i; j < N; j++) {
	if (i == j) continue;
	a = L[i]; b = L[j];

	target = a + b;
	ll lb, ub, mid;
	lb = -1; ub = N;
	while (lb + 1 < ub) {
	  mid = (lb + ub) / 2;  
	  if (L[mid] < target) lb = mid;
	  else ub = mid;
	}
	cmax = lb;
	
	target = b - a;
	lb = -1; ub = N;
	while (lb + 1 < ub) {
	  mid = (lb + ub) / 2;  
	  if (L[mid] > target) ub = mid;
	  else lb = mid;
	}
	cmin = ub;

	ll add = 0;
	add = (cmax - cmin + 1);
	if (cmin <= i && i <= cmax) add--;
	if (cmin <= j && j <= cmax) add--;
	ans += add;
      }
    }

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



Measured memory_bytes: 384
function main(input) {
    const args = input.split(' ');
    const a = parseInt(args[0], 10);
    const b = parseInt(args[1], 10);

    calc(a,b);
}
function calc(a, b){
    if ((a * b) % 2 === 0) {
        console.log('Even');
    } else {
        console.log('Odd');
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
//main();

Measured memory_bytes: 7372
#include <stdio.h>
int main(){
  int i,n;
  while (scanf("%d",&n)){
    if (n==0)
      break;
    int t=n*(n-1)/2,temp=0,cnt=0;
    for (i=0;i<t;i++){
      scanf("%d",&temp);
      cnt+=temp;
    }
    printf("%d\n",cnt/(n-1));
  }

  return 0;
}

Measured memory_bytes: 600
#include<ctime>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<unordered_map>
#define file(x)freopen(x".in","r",stdin);freopen(x".out","w",stdout)
#define rt register int
#define l putchar('\n')
#define ll long long
#define r read()
using namespace std;
inline ll read(){
    ll x=0;char zf=1;char ch=getchar();
    while(ch!='-'&&!isdigit(ch))ch=getchar();
    if(ch=='-')zf=-1,ch=getchar();
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();return x*zf;
}
void write(ll y){if(y<0)putchar('-'),y=-y;if(y>9)write(y/10);putchar(y%10+48);}
void writeln(const ll y){write(y);putchar('\n');}
int k,m,n,x,y,z,cnt,ans;
unordered_map<int,int>b[200010];
int Min[200010];
int main(){
	n=r;m=r;int q=r;
	for(rt i=1;i<=n;i++)Min[i]=m+1;
	for(rt i=1;i<=q;i++){
		x=r;y=r;Min[x]=min(Min[x],y);
		b[x][y]=1;
	}
	for(rt x=2,y=1;x<=n;x++){
		if(!b[x][y+1]&&y<m)y++;
		if(y>=Min[x]){
			write(x-1);
			return 0;
		}
	}
	write(n);
	return 0;
}


Measured memory_bytes: 30592
from collections import deque
n,m,*L=map(int,open(0).read().split())
con=[[]for _ in range(n)]
for a,b in zip(*[iter(L)]*2):
	con[a-1].append(b-1)
	con[b-1].append(a-1)
q=deque([0])
par=[-1]*n
par[0]=1
while q:
	cur=q.popleft()
	for nxt in con[cur]:
		if par[nxt]==-1:
			par[nxt]=cur+1
			q.append(nxt)
if any(x==-1 for x in par):
	print("No")
	exit()
print("Yes")
print("\n".join(map(str,par[1:])))

Measured memory_bytes: 60272
// https://atcoder.jp/contests/abc129/tasks/abc129_b

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, sum = 0, cnt = 0, minv = INF;
    cin >> n;
    vector<int> w(n);
    for (auto &x : w) {
        cin >> x;
        sum += x;
    }
    for (auto &x : w) {
        cnt += x;
        minv = min(minv, abs(sum - cnt * 2));
    }
    cout << minv << endl;

    return 0;
}


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

public class Main {

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

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      final int n = Integer.parseInt(br.readLine());
      String op;
      String[] words;
      Tree tree = new Tree();

      for(int i=0,k=0; i<n; i++,k=0){
        words = br.readLine().split(" ");
        op  = words[k++];
        if ( op.equals("insert") ) { 
          tree.insert(Integer.parseInt(words[k++]));
        }
        else {
          tree.dispRoundPath();
        }
      }

    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }
}

class Tree {

  static final BTreeNode NIL = new BTreeNode(-1);
  BTreeNode root;
  StringBuilder buf;

  public Tree() {
    root = NIL;
    buf = new StringBuilder();
  }

  public void insert(int val) {
    BTreeNode y = NIL;
    BTreeNode x = root;
    BTreeNode z = new BTreeNode(val);

    while( !x.equals(NIL) ) {
      y = x;
      if( z.key < x.key )
        x = x.left;
      else
        x = x.right;
    }
    z.parent = y;

    if( y.equals(NIL) ){
      root = z;
    }
    else if( z.key < y.key )
      y.left = z;
    else
      y.right = z;
  } 
  void preParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      buf.append(" ").append(u.key);
      preParse(u.left);
      preParse(u.right);
    }
  }
  void inParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      inParse(u.left);
      buf.append(" ").append(u.key);
      inParse(u.right);
    }
  }

  void dispRoundPath() {

    inParse(root);
    buf.append("\n");
    preParse(root);
    buf.append("\n");

    System.out.print(buf);
    buf.setLength(0);
  }
}

class BTreeNode {
  int key;
  BTreeNode parent,left,right;

  public BTreeNode(int key) {
    this.key = key;
    this.parent =
    this.left =
    this.right = Tree.NIL;
  }

  @Override
  public boolean equals(Object o) {
    if(o == this) return true;
    if(o == null) return false;
    if(!(o instanceof BTreeNode)) return false;

    BTreeNode node = (BTreeNode)o;
    if(!(this.key == node.key)) return false;

    return true;
  }
}


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


#define ull unsigned long long int
#define ll long long
#define vi vector<int>
#define mii map<int,int>
#define all(x) x.begin(),x.end()
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define MOD 1e9+7
#define INF 0x3f3f3f3f

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

int main()
{
string s,t;
cin>>s>>t;
int ans = 0 ; 
for(int i = 0 ;i<s.length();i++)
if(s[i]!=t[i])
ans++;
cout<<ans<<endl;
}


Measured memory_bytes: 3916
ar = list(input())
br = set(ar)
if len(br) == 4:
    print("Yes")
elif len(br) == 1 or len(br) == 3:
    print("No")
else:
    if "N" in br and "S" in br:
        print("Yes")
    elif "E" in br and "W" in br:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
num = input()


if int(num[0])+int(num[1])+int(num[2])+int(num[3])==7:
  print(num[0]+"+"+num[1]+"+"+num[2]+"+"+num[3]+"=7")
  exit()
elif int(num[0])+int(num[1])+int(num[2])-int(num[3])==7:
  print(num[0]+"+"+num[1]+"+"+num[2]+"-"+num[3]+"=7")
  exit()
elif int(num[0])+int(num[1])-int(num[2])+int(num[3])==7:
  print(num[0]+"+"+num[1]+"-"+num[2]+"+"+num[3]+"=7")
  exit()
elif int(num[0])+int(num[1])-int(num[2])-int(num[3])==7:
  print(num[0]+"+"+num[1]+"-"+num[2]+"-"+num[3]+"=7")
  exit()
elif int(num[0])-int(num[1])+int(num[2])+int(num[3])==7:
  print(num[0]+"-"+num[1]+"+"+num[2]+"+"+num[3]+"=7")
  exit()
elif int(num[0])-int(num[1])+int(num[2])-int(num[3])==7:
  print(num[0]+"-"+num[1]+"+"+num[2]+"-"+num[3]+"=7")
  exit()
elif int(num[0])-int(num[1])-int(num[2])+int(num[3])==7:
  print(num[0]+"-"+num[1]+"-"+num[2]+"+"+num[3]+"=7")
  exit()
elif int(num[0])-int(num[1])-int(num[2])-int(num[3])==7:
  print(num[0]+"-"+num[1]+"-"+num[2]+"-"+num[3]+"=7")
  exit()

Measured memory_bytes: 3192
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cctype>
#include <functional>
#include <string>
#include <cstring>
#include <sstream>
#include <deque>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> Q;

const int inf1=2e9+9;
const ll inf2=8e18+9;
const ll mol=998244353;
const int maxn=1e5+9;
const int maxx=1e9+9;

int n;
ll ar[maxn];

int main()
{
    scanf("%d",&n);
    int flag=0;
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&ar[i]);
        if(ar[i]==0) flag=1;
    }
    if(flag) printf("0\n");
    else
    {
        ll limit=1e18;
        ll sum=1;
        flag=1;
        for(int i=0;i<n&&flag;i++)
        {
            ll tmp=sum*ar[i];
            if(tmp<sum||tmp<ar[i]||tmp>limit) flag=0;
            else sum=tmp;
        }
        if(flag) printf("%lld\n",sum);
        else printf("-1\n");
    }
}


Measured memory_bytes: 4008
#include<cstdio>

int n;
long x, ans;
long po[51];

void dfs(int n, long x) {
    if (x == 2 * po[n] - 1) ans += po[n];
    else if (x >= po[n]) {
        ans += po[n - 1] + 1;
        dfs(n - 1, x - po[n]);
    }
    else if (x > 0) {
        dfs(n - 1, x - 1);
    }
}

int main() {
    scanf("%d %ld", &n, &x);
    po[0] = 1;
    for (int i = 1; i <= n; i++) po[i] = 2 * po[i - 1] + 1;
    dfs(n, x);
    printf("%ld\n", ans);
    return 0;
}   


Measured memory_bytes: 256
def gcd(a,b)
    while b > 0
        a,b = b,a%b
    end
    return a
end

n,x=gets.chomp.split.map(&:to_i)
xi=gets.chomp.split.map(&:to_i)
xi2 = xi.map{|v| (x-v).abs}
if n == 1
    puts xi2[0]
    exit
end

g = gcd(xi2[0],xi2[1])
2.upto(n-1) do |i|
    g=gcd(g,xi2[i])
end
puts g


Measured memory_bytes: 10244
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in);
        String s="";
        while(in.hasNext()) s+=in.nextLine();
        s=s.toLowerCase();
		char[] a={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
        for(char c:a){
        	int r=0;
        	for(int i=0;i<s.length();i++){
            	if(s.charAt(i)==c) r+=1; 
        	}
        	System.out.println(c+" : "+r);
        }
	}
}

Measured memory_bytes: 26252
/* ****revpro**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl	   '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii	    map<ll,ll>
using namespace std;

#define N  100005
ll add(ll x,ll y,ll mod=hell) { x += y; if(x >= mod) x -= mod; return x;}
ll sub(ll x,ll y,ll mod=hell) { x -= y; if(x < 0) x += mod; return x;}
ll mul(ll x,ll y,ll mod=hell) { return (x * 1ll * y) % mod;}
ll  num[2][65]; // two numbers num[0]>=num[1]
ll DP[65][2][2][2][2];
ll call(ll pos,ll f1,ll f2,ll f3,ll f4){
    if(pos == 65)
      return 1;
    if(DP[pos][f1][f2][f3][f4] != -1) return DP[pos][f1][f2][f3][f4];
    ll res = 0;
    ll LMT1 = f1?1:num[0][pos];
    ll ST1 = f2?0:num[1][pos];
    ll LMT2 = f3?1:num[0][pos];
    ll ST2 = f4?0:num[1][pos];
    rep(dgt1,ST1,LMT1+1){
    	rep(dgt2,ST2,LMT2+1) 
    		if(dgt2<=dgt1)
            	res = add(res,call(pos+1,f1||(dgt1<LMT1),f2||(dgt1>ST1),f3||(dgt2<LMT2),f4||(dgt2>ST2)));
    }
    return DP[pos][f1][f2][f3][f4] = res;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		memset(DP,-1,sizeof(DP));
		ll l,r;
		cin>>l>>r;
		rep(i,0,65){
			num[1][i]=l&1;
			l>>=1;
		}
		rep(i,0,65){
			num[0][i]=r&1;
			r>>=1;
		}
		reverse(num[0],num[0]+65);
		reverse(num[1],num[1]+65);
		ll f1=0,f2=0,f3=0,f4=0;
		ll res = 0;
	    rep(i,0,65){
		    ll LMT1 = f1?1:num[0][i];
		    ll ST1 = f2?0:num[1][i];
		    ll LMT2 = f3?1:num[0][i];
		    ll ST2 = f4?0:num[1][i];
	    	if(LMT1==1&&LMT2==1){
	    		ll dgt1=1,dgt2=1;
	    		res=add(res,call(i+1,f1||(dgt1<LMT1),f2||(dgt1>ST1),f3||(dgt2<LMT2),f4||(dgt2>ST2)));
	    	}
	    	if(ST1==0&&ST2==0)
	    	{ll dgt1=0,dgt2=0;
	    	f1=f1||(dgt1<LMT1),f2=f2||(dgt1>ST1),f3=f3||(dgt2<LMT2),f4=f4||(dgt2>ST2);}
	    	else break;
	    }
	    cout<<res;
	}
	return 0;
}

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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> F(M,0);
  vector<int> K(N);
  int x;
  for(int i=0;i<N;i++){
    cin >> K.at(i);
    for(int j=0;j<K.at(i);j++){
      cin >> x;
      F.at(x-1) ++;
    }
  }
  int ans = 0;
  for(int i=0;i<M;i++){
    if(F.at(i) == N){
      ans ++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	string A;
	cin >> A;
	N = A.size();
	vector< int > dp(N + 1);
	vector< bool > done(26, false);
	int c = 0, k = 0;
	for (int i = N; i > 0; i--) {
		int a = A[i - 1] - 'a';
		if (!done[a]) {
			++c;
			done[a] = true;
		}
		dp[i] = k;
		if (c == 26) {
			++k;
			c = 0;
			done.assign(26, false);
		}
	}
	dp[0] = k;
	string ans = "";
	done.assign(26, false);
	int i = 0, j = k;
	while (i <= N) {
		//cout << i << endl;
		if (i == N || dp[i + 1] < j) {
			rep(k, 26) {
				if (done[k] == false) {
					ans.push_back('a' + k);
					while (i < N && A[i] != 'a' + k)
						++i;
					break;
				}
			}
			--j;
			done.assign(26, false);
			++i;
			continue;
		}
		done[A[i] - 'a'] = true;
		++i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2180
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100000;
const int T = 19; // log N
int x[N];
int m[N][T]; // 点iから2^j日で右方向に移動できる最大の点
int n;
int l;

int solve(int a, int b) {
  for(int i = 0; i < T; i++) {
    if(m[a][i] >= b) {
      if(i == 0) return 1;
      return solve(m[a][i - 1], b) + (1 << (i - 1));
    }
  }
  for(;;);
  return -1;
}


int main() {
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> x[i];
  }
  cin >> l;
  for(int i = 0; i < n; i++) {
    int index = lower_bound(x, x + n, x[i] + l + 1) - x; // 辿り付けない最小の点
    m[i][0] = index - 1;
  }
  for(int t = 0; t < T - 1; t++) {
    for(int i = 0; i < n; i++) {
      m[i][t + 1] = m[m[i][t]][t];
    }
  }
  int q;
  cin >> q;
  for(int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    cout << solve(min(a, b) - 1, max(a, b) - 1) << endl;
  }
  return 0;
}


Measured memory_bytes: 8704
import java.util.Scanner;

//Pablo Squarson's Headache
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] dt = {{-1,0},{0,-1},{1,0},{0,1}};
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int[][] p = new int[n][2];
			p[0][0] = 0;
			p[0][1] = 0;
			int minx = 0;
			int miny = 0;
			int maxx = 0;
			int maxy = 0;
			for(int i=1;i<n;i++){
				int id = sc.nextInt();
				int d = sc.nextInt();
				int nx = p[id][0] + dt[d][0];
				int ny = p[id][1] + dt[d][1];
				minx = Math.min(minx, nx);
				maxx = Math.max(maxx, nx);
				miny = Math.min(miny, ny);
				maxy = Math.max(maxy, ny);
				p[i][0] = nx;
				p[i][1] = ny;
			}
			System.out.println((maxx-minx+1) + " " + (maxy-miny+1));
		}
	}
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <queue>
#include <stdarg.h>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <numeric>
#include <set>

#define ll long long

using namespace std;

bool
check(vector<pair<int, int>> & data) {
  int now = 0;
  sort(data.rbegin(), data.rend());
  for (auto & p : data) 
    if (p.first + now >= 0)
      now += p.second;
    else 
      return false;

  return true;
}

void
solve() {
  int n;
  cin>>n;

  vector<pair<int, int>> up;
  vector<pair<int, int>> down;
  string s;
  int total = 0;
  for (int i=0; i<n; i++) {
    cin>>s;

    int bottom = 0;
    int change = 0;
    for (auto & c : s) {
      if (c == '(')
        change++;
      else
        change--;

      bottom = min(bottom, change);
    }

    if (change >= 0)
      up.push_back({bottom, change});
    else
      down.push_back({bottom-change, -change});
    total += change;
  }

  if (check(up) && check(down) && total == 0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

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

  int t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}




Measured memory_bytes: 11236
#pragma GCC optimize(2)
#include<bits/stdc++.h> 
using namespace std;
#define ll long long
#define endl "\n"
const int MAX=1e6+7;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int pre[MAX],a[MAX],n;
vector<int>g[MAX];
void init(int n)
{
    for(int i=0;i<=n;i++)
        pre[i]=i;
}
int FIND(int x)
{
    return pre[x]==x?x:pre[x]=FIND(pre[x]);
}
void mix(int a,int b)
{
    int fa=FIND(a),fb=FIND(b);
    if(fa!=fb){
        pre[fa]=fb;
    }
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
	int n,m;cin>>n>>m;
	init(n);
	for(int i=0;i<m;i++){
		int u,v;cin>>u>>v;
		mix(u,v);
	}
	unsigned ll ans=0;
	for(int i=1;i<=n;i++){
		int fa=FIND(i);
		g[fa].push_back(i);
		ans=max(ans, 1ll*g[fa].size() );
	}
	cout<<ans;
	
   return 0;
}  

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

int main(){
    ll n;
    string s;
    cin>>s;
    for(ll i=0;i<(ll)s.size();i++)  n+=(ll)(s[i]-'0');
    if(n%9ll==0ll)  cout<<"Yes"<<endl;
    else            cout<<"No"<<endl;   
    return 0;
}


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define re register
#define il inline
#define inf 0x3f3f3f
using namespace std;

const int MAXN = 1e5 + 10;
int n, m, first[MAXN], tot, d[MAXN], s, t;

struct edge {
  int from, v, w;
} e[20 * MAXN];
struct Node {
  int x, d;
  bool operator<(const Node &b) const { return d > b.d; }
} cyc;
priority_queue<Node> q;
inline void insert(int u, int v, int w) {
  tot++;
  e[tot].v = v;
  e[tot].w = w;
  e[tot].from = first[u];
  first[u] = tot;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (register int i = 1; i <= n; i++)
    for (register int j = 0; j <= 9; j++)
      insert(i, ((i - 1) * 10 + j) % n + 1, j);
  for (register int j = 1; j <= 9; j++)
    insert(0, j + 1, j);
  s = 0;
  t = 1;
  memset(d, 0x3f, sizeof d);
  d[s] = 0;
  q.push((Node){s, d[s]});
  while (!q.empty()) {
    cyc = q.top();
    q.pop();
    if (cyc.d != d[cyc.x])
      continue;
    register int x = cyc.x;
    for (register int i = first[x]; i; i = e[i].from)
      if (d[e[i].v] > d[x] + e[i].w) {
        d[e[i].v] = d[x] + e[i].w;
        q.push((Node){e[i].v, d[e[i].v]});
      }
  }
  return cout << d[t], 0;
}


Measured memory_bytes: 15476
#include<stdio.h>
#include<string.h>
int main(){
  char s[200001];
  scanf("%s",s);
  int n=strlen(s);
  int a=0, z=0;
  for(int i=0; i<n; i++){
    if(s[i]=='A'){
      a=i;
      break;
    }
  }
  for(int j=n-1; j>0; j--){
    if(s[j]=='Z'){
      z=j;
      break;
    }
  }
  printf("%d\n",z-a+1);
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int n,a,b,c;
vector<int> v;

int dfs(int num,int aa,int bb,int cc){
    int ret;
    int u,r,y,s;
    
    if(num==n){
        if(aa==0||bb==0||cc==0){
            return 100000000;
        }else{
            ret=abs(a-aa)+abs(b-bb)+abs(c-cc)-30;}
    }else{
        u=dfs(num+1,aa+v[num],bb,cc)+10;
        r=dfs(num+1,aa,bb+v[num],cc)+10;
        y=dfs(num+1,aa,bb,cc+v[num])+10;
        s=dfs(num+1,aa,bb,cc);
        ret=min({u,r,y,s});
    }
    
    return ret;
}



int main(){
    cin>>n>>a>>b>>c;
    rep(i,n){
        int x;cin>>x;
        v.push_back(x);
    }
    cout<<dfs(0,0,0,0)<<endl;
    
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
        long long int a, b1, b2;
        cin >> a;
        char c;
        cin >> b1 >> c >> b2;
        a = a * (b1 * 100 + b2) / 100;
        cout << a << endl;
    return 0;
}


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

using namespace std;

int main() {
    long long int n,i,j,k;
    cin>>n;
    long long int a[n][3];
    for(i=0;i<n;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    for(i=1;i<n;i++)
    {   
        for(j=0;j<3;j++)
        {
            a[i][j]=max(a[i][j]+a[i-1][(j+1)%3],a[i][j]+a[i-1][(j+2)%3]);
        }
        
    }
    cout<<max(max(a[n-1][0],a[n-1][1]),a[n-1][2]);
    
}

Measured memory_bytes: 5960
<?php
fscanf(STDIN, "%d", $n);

$arr = [];

for(; $n>0; $n--){
  fscanf(STDIN, "%s", $s);

  $split = str_split($s);
  sort($split);
  $sorted = implode('', $split);

  $arr[$sorted] = isset($arr[$sorted])? $arr[$sorted]+1 : 1;
}

$cnt = 0;
foreach($arr as $str){
  if($str === 1) continue;
  $cnt += array_sum(array_map(function($v){ return $v-1; },range(2,$str)));
}

echo $cnt, "\n";

Measured memory_bytes: 14840
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    cout << n * n * n << endl;
    return 0;
}

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

void calc_lunlun(int64_t num, int digit, std::vector<int64_t> &vec_lun){
  
  vec_lun.push_back(num);
  
  // Kの最大値からルンルン数は最大で10桁
  if(digit == 10){
    return;
  }
  
  // 今の値を基準にこの関数を再帰する
  for(int cnt = -1 ; cnt < 2; cnt++){
    int64_t next_digit_num = (num % 10) + cnt;
    if( 0 <= next_digit_num && next_digit_num <=9 ){
      calc_lunlun( num*10+next_digit_num, digit+1, vec_lun );
    }
  }
}


int main(){
  int K = 0;
  std::cin >> K;
  
  std::vector<int64_t> vec_lun;
  for(int cnt = 1; cnt < 10; cnt++){
    calc_lunlun(cnt, 1, vec_lun);
  }
  
  std::sort(vec_lun.begin(), vec_lun.end());
  
  std::cout << vec_lun.at(K-1) << std::endl;
  
  return 0;
}

Measured memory_bytes: 2420
#include<stdio.h>
int main(){
	int t[100],n[100],goukei[100],i;
	for(i=0;i<4;i++){
		scanf("%d%d",&t[i],&n[i]);
		if(t[i]==1){
		goukei[i]=n[i]*6000;
	}
	else if(t[i]==2){
		goukei[i]=n[i]*4000;
	}
	else if(t[i]==3){
		goukei[i]=n[i]*3000;
	}
	else if(t[i]==4){
		goukei[i]=n[i]*2000;
	}
}
	for(i=0;i<4;i++){
		printf("%d\n",goukei[i]);
	}
	return 0;
}


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

int main() {
int n;
cin>>n;
int h[n];
for(int i=0;i<n;i++)
{
	cin>>h[i];
}
int ans=0;
for(int i=0;i<n;i++)
{
	if (h[i] > 0){
      while(h[i] != 0){
        h[i]--;
        i++;
      }
      i = -1;
      ans++;
    }
	
}
cout<<ans;
	return 0;
}

Measured memory_bytes: 256