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

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

		//入力
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		int l = scanner.nextInt();

		//配列nm,ml
		int[][] nm = new int[n][m];
		int[][] ml = new int[m][l];

		//nm入力
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				nm[i][j] = scanner.nextInt();
			}
		}
		//ml入力
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < l; j++) {
				ml[i][j] = scanner.nextInt();
			}
		}

		//n*lをm回繰り返しsumに計上。sumをn*l回繰り返し出力
		for(int i=0; i<n; i++) {
			
			for(int j=0; j<l; j++) {
				
				long sum = 0;
				for(int k=0; k<m; k++) {
					
					sum += nm[i][k] * ml[k][j];
					
				}
				if(j == 0) {
					System.out.print(sum);
				}else {
					System.out.print(" " + sum);
				}
			}
							System.out.println();
		}
	}
}


Measured memory_bytes: 53276
#include<stdio.h>

int main(){

  int P[500][500];
  int n,i,j,u,k,v;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      P[u][v]=1;
    }
  }

  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      printf("%d",P[i][j]);
      if(j!=n) printf(" ");
    }
    printf("\n");
  }
}



Measured memory_bytes: 2088
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    int min=10000;
    int max=-1;
    
    for(int i=0;i<n;i++){
        if(min>v[i]) min=v[i];
        if(max<v[i]) max=v[i];
    }
    
    cout<<max-min<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {


    public static void main(String[] args) {
        try (CustomReader in = new CustomReader()) {
            new Main().execute(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public void execute(CustomReader in) throws IOException {
        int N = Integer.parseInt(in.readLine());
        int[] A = in.readLineAsIntArray();
        int[] gcdForward = new int[N];
        int[] gcdBackward = new int[N];
        gcdForward[0] = A[0];
        gcdBackward[N - 1] = A[N - 1];
        for (int i = 1; i < N; i++) {
            gcdForward[i] = gcd(gcdForward[i - 1], A[i]);
            gcdBackward[N - 1 - i] = gcd(gcdBackward[N - i], A[N - 1 - i]);
        }

        int maxGcd = Math.max(gcdForward[N - 2], gcdBackward[1]);

        for (int i = 1; i < N - 1; i++) {
            maxGcd = Math.max(maxGcd, gcd(gcdForward[i - 1], gcdBackward[i + 1]));
        }

        System.out.println(maxGcd);
    }

    private int gcd(int x, int y) {
        if (y > x) {
            return gcd(y, x);
        }
        int r = x % y;
        if (r == 0) {
            return y;
        } else {
            return gcd(y, r);
        }
    }


    static class CustomReader extends BufferedReader {
        public CustomReader() throws IOException {
            super(new InputStreamReader(System.in));
        }


        public int[] readLineAsIntArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            int[] intArray = new int[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                intArray[i] = Integer.parseInt(strArray[i]);
            }
            return intArray;
        }

        public long[] readLineAsLongArray() throws IOException {
            String[] strArray = this.readLine().split(" ");
            long[] longArray = new long[strArray.length];
            for (int i = 0, n = strArray.length; i < n; i++) {
                longArray[i] = Long.parseLong(strArray[i]);
            }
            return longArray;
        }


        public int[][] readAsIntMatrix(int rows, int columns) throws IOException {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++) {
                String[] r = this.readLine().split(" ");
                for (int j = 0; j < columns; j++) {
                    matrix[i][j] = Integer.parseInt(r[j]);
                }
            }
            return matrix;
        }
    }

}

Measured memory_bytes: 45336
from fractions import gcd
 
def sequential_gcd(a):
    d = a[0]
    res = [d]
    for v in a[1:]:
        d = gcd(d, v)
        res.append(d)
    return res
    
n = int(input())
a = list(map(int, input().split()))
if n == 2:
    print(max(a))
else:
    l = sequential_gcd(a)
    r = sequential_gcd(a[::-1])[::-1]
    m = []
    for i in range(n):
        if i == 0:
            m.append(r[1])
        elif i == n-1:
            m.append(l[n-2])
        else:
            m.append(gcd(l[i-1], r[i+1]))
    print(max(m))

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

int main(){
    int n,m,x;
    int totalcost = INF;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int> > a(n,vector<int>(m));
    rep(i,n){
        cin >> c.at(i);
        rep(j,m)cin >> a.at(i).at(j);
    }

    for(int bit = 0; bit < (1 << n); bit++){
        vector<int> skill(m);
        int cost = 0;
        rep(i,m)skill.at(i) = 0;
        rep(i,n){
            if(bit & (1 << i)){
                cost += c.at(i);
                rep(j,m){
                    skill.at(j) += a.at(i).at(j);
                }
            }
        }    
        rep(i,m){
            if(skill.at(i) < x)break;
            if(i == m-1){
                if(totalcost > cost)totalcost=cost;
            }
        }
    }

    if(totalcost == INF) totalcost = -1;
    cout << totalcost << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<stack>
#include<map>
#include<vector>
#include<queue>
#define N 15
using namespace std;
typedef long long ll;
char a[N];
int main()
{
    ios::sync_with_stdio(false);
    int n,left,right,mid,x,y;
    cin>>n;
    cout<<"0"<<endl;
    cin>>a;
    if(a[0]=='V')
        return 0;
    if(a[0]=='M') x=1;
    else x=0;
    left=0,right=n;
    while(left!=right-1)
    {
        mid=(left+right)/2;
        cout<<mid<<endl;
        cin>>a;
        if(a[0]=='V')
           return 0;
        else if(a[0]=='M') y=1;
        else  y=0;
        int t =mid-left;
        if(t%2==0){
            if(y==x) left=mid;
            else right=mid;
            }
        else{
            if(x==y)right=mid;
            else left=mid,x=y;
            }
    }
    cout << flush;
    return 0;
}



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

int main() {
	
	int n, y;
	cin >> n >> y;
	
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n - i; j++){
			int k = n - i - j;
			int sum = 10000 * i + 5000 * j + 1000 * k;
			if(sum == y){
				printf("%d %d %d\n", i, j, k);
				return 0;
			}
		}
	}
	printf("%d %d %d\n", -1, -1, -1);
	return 0;
}

Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
arr = Array.new(10**5, 0)
n.times do
  v, t = gets.split.map(&:to_i)
  arr[v - 1] += t
end

ans = 0
cnt = 0
(10**5).times do |i|
  cnt += arr[i]

  if cnt >= k
    ans = i + 1
    break
  end
end
puts ans

Measured memory_bytes: 2556
#include <stdio.h>
#include <stdlib.h>

#define N 100000

int main()
{
  int i, n, q, v, x, y, z, dx, dy, x0, y0, ex, rx, sx, tmp;
  char *p, buf[32];
  buf[31]=0;
  buf[30]='\n';
  int *s = (int*)malloc(sizeof(int)*N+1);
  int *d = (int*)malloc(sizeof(int)*N+1);
  while (fgets(buf, 32, stdin)) {
    for (n=0,p=buf; *p!=' '; n=n*10+*(p++)-'0'); 
    for (q=0,p++; *p!='\n'; q=q*10+*(p++)-'0'); 
    if (n==0 && q==0) break;
    for (i=1; i<=n; s[i]=i,d[i++]=0);
    for (int t=0; t<q; t++) {
      fgets(buf, 32, stdin);
      for (x=0,p=buf+2; *p!=' '; x=x*10+*(p++)-'0');
      for (y=0,p++; *p>='0'; y=y*10+*(p++)-'0');

      if (buf[0]=='!') { // relate x y z
	for (z=0,p++; *p!='\n'; z=z*10+*(p++)-'0');
	for (x0=x,dx=0; s[x]!=x; dx+=d[x], x=s[x]);
	for (y0=y,dy=0; s[y]!=y; dy+=d[y], y=s[y]);
	s[x0]=x;
	d[x0]=dx;
	s[y0]=y;
	d[y0]=dy;
	if (x<y) {
	  s[y] = x;
	  d[y] = z + dx - dy;
	} else if (x>y) {
	  s[x] = y;
	  d[x] = -z - dx + dy;
	} else continue;
	
      } else { // diff

	for (x0=x,dx=dy=0; s[x]!=x; dx+=d[x], x=s[x]);
	for (rx=x, x=x0, ex=dx; s[x]!=x; x=sx) {
	  sx=s[x];
	  s[x]=rx;
	  tmp=d[x];
	  d[x]=ex;
	  ex-=tmp;
	}
	for (y0=y; s[y]!=y; dy+=d[y], y=s[y]);
	v=-dx+dy;
	if (x!=y) {
	  fputs("UNKNOWN\n", stdout);
	} else {
	  i=30;
	  if (v>0)  for (; v>0; buf[--i]='0'+v%10,v/=10);
	  else if (v<0) {
	    for (; v<0; buf[--i]='0'-v%10,v/=10);
	    buf[--i] = '-';
	  } else  buf[--i] = '0';
	  fputs(buf+i, stdout);
	}
      }
    }
  }
  return 0;
}



Measured memory_bytes: 2332
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<numeric>
#include<set>
#include<math.h>
using namespace std;

int main(){
    vector<int> pqr(3);
    for(int i = 0; i < 3; i++) cin >> pqr[i];
    stable_sort(pqr.begin(), pqr.end());

    cout << pqr[0] + pqr[1] << endl;
    
    return 0;
}

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

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

  int mae;
  int ato;

  mae=N/100;
  ato=N%100;

  if((1<=mae)&&(mae<=12)&&(1<=ato)&&(ato<=12)){
    cout << "AMBIGUOUS" << endl;
  }

  else if((1<=mae)&&(mae<=12)){
    cout << "MMYY" << endl;
  }

  else if((1<=ato)&&(ato<=12)){
    cout << "YYMM" << endl;
  }

  else{
    cout << "NA" << endl;
  }
}

Measured memory_bytes: 256
// algo.cpp: 定义应用程序的入口点。
//
#include <iostream>
#include <fstream>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <climits>
#include <cassert>
using namespace std;
struct UnionFind {
    vector<int> par, sz;
    int n_tree;

    explicit UnionFind(int n) : par(n), sz(n, 1), n_tree(n) { //0-indexed
        iota(par.begin(), par.end(), 0);
    }

    int n_cluster() const {
        return n_tree;
    }

    int size(int x) {
        return sz[root(x)];
    }

    int root(int x) {
        return x == par[x] ? x : par[x] = root(par[x]);
    }

    bool unite(int x, int y) {
        int rx = root(x), ry = root(y);
        if (rx != ry) {
            par[rx] = ry;
            --n_tree;
            sz[ry] += sz[rx];
            return true;
        }
        return false;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    bool is_root(int x) const {
        return par[x] == x;
    }
};

int main() {
#ifdef LOCAL
    // 如何使用相对路径？
    ifstream in("in.txt");
    cin.rdbuf(in.rdbuf());
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s, t;
    int n;
    cin >> n >> s >> t;
    for (int i = 0; i < n; ++i) {
        cout << s[i] << t[i];
    }
        
#if defined LOCAL
    cout << "Time elapsed: " << (double)clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long; 
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n, k;
	cin >> n >> k;
	int piece = 0;
	rep(i, k) {
		int a;
		cin >> a;
		piece += a;
	}
	n++;
	cout << (piece+n-1) / n << endl;
	return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main(){
 string S;
  cin>>S;
  string ans;
  if(S.at(2)==S.at(3) && S.at(4)==S.at(5))
     ans="Yes";
     else
     ans="No";
     
     cout<<ans<<endl;


 return 0;
}

Measured memory_bytes: 256
S = list(input())
P = set(["A","C","T","G"])
count = 0
if P&set(S) == set():
  print(0)
  exit()
else:
  for i in range(0,len(S)):
    for j in range(i+1, len(S)+1):
      if set(S[i:j])-P == set():
        count = max(count,j-i)
        
print(count)

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

using namespace std;

int main()
{
  int N, Z, W, A[2000];

  cin >> N >> Z >> W;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int ret = abs(A[N - 1] - W);
  if(N > 1) ret = max(ret, abs(A[N - 2] - A[N - 1]));
  cout << ret << endl;
}


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


int main(){
  int n, m;
  scanf("%d %d", &n, &m);
  vector<int> vc_a;
  for(int i=0; i<m; i++) {
    int a;
    scanf("%d", &a);
    vc_a.push_back(a);
  }
  sort(vc_a.begin(), vc_a.end(), greater<int>());
  
  int num[10] = {-1,2,5,5,4,5,6,3,7,6};
  
  int dp[10001] = {};
  for(int i=1; i<n; i++){
  	dp[i] = -10000000;
  }
  for(int i=2; i<=n; i++){
    for(int j=0; j<m; j++){
      int x = num[vc_a[j]];
      if (x > i) continue;
      dp[i] = max(dp[i-x]+1, dp[i]);
    }
  }
  for(int i=0; i<=n; i++){
    //printf("%d ", dp[i]);
    //if(i % 10 == 9) printf("\n");
  }
  for(int i=dp[n]; i>0; i--){
    for(int j=0; j<m; j++){
      int x = num[vc_a[j]];
      if (x > n) continue;
      if(dp[n-x] == dp[n] - 1){
        printf("%d", vc_a[j]);
    	n -= x;
    	//printf("%d ", n);
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int cnt=0,i;
    string s,s1;


    cin>>s>>s1;
    int len = s.size();

    for(i=0;i<len;i++)
    {
        if(s[i]!=s1[i])
        {
            cnt++;
        }
    }

    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 3916
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			if (n % 2 == 0) {
				Console.WriteLine((double)(n / 2) / n);
			} else {
				Console.WriteLine((double)((n / 2) + 1) / n);
			}
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 11092
def inputIntArray
  gets.chomp.split.map(&:to_i)
end

def inputFloatArray
  gets.chomp.split.map(&:to_f)
end

def inputStringArray
  gets.chomp.split
end

t,d = inputIntArray
ta,tb = inputIntArray
da,db = inputIntArray

def temp ta,tb,va,vb
  (ta*va + tb*vb) / (va+vb).to_f
end

ans = 100
0.step(d,da) do |va|
  0.step(d,db) do |vb|
    if 1 <= va+vb && va+vb <= d
      ans = [ans,(t-temp(ta,tb,va,vb)).abs].min
    end
  end
end

puts "%.10f" % [ans]

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

int main(){
    long long n;
    cin>>n;
    long long a,b,ans=1e18,res;
    for(int i=1;i<=n/i;i++){
        if(n%i==0){
            a=i,b=n/i;
            res=0;

            while(b){
                res++;
                b/=10;
            }
        
            ans=min(ans,res);
            cerr<<ans<<" "<<i<<endl;
        }
    }

    cout<<ans;

}

Measured memory_bytes: 256
import java.util.Scanner;

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

		String str = sc.next();

		int acount=0;
		int zcount =300000;

		for(int i=0;i<str.length();i++) {
			if(String.valueOf(str.charAt(i)).equals("A")){
				acount =i;
				break;
			}
		}

		for(int i=str.length()-1; i>=0;i--) {
			if(String.valueOf(str.charAt(i)).equals("Z")){
				zcount =i;
				break;
			}
		}

		System.out.print(zcount-acount+1);
	}

}

Measured memory_bytes: 31808
N = int(input())
A = [int(i) for i in input().split()]
mod = 1000000007

RGB = [0,0,0]
ans = 1
for i in range(N):
    X = RGB.count(A[i])
    ans = (ans * X) % mod
    for j in range(3):
        if RGB[j] == A[i]:
            RGB[j] += 1
            break
print(ans)
            
    

Measured memory_bytes: 52952
# 上から貪欲

N, K = map(int, input().split())
a = list(map(int, input().split()))

s = [0 for _ in range(50)]
# s[j]: sum(aa >> j & 1 for t in a)

for t in a:
    for j in range(50):
        s[j] += (t >> j) & 1

temp = 0
for j in range(50, -1, -1):
    if temp | (1 << j) <= K:
        if s[j] * 2 < N:
            temp |= (1 << j)
ans = 0
for j in range(50):
    if (temp >> j) & 1 == 0:
        ans += s[j] << j
    else:
        ans += (N - s[j] << j)
print(ans)


Measured memory_bytes: 14620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;




signed main(){
  
  ll n,ans=0;cin>>n;
  vector<PL> v(n);

  rep(i,n){
    ll A,B;cin>>A>>B;
    v[i]={A+B,A};
  }
  sort(all(v),greater<PL>());

  rep(i,n){
    if(i%2)ans-=v[i].fi-v[i].se;
    else ans+=v[i].se;
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 1792
N, M = map(int, input().split())
l_max = -float("inf")
r_min = float("inf")

for i in range(M):
    l, r = map(int, input().split())
    if l > l_max:
        l_max = l
    if r < r_min:
        r_min = r
if r_min>N:
    r_min = N
print(len(range(l_max, r_min+1)))

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }


signed main() {
  string N = readString();
  int a = (int)(N[0] - '0'), b = (int)(N[1] - '0'), c = (int)(N[2] - '0');

  if( a >= b && a >= c ) {
    cout << a << a << a << endl;
  } else {
    cout << a + 1 << a + 1 << a + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 2304
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))

L.sort()
result = 0
for i in range(N - 2):
    a = L[i]
    for j in range(i + 1, N - 1):
        result += bisect_left(L, a + L[j]) - j - 1
print(result)


Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<random>
using namespace std;


int main(){

  int h, w;
  cin >> h >> w;
  vector< string > a(h);

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

  bool f = true;
  for(int i=0; i<h-1; i++){
    for(int j=0; j<w-1; j++){
      if( a[i+1][j] == '#' && a[i][j+1] == '#' ){
        f = false;
        break;
      }
    }
  }
  if( f ) cout << "Possible" << endl;
  else cout << "Impossible" << endl;


  return 0;
}














// EOF


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

typedef long long int ll;

using namespace std;

int a[200];

int main(void)
{
    int n,avg = 0;
    cin>>n;

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

    if(avg > 0)
	avg = (1.0*avg)/n+0.5;
    else
	avg = (1.0*avg)/n-0.5;

    ll cost = 0;
    for(int i = 1;i <= n;i++)
    {
	cost += (a[i]-avg)*(a[i]-avg);
    }

    cout<<cost<<endl;

    return 0;
}



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


int main(){
    int n;
    cin>>n;
    
    v_int v1(n);
    v_int v2(n);
    v_int v3(n);

    for(int i=0;i<n;i++){
        cin>>v1[i]>>v2[i]>>v3[i];
    }

    vector<v_int> dp(n+1,v_int(3,0));

    int total_happiness=0;

    for(int i=1;i<=n;i++){
        dp[i][0]=v1[i-1]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=v2[i-1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=v3[i-1]+max(dp[i-1][0],dp[i-1][1]);
    }
    total_happiness+=max(dp[n][0],max(dp[n][1],dp[n][2]));
    cout<<total_happiness;
    return 0;
}

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

void divisor(vector<int> &d, int n)
{
    for (int i = 1; i * i <= n; i++)
    {
        if(n % i == 0)
        {
            d.push_back(i);
            if(i * i != n)d.push_back(n / i);
        }
    }
    
}

int main()
{
    long long n,m;
    cin >> n >> m;

    vector<int> mm;
    divisor(mm, m);
    sort(mm.begin(), mm.end());
    //for (int i = 0; i < mm.size(); i++)cout << mm[i] << " ";cout << endl;

    int ans = mm[mm.size() - 1];
    for (int i = 0; i < mm.size(); i++)
    {
        if(mm[i] * n > m)
        {
            ans = mm[i - 1];
            break;
        }
    }

    
    cout << ans << endl;
}

Measured memory_bytes: 256
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

void solve() {
    cini(n);
    cini(d);

    int ans=0;
    for(int i=0; i<n; i++) {
        cini(x);
        cini(y);
        if(x*x+y*y<=d*d)
            ans++;
    }
    cout<<ans<<endl;
}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


Measured memory_bytes: 3528
#include <iostream>
using namespace std;
long long n,m,f[105][100005],w[105],v[100005],i,j;
int main()
{
    cin>>n>>m;
    f[0][0]=0;
    for (i=1;i<=n;i++)
    cin>>w[i]>>v[i];
    for (i=1;i<=n;i++)
    {
        for (j=1;j<=m;j++)
        {
            if (w[i]<=j) f[i][j]=max(f[i-1][j],f[i-1][j-w[i]]+v[i]);
            else f[i][j]=f[i-1][j];
        }
    }
    cout<<f[n][m];
    return 0;
}


Measured memory_bytes: 78592
#include<stdio.h>
#include<iostream>
using namespace std;
int n,a;
int main()
{
	scanf("%d",&n);
	int maxn=0,ans=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a);
		if(a>=maxn)
		{
			ans++;
			maxn=a;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    int a[3];
    rep(i, 3) cin >> a[i];
    cout << a[2] << " " << a[0] << " " << a[1] << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int n,m;
vector<int> adj[8];
unordered_set<string> ans;
void dfs(int i,vector<int> visited,int time){
    visited[i] = time;
    if(time == n){
        string str = "";
        for(int k=0;k<n;k++){
            str += to_string(visited[k]);
        }
        ans.insert(str);
        return;
    }
    for(auto j : adj[i]){
        if(visited[j] == -1){
            dfs(j,visited,time+1);
        }
    }

}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    dfs(0,vector<int>(n,-1),1);
    cout<<ans.size()<<"\n";
    return 0;

}




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

#define mp make_pair
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define eb emplace_back

typedef pair< int, int > pii;
typedef pair< long long, long long > pll;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef vector< pii > vpii;
typedef vector< vpii > vvpii;
typedef vector< pll > vpll;
typedef long double ld;
typedef vector< ld > vld;
typedef unsigned int uint;
 
template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    const bool operator<(const M& o) const {return v < o.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
 
using Mint = ModInt<(int)998244353>;
 
int main() { 
    #ifdef BLAT
        freopen("stdin", "r", stdin);
        freopen("stderr", "w", stderr);
    #endif
 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(12);
    srand(time(NULL));

    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    cout << max(0, (h2-h1)*60-m1+m2-k);
    return 0;
}

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

const int N=305;
const int M=90005;
const int mod=998244353;
const int inv2=499122177;
int n,dp[2][M],a[N],oldpos,newpos;
int sum,fac2=1,fac3=1;

namespace MATHEMATICS
{
	int add(int x,int y)
	{
		int ret=x+y;
		if(ret>=mod) ret-=mod;
		return ret;
	}
	int mi(int x,int y)
	{
		int ret=x-y;
		if(ret<0) ret+=mod;
		return ret;
	}
	
	void inc(int &x,int y)
	{
		x+=y;
		if(x>=mod) x-=mod;
	}
	void dec(int &x,int y)
	{
		x-=y;
		if(x<0) x+=mod;
	}
	
	int mul(int x,int y)
	{
		return 1LL*x*y%mod;
	}
}
using namespace MATHEMATICS;

void init()
{
	int i;scanf("%d",&n);
	for(i=1;i<=n;++i) scanf("%d",&a[i]),sum+=a[i];
}

void prework()
{
	int i,j;oldpos=0,newpos=1;
	dp[oldpos][0]=1;
	for(i=1;i<=n;++i)
	{
		for(j=0;j<=sum;++j) dp[newpos][j]=0;
		for(j=0;j<=sum;++j)
		{
			if(!dp[oldpos][j]) continue;
			inc(dp[newpos][j],dp[oldpos][j]);
			inc(dp[newpos][j+a[i]],mul(dp[oldpos][j],inv2));
		}
		oldpos^=1,newpos^=1;
	}
	for(i=1;i<=n;++i) fac2=mul(fac2,2),fac3=mul(fac3,3);
	for(j=0;j<=sum;++j) dp[oldpos][j]=mul(dp[oldpos][j],fac2);
}

void work()
{
	int i,j;
	for(j=0;j<=sum;++j)
	{
		if(j>=sum-j)
			dec(fac3,mul(dp[oldpos][j],3));
	}
}

void prework2()
{
	int i,j;oldpos=0,newpos=1;
	memset(dp,0,sizeof(dp));
	dp[oldpos][0]=1;
	for(i=1;i<=n;++i)
	{
		for(j=0;j<=sum;++j) dp[newpos][j]=0;
		for(j=0;j<=sum;++j)
		{
			if(!dp[oldpos][j]) continue;
			inc(dp[newpos][j],dp[oldpos][j]);
			inc(dp[newpos][j+a[i]],dp[oldpos][j]);
		}
		oldpos^=1,newpos^=1;
	}
}

void work2()
{
	inc(fac3,mul(3,dp[oldpos][sum>>1]));
}

int main()
{
	init();prework();work();
	if(sum%2==0) prework2(),work2();
	printf("%d\n",fac3);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <iomanip>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
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; }
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

void print_setprecision(int i, long double rsl) {
  cout << fixed << setprecision(i) << rsl << endl;
}

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

  string s, t;
  cin >> s >> t;
  rep(i, 0, s.size()) {
    if(s[i] != t[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3652
def main():
    N, M, C = map(int, input().split())
    A = []
    res = 0
    B = list(map(int, input().split()))
    for _ in range(N):
        result = C
        for i, a in enumerate(list(map(int, input().split()))):
            result += a * B[i]
        if result > 0:
            res += 1
    print(res)
    

main()

Measured memory_bytes: 3060
import math
N = int(input())
A = list(map(int, input().split()))
C = 1
m = A[0]
M = A[0]
money = 1000;
for i in range(1,N):
  if C == 1 and M <= A[i]:
    M = A[i]
  elif C == 1 and M > A[i]:
    money = (money % m) + math.floor(money / m)*M
    C = 0
    m = A[i]
  elif C == 0 and m >= A[i]:
    m = A[i]
  elif C == 0 and m < A[i]:
    M = A[i]
    C = 1
if C == 1:
  money = (money % m) + math.floor(money / m)*M
print(money)

Measured memory_bytes: 9232
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x1,x2,y1,y2;
  cin>>x1>>y1>>x2>>y2;
  int dx=x2-x1,dy=y2-y1;
  int x3=x2-dy,y3=y2+dx;
  int x4=x3-dx ,y4=y3-dy;
  cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4;
}

Measured memory_bytes: 256
import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    x = int(input())
    dp = [0 for _ in range(x+106)]
    dp[0] = 1
    for i in range(x):
        if dp[i] == 1:
            for j in range(100, 106):
                dp[i+j] = 1
    print(dp[x])
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 10888
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		char[][] s = new char[n][];
		int[][] az = new int[n][26];
		for (int i = 0; i < n; i++) {
			s[i] = sc.next().toCharArray();
			for (int j = 0; j < s[i].length; j++) {
				az[i][s[i][j] - 'a']++;
			}
		}
		int min;
		char c;
		for (int i = 0; i < 26; i++) {
			c = (char) ('a' + i);
			min = 50;
			for (int j = 0; j < n; j++) {
				min = Math.min(min, az[j][i]);
			}
			for (int j = 0; j < min; j++) {
				sb.append(c);
			}
		}
		System.out.println(sb);
	}
}


Measured memory_bytes: 23124
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long


int main()
{
	string S;
	cin >> S;
	if ((S[0] == S[1] && S[1] == S[2]) || (S[1] == S[2] && S[2] == S[3])) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3576
def main():
  a = []
  ans = "No"
  hit_examples = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]
  for i in range(3):
    a.extend(list(map(int, input().split())))
  n = int(input())
  b = []
  for i in range(n):
    b.append(int(input()))
  for b_value in b:
    for i in range(len(a)):
      if b_value == a[i]:
        a[i] = -1

  for hit_example in hit_examples:
    cnt = 0
    for i in range(len(a)):
      if a[i] == -1 and i in hit_example:
        cnt += 1
      if cnt == 3:
        ans = "Yes"
        print(ans)
        return
  print(ans)

if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	cin>>n;
	int a[3][100001];
	for(int i=0; i<n; i++) cin>>a[0][i]>>a[1][i]>>a[2][i];
	int dp[3][100000];
	for(int i=0; i<3; i++) dp[i][0]=a[i][0];
	for(int i=1; i<n; i++){
		for(int j=0; j<3; j++){
			dp[j][i]=0;
			for(int k=0; k<3; k++){
				if(k==j) continue;
				dp[j][i]=max(dp[j][i], dp[k][i-1]+a[j][i]);
			}
		}
	}
	cout<<max({dp[0][n-1], dp[1][n-1], dp[2][n-1]})<<endl;
	return 0;
}

Measured memory_bytes: 2560
//Name: Grid
//Level: 2
//Category: 数学,動的計画法,DP
//Note:

/*
 */
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MOD = 100000007;

int memo[1001][1001];
int comb(int n, int r) {
    if(r == 0) return 1;
    if(n == r) return 1;
    if(n < r) return 0;
    if(memo[n][r] != 0) return memo[n][r];
    return memo[n][r] = (comb(n-1, r) + comb(n-1, r-1)) % MOD;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int R, C;
    pair<int,int> start, goal;
    while(cin >> R >> C >> start.first >> start.second >> goal.first >> goal.second) {
        const int left = (start.second - goal.second+C) % C;
        const int right = (goal.second - start.second+C) % C;
        const int up = (start.first - goal.first+R) % R;
        const int down = (goal.first - start.first+R) % R;
        const int mc = min(left, right);
        const int mr = min(up, down);
        int pat = comb(mc+mr, mc);
        if(left != 0 && left == right) pat = (pat*2) % MOD;
        if(up != 0 && up == down) pat = (pat*2) % MOD;
        cout << pat << endl;
    }
    return 0;
}

Measured memory_bytes: 5144
R,G,B,N = (int(i) for i in input().split())

patterns = 0
for i in range(0,N+1,R):
    numredballs = i
    numothers = N - numredballs
    
    for j in range(0,numothers+1,G):
        numgreenballs = j
        numblueballs = numothers - numgreenballs
        
        if numblueballs % B != 0:
            continue
        else:
            patterns += 1

print(patterns)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
using  namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	if(n-m<=0)	cout<<"0\n";
	else		cout<<n-m<<endl;
}

Measured memory_bytes: 256
/******techknight_18@7******/
#include<bits/stdc++.h>
using namespace std;
#define lld               long long int
#define ld                long double
#define pb                push_back
#define ppb               pop_back
#define mp                make_pair
#define F                 first
#define S                 second
#define nl                '\n'
#define all(c)            (c).begin(),(c).end()
#define rall(c)           (c).rbegin(),(c).rend()
#define sz(c)             (c).size()
#define tr(x,a)           for(auto &a : x)
#define psnt(x,a)         (x).find(a)!=(x).end()
#define vpsnt(x,a)        find(all(x),a)!=(x).end()
#define lexichar(x,y)     lexicographical_compare(x,x+strlen(x),y,y+strlen(y)) //modify the ranges
#define lexistr(x,y)      lexicographical_compare(x.begin(),x.end(),y.begin(),y.end()) 
#define MOD               1000000007
#define pi                3.1415926536
#define tod               1
#define itr(i,a,b)        for(lld i=a;i<=b;i++)
#define itrn(i,a,b)       for(lld i=a;i>=b;i--)
#define iot(n)            for(lld i=0;i<n;i++)
#define pls(n,arr)        lld arr[n]; iot(n)  cin>>arr[i];
#define bye               fflush(stdout)

typedef pair<lld,lld>     pii;
typedef pair<string,lld>  psi;
template <typename T>
bool mycomp(T x,T y){ 
   return (x==y);  //give your condition here
}
bool paircomp(const pair<lld,lld> &x,const pair<lld,lld> &y){ 
return x.second<y.second;
}

int main(){
       ios_base::sync_with_stdio(false);
             cin.tie(0);
            cout.tie(0);
      lld t=1; //cin>>t;  
      while(t--){
          lld n; cin>>n;
          n=n%10;
          if(n==2||n==4||n==5||n==7||n==9)
            cout<<"hon";
         else if(n==3)
             cout<<"bon";
        else
          cout<<"pon";
      }
}



Measured memory_bytes: 3604
#!/usr/bin/env python3
import sys


def solve(N: int, h: "List[int]"):
    INF = 1000000000
    dp = [INF] * (N+100)
    dp[0] = 0
    for i in range(N-1):
        dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1]-h[i]))
        if(i < N-2):
            dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2]-h[i]))

    print(dp[N-1])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    h = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, h)

if __name__ == '__main__':
    main()


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

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define RFOR(i, l, r) for (int i = (int)(r); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    vi x(n);
    REP(i, n) {int a; cin >> x[i];}
    int l, q;
    cin >> l >> q;

    vvi dp(30, vi(100005, 0));
    REP(i, n) {
        auto it = upper_bound(all(x), x[i] + l);
        it--;
        dp[0][i] = it - x.begin();
        // cout << dp[0][i] << " ";
    }
    // int low = 1, high = 30;cout << endl;

    FOR(i, 1, 30) {
        // cout << " day " << i << " : ";
        REP(j, n) {
            dp[i][j] = dp[i - 1][dp[i - 1][j]];
        //    cout << dp[i][j] << " ";
        }
        // cout << endl;
    }

    REP(i, q) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (a > b) swap(a, b);
        int ans = 0;
        RREP(i, 30) {
            if (dp[i][a] < b) {
                a = dp[i][a];
                ans += 1 << i;
            }
        }

        cout << ans + 1 << endl;
    }



    return 0;
}

Measured memory_bytes: 13048
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

const ll inf = 1LL << 50;

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

    ll N, M, L;
    cin >> N >> M >> L;
    vector<vector<ll>> graph(N, vector<ll>(N, inf));
    Rep (i, M) {
        ll A, B, C;
        cin >> A >> B >> C;
        A--; B--;
        graph[A][B] = C;
        graph[B][A] = C;
    }

    Rep (i, N) {
        graph[i][i] = 0;
    }

    Rep (k, N) {
        Rep (i, N) {
            Rep (j, N) {
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
            }
        }
    }

    Rep (i, N) {
        Rep (j, N) {
            if (graph[i][j] <= L) graph[i][j] = 1;
            else graph[i][j] = inf;
        }
    }

    Rep (k, N) {
        Rep (i, N) {
            Rep (j, N) {
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
            }
        }
    }

    int Q;
    cin >> Q;
    while (Q--) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        int ans = graph[s][t]-1;
        if (ans >3e4) ans = -1;
        cout << ans << "\n";
    }
}

Measured memory_bytes: 1280
n,w = map(int,input().split())
x = []
for i in range(n):
    x1,y1=[int(i) for i in input().split()]
    if i == 0:
      ti = x1
      zero = 0
      iti = 0
      ni = 0
      san = 0
    if x1 == ti:
      zero += 1
    elif x1 == ti+1:
      iti += 1
    elif x1 == ti+2:
      ni += 1
    else:
      san +=1
    x.append([x1,y1])
x.sort()
zer = x[:zero]
one = x[zero:iti+zero]
two = x[iti+zero:iti+ni+zero]
three = x[iti+ni+zero:zero+iti+ni+san]
zer.append([0,0])
one.append([0,0])
two.append([0,0])
three.append([0,0])
zer = sorted(zer,key = lambda x: -x[1])
one = sorted(one,key = lambda x: -x[1])
two = sorted(two,key = lambda x: -x[1])
three = sorted(three,key = lambda x: -x[1])
ans = 0
zer0 = [0]* len(zer)+ [0]
one0 = [0]* len(one)+ [0]
two0 = [0]* len(two)+ [0]
three0 = [0]* len(three)+ [0]
zerk = [0]* len(zer)+ [0]
onek = [0]* len(one)+ [0]
twok = [0]* len(two)+ [0]
threek = [0]* len(three)+ [0]
for i in range(1,len(zer)+1):
  zer0[i] = zer0[i-1] + zer[i-1][0]
  zerk[i] = zerk[i-1] + zer[i-1][1]
for i in range(1,len(one)+1):
  one0[i] = one0[i-1] + one[i-1][0]
  onek[i] = onek[i-1] + one[i-1][1]
for i in range(1,len(two)+1):
  two0[i] = two0[i-1] + two[i-1][0]
  twok[i] = twok[i-1] + two[i-1][1]
for i in range(1,len(three)+1):
  three0[i] = three0[i-1] + three[i-1][0]
  threek[i] = threek[i-1] + three[i-1][1]
for i in range(len(zer)):
  for j in range(len(one)):
    for k in range(len(two)):
      for l in range(len(three)):
        omo = zer0[i] + one0[j] + two0[k] + three0[l]
        kati  = zerk[i] + onek[j] + twok[k] + threek[l]
        if omo <= w:
          ans = max(ans,kati)
print(ans)

Measured memory_bytes: 3192
import numpy as np


def isint(x):
    return np.equal(np.mod(x, 1), 0)


def main():
    n, d = list(map(int, input().split()))
    vecs = []
    for _ in range(n):
        vecs.append(list(map(int, input().split())))

    vecs = np.array(vecs)
    # print(vecs)
    v1 = np.tile(vecs, (1, n))
    v2 = np.tile(vecs.reshape(1, n * d), (n, 1))
    # print(v1)
    # print(v2)
    dists = v1 - v2
    # print(dists)
    dists = dists.reshape([-1, d])
    # print(dists)
    dists = np.linalg.norm(dists, axis=1)
    # print(dists)
    score = (np.count_nonzero(isint(dists)) - n) // 2
    print(score)


main()

Measured memory_bytes: 12508
import java.util.*;
import java.awt.geom.Point2D;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
//Loopで使う文字列の長さは固定！
//intで大丈夫？オーバーフローしない？
//Loop回数は本当に10⁹以内になってる？Loopは回る？？
public class Main {
    public static void main(String[]$){
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        int[] x=new int[n];
        for (int i = 0; i < n; i++) {
            x[i]=sc.nextInt();
        }
        long ans=1000000000;
        for (int i = 0; i <= n-k; i++) {
            ans=min(min(x[i+k-1]-x[i]+abs(x[i]),x[k-1+i]-x[i]+abs(x[k-1+i])),ans);
        }
        out.println(ans);
    }
    static long power(long x,int n){
        long mod=1000000007;
        long ans=1;
        while (n>0) {
            if((n&1)==1){
                ans=(ans*x)%mod;
            }
            x=(x*x)%mod;
            n>>=1;
        }
        return ans;
    }
    //最大公約数
    static int gcd (int a, int b) {
        int temp;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return b;
    }
//※最小公倍数はa*b/gcd(a,b)である
}


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

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

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

	int cnt = 0;
	for(int i = 0; i < m; i++){
		if(b[i] == n) cnt++;
	}

	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int binarySearch(int, int *, int);

int main(void)
{
	int n, S[100000], q, T[50000], i, C = 0;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &S[i]);
	scanf("%d", &q);
	for (i = 0; i < q; i++)
		scanf("%d", &T[i]);
	for (i = 0; i < q; i++) {
		if (binarySearch(n, S, T[i]) != -1)
			C++;
	}
	printf("%d\n", C);
	return 0;
}

int binarySearch(int n, int *A, int key)
{
	int left = 0, mid, right = n;
	
	while (left < right) {
		mid = (left + right) / 2;
		if (A[mid] == key)
			return mid;
		else if (key < A[mid])
			right = mid;
		else if (key > A[mid])
			left = mid + 1;
	}
	return -1;
}

Measured memory_bytes: 1184
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        boolean can=true;

        while(can){
            int H=sc.nextInt();
            int W=sc.nextInt();
            if((H==0)&&(W==0)) can=false;
            else {
                if(H==1){
                    for(int i=0;i<W;i++)System.out.print("#");
                    System.out.println();
                }
                else{
                    for(int i=0;i<H;i++){
                        for(int j=0;j<W;j++){
                            System.out.print("#");
                        }
                        System.out.println();
                    }
                }
                System.out.println();
            }
        }
    }
}


Measured memory_bytes: 33096