akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	cin >> n;
	
	char s[n];
	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
	}
	
	int ans = 0;
	
	for (int i = 0; i < n; i++)
	{
		int temp = 0;
		for (int j = 0; j < 26; j++)
		{
			bool first = false;
			bool second = false;
			for (int k = 0; k <= i; k++)
			{
				if (s[k] == 'a' + j)
				{
					first = true;
					break;
				}
			}
			
			for (int m = i + 1; m < n; m++)
			{
				if (s[m] == 'a' + j)
				{
					second = true;
					break;
				}
			}
			
			if (first && second)
			{
				temp++;
			}
		}
		
		ans = max(ans, temp);
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
import bisect
INF=10**18
A,B,Q=map(int,input().split())
s=[int(input()) for i in range(A)]
t=[int(input()) for i in range(B)]
s=[-INF]+s+[INF]
t=[-INF]+t+[INF]
for q in range(Q):
    X=int(input())
    t1=bisect.bisect_right(t,X)
    s1=bisect.bisect_right(s,X)
    res=INF
    for T in [t[t1],t[t1-1]]:
        for S in [s[s1],s[s1-1]]:
            ans1=abs(X-T)+abs(S-T)
            ans2=abs(X-S)+abs(S-T)
            res=min(res,ans1,ans2)
    print(res)



Measured memory_bytes: 12800
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
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABeginner solver = new ABeginner();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABeginner {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int r = in.nextInt();
            if (n < 10) {
                out.println(r + (100 * (10 - n)));
            } else {
                out.println(r);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 21460
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long N = Integer.parseInt(sc.next());
		
		HashMap<String, Integer> map = new HashMap<>();
		long count = 0;
		for (int i = 0; i < N; i++) {
			char[] c = sc.next().toCharArray();
			Arrays.sort(c);
			String s = new String(c);
			Integer n;
			if (map.containsKey(s)) {
				n = map.get(s);
				map.put(s, n+1);
				count += n+1;
			}	
			else {
				map.put(s, 0);
			}	
		}
		
		System.out.println(count);
	}
}

Measured memory_bytes: 52340
#include<stdio.h>
#include<math.h>
int main(){
long long n,m,i,j,k,l,x,y,z,a,b,c,q;
double w;
x=0;y=0;z=0;
scanf("%lld",&q);
for(j=0;j<q;j++){
x=0;
scanf("%lld%lld",&a,&b);if(a>b){c=a;a=b;b=c;}
if(a==b){printf("%lld\n",2*a-2);}else{
y=a*b;
w=sqrt(y-1);
n=w/1;
if(n*n>y-1){n--;}
if(n*(n+1)<y){x++;}
printf("%lld\n",x+2*n-2);
}}
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n;
    cin >> n;
    string cad = to_string(n);
    int sum = 0;
    forn(i, sz(cad)) {
        sum += cad[i] - '0';
    }
    if (n % sum == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;

    vector<int> l(n), r(n);
    int ans = 0;
    for(int i = 0; i < n; i++){
        cin >> l[i] >> r[i];
        ans += r[i] - l[i] + 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def check(M_1, M_2):
    M_1 = int(M_1)
    M_2 = int(M_2)
    MM = M_1 * 10 + M_2
    if 1 <= MM <= 12:
        return True
    else:
        return False


S = input()
ans = [0, 0]
if check(S[0], S[1]):
    ans[0] += 1
if check(S[2], S[3]):
    ans[1] += 1

if ans == [0, 0]:
    print("NA")
elif ans == [0, 1]:
    print("YYMM")
elif ans == [1, 0]:
    print("MMYY")
elif ans == [1, 1]:
    print("AMBIGUOUS")


Measured memory_bytes: 3064
A, B, C, X = [int(input()) for _ in range(4)]
count = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500 * i + 100 * j + 50 * k == X:
                count += 1

print(count)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;
ll sum[100100];

int main() {
	while (cin >> n&&n) {
		fill(sum, sum + 100100, 0);
		REP(i, n) {
			char c;
			int h, m, s;
			cin >> h >> c >> m >> c >> s;
			sum[h * 60 * 60 + m * 60 + s]++;
			cin >> h >> c >> m >> c >> s;
			sum[h * 60 * 60 + m * 60 + s]--;
		}
		ll ans = 0;
		REP(i, 100100 - 1) {
			sum[i + 1] += sum[i];
			ans = max(ans, sum[i]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3904
#include <iostream>
#include <vector>

int main() {
    int N;
    int a = 0;

    std::cin >> N;

    std::vector<int> A(N);

    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
        if ( A[i] % 2 == 0) {
            if (A[i] % 3 != 0 && A[i] % 5 != 0)
                a = 1;
        }
    }

    if (a)
        std::cout << "DENIED" << std::endl;
    else
        std::cout << "APPROVED" << std::endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int t[n+1];
    for (int i = 1; i <= n; i++) {
        scanf("%d", &t[i]);
    }
    int m;
    scanf("%d", &m);
    int px[m+1][2];
    for (int i = 1; i <= m; i++) {
        scanf("%d %d", &px[i][0], &px[i][1]);
    }

    for (int i = 1; i <= m; i++) {
        int sc = 0;
        for (int j = 1; j <= n; j++) {
            sc += px[i][0] == j ? px[i][1] : t[j];
        }
        printf("%d\n", sc);
    }

    return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int,int>;
using PLL = pair<LL, LL>;
const int INF = 1e9;
const int MXN = 0;
const int MXV = 0;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for(int i = L; i != (int)R; ++i)
#define FORD(i, L, R) for(int i = L; i != (int)R; --i)
#define IOS cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false);

int main()
{
    IOS;
    int n, r;
    cin >> n >> r;
    if(n < 10)
    {
        cout << r + 100 * (10 - n) << '\n';
    }
    else
    {
        cout << r << '\n';
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>


#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define vint vector<int>
#define INF 1e9

using namespace std;
typedef long long  ll;

int main(){
    ll k, a, b;
    cin >> k >> a >> b;
    REP(i, a, b+1){
        if(i%k == 0){
            p("OK");
            return 0;
        }
    }

    p("NG");
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  int left = A + B,right = C + D;
  if(left > right){
    cout << "Left" << endl;
  }
  else if(left == right){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}


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

using P = pair<int, int>;

int H, W;
vector<vector<char>> maze;  // 迷路の内容を保存する配列

// dfs
int dx[4] = {1, -1, 0, 0};  // dx,dy は次の探索場所への距離を表す（４方向分）
int dy[4] = {0, 0, 1, -1};
bool solve(P p) {
    for (int i = 0; i < 4; i++) {
        int ny = p.first + dy[i];                              // 次の探索場所の行番号
        int nx = p.second + dx[i];                             // 次の探索場所の列番号
        if (ny < 0 || H <= ny || nx < 0 || W <= nx) continue;  // 迷路の外に出るならスルー
        if (maze[ny][nx] == '#') {
            return true;
        }
    }
    return false;
}

int main() {
    cin >> H >> W;

    maze.assign(H, vector<char>(W, '.'));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> maze[i][j];
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (maze[i][j] == '#' && !solve(P(i, j))) {
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << "Yes\n";

    return 0;
}


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

int main() {
    char c;
    cin >> c;

    if (c >= 'A' && c <= 'Z')
        cout << "A";
    else
        cout << "a";
    cout << endl;

    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;

// ------------------------------------------------
const int CAP = 1e5;
int ac[CAP + 100];
int cumSum[CAP + 100];
// ------------------------------------------------

int main(void) {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;

    for (int i = 0; i < n - 1; i++) {
        if (s[i] == 'A' && s[i + 1] == 'C') {
            ac[i]++;
            i++;
        }
    }

    int sum = 0;
    for (int i = 1; i <= n; i++) {
        sum += ac[i - 1];
        cumSum[i] = sum;
    }

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        cout << cumSum[r - 1] - cumSum[l - 1] << endl;
    }

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
#define endl '\n'
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	string s; cin>>s;
	int size = s.size();
	deque<char> dq(size);
	for(int i=0; i<size; i++){
		dq[i] = s[i];
	}	
	int c, n; cin>>c;
	bool change = false;
	while(c--){
		cin>>n;
		if(n==1){
			change = !change;
		}
		else{
			int ind; cin>>ind;
			char x; cin>>x;
			if(change)ind==1?ind++:ind--;
			if(ind == 1)dq.push_front(x);
			else dq.push_back(x);
		}
	}
	if(change){
		int tam = dq.size();
		for(int i=tam-1; i>=0; i--){
			cout<<dq[i];
		}
		cout<<endl;
	}
	else{
		for(auto&x: dq){
			cout<<x;
		}
		cout<<endl;
	}
}


Measured memory_bytes: 4012
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>

using namespace std;

deque<int> to_visit;
int t = 1;

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

  vector<bool> visited(n + 1, false);
  vector<int> dist(n + 1, -1);
  vector<vector<int>> V(n + 1);

  cin.ignore();

  for (string line; getline(cin, line);) {
    istringstream is{line};
    int id, n_nbrs, nbr;
    is >> id >> n_nbrs;
    vector<int> out_nbrs;
    while (is >> nbr)
      out_nbrs.push_back(nbr);
    V[id] = out_nbrs;
  }

  to_visit.push_back(1);
  dist[1] = 0;
  while (!to_visit.empty()) {
    if (visited[to_visit.front()]) {
      to_visit.pop_front();
      continue;
    }
    int curr = to_visit.front();
    to_visit.pop_front();
    visited[curr] = true;
    for (auto nbr : V[curr]) {
      if (dist[nbr] == -1)
        dist[nbr] = dist[curr] + 1;
      to_visit.push_back(nbr);
    }
  }

  for (int i = 1; i < V.size(); ++i) {
    cout << i << " " << dist[i] << endl;
  }
}


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

int main() {
  int n;
  cin >> n;
  vector<long> a(n+1, 0);
  long t;
  for (int i = 0; i < n; i++) {
    cin >> t;
    a[i+1] = a[i] + t;
  }
  sort(a.begin(), a.end());
  long r = 1;
  long cnt = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == a[i+1]) {
      r += 1;
    } else {
      cnt += r*(r-1)/2;
      r = 1;
    }
  }
  cnt += r*(r-1)/2;

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1792
N, A, B = map(int, input().split())
X = list(map(int, input().split()))
ans = 0
for x1, x2 in zip(X, X[1:]):
    if (x2 - x1) * A < B:
        ans += (x2 - x1) * A
    else:
        ans += B
print(ans)

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

int main() {
  string S;
  cin >> S;
  if (S == "Sunny") {
    cout << "Cloudy" << endl;
  }
  if (S == "Cloudy") {
    cout << "Rainy" << endl;
  }
  if (S == "Rainy") {
    cout << "Sunny" << endl;
  }
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	// ReadString returns a WORD string.
	ReadString func() string
)

func init() {
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
}

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt64() int64 {
	n, _ := strconv.ParseInt(ReadString(), 10, 64)
	return n
}

func readInt() int {
	return int(readInt64())
}

// 10 11 12 => [10, 11, 12]
func readIntSlice(size int) []int {
	a := make([]int, size)
	for i := 0; i < size; i++ {
		a[i] = readInt()
	}
	return a
}

func get2byte(size int) [][]byte {
	a := make([][]byte, size)
	for i := 0; i < size; i++ {
		var low string
		fmt.Scan(&low)
		a[i] = []byte(low)
	}
	return a
}

func transpose(a [][]int) {
	n := len(a)
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			a[i][j], a[j][i] = a[j][i], a[i][j]
		}
	}
}

func fact(n, m int) int {
	res := 1
	for i := m + 1; i <= n; i++ {
		res *= i
	}
	return res
}

func perm(n, r int) int {
	if r > n {
		return 0
	}
	return fact(n, n-r)
}

func comb(n, m int) int {
	if m > n {
		return 0
	}
	return fact(n, n-m) / fact(m, 0)
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

func main() {
	n, m, k := readInt(), readInt(), readInt()
	as := readIntSlice(n)
	bs := readIntSlice(m)
	var maxASum int
	var maxAIndex = -1
	var readACount int
	for i, a := range as {
		if maxASum+a <= k {
			maxASum += a
			maxAIndex = i
			readACount++
		} else {
			break
		}
	}
	rest := k - maxASum
	var maxBSum int
	var maxBIndex = -1
	var readBCount int
	for i, b := range bs {
		if maxBSum+b <= rest {
			maxBSum += b
			maxBIndex = i
			readBCount++
		} else {
			break
		}
	}
	rest = rest - maxBSum
	cur := readACount + readBCount
	result := cur
	aIndex := maxAIndex
	bIndex := maxBIndex
	for aIndex >= 0 && bIndex < m-1 {
		rest += as[aIndex]
		aIndex--
		cur--
		for bIndex < m-1 && rest >= bs[bIndex+1] {
			rest -= bs[bIndex+1]
			cur++
			bIndex++
		}
		if result < cur {
			result = cur
		}
	}
	fmt.Println(result)
}


Measured memory_bytes: 7820
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int[][][] dp = new int[21][11][156];
		dp[0][0][0] = 1;
		for (int n = 1; n <= 20; ++n) {
			for (int k = 0; k <= 10; ++k) {
				for (int s = 0; s <= 155; ++s) {
					dp[n][k][s] += dp[n - 1][k][s];
					if (k > 0 && s >= n) dp[n][k][s] += dp[n - 1][k - 1][s - n];
				}
			}
		}
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			int K = sc.nextInt();
			int S = sc.nextInt();
			System.out.println(dp[N][K][S]);
		}
	}

}

Measured memory_bytes: 20520
#include <iostream>
using namespace std;
int main() {
    long long i, o, t, j, l, s, z; cin >> i >> o >> t >> j >> l >> s >> z;
    long long ans = 0;
    ans += o;
    ans += 2 * (i/2 + j/2 + l/2);
    switch (i %2 + j % 2 + l % 2) {
    case 0:
    case 1: break;
    case 2: if (i > 0 && j > 0 && l > 0) ans += 1; break;
    case 3: ans += 3; break;
    }
    cout << ans << endl;
}


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

int main(){
    int x,y; cin >> x >> y;
    if(2*x == y){ cout << "Yes" << endl;
        return 0;
    }
    if(4*x == y){ cout << "Yes" << endl;
        return 0;
    }
    bool ans = false;
    for(int a=0;a<x;++a){
        for(int b=0;b<x;++b){
        if(a+b == x && 2*a + 4*b == y) {
        ans = true; 
        break;
        }
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

namespace kakomon
{
    class Program
    {
        static void Main(string[] args)
        {
            abc152_c();
        }

        static void abc152_c()
        {
            // C - Low Elements
            int n = int.Parse(Console.ReadLine());
            int[] P = Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
            // それまでの最小値以下なら+1、最小値を更新していく
            int ans = 0;
            int p_min = P[0];
            for (int i=0; i<n; i++)
            {
                if (P[i] <= p_min) ans += 1;
                p_min = Math.Min(P[i], p_min);
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 31964
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
#define fi first
#define se second
#define ls son[x][0]
#define rs son[x][1]
using namespace std;

const int N = 131075;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
ll n, dis[N], l = 0, r = 1ll * N * N, lim, ans;
int son[N][3], num[N];
vp f[N];

vp dp(vp a, vp b) {
    vp ret; ret.clear();
    int x = a.size(), y = b.size(), i = 0, j = 0;
    if (!y) return ret;
    while (i != x) {
        while (j != y && a[i].se + b[j].fi <= lim) ++j;
        if (j) --j;
        if (a[i].se + b[j].fi <= lim) ret.push_back(make_pair(a[i].fi, b[j].se));
        ++i;
    } return ret;
}

void insert(vp &a, pll b) {
    if (!a.size()) a.push_back(b);
    else if (a.back().fi == b.fi) a.back().se = min(a.back().se, b.se);
    else if (b.se < a.back().se) a.push_back(b);
}

vp merge(vp a, vp b) {
    vp ret; ret.clear();
    int x = a.size(), y = b.size(), i = 0, j = 0;
    while (i != x && j != y) {
        if (a[i].fi < b[j].fi) insert(ret, a[i++]);
        else insert(ret, b[j++]);
    }
    while (i != x) insert(ret, a[i++]);
    while (j != y) insert(ret, b[j++]);
    return ret;
}

void dfs(int x) {
    if (!num[x]) {
        f[x].clear();
        f[x].push_back(make_pair(dis[x], dis[x]));
        return;
    }
    dfs(ls), dfs(rs);
    lim += dis[x] * 2;
    vp t1 = dp(f[ls], f[rs]);
    vp t2 = dp(f[rs], f[ls]);
    f[x] = merge(t1, t2);
    lim -= dis[x] * 2;
}

bool chk() {
    dfs(1);
    if (f[1].size()) return 1;
    else return 0;
}

int main() {
    cin >> n;
    rep(i, 2, n) {
        int fa, v; scanf("%d%d", &fa, &v);
        dis[i] = dis[fa] + v;
        son[fa][num[fa]++] = i;
    }
    while (l <= r) {
        lim = (l + r) >> 1;
        if (chk()) ans = lim, r = lim - 1;
        else l = lim + 1;
    }
    printf("%lld\n", ans);
    return 0;
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int N, M;
    cin >> N >> M;

    vi a(M);
    for (int i = 0; i < M; i++) {
        cin >> a[i];
    }

    if (sz(a) == 1) {
        cout << a[0] << "\n";

        if (a[0] > 1) {
            cout << "2\n" << a[0] - 1 << " 1\n";
        } else {
            cout << "1\n1\n";
        }
        return 0;
    }

    sort(all(a), [](int i, int j) {
        return (i&1) < (j&1);
    });

    if (sz(a) > 2 && (a[M - 3]&1)) {
        cout << "Impossible\n";
        return 0;
    }

    if (a.back()&1) {
        a.insert(a.begin(), a.back());
        a.pop_back();
    }

    for (int i = 0; i < M; i++) {
        if (i) cout << " ";
        cout << a[i];
    }
    cout << endl;

    vi b;
    if (a[0] > 1) b.push_back(a[0] - 1);
    for (int i = 1; i + 1 < M; i++)
        b.push_back(a[i]);
    b.push_back(a[M - 1] + 1);

    cout << sz(b) << "\n";
    for (int i = 0; i < sz(b); i++) {
        if (i) cout << " ";
        cout << b[i];
    }
    cout << "\n";

    return 0;
}



Measured memory_bytes: 256
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

w = int(arr_data[0][0])
a = int(arr_data[0][1])
b = int(arr_data[0][2])

#print(w,a,b)

#print(b-a-w if a<=b else a-b-w)


if abs(b-a)-w<=0 :
    
    print(0)

elif abs(b-a)-w>0:
    
    print(abs(b-a)-w)
    

Measured memory_bytes: 3064
#include <stdio.h>
typedef long long ll;
ll mod=1000000007;

ll powmod(ll x,ll y){
  ll res=1;
  for(ll i=0;i<y;i++){
    res=res*x%mod;
  }
  return res;

}


int main(void){
  ll n;
  scanf("%lld",&n);
  ll ans=powmod(10,n)-powmod(9,n)-powmod(9,n)+powmod(8,n);
  ans%=mod;
  ans=(ans+mod)%mod;
  printf("%lld\n",ans);
  return 0;
}


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

#define int long long
#define INF 1e18

int const mod = 1e9+7;

vector<int> Graph[100009];

int memo[100009][2];

int dp(int a, int c, int last){
    if(memo[a][c] != -1) return memo[a][c];
    memo[a][c] = 1;
    if(c == 1){
        //BLACK
        memo[a][c] = 1;
        for(int b : Graph[a]){
            if(b == last) continue;
            memo[a][c] *= dp(b,0,a);
            memo[a][c] %= mod;
        }
    }else{
        for(int b : Graph[a]){
            if(b == last) continue;
            int t = 0;
            t += dp(b,0,a);
            t %= mod;
            t += dp(b,1,a);
            t %= mod;
            memo[a][c] *= t;
            memo[a][c] %= mod;
        }
    }
    return memo[a][c];
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n-1; i++){
        int a, b;
        cin >> a >> b;
        Graph[a].push_back(b);
        Graph[b].push_back(a);
    }
    for(int i = 0; i < 100009; i++){
        for(int j = 0; j < 2; j++){
            memo[i][j] = -1;
        }
    }
    cout << (dp(1,1,-1)+dp(1,0,-1))%mod << endl;
}


Measured memory_bytes: 15616
#pragma GCC optimize ("O2") // "Ofast" for REAL FAST
// #pragma GCC optimization ("unroll-loops")

// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"

#include <bits/stdc++.h>
#define DEBUG 1

using namespace std;

#define rep(i, a, b) for (i = (a); i < (b); i++)
#define trav(a, x) for (auto & a : x)
#define all(x) (x).begin (), (x).end ()
#define rall(x) (x).rbegin (), (x).rend ()
#define sz(x) (int) (x).size ()
#define FASTIO cin.sync_with_stdio (0); cin.tie (0); cin.exceptions (cin.failbit);

typedef long long ll;

typedef pair <int, int> pii;
#define f first
#define s second
#define mp(x, y) make_pair (x, y)

typedef vector <int> vi;
#define pb(x) push_back (x)

#define ddcout if (DEBUG) cout
#define ddprintf(fmt, ...) if (DEBUG) printf (fmt, ##__VA_ARGS__)

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x3f3f3f3f3f3f3f3f;
const int  INFi  =  0x3f3f3f3f;
const ll   MAXN  =  1e+6+7; // UPDATE

int main ()
{
    ll i, j, a, b, k;
    cin >> a >> b >> k;
    cout << max (0LL, a - k) << " " << max (0LL, b - max (0LL, k - a)) << "\n";

    return 0;
}


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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
    ll S;
    cin >> S;
    if (S < 3) {
      cout << 0 << endl;
      return 0;
    }
    ll boxes = S / 3;
    mint ans = mint(0);
    combination nCr = combination(S);
    for (ll i = 2; i <= boxes; i++) {
      ll ball = S - i * 3;
      ans = ans + nCr(ball + i - 1, ball);
    }

    ans = ans + 1;

    cout << ans.x << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
static const int N = 100;

int main(){
   int n, p[N+1], m[N+1][N+1];
   cin >> n;
   for (int i=1; i<= n; i++){
       cin >> p[i-1] >> p[i];
   }
   
   for(int i=1; i<=n; i++) m[i][i]=0;
   for(int l =2; l <= n; l++){
       for (int i=1; i <= n-l+1; i++ ){
           int j =i+l -1;
           m[i][j] = (1 <<21);
           for (int k =i; k <= j-1; k++ ){
               m[i][j] = min(m[i][j], m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
           }
       }
   }
   cout << m[1][n] << endl;
   return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define pb push_back
#define all(v) v.begin(),v.end()
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
const ll mod = 1e9 + 7;
const int mx = 2e5 + 5;

ll dp[3005];
pii O[3005];
ll fc[mx] = {1}, iv[mx], ic[mx] = {1};
int h, w, n;

void build(){
    for(int i = 1; i < mx; i++){
        fc[i] = fc[i-1] * i % mod;
        if(i > 1) iv[i] = (mod - mod / i) * iv[mod % i] % mod;
        else iv[i] = 1;
        ic[i] = ic[i-1] * iv[i] % mod;
    }
}

ll nCr(int n, int k){
    if(n < 0 || k < 0 || n < k) return 0;
    return fc[n] * ic[k] % mod * ic[n-k] % mod;
}

int main(){
    fio;
    build();
    cin >> h >> w >> n;
    --h; --w;
    for(int i = 0; i < n; i++){
        cin >> O[i].va >> O[i].vb;
        --O[i].va; --O[i].vb;
        O[i].va += O[i].vb;
    }
    sort(O, O+n);
    ll ans = nCr(h+w,w);
    for(int i = 0; i < n; i++){
        dp[i] = nCr(O[i].va, O[i].vb);
        for(int j = 0; j < i; j++){
            dp[i] += mod - dp[j] * nCr(O[i].va - O[j].va, O[i].vb - O[j].vb) % mod;
            dp[i] %= mod;
        }
        ans += mod - dp[i] * nCr(h+w - O[i].va, w - O[i].vb) % mod;
        ans %= mod;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 4992
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int[] N = new int[5];
		for(int i=0;i<5;i++) {
			N[i] = scan.nextInt();
			if(N[i]==0) {
				System.out.println(i+1);
			}
		}
		scan.close();
	}

}

Measured memory_bytes: 35740
#include <bits/stdc++.h>
#define int long long
#define MAX_V 1000
#define N MAX_V
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}

/*?????§?????¢?????´?????????(Ford_Fulerson????????¨)???O(F|E|)*/

//????????¨????§???????(???????????????????????????)
struct edge{int to, cap, rev;};

vector<edge> G[MAX_V]; //??°???????????£??\?????????
bool used[MAX_V];      //DFS??§?????§??????????????????????????°

//from??????to??????????????????cap???????????°?????????????????????
void add_edge(int from,int to,int cap=1){
  G[from].push_back((edge){to,cap,(int)G[to].size()});
  G[to].push_back((edge){from,0,(int)G[from].size()-1});  
}

//?¢?????????????DFS??§??¢???
int dfs(int v,int t,int f){
  if(v == t)return f;
  used[v]=true;
  for(int i=0; i<G[v].size() ;i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      int d = dfs(e.to ,t , min(f,e.cap));
      if(d > 0){
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

//s??????t???????????§???????±???????
int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    memset(used,0,sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0)return flow;
    flow += f;
  }
}

signed main(){

  int cnt = 0;

  while(1){
    cnt ++;
    int H, W, C, M, N_W, N_C, N_M;
    cin >>H>>W>>C>>M>>N_W>> N_C>>N_M;
    if(H==-1) return 0;
    for(int i=0;i<N;i++)G[i].clear();
    
    const int S = N-1, T = S-1;
    const int NW = H+W+C+M, NC = NW+1, NM = NC+1;
    const int of = 500; //ofset
    
    add_edge(NW,of+NW,N_W);
    add_edge(NC,of+NC,N_C);
    add_edge(NM,of+NM,N_M);
    for(int i=0;i<H;i++) add_edge(i,of+i); //hero
    for(int i=0;i<W;i++) add_edge(H+i,of+H+i); // warriror
    for(int i=0;i<C;i++) add_edge(H+W+i,of+H+W+i); // Cleric
    for(int i=0;i<M;i++) add_edge(H+W+C+i,of+H+W+C+i); //Mage
  
    
    for(int i=0;i<H;i++) add_edge(S,i); // S -> Hero

    
    for(int i=0;i<H;i++) add_edge(of+i,NW); // Hero -> no warrior
    for(int i=0,k;i<W;i++){
      cin>>k;
      for(int j=0,a;j<k;j++) {
        cin>>a; a--;
        add_edge(of+a,H+i); // hero -> warrior
      }
    }

    
    for(int i=0;i<W;i++) add_edge(of+H+i,NC); // warrior -> no cleric
    for(int i=0;i<C;i++) add_edge(of+NW,H+W+i); // no warrior -> cleric
    for(int i=0,k;i<C;i++){
      cin>>k;
      for(int j=0,a;j<k;j++){
        cin>>a,a--;
        add_edge(of+H+a,H+W+i); // warrior -> cleric 
      }
    }

    
    for(int i=0;i<C;i++) add_edge(of+H+W+i,NM); // cleric -> no mage
    for(int i=0;i<M;i++) add_edge(of+NC,H+W+C+i); // no cleric -> mage   
    for(int i=0,k;i<M;i++){
      cin>>k;
      for(int j=0,a;j<k;j++){
        cin>>a;a--;
        add_edge(of+H+W+a,H+W+C+i); // cleric -> mage
      }
    }

    add_edge(of+NM,T,N_M);//no mage -> T 
    for(int i=0;i<M;i++) add_edge(of+H+W+C+i,T); // mage -> T
    cout<<max_flow(S,T)<<endl;
  }

  return 0;
}

Measured memory_bytes: 3556
import itertools

N = input()

A = []
nums = [3,5,7]
con = 0

for i in range(3,len(N) + 1):
  A += list(itertools.product(nums,repeat = i))

L = []

for i in range(0,len(A)):
  a = set(list(A[i]))
  if len(a) == 3:
    L.append(A[i])

Slist = []
    
for i in range(0,len(L)):
  S = ""
  for j in range(0,len(L[i])):
    S += str(L[i][j])
  S = int(S)
  Slist.append(S)

print(len([c for c in Slist if c <= int(N)]))

Measured memory_bytes: 8408
#include <bits/stdc++.h>
using namespace std;
int const MN = 100000;
int const INF = 1e9+7;

int dp[MN+1];
vector<int> a;

/*int main(){
    int n;
    cin >> n;

    a.resize(n);
    for(auto &t: a){
        cin >> t;
    }

    fill(dp,dp+MN+1,1);

    int res=0;
    for(int i=0;i<n;i++){
        for(int j=i-1;j>=0;j--){
            if(a[i] > a[j]){
                dp[i] = max(dp[i],dp[j]+1);
            }
        }
        res = max(dp[i],res);
    }

    cout << res << endl;
}*/

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

    a.resize(n);
    for(auto &t: a){
        cin >> t;
    }

    fill(dp,dp+n,INF);

    for(int i=0; i<n; i++){
        *lower_bound(dp,dp+n,a[i]) = a[i];
    }

    cout << lower_bound(dp,dp+n,INF) - dp << endl;
}

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

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

    if((a+b)==c)
        cout << "Yes";
    else if((b+c)==a)
        cout << "Yes";
    else if((c+a)==b)
        cout << "Yes";
    else cout << "No";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n, ans = 0, a = 0, b = 0, c = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        int len;
        string s;
        cin >> s;
        len = s.length();
        for(int j=0;j<len-1;j++){
            if(s.substr(j, 2) == "AB"){
                ans++;
                j++;
            }
        }
        
        
        if(s[0] == 'B' && s[len-1] == 'A')c++;
        else if(s[0] == 'B')b++;
        else if(s[len-1] == 'A')a++;
    }
    //cout << ans << endl;
    if(c > 0){
        ans += c-1;
        c = 0;
        if(a > 0){
            ans++;
            a--;
        }
        if(b > 0){
            ans++;
            b--;
        }
    }
    ans += min(a, b);
    cout << ans << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

const int N = 50 + 1;
vector<int> g[N];

void solve(){
  int n, m;
  cin >> n >> m;
  for(int i = 0; i < m; i++){
	  int x, y;
	  cin >> x >> y;
	  x--, y--;
	  g[x].push_back(y);
	  g[y].push_back(x);  
	} 
  for(int i = 0; i < n; i++){
	  cout << (int)g[i].size()<< endl;  
	}
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int A,B;

	scanf("%d %d",&A,&B);

	for(int i = 9*B; i <= 3000; i++){

		if((8*i)/100 == A && (10*i)/100 == B){

			printf("%d\n",i);
			return 0;
		}
	}

	printf("-1\n");

	return 0;
}


Measured memory_bytes: 256
//  __      __       .__           .____________                   __________        __ ________   __                 
// /  \    /  \ ____ |_________  __| _\______   \__ __  ____  _____\______   \__ ___/  |\_____  \ |  | ______  ___.__.
// \   \/\/   _/ __ \|  \_  __ \/ __ | |    |  _|  |  \/ ___\/  ___/|    |  _|  |  \   __/   |   \|  |/ \__  \<   |  |
//  \        /\  ___/|  ||  | \/ /_/ | |    |   |  |  / /_/  \___ \ |    |   |  |  /|  |/    |    |    < / __ \\___  |
//   \__/\  /  \___  |__||__|  \____ | |______  |____/\___  /____  >|______  |____/ |__|\_______  |__|_ (____  / ____|
//        \/       \/               \/        \/     /_____/     \/        \/                   \/     \/    \/\/     

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ff first
#define ss second
#define PI 3.14159265358979323846
#define endl '\n'

using namespace std;

void solve()
{
    int h, w;
    cin >> h >> w;
    string s[h];
    for(int i = 0; i < h; i++)
        cin >> s[i];
    auto ok = [&](int x, int y)
    {
        if(x < 0 || x >= h)
            return false;
        if(y < 0 || y >= w)
            return false;
        if(s[x][y] == '#')
            return false;
        return true;
    };
    int ans = 0;
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
        {
            if(s[i][j] == '#')
                continue;
            queue <pair <int, int> > bfs;
            bfs.push({i, j});
            int dis[h][w];
            for(int x = 0; x < h; x++)
                for(int y = 0; y < w; y++)
                    dis[x][y] = 1e9;
            dis[i][j] = 0;
            while(!bfs.empty())
            {
                auto x = bfs.front();
                bfs.pop();
                int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
                for(int l = 0; l < 4; l++)
                    if(ok(x.ff + dx[l], x.ss + dy[l]))
                    {
                        if(dis[x.ff + dx[l]][x.ss + dy[l]] > dis[x.ff][x.ss] + 1)
                        {
                            dis[x.ff + dx[l]][x.ss + dy[l]] = dis[x.ff][x.ss] + 1;
                            bfs.push({x.ff + dx[l], x.ss + dy[l]});
                        }
                    }
            }
            for(int k = 0; k < h; k++)
                for(int l = 0; l < w; l++)
                    if(dis[k][l] != 1e9)
                        ans = max(ans, dis[k][l]);
        }
    cout << ans << endl;
}

int main()
{
	int q = 1;
	//scanf("%d", &q);
	for(int i = 1; i <= q; i++)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]

def divisors(N: int) -> set:
    """ 約数の列挙・個数 """
    from math import sqrt

    # 1とその数はデフォで入れとく
    s = {1, N}
    # 終点はルート切り捨て
    for i in range(2, int(sqrt(N))+1):
        # 割り切れるなら、iとN/iを追加
        if N % i == 0:
            s.add(i)
            s.add(N // i)
    return s

N = INT()

ans = 10 ** 18
for div in divisors(N):
    ans = min(ans, div+N//div-2)
print(ans)


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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


int main() {
	int n, i, j;
	cin >> n;
	vi p(n);
	for (i = 0; i < n; i++) {
		cin >> p[i];
		p[i]--;
	}

	vl a(n), b(n);
	a[0] = 25000;
	b[0] = 1000000000 - 25000;
	for (i = 1; i < n; i++) {
		a[i] = a[i - 1] + 50000;
		b[i] = b[i - 1] - 50000;
	}
	int diff = -24999;
	for (i = 0; i < n; i++) {
		a[p[i]] += diff;
		b[p[i]] += diff;
		diff += 2;
	}
	for (i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
	for (i = 0; i < n; i++) {
		cout << b[i] << " ";
	}
	cout << endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

ll ans = 10000000000000;

void enum_div(ll n){
	vll ret;
	for(ll i=1 ; i*i<=n ; ++i){
		if(n%i == 0){
            ans = min(ans, (ll)max(log10(i) + 1, log10(n/i) + 1));
		}
	}
}

int main(){
    ll N;
    cin >> N;
    enum_div(N);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int, custom_hash>
#define usl unordered_set<long long int, custom_hash>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int, custom_hash>
#define uml unordered_map<long long int, long long int, custom_hash>
#define ski stack<int>
#define skl stack<long long int>
#define all(v) v.begin(),v.end()
using namespace std;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c`
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};


const int N=1e5+1;
const int mod=998244353;
ll a[N], b[N], c[N];

ll dp[101][N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif
    
    int n, w;
    cin>>n>>w;
    for(int i=1;i<=n;++i){
        ll x, y;   cin>>x>>y;
        for(int j=0;j<=w;++j){

            dp[i][j]=max(dp[i][j], dp[i-1][j]);
            if(j>=x){
                dp[i][j]=max(dp[i][j], y+dp[i-1][j-x]);
            }
            // cout<<dp[i][j]<<' ';
        }
        // cout<<endl;
    }

    cout<<dp[n][w]<<endl;

}

Measured memory_bytes: 79360
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<long long int> CS(N+1, 0);
    for(int n=0; n<N; n++) {
        long long int a;
        cin >> a;
        CS[n+1] = a + CS[n];
    }
    
    long long int ans=1e9*3;
    for(int n=0; n<N-1; n++) {
        ans = min(ans, abs(CS[N]-2*CS[n+1]));
    }
    
    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 1792
import warnings

data = map(float, raw_input().split())

w = data[0]
h = data[1]
x = data[2]
y = data[3]
r = data[4]

if (x >= r and x <= (w - r) and y >= r and y <= (h - r)):
	print "Yes"
else:
	print "No"

Measured memory_bytes: 4220
import sys
input = sys.stdin.readline

n,m=map(int, input().split())

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

uf1=UnionFind(n)
ans=[]
for i in range(m):
    a,b=map(int, input().split()) #a,b:つながっている辺
    uf1.union(a-1,b-1)

for i in range(n):
    ans.append(uf1.find(i))
from collections import Counter
c=Counter(ans)
print(max(c.values()))

Measured memory_bytes: 115500
#! /usr/bin/env python3

import sys
from math import gcd
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, *A = map(int, read().split())
A = sorted(A)
M = pow(10, 6) + 1
divs = [False] * M
cnt = 0
for i, a in enumerate(A):
    if divs[a]:
        continue

    if i == N - 1 or a != A[i + 1]:
        cnt += 1

    acc = a
    while acc < M:
        divs[acc] = True
        acc += a
print(cnt)


Measured memory_bytes: 30488
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (k, x) = listOfInt()
    var start = x - k + 1
    if (start < -1000000) start = -1000000
    var end = x + k - 1
    if (end > 1000000) end = 1000000

    var answer = ""
    for (pos in start..end) {
        answer += ("$pos ")
    }

    println(answer)
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 37900