akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, M, K;
  cin >> N >> M >> K;
  vector<ll> A(N), B(M);
  for (auto &it : A)
    cin >> it;
  for (auto &it : B)
    cin >> it;
  vector<ll> ASum(N + 1);
  vector<ll> BSum(M + 1);
  for (int i = 0; i < N; i++)
  {
    ASum[i + 1] = ASum[i] + A[i];
  }
  for (int i = 0; i < M; i++)
  {
    BSum[i + 1] = BSum[i] + B[i];
  }
  ll ans = 0;
  for (int i = 0; i <= N; i++)
  {
    ll rem = K - ASum[i];
    if (rem < 0)
      continue;
    int idx = upper_bound(BSum.begin(), BSum.end(), rem) - BSum.begin();
    idx--;
    if (idx >= 0)
      ans = max(ans, (ll)i + idx);
    else
      ans = max(ans, (ll)i);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9492
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M 998244353
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 
ll A(ll x){
    if(x>=0)return x;
    else return -x;
}
 
ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

ll c[30];
ll t[400];
ll s[400][30];
ll last[400][30];

int main(void){
	int D;
	cin>>D;
	for(int i=1;i<=26;i++){
        cin>>c[i];
        last[1][i]=0;
        last[0][i]=0;
    }
	for(int i=1;i<=D;i++){
		for(int j=1;j<=26;j++){
			cin>>s[i][j];
		}
	}
    ll ans=0;
	for(ll d=1;d<=D;d++){
		cin>>t[d];
		for(int i=1;i<=26;i++){
            last[d][i]=last[d-1][i];
            if(i==t[d])last[d][t[d]]=d;
        }
		ans+=s[d][t[d]];
		for(ll j=1;j<=26;j++){
            ans-=c[j]*(d-last[d][j]);
		}
	}
    ll m;
    cin>>m;
    /*for(int i=1;i<=26;i++){
        for(int j=1;j<=D;j++){
            cout<<last[j][i]<<" ";
        }
        cout<<endl;
    }*/
    for(int query=0;query<m;query++){
        ll d,q;
        cin>>d>>q;
        ans+=s[d][q]-s[d][t[d]];
        ll old1 = last[d][t[d]];
        ll new1 = last[d-1][t[d]];
        ll old2 = last[d][q];
        ll new2 = d;
        for(ll i=d;i<=D;i++){
            ans+=c[t[d]]*(i-last[i][t[d]]);
            if(last[i][t[d]]==old1)last[i][t[d]]=new1;
            ans-=c[t[d]]*(i-last[i][t[d]]);
        }
        for(ll i=d;i<=D;i++){
            ans+=c[q]*(i-last[i][q]);
            if(last[i][q]==old2)last[i][q]=new2;
            ans-=c[q]*(i-last[i][q]);
        }
        //cout<<query+1<<endl;
        /*for(int i=1;i<=26;i++){
        for(int j=1;j<=D;j++){
            cout<<last[j][i]<<" ";
        }
        cout<<endl;
    }*/
        t[d]=q;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3780
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int main(){

	int N, T;
	cin >> N >> T;
	int ans = 10000;
	for(int i = 0; i < N; i ++){
		int c,t;
		cin >> c >> t;
		if(t <= T){
			ans = min(ans, c);
		}
	}
	if(ans == 10000)cout << "TLE" << endl;
	else cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int j,i,N,A[100],key;
  scanf("%d",&N);
  for(j = 0 ; j < N ; j++){
    scanf("%d",&A[j]);
    printf("%d",A[j]);
    if(j < N-1){
      printf(" ");
    }
  }
  printf("\n"); 
  for(j = 1 ; j < N ;j++){
    key = A[j];
    i = j - 1;
    while(A[i] > 0 && A[i] > key){
      A[i+1] = A[i];
      i = i - 1;
    }
    A[i+1] = key;
    for(i = 0 ; i < N ; i++){
      printf("%d",A[i]);
      if(i < N-1){
	printf(" ");
      }
    }     
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 0
N=int(input())
S=[list(input()) for i in range(N)]

numM, numA, numR, numC, numH = 0,0,0,0,0
ans=0

for i in range(N):
    if S[i][0]=='M':
        numM+=1
    elif S[i][0]=='A':
        numA+=1
    elif S[i][0]=='R':
        numR+=1
    elif S[i][0]=='C':
        numC+=1
    elif S[i][0]=='H':
        numH+=1

P=[0,0,0,0,0,0,1,1,1,2]
Q=[1,1,1,2,2,3,2,2,3,3]
R=[2,3,4,3,4,4,3,4,4,4]

D=list()
D.append(numM)
D.append(numA)
D.append(numR)
D.append(numC)
D.append(numH)

for i in range(10):
    ans+=D[P[i]]*D[Q[i]]*D[R[i]]

print(ans)


Measured memory_bytes: 20276
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mx = 1e5+5;
vector<int>tree[mx];
int visited[mx];
void dfs(int n)
{
	visited[n] = 1;
	for(int i=0;i<tree[n].size();i++)
	{
		if(!visited[tree[n][i]])
		{
			dfs(tree[n][i]);
		}
	}
}
main()
{
	//freopen("input.txt","rt",stdin);
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int p,q,z;
		cin>>p>>q>>z;
		tree[p].push_back(q);
		tree[q].push_back(p);
	}
	int c =0;
	for(int i=1;i<=n;i++)
	{
		if(!visited[i])
		{
			dfs(i);
			c++;
		}
	}
	cout<<c<<endl;
}

Measured memory_bytes: 9600
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		// your code goes here
		
		int n = int.Parse(Console.ReadLine());
		int[] a = new int[n];
		int[] copy = new int[n];
		for(int i=0; i!=n; i++){
			a[i] = int.Parse(Console.ReadLine());
			copy[i] = a[i]; 
		}
		Array.Sort(copy);
		int max = copy[n-1];
		int second = copy[n-2];
		for(int j=0; j!=n; j++){
			if(a[j]==max){
				Console.WriteLine(second);
			}else{
				Console.WriteLine(max);
			}
		}
		
	}
}

Measured memory_bytes: 17876
#include<stdio.h>

int main() {
  int n, max, sum = 0;
  scanf("%d", &n);
  int x[n];
  for(int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }
  max = x[0];
  for(int i = 0; i < n; i++) {
    if(max < x[i]) {
      max = x[i];
    }
    sum += x[i];
  }
  
  if(max < sum-max) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
}

Measured memory_bytes: 128
import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val n = StdIn.readLine.toInt
    val ns = StdIn.readLine.split(' ').map(_.toInt)
    val sorted = ns.sortBy(identity)
    println(sorted.zipWithIndex.filter { case (v, i) => i % 2 == 0 }.map(_._1)sum)
  }
}

Measured memory_bytes: 21692
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EMP emplace
#define EMPB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int N;
int A[100010];
int B[100010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  int sumA = 0, sumB = 0;
  REP(i, N) {
    cin >> A[i];
    sumA += A[i];
  }
  REP(i, N) {
    cin >> B[i];
    sumB += B[i];
  }
  if (sumA < sumB) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> v, w;
  REP(i, N) {
    int tmp = A[i]-B[i];
    if (tmp < 0) v.PB(tmp);
    else w.PB(tmp);
  }
  if (v.size() == 0) {
    cout << 0 << endl;
    return 0;
  }
  sort(ALL(v));
  sort(ALLR(w));
  int s = 0;
  REP(i, v.size()) s += -v[i];
  int ans = v.size();
  int t = 0;
  for (int i = 0; i < w.size(); i++) {
    t += w[i];
    ans++;
    if (s <= t) break;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2936
n = int(input())
txyArray = []
for i in range(n):
    t,x,y = [int(i) for i in input().split()]
    txyArray.append([t,x,y])
t=0
x=0
y=0
for t2,x2,y2 in txyArray:
    sum = abs(x2-x) + abs(y2-y)
    diff = sum -(t2-t)
    if diff > 0 or diff%2 != 0:
        break
    t2=t
    x2=x
    y2=y
if diff > 0 or diff%2 != 0:
    print("No")
else:
    print("Yes")


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

int main() {
//	vector<int> s(4);
//	for(auto& x:s){
//		cin>>x;
//	}
//	int a1=s[0]*10+s[1];
//	int a2=s[2]*10+s[3];
	int n;cin>>n;
	int a2=n%100;
	int a1=n/100;
	if((a1>12)+(a1==0)){
		if((a2>12)+(a2==0)){
			cout<<"NA"<<endl;
		}else{
			cout<<"YYMM"<<endl;
		}
	}else{
		if((a2>12)+(a2==0)){
			cout<<"MMYY"<<endl;
		}else{
			cout<<"AMBIGUOUS"<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>

int main(){
    for(int i = 0; i < 3000; i++){
        int x, y;
        std::cin >> x >> y;
        if(x == 0 && y == 0){
            break;
        }
        if(x > y) std::swap(x,y);
        std::cout << x << " " << y << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3016
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less   
using namespace __gnu_pbds;  
using namespace std;  
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> set1;
ll find(ll a,ll p[])
{
   //cout<<"find "<<a<<endl;
   if(a==p[a])
   return a;
   else return p[a]=find(p[a],p);

}
void join(ll a,ll b,ll p[],ll sz[])
{
   a=find(a,p);
   b=find(b,p);
   if(a!=b)
   {
      if(sz[a]<sz[b])
      swap(a,b);
      sz[a]+=sz[b];
      p[b]=a;
   }
}
ll power(ll a,ll b,ll mod)
{
   ll res=1;
   while(b>0)
   {
      if(b&1)
      res=(res*a)%mod;
      b=b/2;
      a=(a*a)%mod;
   }
   return res;
}
ll inverse(ll x, ll p)
{
   return power(x,p-2,p);
}
ll hash1(ll x,ll y)
{
   return x+y+x*y;
}
ll f[200000]={0};
ll mod;
void ini()
{
   f[0]=1;
   for(ll i=1;i<=200000;i++)
   f[i]=(i*f[i-1])%mod;
}



ll ncr(ll n,ll r)
{
   ll res=1;
   ll k=f[n];
   ll v=inverse(f[n-r],mod);
   ll u=inverse(f[r],mod);
   ll x=(u*v)%mod;
   k=(k*x)%mod;
   return k;
}

int main()
{
  // ini();
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 ll n;ll W;
 cin>>n>>W;
 ll v[n],w[n];
 ll sum=0;
 for(ll i=0;i<n;i++)
 {
    cin>>w[i]>>v[i];
    sum+=v[i];
 }
 ll max_val=n*1000;
 ll dp[n][max_val+1];
 ll large=1e18;
 for(ll i=0;i<n;i++)
 {
    for(ll j=1;j<=sum;j++)
    dp[i][j]=large;
 }
 dp[0][v[0]]=w[0];
 dp[0][0]=0;

 for(ll i=1;i<n;i++){
    for(ll j=0;j<=sum;j++)
    {
       if(dp[i-1][j]!=large)
       dp[i][j]=dp[i-1][j];
       ll x=j-v[i];
       if(x>=0)
      // cout<<i<<" "<<j<<" "<<v[i]<<" "<<dp[i-1][x]<<endl;
       if(x>=0 && dp[i-1][x]!=large)
       {
         dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
       }
    }
}
 
 ll ans=0;
// cout<<endl<<" "<<endl;
 /*for(ll i=0;i<n;i++)
 {
    for(ll j=0;j<=sum;j++)
    cout<<dp[i][j]<<" ";
    cout<<endl;
 }*/
 for(ll i=sum;i>=0;i--)
 {
    if(dp[n-1][i]<=W)
    {
       ans=i;
       break;
    }
 }
 cout<<ans<<endl;
 return 0;
}

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

const double PI = 3.14159265358979323846;

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

    double hd = PI / 6.0 * h + PI / 6.0 / 60.0 * m;
    double md = PI / 30.0 * m;

    double hx = sin(hd) * a;
    double hy = cos(hd) * a;

    double mx = sin(md) * b;
    double my = cos(md) * b;

    double x = hx - mx;
    double y = hy - my;

    double ans = sqrt(x * x + y * y);

    printf("%.15lf", ans);
    cout << endl;

    return 0;
}

Measured memory_bytes: 4084
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7

a_matrix = []
for i in range(3):
    a_vec = list(map(int, input().split()))
    a_matrix.append(a_vec)

a_mat = np.array(a_matrix)

def bingo_check(m):
    ch1 = (0 in m.sum(axis = 0))
    ch2 = (0 in m.sum(axis = 1))
    ch3 = not (m.trace())
    ch4 = not (np.rot90(m).trace())
    return ch1 or ch2 or ch3 or ch4
    
def num_change(n):
    dim1 = a_mat.shape[0]
    dim2 = a_mat.shape[1]
    for i in range(dim1):
        for j in range(dim2):
            if a_mat[i][j] == n:
                a_mat[i][j] = 0

n = int(input())
for i in range(n):
    b = int(input())
    num_change(b)

if bingo_check(a_mat):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 27400
from collections import deque
s = list(input())
ans = deque(s)
q = int(input())
check = 1
for i in range(q):
    a = list(input().split())
    if a[0] == "1":
        check *= -1
    else:
        if a[1] == "1":
            if check == 1:
                ans.appendleft(a[2])
            else:
                ans.append(a[2])
        else:
            if check == 1:
                ans.append(a[2])
            else:
                ans.appendleft(a[2])
    
ans = list(ans)
if check==1:
    print(*ans,sep="")
else:
    ans = ans[::-1]
    print(*ans,sep="")



Measured memory_bytes: 93864
require 'set'

class Heap
	require 'forwardable'
	extend Forwardable

	def initialize
		@array = []
		@index = {}
	end

	def add(obj, key)
		@array << [obj, key]
		@index[obj] = @array.size - 1
		lift_up(@array.size - 1)
	end

	def swap(i, j)
		u = @array[i]
		v = @array[j]
		@index[u[0]], @index[v[0]] = j, i
		@array[i], @array[j] = v, u
	end

	def lift_up(i)
		return if i == 0
		j = (i - 1) / 2
		if (@array[i][1] <=> @array[j][1]) < 0
			swap(i, j)
			lift_up(j)
		end
	end

	def del_min
		raise "heap is empty!" if empty?
		min = @array[0]
		if size > 1
			swap(0, @array.size-1)
			@array.pop
			lift_down(0)
		else
			@array.pop
		end
		@index.delete(min[0])
		min
	end

	def inc_key(obj, diff)
		i = @index[obj]
		@array[i][1] += diff
		lift_down(i)
	end

	def dec_key(obj, diff)
		i = @index[obj]
		@array[i][1] -= diff
		lift_up(i)
	end

	def update_key(obj, new_key)
		i = @index[obj]
		return unless i
		return if (new_key <=> @array[i][1]) >= 0
		@array[i][1] = new_key
		lift_up(i)
	end

	def min_obj
		@array[0][0]
	end

	def min_key
		@array[0][1]
	end

	def lift_down(i)
		j = 2 * i + 1
		k = j + 1
		if k >= size
			return if j >= size
			if (@array[i][1] <=> @array[j][1]) > 0
				swap(i, j)
				lift_down(j)
			end
		else
			l = ((@array[j][1] <=> @array[k][1]) < 0 ? j : k)
			if (@array[i][1] <=> @array[l][1]) > 0
				swap(i, l)
				lift_down(l)
			end
		end
	end

	def_delegators :@array, :empty?, :size
end

def c(i, j)
	i * 32 + j
end

def dijkstra
	h = Heap.new
	s = c($h-1, $w-1)
	reached = Set[s]
	h.add(s, 0)

	dist = {}
	until h.empty?
		u, key = h.del_min
		return key if u == 0
		dist[u] = key
		$g[u].each do |v|
			e = (u < v ? [u, v] : [v, u])
			d = [$retry_dist[e][v] || -Float::INFINITY, dist[u] + 1].max
			if reached.include?(v)
				h.update_key(v, d)
			else
				h.add(v, d)
				reached << v
			end
		end
	end
end

loop do
	h, w = gets.split.map(&:to_i)
	break if h == 0
	g = {}
	(0..h-1).to_a.product((0..w-1).to_a).each do |i, j|
		g[c(i, j)] = Set.new
	end
	edges = Set.new
	h.times do |i|
		gets.split.map(&:to_i).each_with_index do |x, j|
			if x == 0
				u = c(i, j)
				v = c(i, j+1)
				edges << [u, v]
				raise if ! [1, 32].include? (u-v).abs
				g[u] << v
				g[v] << u
			end
		end

		break if i == h-1
		gets.split.map(&:to_i).each_with_index do |x, j|
			if x == 0
				u = c(i, j)
				v = c(i+1, j)
				raise if ! [1, 32].include? (u-v).abs
				edges << [u, v]
				g[u] << v
				g[v] << u
			end
		end
	end

	dist = {}
	edges.each do |e|
		u0, v0 = e
		g[u0].delete v0
		g[v0].delete u0
		s = c(h-1, w-1)
		d = {s => 0}
		queue = [s]
		until queue.empty?
			u = queue.shift
			g[u].each do |v|
				next if d[v]
				d[v] = d[u] + 1
				queue << v
			end
		end
		if !d[0]
			dist = nil
			break
		end
		dist[e] = d
		g[u0] << v0
		g[v0] << u0
	end
	
	if ! dist
		puts -1
		next
	end

	$g = g
	$retry_dist = dist
	$h = h
	$w = w

	p dijkstra
end

Measured memory_bytes: 152600
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i <= 50000; i++) {
        if (i * 108 / 100 == n) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,a) rep((i),0,(a))
using namespace std;
//global
int h, w;
int need_e;
int town[33][33] = { 0 };



struct Group{
	int min_cost;
	int g_num;
};
Group dp[32][32][33][33] = { 0 };

int get_sum(int s_x, int s_y, int _h, int _w){
	int sum = 0;
	rep(i, s_x, s_x + _h)rep(j, s_y, s_y + _w)sum += town[i][j];
	return(sum);
}

void calc(int s_x, int s_y, int _h, int _w){
	
	Group one, two,c;
	c.g_num = 1;
	c.min_cost = get_sum(s_x, s_y, _h, _w);
	rep(i, 1, _h ){
		one = dp[s_x][s_y][i][_w];
		two = dp[s_x + i][s_y][_h - i][_w];
		//printf("[%d,%d],h=%d,h-i=%d,one=%d,two=%d\n", s_x, s_x+i, i, _h-i, one.min_cost, two.min_cost);
		if (one.min_cost < need_e || two.min_cost < need_e)continue;
		one.g_num = one.g_num + two.g_num;
		one.min_cost = (one.min_cost < two.min_cost) ? one.min_cost : two.min_cost;
		if (c.g_num < one.g_num)c = one;
		else if (c.g_num == one.g_num&&c.min_cost < one.min_cost)c = one;
	}
	rep(i, 1, _w){
		one = dp[s_x][s_y][_h][i];
		two = dp[s_x][s_y+i][_h][_w-i];
		if (one.min_cost < need_e || two.min_cost < need_e)continue;
		one.g_num = one.g_num + two.g_num;
		one.min_cost = (one.min_cost < two.min_cost) ? one.min_cost : two.min_cost;
		if (c.g_num < one.g_num)c = one;
		else if (c.g_num == one.g_num&&c.min_cost < one.min_cost)c = one;
	}
	dp[s_x][s_y][_h][_w] = c;
	//printf("[%d,%d],h=%d,w=%d,g_num=%d,min_cost=%d\n", s_x, s_y, _h, _w,c.g_num,c.min_cost);
}

void solve(){
	int m = h > w ? h : w;
	rep(height, 2, m + 1){
		rep(width, 1, height)
			rep(i, 0, h - width+1)
			rep(j, 0, w - width+1){
				if (i + height <= h&&j + width <= w)
					calc(i, j, height, width);
				if (i + width <= h&&j + height <= w)
					calc(i, j, width, height);
			}
		rep(i, 0, h - height+1)rep(j, 0, w - height+1)
			calc(i, j, height, height);
	}

}


int main(void){
	while (true){
		cin >> h >> w >> need_e;
		if (need_e == 0)return(0);
		rep(i, 0, h)rep(j, 0, w){
			cin >> town[i][j];
			dp[i][j][1][1].min_cost = town[i][j];
			dp[i][j][1][1].g_num = 1;
		}
		need_e = get_sum(0, 0, h, w) - need_e;
		//cout << need_e << endl;
		solve();
		printf("%d %d\n", dp[0][0][h][w].g_num, dp[0][0][h][w].min_cost - need_e);
	}

}

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

int main(){
    int A, B, C, X, cnt=0;
    cin >> A >> B >> C >> X;
    for(int k=0; k<=C; k++){
        for(int j=0; j<=B; j++){
            for(int i=0; i<=A; i++){
                if(i*500+j*100+k*50==X) cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;

int main(){
  string s,t;
  cin>>s>>t;
  int n=s.size();
  bool finished=false;
  rep(i,n){
    int count=0;
    rep(j,n){
      int d=(i+j)%n;
      if(s[j]==t[d])count++;
      
    }
    //cout<<count<<endl;
    if(count==n)finished=true;
  }
  if(finished)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
      
    
           
     
          
  
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

int K;
ll A[100010], inf[100010], sup[100010];

signed main(){
    cin >> K;
    REP(i, K) cin >> A[i];
    if(A[K - 1] != 2){
        PRINT("-1");
        return 0;
    }
    inf[K] = 2; sup[K] = 2;
    for(int i = K - 1; i >= 0; i--){
        if(inf[i + 1] % A[i] != 0 && sup[i + 1] % A[i] != 0 && inf[i + 1] % A[i] < sup[i + 1] % A[i] && sup[i + 1] - inf[i + 1] < A[i]){
            PRINT("-1");
            return 0;
        }
        inf[i] = (inf[i + 1] + A[i] - 1) / A[i] * A[i];
        sup[i] = sup[i + 1] / A[i] * A[i] + A[i] - 1; 
    }
    cout << inf[0] << " " << sup[0] << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cmath>
#include <climits>
#include <algorithm>
#define N 10000
using namespace std;

int check(int);
int main()
{
    int n,cnt=0;
    int a[N];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(check(a[i]))
            cnt++;
    }
    cout<<cnt<<endl;
}
int check(int n)
{
    if(n==1) return 0;
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0) return 0;
    }
    return 1;
}



Measured memory_bytes: 3120
#include<iostream>
#include<cstring>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
int main() 
{
 
int a,b;
cin>>a>>b;
if(b%2==0)
{
if(a>=13)
cout<<b;
else if(a>=6&&a<=12)
cout<<b/2;
else if(a>=0&&a<=5)
cout<<"0";
}
return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    ll N;
    cin>>N;
    rep(i,0,N+1){
        if((i+i*8/100) == N){
            cout<<i;
            return 0;
        }
    }
    cout<<":(";
    return 0;
}

Measured memory_bytes: 3568
x, y, a, b, c = map(int, input().split())
p_list = sorted(list(map(int, input().split())), reverse=True)
q_list = sorted(list(map(int, input().split())), reverse=True)
r_list = sorted(list(map(int, input().split())), reverse=True)
z_list = sorted(p_list[:x] + q_list[:y])
ans = sum(z_list)
for r, z in zip(r_list, z_list):
    if r < z:
        break
    ans += r - z
print(ans)


Measured memory_bytes: 22720
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

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

vector<int> prime;

int main() {
	
	vector<bool> use(1299710, false);
	REP(i, 2, 1299710){
		if(!use[i])prime.push_back(i);
		for(int j = 2; i * j <= 1299710; j++) use[i * j] = true;
	}
	
	int n;
	while(cin >> n, n){
		auto it1 = upper_bound(prime.begin(), prime.end(), n);
		auto it2 = lower_bound(prime.begin(), prime.end(), n);
		it1--;
		cout << *it2 - *it1 << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 3412
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
			// TODO Auto-generated method stub
			Scanner sc=new Scanner(System.in);
			int a[]=new int[200];
			int n=sc.nextInt();
			int flag=1,cnt=0;
			for(int i=0;i<n;i++) {
				a[i]=sc.nextInt();
				if(a[i]%2!=0)	flag=0;	
			}
			if(flag==1) {
				do {
					for(int i=0;i<n;i++) {
						a[i]=a[i]/2;
						if(a[i]%2!=0)	flag=0;
					}
					cnt++;
				}while(flag==1);
			}
			System.out.println(cnt);

		}

}

Measured memory_bytes: 21972
n,k = map(int,input().split())
v = list(map(int,input().split()))

def mc(arr):
    count = 0
    for ar in arr:
        if ar<0:
            count += 1
    return count

def ps(arr):
    sum = 0
    for ar in arr:
        if ar > 0 :
            sum += ar
    return sum

maxsumv = 0
for l in range(0,n+1):
    for r in range(0,n+1):
        if l+r > min(k,n):
            break
        else:
            hand = v[0:l] + v[n-r:n]
            hand.sort()
            c = mc(hand)
            for i in range(0,c+1):
                if l+r+i > k:
                    break
                else:
                    sumv = sum(hand[i:len(hand)])
                    maxsumv = max(sumv,maxsumv)
        
print(maxsumv)

Measured memory_bytes: 42584
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, S: str):
    x = 0
    anx = 0
    for i in range(N):
        if S[i] == 'I':
            x += 1
        else:
            x -= 1
        anx = max(anx, x)

    print(anx)

    
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
n = int(input())
p_list = list(map(int, input().split()))
count = 0
for i in range(1, n - 1):
    p1 = p_list[i-1]
    p2 = p_list[i]
    p3 = p_list[i+1]
    if p1 < p2 < p3 or p1 > p2 > p3:
        count += 1
print(count)


Measured memory_bytes: 3064
#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++)
typedef long long ll;

int main() {
  int N; cin >> N;
  int ans = 0;
  rep(i, 100 / 4 + 1) {
    rep(j, 100 / 7 + 1) {
      if (4 * i + 7 * j == N) {
        ans++;
      }
    }
  }
  if (ans) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
a, b, c, x, y = map(int, input().split())
# 3通り
# 1: ax+by
# 2: 2c*large
# 3: 2c*small + (a/b) * diff

tar1 = a * x + b * y
tar2 = 2 * c * max(x, y)

dif = abs(x - y)
if (x > y):
    tar3 = 2 * c * y + a * (x - y)
else:
    tar3 = 2 * c * x + b * (y - x)


ans = min(tar1, tar2, tar3)


# ---------
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
// #include <bits/stdc++.h> all

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int n, k; cin >> n >> k;

  vector<int> h(n);

  for(int i = 0; i < n; i++){
    int temp;
    cin >> temp;
    h[i] = temp;
  }

  sort(h.begin(), h.end(), greater<int>());

  ll sum = 0;
  for(int i = k; i < n; i++){
    sum += h[i];
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <vector>
using namespace std;

namespace zyt
{
	template<typename T>
	inline bool read(T &x)
	{
		char c;
		bool f = false;
		x = 0;
		do
			c = getchar();
		while (c != EOF && c != '-' && !isdigit(c));
		if (c == EOF)
			return false;
		if (c == '-')
			f = true, c = getchar();
		do
			x = x * 10 + c - '0', c = getchar();
		while (isdigit(c));
		if (f)
			x = -x;
		return true;
	}
	template<typename T>
	inline void write(T x)
	{
		static char buf[20];
		char *pos = buf;
		if (x < 0)
			putchar('-'), x = -x;
		do
			*pos++ = x % 10 + '0';
		while (x /= 10);
		while (pos > buf)
			putchar(*--pos);
	}
	typedef long long ll;
	const int N = 110;
	int n, dep[N], dp[N], D, deg[N], pre[N], r, r2;
	ll ans;
	vector<int> g[N];
	void dfs1(const int u, const int f)
	{
		dp[u] = 1;
		for (auto v : g[u])
		{
			if (v == f)
				continue;
			dfs1(v, u);
			if (dp[u] + dp[v] > D)
				r = u, r2 = (dp[u] < dp[v] + 1 ? pre[u] : v), D = dp[u] + dp[v];
			if (dp[u] < dp[v] + 1)
				dp[u] = dp[v] + 1, pre[u] = v;
		}
	}
	void dfs2(const int u, const int f, const int d)
	{
		dep[u] = d;
		deg[u] = 0;
		for (auto v : g[u])
		{
			if (v == f)
				continue;
			++deg[u];
			dfs2(v, u, d + 1);
		}
	}
	ll solve(const int r1, const int r2)
	{
		static int mx[N];
		ll tmp = (r2 ? 2 : 1);
		memset(mx, 0, sizeof(mx));
		dfs2(r1, r2, 0);
		if (r2)
			dfs2(r2, r1, 0);
		for (int i = 1; i <= n; i++)
			mx[dep[i]] = max(mx[dep[i]], deg[i]);
		for (int i = 0; i <= n && mx[i]; i++)
			tmp *= mx[i];
		return tmp;
	}
	int work()
	{
		read(n);
		for (int i = 1; i < n; i++)
		{
			int a, b;
			read(a), read(b);
			g[a].push_back(b), g[b].push_back(a);
		}
		dfs1(1, 0);
		vector<int> d;
		while (r)
			d.push_back(r), r = pre[r];
		reverse(d.begin(), d.end());
		while (r2)
			d.push_back(r2), r2 = pre[r2];
		int rot1 = d[d.size() / 2], rot2 = (D & 1 ? 0 : d[d.size() / 2 - 1]);
		write((D + 1) / 2), putchar(' ');
		if (rot2)
			ans = solve(rot1, rot2);
		else
		{
			ans = solve(rot1, 0);
			for (auto v : g[rot1])
				ans = min(ans, solve(rot1, v));
		}
		write(ans);
		return 0;
	}
}
int main()
{
	return zyt::work();
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <chrono>
//#include <intrin.h>

using namespace std;

typedef long long ll;

inline void solve() {
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int t1 = h1 * 60 + m1;
	int t2 = h2 * 60 + m2;
	cout << t2 - k - t1;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define IL inline
#define RG register
#define LL long long
#define Upd(a) (a)>=mod?(a-=mod):1
using namespace std;
template <class T>
IL char gc () {
	static char buf[1<<6], *p1=buf, *p2=buf;
	return (p1==p2) && (p2=(p1=buf)+fread(buf,1,1<<6,stdin), p1==p2) ?EOF:*p1++;
}
template <typename T>
IL void read (T&data) {
	data=0;
	RG char ch=0;
	while (ch<'0' || ch>'9') ch=getchar();
	while (ch<='9' && ch>='0') data=(data<<1)+(data<<3)+(ch&15), ch=getchar();
}
const int mod = 1e9+7;
const int _ =2011;
int n, k;
int dp[2][_], jc[_*_], jcn[_*_];
IL int poww (RG int a, RG int b) {
	RG int ret=1, Base=a;
	for (;b;b>>=1, Base=1LL*Base*Base%mod) if (b&1) ret=1LL*ret*Base%mod;
	return ret;
}
IL int C (RG int a, RG int b) {
	if (a<b) return 0;
	return 1LL*jc[a]*jcn[b]%mod*jcn[a-b]%mod;
}
int main (/*int aa, int bb*/) {
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	//n=aa, k=bb;
	read(n), read(k);
	if (k<=1) {puts("1"); return 0;}
	jc[0]=jcn[0]=1;
	RG int i, j, pre=1, cur=0;
	for (i=1; i<=n*k; ++i) jc[i]=1LL*jc[i-1]*i%mod, jcn[i]=poww(jc[i], mod-2);
	dp[0][0]=1;
	for (i=1; i<=n*2; ++i) {
		swap(cur, pre);
		for (j=0; j<min(i,n+1); ++j) dp[cur][j]=0;
		for (j=1; j<=min(i,n); ++j) {
			if ((i-j)%2) continue;
			if (n*2-i+1<j) break;
			RG int a=(i+j-2)>>1, b=(i-j)>>1;
			dp[cur][j]=1LL*dp[pre][j-1]*C(a*(k-1)+b+k-1-1,k-1-1)%mod;
			dp[cur][j]+=dp[pre][j+1];
			Upd(dp[cur][j]);
		}
		if (cur%2==0) dp[cur][0]=dp[pre][1];
	}
	//return 1LL*dp[cur][0]*jc[n]%mod;
	printf("%lld",1LL*dp[cur][0]*jc[n]%mod);
}


Measured memory_bytes: 31744
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int w, a, b, ans; cin >> w >> a >> b;
    if (a < b)
    {
        if (a + w < b)
        {
            ans = b - (a + w);
        }
        else
        {
            ans = 0;
        }
    }
    else
    {
        if (b + w < a)
        {
            ans = a - (b + w);
        }
        else
        {
            ans = 0;
        }

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<map>
#define mod 1000000007


int main() {
    int n; std::cin >> n;
    std::map<int, int> m; 
    for(int i = 2; i <= n; i++) {
        m.insert(std::make_pair(i, 0));
    }

    for(int i = 2; i <= n; i++)  {
        int div = i;
        for(int j = 2; j * j <= n; j++) {
            while(div%j == 0) {
                m[j] ++;
                div /= j;
            }
        }
        m[div]++;
    }

    long long ans = 1;
    for(auto itr = m.begin(); itr != m.end(); itr++) {
        if(itr->first != 1) {
        ans *= (itr->second+1);
        }
        //std::cout << itr->first << " " << itr->second << std::endl;
        ans %= mod;
    }

    std::cout << ans << std::endl;
}

/*long long fact(int n) {
    std::vector<std::pair<int, int>> a;
    long long r = 1;
    for (int i = 2; i <= n; i++) {

        if(i < 4) {
            r *= 2;
       
        }


        for (int j = 2; j <= i; j++)
        {
            long long tmp = j;
            int index = 0;
            int k = 2;
            while (tmp > 1)
            { 
                if (tmp % k == 0)
                {
                    tmp /= k;
                    index++;
                }
                else
                {
                    k++;
                    r *= index + 1;
                    std::cout << k << " " << index + 1 << "\n";
                    r %= mod;
                }

            }

         
        }
    }

    return r;
}

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

    long long N = fact(n);

    std::cout << N << "\n";
}
*/

Measured memory_bytes: 3688
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($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)*}
    };
}

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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

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

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn f(x: i64) -> i64 {
    if x >= 3 {
        return x - 2;
    }
    if x == 2 {
        return 0;
    }
    1
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!(n: i64, m: i64);
    puts!("{}\n", f(n) * f(m));
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}

using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  
  int M,D;
  cin>>M>>D;
  int ans = 0;
  REPP(m,M){
    REPP(d,D){
      if(d%10 >= 2 && d/10 >= 2 && m == (d%10)*(d/10)){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string S;
    cin >> S;

    if(S == "AAA" || S == "BBB") cout << "No" <<endl;
    else cout << "Yes" << endl;
    
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
using namespace std;
typedef unsigned long long ull;
typedef  long long ll;


int main()
{
	int n;
	vector<vector<int>> a;
	cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++) {
		a[i].resize(n);
	}
	for (int i = 0; i < n; i++) {
		int temp, k;
		cin >> temp >> k;
		for (int j = 0; j < k; j++) {
			int temp2;
			cin >> temp2;
			a[temp - 1][temp2 - 1] = 1;
		}
	}
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << a[i][j];
			if (j == n - 1) {
				cout << endl;
			}
			else {
				cout << " ";
			}
		}
	}

	return 0;
}



Measured memory_bytes: 3100
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

void disp(vector<int> V) {
  for (int i : V) {
    cout << i << " ";
  }
  cout << endl;
}

int main() {
  int N;
  cin >> N;
  vector<int> B;
  rep(i, N) {
    int b;
    cin >> b;
    B.push_back(b);
  }

  stack<int> S;

  bool isSuccess = true;
  int M = B.size();
  rep(i, N) {
    bool hasPop = false;
    for (int k = M - 1; k >= 0; k--) {
      // cout << "i, k =" << i << " " << k << endl;
      if (B[k] == k + 1) {
        B.erase(B.begin() + k);
        M--;
        S.push(k + 1);
        hasPop = true;
        // cout << "break" << endl;
        break;
      }
    }
    if (!hasPop) {
      isSuccess = false;
      break;
    }
  }

  // cout << "result" << endl;

  if (isSuccess) {
    rep(i, N) {
      cout << S.top() << endl;
      S.pop();
    }
  } else {
    cout << -1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  string s; cin >> s;
  int a = 0, b = 0, c = 0;
  for (char ch : s) {
    if (ch == 'a') ++a;
    else if (ch == 'b') ++b;
    else ++c;
  }
  if (abs(a-b)>1||abs(b-c)>1||abs(c-a)>1) cout << "NO" << '\n';
  else cout << "YES" << '\n';
  return 0;
}


Measured memory_bytes: 764
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int> > adj[MAX]; // Adjacency list

void dijkstra(int s) {
    priority_queue<pair<int, int> > PQ;
    int color[n], d[n], p[n];
    for (int i=0; i<n; i++) {
        color[i] = WHITE;
        d[i] = INFTY;
    }
    d[s] = 0;
    PQ.push(make_pair(0, s));
    color[s] = GRAY;

    while (!PQ.empty()) {
        pair<int, int> f = PQ.top();
        PQ.pop();
        int u = f.second;
        color[u] = BLACK;
        if (d[u] < f.first * (-1)) {
            continue; // Not the minimum
        }

        for (int j=0; j<adj[u].size(); j++) {
            int v = adj[u][j].second;
            if (color[v]==BLACK) {
                continue;
            }
            int tmp = d[u] + adj[u][j].first;
            if (tmp < d[v]) {
                d[v] = tmp;
                color[v] = GRAY;
                PQ.push(make_pair(d[v]*(-1), v)); // Descending order
            }
        }
    }

    for (int i=0; i<n; i++) {
        printf("%d %d\n", i, d[i]);
    }
}

int main() {
    scanf("%d", &n);
    int u, k, v, c;
    for (int i=0; i<n; i++) {
        scanf("%d %d", &u, &k);
        for (int j=0; j<k; j++) {
            scanf("%d %d", &v, &c);
            adj[u].push_back(make_pair(c, v));
        }
    }
 
    dijkstra(0);
    return 0;
}


Measured memory_bytes: 7620
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))

A = [(-1)*x for x in A]
heapq.heapify(A)

for m in range(M):
    temp = heapq.heappop(A)
    temp = (-1) * temp
    temp = temp // 2
    temp = (-1) * temp
    heapq.heappush(A, temp)

ans = (-1) * sum(A)
print(ans)

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

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int N;

ll mul(ll a, ll b) { return a*b%MOD; }

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N;
    ll ans = 1;
    int num = 0;
    F0R(i,N) {
        int x; cin >> x;
        if (x < 2*num+1) ans = mul(ans,num+1);
        else num ++;
    }
    while (num > 0) ans = mul(ans,num--);
    cout << ans;
}

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

Measured memory_bytes: 256
local n = io.read("*n")
local t = {}

local lastval = 10000
while 0 < n do
  local min, max = 0, lastval
  while 1 < max - min do
    local mid = (min + max) // 2
    if n <= (mid * (mid + 1)) // 2 then
      max = mid
    else
      min = mid
    end
  end
  lastval = max
  table.insert(t, max)
  n = n - max
end
print(table.concat(t, "\n"))


Measured memory_bytes: 2936
import java.io.*;
import java.lang.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int N=Integer.parseInt(br.readLine());
        int[] f=new int[N+1];
        int[] arr=new int[N];
        StringTokenizer st=new StringTokenizer(br.readLine()," ");
        for(int i=0;i<N;i++){
            arr[i]=Integer.parseInt(st.nextToken());
            f[arr[i]]++;
        }
        long count=0;
        for(int i=1;i<=N;i++){
            long n=f[i];
            count=count+n*(n-1)/2;
        }
        for(int i=0;i<N;i++){
            int n=arr[i];
            int freq=f[n];
            System.out.println(count+1-freq);
        }
    }
}

Measured memory_bytes: 62752
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
 
template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }
 
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
 
int main(){
  const int N = 4001;
  const int M = 4;
  int dp[M + 1][N] = {};
  dp[0][0] = 1;
  for(int i = 0; i < M; i++){
    for(int j = 0; j < N; j++){
      for(int k = 0; j + k < N && k <= 1000; k++){
        dp[i + 1][j + k] += dp[i][j];
      }
    }
  }
  int n;
  while(cin >> n) cout << dp[M][n] << endl;
  return 0;
}


Measured memory_bytes: 3172