akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

void maxHeap(int *,int);

int N;

int main(){
  
  int i,A[500000];
  
    scanf("%d",&N);
    for(i=1; i<=N ; i++){
    scanf("%d",&A[i]);
  }
  
  for(i=N/2 ; i>=1 ; i--){
    maxHeap(&A[0],i);
  }
  
  for(i=1 ; i<=N ; i++){
    printf(" %d",A[i]);
  }
  
  printf("\n");
  
  return 0;
}

void maxHeap(int *A,int i){
   
   int temp,l,j,r,largest;
   
   l = i*2;
   r = i*2+1;
   
   if(l <= N && A[l] > A[i]) largest = l;
   else largest = i;
   
   if(r <= N && A[r] > A[largest]) largest = r;
   
   if (largest != i){
     temp = A[i];
     A[i] = A[largest];
   A[largest] = temp;
   
   maxHeap(&A[0],largest);	 
   }
 }



Measured memory_bytes: 3656
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 100005

using namespace std;

char str[SIZE];
char ans[SIZE];
int n;

char get(char c,char state)
{
	if(state=='o') return c;
	if(c=='S') return 'W';
	return 'S';
}
char get2(char c,char state)
{
	if(c=='S'&&state=='o') return 'o';
	if(c=='W'&&state=='x') return 'o';
	return 'x';
}
bool check()//0,1決める
{
	for(int i=1;i<n;i++) ans[i+1]=get(ans[i-1],get2(ans[i],str[i]));
	if(ans[0]!=ans[n]) return false;
	if(ans[1]!=get(ans[n-1],get2(ans[0],str[0]))) return false;
	return true;
}
int main()
{
	scanf("%d",&n);
	scanf("%s",&str);
	ans[0]='S',ans[1]='S';
	if(check())
	{
		for(int i=0;i<n;i++) printf("%c",ans[i]);
		puts("");
		return 0;
	}
	ans[0]='S',ans[1]='W';
	if(check())
	{
		for(int i=0;i<n;i++) printf("%c",ans[i]);
		puts("");
		return 0;
	}
	ans[0]='W',ans[1]='S';
	if(check())
	{
		for(int i=0;i<n;i++) printf("%c",ans[i]);
		puts("");
		return 0;
	}
	ans[0]='W',ans[1]='W';
	if(check())
	{
		for(int i=0;i<n;i++) printf("%c",ans[i]);
		puts("");
		return 0;
	}
	puts("-1");
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int maxn = 1e5 + 10;

int n,a[maxn],t[2*maxn],res;

void update(int x) {
    while (x<2*maxn) {
        t[x]++;
        x += x&(-x);
    }
}

int Get(int x) {
    int res=0;
    while (x>0) {
        res += t[x];
        x -= x&(-x);
    }
    return res;
}

int main() {
   // freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    vector<int> tmp;
    for (int i=1;i<=n;i++) tmp.push_back(a[i]);
    sort(tmp.begin(),tmp.end());
    tmp.resize(unique(tmp.begin(),tmp.end()) - tmp.begin());
    int l = 0, r= tmp.size()-1;
    ll all = 1ll*n*(n+1)/2;
    while (l<=r) {
        int mid = (l+r)/2;
        int X = tmp[mid];
       // cout<<X<<" "<<l<<" "<<r<<endl;
        memset(t,0,sizeof(t));
        int cur = n+1;
        update(cur);
        ll num=0;
        for (int i=1;i<=n;i++) {
            if (a[i]<=X) cur++;
            else cur--;
            //cout<<Get(cur)<< " cur = " <<cur<< " ";
            num += Get(cur-1);
            update(cur);
        }
        //cout<<num<<endl;
        if (2*num <= all) l = mid+1;
        else res=mid,r = mid-1;

    }
    cout<<tmp[res]<<endl;
}


Measured memory_bytes: 1912
#include <iostream>
#include <stack>
#define N 100
#define WHITE 0
#define GREY 1
#define BLACK 2
#define INFTY 100000
using namespace std;

int color[N];//color用来记录访问状态
int M[N][N];//M[N][N]是图的邻接矩阵表示法
int d[N],p[N];
//d[N]用来记录连接T内顶点与V-T内顶点的边中，权值最小的边的权值
//p[n]用来记录MST中顶点v的父节点
void init_color_d()
{
    for(int i = 0; i < N; i++)
    {
        color[i] = WHITE;
        d[i] = INFTY;
    }
}
int prim(int n)
{
    init_color_d();
    d[0] = 0;//起始点为0结点，距离设置为0
    p[0] = -1;
    int u;
    while(true)//访问结点为u
    {
        int mincost = INFTY;
        for(int i = 0; i < n; i++)
        {
            if(color[i]!=BLACK&&d[i]<mincost)//求最小值
            {
                mincost = d[i];
                u = i;
            }
        }
        if(mincost==INFTY)break;//这时候表示没有取到最小值，即最小生成树已经完成
        color[u] = BLACK;//因为u是最小值，那么就先标志为访问完
        for(int v = 0; v < n; v++)
        {
            if(color[v]!=BLACK&&M[u][v]!=-1)//如果v没有被选入到MST集合里面，并且此边存在
            {
                if(M[u][v]<d[v])
                {
                    d[v] = M[u][v];//d[v]记录最小值
                    p[v] = u;//记录父节点
                    color[v] = GREY;//设置为已经尝试过此结点
                }
            }
        }
    }
    int sum = 0;
    for(int i = 0;i < n;i++){
        if(p[i]!=-1)sum+=M[i][p[i]];
    }
    return sum;
}

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j <n; j++)
        {
            cin >> M[i][j];
        }
    }
    cout<<prim(n)<<endl;

    return 0;
}



Measured memory_bytes: 3112
N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]


def dfs(cur, a, b, c):
    if cur == N:
        if min(a, b, c) > 0:
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
        else:
            return float('inf')
    ret0 = dfs(cur+1, a, b, c)
    ret1 = dfs(cur+1, a+L[cur], b, c) + 10
    ret2 = dfs(cur+1, a, b+L[cur], c) + 10
    ret3 = dfs(cur+1, a, b, c+L[cur]) + 10
    return min(ret0, ret1, ret2, ret3)


print(dfs(0, 0, 0, 0))

Measured memory_bytes: 45276
import bisect
A,B,Q=map(int,input().split())
INF=10**18
S=[-INF]+[int(input()) for i in range(A)]+[INF]
T=[-INF]+[int(input()) for i in range(B)]+[INF]
for q in range(Q):
    x=int(input())
    s=bisect.bisect_right(S,x)
    t=bisect.bisect_right(T,x)
    d=INF
    for i in [S[s-1],S[s]]:
        for j in [T[t-1],T[t]]:
            ds=abs(i-x)+abs(i-j)
            dt=abs(j-x)+abs(i-j)
            d=min(d,ds,dt)
    print(d)

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
using namespace std;
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
typedef long long ll;
const int INF = 1e9;
const ll INFl = 1e18;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll n, a, b; cin >> n >> a >> b;
	if (((a+b)&1)^1) cout << abs(a - b) / 2 << '\n';
	else {
		cout << min((abs(1ll - a) + abs(1ll - b) + 1) / 2, (abs(n - a) + abs(n - b) + 1) / 2) << '\n';
	}
	
	return 0;
}


Measured memory_bytes: 764
import java.util.*;


public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	class Pair{
		int a;
		int b;
		Pair(int a,int b){
			this.a=a;
			this.b=b;
		}
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		ArrayList<Pair> pl = new ArrayList<Pair>();
		for(int i=0; i<m; i++) {
			int a=sc.nextInt();
			int b=sc.nextInt();
			a--;
			b--;
			pl.add(new Pair(a,b));
		}

		UnionFind uf = new UnionFind(n);

		ArrayList<Long> ans = new ArrayList<Long>();
		long pre = (long)n*(long)(n-1)/(long)2;

		for(int i=m-1; i>=0; i--) {
			ans.add(pre);
			Pair p = pl.get(i);
			if(uf.find(p.a)!=uf.find(p.b)) {
				int as = uf.size(p.a);
				int bs = uf.size(p.b);
				pre = Math.max(0, pre-(long)as*(long)bs);
				uf.unite(p.a, p.b);
			}

		}
		for(int i=ans.size()-1; i>=0; i--) {
			System.out.println(ans.get(i));
		}
		sc.close();
	}

	class UnionFind {

		int r[];
		int size[];
		int rank[];
		UnionFind(int n){
			r = new int[n];
			size = new int[n];
			rank = new int[n];
			for(int i=0; i<n; i++) {
				r[i]=i;
				size[i]=1;
				rank[i]=0;
			}
		}

		public void link(int x, int y) {

			if(rank[x]<rank[y]) {
				r[x]=y;
				size[y] += size[x];
			}else {
				r[y]=x;
				size[x] += size[y];
				if(rank[x]==rank[y]) {
					rank[x]++;
				}
			}
		}

		public void unite(int x, int y) {
			link(find(x), find(y));
		}

		public int size(int x) {
			return size[find(x)];
		}

		public int find(int x) {
			int res = x;
			if(r[x] != x) {
				res = find(r[x]);
			}
			return res;
		}
	}
}


Measured memory_bytes: 81512
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  double x,s;
  while(cin>>x){
    s=x;
    for(int i=0;;i++){
      x*=2;
      s+=x;
      if (i==4)break;
      x/=3;
      s+=x;
    }
    printf("%.8f\n",s);
  }
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
public class AtCoder
{

    public static void Main()
    {
        //入力を保持する
        var N = int.Parse(Console.ReadLine());
        var As = Console.ReadLine().Split().Select(e => long.Parse(e)).ToArray();
        //Array.Sort(As);
        foreach (var a in As)
        {
            if (a == 0)
            {
                Console.WriteLine(0);
                return;
            }
        }
        long ans = 1;
        for (int i = 0; i < N; i++)
        {
            if (1000000000000000000 / As[i] < ans)
            {
                ans = -1;
                break;
            }
            ans = ans * As[i];
        }
        Console.WriteLine(ans);
    }
}


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

int main(){
    int n;
    vector <int> v;
    cin>>n;

    while(n--){
        int a;
        cin>>a;
        v.push_back(a);
    }

    int Max=-2000000000;
    int Min=v[0];
    int len=v.size();
    for(int i=1; i<len; i++){
        Max=max(Max, v[i]-Min);
        Min=min(Min,v[i]);
    }
    cout<<Max<<endl;

    return 0;
}



Measured memory_bytes: 3920
using System;

class Program
{
  static void Main()
  {
    int a = int.Parse(Console.ReadLine());
    if(a ==25) Console.WriteLine("Christmas");
    else if(a == 24) Console.WriteLine("Christmas Eve");
    else if(a == 23) Console.WriteLine("Christmas Eve Eve");
    else if(a == 22) Console.WriteLine("Christmas Eve Eve Eve");
  }
}


Measured memory_bytes: 11092
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <tuple>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rep1(i, n) for(int i=1; i<=n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
#define countof(array) (sizeof(array) / sizeof(array[0]))
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

string ab = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
string as = {"abcdefghijklmnopqrstuvwxyz"};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

void yes() {
  cout << "Yes" << endl;
}

void no() {
  cout << "No" << endl;
}

void print_array(int array[], int len) {

  for(int i=0; i<len; ++i) {
    cout << array[i] << endl;
  }

}

ll absolute(ll x) {
  return (x<0)? (-1)*x : x;
}

//g++ AtCoder.cpp -o AtCoder
//AtCoder

//--------------------------
int main() {

  string s, t, u;
  cin >> s >> t;
  int a, b;
  cin >> a >> b >> u;

  if(s==u) cout << a-1 << " " << b << endl;
  else if(t==u) cout << a << " " << b-1 << endl;

  return 0;
}


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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);


ll go(ll n){
    if(n == 1)return 1;
    return 1ll + 1ll * 2 * go(n / 2);
}


void solve(int testCase){

    ll n; scanf("%lld" , &n);
    printf("%lld\n" , go(n));

}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N;
void input(int **line){
	cin>>N;
	*line = new int[N];
	for(int i=0;i<N;++i){
		cin>>(*line)[i];
	}
}
long long merge(int *line,int lp,int mid,int rp){
	int ln=mid - lp;
	int rn=rp - mid;
	int *L=new int[ln+1];
	int *R=new int[rn+1];
	for(int i=0;i<ln;++i){
		L[i] = line[lp + i];
	}
	for(int i=0;i<rn;++i){
		R[i] = line[mid + i];
	}
	L[ln]=R[rn]=2000000000;
	long long res=0;
	int lu=0;
	int ru=0;
	for(int i = 0,I=rp-lp;i<I;++i){
		if(L[lu]<=R[ru]){
			line[lp+i]=L[lu];
			++lu;
		}else{
			line[lp+i]=R[ru];
			++ru;
			res+=ln-lu;
		}
	}	
	return res;
}
long long mergesort(int *line,int lp,int rp){
	long long res = 0;
	if(rp - lp >=2){
		int mid = (lp + rp)/2;
		res+=mergesort(line,lp,mid);
		res+=mergesort(line,mid,rp);
		res+=merge(line,lp,mid,rp);
	}
	return res;
}
int main(){
	int *line;
	input(&line);
	cout<<mergesort(line,0,N)<<endl;
	return 0;
}



Measured memory_bytes: 27296
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

def Pf(n):#nの素因数分解(prime:素数リスト)

    #if prime==None: prime=[True]*(n+1)

    ret=[]
    tmp=n

    for i in range(2,int(n**0.5)+1):
        #if not prime[i]: continue
        if tmp%i==0:
            cnt=0
            while tmp%i==0:
                #ret.append(i)
                cnt+=1
                tmp//=i
            ret.append((i,cnt))
    if ret==[] or tmp!=1: ret.append((tmp,1))

    return ret

N=int(input().rstrip())
if N==1:
    print(0)
    exit()
a=Pf(N)
#print(a)
ans=0
for i in a:
    n,x=i
    cnt=1
    while x-cnt>=0:
        ans+=1
        x-=cnt
        cnt+=1
print(ans)
        

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	double a,b,v,w,t;
	cin>>a>>v>>b>>w>>t;
	double  c,d,e;
	if(a>b){
		c=a-b;
	}else if(a<b){
		c=b-a;
	}
	if(c<0)c*=-1;
	d=v-w;
	if(d<=0){
		cout<<"NO"<<endl;
		return 0;
	}else{
		e=c/d;
	}
	if(ceil(e)<=t){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}


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

int main(){
  
  int n;
  cin >>n;
  int p[n];
  for(int i=0; i<n; i++) cin >> p[i];
  
  int ans=0;
  for(int i=1; i<n-1; i++){
  	if( (p[i-1]<p[i]&&p[i]<p[i+1]) || (p[i+1]<p[i]&&p[i]<p[i-1]) ) ans++;
  }
  
    cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, long long>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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; }

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);

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

  int k, t; cin >> k >> t;
  vector<int> a(t);
  rep(i, t) {
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());

  int ans = max(0, a[0] - (k-a[0])-1);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll h; cin>>h;
    ll res=0,num=1,kaisu=0;
    while(h>0){
        res+=num*h;
      	kaisu+=num;
        h/=2; num*=2;
    }
    cout<<kaisu<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100000
#define Q 50000
 
int main(){
  int S[N], T[Q], c = 0;
  int left, right, mid, key,i,n,q;
 
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &S[i]);
  }
 
  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &T[i]);
  }
 
  for(i = 0; i < q; i++){
    key = T[i];
    left = 0;
    right = n;
 
    while(left < right){
      mid = (left + right) / 2;
      if(S[mid] == key){
        c++;
        break;
      }
      else if (key < S[mid]){
        right = mid;
      }
      else left = mid + 1;
    }
  }
 
  printf("%d\n", c);
 
  return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}


int N,K;
vi d;
vi memo;

int dfs(int x) {
  if(x >= N) {
    return x;
  }
  if(memo[x] != INF) return memo[x];
  int ans = INF;
  rep(i,sz(d)) {
    if(x != 0) {
      ans = min(ans,dfs(10 * x + d[i]));
    } 
  }
  memo[x] = ans;
  return ans;
}

int main() {
  cin >> N >> K;
  vi D(10,0);
  rep(i,K) {
    int x;
    cin >> x;
    D[x]++;
  }
  rep(i,10) {
    if(D[i] == 0) d.push_back(i);
  }
  memo = vi(N,INF);
  int ans = INF;
  rep(i,sz(d)) {
    ans = min(dfs(d[i]),ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	
	int d = a/b;
	int r = a%b;
	double f = a/(double)b;
	
	System.out.printf("%d %d %f",d,r,+f);
 }
}



Measured memory_bytes: 26540
{
  const main = (
    input: string
  ): void | string | number | string[] | number[] => {
    const r = _reader(input)
    const [_N, M] = r.nn()

    const ok: Record<string, boolean> = {}
    const bads: Record<string, number> = {}

    let good = 0
    let bad = 0

    for (let i = 0; i < M; i++) {
      const [p, s] = r.ss()

      if (!!ok[p]) continue

      if (s === 'AC') {
        ok[p] = true
        good += 1
        bad += bads[p] || 0
      } else {
        if (!bads[p]) bads[p] = 0

        bads[p] += 1
      }
    }

    return [good, bad]
  }

  const _reader = (str: string, i = 0) => {
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')
    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map(v => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  const _getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  const _res = main(_getInput())

  if (typeof _res === 'number' || typeof _res === 'string') console.log(_res)
  if (typeof _res === 'object') console.log(_res.join(' '))
}


Measured memory_bytes: 30132
#include<vector>
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=2e3+5;
int n,x,y,ans[maxn],d[maxn][maxn];
vector<int> e[maxn];
//pair<int,int> a;
//queue<pair<int,int> > q;
bool vis[maxn];
void dfs(int beg,int pos,int len){
	d[beg][pos]=min(d[beg][pos],len);
//	printf("ssssss%d %d %d\n",beg,pos,len);
	for(int i=0;i<e[pos].size();i++){
		int x=e[pos][i];
		if(!vis[x]){
			vis[x]=1;
			dfs(beg,x,len+1);
			vis[x]=0;
		}
	}
	return ;
}
int main(){
	memset(d,0x3f,sizeof(d));
	scanf("%d %d %d",&n,&x,&y);
	e[x].push_back(y);
	e[y].push_back(x);
	for(int i=1;i<n;i++){
		e[i].push_back(i+1);
		//e[i].push_back(i-1);
	}
	for(int i=2;i<=n;i++){
		e[i].push_back(i-1);
	}
	for(int i=1;i<=n;i++){
		memset(vis,0,sizeof(vis));
		vis[i]=1;
		dfs(i,i,0);
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			ans[d[i][j]]++;
		//	printf("%d ",d[i][j]);
		}
		//printf("\n");
	}
	for(int i=1;i<=n-1;i++){
		printf("%d\n",ans[i]/2);
	}
	return 0;
}


Measured memory_bytes: 16128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
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(){
    string s;
    ll k;
    cin >> s >> k;
    rep(i,k){
        if(s[i]!='1'){
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

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

    vector<int> ord(n, 0);
    iota(ord.begin(), ord.end(), 0);
    long double sum = 0;
    long double cnt = 0;
    do {
        long double dis = 0;
        for (int i = 0; i + 1 < n; ++i) {
            int a = ord[i], b = ord[i + 1];
            int x = P[a].first - P[b].first;
            int y = P[a].second - P[b].second;
            dis += hypot(x, y);
        }
        sum += dis;
        cnt += 1;
    } while (next_permutation(ord.begin(), ord.end()));

    auto res = sum / cnt;
    cout << res << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
//int ar[100001];

int main() {
	io;
	string s, dup;
	cin>>s;
	int q;
	cin>>q;
	vector<vector<char> > qs;
	vector<int>rev(q, 0);
	int n=q;
	while(q--) {
		int t;
		cin>>t;
		if(t == 1) {
			qs.pb({'R'});
		}
		else {
			int f;
			char c;
			cin>>f>>c;
			if(f == 1)
			qs.pb({'F', c});
			else qs.pb({'B', c});
		}
	}
	int init = 0;
	int k = -1;
	
	int r = 0;
	for(int i = n-1; i>=0; i--) {
		if(qs[i].size() == 1) {
			rev[i] = ++r;
			}
		else rev[i] = r;
	}
	k = 0;
	for(int i = 0; i<n; i++) if(qs[i].size() == 1) k ++;
	if(k&1)
		reverse(s.begin(), s.end());
	deque<char>dq;
	for(int i = 0; i<s.size(); i++)
	dq.pb(s[i]);
	for(int i = 0; i<n; i++) {
			if((rev[i] & 1) && qs[i].size() == 2) {
				if(qs[i][0] == 'F')
					dq.pb(qs[i][1]);
				else {
					dq.push_front(qs[i][1]);
				}
			}
			else if(qs[i].size() == 2) {
				if(qs[i][0] == 'B')
					dq.pb(qs[i][1]);
				else {
					dq.push_front(qs[i][1]);
				}
			
		}
	}
	while(!dq.empty()){
		dup += dq.front();
		dq.pop_front();
	}
	cout<<dup;
}


Measured memory_bytes: 14844
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
	int N,M,i,j,need_cans;
	long ans=0;

	cin >> N >> M;

	vector< pair<int,int> > A(N);

	for(i=0;i<N;++i){
		cin >> A[i].first >> A[i].second;
	}
	sort(A.begin(),A.end(),[](const pair<int,int> a, const pair<int,int> b){return a.first<b.first;});

	i=0;need_cans=M;
	while(need_cans>0){
		ans+=((long)min(need_cans,A[i].second))*A[i].first;
		need_cans-=A[i].second;
		++i;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
// 標準入力から一行を読み取り、指定の型に変換する
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let mut d: Vec<u32> = read_vec();

    d.sort();

    // ソートした配列の中央左の値と右の値が等しい場合、整数Kは存在しない
    if d[n / 2 - 1] == d[n / 2] { println!("0"); return; }

    println!("{}", d[n / 2] - d[n / 2 - 1]);
}


Measured memory_bytes: 4352
n = int(input())
A = [int(input()) for i in range(n)]

def insertionSort(A, n, g):
 global cnt
 for i in range(g, n):
  v = A[i]
  j = i - g
  while j >= 0 and A[j] > v:
   A[j + g] = A[j]
   j -= g
   cnt +=1
  A[j + g] = v

def shellSort(A, n, m, G):
 A1 = A[:]
 global cnt
 cnt = 0
 for i in range(m):
  insertionSort(A1, n, G[i])
 return A1

def Gmake(n):
 G=[]
 k = 1
 while k <= n and len(G) < 100:
  G.append(k)
  k = 3 * k + 1
 G.reverse()
 return G

G = Gmake(n)
A2 = shellSort(A, n, len(G), G)
print(str(len(G)))
print(" ".join(map(str, G)))
print(str(cnt))
for i in A2:
 print(str(i))

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

int main() {
  int a, b, c, d; cin >> a >> b >> c >> d;
  
  if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

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

    vector<char> d(n);
    vector<int> L(n);
    rep(i,n) cin >>d[i] >>L[i];

    priority_queue<pi, vector<pi>, greater<pi>> pq;
    rep(i,n)if(d[i]=='y') pq.push({L[i],i});

    int ans = 0;
    vector<bool> erased(n);
    while(!pq.empty()){
        pi p = pq.top();
        pq.pop();

        int len = p.fi;
        int idx = p.se;
        if(erased[idx]) continue;

        ++ans;
        int l = idx, r = idx;
        while( l>=0 && (d[l]=='y' || (d[l]=='n'&& L[l]<len)) ) --l;
        while( r<n && (d[r]=='y' || (d[r]=='n'&& L[r]<len)) ) ++r;

        for(int i=l+1; i<r; ++i) erased[i] = true;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3116
n = input()
a,b,c,d = n[0], n[1], n[2], n[3] 

def calc(arg1, arg2, arg3):
    if arg1 == 0:
        arg2 += "+" + arg3
    else:
        arg2 += "-" + arg3
    return arg2


for op1 in range(2):
    for op2 in range(2):
        for op3 in range(2):
            ans = a
            ans = calc(op1, ans, b)
            ans = calc(op2, ans, c)
            ans = calc(op3, ans, d)
            if eval(ans) == 7:
               break
        else:
            continue
        break
    else:
        continue
    break

print(ans + "=7")

Measured memory_bytes: 38384
package main

import (
	"fmt"
)

type Line struct {
	a, b int
}

type Point struct {
	value int
	next  map[int]bool
}

var points map[int]*Point

type Graph struct {
	lines      []Line
	startPoint int
	points     map[int]bool
}

func (g Graph) String() string {
	return fmt.Sprintf("%d:%v:%v", g.startPoint, g.lines, g.points)
}

func (g Graph) nextGrpah(num int) Graph {
	nextG := Graph{}
	nextG.lines = make([]Line, 0, 0)
	nextG.points = make(map[int]bool)
	if g.lines[num].a == g.startPoint {
		nextG.startPoint = g.lines[num].b
	} else {
		nextG.startPoint = g.lines[num].a
	}
	for i := 0; i < len(g.lines); i++ {
		if i == num {
			continue
		}
		nextG.lines = append(nextG.lines, g.lines[i])
	}
	for p, _ := range g.points {
		if g.lines[num].a == p || g.lines[num].b == p {
			continue
		}
		nextG.points[p] = true
	}
	return nextG
}

func (g Graph) candidateLines() []int {
	paths := make([]int, 0, 0)
	for i, line := range g.lines {
		if line.a == g.startPoint {
			if _, ok := g.points[line.b]; ok {
				paths = append(paths, i)
			}
		} else if line.b == g.startPoint {
			if _, ok := g.points[line.a]; ok {
				paths = append(paths, i)
			}
		}
	}
	return paths
}

func (g Graph) countEuler() int {
	sum := 0

	if len(g.lines) == 0 || len(g.points) == 0 {
		return 1
	}

	for _, path := range g.candidateLines() {
		nextG := g.nextGrpah(path)
		//fmt.Println(nextG)
		sum += nextG.countEuler()
	}
	return sum
}

func main() {
	var n, m int
	var a, b int
	fmt.Scan(&n, &m)
	g := Graph{}
	g.startPoint = 1
	g.lines = make([]Line, 0, 0)
	g.points = make(map[int]bool)
	for i := 1; i <= n; i++ {
		g.points[i] = true
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&a, &b)
		g.lines = append(g.lines, Line{a: a, b: b})
	}
	fmt.Println(g.countEuler())
}

Measured memory_bytes: 5504
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define reft0(i, j) setfill('0') << setw(i) << j

template<class T> inline bool chMax(T& a, T b){if(a < b) {a = b; return true;} return false;}
template<class T> inline bool chMin(T& a, T b){if(a > b) {a = b; return true;} return false;}

int main(){
    ll N, M;
    vector<pair<ll, ll>> drink;
    cin >> N >> M;
    rep(i, 0, N){
        ll temp1, temp2;
        cin >> temp1 >> temp2;
        drink.push_back(make_pair(temp1, temp2));
    }
    sort(begin(drink), end(drink));
    ll sum = 0;
    ll money = 0;
    rep(i, 0, N){
        ll cnt = 0;
        if (sum + drink[i].second <= M){
            cnt = drink[i].second;
        }else{
            cnt = M - sum;
        }
        money += (drink[i].first * cnt);
        sum += cnt;
    }
    cout << money << endl;
    return 0;
}

Measured memory_bytes: 2420
N, Y = map(int, input().split())

A, B, C = -1, -1, -1
for i in range(N + 1):
    for j in range(N + 1):
        k = N - i - j
        if k < 0:
            continue
        else:
            y = 10000 * i + 5000 * j + 1000 * k
            if Y == y:
                A = i
                B = j
                C = k
                break

print(A, B, C)

Measured memory_bytes: 3188
#if 1

#include <bits/stdc++.h>
using namespace std;
int n,a[25][25];
long long d[70005];

int main()
{
    scanf("%d",&n);
    for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j <= n;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
    for(int i = 1;i < (1 << n);i++)
    {
        for(int j = 1;j <= n;j++)
        {
            if((i & (1 << (j-1))))
            {
                for(int k = j+1;k <= n;k++)
                {
                    if((i & (1 << (k-1))))
                    {
                        d[i] += a[j][k];
                    }
                }
            }
        }
    }
    for(int i = 1;i < (1 << n);i++)
    {
        for(int j = i;j >= 1;j = i & (j-1))
        {
            d[i] = max(d[i],d[i-j]+d[j]);
        }
    }
    printf("%lld\n",d[(1 << n)-1]);
}

#endif // 1

Measured memory_bytes: 768
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int c = scanner.nextInt();
			scanner.nextLine();
			int[] l = new int[n];
			IntStream.range(0, n).forEach(i -> {
				l[i] = scanner.nextInt();
				scanner.nextLine();
			});
			System.out.println(dfs(0, 0, 0, 0, n, a, b, c, l));
		}
	}

	private static long dfs(int cur, int d, int e, int f, int n, int a, int b, int c, int[] l) {
		if (cur == n) {
			if (min(d, e, f) > 0) {
				return Math.abs(d - a) + Math.abs(e - b) + Math.abs(f - c) - 30;
			} else {
				return Integer.MAX_VALUE;
			}
		}
		long ret0 = dfs(cur + 1, d, e, f, n, a, b, c, l);
		long ret1 = dfs(cur + 1, d + l[cur], e, f, n, a, b, c, l) + 10;
		long ret2 = dfs(cur + 1, d, e + l[cur], f, n, a, b, c, l) + 10;
		long ret3 = dfs(cur + 1, d, e, f + l[cur], n, a, b, c, l) + 10;
		return min(ret0, ret1, ret2, ret3);
	}

	private static int min(int... x) {
		int min = Integer.MAX_VALUE;
		for (int number : x) {
			min = Math.min(min, number);
		}
		return min;
	}

	private static long min(long... x) {
		long min = Long.MAX_VALUE;
		for (long number : x) {
			min = Math.min(min, number);
		}
		return min;
	}
}


Measured memory_bytes: 30584
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define init(x,y) memset(x,y,sizeof(x))
#define mod 1000000007

int modexp(int x, int n){
	if(n==0){
		return 1;
	}
	else if(n&1){
		return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
	}
	else{
		return (modexp((x*x)%mod, n/2)%mod);
	}
}


signed main() 
{
   // haha
    int n,k;
    cin>>n>>k;
    int arr[k+1];
    init(arr,0);
    for(int i=k;i>=1;i--)
    {
        int v=k/i;
        int p=modexp(v,n);
        arr[i]+=p;
        for(int j=2*i;j<=k;j+=i)
        {
            arr[i]=(arr[i]-arr[j]+mod)%mod;
        }
    }
    int s=0;
    for(int i=1;i<=k;i++)
    {
        s+=(i*arr[i]);
        s%=mod;
    }
    cout<<s;
    
    
   
}
    
    

Measured memory_bytes: 4300
#include <stdio.h>

int main(void)
{

  int a,b,c,N1,N2,N3;

  N1=N2=N3=0;
  scanf("%d %d %d", &a,&b,&c);
  if(a >= b)
    if(b >= c){
      N1=a;
      N2=b;
      N3=c;
    }
    else if(a >= c){
      N1=a;
      N2=c;
      N3=b;
    }
    else{
      N1=c;
      N2=a;
      N3=b;
    }
  else{
    if(a >= c){
      N1=b;
      N2=a;
      N3=c;
    }
    else if(b >= c){
      N1=b;
      N2=c;
      N3=a;
    }
    else{
      N1=c;
      N2=b;
      N3=a;
    }
  }
    printf("%d %d %d\n", N3,N2,N1);
    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

ll f[105][15];
ll p[105][15];

int main() {
    cin >> n;
    REP(i,n) {
        REP(j,10) {
            cin >> f[i][j];
        }
    }
    REP(i,n) {
        REP(j,11) {
            cin >> p[i][j];
        }
    }

    ans = -(1LL << 32);
    FOR(b,1,(1<<10)) {
        sum = 0;
        REP(i,n) {
            cnt = 0;
            REP(j,10) {
                if((b>>j&1)&&f[i][j]){
                    cnt++;
                }
            }
            sum += p[i][cnt];
        }
        chmax(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
 
   int N = sc.nextInt();
   int M = sc.nextInt();
   int[] ans = new int[N];
   
   int tmp1;
   int tmp2;

   for(int i=0;i<M;i++)
   {
     tmp1 = sc.nextInt();
     tmp2 = sc.nextInt();
     
     ans[tmp1-1]++;
     ans[tmp2-1]++;
   }
   for(int i=0;i<N;i++) System.out.println(ans[i]);
 }
}

Measured memory_bytes: 21844
#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) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
	int N;
	cin>>N;
	while(N--){
		int gx,gy,M;
		cin>>gx>>gy>>M;
		ll dp[18][18] = {};
		dp[0][0] = 1;
		bool tabi[18][18][2] = {};
		while(M--){
			int x1,y1,x2,y2;
			cin>>x1>>y1>>x2>>y2;
			if(x1>x2 || y1>y2){
				swap(x1,x2);
				swap(y1,y2);
			}
			if(x2-x1)tabi[y1][x1][0] = true;
			else tabi[y1][x1][1] = true;
		}
		REP(x,17)REP(y,17){
			if(!tabi[y][x][0])dp[y][x+1] += dp[y][x];
			if(!tabi[y][x][1])dp[y+1][x] += dp[y][x];
		}
		if(dp[gy][gx]){
			cout<<dp[gy][gx]<<endl;
		}else{
			cout<<"Miserable Hokusai!"<<endl;
		}
	}
	return 0;
}

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

int main() {
  long long n, p;
  cin >> n >> p;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  long long ans = 1, cnt = 0;
  for (long long i = 2; i*i <= p; i++) {
    cnt = 0;
    while (p%i == 0) {
      cnt++;
      p /= i;
      if (cnt == n) {
        ans *= i;
        cnt = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 100100;
vector<int>g[maxn];
int n, m, u, v, dp[maxn];
bool visited[maxn];

int dfs(int node) {
    if(visited[node]) return dp[node];
    visited[node] = true;
    for(int i:g[node]) {
        if(!visited[i]) {
            dp[node] = max(dp[node], dfs(i)+1);
        }
        else {
            dp[node] = max(dp[node], dp[i] + 1);
        }
    }
    return dp[node];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    for(int i=0;i<m;i++) {
        cin>>u>>v;
        g[u].pb(v);
    }

    int result = 0;
    for(int i=1;i<=n;i++) {
        if(!visited[i]) {
            result = max(result, dfs(i));
        }
    }
    cout<<result<<"\n";

    return 0;
}


Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF LLONG_MAX/10
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007
//最大公約数
int gcd(int s,int t){
    if(t==0)return s;
    return gcd(t,s%t);
}
signed main(){
    int n;
    cin>>n;
    int a[n],key=0;
    rep(i,n){
        cin>>a[i];
        key+=a[i];
    }
    int con=0,ans=INF;
    rep(i,n-1){
        con+=a[i];
        ans=min(abs(con*2-key),ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5152
n = int(input())
s = ["A","T","G","C"]
ban = ["AGC","ACG","GAC"]
ban4 = ["ATGC","AGTC","AGGC"]
last3 = [{},{}]
zl = {}
for i in s:
    for j in s:
        for k in s:
            if i+j+k not in ban:
                last3[0][i+j+k] = 1
                zl[i+j+k] = 0
last3[1] = zl.copy()

for k in range(3,n):
    for i in last3[0]:
        for j in s:
            l = i+j
            if not (l in ban4 or l[1:] in ban):
                last3[1][l[1:]] += last3[0][i]
    last3[0] = last3[1]
    last3[1] =zl.copy()

print(sum(last3[0].values())%(10**9+7))

Measured memory_bytes: 3064
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto B = readln.split.map!(to!int).array;
    auto C = readln.split.map!(to!int).array;
    A.sort();
    B.sort();
    C.sort();
    long ans = 0;

    foreach (b; 0..N)
        ans += A.assumeSorted.lowerBound(B[b]).length.to!long * C.assumeSorted.upperBound(B[b]).length.to!long;

    ans.writeln;
}


Measured memory_bytes: 12500
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>

using namespace std;

//long long MOD = 1000000007;

int main()
{

    int n;
    cin >> n;
    long long b[100];
    for (size_t i = 0; i < n; i++)
    {
        cin >> b[i];
    }

    std::vector<long long> a(n, 0);
    for (size_t i = 0; i < n; i++)
    {
        if (i == 0) {
            a[i] = b[i];
            continue;
        }
        if (i == n - 1) {
            a[i] = b[i - 1];
            continue;
        }
        a[i] = std::min(b[i - 1], b[i]);
    }

    int s = 0;
    s = std::accumulate(a.begin(), a.end(), 0);
    std::cout << s << std::endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e9 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
    int n;
    cin >> n;
    ll a[n];
    set<ll> s;
    for(int i=0; i<n; i++){
    	cin >> a[i];
    	s.insert(a[i]);
    }
    if(s.size() == n){
    	cout << "YES\n";
    }else{
    	cout << "NO\n";
    }
    return 0;
}



Measured memory_bytes: 14552
#include<iostream>
using namespace std;
int bi(int a) {
  return a * a;
}
int main () {
  bool key[40000];
  for (int i = 0; i < 40000; i ++) {
    key[i] = false;
  }
  for (int i = 0; i < 200; i ++) {
    key[i * i] = true;
  }
  int sta[11][11];
  int N, D;
  cin >> N >> D;
  for (int i = 0; i < N; i ++) {
    for (int j = 0; j < D; j ++) {
      cin >> sta[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < N - 1; i ++) {
    for (int j = i + 1; j < N; j ++) {
      int k = 0;
      for (int l = 0; l < D; l ++) {
        k += bi(sta[i][l] - sta[j][l]);
      }
      if (key[k]) ans ++;
    }
  }
  cout << ans << endl;
}

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

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

	int ans = 0;
	int f_n = n >= 2 ? (n * (n-1)) / 2 : 0;
	int f_m = m >= 2 ? (m * (m-1)) / 2 : 0;

	ans += (f_n + f_m);

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

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var input = Console.ReadLine();
            var s = input.Split(' ');
            var abs = s[0] + s[1];
            int answer = (int)Math.Sqrt(int.Parse(abs));
            if (answer * answer == int.Parse(abs))
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("No");
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int main(){
    string s; cin>>s;
    int count=0;
    int a=s.size();
    for(int i=0;i<a;i++){
      if(s[i]!=s[a-1-i]) count++;
    }
    cout<<count/2;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

#define lc c[x][0]
#define rc c[x][1]

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 2e5+10;
const int MAXM = (int) 3e6+10;

///--------------------START-------------------------
int N,M;
int mark[MAXN];
int h[MAXN];

void work(){
    scanf("%d%d",&N,&M);
    for(int i=1;i<=N;i++) scanf("%d",&h[i]);
    for(int i=1;i<=M;i++){
        int u,v; scanf("%d%d",&u,&v);
        if(h[u]>=h[v]) mark[v]=1;
        if(h[v]>=h[u]) mark[u]=1;
    }
    int ans=0;
    for(int i=1;i<=N;i++)if(!mark[i]) ans++;
    printf("%d\n",ans);
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}









Measured memory_bytes: 4612