akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

typedef long long int int64;

const int mod=1000000007;

int comb(int n,int k){
  int res=1;
  int inv[31];
  inv[1]=1;
  int i;
  for(i=1;i<=k;i++){
    if(i>=2) inv[i]=mod-(int64)(mod/i)*inv[mod%i]%mod;
    res=(int64)res*(n+1-i)%mod*inv[i]%mod;
  }
  return res;
}

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  int ans=1;
  int k;
  for(k=2;k*k<=m;k++){
    if(m%k==0){
      int c=0;
      while(m%k==0){
	c++;
	m/=k;
      }
      ans=(int64)ans*comb(n-1+c,c)%mod;
    }
  }
  if(m>1) ans=(int64)ans*comb(n-1+1,1)%mod;
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}


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

const int N = 101010;

inline char get(void) {
  static char buf[100000], *S = buf, *T = buf;
  if (S == T) {
    T = (S = buf) + fread(buf, 1, 100000, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
template<typename T>
inline void read(T &x) {
  static char c; x = 0; int sgn = 0;
  for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1;
  for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
  if (sgn) x = -x;
}

int ans;
int r, c, n, pnt, top;
int sta[N], vis[N];
struct Point {
  int x, y, id;
};
Point a[N << 1];

inline int type(Point a) {
  if (a.y == c) return 0;
  if (a.x == r) return 1;
  if (a.y == 0) return 2;
  if (a.x == 0) return 3;
  return 4;
}
inline bool cmp(Point a, Point b) {
  int ta = type(a), tb = type(b);
  if (ta != tb) return ta < tb;
  if (ta == 0) return a.x < b.x;
  if (ta == 1) return a.y > b.y;
  if (ta == 2) return a.x > b.x;
  if (ta == 3) return a.y < b.y;
}

int main(void) {
  read(r); read(c); read(n);
  ans = 1;
  for (int i = 1; i <= n; i++) {
    read(a[++pnt].x); read(a[pnt].y); a[pnt].id = i;
    read(a[++pnt].x); read(a[pnt].y); a[pnt].id = i;
    if (type(a[pnt]) == 4 || type(a[pnt - 1]) == 4) pnt -= 2;
  }
  sort(a + 1, a + pnt + 1, cmp);
  for (int i = 1; i <= pnt; i++) {
    if (vis[a[i].id]) {
      if (sta[top] != a[i].id) ans = 0;
      --top;
    } else {
      vis[a[i].id] = 1; sta[++top] = a[i].id;
    }
  }
  if (ans) printf("YES");
  else printf("NO");
  return 0;
}


Measured memory_bytes: 3200
#define		_CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdint>
#include <iostream>

#define		MAX			100

typedef		std::int_least64_t			LL;

int main()
{
	int		n, m, l;
	int		A[MAX][MAX];
	int		B[MAX][MAX];
	LL		C[MAX][MAX];

	scanf("%d %d %d", &n, &m, &l);

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			scanf("%d", &(A[i][j]));
		}
	}

	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < l; j++)
		{
			scanf("%d", &(B[i][j]));
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < l; j++)
		{
			LL sum = 0;
			for (int k = 0; k < m; k++)
			{
				sum += static_cast<LL>(A[i][k]) * B[k][j];
			}
			C[i][j] = sum;
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < l; j++)
		{
			if (j)	std::cout << " ";
			std::cout << C[i][j];
		}
		std::cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 3320
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int n = in.nextInt();

        int[][] a = new int[2][n + 1];

        for (int i = 0; i < 2; i++) {
            for (int j = 1; j <= n; j++) {
                a[i][j] = a[i][j - 1] + in.nextInt();
            }
        }

        int max = 0;
        for (int i = 1; i <= n; i++) {
            max = Math.max(max, a[0][i] + (a[1][n] - a[1][i - 1]));
        }

        out.println(max);
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}


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


int main() {
    int X;
    cin >> X;
    int gofyaku = 0;    
    int goen = 0;
    gofyaku = X/500;
    X = X%500;
    goen = X/5;
    cout << (gofyaku*1000)+(goen * 5) << endl;

    return 0;
}

Measured memory_bytes: 256
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <math.h>
# include <algorithm>
using namespace std;
# define pi acos(-1.0)
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
typedef long long LL;
typedef unsigned long long ULL;

int a[30];
char b[30];

int main()
{

    bool flag=false;
    cin>>b;
    for(int i=0;i<strlen(b);i++)
        a[b[i]-97]++;
    for(int i=0;i<26;i++)
        if(a[i]>1)flag=true;
    if(flag)cout<<"no"<<endl;
    else cout<<"yes"<<endl;
    return 0;
}





















Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i, n) for (int i=1;i<n+1;i++)
using namespace std;
int main() {
  int m,d,a=0;
  cin >> m >> d;
  r(i, m) {
    r(j, d) {
      if((j%10)>=2 && (j/10)>=2 && (j%10)*(j/10)==i) a++;
    }
  }
  cout << a <<endl;
  return 0;
}

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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int INF = 1e9 + 7;
const int maxn = 3005;

int n;
int sum[maxn], dp[maxn][maxn];
char s[maxn];

int main(){
	scanf("%d", &n);
	scanf("%s", s);
	dp[0][0] = sum[0] = 1;
	
	FOR(i, 1, n){
		REP(j, 0, i){
			if(s[i - 1] == '>') dp[i][j] = (sum[i - 1] - (j ? sum[j - 1] : 0) + INF) % INF;
			else if(j) dp[i][j] = sum[j - 1];
		}
		sum[0] = dp[i][0];
		REP(j, 1, i) sum[j] = (sum[j - 1] + dp[i][j]) % INF;
	}
	
	printf("%d\n", sum[n - 1]);
	return 0;
}

Measured memory_bytes: 34176
#include <bits/stdc++.h>
using namespace std;
#define MAX 100000

int main(){
        int N;
        int p;
        int sumP = 0;
        int maxP = 0;

        cin >> N;
        for (int i=0; i<N; i++){
                cin >> p;
                sumP += p;
                if(p > maxP){
                        maxP = p;
                }
        }
        cout << sumP - maxP/2 << endl;
        return 0;
}


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

const int maxn = 1e5 + 5;
bool vis[maxn];
int cnt = 0;
int num[maxn];

int main(){
	memset(vis,1,sizeof vis);

	int n,m; cin >> n >> m;
	for(int i = 1; i <=n; i++) cin >> num[i];

	for(int i = 1; i <= m; i++){
		int u,v; cin >> u >> v;
		if(num[u] <= num[v]) vis[u] = 0;
		if(num[v] <= num[u]) vis[v] = 0;
	}

	for(int i = 1; i <= n; i++){
		if(vis[i]) cnt++;
	}
	cout << cnt << endl;


}

Measured memory_bytes: 4112
from itertools import accumulate
N, T = map(int, input().split())
A = list(map(int, input().split()))

A_MIN = list(accumulate(A, func=min))
diff = [a - a_min for a, a_min in zip(A, A_MIN)]

MAX_diff = max(diff)
print(diff.count(MAX_diff))


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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 500005
#define all(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

int n, k;
int A[N];
bool ok(int x){
	int ans = 0;
	for(int i = 0; i < n; i++){
		int tmp = A[i];
		ans += (tmp + x - 1) / x - 1;
	}
	return ans <= k;
}

int32_t main(){
	IOS;
	int tt = 1; 
	//cin >> tt;
	while(tt--){
		cin >> n >> k;
		int l = 1, r = 0;
		for(int i = 0; i < n; i++) {
			cin >> A[i];
			r = max(r, A[i]);
		}
		int ans = r;
		
		while(l <= r){
			int mid = (l + r) / 2;
			if(ok(mid)){
				ans = min(mid, ans), r = mid -1;
			}
			else l = mid + 1;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 5148
/* Generated by powerful Codeforces Tool
 * Author: rockphy
 * Time: 2020-06-11 22:35:14
**/
#include  <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int X, Y; cin>>X>>Y;
    int lo = 2*X;
    int hi = 4*X;
    bool ok=true;
    if(Y%2!=0 || Y<lo || Y>hi){
        ok=false;
    }
    cout << (ok?"Yes":"No") << '\n';
}

Measured memory_bytes: 3652
import sys

stdin = sys.stdin

sn = lambda : stdin.readline().rstrip()
an = lambda : map(int, stdin.readline().split())
ni = lambda : int(sn())

s = sn()

if s == "Sunny":
  print("Cloudy")
elif s == "Cloudy":
  print("Rainy")
elif s == "Rainy":
  print("Sunny")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>

#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define vpii vector<pii>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define pdd pair<double, double>
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define forstl(i,v) for(auto &i: v)

#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define pdd pair<double, double>

using namespace std;

int main(){
    /*
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    */
    int t, p;
    cin >> t;
    vector < pair < string, int> > v(t), sol(t);
    rep(i, t){
        cin >> v[i].f;
        cin >> v[i].s;
        // cout << v[i].f <<" ";
        // cout << v[i].s << "\n";
    }
    sol = v;
    sort(all(v));
    int x = 100;
    while(x--)
    rep(i, t-1){
        if(v[i+1].f == v[i].f){
            int tmp;
            if(v[i+1].s >= v[i].s){
                tmp = v[i+1].s;
                v[i+1].s = v[i].s;
                v[i].s = tmp;
            }
            //string tp;

        }
    }

    rep(i, t){
        rep(j, t){
            if(v[i] == sol[j]){
                cout << j+1 << "\n";
            }
        }
    }


    //cout << (3*t + p)/2;

    

    //cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}
vector<long long> calc_divisor(long long n){
  vector<long long> res;
  for(long long i = 1LL;i * i <= n; i++){
    if(n % i == 0){
      res.push_back(i);
      long long j = n / i;
      if(j != i){
        res.push_back(j);
      }
    }
  }
  sort(res.begin(),res.end());
  return res;
}


int N,M;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> N >> M;
  vector<ll> divisor = calc_divisor(M);
  long long res = 1;
  for(auto d : divisor){
    if( d * N <= M ){
      res = max(res,d);
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <string>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,P> pip;
typedef long long ll;
const int inf=(1<<31)-1;
const double pi=acos(-1);

char s,t,tmp,now='A';

int main(){
	while(cin>>s>>tmp>>t){
		if(s==now) now=t;
		else if(t==now) now=s;
	}
	cout<<now<<endl;
}

Measured memory_bytes: 1132
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int N;
	long[] A;
	Deque<Long> queue;
	List<String> logs;

	Main(int N, long[] A) {
		this.N = N;
		this.A = A;
		this.queue = new ArrayDeque<>();
		Arrays.sort(A);
		for (int i = 0; i < N; ++i) {
			queue.add(A[i]);
		}
		this.logs = new ArrayList<>();

		calc();
		show();
	}

	void calc() {
		while (queue.size() > 2) {
			long first = queue.pollFirst();
			long last = queue.pollLast();
			long diffA = Math.abs(queue.peekFirst() - (first - last));
			long diffB = Math.abs(queue.peekLast() - (last - first));
			if (diffA >= diffB) {
				queue.addFirst(first - last);
				this.logs.add(first + " " + last);
			} else {
				queue.add(last - first);
				this.logs.add(last + " " + first);
			}
		}
		long s = queue.poll();
		long f = queue.poll();
		queue.add(f - s);
		this.logs.add(f + " " + s);

	}

	void show() {
		System.out.println(queue.poll());
		for (int i = 0; i < this.logs.size(); ++i) {
			System.out.println(this.logs.get(i));
		}
	}

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int N = Integer.parseInt(in.readLine());
		long[] A = new long[N];
		String[] tokens = in.readLine().split(" ");

		in.close();
		for (int i = 0; i < N; ++i) {
			A[i] = Long.parseLong(tokens[i]);
		}

		Main ins = new Main(N, A);

	}

}

Measured memory_bytes: 56508
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 1000000007;
int main() {
    int N, K; cin >> N >> K;
    vector<Int> plus, minus;
    for (int i = 0; i < N; i++) {
        Int a; cin >> a;
        if (a >= 0) plus.push_back(a);
        else minus.push_back(a);
    }
    if (plus.size() == 0) {
        if (K % 2 == 0) sort(begin(minus), end(minus));
        if (K % 2 == 1) sort(rbegin(minus), rend(minus));
        Int ans = 1;
        for (int i = 0; i < K; i++) {
            ans = ans * (MOD + minus[i]) % MOD;
        }
        cout << ans << '\n';
    } else if (N == K) {
        Int ans = 1;
        for (auto x : plus) ans = ans * x % MOD;
        for (auto x : minus) ans = ans * (MOD + x) % MOD;
        cout << ans << '\n';
    } else {
        sort(rbegin(plus), rend(plus));
        sort(begin(minus), end(minus));
        Int ans = 1;
        int n = 0, m = 0;
        if (K % 2) ans = ans * plus[0] % MOD, n++;
        while (n + m < K) {
            Int a = (n + 1 < plus.size() ? plus[n] * plus[n + 1] : -1);
            Int b = (m + 1 < minus.size() ? minus[m] * minus[m + 1] : -1);
            if (a > b) {
                ans = ans * (a % MOD) % MOD;
                n += 2;
            } else {
                ans = ans * (b % MOD) % MOD;
                m += 2;
            }
        }
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 5636
double d,r,s,z[];main(i){for(;~scanf("%lf",z-i--%6);!i|i%6||puts((d=hypot(*z-z[3],z[1]-z[4]))>r+(s=z[5])?"0":r>d+s?"2":s>d+r?"-2":"1"))r=z[2];}

Measured memory_bytes: 0
#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
	map<int, int>ans;
	int now = 2;
	while (now * now <= x) {
		if (x % now == 0) {
			x /= now;
			ans[now]++;
		}
		else now++;
	}
	if (x != 1) ans[x]++;
	return ans;
}
int comb(int n, int k) {
	k = min(k, n - k);
	int x = 1, y = 1;
	rep(i, k) {
		y *= i + 1;
		y %= MOD;
	}
	for (int i = n - k + 1; i <= n; i++) {
		x *= i;
		x %= MOD;
	}
	return x * modinv(y, MOD) % MOD;
}

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

	int k, n;
	int a[200005];
	int ans = INF;
	cin >> k >> n;
	rep(i, n) cin >> a[i];
	a[n] = k + a[0];
	rep(i, n) {
		chmin(ans, k - (a[i + 1] - a[i]));
	}
	cout << ans << endl;

	return 0;
}


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

typedef long long ll;

int main() {
    int N, a, b;
    cin >> N;
    vector<vector<int>> edge(N, vector<int>(0));
    rep(i, N - 1) {
        cin >> a >> b;
        a--;
        b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vector<int> d(N, -1);
    queue<vector<int>> q;
    q.push({0, 0});
    while (!q.empty()) {
        auto p = q.front();
        q.pop();
        d[p[0]] = p[1];
        rep(i, edge[p[0]].size()) {
            int j = edge[p[0]][i];
            if (d[j] > -1) continue;
            q.push({j, p[1] + 1});
        }
    }
    int dmax = 0, imax = 0;
    rep(i, N) {
        if (d[i] > dmax) {
            dmax = d[i];
            imax = i;
        }
    }
    rep(i, N) d[i] = -1;
    q.push({imax, 0});
    while (!q.empty()) {
        auto p = q.front();
        q.pop();
        d[p[0]] = p[1];
        rep(i, edge[p[0]].size()) {
            int j = edge[p[0]][i];
            if (d[j] > -1) continue;
            q.push({j, p[1] + 1});
        }
    }
    dmax = 0;
    rep(i, N) {
        if (d[i] > dmax) {
            dmax = d[i];
        }
    }
    if (dmax % 3 == 1) cout << "Second" << endl;
    else cout << "First" << endl;
}

Measured memory_bytes: 23924
#include<stdio.h>
int main(){
 int i,n,b,c=0,a=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){ scanf("%d",&b); if(b%2==0){  c++; if(b%3==0||b%5==0){a++;} } }
  puts(c==a?"APPROVED":"DENIED");              
}


Measured memory_bytes: 1624
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REP1(i,n) for(int i=1;i<=(int)(n);i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;

int main(){
  int x;
  cin >> x;
  if(x>=30)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3620
/// 2:59 PM 27/05/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>

using namespace std;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define VARIABLE_ERROR(x) cout << #x << " = " << x << endl;
#define CONTAINER_ERROR(v) cout << "{";for (auto &x:v) { cout << x << ','; }cout << "}" << endl;
#define PI 3.14159265358979323846
#define M 1000000007
#define INF 1e15
typedef long long ll;

ll sol(ll pos, ll sum, ll flag, string &s, ll n, ll d, vector<vector<vector<ll> > > &dp) {
    if (pos == n) {
        return (sum == 0);
    }
    if (dp[pos][sum][flag] != -1) {
        return dp[pos][sum][flag];
    }
//    sum = (sum * 10) % d;
    ll ans = 0;
    ll limit = flag ? s[pos] - '0' : 9;
    for (ll i = 0; i <= limit; i++) {
        ll nf = 0;
        if(i == limit && flag == 1) {
            nf = 1;
        }
        ans += sol(pos + 1, (sum + i) % d, nf, s, n, d, dp);
        ans = (ans % M);
    }
    return dp[pos][sum][flag] = ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    string s;
    cin >> s;
    ll d;
    cin >> d;
    ll n = s.size();
    vector<vector<vector<ll> > > dp(n + 1, vector<vector<ll> >(d + 1, vector<ll>(2, -1)));
    ll ans = sol(0, 0, 1, s, n, d, dp);
    ans = (ans - 1 + M) % M;
    cout << ans;
//    reverse(s.begin(), s.end());
//    for (ll i = 0; i <= (s[0] - '0'); i++) {
//        dp[0][i % d][0] = (dp[0][i % d][0] + 1) % M;
//    }
//    for (ll i = s[0] - '0' + 1; i <= 9; i++) {
//        dp[0][i % d][1] = (dp[0][i % d][1] + 1) % M;
//    }
//    for (ll rem = 0; rem < d; rem++) {
//        dp[0][rem][1] = (dp[0][rem][1] + dp[0][rem][0]) % M;
//    }
//    for (ll i = 1; i < n; i++) {
//        ll limit = s[i] - '0';
//        for (ll rem = 0; rem < d; rem++) {
//            for (ll val = 0; val < limit; val++) {
//                ll newRem = (rem + pow10[i] * val) % d;
//                dp[i][newRem][0] = (dp[i][newRem][0] + dp[i - 1][rem][1]) % M;
//            }
//            for (ll val = limit; val < 10; val++) {
//                ll newRem = (rem + pow10[i] * val) % d;
//                dp[i][newRem][1] = (dp[i][newRem][1] + dp[i - 1][rem][1]) % M;
//            }
//        }
//    }
//    cout << dp[n - 1][0][0] << endl;
    return 0;
}

Measured memory_bytes: 57216
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
// ------------------------------

int main() {
    int L, R, d;
    cin >> L >> R >> d;
    int ans = 0;
    FOR(i, L, R + 1){
        if (i % d == 0) ans += 1;
    }
    cout << ans << endl;
    return 0;
}

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

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class A
{
	public static void Main()
	{
		Console.WriteLine((GetInt() < 1200) ? "ABC" : "ARC");
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
using Graph = vector<vector<int>>;

int main() {
	int n, a, maxa = 0, mina = INF;
	cin >> n;
	rep(i, n) {
		cin >> a;
		mina = min(mina, a);
		maxa = max(maxa, a);
	}
	cout << maxa - mina << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int dp[2][101];
int a[101],b[101],A[101],B[101];
int n;
main()
{
	while(cin>>n,n)
	{
	    for(int i=0;i<=100;i++)a[i]=b[i]=A[i]=B[i]=0;
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
			dp[0][i]=1e9;
		}
		for(int i=0;i<n;i++)
		{
			cin>>b[i];
			dp[1][i]=1e9;
		}
		for(int i=0;i<n;i++)
		{
			A[i]=i;
			if(a[i]==1)
			{
				while(A[i]<n-1&&a[A[i]+1]==1)A[i]++;
			}
			else if(a[i]==2)
			{
				while(A[i]>0&&a[A[i]]==2)A[i]--;
			}
			B[i]=i;
			if(b[i]==1)
			{
				while(B[i]<n-1&&b[B[i]+1]==1)B[i]++;
			}
			else if(b[i]==2)
			{
				while(B[i]>0&&b[B[i]]==2)B[i]--;
			}
		}
		dp[0][A[0]]=dp[1][B[0]]=0;
		for(int cnt=n*2;cnt--;)
		for(int i=0;i<n;i++)
		{
			dp[1][B[i]]=min(dp[1][B[i]],dp[0][i]+1);
			dp[0][A[i]]=min(dp[0][A[i]],dp[1][i]+1);
			if(i<n-1)
			{
				dp[1][B[i+1]]=min(dp[1][B[i+1]],dp[0][i]+1);
				dp[0][A[i+1]]=min(dp[0][A[i+1]],dp[1][i]+1);
			}
			if(i<n-2)
			{
				dp[1][B[i+2]]=min(dp[1][B[i+2]],dp[0][i]+1);
				dp[0][A[i+2]]=min(dp[0][A[i+2]],dp[1][i]+1);
			}
		}
		int ans=min(dp[0][n-1],dp[1][n-1]);
		if(ans<1e9)cout<<ans<<endl;
		else cout<<"NA"<<endl;
	}
}



Measured memory_bytes: 3080
#include <cstdio>
#include <cmath>

using namespace std;

double X1,Y1,r1,X2,Y2,r2;

int main()
{
    int n; scanf( "%d\n", &n );
    while( n > 0 ){
        scanf("%lf %lf %lf %lf %lf %lf\n", &X1, &Y1, &r1, &X2, &Y2, &r2 );
        double dx = X2 - X1, dy = Y2 - Y1;
        double dis = sqrt( dx * dx + dy * dy );


        if( dis < r1 - r2 )
        {
            printf( "%d\n", 2 );
        }
        else if( dis < r2 - r1 )
        {
            printf( "%d\n", -2 );
        }
        else if( abs( r2 - r1 ) <= dis && dis <= r2 + r1 )
        {
            printf( "%d\n", 1 );
        }
        else
        {
            printf( "%d\n", 0 );
        }
        n--;
    }
    return 0;
}


Measured memory_bytes: 2660
fun main (args : Array<String>) {
	val n = readLine()!!
	val s = readLine()!!
	val N : Int = n.toInt()
	val S : String = s.toString()
	val list : List<String> = listOf("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")
	var result : String = ""
	for (i in S) {
		val num = list.indexOfFirst{ it == i.toString()} + N
		if (num <= 25) {
			result += list[num]
		} else {
			result += list[num - 26]
		}
	}
	println("${result}")
}

Measured memory_bytes: 67616
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const int MOD=1000000007;
int INF=100100100100100;
int add(int a,int b){
  return (a+b)%MOD;
}
int prod(int a,int b){
  return (a*b)%MOD;
}

int beki(int a,int b)
{
	if(b==0)return 1;
	int x=beki(a,b/2);
	if(b%2==0)return (x*x);
	else return (((a*x))*x);
}

int inv(int a)
{
	return beki(a,MOD-2);
}

int kaijou(int a)
{
	int ans=1;
	for(int i=1;i<=a;i++)
	{
		ans=(ans*i)%MOD;
	}			
	return ans;
}

/*int combi(int a,int b)
{
	int ret=1;
	for(int i=1;i<=b;i++)
	{
		ret=(((ret*(a+1-i))%MOD)*inv(i))%MOD;
	}
	return ret;
}*/
/*
const int MAX_a=200010;
int cb[MAX_a+1]
void combi(int a,int b)
{
    int ret=1;
    cb[0]=1;
    for(int i=1;i<=b;i++)
    {
	ret=(((ret*(a+1-i))%MOD)*inv(i))%MOD;
        cb[i]=ret;
    }
	
}*/

vector<P> prime_factorize(int N)
{
	vector<P> res;
	for(int a=2;a*a<=N;a++)
	{
		if(N%a!=0)continue;
		int ex=0;
		while(N%a==0)
		{
			ex++;N/=a;
		}
		res.push_back(P(a,ex));
	}
	if(N!=1)res.push_back(P(N,1));
	return res;
}

//ここから書く
signed main(){
  int n,m;
  cin>>n>>m;
  vector<P> res=prime_factorize(m);
  int ans=1;
  for(auto p:res){
    ans*=beki(p.F,p.S/n);
  }
  cout<<ans<<endl;
  
  return 0;
}

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,ret=0,x; cin>>n;
	map<int,int> ct;
	for (int i=0; i<n; i++)
		cin>>x, ct[x]++;
	for (auto it : ct) {
		int key=it.first, value=it.second;
		ret+=value - ((value<key) ? 0 : key);
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 4736
//int a = s - '0'; 文字から数字
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define PI 3.14159265358979323846264338327950L
using namespace std;

//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

int main() {
	string w;cin >> w;

	map<char, int> p;
	for(int i = 0; i < w.size(); i++)p[w[i]]++;
	
	auto begin = p.begin(), end = p.end();
	for (auto it = begin; it != end; it++) {
		if(it->second%2 != 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}	

Measured memory_bytes: 10864
/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpl vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
#define modA(cccc,bbbb ,p) (((cccc+bbbb)%p+p)%p)
#define modS(cccc,bbbb ,p) (((cccc-bbbb)%p+p)%p)
#define modM(cccc,bbbb ,p) ((((cccc%p)*(bbbb%p))%p+p)%p)

long long int modp(lld a,lld p,lld n)
{
    lld d[100];
    lld i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

lld fac[1000001]; 

void getfac(lld p)
{
    fac[0] = 1; 
    for (lld i=1 ; i<=200000; i++) 
        fac[i] = fac[i-1]*i%p; 
}    

long long int nCrmodp(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
     
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}


long long int gcd(lld b,lld a)
{
    if(a<b) return gcd(a,b);
    if(a%b==0) return b;
    return gcd(a%b , b);
}

lld p1=1e9 + 7,p2=998244353;
lld l,r,mid,ans=0;
lld n,i,j,k,m;
lld x,y,n1,b=0,a,n2,h,z,c;
lld p=1000000000;
double pi=3.1415926535;

void solve()
{
    cin>>n >>k;
    vector<lld> v,w(n);
    for(i=0;i<n;i++)
    {
        cin>>l;
        v.pb(l);
    }
    w[0]=0;
    for(i=1;i<=min(n-1,k);i++)
    {
        w[i] =abs(v[i]-v[0]);
    }
    for(i=k+1;i<n;i++)
    {
        x=INF;
        for(j=i-1;j>=i-k;j--)
        {
            x =min(x,w[j]+abs(v[j]-v[i]));
        }
        w[i] = x;
    }
 //   for(i=0;i<5;i++) cout<<w[i]<<" ";
    cout<<w[n-1];
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t=1;
    
   //  cin>>t;
    //cout<<t;
     //getfac(p1);
    //check the value by which modulo is to be taken

    for(int i=0;i<t;i++)
    {
   //     cout<<"Case #"<<i+1<<": ";
            solve();
        cout<<"\n";
    }
    return 0;
}

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

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

    vector<int> h(N+1, 0);
    for(int i = 0; i < N; i++){
        cin >> h[i];
    }
    
    int ans = 0;
    for(int i = 1; i < N+1; i++){
        if(h[i-1] > h[i]){
            ans += h[i-1] - h[i];
        }
    }

    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

		System.out.println(((a < b) && (b < c))? "Yes" : "No");
	}
}

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

#define ll long long
#define ull unsigned long long 
#define endl '\n'
#define pii pair<int, int>
#define all(a) a.begin(),a.end()

template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

int main(){
    ll n;
    cin >> n;
    n *= 3;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];

    sort(all(a));


    ll s=0, t=2, i=0;
    while(i<n/3){
        s+=a[n-t];
        t +=2;
        ++i;
    }

    cout << s;
}

Measured memory_bytes: 4548
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;

using namespace std;

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

  for (auto i = M / N; i > 0; i--) {
    if (M % i != 0) continue;
    cout << i << endl;
    break;
  }

  return 0;
}


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

void BFS(vector<vector<int> >& V, vector<int>& time) {
	int i,k;
	int cnt=1;
	queue<pair<int,int> > qv;

	qv.push({1,0});
	time[1]=0;
	while(!qv.empty()) {
		k=qv.front().first;
		cnt=qv.front().second+1;
		qv.pop();
		for(i=0; i<(int)V[k].size(); ++i) {
			if(time[V[k][i]]==-1) {
				qv.push({V[k][i],cnt});
				time[V[k][i]]=cnt;
			}
		}
	}
}

int main() {
	int n,k,u;
	vector<vector<int> > V;
	vector<int> time;

	scanf("%d",&n);
	V.resize(n+1);
	time.resize(n+1);

	for(int i=1; i<=n; ++i) {
		scanf("%d%d",&u,&k);
		V[u].resize(k);
		time[u]=-1;
		for(int j=0; j<k; ++j) {
			scanf("%d",&V[u][j]);
		}
	}
	BFS(V,time);

	for(int i=1; i<=n; ++i) {
		printf("%d %d\n",i,time[i]);
	}
	return 0;
}

Measured memory_bytes: 2704
table = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

N = int(input())

for loop in range(N):
    house_id,floor,room,add = map(int,input().split())
    table[house_id-1][floor-1][room-1] += add

for i in range(4):
    for j in range(3):
        print(' '+' '.join(map(str, table[i][j])))
    if(i != 3):
        print("#"*20)


Measured memory_bytes: 5608
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut arr: [(i64, i64); n],
    }

    let mut a: Vec<_> = arr.iter().copied().map(|(a, _)| a).collect();
    let mut b: Vec<_> = arr.iter().copied().map(|(_, b)| b).collect();
    a.sort();
    b.sort();

    if n % 2 == 0 {
        let min = a[n / 2 - 1] + a[n / 2];
        let max = b[n / 2 - 1] + b[n / 2];
        println!("{}", max - min + 1);
    } else {
        let min = a[n / 2];
        let max = b[n / 2];
        println!("{}", max - min + 1);
    }
}


Measured memory_bytes: 12824
def main():
    a, b, n = [int(x) for x in input().split()]
    # gen = (a * x // b - x // b * a for x in range(min(b, n) + 1))

    if n >= b - 1:
        x = b - 1
    else:
        x = n

    return a * x // b - x // b * a


if __name__ == '__main__':
    print(main())


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

public class Main {
	FastScanner in = new FastScanner(System.in);
	PrintWriter out = new PrintWriter(System.out);

	public void run() {
		while (true) {
			int M = in.nextInt(), T = in.nextInt(), P = in.nextInt(), R = in.nextInt();
			if ((M|T|P|R) == 0) break;
	
			int[] solved = new int[T+1];
			int[] penalty = new int[T+1];
			int[][] missCount = new int[T+1][P+1];
			
			for (int i = 0; i < R; i++) {
				int m = in.nextInt(), t = in.nextInt(), p = in.nextInt(), j = in.nextInt();
				if (j == 0) {
					solved[t]++;
					penalty[t] += (missCount[t][p] * 20) + m;
				} else {
					missCount[t][p]++;
				}
			}
			
			boolean[] used = new boolean[T+1];
			int beforeSolved = -1, beforePenalty = 1000000;
			for (int i = 1; i <= T; i++) {
				int nextTeam = -1;
				int maxSolved = -1, minPenalty = 10000000;
				for (int j = 1; j <= T; j++) {
					if (used[j]) continue;
					if (maxSolved < solved[j] || (maxSolved == solved[j] && minPenalty >= penalty[j])) {
						nextTeam = j;
						maxSolved = solved[j];
						minPenalty = penalty[j];
					}
				}
				if (i != 1)
					if (minPenalty == beforePenalty && maxSolved == beforeSolved) {
						System.out.print("=");
					} else {
						System.out.print(",");
					}
				System.out.print(nextTeam);
				beforeSolved = maxSolved;
				beforePenalty = minPenalty;
				used[nextTeam] = true;
			}
			
			System.out.println();
		}
	}

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

	public void debug(Object... obj) {
		System.out.println(Arrays.deepToString(obj));
	}

	class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
			//stream = new FileInputStream(new File("dec.in"));

		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}

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

int main(){
	long n;
	cin >> n;
	double s = sqrt(n);
	long s1 = static_cast<long>(s);
	long s2 = s1;
	while(1){
		if(n%s1 == 0){
			s2 = n/s1;
			break;
		}
		if(n%s2 == 0){
			s1 = n/s2;
			break;
		}
		s1++;
		s2--;
	}
	int c1 =0;
	int c2 = 0;
	while(s1 != 0){
		s1 /= 10;
		c1++;
	}
	while(s2 != 0){
		s2 /= 10;
		c2++;
	}
	cout << max(c1, c2) << endl;

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

long long solve(const vector<pair<int, int> >& v)
{
    int n = v.size();
    multiset<int> x;
    multiset<int> y;
    multiset<pair<int, int> > p;
    for(int i=0; i<n; ++i){
        x.insert(v[i].first);
        y.insert(v[i].second);
        p.insert(make_pair(v[i].second, v[i].first));
    }

    long long ans = LLONG_MAX;
    for(;;){
        long long tmp = *x.rbegin() - *x.begin();
        tmp *= *y.rbegin() - *y.begin();
        ans = min(ans, tmp);

        if(p.empty())
            break;

        int a, b;
        tie(a, b) = *p.begin();
        p.erase(p.begin());
        x.erase(x.find(b));
        x.insert(a);
        y.erase(y.find(a));
        y.insert(b);
    }

    return ans;
}

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int> > v(n);
    for(int i=0; i<n; ++i){
        int x, y;
        cin >> x >> y;
        v[i].first = min(x, y);
        v[i].second = max(x, y);
    }
    sort(v.begin(), v.end());

    cout << solve(v) << endl;

    return 0;
}


Measured memory_bytes: 29952
#include<vector>
#include<iostream>
#include<queue>
#include<functional>
using namespace std;

constexpr int INF = 1e9;

struct edge
{
	int from, to, cost;
	bool operator>(const edge& other)
	const{
		return cost > other.cost;
	}
};

using edges= vector<edge>;
using graph = vector<edges>;

void add_edge(graph& g,int from,int to,int cost)
{
	g[from].push_back(edge{ from,to,cost });
	g[to].push_back(edge{ to,from,cost });
}

edges prim(const graph& g)
{
	const int N = g.size();
	vector<bool>used(N);
	used[0] = true;
	priority_queue<edge, vector<edge>, greater<edge>>que;
	for (auto e:g[0])
	{
		que.push(e);
	}
	edges mst;
	while (!que.empty())
	{
		auto e = que.top();
		que.pop();
		if (used[e.to])
		{
			continue;
		}
		mst.push_back(e);
		used[e.to] = true;
		for (auto new_e:g[e.to])
		{
			que.push(new_e);
		}


	}
	return mst;


	
}
int main()
{
	int V, E;
	cin >> V >> E;
	graph g(V);
	for (int i = 0; i < E; i++)
	{
		int s, t, w;
		cin >> s >> t >> w;
		add_edge(g, s, t, w);
	}
	const auto mst = prim(g);
	int ans = 0;
	for (auto& e : mst)
	{
		ans += e.cost;
	}
	cout << ans << endl;
	return 0;
}
/*
メンバ関数（今回は演算子オーバーロードですが同じ）のこの位置にある const の意味は
この関数の呼び出しによって，オブジェクトの内部状態が変わらないという保証になります
つまり今回であれば，operator > が呼び出されても，edge の中身のデータは変わらないよ，ということを，関数の宣言時点で明言しているということです
エラーが出る理由についてですが
std::sort のデフォルトの挙動では，std::less が使われます
（つまり < ですね
std::less<edge> の呼び出し時の引数の型は (const edge& e1, const edge& e2) であり，どちらも const が付いています
つまり，std::less の中で，e1 にも e2 にも変更を加えることが出来ないということを意味します．
もしこの時に，e1 （あるいは e2）の const でないメンバ関数を呼び出すことが出来てしまうと，オブジェクトの状態が変わる可能性があり，e1 が const であることに反し許容できません．
したがってエラーとなります．
const をつけた場合，その関数を呼び出しても内部状態が変わらないことがコンパイラにわかるので，std::less<edge> のなかで e1 < e2 が呼び出されても，問題ないというわけです
多分さっきのコードは greater だったはずなので，less を greater に置き換えて貰えれば同じです
ひえ～長文になってしまった（C++早口オタクじゃん（ごめん
doi [19:01]
　less の引数のe1あるいはe2がconstであることはbool operator>(const edge& other)で引数がconstであることによってしめされないのでしょうか？
suibaka [19:02]
e1 > e2 としたとき，other は e2 になってこっちはいいのですが，e1 はそうじゃないのでダメですね
例えば operator の定義を edge の外に出して，
bool operator>(const edge& e1, const edge& e2) {
return e1.cost > e2.cost;
}
とやれば問題ないです．
suibaka [19:33]
メンバ関数は，暗黙のうちに（僕らには見えないけど）第一引数にそのオブジェクトのポインタが渡されています
w.f(42) なら f(&w, 42) みたいなイメージです
ここまでは大丈夫ですか
doi [19:34]
大丈夫です
suibaka [19:35]
メンバ関数を const 修飾すると，この this ポインタに const が付きます
すると，this ポインタが指す先のデータの変更がダメという意味になりますね
f() は const 修飾されているので，this->data = arg は this が const なのでできません．
g は問題ないです．this は const じゃないから．
#include <iostream>
using namespace std;
class widget {
public:
widget() : data(0) {}
void f(int arg) const {
data = arg; // error
}
void g(int arg) {
data = arg; // ok
}
private:
int data;
};
// widget::f, g はこういう意味だと思うと良い
// void f(const this ポインタ, int arg) {
//	this->data = arg;
//}
// void g(widget* w, int arg) {
// this->data = arg;
//}
//
// メンバ関数の第1引数には，暗黙のうちに this ポインタが渡されている．
// メンバ関数を const 修飾すると，この this ポインタに const がつく．
// だから，this->data = arg は const 修飾されているとエラーになる．
// g の方は const じゃないので，this->data はOK
int main() {
widget w;
w.f(42); // error
w.g(42); // ok
return 0;
}
*/


Measured memory_bytes: 10228