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

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n,x;
    cin>>n>>x;

    ll a[n],d[n];

    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(ll i=0;i<n;i++){
        // if(x>=a[i]){
        //     d[i] = a[i];
        //     x-=a[i];
        // }else {
        //     d[i] = x;
        //     x-=a[i];
        // }

        d[i] = min(a[i],x);
        x-=min(a[i],x);
    }
    ll cnt = 0;
    for(ll i=0;i<n;i++){
        if(a[i] == d[i]){
            cnt++;
        }
    }
    if(x > 0 && cnt){
        cnt--;
    }
    cout<<cnt<<endl;

}

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

int main() {
  int n;
  cin >> n;
  int p[n];
  for (int i = 0; i < n; ++i) cin >> p[i];
  int m = p[0], ans = 0;
  for (int i = 0; i < n; ++i) {
    if (p[i] <= m) {
      ++ans;
      m = p[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int t=1;
	char c;
	bool f=true;
	while(1){
		c=getchar();
		if(c=='\n')break;
		if((c=='R'||c=='U'||c=='D')&&t%2);
		else if((c=='L'||c=='U'||c=='D')&&t%2==0);
		else f=false;
		t++;
	}
	printf("%s\n",(f)?"Yes":"No");
}

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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  ll N;
  std::cin >> N;

  ll ans = 0;
  for(ll K = 1; K <= N; ++K) {
    ans += K * (N / K) * (N / K + 1) / 2;
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 3604
n,k = map(int, input().split())
sunuke = []

for i in range(n):
    sunuke.append(1)

for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    for j in range(d):
        sunuke[a[j]-1] = 0

print(sum(sunuke))

Measured memory_bytes: 9016
S = input()

len_s = len(S)
key_s = "keyence"
len_key_s = len(key_s)

def main(S, key_s):
    if len_s >= len_key_s:
        ok =True
        for char_i in range(len_key_s):
            if key_s[char_i] != S[char_i]:
                first_diff_i = char_i
                ok = False
                break

        if ok: # keyence + "abdedd"
            #print("YES")
            return True
        else:
            end_diff_i = None
            for rev_char_i in range(len_key_s):
                char_i = - rev_char_i - 1
                
                if key_s[char_i] != S[char_i]:
                    end_diff_i = char_i
                    break

            if end_diff_i is None:
                end_diff_i = - len_key_s - 1

            mod_S = S[:first_diff_i] + S[end_diff_i+1:]

            if mod_S == key_s:
                #print("YES")
                return True
            else:
                #print("NO")
                #mod_S = S[:first_diff_i] + S[end_diff_i+1:]
                last_char = mod_S[0]
                mod_S2 = last_char
                for char in mod_S[1:]:
                    if last_char != char:
                        mod_S2 += char
                    last_char = char
                
                if mod_S2 == key_s:
                    return True

                return False
    else:
        #print("NO")
        return False

res1 = main(S, key_s)
#res2 = main(S[::-1], key_s[::-1])

#res = res1 and  res2
res = res1

out = "YES" if res else "NO"
print(out)

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

const long long INF = 1e18;

int main() {
    int n, m, p;
    cin >> n >> m >> p;
    vector<int> a(m), b(m), c(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i] >> c[i];
        c[i] -= p;
        c[i] *= -1;
    }

    vector<long long> dist(n+1);
    dist[1] = 0;
    for (int i = 2; i < n + 1; i++) {
        dist[i] = INF;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            // cout << b[j] << " is " << dist[b[j]] << endl;
            if (dist[a[j]] != INF && dist[a[j]] + c[j] < dist[b[j]]) {
                dist[b[j]] = dist[a[j]] + c[j];
                // cout << b[j] << " is " << dist[b[j]] << endl;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (dist[a[j]] != INF && dist[a[j]] + c[j] < dist[b[j]]) {
                dist[b[j]] = -INF;
            }
        }
    }
    if (dist[n] == -INF) {
        cout << -1 << endl;
    } else {
        cout << max(0LL, -1 * dist[n]) << endl;
    }
    return 0;
}


Measured memory_bytes: 384
/*
 * main.c
 *
 *  Created on: 2013/05/25
 *      Author: freude
 */

/* test program */

#include <stdio.h>

int main()
{
    char a[65535];
    int i,t;

    for(i=0;;i++){
                if(scanf("%c",a+i)==EOF){
                      t=i;break;
                }
        }
    for(i=0;i<t;i++){
        if(a[i]>96&&a[i]<123){
            a[i]-=32;
        }
    }
    printf(a);
    return 0;
}

Measured memory_bytes: 536
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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


    int N;  cin >> N;
    vi T(N); REP(i, N) cin >> T[i];
    vd V(N); REP(i, N) cin >> V[i];

    int TSum = 0;
    REP(i, N) TSum += T[i];
    TSum *= 2;

    vd vMax(TSum+MGN,0);
    vMax[0] = 0; // Begin
    vMax[TSum] = 0; // End
    for(int t=1; t<TSum; t++) {
        vMax[t] = LINF;
    }

    int now = 0;
    REP(i,N) {
        int next = now + T[i] * 2;
        for (int t = now; t <= next; t++) {
            vMax[t] = min(vMax[t], V[i]);
        }
        now = next;
    }

    for (int t = 1; t <= TSum; t++) {
        vMax[t] = min(vMax[t - 1] + 0.5, vMax[t]);
    }
    for(int t = TSum-1; t >= 0; t--) {
        vMax[t] = min(vMax[t + 1] + 0.5, vMax[t]);
    }

    double ans = 0;
    for(int t=0; t<TSum; t++) {
        ans += 0.5 * (vMax[t] + vMax[t + 1]) / 2; // Trapezoid
    }

    cout << fixed << setprecision(15) << ans << endl;


    return 0;
}

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

using namespace std;

int ans = 0;
int n;

bool is357(long long n)
{
	bool three, five, seven;
	three = five = seven = false;

	string s = to_string(n);
	for (int i = 0; (size_t) i < s.size(); i++) {
		if (s[i] == '3') {
			three = true;
		} else if (s[i] == '5') {
			five = true;
		} else if (s[i] == '7') {
			seven = true;
		}
	}

	return three && five && seven;
}

void search(long long head)
{
	if (head <= n) {
		if (is357(head)) {
			ans++;
		}
		search(head * 10 + 3);
		search(head * 10 + 5);
		search(head * 10 + 7);
	}
}

int main()
{
	cin >> n;

	search(0);

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


Measured memory_bytes: 256
local n, m, q = io.read("*n", "*n", "*n")

local t = {}
for i = 1, n * n do t[i] = 0 end

for i = 1, m do
  local l, r = io.read("*n", "*n")
  local idx = (r - 1) * n + l
  t[idx] = t[idx] + 1
end

for l = 1, n do
  for r = 2, n do
    local src = (r - 2) * n + l
    local dst = (r - 1) * n + l
    t[dst] = t[dst] + t[src]
  end
end
for r = 1, n do
  for l = n - 1, 1, -1 do
    local src = (r - 1) * n + l + 1
    local dst = (r - 1) * n + l
    t[dst] = t[dst] + t[src]
  end
end

for i = 1, q do
  local a, b = io.read("*n", "*n")
  local idx = (b - 1) * n + a
  print(t[idx])
end


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
typedef long long int64;
int main() {
#ifdef LOCAL
  freopen(".a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);
  int n;
  cin >> n;
  vector<int> A(n), B(n);
  for (int i = 0; i < n; ++i) cin >> A[i] >> B[i];
  for (int i = 0; i + 3 <= n; ++i) {
    if (A[i] == B[i] && A[i + 1] == B[i + 1] && A[i + 2] == B[i + 2]) {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";

  return 0;
}
//2020.09.19 20:02:35


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

void solve() {
	int h1,m1,h2,m2,k,mins;
	
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	
	mins = (h2-h1)*60 + (m2-m1);
	
	cout << mins-k << endl;
	
	
	

}
		
			
		

int32_t main() {
	IOS;
	solve();
	return 0;
}


Measured memory_bytes: 3608
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=x && x<w && 0<=y && y<h)

const int INF = 10000000;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
using namespace std;
typedef long long  ll;
typedef pair<int, int> P;
const int MAX = 2*123500;


/** Problem1174 : Identically Colored Panels Connection **/
typedef struct {
	int field[8][8];
	bool area[8][8];
	int cost;
} S;

int w, h;
void bond(int f[8][8], bool b[8][8])
{
	bool vis[8][8];
	queue<P> Q;
	fill(vis[0], vis[0]+8*8, false);
	Q.push(P(0, 0));
	
	while (Q.size()) {
		P p = Q.front(); Q.pop();
		if (vis[p.first][p.second]) continue;
		else vis[p.first][p.second]=true;
		
		rep(i, 4) {
			int nx=p.first+dx[i], ny=p.second+dy[i];
			if_range(nx, ny, w, h) {
				if (f[nx][ny] == f[p.first][p.second]) {
					b[nx][ny] = true;
					Q.push(P(nx, ny));
				}
			}
		}
	}
}

int main()
{
	int c;
	
	while (cin>>h>>w>>c, h||w||c) {
		c--;
		
		queue<S> Q;
		S first;
		int ans=0;
		

		rep(y, h) rep(x, w) {
			cin >> first.field[x][y];
			first.field[x][y]--;
			first.area[x][y]=false;
		}
		
		first.area[0][0]=true;
		bond(first.field, first.area);
		
		rep(y, h) rep(x, w) {
			rep(i, 4) {
				int nx=x+dx[i], ny=y+dy[i];
				if (0<=nx&&nx<w&&0<=ny&&ny<h&&first.area[x][y]&&first.field[0][0]==first.field[nx][ny])
					first.area[nx][ny]=true;
			}
		}
		
		first.cost = 0;
		Q.push(first);
		
		while (Q.size()) {
			S s = Q.front();
			
			if (s.cost==5 && s.field[0][0]==c) {
				int cnt=0;
				rep(y, h){
					rep(x, w) {
						if (s.area[x][y])
							cnt++;
					}
				}
				ans = max(ans, cnt);
				Q.pop(); continue;
			} else if (s.cost>5) {
				Q.pop(); continue;
			}
			
			rep(i, 6) {
				if (s.field[0][0]==i) continue;
				rep(y, h) rep(x, w) {
					if (s.area[x][y])
						s.field[x][y] = i;
				}
				bond(s.field, s.area);
				s.cost++;
				Q.push(s);
				s = Q.front();
			}
			Q.pop();
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 5568
#include<stdio.h>
main()
{
    char s[4];
    gets(s);
    int i,j=0;
    for(i=0;s[i]!='\0';i++){
        if(s[i]=='R'){
            j++;
        }
        if(s[0]=='R'&&s[1]=='S'||s[1]=='S'&&s[2]=='R'){
            j=1;
            break;
        }
    }
    printf("%d\n",j);
}


Measured memory_bytes: 1632
import string
import sys
import math

#??????????????\????????????ip?????\??????
ip = sys.stdin.readlines()
ip_list = {}
for i in range(len(ip)):
    ip_list[i] = ip[i].strip("\n").split()

for i in range(len(ip)):
    ans = int(ip_list[i][0]) + int(ip_list[i][1])
    print( int(math.log10(ans)+1) )

Measured memory_bytes: 8356
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var n int
	fmt.Fscan(read, &n)

	a := make([]int, n)
	b := make([]int, n)
	for i := range a {
		fmt.Fscan(read, &a[i])
	}
	for i := range b {
		fmt.Fscan(read, &b[i])
	}

	ans := 0
	for i := range a {
		if a[i]-b[i] > 0 {
			ans += a[i] - b[i]
		}
	}
	fmt.Fprintln(write, ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
ll n;
ll a[200005];
ll solve(ll x)
{
        ll ret = 0;
        for(ll i=1;i<=n;i++) {
                ret += abs(x - a[i]);
        }
        return ret;
}
int main()
{
        cin >> n;
        for(ll i=1;i<=n;i++) {
                cin >> a[i];
                a[i] -= i;
        }
        if(n==1){
                cout << 0 << endl; return 0;
        }
        sort(a+1  , a+n+1);
        ll ans = solve(a[n/2]);
        ans = min(ans , solve(a[(n/2) + 1]));
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 1792
a, b, c, x, y = map(int,input().split())
 
if a+b <= c * 2:
    print(x*a + y*b)
    exit()
    
ans = 0
 
ans += min(x,y) * c * 2
 
if x >= y:
    ans += min((x-y)*a, (x-y)*2*c)
else:
    ans += min((y-x)*b, (y-x)*2*c)
    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    int t;
    cin >> t;
    a[i] = (a[i - 1] + t) % m;
  }
  sort(a.begin(), a.end());
  long long ret = 0;
  int tmp = 0;
  int crr = -1;
  for (int i = 0; i <= n; i++) {
    if (crr != a[i]) {
      ret += ((long long)tmp * (tmp + 1)) >> 1;
      crr = a[i];
      tmp = 0;
    } else {
      tmp++;
    }
  }
  ret += ((long long)tmp * (tmp + 1)) >> 1;
  cout << ret << '\n';
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
  

    ll r;
    cin >> r;
    cout << 3 * r * r << endl;

}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

def main():
    n, k = map(int, input().split())
    num = len(list(Base_10_to_n(n, k)))
    print(num)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
n = int(input())

t = []

for i in range(n):
    s = list(input())
    s.sort()
    t.append(s)

t.sort()

s = 0
c = 0
l = []

for i in range(n):
    if t[i] == l:
        c += 1
    else:
        s += c * (c+1) // 2
        c = 0
        l = t[i]

if c > 0:
    s += c * (c+1) // 2

print(s)


Measured memory_bytes: 127052
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int D[30][30];
map<int, int> cnt[3];
int main() {
	int N, C;
	cin >> N >> C;
	for (int i = 0; i < C; i++) {
		for (int j = 0; j < C; j++) cin >> D[i][j];
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			int c;
			cin >> c;
			c--;
			cnt[(i + j) % 3][c]++;
		}
	}
	int ans = 1 << 30;
	for (int i = 0; i < C; i++) {
		for (int j = 0; j < C; j++) {
			for (int k = 0; k < C; k++) {
				if (i == j || j == k || k == i) continue;
				int sum = 0;
				for (auto itr = cnt[0].begin(); itr != cnt[0].end(); itr++) {
					sum += D[itr->first][i] * itr->second;
				}
				for (auto itr = cnt[1].begin(); itr != cnt[1].end(); itr++) {
					sum += D[itr->first][j] * itr->second;
				}
				for (auto itr = cnt[2].begin(); itr != cnt[2].end(); itr++) {
					sum += D[itr->first][k] * itr->second;
				}
				ans = min(ans, sum);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace D
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var max = A.Max();
            var answer = new bool[max + 1];
            var tmp = new bool[max + 1];
            Array.Sort(A);
            foreach (var n in A)
            {
                if (answer[n]) answer[n] = false;
                if (tmp[n]) continue;
                answer[n] = true;
                for (var i = n; i < tmp.Length; i += n)
                {
                    tmp[i] = true;
                }
            }
            Console.WriteLine(answer.Count(x => x));
        }
    }
}


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

vector<string>strs;

int main(){
  string s;
  int k;
  cin >> s >> k;
  for(int i=1; i<=min(5, int(s.length())); i++){
    for(int j=0; j<s.length()-i+1; j++){
      string now = "";
      for(int l=0; l<i; l++){
        now += s[j+l];
      }
      bool trig = false;
      for(int l=0; l<strs.size(); l++){
        if(strs[l] == now){
          trig = true;
          break;
        }
      }
      if(!trig)strs.push_back(now);
    }
  }
  sort(strs.begin(), strs.end());
  cout << strs[k-1];
}
    


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    int n, k;
    cin >> n >> k;
    vector<int> p;
    rep(i, n) {
        int t;
        cin >> t;
        p.push_back(t);
    }
    sort(p.begin(), p.end());
    int ans = 0;
    rep(i, k) ans += p[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,x;
  cin>>N>>x;
  vector<int> okashi(N);
  int answer=0;
  int sum=0;
  for(int i=0; i<N; i++){
    int a;
    cin>>a;
    okashi.at(i)=a; //i人目が喜ぶお菓子の個数
  }
  sort(okashi.begin(), okashi.end());
  for(int i=0; i<N; i++){
    sum+=okashi.at(i);
    answer++;
    if(sum>=x){
      break;
    }
  }
  if(sum!=x){
    answer--;
  }
    cout<<answer<<endl;
}


Measured memory_bytes: 256
a,b,c,x,y=list(map(int, input().split()))
ans=0

if (a+b)>=c*2:
	if x>y:
		ans=ans+(y*2*c)
		x=x-y
		y=0
	else:
		ans=ans+(x*2*c)
		y=y-x
		x=0

if a>c*2:
	if x>0:
		ans=ans+(x*2*c)
		x=0
elif x>0:
	ans=ans+(x*a)
	x=0

if b>c*2:
	if y>0:
		ans=ans+(y*2*c)
		y=0
elif y>0:
	ans=ans+(y*b)
	y=0

print(ans)

Measured memory_bytes: 3064
import collections

n=int(input())
a=list(map(int,input().split()))
a1=[a[2*i] for i in range(n-n//2)]
a2=[a[2*i+1] for i in range(n//2)]
c1=collections.Counter(a1)
c2=collections.Counter(a2)
e1=c1.most_common()
e2=c2.most_common()
d1=e1[0]
d2=e2[0]
if d1[0]!=d2[0]:
    print(n-d1[1]-d2[1])
elif len(e1)==1 and len(e2)==1:
    print(min(d1[1],d2[1]))
elif len(e1)==1:
    print(min((n//2-d2[1])+d1[1],n//2-e2[1][1]))
elif len(e2)==1:
    print(min((n-n//2-d1[1])+d2[1],n-n//2-e1[1][1]))
else:
    print(n-max(d1[1]+e2[1][1],d2[1]+e1[1][1]))


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

int main(){
  int N;
  cin >> N;
  vector<string> W(N);
  for (int i=0; i<N; i++){
    cin >> W[i];
  }
  set<string> S;
  char lastw = ' ';
  for(int i=0; i<N; i++){
    if(lastw != ' '){
      if (lastw != W[i][0]){
        cout << "No" << endl;
        return 0;
      }
    }
    if (S.find(W[i]) != S.end()){
      cout << "No" << endl;
      return 0;
    }
    S.insert(W[i]);
    lastw = W[i][W[i].size()-1];
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 N, M;
  cin >> N >> M;
  cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <map>
typedef long long ll;
using namespace std;
#define rep(i,n) for (int i = 0; i <= int(n); i++)
#define mod 1000000007

int main() {
	string s;
	cin >> s;
	int sum = s.length();
	cout << s[0] << sum - 2 << s[sum - 1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    double n,k;
    cin>>n>>k;
    vector<double> vd;
    //cout<<1/4<<endl;
    for(int i=1;i<=n;i++){
        //cout<<i<<" ";
        double p = (double)(1/n);
        //cout<<p<<" "<<(double)(1/n)<<" ";
        int now = i;
        //cout<<"bool"<<endl;
        //cout<<now<<" "<<k<<endl;
        //cout<<endl;
        while(now<k){
            //cout<<"ei"<<endl;
            p/=2;
            now*=2;
        }
        vd.push_back(p);
        //cout<<p<<endl;
    }
    double ans = 0;
    for(auto u : vd){
        ans+= u;
    }
    printf("%.10lf\n",ans);
    return 0;
}

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

int main(){
  int a,b; cin >> a >>b;
  int outlet = 1;
  int cnt = 0;
  for(int i = 1; ;i++){
    if(outlet >= b){
      cout << cnt;
      return 0;
    }
    cnt++;
    outlet += a-1;
  }
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int r, g;
  cin >> r >> g;
  cout << g*2-r << endl;
  return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <random>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

const Int alp = 26;

Int compute_score(Int &D, vector<vector<Int>> &s, vector<Int> &c, vector<Int> &out) {
    Int score = 0;
    vector<Int> last(alp, 0);

    Int count = out.size();
    for (Int d = 0; d < count; d++) {
        last[out[d]] = d + 1;

        for (Int i = 0; i < alp; i++) {
            score -= (d + 1 - last[i]) * c[i];
        }
        score += s[d][out[d]];
    }

    return score;
}

Int evaluate(Int &D, vector<vector<Int>> &s, vector<Int> &c, vector<Int> &out, Int &k) {
    Int score = 0;
    vector<Int> last(alp, 0);

    Int count = out.size();
    for (Int d = 0; d < count; d++) {
        last[out[d]] = d + 1;

        for (Int i = 0; i < alp; i++) {
            score -= (d + 1 - last[i]) * c[i];
        }
        score += s[d][out[d]];
    }

    count = min(D, (Int)(out.size() + k));
    for (Int d = out.size(); d < count; d++) {
        for (Int i = 0; i < alp; i++) {
            score -= (d + 1 - last[i]) * c[i];
        }
    }

    return score;
}

vector<Int> solve(Int &D, vector<vector<Int>> &s, vector<Int> &c, Int &k) {
    vector<Int> out;

    for (Int _ = 0; _ < D; _++) {
        Int max_score = -INF;
        Int best_i = 0;

        for (Int i = 0; i < alp; i++) {
            out.push_back(i);

            Int score = evaluate(D, s, c, out, k);
            if (max_score < score) {
                max_score = score;
                best_i = i;
            }

            out.pop_back();
        }

        out.push_back(best_i);
    }

    return out;
}

Int scoring(Int &D, vector<vector<Int>> &s, vector<Int> &c, vector<Int> &t) {
    Int ans = 0;
    vector<Int> last(alp, 0);

    for (Int i = 0; i < D; i++) {
        ans += s[i][t[i]];
        last[t[i]] = i + 1;

        for (Int j = 0; j < alp; j++) {
            ans -= c[j] * (i - last[j] + 1);
        }
    }

    return ans;
}

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

    Int D;
    cin >> D;
    vector<Int> c(alp);
    vector<vector<Int>> s(D, vector<Int>(alp));
    for (Int i = 0; i < alp; i++) {
        cin >> c[i];
    }
    for (Int i = 0; i < D; i++) {
        for (Int j = 0; j < alp; j++) {
            cin >> s[i][j];
        }
    }

    vector<Int> ans(D, 0);
    Int point = 0;
    for (Int k = 0; k <= alp; k++) {
        vector<Int> t = solve(D, s, c, k);
        Int p = scoring(D, s, c, t);

        if (point < p) {
            point = p;
            ans = t;
        }
    }

    for (auto e : ans) {
        cout << e + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 3744
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n,q,m=0;
    cin>>n>>q;
    vector<ll> a(n+1);
    string s;
    cin>>s;
    for(int i=1;i<n;i++)
       {
        if(s[i-1]=='A'&& s[i]=='C')
        {
            a[i]=1;
        }
       }
    for(int i=1;i<=n;i++)
      a[i]+=a[i-1];
    while(q--)
    {
        int l,r;
        cin>>l>>r;
        if(r==l) cout<<0<<endl;
        else
        { r--;
         cout<<a[r]-a[l-1]<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4308
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

bool check(ll n){
	
	rep(i,1,sqrt(n)+1){
		if(pow(i,2) == n) return true;
	}
	
	return false;
}

signed main(){
	ll n,d,cnt = 0;
	ll memo = 0;
	cin >> n >> d;
	ll a[n][d] ={};
	
	rep(i,0,n){
		rep(j,0,d){
			cin >> a[i][j];
		}
	}
	
	rep(i,0,n-1){
		rep(j,i+1,n){
			memo = 0;
			rep(k,0,d){
				memo += pow(a[i][k] - a[j][k],2);
			}
			
			if(check(memo)) cnt++;
		}
	}
	
	cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sx,sy,tx,ty=map(int,input().split())
ans=""
for i in range(ty-sy):
    ans+="U"
for i in range(tx-sx):
    ans+="R"
for i in range(ty-sy):
    ans+="D"
for i in range(tx-sx):
    ans+="L"
ans+="L"
for i in range(ty-sy+1):
    ans+="U"
for i in range(tx-sx+1):
    ans+="R"
ans+="DR"
for i in range(ty-sy+1):
    ans+="D"
for i in range(tx-sx+1):
    ans+="L"
ans+="U"
print(ans)


Measured memory_bytes: 43356
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <limits>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
constexpr lnt INF = 2e18;
/*-*/

template <typename T = lnt, T INF = std::numeric_limits<T>::max()>
struct Dinic
{
	struct Edge
	{
		int a,b; T c,f;
		Edge(int a, int b, T c) : a(a),b(b),c(c),f(0) {}
	};
	int n,m;
	std::vector<Edge> E;
	std::vector<std::vector<int> > G,Gf;
	Dinic(int n) : n(n),m(0),G(n) {}
	void add_edge(int i, int j, int c) {
		E.emplace_back(i,j,c);
		E.emplace_back(j,i,0);
		G[i].emplace_back(m);
		G[j].emplace_back(m|1);
		m+=2;
	}
	bool bfs(int s, int t) {
		Gf.assign(n,std::vector<int>());
		std::queue<int> que; que.emplace(s);
		std::vector<int> dist(n,-1); dist[s]=0;
		while(!que.empty()) {
			int i=que.front(); que.pop();
			for(int to:G[i]) {
				if(dist[E[to].b]!=-1 || E[to].c==E[to].f) continue;
				dist[E[to].b]=dist[E[to].a]+1;
				que.emplace(E[to].b);
			}
		}
		if(dist[t]==-1) return false;
		for(int i=0;i<m;i++) {
			if(dist[E[i].a]+1!=dist[E[i].b] || E[i].c==E[i].f) continue;
			if(dist[E[i].a]>=dist[t]) continue;
			Gf[E[i].a].emplace_back(i);
		}
		return true;
	}
	T dfs(int i, T a_f, const int& t) {
		if(i==t || a_f==0) {
			return a_f;
		}
		T v_f=0;
		for(int to:Gf[i]) {
			T f=dfs(E[to].b,std::min(a_f-v_f,E[to].c-E[to].f),t);
			if(f>0) {
				E[to].f+=f; E[to^1].f-=f;
				v_f+=f;
			}
			if(a_f==v_f) break;
		}
		return v_f;
	}
	T flow(int s, int t) {
		T max_flow=0;
		while(bfs(s,t)) {
			T f = dfs(s,INF,t);
			if(f==0) break;
			max_flow+=f;
		}
		return max_flow;
	}
};

int main() {
	int h,w;
	std::cin >> h >> w;
	std::vector<std::string> g(h);
	rep(i,h) std::cin >> g[i];
	std::vector<std::vector<int> > X(h),Y(w);
	int sx,sy,tx,ty;
	rep(i,h) {
		rep(j,w) {
			if(g[i][j]=='o'||g[i][j]=='S'||g[i][j]=='T') {
				if(g[i][j]=='S') {
					sx=i; sy=j;
				}
				if(g[i][j]=='T') {
					tx=i; ty=j;
				}
				X[i].emplace_back(j);
				Y[j].emplace_back(i);
			}
		}
	}
	if(sx==tx||sy==ty) {
		print(-1);
		return 0;
	}
	auto enc = [&] (int i, int j) {
		return i*w+j;
	};
	debug(sx,sy,tx,ty);
	Dinic<int> flow(2*h*w);
	rep(i,h) {
		for(auto y1:X[i]) for(auto y2:X[i]) {
			if(y1==y2) continue;
			flow.add_edge(enc(i,y1),h*w+enc(i,y2),1);
		}
	}
	rep(i,w) {
		for(auto x1:Y[i]) for(auto x2:Y[i]) {
			if(x1==x2) continue;
			flow.add_edge(enc(x1,i),h*w+enc(x2,i),1);
		}
	}
	rep(i,h) rep(j,w) flow.add_edge(enc(i,j)+h*w,enc(i,j),1);
	print(flow.flow(enc(sx,sy),enc(tx,ty)+h*w));
}


Measured memory_bytes: 85340
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	for(register int i=0;i<s.size();i++){
		if(s[i]==','){
			printf(" ");
			continue;
		}
		cout<<s[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"io"
	"os"
)

const Mod = 1000000007

func main() {
	r := NewScannerSize(os.Stdin, 1024*8)
	h, w := r.Int(), r.Int()

	grid := make([]string, h)
	for i := 0; i < h; i++ {
		grid[i] = r.Text()
	}

	var dp [1001][1001]int
	dp[0][0] = 1

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if grid[i][j] != '.' {
				continue
			}
			if i == 0 && j == 0 {
				dp[i][j] = 1
				continue
			}
			if i == 0 {
				dp[i][j] = dp[i][j-1]
				continue
			}
			if j == 0 {
				dp[i][j] = dp[i-1][j]
				continue
			}

			dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % Mod
		}
	}

	fmt.Println(dp[h-1][w-1])
}

// generated by https://github.com/murosan/gollect

type Scanner struct {
	r     io.Reader
	buf   []byte
	delim byte
	size, eof,
	start, end int
}

func NewScannerSize(r io.Reader, size int) *Scanner {
	return &Scanner{
		r:     r,
		buf:   make([]byte, size),
		delim: ' ',
		size:  size, start: size, end: size,
	}
}

func (s *Scanner) Text() string { return string(s.bytes()) }

func (s *Scanner) Int() int { return ParseInt(s.bytes()) }

func (s *Scanner) bytes() []byte { b, _ := s.next(); return b }
func (s *Scanner) next() (b []byte, size int) {
	for n := 0; ; {
		for i := s.end; i < s.size; i++ {
			if s.buf[i] == s.delim || s.buf[i] == '\n' || i == s.eof {
				b, size = s.buf[s.start:i], i-s.start
				s.start, s.end = i+1, i+1
				return
			}
		}
		s.end = s.size
		if n++; n == 2 {
			panic("lack of buffer size")
		}
		s.read()
	}
}
func (s *Scanner) read() {
	copy(s.buf, s.buf[s.start:s.end])
	s.end -= s.start
	s.start = 0
	n, _ := s.r.Read(s.buf[s.end:])
	s.eof = s.end + n
}

func ParseInt(b []byte) (n int) {
	var i int
	if b[0] == '-' {
		i++
	}
	for ; i < len(b); i++ {
		n *= 10
		n += int(b[i] - '0')
	}
	if b[0] == '-' {
		return -n
	}
	return
}


Measured memory_bytes: 9472
arr=list(map(int,input().split()))
arr=sorted(arr)
if (arr[0]+arr[2]-arr[1])%2==arr[2]%2:
  print(arr[2]-arr[1]+(arr[1]-arr[0])//2)
else:
  print(arr[2]-arr[1]+1+(arr[1]+1-arr[0])//2)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <map>
#include <algorithm>
#include <math.h>
#include <iostream>     // std::cout, std::fixed
#include <iomanip>
#include<queue>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <iostream>
#include <sstream>
typedef long long ll;
using namespace std;

vector<int> nums;

void rec(vector<int>& p,int place)
{

    if(place==3)
    {
    int ans=nums[0];
    for(int i=0;i<3;i++)
    {
        if(p[i]==0)
        {
            ans-=nums[i+1];
        }
        else
        {
            ans+=nums[i+1];
        }
    }
    if(ans==7)
    {
        p.push_back(2);
        for(int i=0;i<nums.size();i++)
        {
            cout<<nums[i];
            if(p[i]==0)
                cout<<'-';
            if(p[i]==1)
                cout<<'+';
            if(p[i]==2)
                cout<<'=';
        }
        cout<<7;
        exit(0);
    }
        return;
    }
    for(int i=0;i<3;i++)
    {
        rec(p,place+1);
        p[place]=1;
        rec(p,place+1);
        p[place]=0;
    }
        
    
}
int main () {
    ios_base::sync_with_stdio(false);
    string s;
    cin>>s;
    nums=vector<int> (4);
    for(int i=0;i<4;i++)
        nums[i]=s[i]-'0';
    vector<int> pol(3,0);
    rec(pol,0);
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<functional>
#include<iostream>
#include<cfloat>
#include<climits>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<time.h>
#include<vector>
using namespace std;
int main()
{
	int a,b;
	while(cin >> a >> b)
	{
		int sum;
		if(b<10) sum=a*10+b;
		else if(b<100) sum=a*100+b;
		else sum=a*1000+b;
		int root=(int)sqrt(sum);
		if(root*root==sum){cout << "Yes\n";break;}
		else{cout << "No\n";break;}
	}
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
const ll mod = 1e9 + 7, N = 100010;
ll dp[N][4];
int main() {
    string s; cin >> s;
    int n = s.length();
    dp[0][0] = 1;
    REP(i,n){
        if (s[i] == 'A' || s[i] == '?'){
            REP(j,4){
                dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % mod;
                if (j == 0) dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % mod;
            }
        }
        if (s[i] == 'B' || s[i] == '?'){
            REP(j,4){
                dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % mod;
                if (j == 1) dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % mod;
            }
        }
        if (s[i] == 'C' || s[i] == '?'){
            REP(j,4){
                dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % mod;
                if (j == 2) dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % mod;
            }
        }
    }
    cout << dp[n][3] << endl;
    return 0;
}

Measured memory_bytes: 3584
all_list = [int(input()) for _ in range(5)]
k = int(input())
count = 0
for i in range(5):
    for j in range(i+1,5):
        result = abs(all_list[i] - all_list[j])
        if k < result:
            count += 1
if count == 0:
    print('Yay!')
else:
    print(':(')

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

//短縮
#define rep(i,n) for(int i=0;i<(n);++i)
//sort()用
#define all(v) v.begin(), v.end()

using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> d(K);
  vector<vector<int>> A(K,vector<int>(N));
  rep(i,K){
    cin >> d.at(i);
    rep(k,d.at(i)){
      cin >> A.at(i).at(k);
    }
  }
  set<int> S;
  rep(i,K){
    rep(j,d.at(i)){
      S.insert(A.at(i).at(j));
    }
  }
  cout << N-S.size();
  return 0;
}


Measured memory_bytes: 3664
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.trim().split('\n');

while (line = lines.shift()) {
    const numbers = line.split(' ').map(Number);

    let a = numbers[0];
    let b = numbers[1];

 	if ( a === 0 && b === 0 ) {break;}

 	if (a > b){
 		const temp = a ;
 		a =b ;
 		b= temp;

 	}
    const output = a + ' ' + b;

    
    console.log(output);
    
}


Measured memory_bytes: 18828
n=int(input())

def get_prime(n):
    l=[]
    i=2
    while n>0:
        flg=True
        for j in range(2,int(i**0.5)+1):
            if i%j==0:
                flg=False
                break
        if flg:
            l.append(i)
            n-=1
        i+=1
    return l

p=get_prime(1000)
a=[]
for i in p:
    if i%5==1:
        a.append(i)
    if len(a)==n:
        break
print(*a)

Measured memory_bytes: 39660
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const ll INF = 1LL<<60;

ll dp[500005][5];

ll cost(int i, int s, const vector<ll> &a) {
  if (s == 0 || s == 4) return a[i]; // snukeくんが散歩しない区間 (通る回数が0)
  if (s == 1 || s == 3) {            // スタートとゴールの範囲外の区間 (通る回数が偶数)
    if (a[i] == 0) return 2;
    else return a[i] % 2;
  }
  if (s == 2) {                      // スタートとゴールの間の区間 (通る回数が奇数)
    if (a[i] % 2 == 0) return 1;
    else return 0;
  }
  puts("state is invalid.");
  exit(0);
}

int main() {
  int l;
  cin >> l;
  vector<ll> a(l);
  rep(i, l) cin >> a[i];

  rep(i, 500005) rep(j, 5) dp[i][j] = INF;
  dp[0][0] = 0;

  rep(i, l) rep(j, 5) for (int k = j; k < 5; ++k) {
    chmin(dp[i + 1][k], dp[i][j] + cost(i, k, a));
  }
  
  ll ans = INF;
  rep(i, 5) chmin(ans, dp[l][i]);
  cout << ans << endl;
}

Measured memory_bytes: 21376
#include <iostream>
#include <algorithm>
using namespace std;
long long int n,m,sum;
int main() {
	// your code goes here
	cin>>n>>m;
	sum=n;
	long long int ans=-1;
	for(long long int i=1;i*i<=m;i++){
		if(m%i==0&&i>=sum){
			ans=max(ans,m/i);
		}
		if(m%i==0&&m/i>=sum){
			ans=max(ans,i);
		}
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		int count=3;
		if(a==b){count--;
			 }if(b==c){count--;
			 }if(a==c){count--;
			 }
		 if(count==0) {
			 count++;
		 }
		System.out.println(count);
	}
}


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

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


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

# perms = itertools.permutations(L, 3)
# print(list(perms))

res = 0
for i in range(len(L)):
    for j in range(i+1, len(L)):
        for k in range(j+1, len(L)):
            if L[i] != L[j] and L[i] != L[k] and L[j] != L[k]:
                # abs(a - b) < c < a + b
                if abs(L[i] - L[j]) < L[k] < L[i] + L[j]:
                    # print(i, j, k)
                    res += 1

# for a, b, c in perms:
#     if a != b and b != c:
#         if abs(a - b) < c < a + b:
#             res += 1

print(res)


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

long N, ans;

int main(void) {

    cin >> N;
    for (long i = 1; i <= N; i+=2) {
        long count = 0;
        for (long j = 1; j <= i; j++) {
            if (i % j == 0) count++;
        }

        if (count == 8) ans++;
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 3592
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

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

    ll n,m;
    cin>>n>>m;
    vector<ll> v(n+1);
    vector<ll> skip(n+1);
    FOR(i,0,m){
      ll in;
      cin>>in;
      skip[in] = 1;
    }
    ll mod = 1e9+7;
    v[0] = 1;

    FOR(i,0,n-1){
      if(skip[i+1] == 0) v[i+1] = (v[i+1] + v[i])%mod;
      if(skip[i+2] == 0) v[i+2] = (v[i+2] + v[i])%mod;
    }
    if(skip[n] == 0) v[n] = (v[n] + v[n-1])%mod;

    cout<<v[n]<<endl;

}


Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		Array.Sort(A);
		Array.Sort(F);
		Array.Reverse(F);
		
		if(isPossible(0)){
			Console.WriteLine(0);
			return;
		}
		long l = 0, r = (long) 1e18;
		while(r - l > 1){
			var c = (l + r) / 2;
			if(!isPossible(c)){
				l = c;
			} else {
				r = c;
			}
		}
		
		Console.WriteLine(r);
	}
	
	bool isPossible(long v){
		
		long ex = 0;
		for(int i=0;i<N;i++){
			long need = v / F[i];
			if(need < A[i]){
				ex += A[i] - need;
			}
		}
		return ex <= K;
	}
	
	int N;
	long K;
	long[] A;
	long[] F;
	public Sol(){
		var d = rla();
		N = (int) d[0];
		K = d[1];
		A = rla();
		F = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 47252
N = int(input())
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
# どのタイミングで下移動を使うかだけが重要

lst = [0]*N
for i in range(N):
    lst[i] = sum(A1[:i+1]) + sum(A2[i:])
ans = max(lst)
print(ans)


Measured memory_bytes: 9176
def main():
  s = input()
  si , ei = 0, len(s) - 1
  while True:
    if s[si] == 'A':
      break
    si += 1
  while True:
    if s[ei] == 'Z':
      break
    ei -= 1
  print(ei - si + 1)

if __name__ == '__main__':
  main()

Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define repr(i, a, n) for (ll i = n - 1; (ll)a <= i; i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e14 + 99);
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
template <typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T>
T mpow(T a, T n)
{
    T res = 1;
    for (; n; n >>= 1)
    {
        if (n & 1)
            res = res * a;
        a = a * a;
    }
    return res;
}

//cin.tie(0);ios::sync_with_stdio(false);

signed main()
{
    ll n, m, l;
    cin >> n >> m >> l;
    ll dp[n][n], dp2[n][n];

    vector<vector<ll>> e(n, vector<ll>(n, INF));

    rep(i, 0, m)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        if (c > l)
            c = LINF;
        e[a][b] = c;
        e[b][a] = c;
    }

    rep(i, 0, n) rep(j, 0, n)
    {
        dp[i][j] = e[i][j];
        dp2[i][j]=INF;
        if (i == j)
        {
            dp[i][j] = 0;
            dp2[i][j]=0;
            e[i][j] = 0;
        }
    }

    rep(k, 0, n) rep(i, 0, n) rep(j, 0, n)
    {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
    }

    rep(i, 0, n) rep(j, 0, n)
    {
        if(dp[i][j]<=l)dp2[i][j]=1;
    }

    rep(k, 0, n) rep(i, 0, n) rep(j, 0, n)
    {
        dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j]);
    }

    int q;
    cin >> q;
    while (q--)
    {
        ll s, g;
        cin >> s >> g;
        s--;
        g--;
        if (dp2[s][g] >= INF)
            cout << -1 << endl;
        else
            cout << dp2[s][g]-1 << endl;
    }
}

Measured memory_bytes: 2688
#include<stdio.h>
#include<math.h>
#define pb push_back
//#define FAST ios::sync_with_stdio(false);cin.tie(NULL),cout.tie(NULL);
//typedef long long ll;
#define pi  3.141592653589793238
//using namespace std;

int main()
{
     double r;
     scanf("%lf",&r);
     printf("%.10lf\n",2*pi*r);
//    cin>>r;
//    cout<<2*pi*r<<fixed<<setprecision(12)<<endl;
    return 0;
}


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

int main(){
	int n, x;
	long long sum=0;
	scanf("%d", &n);
	int f=0, mn=1e9+1;
	for(int i=0; i<n; i++){
		scanf("%d",&x);
		if(x<0)
			f++;
		sum+=abs(x);
		mn=min(mn,abs(x));
	}
	if(f%2==1) sum-=2*mn;
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 256
/*****************************
*  Author :: Prasanna Kumar  *
*****************************/

/***********************************
* Unus pro omnibus, omnes pro uno  *
***********************************/
#include<bits/stdc++.h>
using namespace std;

// #define __AnAkLuSmOs freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define __AcHiLlEs ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define i_64 long long

void solve() {
    i_64 n, res(0), mx(LLONG_MIN);
    cin >> n;
    i_64 a[n];
    std::map<i_64, i_64> m;
    for (i_64 &i: a) cin >> i, m[i]++, mx = max(i, mx);
    sort(a, a + n);
    for (i_64 &i: a) {
        if (m[i] == 1) res++;
        i_64 x = i;
        m[i] += 2;
        while (x <= mx) {
            x += i;
            m[x]++;
        }
    }
    cout << res << "\n";
}

signed main() {
    // #ifndef ONLINE_JUDGE 
    //     __AnAkLuSmOs    
    // #endif

    __AcHiLlEs

    i_64 t(1);
    // cin >> t;
    for (i_64 i = 1; i <= t; /*cout << "Case " << i << ": ",*/ solve(), i++);
    return 0;
}
    

Measured memory_bytes: 75684
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int n,k;
    cin >> n>>k;
    vector<int> h(n+110);
    vector<int> dp(n+110,1e9);
    dp[0] = 0;
    rep(i,n){
        cin >> h[i];
    }
    rep(i,n){
        rep(j,k+1){
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
        }
    }
    cout << dp[n-1] <<endl; 
return 0;
}

Measured memory_bytes: 1024