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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMinimum(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMaximum(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {

    /**
     * 累積和
     */

    int N;
    cin >> N;
    vector<int> w(N);
    for (int i = 0; i < N; ++i) {
        cin >> w[i];
    }

    vector<int> s(N + 1);
    s[0] = 0;
    for (int i = 0; i < N; ++i) {
        s[i + 1] = s[i] + w[i];
    }
    int diff = s[N];
    for (int i = 0; i < N; ++i) {
        int left = s[i];
        int right = s[N] - left;
        int t = abs(right - left);
        if (t < diff) {
            diff = t;
        }
    }

    cout << diff << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long
#define mp make_pair
#define pb push_back
#define se second
#define fi first
#define N 100007
ll a[200007];
//string a, b;
//ll dp[200007];
vector<ll> v[200007];
ll vis[200007];
ll cnt=0, ans=0, maxi=-1, m;

void dfs(ll node, ll cnt, ll maxi) {
    vis[node]=1;
    if(a[node]>0) cnt++;
    else cnt=0;
    maxi=max(maxi,cnt);
    if(v[node].size()==1 && node!=1) {
        if(maxi<=m) ans++;
        //maxi=-1;
        //return;
    }  
    for(int i=0;i<v[node].size();i++) {
        if(!vis[v[node][i]]) {
            dfs(v[node][i], cnt, maxi);
        }
    }
}
 
void solve() {
    ll i, j, k, l, test, n, q, x, y, z;
    string d;
    cin>>n>>d;
    ll c=0;
    map<ll,ll> m;
    for(i=0;i<n;i++) {
        m[d[i]]++;
    }
    for(i=0;i<m['R'];i++) {
        if(d[i]!='R') c++;
    }
    cout<<c;
}
int main() { 
    #ifndef ONLINE_JUDGE
        freopen("input1.txt", "r", stdin);
        freopen("output1.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0; 
}


Measured memory_bytes: 8468
#include<bits/stdc++.h>
#define int long long
using namespace std;
int32_t main(){
    int n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int dp[n+1];
    dp[1]=0;
    for(int i=2;i<=k && i<=n;i++){
        dp[i]=dp[1]+abs(a[i]-a[1]);
    }
    for(int i=k+1;i<=n;i++){
        dp[i]=LONG_LONG_MAX;
        for(int j=k;j>=1;j--){
            dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));    
        }
    }
    cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a, b = LI()
    print(min(n * a, b))
    return

#B
def B():
    n, d = LI()
    x = LIR(n)
    a = list(itertools.combinations(range(n), 2))
    ans = 0
    for a1,a2 in a:
        b = 0
        for bi in range(d):
            b += (x[a1][bi] - x[a2][bi])** 2
        if float.is_integer(math.sqrt(b)):
            ans += 1
    print(ans)
    return

#C
def C():
    l, r = LI()
    ans = 2018
    if l // 2019 == r // 2019:
        for i in range(l, r + 1):
            for k in range(i+1, r + 1):
                ans = min(ans, (i * k) % 2019)
        print(ans)
    else:
        print(0)
    return

#D
def D():
    n = II()
    a = LI()
    a = a + [a[0]]
    ans = [0] * n
    x = 0
    for i in range(1, n, 2):
        x = x + a[i + 1] - a[i]
    ans[1] = a[0] - x
    ans[0] = ans[1] + 2 * x
    for i in range(2, n):
        ans[i] = (a[i - 1] - ans[i - 1] // 2) * 2
    print(" ".join(map(str, ans)))

    return

#E
def E():
    n, k = LI()
    ab = LIR_(n - 1)
    edg = [[] for i in range(n)]
    for a,b in ab:
        edg[a].append(b)
        edg[b].append(a)
    check = defaultdict(int)
    chb = defaultdict(lambda: True)
    ans = k
    q = deque()
    for i in edg[0]:
        check[i] = 1
        q.append(i)
        chb[i] = False
    check[0] = 1
    chb[0] = False
    while q:
        i = q.pop()
        chb[i] = False
        b = 0
        x = 0
        for e in edg[i]:
            b += check[e]
            check[e] += 1
            if chb[e]:
                q.appendleft(e)
            else:
                x += 1
        check[i] = x + 1
        ans *= (k - b)
        ans %= mod
    print(ans)
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    E()


Measured memory_bytes: 97244
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
  int n, m, x;
  int a;
  int cost_0 = 0, cost_x = 0;

  cin >> n >> m >> x;

  for ( int i = 0; i < m; i++) {
    cin >> a;

    if ( a < x ) {
      cost_0++;
    } else {
      cost_x++;
    }
  }

  cout << min(cost_0, cost_x) << endl;

  return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,n;
  cin >>n;
  c=n%10;
  b=n/10%10;
  a=n/100;
  if (a==1)a=9;
  else a=1;
  if (b==1)b=9;
  else b=1;
  if (c==1)c=9;
  else c=1;
	cout << 100*a+10*b+c<<endl;  
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int[] x = new int[3];
		for (int i = 0; i < 3; i++) {
			x[i] = scan.nextInt();
		}
		int bk;
		boolean flg = true;
		while (flg ==true) {
			flg = false;
			for (int i = 1; i < 3; i++) {
				bk = x[i];
				if (x[i - 1] > x[i]) {
					x[i] = x[i - 1];
					x[i - 1] = bk;
					flg = true;
				}
			}
		}
		System.out.printf("%d %d %d\n", x[0], x[1], x[2]);

		scan.close();
	}

}


Measured memory_bytes: 26440
#include <iostream>
#include <set>

int main() {
  char s1;
  char s2;
  char s3;

  std::cin >> s1 >> s2 >> s3;

  std::multiset<char> tmp;
  tmp.insert(s1);
  tmp.insert(s2);
  tmp.insert(s3);

  std::size_t n = tmp.count('1');
  std::cout << n << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

void Get_Val(int &Ret)
{
	Ret = 0;
	char ch;
	while (ch = getchar(), ch > '9' || ch < '0')
		;
	do
	{
		(Ret *= 10) += ch - '0';
	}
	while (ch = getchar(), ch >= '0' && ch <= '9');
}

const int Max_N(200050);
typedef long long int LL;

struct node
{
	int X, Y;
};
int N;
LL Ans(0X3F3F3F3F3F3F3F3FLL);
node V[Max_N];

void init()
{
	Get_Val(N);
	for (int i = 1;i <= N;++i)
	{
		Get_Val(V[i].X), Get_Val(V[i].Y);
		if (V[i].X > V[i].Y)
			swap(V[i].X, V[i].Y);
	}
}

void Task1()
{
	int RMax(V[1].X), RMin(V[1].X), BMax(V[1].Y), BMin(V[1].Y);
	for (int i = 2;i <= N;++i)
	{
		RMax = max(RMax, V[i].X), RMin = min(RMin, V[i].X);
		BMax = max(BMax, V[i].Y), BMin = min(BMin, V[i].Y);
	}
	Ans = min(Ans, (RMax - RMin + 0LL) * (BMax - BMin + 0LL));
}

struct qwq
{
	qwq(const int &_p = 0, const int &_v = 0) : p(_p), v(_v) {}
	int p, v;
};

inline bool operator<(const qwq &a, const qwq &b)
{
	return a.v == b.v ? a.p < b.p : a.v < b.v;
}

int Tot, All[Max_N << 1];
set<qwq> R;
set<int> L;
map< int, vector<qwq> > M;
set<qwq>::iterator Rit;
set<int>::iterator Lit;
inline int qR()
{
	if (R.size())
	{
		Rit = R.end();
		return (--Rit) -> v;
	}
	else
		return -0X3F3F3F3F;
}

inline int qL()
{
	if (L.size())
	{
		Lit = L.end();
		return *(--Lit);
	}
	else
		return -0X3F3F3F3F;
}

void Task2()
{
	int AllMax(max(V[1].X, V[1].Y)), AllMin(min(V[1].X, V[1].Y)), YMin(V[1].Y);
	for (int i = 2;i <= N;++i)
	{
		AllMax = max(AllMax, max(V[i].X, V[i].Y));
		AllMin = min(AllMin, min(V[i].X, V[i].Y));
		YMin = min(YMin, V[i].Y);
	}
	for (int i = 1;i <= N;++i)
		All[++Tot] = V[i].X, All[++Tot] = V[i].Y, M[V[i].X].push_back(qwq(i, V[i].X)), R.insert(qwq(i, V[i].X));
	sort(All + 1, All + 1 + Tot);
	for (int i = 1;i <= Tot && All[i] <= YMin;++i)
	{
		Ans = min(Ans, (AllMax - AllMin + 0LL) * (max(qR(), qL()) - All[i] + 0LL));
		if (i <= Tot && All[i + 1] != All[i])
		{
			vector<qwq> &vec = M[All[i]];
			for (int j = 0;j != vec.size();++j)
				R.erase(vec[j]), L.insert(V[vec[j].p].Y);
		}
	}
}

int main()
{
	init();
	Task1();
	Task2();
	printf("%lld", Ans);
	return 0;
}

Measured memory_bytes: 34560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int N, M;
    cin >> N >> M;
    int L,R, l = 1, r = N;
    for ( int i = 0; i < M; i++ ) {
        cin >> L >> R;
        if ( l < L ) l = L;
        if ( r > R ) r = R;
    }
    ll ans = max(r-l+1,0);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<iostream>
#include<set>
#include<map>
#include<vector>
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)((x).size()))
#define rep(i,j,k) for(int i=(int)j;i<=(int)k;i++)
#define per(i,j,k) for(int i=(int)j;i>=(int)k;i--)
using namespace std;
typedef long long LL;
typedef double DB;
const DB pi=acos(-1.0);
const int N=110000;
int p[N],q[N];
int n,m;
struct gt{
	int ty;
	int w;
}b[N<<1];
inline bool cmp(const gt &a,const gt &b){return a.w<b.w;}
int main(){
	scanf("%d%d",&n,&m);
	rep(i,1,n)scanf("%d",&p[i]);
	rep(i,1,m)scanf("%d",&q[i]);
	rep(i,1,n){
		b[i].ty=0;
		b[i].w=p[i];
	}
	rep(i,1,m){
		b[i+n].ty=1;
		b[i+n].w=q[i];
	}
	sort(b+1,b+1+m+n,cmp);
	int nown=n;
	int nowm=m;
	LL ans=0;
	rep(i,1,n+m)
	if(b[i].ty==0){
		if(!nown)continue;
		ans+=(nowm+1)*1ll*b[i].w;
		nown--;
	}
	else{
		if(!nowm)continue;
		ans+=(nown+1)*1ll*b[i].w;
		nowm--;
	}
	cout<<ans<<endl;
	return 0;
}







Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define dump(x) cerr << #x << " : " << x << '\n'

int main() {
    int a, b;
    cin >> a >> b;
    int ans = a + b;
    ans = max(ans, a - b);
    ans = max(ans, a * b);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt(),b = sc.nextInt();
    if(a <= b){
      for(int i = 0;i<b;i++){
        System.out.print(a);
      }
    }else{
      for(int i = 0;i<a;i++){
        System.out.print(b);
      }
    }
    System.out.println("");
  }
}


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

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

  int a[110]={},b[110]={},x=0;

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

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

    cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
const int INF = 1e9+7;
using namespace std;
ll dp[100005];
ll solve(int n,int k,vector<int>&h){
	dp[1] = 0;

	
	for(int i=2;i<=n;i++){
		ll ans =INF;
	for(int j=1;j<=k;j++){
		ll tmp = INF;
		
			if(i-j>=1){
			tmp = abs(h[i]-h[i-j])+dp[i-j];
			ans = min(tmp,ans);
			dp[i] = ans;		
		}
		else
			break;
	}
	
}
	// op1 = abs(h[st]-h[st+1]) +solve(st+1,n,h);
	// if(st+2<=n)
	// 	op2 = abs(h[st]-h[st+2])+solve(st+2,n,h);
	//cout<<op1<<" "<<op2<<endl;
	return  dp[n];

}
int main(){

// #ifndef ONLINE_JUDGE
//     // for getting input from input.txt
//     freopen("input.txt", "r", stdin);
//     // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
//#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
cin>>n>>k;
vector<int>h;
h.push_back(0);
for(int i=0;i<n;i++){
	int tmp;
	cin>>tmp;
	h.push_back(tmp);
}
if(n==1){
	cout<<0;
	return 0;
}
memset(dp,0,n+1);
cout<<solve(n,k,h);
}
	

Measured memory_bytes: 1528
n = int(input())
a = list(map(int,input().split()))

b = []
for i in range(n):
  b.append((a[i],i))
b.sort(reverse = True)

#dp[i][j]:(大きい順で)i番目まで見て、左に寄せたのがj個である場合の最大値

dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(n):
  x = b[i][0]
  y = b[i][1]
  for l in range(i+1):
    r = i-l
    dp[i+1][l+1] = max(dp[i+1][l+1],dp[i][l]+x*(y-l))
    dp[i+1][l] = max(dp[i+1][l],dp[i][l]+x*(n-1-r-y))

ans = 0
for i in range(n+1):
  ans = max(dp[n][i],ans)
print(ans)
#print(dp)

Measured memory_bytes: 100576
#include<bits/stdc++.h>
using namespace std;
string cmd0(string s)
{
    return s+"0";
}
string cmd1(string s)
{
    return s+"1";
}
string cmdb(string s)
{
    string pos="";
    for(int i=0;i<s.length()-1;i++)
    {
        pos+=s[i];
    }
    return pos;
}
int main()
{
    string s1="";
    string s2="";
    string ans;
    cin>>ans;
    for(int i=0;i<ans.size();i++)
    {
        if(ans[i]=='0')
        {
            s1=cmd0(s1);
        }
        else if(ans[i]=='1')
        {
            s1=cmd1(s1);
        }
        else
        {
            if(s1!="")
            {
            s1=cmdb(s1);
            }
        }

    }
    cout<<s1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define all(a) a.begin(),a.end()
#define fi first
#define se second
int M=1e9+7;
int mm(int x,int y){x%=M,y%=M;return (x*y)%M;}//Modular Multiply
int po(int x,int y){ if(!y)return 1;int a=po(x,y/2)%M;if(y%2)return mm(a,mm(a,x));return mm(a,a);}//(x**y)%M

signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//string s;
	int n,m,c=0,t=1,i,j,k,sum=0,ans,f=0,x,y;
	//cin>>t;
	while(t--){
		
		//vector<int> v;map<int,int> mp;
		set<int> st;
		cin>>n>>k;
		while(k--){
			cin>>m;
			while(m--){
				cin>>x;
				st.insert(x);
			}
		}
		cout<<n-st.size();
		//int a[n];rep(i,n) cin>>a[i];

	}
	return 0;
}




Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main()
{
    lli n;
    cin >> n;
    double k;
    vector<double>v;
    for(lli i=0 ;i<n;i++)
    {
        cin >> k; v.push_back(k);
    }
    double arr[n+2][n+2];
    arr[0][n-1] = 1 - v[n-1];
    arr[1][n-1] = v[n-1];
    for(int i=2;i<=n;i++)
    {
        arr[i][n-1] =0;
    }
    for(lli j=n-2;j>=0;j--)
    {
        for(lli i=n;i>=0;i--)
        {
            arr[i][j] = v[j] * arr[i-1][j+1] + ((1-v[j])* arr[i][j+1]); 
        }
    }
    // for(int i=0;i<=n;i++)
    // {
    //     for(int j=0;j<n;j++)
    //     {
    //         cout << arr[i][j] <<" ";
    //     }
    //     cout << endl;
    // }
    int m = n/2+1;
    double s=0;
    for(int i=m;i<=n;i++)
    {
        s+=arr[i][0];
    }
    cout <<setprecision(11)<< s <<endl;
}

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

int main() {
  string s;
  int a = 0;
  cin >> s;
  
  for(int i = 0; i < 4; i++){
    if(s.at(i) == '+') a++;
    else a--;
  }
  
  cout << a << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if((r <= x && x <= (W-r)) && (r <= y && y <= (H-r))){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
        
    return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long sum = accumulate(a, a + n, 0LL);
  if (sum % ((n + 1LL) * n / 2) != 0) {
    cout << "NO" << "\n";
    return 0;
  }
  int m = sum / ((n + 1LL) * n / 2), t = 0;
  for (int i = 0; i < n; i++) {
    int d = a[(i + 1) % n] - a[i % n];
    if ((m - d) % n != 0 or d > m) {
      cout << "NO" << "\n";
      return 0;
    }
    t += (m - d) / n;
  }
  cout << (t == m ? "YES" : "NO") << "\n";
  return 0;
}

Measured memory_bytes: 640
n = input()
a = map(int, raw_input().split())
print ' '.join(map(str, a))
for j in range(1, len(a)):
	key = a[j]
	i = j - 1
	while (i > -1) and (a[i] > key):
		a[i+1] = a[i]
		i = i - 1
	a[i+1] = key
	print ' '.join(map(str, a))

Measured memory_bytes: 4220
use std::io::stdin;
use std::collections::HashSet;

fn main() {
    let (a, b, c) = {
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();
        let abc: Vec<usize> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
        (abc[0], abc[1], abc[2])
    };

    let mut modulo = HashSet::new();

    for x in (1..).map(|i| a * i) {
        if !modulo.insert(x % b) {
            break;
        }
    }

    if modulo.contains(&c) {
        println!("YES");
    } else {
        println!("NO");
    }
}

Measured memory_bytes: 4352
import sys
sys.setrecursionlimit(1000)
inf = float('inf')

N = int(input())
ad = [[int(e) for e in list(input())] for _ in range(N)]

# 二部グラフ判定

# -1:未訪問, 0:黒, 1:白
visited = [-1] * N
flag = True

# 0を黒塗りでスタート
def dfs(v=0, color=0):
    visited[v] = color
    for nv, bit in enumerate(ad[v]):
        if not bit:
            continue
        ncolor = (color + 1) % 2
        if visited[nv] == -1:
            dfs(nv, ncolor)
        elif visited[nv] != ncolor:
            global flag
            flag = False

dfs()
if not flag:
    print(-1)
    exit()
    
def warshall_floyd(ad):
    N = len(ad)
    dist = [[inf] * N for _ in range(N)]
    for i, line in enumerate(ad):
        for j, p in enumerate(line):
            if p:
                dist[i][j] = 1
            if i == j:
                dist[i][j] = 0
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    return dist

dist = warshall_floyd(ad)

ans = 0
for i, line in enumerate(dist):
    for j, d in enumerate(line):
        if d != inf and d > ans:
            ans = d
ans += 1
print(ans)

Measured memory_bytes: 58204
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 205;

vector <int> ans;
int n, a[MAXN];

inline void Solve(int x)
{
	ans.pb(x);
	for (int i = x; i < n; i ++)
		swap(a[i], a[i - x]);
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read();
	for (int i = 0; i < n; i ++)
		a[i] = Read();
	while (!is_sorted(a, a + n))
		if (a[0] && a[0] < a[n - 1])
			Solve(n - 1);
		else
			Solve(1);
	printf("%d\n", ans.size());
	for (int i = 0; i < ans.size(); i ++)
		printf("%d\n", ans[i]);
	return 0;
}


Measured memory_bytes: 764
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

    int h, w, n; cin>>h>>w>>n;

    cout << (n + max(h, w) - 1) / max(h, w) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int n2 = n;
        int sum = 0;
        while(n2 >= 1){
            sum = sum + n2%10;
            n2 = n2 / 10;
        }
        if(n%sum == 0){
            System.out.print("Yes");
        } else {
            System.out.print("No");
        }
    }
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int l, k;
  cin >> l >> k;
  vector<vector<long long>> dp(2, vector<long long>(l + 1));
  dp[0][0] = 1;
  for (int i = 0; i < l; ++i) {
    dp[1][i + 1] += dp[0][i];
    if (i + k <= l) {
      dp[1][i + k] += dp[0][i];
    }
    dp[0][i + 1] += dp[1][i];
  }
  long long res = accumulate(begin(dp[1]), end(dp[1]), 0LL);
  cout << res << '\n';
}



Measured memory_bytes: 3216
#include<iostream>
#include<stack>
#include<queue>
using namespace std;

int main(){
	int n;
	stack<int> stk;
	queue<int> que;
	while(cin>>n){
		if(n==0){
			que.push(stk.top());
			stk.pop();
		}else{
			stk.push(n);
		}
	}
	while(!que.empty()){
		cout<<que.front()<<endl;
		que.pop();
	}
	return 0;
}

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

int main(){
    //4桁の整数に対して、同じ整数が三連続以上出現するか
    string N;
    cin >> N ;
    if(N[0]==N[1]&&N[1]==N[2]){
        cout << "Yes" << endl;
    }
    else if(N[1]==N[2]&&N[2]==N[3]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int L,N;
    cin >> N >> L;
    vector<string>A(N);

    for (int i = 0; i < N; i++)
    {
        cin>>A.at(i)    ;
    }
    sort(A.begin(),A.end());
    string sum;
    for (int i = 0; i < N; i++)
    {
        sum+=A.at(i);
    }
    cout << sum << endl;;

}

Measured memory_bytes: 256
N,M,C = map(int,input().split())
B = list(map(int,input().split()))

ans = 0
for i in range(N):
    A = list(map(int,input().split()))
    t = 0
    for j in range(M): t += B[j]*A[j]
    if t + C > 0: ans += 1
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

int main() {
    char string[1200];
    fgets(string, 1200, stdin);
    for (int i = 0; i < strlen(string); i++) {
        if (string[i] >= 'a' && string[i] <= 'z') {
            string[i] += -32;
        } else {
            if (string[i] >= 'A' && string[i] <= 'Z') {
            string[i] += 32;
            }
        }
    }
    printf("%s", string);
}


Measured memory_bytes: 2132
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String num = br.readLine();
		int k = Integer.parseInt(num);
		int[] sum = new int[k];
		num = br.readLine();
		String[] str = num.split(" ", 0);
		for (int i = 0; i < k; i++) {
			sum[i] = Integer.parseInt(str[i]);
		}
		Arrays.sort(sum);
		num = br.readLine();
		int n = Integer.parseInt(num);
		int[] sum2 = new int[n];
		num = br.readLine();
		String[] str2 = num.split(" ", 0);
		for (int i = 0; i < n; i++) {
			sum2[i] = Integer.parseInt(str2[i]);
		}
		Arrays.sort(sum2);
		int check = 0;
		for(int i=0;i<k;i++) {
			if(sum2[check]== sum[i]) {
				check++;
				if(check==n) {
					break;
				}
			}
		}
		if(check==n) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
}

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


int main() {
	int n,ans=0; cin >> n;
	vector<long long int> a; REP(i, n) { long long int tmp; cin >> tmp; a.push_back(tmp); }

	for (int i = 0;; i++) {
		for (int j = 0; j < n; j++) {
			if (a[j] % 2)goto ans;
			a[j] /= 2;
		}
		ans++;
	}

ans:
	cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    string s; cin >> s;
    bool flag = false;
    rep(i,3){
        if(s[i]=='7') flag = true;
    }
    Ans(flag);
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
typedef int ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define INF 1000000000
#define sc second
ll n,m;

char b[600][600];

//vector<vector<ll> > dp;
ll dp[510][(1 << 20) + 10];

bool oe[600];

ll dfs(ll i) {
	if(i == n) {
		bool f = true;
		REP(j,m) {
			if(oe[j] == 1) {
				f = false;
			}
		}
		if(f) {
			return 0;
		}
		return -INF;
	}

	ll a = dfs(i + 1);

	char save[600];

	REP(j,m) {
		save[j] = oe[j];
	}

	REP(j,m) {
		oe[j] = (oe[j] xor b[i][j]);
	}

	ll b = dfs(i + 1) + 1;

	REP(j,m) {
		oe[j] = save[j];
	}

	return max(a,b);
}

ll dfs(ll i ,ll S) {
	if(i == n) {
		if(S == 0) {
			return 0;
		}
		return -INF;
	}
	if(dp[i][S] > -INF - 100)
		return dp[i][S];

	ll a = dfs(i + 1,S);

	ll S2 = 0;
	RREP(j,m) {
		S2 *= 2;
		S2 += (((S >> j) & 1) xor b[i][j]);
	}
	ll b = dfs(i + 1,S2) + 1;
	return dp[i][S] = max(a,b);
}

int main(){
	while(true) {
		cin >> n >> m;
		if(n == 0)
			break;
		REP(i,n) 
			cin >> b[i];

		REP(i,n) {
			REP(j,m) {
				b[i][j] -= '0';
			}
		}
		if(m > 20) {
			REP(i,m) {
				oe[i] = 0;
			}
			cout << dfs(0) << endl;
		}else {
			/*dp.clear();
			REP(i,n + 10) {
				vector<ll> v;
				dp.push_back(v);
				REP(j,(1 << m) + 10) 
					dp[i].pb(-INF - 100);
			}*/
			REP(i,n + 1) {
				REP(j,(1 << m) + 1) {
					dp[i][j] = -INF - 100;
				}
			}
			cout << dfs(0,0) << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 115272
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: String,
        t: String,
    };

    let mut count = 0;
    for i in 0..s.len() {
        if s.as_bytes()[i] != t.as_bytes()[i] {
            count += 1;
        }
    }

    println!("{}", count);
}


Measured memory_bytes: 2824
N, A, B = map(int, input().split())

ans = 0
for i in range(1, N+1):
  wa = i//10000 + (i//1000)%10 + (i//100)%10 + (i//10)%10 +i%10
  if A <= wa and wa <= B:
    ans += i
print (ans)

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

int main()
{
    int n, quota;
    cin >> n >> quota;
    
    queue<pair<string, int>> q;
    for (int i = 0; i < n; i++) {
        string s;
        int t;
        cin >> s >> t;
        q.push(make_pair(s, t));
    }
    
    int t = 0;
    while (!q.empty()) {
        auto p = q.front();
        q.pop();
        t += min(p.second, quota);
        p.second -= min(p.second, quota);
        if (p.second == 0) {
            cout << p.first << " " << t << endl;
        } else {
            q.push(p);
        }
    }
    return 0;
}


Measured memory_bytes: 6196
N = int(input())
card = list(map(int, input().split()))
dic = {}
for i in card:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
ans = 0
for value in dic.values():
    if value > 1:
        ans += value - 1
print(N-(ans+(ans % 2)))

Measured memory_bytes: 18272
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let v: Vec<usize> = read_vec();
    let (n, k) = (v[0], v[1]);
    let mut ans = 0;
    if n >= 2 {
        ans += n * (n - 1) / 2;
    }
    if k >= 2 {
        ans += k * (k - 1) / 2;
    }
    println!("{}", ans);
}


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

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

  int count[n] = {0};
  rep(i, m)
  {
    cin >> a >> b;
    count[a-1]++;
    count[b-1]++;
  }

  rep(i, n)
  {
    cout << count[i] << endl;
  }

}


Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for (int i = (a); i < (int)(n); i++)
#define repc(i, a, n) for (int i = (a); i <= (int)(n); i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init)                                              \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
#define DBG(str) // cerr<<(str)<<endl;
int main() {
  int n;
  cin >> n;
  vector<int> l(n + 1, 0), r(n + 1, 0);
  rep(i, 0, n) { cin >> l[i] >> r[i]; }
  sort(all(l), greater<int>());
  sort(all(r));
  ll ma = 0;
  ll sum = 0;
  rep(i, 0, n + 1) {
    sum += 2 * (l[i] - r[i]);
    ma = max(ma, sum);
  }
  cout << ma;

  return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m; cin >> n >> m;
    if (n >= m) { cout << 0 << endl; return 0; }
    int sum = 0;
    int x[m]; for (int i = 0; i < m; ++i) cin >> x[i];
    sort(x, x + m);
    //m - 1個の区間を選ばなくていい
    for (int i = 0; i < m - 1; ++i) x[i] = x[i + 1] - x[i];
    x[m - 1] = 0;
    for (int i = 0; i < m; ++i) sum += x[i];
    sort(x, x + m, greater<int>());
    int notchoose = 0;
    for (int i = 0; i < n - 1; ++i) notchoose += x[i];
    cout << sum - notchoose << endl;
    
    
}


Measured memory_bytes: 640
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 0;
        HashMap<String, Integer> map = new HashMap<String, Integer>();
        for(int i = 0; i < n; i++){
            char[] c = sc.next().toCharArray();
            Arrays.sort(c);
            String s = String.valueOf(c);
            if(map.containsKey(s)){
                map.put(s,map.get(s)+1);
            }else{
                map.put(s,1);
            }
        }
        for(Map.Entry<String, Integer> entry : map.entrySet()){
		    ans += calcComb(entry.getValue());
		}
        System.out.println(ans);
    }

    static long calcComb(int n){
        long ret = (long)n;
        return ((ret*ret)-ret)/2;
    }
}



Measured memory_bytes: 53424
# -*- coding: utf-8 -*-
H, W = map(int, input().split())
inputs = [input() for _ in range(H)]
canvas = [char for char in inputs]


def isSpace(canvas, i, j):
    if i in range(len(canvas)):
        if j in range(len(canvas[i])):
            return True if canvas[i][j] == "." else False
        else:
            return True
    else:
        return True


def isPaintableCanvasBySquare(canvas):
    H = len(canvas)
    W = len(canvas[0])
    for i, j in [(i, j) for i in range(H) for j in range(W)]:
        if(isSpace(canvas, i, j - 1) and
           isSpace(canvas, i, j + 1) and
           isSpace(canvas, i - 1, j) and
           isSpace(canvas, i + 1, j) and
           not isSpace(canvas, i, j)):
            return "No"
    return "Yes"


print(isPaintableCanvasBySquare(canvas))


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	string s;
	cin>>s;
	rep(i,s.size()){
	    if(i==3)cout<<"8";
	    else cout<<s[i];
	}
	return 0;
}


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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int x,y,z; cin>>x>>y>>z;
	x-=z;
	cout << x/(y+z) << endl;
	return 0;
}


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


int main() {
    int N;
    cin >> N;
    
    vector<int> a(N);
    for (int i=0; i<N; i++) {
        cin >> a[i];
    }
    
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    
    int ans = 0;
    
    for (int i=0; i<N-1; i+=2) {
        ans += a[i] - a[i+1];
    }
    if (N%2 != 0) ans += a[N-1];
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){
    long long int a, b, c, n, i, j, min, ans=0;
    scanf("%lld", &n);
    if(n>=10) ans += 9;
    else ans += n;
    if(n>=100){
        if(n>=1000) ans += 900;
        else ans += n-99;
    }
    if(n>=10000){
        if(n>=100000) ans += 90000;
        else ans += n-9999;
    }
    printf("%lld", ans);
}

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

int main(){
    int64_t N;
    cin >> N;
    double n = sqrt(N);
    int ans = to_string(N).size();
    for (int i=1; i<n+1; i++){
        if (N % i== 0){
            int v;
            v = max(to_string(i).size(), to_string(N/i).size());
            ans = min(ans, v);
        }
    }
    cout << ans << endl;
}

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

int main() {
    int k;
    string s;
    cin >> k >> s;
    if (s.size() <= k) {
        cout << s << endl;
    }
    else {
        rep(i,k) {
            cout << s[i];
        }
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3624
import java.util.*;
import java.io.*;
import java.lang.Math;

public class Main {
	public static void main(String[] args){
		Scanner cin = new Scanner(System.in);
		ArrayList<Integer> a = new ArrayList<Integer>(6);
		for(int i = 0; i < 6; i++){
			a.add(cin.nextInt());
		}
		for(int i = 0; i < a.size() - 1; i++){
			for(int j = 0; j < a.size() - 1; j++){
				if(Math.abs(a.get(i) - a.get(j)) > a.get(5)){
					System.out.println(":(");
					System.exit(0);
				}
			}
		}	
		System.out.println("Yay!");
	}
}

Measured memory_bytes: 35692
#include <string.h>
#include <stdio.h>

long long dp[100][21];
int n;
int nums[100];

long long calc(int now, int sum){
	if (now == n - 1){
		return sum == nums[now];
	}
	if (sum < 0 || 20 < sum){
		return 0;
	}
	if (~dp[now][sum]){
		return dp[now][sum];
	}

	long long res = calc(now + 1, sum + nums[now]) + !!(now)* calc(now + 1, sum - nums[now]);

	return dp[now][sum] = res;
}

int main(){
	memset(dp, -1, sizeof(dp));
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%d", &nums[i]);
	}
	printf("%lld\n", calc(0, 0));
	return 0;
}

Measured memory_bytes: 1052
// なんもわからん

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define DEBUG(x) cout<<#x<<": "<<(x)<<endl

int n;
char s[5252];

const ll MOD1 = 998244353;
const ll MOD2 = 1000000181;
const ll MOD3 = 1000000207;
const ll B1 = 10007;
const ll B2 = 10009;
const ll B3 = 1000000007;

int main(){
	scanf("%d",&n);
	scanf("%s",s);

	int ok = 0, ng = n;
	while(abs(ok-ng)>1){
		int l = (ok+ng)/2;
		vector<pair<pii,int>> hashes;
		ll h1 = 0, h2 = 0, h3 = 0;
		ll b1 = 1, b2 = 1, b3 = 1;
		REP(i,l){
			h1 = (h1*B1 + s[i])%MOD1;
			h2 = (h2*B2 + s[i])%MOD2;
			h3 = (h3*B3 + s[i])%MOD3;
			b1 = b1*B1%MOD1;
			b2 = b2*B2%MOD2;
			b3 = b3*B3%MOD3;
		}
		FOR(i,l,n){
			hashes.push_back(make_pair(pii(h1,h2),h3));
			h1 = (h1*B1 + s[i]) % MOD1;
			h1 = (h1 + MOD1 - b1*s[i-l]%MOD1) % MOD1;
			h2 = (h2*B2 + s[i]) % MOD2;
			h2 = (h2 + MOD2 - b2*s[i-l]%MOD2) % MOD2;
			h3 = (h3*B3 + s[i]) % MOD3;
			h3 = (h3 + MOD3 - b3*s[i-l]%MOD3) % MOD3;
		}
		hashes.push_back(make_pair(pii(h1,h2),h3));
		if(hashes.size() <= l){
			ng = l;
			continue;
		}
		set<pair<pii,int>> S;
		bool found = false;
		FOR(i,l,hashes.size()){
			S.insert(hashes[i-l]);
			if(S.count(hashes[i])){
				found = true;
				break;
			}
		}
		(found ? ok : ng) = l;
	}
	printf("%d\n",ok);
	return 0;
}


Measured memory_bytes: 672
#include <iostream>

using namespace std;

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

  char ans[10005] = {'\0'};
  for(int i=0; i<s.size(); i++){
    char ss = s[i];
    ss += n - 65;
    ss %= 26;
    ans[i] = char(ss+65);
  }
  cout << ans << endl;
  return 0;
}


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

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

using namespace std;

using ll = long long;

int main() {
    int N, M;
    cin >> N >> M;
    priority_queue<int> q;
    REP(i, N) {
        int A;
        cin >> A;
        q.push(A);
    }
    REP(_, M) {
        int x = q.top();
        q.pop();
        q.push(x / 2);
    }
    ll result = 0;
    while (!q.empty()) {
        result += q.top();
        q.pop();
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
string s; 
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>s;
	if(s=="hi"||s=="hihi"||s=="hihihi"||s=="hihihihi"||s=="hihihihihi")cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pii             pair<int , int >
#define in(a)           scanf("%d", &a)
#define in2(a, b)       scanf("%d%d", &a, &b)
#define in3(a, b, c)    scanf("%d%d%d", &a, &b, &c)
#define piil            pair<ll , ll >
#define inl(a)          scanf("%lld", &a)
#define inl2(a, b)      scanf("%lld%lld", &a, &b)
#define inl3(a, b, c)   scanf("%lld%lld%lld", &a, &b, &c)
#define ins(s)          scanf("%s",s)
#define prst(s)         printf("%s\n",s)
#define pn              printf("\n")
#define pr(a)           printf("%d\n", a)
#define prl(a)          printf("%lld\n", a)
#define prs(a)          printf("%d ", a)
#define pr2(a, b)       printf("%d %d\n", a, b)
#define pr3(a, b, c)    printf("%d %d %d\n", a, b, c)
#define prsl(a)         printf("%lld ", a)
#define prl2(a, b)      printf("%lld %lld\n", a, b)
#define prl3(a, b, c)   printf("%lld %lld %lld\n", a, b, c)
#define pcs(a)          printf("Case %d: ", a)
#define pf              printf
#define sc              scanf
#define m_p             make_pair
#define vi              vector<int >
#define vil             vector<ll >
#define pb              push_back
#define mem(a, b)       memset((a), (b), sizeof(a))
#define lg2(n)         (31-__builtin_clz(n))
#define PI		acos(-1.0)
#define N 2000010
#define debug(a)	cout<<"debug "<<a<<endl;
#define inf 2e18
#define ll long long
#define ull unsigned long long
#define MIN INT_MIN
#define MAX INT_MAX
#define __  std::ios_base::sync_with_stdio (false); cin.tie(0); cout.tie(0);
#define Check(n, pos) (n & (1<<pos))
#define Set(n, pos) (n | (1<<pos))
ll gcd(ll a, ll b){if(b==0) {return a;}return gcd(b, a % b);}
using namespace std;
ll BigMod(ll B,ll P,ll M){     ll R=1; while(P>0)      {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;}
ll histogram(ll arr[],ll n) {  stack<int>s;  int area=0,i=0;  while(i<n) { if(s.empty() || arr[s.top()]<=arr[i]) s.push(i++); else { int tp=s.top(); s.pop(); int xx=arr[tp]*(s.empty() ? i : i - s.top() - 1);area=max(area,xx);}}while(!s.empty()){ int tp=s.top(); s.pop(); int xx=arr[tp]*(s.empty() ? i : i - s.top() - 1); area=max(area,xx); } return area;}
//___________________________________________________________________________________________________________________
ll dp[N],arr[N];
char str[N];
int main()
{
   ll n,m,k,a,b;
   ll sum=0;
   string s;
    cin>>n>>m;
    if(n==1)
    {
        cout<<1<<endl;
        return 0;
    }
   k=n-m+1;
   cout<<k<<endl;

    return 0;
}



Measured memory_bytes: 256
/* 解説より
S の長さを n、S の左から k 番目の数字を ak とします。
左から k + 1 文字目以降の数字列を整数とみなした時の値 an + 10an−1 + ... + 10n−k−1ak+1 を
Tk とします (Tn = 0)。 すると、(i, j) が条件をみたすのは Ti−1 == Tj (mod2019) のときです。
各 Timod2019 を計算し、mod の値が同じごとに個数を計算して足したものが答えです。Ti =
Ti+1 + 10n−i−1ai より、これは DP で計算でき、mod ごとに m(m − 1)/2 (m は Timod2019 があ
る値になる 0 ≤ i ≤ n の個数) を足せば良いです。
*/

fn main() {
    proconio::input! {
        s: String,
    }
    let mut cmap = std::collections::HashMap::new(); // Tk mod 2019をkeyとするカウンタ
    cmap.insert(0, 1); // 0 のカウンタだけ1で初期化(Tn=0に対応)

    let mut tmp = 1; // 10^k % 2019 (k=0,1,...n) を保持する変数.
    let mut dp = 0; // 一つ前のTを覚えておく
    for c in s.chars().rev() {
        let n = c.to_digit(10).unwrap();
        // カウンター更新
        let key = (dp + n * tmp) % 2019; 
        let cnt = cmap.entry(key).or_insert(0);
        *cnt += 1;
        // 次のkのために DP更新,10^k % 2019 を計算しておく
        dp = key;
        tmp = (tmp * 10) % 2019;
        // println!("{} {}", c, key)
    }
    println!("{}", cmap.values().map(|n| n*(n-1)/2).sum::<i32>());


}

Measured memory_bytes: 2440
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;
void solve(){
  int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
  string ans = "";
  for(int i = 0; i < tx - sx; i++) ans += "R";
  for(int i = 0; i < ty - sy; i++) ans += "U";
  for(int i = 0; i < tx - sx; i++) ans += "L";
  for(int i = 0; i < ty - sy; i++) ans += "D";
  ans += "D";
  for(int i = 0; i < tx - sx + 1; i++) ans += "R";
  for(int i = 0; i < ty - sy + 1; i++) ans += "U";
  ans += "LU";
  for(int i = 0; i < tx - sx + 1; i++) ans += "L";
  for(int i = 0; i < ty - sy + 1; i++) ans += "D";
  ans += "R\n";
  cout << ans;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
n=int(input())
ab=[tuple(map(int,input().split())) for _ in range(n)]
cd=[tuple(map(int,input().split())) for _ in range(n)]
ab=sorted(ab,key=lambda x:x[1],reverse=True)
cd=sorted(cd)
for c,d in cd:
    for a,b in ab:
        if a<c and b<d:
            ab.remove((a,b))
            break
print(n-len(ab))

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

int main() {
	int n, max;
	while(true){
		cin >> n >> max;
		if(n == 0 && max ==0) break;
		if(n == 0 && max == 0) return 0;
		int count = 0;
		for(int i = 1; i <= n; i++){
			for(int j = i+1;j <= n; j++){
				for(int k = j+1; k <= n; k++){
					if(i + j + k == max) count++;
				}
			}
		}
		cout << count << endl;
	}
	// your code goes here
	return 0;
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  if(s[0] == s[1] || s[1] == s[2] || s[2]==s[3]){
    cout << "Bad" << endl;
  }else{
    cout << "Good" << endl;
  }
}


Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong bignum = 1_000_000_007;
alias Pair = Tuple!(long, "number", long, "times");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long n, k;
    scan(n, k);
    auto inputary = new Pair[](n);
    foreach (ref e; inputary)
    {
        long a, b;
        scan(a, b);
        e = Pair(a, b);
    }
    inputary.sort!"a.number < b.number"();
    long limit;
    foreach (e; inputary)
    {
        if(limit + e.times >= k)
        {
            e.number.writeln();
            break;
        }
        
        limit += e.times;
    }
}

Measured memory_bytes: 4476