akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long int lli;
int xh[100],yh[100],zh[100];
int bmx[50][2],xc;
int bmy[50][2],yc;
int bmz[50][2],zc;
int n,p;
int main(void){
  scanf("%d%d",&n,&p);
  int i,j,k,m;
  xc=0;yc=0;zc=0;
  for(i=0;i<n;i++){
    scanf("%d%d%d",&(bmx[i][0]),&(bmy[i][0]),&(bmz[i][0]));
    scanf("%d%d%d",&(bmx[i][1]),&(bmy[i][1]),&(bmz[i][1]));
    xh[xc]=bmx[i][0];xc++;
    yh[yc]=bmy[i][0];yc++;
    zh[zc]=bmz[i][0];zc++;
    xh[xc]=bmx[i][1];xc++;
    yh[yc]=bmy[i][1];yc++;
    zh[zc]=bmz[i][1];zc++;
  }
  sort(xh,xh+xc);
  sort(yh,yh+yc);
  sort(zh,zh+zc);
  int mc;
  int ms;
  mc=xc;
  ms=xh[0];
  xc=0;
  for(i=1;i<mc;i++){
    if(ms!=xh[i]){
      xc++;
      ms=xh[i];
      xh[xc]=xh[i];
    }
  }
  mc=yc;
  ms=yh[0];
  yc=0;
  for(i=1;i<mc;i++){
    if(ms!=yh[i]){
      yc++;
      ms=yh[i];
      yh[yc]=yh[i];
    }
  }
  mc=zc;
  ms=zh[0];
  zc=0;
  for(i=1;i<mc;i++){
    if(ms!=zh[i]){
      zc++;
      ms=zh[i];
      zh[zc]=zh[i];
    }
  }
  lli ans=0;
  int co=0;
  for(i=0;i<xc;i++){
    for(j=0;j<yc;j++){
      for(k=0;k<zc;k++){
	co=0;
	for(m=0;m<n;m++){
	  if(xh[i]>=bmx[m][0] && xh[i+1]<=bmx[m][1] &&
	     yh[j]>=bmy[m][0] && yh[j+1]<=bmy[m][1] &&
	     zh[k]>=bmz[m][0] && zh[k+1]<=bmz[m][1]){
	    co++;
	  }
	}
	if(co>=p){
	  ans+=(lli)(xh[i+1]-xh[i])*(lli)(yh[j+1]-yh[j])*(lli)(zh[k+1]-zh[k]);
	  //printf("%d %d %d\n",i,j,k);
	}
      }
    }
  }
  /*printf("%d %d %d\n",xh[0],xh[1],xc);
  printf("%d %d %d\n",yh[0],yh[1],yc);
  printf("%d %d %d\n",zh[0],zh[1],zc);*/
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 1044
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int [] a = new int [N];
		int [] b = new int [N];
		int [] c = new int [M];
		int [] d = new int [M];

		for (int i = 0; i < N;i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}

		for (int i = 0; i < M;i++) {
			c[i] = sc.nextInt();
			d[i] = sc.nextInt();
		}

		for (int i = 0; i < N; i++) {
			int min = Math.abs(a[i] - c[0]) + Math.abs(b[i] - d[0]);
			int count = 1;
			for (int j = 0; j < M; j++) {
				int sum = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);
				if (sum < min) {
					min = sum;
					count = j+1;
				}
			}
			System.out.println(count);
		}
	}
}


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

int main(){
  int N;
  bool isFour=false;
  cin >> N;
  
  for(int i=0;i<N;i++){
    string arare;
    cin>> arare;
    if(arare=="Y"){
      isFour=true;
    }
  }
  if(isFour){
    cout << "Four"<<endl;
  }else{
    cout << "Three"<<endl;
  }
}

Measured memory_bytes: 256
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     SPEED       ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	hell        1000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2);
	if(b%2==0)
		return((c%hell)*(c%hell))%hell;
	return ((((c%hell)*(c%hell))%hell)*(a%hell))%hell;
}

/********************************************************/
//	d.erase(unique(all(d)), d.end());




int main()
{
	SPEED;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		cin>>n>>m;
		// n=s.length();
		// ll a[n];
		if(n>=13)
			c=m;
		else if(n>=6)
			c=m/2;
		else c=0;
		cout<<c;
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 764
#include <string>
#include <cstdint>
#include <cassert>
#include <functional>
#include <vector>
#include <unordered_map>
#include <iostream>
namespace lc {
struct Edge {
	int to;
	explicit Edge(int to) : to(to) { }
};
}
namespace lc {
template <typename EdgeType>
class AdjacencyList {
public:
	typedef std::vector<EdgeType> ListType;
private:
	std::vector<ListType> m_lists;
public:
	explicit AdjacencyList(int n = 0)
		: m_lists(n)
	{ }
	int size() const { return m_lists.size(); }
	template <typename... Args>
	void add_edge(int u, Args&&... args){
		m_lists[u].emplace_back(args...);
	}
	const ListType &operator[](int u) const { return m_lists[u]; }
};
}
namespace lc {
template <typename EdgeType>
int enumerate_maximal_independent_sets(
	const AdjacencyList<EdgeType> &graph, const std::vector<int> &p)
{
	const int n = graph.size();
	std::vector<uint64_t> bit_graph(n), incr_bit_graph(n + 1);
	for(int i = n - 1; i >= 0; --i){
		uint64_t mask = (1ull << i);
		for(const auto &e : graph[i]){ mask |= (1ull << e.to); }
		bit_graph[i] = mask;
		incr_bit_graph[i] = mask | incr_bit_graph[i + 1];
	}
	std::function<int(int, int, uint64_t, uint64_t)> recur =
		[&, n](int i, int s, uint64_t picked, uint64_t eliminated) -> int {
			if(i == n){ return s; }
			const bool force_ignore = ((eliminated & (1ull << i)) != 0);
			int flags = 1; // 1: select v_i, 2: ignore v_i
			if(bit_graph[i] & ~(incr_bit_graph[i + 1] | eliminated)){
				flags = (force_ignore ? 2 : 1);
			}else if((incr_bit_graph[i + 1] | eliminated) & (1ull << i)){
				flags = (force_ignore ? 2 : 3);
			}
			if(i == 0){ flags = 1; }
			int answer = 0;
			if(flags & 1){
				answer = recur(
					i + 1, s + p[i], picked | (1ull << i),
					eliminated | bit_graph[i]);
			}
			if(flags & 2){
				answer = std::max(answer, recur(i + 1, s, picked, eliminated));
			}
			return answer;
		};
	return recur(0, 0, 0, 0);
}
}
namespace lc {
class NameTable {
private:
	std::unordered_map<std::string, int> m_table;
	std::vector<std::string> m_inv_table;
public:
	NameTable(){ }
	int operator[](const std::string &s){
		const auto it = m_table.find(s);
		if(it != m_table.end()){ return it->second; }
		const int t = m_inv_table.size();
		m_table.insert(std::make_pair(s, t));
		m_inv_table.push_back(s);
		return t;
	}
};
}
using namespace std;
typedef lc::Edge Edge;
int main(){
	ios_base::sync_with_stdio(false);
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		lc::NameTable name_table;
		vector<int> powers(n);
		lc::AdjacencyList<Edge> graph(n);
		for(int i = 0; i < n; ++i){
			string u_name;
			int p, m;
			cin >> u_name >> p >> m;
			const int u = name_table[u_name];
			powers[u] = p;
			for(int j = 0; j < m; ++j){
				string v_name;
				cin >> v_name;
				const int v = name_table[v_name];
				graph.add_edge(u, v);
			}
		}
		const int answer = lc::enumerate_maximal_independent_sets(graph, powers);
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 1256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
	int n,a[4000];
	static ll sum[4001],dp[4001][4001];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
		a[i+n] = a[i];
	}
	sum[0] = 0;
	for(int i=1;i<2*n+1;i++) sum[i] = sum[i-1] + a[(i-1)%n];
	for(int w=0;w<=n;w++){
		for(int i=0;i+w<2*n+1;i++){
			int j = i + w;
			if(w==0){
				dp[i][j] = 0;
			}else if(w==1||w==2){
				dp[i][j] = max(a[i],a[j-1]);
			}else{
				ll vl;
				if(a[i+1]>a[j-1]){
					vl = a[i] + dp[i+2][j];
				}else{
					vl = a[i] + dp[i+1][j-1];
				}
				ll vr;
				if(a[i]>a[j-2]){
					vr = a[j-1] + dp[i+1][j-1];
				}else{
					vr = a[j-1] + dp[i][j-2];
				}
				dp[i][j] = max(vl,vr);
			}
		}
	}
	ll ans = 0;
	for(int i=0;i<n;i++){
		ans = max(ans,dp[i][i+n]);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 65672
/**
 *   author: sahushivam
 *   created: 24 November 2019 (Sunday)  17:26:44
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,a,b) for(int i = a; i<b; i++)
#define MOD 1000000007
#define INF 1e18
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define int long long

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int t=1;
    string s;
    cin>>s;
    map<string,int> mp;
    mp["SUN"]=7;
    mp["MON"]=6;
    mp["TUE"]=5;
    mp["WED"]=4;
    mp["THU"]=3;
    mp["FRI"]=2;
    mp["SAT"]=1;
    cout<<mp[s]<<endl;
return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a, b, c;
    cin >> a >> b >> c;
    queue<int> A, B, C;
    rep(i,a.size()){
        A.push(a[i] - 'a');
    }
    rep(j,b.size()){
        B.push(b[j] - 'a');
    }
    rep(k,c.size()){
        C.push(c[k] - 'a');
    }
    int turn = 0;
    while(true){
        if(turn == 0){
            if(A.empty()){
                cout << "A" << endl;
                return 0;
            }
            turn = A.front();
            A.pop();
        }
        else if(turn == 1){
            if(B.empty()){
                cout << "B" << endl;
                return 0;
            }
            turn = B.front();
            B.pop();
        }
        else if(turn == 2){
            if(C.empty()){
                cout << "C" << endl;
                return 0;
            }
            turn = C.front();
            C.pop();
        }
    }
    return 0;
}

Measured memory_bytes: 3652
x=input().split()
a=int(x[0])
b=int(x[1])
c=int(x[-1])
n=0
if b>=c:
    n+=b+c
    print(n)
else:
    n+=2*b
    c-=b
    if a>=c:
        n+=c
        print(n)
    else:
        n+=a+1  
        print(n)


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

int main(){
	int N;
	cin >> N;
	vector<int> vec (N);
	int count = 0;
	for(int i = 0;i<N;i++){
		cin >> vec.at(i);
		if(vec.at(i) % 2 == 1){
			count++;
		}
	}
	if(count % 2 == 1){
		cout << "NO" << endl;
	}
	else{
		cout << "YES" << endl;
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
using namespace std;
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define max(a,b) (a>b?a:b)
string s, t, res;
int n, m;
vector<vector<int>> dp;
int32_t main() {
    IOS;
    int i = 1, j = 1;
    cin >> s >> t;
    n = sz(s), m = sz(t);
    dp.resize(n+1, vector<int>(m+1));
    for(i = 1; i <= n; i++) {
        for(j = 1; j <= m; j++) {
            if (s[i-1] == t[j-1])
                dp[i][j] = 1 + dp[i-1][j-1];
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    //cout << dp[n][m] << endl;
    i = n, j = m;
    while(i and j) {
        if (dp[i][j] == dp[i-1][j]) 
            i--;
        else if (dp[i][j] == dp[i][j-1]) 
            j--;
        else 
            res += s[i-1], i--, j--;
    }
    reverse(all(res));
    cout << res;
    return 0;
}

Measured memory_bytes: 35584
n=gets.to_i
array=gets.split.map(&:to_i)
absarray=array.map{|i| i.abs}
min=absarray.min
sum=absarray.inject(:+)

if array.include?(0)
    puts sum
    exit
end

(n-1).times{|i|
    if array[i]<0
        array[i]*=(-1)
        array[i+1]*=(-1)
    end
    i+=1
}

if array[-1]>0
    puts sum
else
    puts sum-min-min
end

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

int main() {
  int n, x;
  cin >> n >> x;
  int cnt = 0;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
    x -= vec.at(i);
    cnt++;
  }
  sort(vec.begin(), vec.end());
  while(x>=0) {
    x -= vec.at(0);
    if (x >= 0)
    {
      cnt++;
    }
    
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
l=[]
for i in range(3):
  a,b=map(int,input().split())
  l.append(a)
  l.append(b)
w=0
x=0
y=0
z=0
for i in range(6):
  if l[i]==1:
    w+=1
  elif l[i]==2:
    x+=1
  elif l[i]==3:
    y+=1
  else:
    z+=1
if x==0 or y==0 or z==0 or w==0:
  print('NO')
elif w>2 or x>2 or y>2 or z>2:
  print('NO')
else:
  print('YES')

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

int main() {
string S;
cin >> S;
int cnt = 0;
for (int i = 1;i < S.size();i++) {
    if (S.at(i-1) == '0' && S.at(i) == '0') {
        cnt += 1;
        S.at(i) = '1';
    } else if (S.at(i-1) == '1' && S.at(i) == '1') {
        cnt += 1;
        S.at(i) = '0';  
}
}
cout << cnt << endl;


return 0;
}


Measured memory_bytes: 512
#!venv/bin/python
#from collections import defaultdict 
from itertools import combinations
import math
import datetime
import sys
# L, R = [int(x) for x in input().split()]

S = int(input())
x1 = x2 = y1 = y2 = 0

def print_ans_exit():
    print("0 0 {} {} {} {}".format(x1,y1,x2,y2))
    sys.exit()

square_ele = math.floor(math.sqrt(S))

if square_ele ** 2 == S:
    x1 = y2 = square_ele
    x2 = 0
    y1 = 1
    print_ans_exit()

if square_ele * (square_ele + 1) == S:
    x1 = square_ele
    y2 = square_ele + 1
    x2 = 0
    y1 = 1
    print_ans_exit()
if square_ele * (square_ele + 1) > S:
    x2y1 = square_ele * (square_ele + 1) - S
    x1 = square_ele
    y2 = square_ele + 1
    x2 = 1
    y1 = x2y1
    print_ans_exit()
else:
    x2y1 = (square_ele + 1) * (square_ele + 1) - S
    x1 = y2 = square_ele + 1
    x2 = 1
    y1 = x2y1
    print_ans_exit()


Measured memory_bytes: 3440
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Stack;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        Stack<Integer> stack = new Stack<Integer>();
        while ((line = reader.readLine()) != null && !line.isEmpty()) {
            int n = Integer.parseInt(line);
            if (n == 0) {
                out.println(stack.pop());
            } else {
                stack.push(n);
            }
        }
    }
}

Measured memory_bytes: 9100
#include <iostream>
using namespace std;
int h,w;
int G[1000][1000];
int dx[] = {-1,0,1,-1,1,-1,0,1},dy[] = {-1,-1,-1,0,0,1,1,1};

void dfs(int px,int py){
  G[px][py] = 0;
  for(int i = 0 ; i < 8 ; i++ ){
    int nx = px + dx[i],ny = py + dy[i];
    if(0 <= nx && nx < w && 0 <= ny && ny < h && G[nx][ny] == 1){
      dfs(nx,ny);
    }
  }
}

int main(){
  while( cin >> w >> h,w+h){

    for(int i = 0 ; i < h ; i++){
      for(int j = 0 ; j < w ; j++){
	cin >> G[j][i];
      }
    }

    int cnt = 0;
    for(int i = 0 ; i < h ; i++){
      for(int j = 0 ; j < w ; j++){
	if(G[j][i] == 1){
	  dfs(j,i);
	  cnt++;
	}
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 1424
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

int a[1000010],calc[1000010],pw2[1000010];

signed main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		int val=0,p=i;
		while(p%2==0){
			p/=2;val++;
		}
		pw2[i]=pw2[i-1]+val;
	}
	for(int i=1;i<=n;i++){
		int cnt=pw2[n-1]-pw2[i-1]-pw2[n-i];
		if(cnt==0) calc[i]=1;
	}
	bool flag0=0,flag1=0,flag2=0;
	for(int i=1;i<=n;i++){
		char c;
		cin>>c;
		a[i]=c-'1';
		if(a[i]==0) flag0=1;
		if(a[i]==1) flag1=1;
		if(a[i]==2) flag2=1;
	}
	if(flag0&&flag1&&flag2){
		for(int i=1;i<=n;i++) if(a[i]==2) a[i]=0;
		int ans=0;
		for(int i=1;i<=n;i++) if(calc[i]) ans^=a[i];
		cout<<ans<<endl;
		return 0;
	}
	if(!flag0){
		if(!flag1){
			for(int i=1;i<=n;i++) a[i]-=2;
		}
		else{
			for(int i=1;i<=n;i++) a[i]--;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++) if(calc[i]) ans^=a[i];
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	while (1) {
		string s;
		cin >> s;
		if (s == "0")
			break;
		int sum = 0;
		for (int i = 0; i < s.size(); i++) {
			sum += s[i] - '0';
		}
		cout << sum << endl;
	}
}



Measured memory_bytes: 3204
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;



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

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

	int c[10][10];

	for (int i = 0; i < 10; ++i)
		for (int j = 0; j < 10; ++j)
			cin >> c[i][j];
	
	for (int k = 0; k < 10; ++k)
		for (int i = 0; i < 10; ++i)
			for (int j = 0; j < 10; ++j)
				if (c[i][k] + c[k][j] < c[i][j]) c[i][j] = c[i][k] + c[k][j];

	int cost = 0;
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			int x;
			cin >> x;

			if (x != -1) cost += c[x][1];
		}
	}

	cout << cost;
	
	//system("pause");

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
string s;
main()
{
	cin>>s;
	int ans=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='D')ans++;
		else if(s[i]=='?')
		{
			ans++;
			s[i]='D';
		}
	}
	for(int i=0;i+1<s.size();i++)
	{
		if(s[i]=='P'&&s[i+1]=='D')ans++;
	}
	cout<<s<<endl;
}


Measured memory_bytes: 3764
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N;
    string S;
    cin >> N >> S;

    // string repeat = S + S;
    // cout << repeat << endl;
    vector<vector<ll>> next(N), vertical(N);
    Rep (i, N) {
        char target = S[i];
        for (ll j = 1; i+j < N; j++) {
            if (S[i+j] == target) {
                next[i].push_back(j);
                vertical[j].push_back(i);
            }
        }
    }

    // for (auto e : vertical) {
    //     for (ll f : e) {
    //         cout << f << " ";
    //     }
    //     cout << endl;
    // }

    ll ans = 0;
    Rep (i, N) {
        ll cnt = vertical[i].size();
        if (cnt == 0) continue;
        ll tmp = 1, subans = 0;
        Rep (j, cnt-1) {
            if (vertical[i][j] + 1 == vertical[i][j+1]) {
                tmp++;
            } else {
                subans = max(subans, tmp);
                tmp = 1;
            }
        }

        subans = max(subans, tmp);
        subans = min(subans, i);
        ans = max(subans, ans);
    }

    cout << ans << endl;

}

Measured memory_bytes: 243328
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	char a,b;
	cin>>a>>b;
	cout<<(a<b?"<":(a==b?"=":">"))<<endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from math import gcd
def main():
    K = int(input())
    ans = 0
    for i in range(1, K+1):
        for j in range(1, K+1):
            for k in range(1, K+1):
                g = gcd(i, j)
                g = gcd(g, k)
                ans += g
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 69936
K = int(input())
List = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(List[K-1])

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

using namespace std;

class UnionFind{
public:
    vector<int> parent;
    UnionFind(int n){
        parent = vector<int>(n, -1);
    }
    int root(int a){
        if(parent[a]<0) return a;
        return parent[a] = root(parent[a]);
    }
    int size(int a){
        return -parent[root(a)];
    }
    int connect(int a, int b){
        a = root(a);
        b = root(b);
        if(a == b){
            return false;
        }
        if(size(a)<size(b)) swap(a, b);
        parent[a]+=parent[b];
        parent[b]=a;
        return true;
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    int a[m], b[m];
    for(int i=0;i < m;i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    UnionFind uf(n);
    long long ans[m];
    ans[m-1]=(long long)n*(n-1)/2;
    for(int i=m-1;i>=1;i--){
        ans[i-1] = ans[i];
        if(uf.root(a[i]) != uf.root(b[i])){
            ans[i-1] = ans[i]-(long long)uf.size(a[i])*uf.size(b[i]);
            uf.connect(a[i], b[i]);
        }
    }
    for(int i=0;i<m;i++) cout << ans[i] << endl;
    return 0;
};


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<long long> Subsum(N,0);
	cin >> Subsum[0];
	for (int i = 1; i < N; i++) {
		int a;
		cin >> a;
		Subsum[i] = Subsum[i - 1] + a;
	}
	long long MIN = 2 * pow(10, 14);
	for (int i = 0; i < N - 1; i++) MIN = min(MIN, abs(Subsum[N - 1] - 2 * Subsum[i]));
	cout << MIN << endl;
}


Measured memory_bytes: 1792
def w2l(w)
  return "light fly" if w <= 48.00
  return "fly" if w <= 51.00
  return "bantam" if w <= 54.00
  return "feather" if w <= 57.00
  return "light" if w <= 60.00
  return "light welter" if w <= 64.00
  return "welter" if w <= 69.00
  return "light middle" if w <= 75.00
  return "middle" if w <= 81.00
  return "light heavy" if w <= 91.00
  return "heavy"
end

### main

while (line = gets)
  w = line.chomp.to_f
  puts w2l(w)
end

Measured memory_bytes: 6100
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
  // 整数の入力
  ll N;
  cin >> N;
  ll continueation = 0;
  ll max_continueation = 0;
  for(int i = 0;i < N;i++){
    ll d1, d2;
    cin >> d1 >> d2;
    if (d1 == d2){
      continueation++;
    }else{
      continueation = 0;
    }
    max_continueation = max(max_continueation,continueation);
  }
  if (max_continueation >= 3){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
 return 0;
}

Measured memory_bytes: 3592
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
///////////////////////////////////////////////////////////


int n;
vector<string> ans;
void dfs(string s,int j,int x){
    s += ('a' + j);
    if(s.size() == n)ans.pb(s);
    else{
        for(int i = 0;i < x;i++){
            dfs(s,i,x);
        }
        dfs(s,x,x+1);
    }
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    cin >> n;
    dfs("",0,1);
    sort(all(ans));
    ans.erase(unique(ans.begin(), ans.end()), ans.end());
    for(auto i : ans)cout << i << '\n';
    return 0;
}



Measured memory_bytes: 7796
/*Rabbi Zidni Ilma*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define scl(n) scanf("%lld",&n)
#define scll(n,m) scanf("%lld%lld",&n,&m)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define mod 10000007
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)


int main()
{
	ll a,b,c,d,ans,x,y,p,q;
    cin >> a >> b >> c >> d;
    x=a*c;
    y=a*d;
    p=b*c;
    q=b*d;
    ans=max(max(x,y),max(p,q));
    printf("%lld\n",ans);
}

Measured memory_bytes: 3756
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define int long long
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
    const int MAX =200005;
const int MOD =1000000007;
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}
signed main(){
  int n;
  cin>>n;
  int m=2*n;
  vector<int> v;
  for(int i=2;i*i<=2*n;i++){
    int j=1;
    while(m%i==0){
      m/=i;
      j*=i;
    }
    if(j!=1)v.push_back(j);
  }
  if(m!=1)v.push_back(m);
  int w=v.size();
  int ans=2*n-1;
  for(int i=1;i<(1ll<<w)-1;i++){
    int b=1;
    for(int j=0;j<v.size();j++)if(i&(1ll<<j))b*=v[j];
    int a=2*n/b;
    int x,y;
    if(extGCD(-a,b,x,y)==-1){
      x*=-1;
      y*=-1;
    }
   // cerr<<a<<' '<<b<<' '<<x<<' '<<y<<' '<<-a*x+b*y<<' ';
    int t;
    if(x*a>0)t=-x*a/(a*b);
    else t=abs(x*a)/(a*b) +1;
    //cerr<<x*a+t*a*b<<endl;
    ans=min(ans,x*a+t*a*b);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3640
n = int(input())
h = list(map(int,input().split()))

anss = []
cnt = 0
for i in range(n):
    if i == 0: continue
    if h[i] <= h[i-1]: cnt += 1
    else: anss.append(cnt); cnt = 0
    if i == n-1 : anss.append(cnt)

try: print(max(anss))
except: print(0)


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

int main() {
  int A, B;
  cin >> A >> B;
  int answer = -1;
  if (1<=A && A<=9) {
    if (1<=B && B<=9) {
      answer = A*B;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

enum P = 10L^^9+7;

void main()
{
    auto S = readln.chomp;
    auto DP = new long[][](S.length, 4);
    foreach (ref dp; DP) dp[] = -1;
    long solve(int i, int s) {
        if (i == S.length) return s == 3 ? 1 : 0;

        if (DP[i][s] == -1) {
            long r;
            auto c = S[i];
            if (c == 'A' || c == '?') {
                r = (r + solve(i+1, s)) % P;
                if (s == 0) r = (r + solve(i+1, s+1)) % P;
            }
            if (c == 'B' || c == '?') {
                r = (r + solve(i+1, s)) % P;
                if (s == 1) r = (r + solve(i+1, s+1)) % P;
            }
            if (c == 'C' || c == '?') {
                r = (r + solve(i+1, s)) % P;
                if (s == 2) r = (r + solve(i+1, s+1)) % P;
            }
            DP[i][s] = r;
        }
        return DP[i][s];
    }
    writeln(solve(0, 0));
}

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

typedef pair<string, int> P;

int main()
{
	P run[4][8];
	vector<P> sub;
	
	for (int i = 0; i < 3; i++){
		for (int j = 0; j < 8; j++){
			cin >> run[i][j].second >> run[i][j].first;
		}
		sort(run[i], run[i] + 8);
		
		for (int j = 2; j < 8; j++){
			sub.push_back(run[i][j]);
		}
	}
	sort(sub.begin(), sub.end());
	run[3][0] = sub[0];
	run[3][1] = sub[1];
	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 2; j++){
			cout << run[i][j].second << " " << run[i][j].first << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <string>
using namespace std;

int main(){
    char c[2][3];
    for ( int i = 0 ; i < 2 ; i++){
        for ( int j = 0 ; j < 3 ; j++) cin >> c[i][j];
    }
    if ( c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0]){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<math.h>
using namespace std;

int main()
{
	int i,n,flg;
	double x1,x2,x3,y1,y2,y3;
	double m1,m2,xm1,xm2,ym1,ym2,px,py,r;
	//m1,m2…辺の法線 xm1,ym1…辺の中点の座標

	cin>>n;
	for(i=0;i<n;i++){
		flg=0;
		cin>>x1>>y1>>x2>>y2>>x3>>y3;

		xm1=(x1+x2)/2;
		xm2=(x2+x3)/2;
		ym1=(y1+y2)/2;
		ym2=(y2+y3)/2;
		
		if(y1-y2!=0) 		m1=(-1)*(x1-x2)/(y1-y2);
		else if(y1-y2==0)	flg=1;
		
		if(y2-y3!=0)		m2=(-1)*(x2-x3)/(y2-y3);
		else if(y2-y3==0)	flg=2;
		
		if(flg==0) 	px=(m1*xm1-m2*xm2+ym2-ym1)/(m1-m2);
		else if(flg==1)px=xm1;
		else if(flg==2)px=xm2;

		if(flg==1)py=m2*(px-xm2)+ym2;
		else		py=m1*(px-xm1)+ym1;
		r=sqrt((x1-px)*(x1-px)+(y1-py)*(y1-py));
		printf("%.3lf %.3lf %.3lf\n",px,py,r);
	}
}

Measured memory_bytes: 1244
#include <stdio.h>
#include <math.h>
#define N 10000

int isprime(int);

int main(){

  int A[N],n;
  int i;
  int count=0;
  
  scanf("%d",&n);

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

    if(isprime(A[i])==1)count++;
    
  }

  printf("%d\n",count);

  return 0;
}

int isprime(int x){
  int i=3;
  if(x==2)return 1;
  if(x<2 || x%2==0)return 3;

  while(i<=sqrt(x)){
    if(x%i==0)return 3;
    i=i+2;
  }

  return 1;
    }



Measured memory_bytes: 2072
#include <iostream>
using namespace std;
int main(){
	int A,B,C,X; //500,100,50円の枚数と目標金額
  	cin >> A >> B >> C >> X;
    int count; //何通りか
	for(int i=0;i<=A;i++){
    	for(int j=0;j<=B;j++){
        	for(int k=0;k<=C;k++){
              int total=500*i+100*j+50*k;
            	if(total==X) count++;
            }
        }
   }
  cout << count << endl;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  string s, t;
  while (cin >> s >> t) {
    vvi dp(s.size() + 1, vi(t.size() + 1));
    int maxi = 0;
    rep(i, s.size()) rep(j, t.size()) {
      if (s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
      cmax(maxi, dp[i + 1][j + 1]);
    }
    cout << maxi << endl;
  }
}

Measured memory_bytes: 127952
/*
https://open.spotify.com/track/1nEjpWJlqcOsf2ZaRQ3XdW?si=kp72YcBSRjSiiZjnbDqP2A

In the particularly cold night
Perhaps you couldn’t sleep well
In the bright morning woken up from sleep
You are full of darkness
You, who were so worried for some reason that you
Hugged me tightly and asked for my love

You broke and ruined my everything
My daily life and even my people yeah
I resent you all day
But to leave you I oh I

Don’t worry babe
I love you babe
I’ll be by your side
Maybe

Maybe

Looks about to collapse but remains
And the cycle continues unsteadily
I’m about to give up but when I see you I Oh I

No babe
I love you babe
I’ll hold your hand
Maybe

Maybe
I’ll be by your side
Maybe
I’ll trust you

Stay with me, stay with me
So you won’t think of anything
I’ll stay here pretending to be reluctant
So hold me back
Maybe

Maybe
I will be by your side
Maybe
I’ll trust you

Maybe
*/

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define for1(i, a, b) for(i = a; i <= b; ++i)
#define for0(i, a, b) for(i = a; i < b; ++i)
#define forw1(i, a, b) for(i = a; i >= b; --i)
#define forw0(i, a, b) for(i = a - 1; i >= b; --i)
#define fora(v, a) for(auto v : a)
#define bp __builtin_popcount
#define bpll __builtin_popcountll

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

const int modd1 = 1e9 + 7, modd2 = 998244353, maxn = 1e5 + 10, K = 26, inf = 1e9;

int n, a[maxn], deg[maxn];
vi gr[maxn];

int dfs(int u, int par){
	int res = 0;	
	if(gr[u].size() == 1 && gr[u][0] == par){
		return a[u];
	}
	int mx = 0;
	fora(v, gr[u]){
		if(v == par){
			continue;
		}
		int tmp = dfs(v, u);
		res += tmp;
		mx = max(mx, tmp);
	}
	if(gr[u].size() == 2 && par != -1){
		if(res != a[u]){
			cout << "NO\n"; exit(0);
		}
		return a[u];
	}
	if(mx * 2 > res && par == -1){
		cout << "NO\n"; exit(0);
	}
	if(2 * a[u] - res < 0){
		cout << "NO\n"; exit(0);
	}
	if(2 * a[u] - res > res){
		cout << "NO\n"; exit(0);
	}
	if(a[u] < mx){
		cout << "NO\n"; exit(0);
	}
	return 2 * a[u] - res;
}

void solve(){
	int i, j, k, l, r; cin >> n;
	for1(i, 1, n){
		cin >> a[i];
	}
	for0(i, 1, n){
		int u, v; cin >> u >> v;
		gr[u].pb(v); gr[v].pb(u);
		deg[u]++; deg[v]++;
	}
	if(n == 2){
		if(a[1] == a[2]){
			cout << "YES\n"; return;
		}
		else cout << "NO\n"; return;
	}
	int root = -1;
	for1(i, 1, n){
		if(deg[i] > 1){
			root = i;
		}
	}
	//cout << root << '\n';
	int now = dfs(root, -1);
	if(now == 0){
		cout << "YES\n";
	}
	else{
		cout << "NO\n";
	}
}

signed main() {
    //freopen(".INP", "r", stdin);
    //freopen(".OUT", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
}

Measured memory_bytes: 17700
fun main(args: Array<String>) {
    abc066b()
}

fun abc066b() {
    val s = readLine()!!.let { if (it.length % 2 == 0) it else it.take(it.length - 1) }

    for (i in s.length - 2 downTo 2 step 2) {
        val tempS = s.substring(0, i)
        if (tempS.take(tempS.length / 2) == tempS.takeLast(tempS.length / 2)) return println(tempS.length)
    }
}


Measured memory_bytes: 33788
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//Library
/*Union-Find木
int par[1000010], rankh[1000010];
void init(int n) {
	for (int i = 0; i <= n; i++) {
		par[i] = i;
		rankh[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x)return x;
	else return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rankh[x] < rankh[y])par[x] = y;
	else {
		par[y] = x;
		if (rankh[x] == rankh[y])rankh[x]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
template<typename t>
t GCD(t a, t b) {
	while (max(a, b) % min(a, b)) {
		if (a > b)a %= b;
		else b %= a;
	}
	return min(a, b);
}
Union-Find木end*/
//Library end
int main() {
	string w, t;
	int ans = 0;
	cin >> w >> t;
	while (t != "END_OF_TEXT") {
		for (int i = 0; i < t.size(); i++) {
			t[i] = tolower(t[i]);
		}
		if (w == t)ans++;
		cin >> t;
	}
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define FOR_EX(i, a, b) for (int i = a; i < b; i++)
#define FOR_IN(i, a, b) for (int i = a; i <= b; i++)

#define ALL(a) a.begin(), a.end()

int fact(int n) {
    if (n == 1)
        return 1;
    return n * fact(n - 1);
}

long double dist(int xi, int xj, int yi, int yj) {
    return sqrt(pow(xi - xj, 2) + pow(yi - yj, 2));
}

void genPerms(vector<int> &candidates, vector<int> &cur, vector<vector<int>> &perms) {
    if (candidates.empty()) {
        perms.push_back(cur);
    } else {
        for (int i = 0; i < candidates.size(); i++) {
            auto left = vector<int>(candidates.begin(), candidates.begin() + i);
            auto right = vector<int>(candidates.begin() + i + 1, candidates.end());
            left.insert(left.end(), right.begin(), right.end());
            cur.push_back(candidates[i]);
            genPerms(left, cur, perms);
            cur.pop_back();
        }
    }
}

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution
    int n;
    cin >> n;
    int x[n + 1];
    int y[n + 1];
    FOR_IN(i, 1, n) {
        cin >> x[i];
        cin >> y[i];
    }
    vector<int> candidates;
    FOR_IN(i, 1, n) {
        candidates.push_back(i);
    }
    vector<vector<int>> perms;
    vector<int> cur;
    genPerms(candidates, cur, perms);

    long double tot = 0;
    for (auto &p : perms) {
        FOR_IN(i, 1, p.size() - 1) {
            tot += dist(x[p[i - 1]], x[p[i]], y[p[i - 1]], y[p[i]]);
        }
    }

    cout << fixed << setprecision(10) << tot * 1.0 / perms.size() << endl;
}


Measured memory_bytes: 3384
#include <bits/stdc++.h>
#define REP(a, b) for(int a = 0; a < b; a++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;

const ll INF = -1e15;
const int MAXN = 1e5 + 100;

ll MOD;
int n;
ll m;
ll DP[MAXN], D[MAXN];
int p[MAXN];
vector<ll> pre[MAXN], suf[MAXN];
ll idxpre[MAXN], idxsuf[MAXN];
vi v[MAXN];

void dfs(int x) {
	REP(i, v[x].size()) {
		int now = v[x][i];
		if (p[x] == now) continue;
		idxpre[now] = i;
		idxsuf[now] = v[x].size() - 1 - i;
		p[now] = x;
		dfs(now);
	}
}

ll rek(int pos) {
	ll &ret = DP[pos];
	if (ret != -1) return ret;
	ret = 1;
	REP(i, v[pos].size()) {
		ll now = v[pos][i];
		if (p[pos] == now) {
			pre[pos].pb(ret);
			continue;
		}
		ret = (ret * (1 + rek(now))) % MOD;
		pre[pos].pb(ret);
	}	
	ret = 1;
	for(int i = v[pos].size() - 1; i >= 0; i--) {
		ll now = v[pos][i];
		if (p[pos] == now) {
			suf[pos].pb(ret);
			continue;
		}
		ret = (ret * (1 + rek(now))) % MOD;
		suf[pos].pb(ret);
	}
	return ret;
}

ll rekk(int pos) {
	if (pos == 0) return 1;
	ll &ret = D[pos];
	if (ret != -1) return ret;
	ll nyok = 1;
	if (idxpre[pos] > 0) nyok = (nyok * pre[p[pos]][idxpre[pos] - 1]) % MOD;
	if (idxsuf[pos] > 0) nyok = (nyok * suf[p[pos]][idxsuf[pos] - 1]) % MOD;
	ret = nyok * rekk(p[pos]) + 1;
	ret %= MOD;
	return ret;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	memset(DP, -1, sizeof DP);
	memset(D, -1, sizeof D);
	memset(p, -1, sizeof p);
	cin >> n >> MOD;
	REP(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		v[a].pb(b);
		v[b].pb(a);
	}
	//cout << "eA\n";
	p[0] = -1;
	dfs(0);
	//cout << "eA\n";
	REP(i, n) cout << rek(i) * rekk(i) % MOD << '\n';
}

Measured memory_bytes: 27008
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        k: usize,
        v: [usize; k]
    }
    let mut l = vec![false; 10];
    for i in 0..k {
        l[v[i]] = true;
    }
    'outer: for i in n..n * 10 {
        let mut m = i;
        while m > 0 {
            if l[m % 10] {
                continue 'outer;
            }
            m /= 10;
        }
        println!("{}", i);
        return;
    }
}


Measured memory_bytes: 4352
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			
			final int K = sc.nextInt();
			final int T = sc.nextInt();
			
			PriorityQueue<Integer> queue = new PriorityQueue<Integer>(Collections.reverseOrder());
			for(int i = 0; i < T; i++){
				queue.add(sc.nextInt());
			}
			
			if(T == 1){
				System.out.println(Math.max(0, queue.poll() - 1));
			}else{
				while(queue.size() > 1){
					final int fst = queue.poll();
					final int snd = queue.poll();
					
					if(fst != 1){ queue.add(fst - 1); }
					if(snd != 1){ queue.add(snd - 1); }
				}
				
				System.out.println(Math.max(0, (queue.size() == 0 ? 0 : queue.poll()) - 1));
			}
		}
	}
}

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

int uf[100001];

int find(int x)
{
	if(uf[x] < 0)
	{
		return x;
	}
	return uf[x] = find(uf[x]);
}

bool merge(int x,int y)
{
	x = find(x);
	y = find(y);
	if(x==y)
	{
		return false;
	}
	uf[x] += uf[y];
	uf[y] = x;
	return true;
}

vector <int> l[100001];

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

	int n,m,k,a;

	cin >> n >> m;
	
	for(int i=0;i<n;i++)
	{
		cin >> k;
		for(int j=0;j<k;j++)
		{
			cin >> a;
			l[a].push_back(i);
		}
	}

	memset(uf,-1,sizeof(uf));

	for(int i=1;i<=m;i++)
	{
		if(l[i].size()<=1)
		{
			continue;
		}
		for(int j=1;j<l[i].size();j++)
		{
			//cout << i << ' ' << l[i][0] << ' ' << l[i][1] << '\n';
			merge(l[i][0],l[i][j]);
		}
	}

	int x = find(0);
	//cout << x << ' ' << uf[x] << '\n';
	if(abs(uf[x])==n)
	{
		cout << "YES" << '\n';
	}
	else
	{
		cout << "NO" << '\n';
	}

	return 0;
}

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

using namespace std;

#define int long long
#define MKP make_pair
#define fi first
#define se second
typedef pair<int, int> pii;

constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 205;
constexpr int MAX_W = 10005;
constexpr int INF = 1LL << 60;

/* 基本要素 */

typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;
const D EPS = 1e-9;    // 許容誤差。問題によって変える
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

// 内積　dot(a,b) = |a||b|cosθ
D dot(P a, P b) {
  return (conj(a)*b).X;
}
// 外積　cross(a,b) = |a||b|sinθ
D cross(P a, P b) {
  return (conj(a)*b).Y;
}

VP crosspointCC(P a, D ar, P b, D br) {
  VP ps;
  P ab = b-a;
  D d = abs(ab);
  D crL = (norm(ab) + ar*ar - br*br) / (2*d);
  if (EQ(d, 0) || ar < abs(crL)) return ps;

  P abN = ab * P(0, sqrt(ar*ar - crL*crL) / d);
  P cp = a + crL/d * ab;
  ps.push_back(cp + abN);
  if (!EQ(norm(abN), 0)) ps.push_back(cp - abN);
  return ps;
}

int n;
vector<P> v;

bool solve() {
    v.clear();
    cin >> n;
    if (!n) return false;

    for (int i = 0; i < n; ++i) {
        double x, y;
        cin >> x >> y;
        v.emplace_back(P(x, y));
    }

    int res = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            auto crs = crosspointCC(v[i], 1.0, v[j], 1.0);
            for (int k = 0; k < crs.size(); ++k) {
                int cnt = 0;
                for (int l = 0; l < n; ++l) {
                    double dist = abs(crs[k] - v[l]);
                    if (dist <= 1.0 + EPS) cnt++;
                }

                res = max(res, cnt);
            }
        }
    }

    cout << res << endl;

    return true;
}

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

    while (solve());
}



Measured memory_bytes: 3220
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
 
using namespace std;
 
int main(){
    int N; cin>>N;
    vector<int> H(N);
    for(int i=0;i<N;i++)cin>>H.at(i);
    bool ans = 1;
    int max = 0;
    for(int i=0;i<N-1;i++){
        if(H.at(i)-H.at(i+1)==1)H.at(i+1)++;
        if(H.at(i)-H.at(i+1)>1)ans=0;
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
template<typename T> inline void add(T& a, T b) { a += b; if (a >= MOD) a -= MOD; }

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

  string s; cin >> s;
  vector<int> BI(26, -10);
  int n = s.size();
  rep(i, n) {
    if(i - BI[s[i] - 'a'] <= 2) {
      cout << BI[s[i] - 'a'] + 1 << " " << i + 1 << endl;
      return 0;
    }
    BI[s[i] - 'a'] = i;
  }
  cout << "-1 -1" << endl;
  return 0;
}


Measured memory_bytes: 512