akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	// Atcoder用のサンプルプログラム
    public static void main(String[] args) throws Exception {
    	
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	
    	 /* 
    	  * 文字の種類抜き出し
    	  * N繰り返し
    	  * i文字目で分裂
    	  * 抜き出した文字がXに含まれる　かつ　Yに含まれる
    	  * →count+1
    	  *  
    	  *  */
    	 String N = br.readLine();
    	 String S = br.readLine();
    	 int Nint = Integer.parseInt(N);
    	 String[] mozisyuryui = new String[Nint];
    	 int mozisyuruiSu=0;
    	 for (int i = 0;i < Nint;i++) {
    		 if (!Arrays.asList(mozisyuryui).contains(String.valueOf(S.charAt(i)))) {
    			 mozisyuryui[mozisyuruiSu]=String.valueOf(S.charAt(i));
    			 mozisyuruiSu++;
    		 }
    	 }
    	 
    	 int result=0;
    	 int tempCnt=0;

    	 for (int j = 0;j < Nint;j++) {
    		 for (int i = 0;i < mozisyuruiSu;i++) {
    			 String judgeMozi = mozisyuryui[i];

        		 if (S.substring(0,j).contains(judgeMozi) && S.substring(j,Nint).contains(judgeMozi)) {
        			 tempCnt++;
        		 }
        	 }
    		 if (tempCnt > result) {
    			 result = tempCnt;
    		 }
    		 tempCnt=0;
    	 }
     	System.out.println(result); 

    	 
    	 
    	 
    	//System.out.println("End!!");
    }
    
    private static int add(String a, String b) throws Exception{
    	return Integer.parseInt(a) + Integer.parseInt(b);
    }

    private static int subtract(String a, String b) throws Exception {
    	return Integer.parseInt(a) - Integer.parseInt(b);
    }
    
    private static int multiply(String a, String b) throws Exception {
    	return Integer.parseInt(a) * Integer.parseInt(b);
    }
    
    private static int divide(String a, String b) throws Exception {
    	return Integer.parseInt(a) / Integer.parseInt(b);
    }
    
    private static int pow(String a, String b) throws Exception {
    	Double result = Math.pow(Double.parseDouble(a),Double.parseDouble(a));
    	return Integer.parseInt(Double.toString(result));
    }
    
    private static String getBigger(String a, String b) throws Exception {
    	String result = b;
    	if (Integer.parseInt(a) >= Integer.parseInt(b)) {
    		result = a;
    	}
    	return result;
    }
    
    private static double getBigger(double a, double b) throws Exception {
    	double result = b;
    	
    	Double.compare(a, b);
    	if (Double.compare(a, b) > 0) {
    		result = a;
    	}
    	return result;
    }
    // 備忘録
    // int → String  String.valueOf();
    // String → int  Integer.parseInt();
    // BigDecimal → int XXX.intValue();
    // double → BigDecimal new BigDecimal(XXX);
    // setScale BigDecimalの桁まとめ 
    // nBig.setScale(0,BigDecimal.ROUND_DOWN);
    // 絶対値 → Math.abs
    
}

Measured memory_bytes: 22612
#include<iostream>
using namespace std;
#define MAX 2000000

int H,A[MAX+1];

void maxHeapify(int i){
  int l,r,largest;
  l = 2 * i;
  r = 2 * i + 1;

  if(l <= H && A[l] > A[i])largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest])largest = r;

  if(largest != i){
    swap(A[i],A[largest]);
    maxHeapify(largest);
  }
}

int main(){
  cin >> H;

  for(int i = 1;i <= H; i++)cin >> A[i];

  for(int i = H / 2; i >= 1; i--)maxHeapify(i);

  for(int i = 1; i <= H; i++){
    cout << " " << A[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3116
function Main (input) {
  const inputValue = input.split(/\s/g).map(num => parseInt(num));
  const west = inputValue[0];
  const east = inputValue[1];
  if (west < 499500 && east < 499500) {
    const diff = east - west;
    const eastTowerHight = new Array(diff).fill('').map((value, index) => index + 1).reduce((prev, current) => prev + current);
    console.log('%s', eastTowerHight - east);
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7500
from collections import defaultdict

d = defaultdict(int)

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

ans = []
for i in a:
  d[i] += 1
  if d[i] == 2:
    d[i] = 0
    ans.append(i)
ans.sort(reverse=True)
if len(ans) >= 2:
  print(ans[0]*ans[1])
else:
  print(0)


Measured memory_bytes: 22032
#include<stdio.h>
int main(){
  char *s;
  int d;
  scanf("%d",&d);
  if(d==25)s="Christmas";
  else if(d==24)s="Christmas Eve";
  else if(d==23)s="Christmas Eve Eve";
  else if(d==22)s="Christmas Eve Eve Eve";
  else s="";
  printf("%s",s);
  return 0;
}

Measured memory_bytes: 128
# G点を超えるために解く問題数の最小値
# 配点の大きいi=Dの問題から点数を加算していき、Gを超えた時点での解答数を出せばよさそう
# と思ったがコンプリートボーナスがあるからそう単純でない。

# 制約から全探索するとO(2***1000)かかるため、これは無理
# i番目の問題をx(i)個解くと考えると、x(i)の全探索はO(100)
# これをすべてのiについて考えるとO(1000)

D, G = map(int, input().split())
P, C = [], []
for _ in range(D):
    p, c = map(int, input().split())
    P.append(p)
    C.append(c)


# ボーナスの取り方（2**10 = 10**3）を全探索 → ボーナスが固定される
ans = float("inf")
for bit in range(0, 1<<D):
    s = 0
    num = [0 for _ in range(D)]  # i番目の問題を何個解いたか
    for i in range(D):
        if (bit>>i) & 1:
            num[i] += P[i]
            s += 100*(i+1)*P[i] + C[i]
    # 足りない場合は残ってる問題で100iの値が大きい順に解いていく
    if s < G:
        for i in reversed(range(D)):
            if not (bit>>i) & 1:
                while num[i] < P[i]-1:
                    s += 100*(i+1)
                    num[i] += 1
                    if s >= G:
                        ans = min(ans, sum(num))
                        break
                break
    else:
        ans = min(ans, sum(num))

print(ans)

Measured memory_bytes: 42604
//This is getting accepted!
// I HATE BUG
// God Of The Bugs
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int n, a[MAXN], par[70][MAXN], cur[MAXN], ans[MAXN];
ll d[MAXN], pos[MAXN];
int M;
ll K;

int main() {
//#ifndef ONLINE_JUDGE
//    freopen("inp.txt", "r", stdin);
////    freopen("out.txt", "w", stdout);
//#endif

	scanf("%d", &n);
	for (int i=0; i<n; i++) scanf("%lld", &pos[i]);
	
	scanf("%d%lld", &M, &K);
	for (int i=0; i<M; i++) scanf("%d", &a[i]);
	
	for (int i=0; i<n-1; i++) d[i] = pos[i+1] - pos[i];
	
	for (int i=64; i>=0; i--) {
		for (int j=0; j<n; j++) par[i][j] = j;
	}
	
	for (int i=0; i<n; i++) cur[i] = i;
	
	for (int i=0; i<M; i++) {
		swap(cur[a[i] - 2], cur[a[i] - 1]);
	}
	
//	cout << cur[0] << " " << cur[1] << endl;
	
	for (int i=0; i<n; i++) {
		par[0][cur[i]] = i;
	}
	
	for (int i=1; i<63; i++) {
		for (int j=0; j<n; j++) {
			par[i][j] = par[i-1][par[i-1][j]];
		}
	}
	
//	cout << (1ll << 62) << endl;
	for (int i=0; i<n-1; i++) {
		ll now = K;
		int AN = i;
		for (int j=62; j>=0; j--) {
			if ((1ll << j) <= now) {
				now -= (1ll << j);
//				cout << j << " " << AN << endl;
				AN = par[j][AN];
			}
		}
//		cout << AN << " " << i << endl;
		ans[AN] = i;
	}

//	cout << ans[0] << " " << ans[1] << endl;
	
	printf("%lld\n", pos[0]);
	ll now = pos[0];
	for (int i=0; i<n-1; i++) {
		int idx = ans[i];
		now = d[idx] + now;
		printf("%lld\n", now);
	}
	
	return 0;	
}


Measured memory_bytes: 29312
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- getl toInt
  k <- getl toInt
  unless (n == 0 && k == 0) $ do
    solve k <$> replicateM n getLine >>= print
    main

solve :: Int -> [String] -> Int
solve k = length . nub . map concat . perm k
  where
    perm n xs
      | n == 1 = [[x] | x <- xs]
      | otherwise = [ys | x <- xs, ys <- map (x:) (perm (n-1) (xs \\ [x]))]

toInt :: String -> Int
toInt = read

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 5408
import java.lang.Long.max
import java.lang.Math.ceil

//

fun main() {
    abc174e()
}

fun abc174e() {
    val (n, k) = readLine()!!.split(" ").map { it.toLong() }
    val a = readLine()!!.split(" ").map { it.toLong() }
    if (k == 0L) {
        println(a.max())
        return
    }
    var total = 0L
    var max = 0L
    for (l in a) {
        max = max(max, l)
        total += l
    }
    if (total <= k) {
        println(1)
        return
    }
    var left = 1L
    var right = max
    while (left + 1L < right) {
        val mid = (left + right) / 2
        var count = 0L
        for (l in a) {
            count += (ceil(l.toDouble() / mid) - 1).toInt().coerceAtLeast(0)
            if (count > k) break
        }
        if (count <= k) {
            right = mid
        } else {
            left = mid
        }
    }
    println(right)
}


Measured memory_bytes: 65088
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int k=sc.nextInt(), s=sc.nextInt();
		int cnt=0;
		for(int x=0;x<=k;x++){
			for(int y=0;y<=k;y++){
				if(s-x-y>=0&&s-x-y<=k)cnt++;
			}
		}
		System.out.println(cnt);
		sc.close();
	}

}


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

#define mp make_pair
#define pb push_back

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef long long ll;
typedef double db;

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


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

using namespace __gnu_pbds;
using namespace std;

#define inf 1013161010
#define ninf -1013161010
#define mod 1000000007
#define ll long long
#define lf long double
#define in(x) scanf("%d",&x);
#define sz(x) ((int)x.size())
#define lld l64d
#define rep(i,n) for(i=0;i<n;i++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
#define rep1(i,a,b) for(i=a;i<=b;i++)
#define rrep1(i,a,b) for(i=a;i>=b;i--)
#define stlfor(i,t) for(auto i =t.begin();i!=t.end();i++)
#define fr freopen("x.txt","r",stdin)
#define frc freopen("y.txt","w",stdout)
#define all(x) x.begin(),x.end()
#define set0(x) memset(x,0,sizeof(x))
#define dbg cout<<"yo "<<endl;
#define pset(n) fixed<<showpoint<<setprecision(n)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define min_pq priority_queue<pll, vector<pll>, greater<pll> >
#define vpii vector<pair<int,int> >
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
#define si set<int>
#define mii map<int,int>
#define umii unordered_map<int,int>
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define modulo %
#define moduloe %=

typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> OST;

ll toint(const string &s) { stringstream ss; ss << s; ll x; ss >> x; return x; }
ll add(ll a, ll b) {a+=b; while(a >= mod) a-= mod; while(a<0) a+= mod;}
ll mul(ll a, ll b) {return (a * 1LL *b % mod);}
string tostring ( ll number ){  stringstream ss; ss<< number; return ss.str();}

const lf pi = 2*acos(0);
const int nn = 500006;
const lf EPS = 0.000000001;

ll gcd(ll a,ll b){return (b==0)? a:gcd(b,a%b); }
void nope(int num = 0){ if(num==0) cout<<"NO"; else cout<<"-1"; exit(0); }

ll sum[403][413], cost[413][412], a[410];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll i,j,n,tt;
    tt=1;
    //cin>>tt;
    while(tt--)
    {
        cin>>n;
        rep(i, n)
            cin>>a[i];

        for(i=0;i<n;i++)
        {
            ll ans = 0;
            for(j=i;j<n;j++)
            {
                ans += a[j];
                sum[i][j] = ans;
            }
        }

        for(i=2;i<=n;i++)
        {
            for(j=0;j<n-i+1;j++)
            {
                int last = j + i - 1;
                ll ans = 1e18;
                for(int k=j; k<last; k++)
                {
                    ans = min(ans, cost[j][k] + cost[k+1][last] + sum[j][k] + sum[k+1][last]);
                }
                cost[j][last] = ans;
            }
        }

        cout<<cost[0][n-1]<<endl;

    }
    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


Measured memory_bytes: 2816
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskA {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int[] a = new int[n];
			int[] b = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = in.nextInt();
				b[i] = in.nextInt();
			}
			long x = 0;
			for (int i = n - 1; i >= 0; i--) {
				x = b[i] * ((x + a[i] + b[i] - 1) / b[i]) - a[i];
			}
			out.println(x);
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

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

	}
}



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

using namespace std;

const int MAXN = 200005;

long long h[MAXN], dp[MAXN];

long double f(int i, int j)
{
    return (dp[i] - dp[j] + h[i]*h[i] - h[j]*h[j]) / (2.0 * (h[i]-h[j]));
}

int main()
{
    int n;
    long long c;
    scanf("%i%lli", &n, &c);
    for (int x = 1; x <= n; x++)
        scanf("%lli", &h[x]);
    deque<int> buf;
    buf.push_back(1);
    for (int x = 2; x <= n; x++)
    {
        while (buf.size() >= 2 && f(buf[0], buf[1]) <= h[x])
            buf.pop_front();
        dp[x] = dp[buf.front()] + (h[x] - h[buf.front()]) * (h[x] - h[buf.front()]) + c;
        while (buf.size() >= 2 && f(buf[buf.size()-2], buf[buf.size()-1]) >= f(buf[buf.size()-1], x))
            buf.pop_back();
        buf.push_back(x);
    }
    printf("%lli\n", dp[n]);
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
char mmp[1001][1001];
int ans[1001][1001];int n,m;
int u[]={1,1,1,0,0,-1,-1,-1},v[]={1,0,-1,1,-1,1,0,-1};
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
	{
		cin>>mmp[i][j];
		if(mmp[i][j]=='#') for(int k=0;k<8;k++) ans[i+u[k]][j+v[k]]++;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++) if(mmp[i][j]=='#') putchar('#');else cout<<ans[i][j];
		puts("");
	}
}

Measured memory_bytes: 2432
import numpy as np
N=int(input())
L=list(map(int,input().split()))
R=[i+1 for i in range(N)]
C=[0 for i in range(N)]

for i in range(N):
  C[i]=L[i]-R[i]

D=np.array(C)
if np.count_nonzero(D)>2:
  print("NO")
else:
  print("YES")

Measured memory_bytes: 21932
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

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

int main()
{
    int N;
    cin >> N;
    int ans = 0;
    rep(i, N)
    {
        int a, b;
        cin >> a >> b;
        ans += b - a + 1;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    if(N==M){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
using namespace std;
int main(){
  long long a,b,n,j;
  cin>>a>>b>>n;
  if (n > b - a + 1)
    for (int i=a;i<=b;i++)
      cout<<i<<endl;
  else{
    for (j=a;j<=a+n-1;j++)
      cout<<j<<endl;
    for (int q=b-n+1;q<=b;q++)
      if (q >= j)
        cout<<q<<endl;
    }
  system ("pause");
  return 0;
}

Measured memory_bytes: 504
#ifdef BUILT_LOCAL

#include "niklib.h"

#endif

#include <iostream>
#include <utility>
#include <numeric>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <list>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mod = 1000000007;

#define bs(n) (1ll<<(ll)(n))
#define rep(i, n) for(ll (i) = 0;(i) < (n);(i)++)
#define rrep(i, n) for(ll (i) = 1;(i) <= (n);(i)++)

int main() {
    string s, t;
    cin >> s >> t;
    if (t.substr(0, t.length() - 1) == s) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] as = new int[N];
        for (int i = 0; i < N; i++) {
            as[i] = sc.nextInt();
        }
        System.out.println( solve(N, as) );
    }

    private static int solve(int N, int[] as) {
        int min = Integer.MAX_VALUE;

        for (int n = -100; n <= 100; n++) {
            min = Math.min( calc(n, as), min );
        }
        return min;
    }

    private static int calc(int n, int[] as) {
        int cost = 0;
        for (int a : as) {
            int diff = a - n;
            cost += diff * diff;
        }
        return cost;
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define FI first
#define SE second
#define PB(a) push_back(a)
#define DEBUG(x) cerr << __LINE__ << ":" << #x << ": " << x << "\n";
#define SZ(x) ((int)(x).size())
#define SO(x) sizeof((x)) / sizeof((x)[0])
//#define int long long
using namespace std;
using lint = long long;
struct Fast{Fast(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};} fast;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
inline int in() {int x; cin >> x; return x;}
inline lint IN() {lint x; cin >> x; return x;}
inline void co(int a[], int n) {REP(i, n) cout << a[i] << " "; cout << "\n";}
//if (IO > 1e5){lint a;	scanf(%lld, &a);	printf("%lld\n", a);}

signed main(){
	int n;	cin >> n;
	if (n%111 == 0){
		cout << n << endl;
		return 0;
	}
	cout << (n/111 + 1) * 111 << endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pi 3.1415926535
#define endl '\n'
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll inf=1e18;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
//ll fac[250001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   ll n,m,i,j,a,b,c,r,k,s;
   cin>>n>>m;
   ll arr[n+1][m+1];
   char ch;
   c=0;
   for(i=1;i<=n;i++)
   {
       for(j=1;j<=m;j++)
       {
           cin>>ch;
           if(ch=='#')
            arr[i][j]=0;
           else
           {
               c++;
               arr[i][j]=c;
           }
       }
   }
   ll arr1[c+1][c+1];
   memset(arr1,-1,sizeof(arr1));
   for(i=1;i<=n;i++)
   {
       for(j=1;j<=m;j++)
       {
           a=arr[i][j];
           if(a==0)
            continue;
           arr1[a][a]=0;
           if(i+1<=n)
           {
               if(arr[i+1][j]!=0)
               {
                   b=arr[i+1][j];
                arr1[a][b]=1,arr1[b][a]=1;
               }
           }
           if(j+1<=m)
           {
               if(arr[i][j+1]!=0)
               {
                   b=arr[i][j+1];
                arr1[a][b]=1,arr1[b][a]=1;
               }
           }
       }
   }
   for(i=1;i<=c;i++)
    for(j=1;j<=c;j++)
   {
       if(arr1[i][j]==-1)arr1[i][j]=inf;
   }
   for(k=1;k<=c;k++)
   {
       for(i=1;i<=c;i++)
       {
           for(j=1;j<=c;j++)
           {
               if(arr1[i][k]+arr1[k][j]<=arr1[i][j])
                arr1[i][j]=arr1[i][k]+arr1[k][j];
           }
       }
   }
   r=0;
   for(i=1;i<=c;i++)
    for(j=1;j<=c;j++)
        r=max(r,arr1[i][j]);
    cout<<r<<endl;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int input;
    cin >> input;
    v.push_back(input);
  }
  sort(v.begin(), v.end());
  int center_upper_index = v.size() / 2;
  int center_upper = v[center_upper_index];
  // cout << "center_upper: " << center_upper << "\n";
  int center_lower_index = center_upper_index - 1;
  int center_lower = v[center_lower_index];
  // cout << "center_lower: " << center_lower << "\n";
  int counter = center_upper - center_lower;
  cout << counter;
}


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

int main(){
    int N,A,B,C,D;
    cin>>N>>A>>B>>C>>D;
    int a=0,b=0,c=0,d=0;
    a=(N+A-1)/A;
    c=a*B;
    b=(N+C-1)/C;
    d=b*D;
    if(c<=d){
        cout<<c<<endl;
    }
    else if(c>d){
        cout<<d<<endl;
    }
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, H, W, ans = 0;
    cin >> N >> H >> W;
    
    rep(i, N) {
        int a, b;
        cin >> a >> b;
        
        if ((a >= H) && (b >= W)) {
            ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		final int N = sc.nextInt();

		String[] s = new String[N];
		for (int i = 0; i < N; i++)
			s[i] = sc.next();
		char[] c = new char[10];
		for (int i = 0; i < N; i++) {

			for (int j = 0; j < 10; j++) {

				c[j] = s[i].charAt(j);
			}

			Arrays.sort(c);
			s[i] = String.valueOf(c);

		}
		Arrays.sort(s);
		long ans = 0;
		long count = 0;

		for (int i = 0; i < N - 1; i++) {

			if (s[i].equals(s[i + 1]))
				count++;

			if (!(s[i].equals(s[i + 1])) || i == N - 2) {
				ans += (count + 1) * count / 2;
				count = 0;
			}
		}

		System.out.println(ans);

	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


Measured memory_bytes: 49008
S = input()

def solve(n,S,idx):
    if len(n) == 7:
        if eval(n) == 7:
            n += "=7"
            print(n)
            exit()
        return

    solve(n+"+"+S[idx], S,idx+1)
    solve(n+"-"+S[idx], S,idx+1)

solve(S[0], S, 1)

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++)  cin >> a[i];
    for(int i = 0; i < n; i++)  cin >> b[i];
    sort(b.begin(), b.end());
    int ans = 0;
    for(int i = 28; i >= 0; i--){
        int now = 1<<i;
        for(int j = 0; j < n; j++){
            a[j] %= now*2;
            b[j] %= now*2;
        }
        sort(b.begin(), b.end());
        ll sum = 0;
        for(int j = 0; j < n; j++){
            sum += lower_bound(b.begin(), b.end(), 2*now-a[j]) - lower_bound(b.begin(), b.end(), now-a[j]);
            sum += lower_bound(b.begin(), b.end(), 4*now-a[j]) - lower_bound(b.begin(), b.end(), 3*now-a[j]);
        }
        ans += now*(sum%2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdio.h>

using namespace std;

int main(void)
{
    int ans=0;
    string s,t;cin>>s>>t;
    if(s[0]==t[0])ans++;
    if(s[1]==t[1])ans++;
    if(s[2]==t[2])ans++;
    cout<<ans;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

ll n,x;
ll ans=0;
pair<ll,ll> p[51];
void bg(ll i){
    if (i==0){
        ans++;
        x--;
        return;
    }
    x--;
    if (x<=0){
        return;
    }
    if (x>p[i-1].first){
        x-=p[i-1].first;
        ans+=p[i-1].second;
    }else bg(i-1);
    if (x<=0){
        return;
    }
    ans++;
    x--;
    if (x<=0){
        return;
    }
    if (x>p[i-1].first){
        x-=p[i-1].first;
        ans+=p[i-1].second;
    }else bg(i-1);
    x--;
}

int main(){
    cin >> n >> x;
    p[0]=(make_pair(1,1));
    for (ll i=1;i<=50;i++){
        p[i]=make_pair(p[i-1].first*2+3,p[i-1].second*2+1);
    }
    bg(n);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3568
N,K = list(map(int,input().split()))
H = [int(input()) for i in range(N)]
H.sort()
result = 10000000000
for i,h in enumerate(H):
    if K + i - 1 > N -1:
        break
    if result > H[K + i - 1] - H[i]:
        result = H[K + i - 1] - H[i]
print(result)




Measured memory_bytes: 7384
import java.util.Scanner;


public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			String[] s = sc.nextLine().split(",");
			double[] a = new double[8];
			for(int i=0;i < 8;i++){
				a[i] = Double.parseDouble(s[i]);
			}
			
			if(isCross(a[0],a[1],a[4],a[5],a[2],a[3],a[6],a[7]) > 0.0 || isCross(a[2],a[3],a[6],a[7],a[0],a[1],a[4],a[5]) > 0.0){
				System.out.println("NO");
			}else{
				System.out.println("YES");
			}
		}
	}
	
	private static double isCross(double p1_x,double p1_y,double p2_x,double p2_y,double p3_x,double p3_y,double p4_x,double p4_y){  
	    return ( (p1_x-p2_x)*(p3_y-p1_y) + (p1_y-p2_y)*(p1_x-p3_x)) * ((p1_x-p2_x)*(p4_y-p1_y) + (p1_y-p2_y)*(p1_x-p4_x));  
	}
}

Measured memory_bytes: 17164
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

ll gcd(ll a, ll b) {
  while (a && b) {
    if (a >= b) a %= b;
    else b %= a;
  }
  return a + b;
}
ll ketasum(ll n) { //桁の数字全ての和を返す 例: 112 -> 4
	ll sum=0;
	if (n<0) return 0;
	while (n>0) {
		sum += n%10;
		n /= 10;
	}
	return sum;
}

typedef pair<ll, ll> pair_t;

bool comp(const pair_t &a, const pair_t &b) {
        return a.first < b.first;
}

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{ // ふたつの配列をまとめてそーと A[2,1] B[3,4] -> 1,4 2,3
        ll n = av.size();
        vector<pair_t> p(n);
        vector<ll> av2(n), bv2(n);
        for (ll i = 0; i < n; i++)
                p[i] = make_pair(av[i], bv[i]);
        sort(p.begin(), p.end(), comp);
        for (ll i = 0; i < n; i++) {
                av2[i] = p[i].first;
                bv2[i] = p[i].second;
        }
        av = av2;
        bv = bv2;
}
ll facctorialMethod(ll k){ //階乗
	ll s;
	if(k > 1){
		s = k*facctorialMethod(k-1);
	} else {
		s = 1;
	}
	return s;
}
vl primes(ll n){
	vl x(n);
	REP(i, n){
		x[i] = 0;
	}
	for(ll i = 2; i < sqrt(n) + 2; i++){
		while(n % i == 0){
			n /= i;
			x[i-1] += 1;
		}
	}
	if(n > 1){
		x[n-1] += 1;
	}
	return x;
}


void solve(){
	string S;
	cin >> S;
	if(S == "Sunny"){
		cout << "Cloudy" << endl;
	} else if (S == "Cloudy"){
		cout << "Rainy" << endl;
	} else {
		cout << "Sunny" << endl;
	}
}


const ll mod = 1000000007;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}


Measured memory_bytes: 256
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn f(n: usize, k: usize) -> usize {
    if n == 0 {
        return 0;
    }
    1 + f(n / k, k)
}

fn main() {
    let (n, k): (usize, usize);
    input!(n, k);
    println!("{}", f(n, k));
}


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

int main() {
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    int minutes = h*60+m;
    double akakudo = 0.5*minutes;
    int bkakudo = 6*minutes%360;
    double p = abs(akakudo-bkakudo);
    p = min(p, 360-p);
    const double PI = 3.14159265359;
    p = PI/180*p;
    double ans = sqrt(a*a+b*b - 2*a*b*cos(p));
    cout << std::fixed << std::setprecision(15) << ans << endl;
}

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

int main()
{
	int a, b, c;

	cin >> a >> b;
	c = a * b;

	if (c % 2 == 0)
		cout << "Even" << endl;
	else
		cout << "Odd" << endl;

    return 0;
}



Measured memory_bytes: 256
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end
N = gets_i


if N % 1000 == 0
  puts 0
else
  puts 1000 * (N/1000 + 1) - N
end

Measured memory_bytes: 14664
def main():
    N, T = map(int, input().split())
    A = list(map(int, input().split()))
    minimum = float("inf")
    maximum = -1
    ans = 0
    for i in range(N):
        minimum = min(A[i], minimum)
        if maximum == A[i] - minimum:
            ans += 1
        elif maximum < A[i] - minimum:
            maximum = A[i] - minimum
            ans = 1
    print(ans)


if __name__ == "__main__":
    main()


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

typedef long long ll;
#define pii pair<int ,int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int a , b , c;

int main()
{
    _FastIO;
    set<int> s;
    cin >> a;
    s.insert(a);
    cin >> b;
    s.insert(b);
    cin >> c;
    s.insert(c);
    if(s.size() == 2){
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
    return 0;
}


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

vector<vector<int>> S;
vector<int> s;
void subset(int i, int n, int m)
{
	if(s.size() == n)
	{
		S.push_back(s);
		return;
	}
	if(i > m) return;
	s.push_back(i);
	subset(i,n,m);
	s.pop_back();
	subset(i+1,n,m);
}


int main()
{
  	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
	int n, m, q;
	cin >> n >> m >> q;
	vector<int> a(q), b(q), c(q), d(q);
	for(int i=0; i<q; i++)
	{
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	subset(1,n,m);
	int score = INT_MIN;
	for(auto x : S)
	{
		int val = 0;
		for(int i=0; i<q; i++)
		{
			if(x[b[i]-1] - x[a[i]-1] == c[i]) val += d[i];
		}
		score = max(score,val);
	}
	cout << score << "\n";
		
	return 0;
}

Measured memory_bytes: 9780
#include<bits/stdc++.h>
int main()
{
    long long a,h,m,s,r;
    scanf("%lld",&a);
    h=a/3600;
    r=a%3600;
    m=r/60;
    s=r%60;
    printf("%lld:%lld:%lld\n",h,m,s);
    return 0;
}

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

#define LL long long
#define ls node << 1
#define rs node << 1 | 1

const int maxN = 1e5 + 100, mod = 1e9 + 7;

struct Node
{
	int sum;
	bool flag;
};

int n;
LL A, B, a[maxN + 1];

inline int ADD(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }

inline int SUB(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }

struct Seg
{
	Node tree[maxN * 4 + 1];

	void pushup(int node)
	{
		tree[node].sum = ADD(tree[ls].sum, tree[rs].sum);
	}

	void pushdown(int node)
	{
		if(!tree[node].flag) return;
		tree[ls].sum = tree[rs].sum = 0;
		tree[ls].flag = tree[rs].flag = true;
		tree[node].flag = false;
	}

	void change(int node, int l, int r, int x, int v)
	{
		if(l == r) { tree[node].sum = ADD(tree[node].sum, v); return; }
		pushdown(node);
		int mid = (l + r) >> 1;
		if(x <= mid) change(ls, l, mid, x, v);
		else change(rs, mid + 1, r, x, v);
		pushup(node);
	}

	int query(int node, int l, int r, int x, int y)
	{
		if(x <= l && r <= y) return tree[node].sum;
		pushdown(node);
		int mid = (l + r) >> 1, ans = 0;
		if(x <= mid) ans = ADD(ans, query(ls, l, mid, x, y));
		if(y > mid) ans = ADD(ans, query(rs, mid + 1, r, x, y));
		return ans;
	}

	void add(int x, int v) { change(1, 0, n, x, v); }

	void clear() { tree[1].flag = true; }

	int ask(int x) { return query(1, 0, n, 0, x); }
}F, G;

int main()
{
	scanf("%d %lld %lld", &n, &A, &B);
	a[0] = -3e18;
	for(int i = 1; i <= n; i++) scanf("%lld", &a[i]);

	F.add(0, 1); G.add(0, 1);
	for(int i = 1; i < n; i++)
	{
		int r1 = F.ask( upper_bound(a, a + n + 1, a[i + 1] - B) - a - 1 );
		int r2 = G.ask( upper_bound(a, a + n + 1, a[i + 1] - A) - a - 1 );
		if(a[i + 1] < a[i] + A) F.clear();
		if(a[i + 1] < a[i] + B) G.clear();
		F.add(i, r2); G.add(i, r1);
	}

	printf("%d\n", ADD(F.ask(n), G.ask(n)));
	return 0;
}


Measured memory_bytes: 8736
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

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


int main() {
	int x, y;
	cin >> x >> y;
	cout << x + y - gcd(x, y) + 1 << endl;
	
	return 0;
}

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

int main() {
	int n, a, b, ans=0, temp=0, idx;
	cin >> n >> a >> b;
	int dig=0;
	for (int i = 1; i <= n; i++) {
		idx = i;
		temp = 0;
		while (idx) {
			dig = idx % 10;
			temp = temp + dig;
			idx = idx / 10;
		}
		if (temp >= a&&temp <= b) {
			ans += i;
		}
	}
	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define eps 1e-9
#define oo 1e7+5

using namespace std;

typedef unsigned long long ull;
typedef vector<pair<int,pair<int,int>>> dirgraph;
typedef vector<vector<int>> graph;

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	int n,m,k;
	cin>>n>>m>>k;
	vector<int> a(n+1);
	vector<int> b(m+1);

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

	for(int i=1;i<m+1;i++){
		cin>>b[i];
		b[i]+=b[i-1];
	}

	int ans=0;

	for(int i=0;i<=n;i++){
		if(a[i]<=k){
			ans=max(ans,i);
			int l=0;
			int r=m+1;
			while(l+1<r){
				int mid=(l+r)>>1;
				if(b[mid]+a[i]<=k){
					ans=max(ans,i+mid);
					l=mid;
				}
				else r=mid;
			}
		}
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 6356
#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 all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int dist[216][216];
int main() {
	int N,M,R;
	cin>>N>>M>>R;
	vector<int> r(R);
	rep(i,R){
		cin>>r[i];
		r[i]--;
	}
	rep(i,N)rep(j,N)dist[i][j] = INF;
	rep(i,M){
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		dist[a][b] = dist[b][a] = c;
	}
	rep(k,N)rep(i,N)rep(j,N){
		dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
	}
	ll ans = INF;
	sort(all(r));
	do{
		ll tmp = 0;
		for (int i = 0; i < R-1; ++i){
			tmp += dist[r[i]][r[i+1]];
		}
		ans = min(ans, tmp);
		print(r);
	}while(next_permutation(all(r)));
	cout<<ans<<endl;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp11
{
    class Class19
    {
        static void Main()
        {
            string S = Console.ReadLine();
            List<int> Data = new List<int>();
            for(int i = 0; i < S.Length - 2; i++)
            {
                Data.Add(int.Parse(S.Substring(i,3)));

            }
            int R = Data.Min(x => Math.Abs(753 - x));
            Console.WriteLine(R);
        }
    }
}


Measured memory_bytes: 11348
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef vector<vector<int>> MX;

const ll MOD=1e9+7;
const int INF = 100000000;

int main()
{
	int N,X,Y;
	cin>>N>>X>>Y;

	vector<vector<int>>v(N);
	for(int i=0;i<N-1;i++)
	{
		v[i].push_back(i+1);
		v[i+1].push_back(i);
	}
	v[X-1].push_back(Y-1);
	v[Y-1].push_back(X-1);


	vector<int> R=vector<int>(N+1,0);
	for(int s=0;s<N;s++)
	{
		queue<int>Q;
		Q.push(s);
		vector<int>d(N,INF);d[s]=0;
		while(!Q.empty())
		{
			int p=Q.front();Q.pop();
			for(int j=0;j<v[p].size();j++)
			{
				if(d[v[p][j]]>d[p]+1)
				{
					d[v[p][j]]=d[p]+1;
					Q.push(v[p][j]);

				}
			}
		}
		for(int i=0;i<N;i++)
			if(d[i]!=INF)R[d[i]]++;
	}

	for(int i=1;i<N;i++)
		cout<<R[i]/2<<endl;
}


Measured memory_bytes: 3620
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools

def main():
    num = int(input())
    data = list(map(int, input().split()))
    data.sort()
    now_ele = data[0]
    for i in range(1, num):
        aaa = now_ele + data[i]
        now_ele = aaa / 2
    print(now_ele
          )




if __name__ == '__main__':
    main()



Measured memory_bytes: 38384
# -*- coding: utf-8 -*-

import sys
import math
import bisect

debug = False

def log(text):
    if debug:
        print(text)


def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
    
    (x, ) = [int(e) for e in lines[0].split(' ')]

    return (x, )


def solve(x):

    result = [0, 0]
    memo = dict()
    for a in range(-1000, 1001):
        if a in memo:
            aa = memo[a]
        else:
            aa = a**5
            memo[a] = aa

        for b in range(-1000, 1001):
            if b in memo:
                bb = memo[b]
            else:
                bb = b**5
                memo[b] = bb 

            if aa - bb == x:
                result = [a, b]

    return result

def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':
  
    main()


Measured memory_bytes: 68288
# -*- coding: utf-8 -*-
from sys import stdin
from decimal import *
import numpy as np
input = stdin.readline
N = int(input())
A = list(map(Decimal,input().split()))
np_A = np.array(A)
ans = np_A[0]

zero_flag = False
if 0 in A:
    zero_flag = True

flag = True

for i in range(1, N, 1):
    ans = Decimal(ans)*Decimal(np_A[i])
    #print(ans)
    if ans > 10**18:
        flag = False
        break


if zero_flag == True:
    print(0)


else:
    if flag == False:
        print(-1)

    else:
        print(ans)


Measured memory_bytes: 47624
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val b = List.fill(n - 1)(sc.nextInt)
    sc.close

    val ans = (1 until n - 1).foldLeft(b.head + b.last)((acc, cur) => {
      acc + Math.min(b(cur - 1), b(cur))
    })

    println(ans)
  }
}

Measured memory_bytes: 25688