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

int H, W, K;
int check_point(vector<vector<int>> board, pair<int, int> hw)
{
  int ans = 0;
  board.at(hw.second - 1).erase(board.at(hw.second - 1).begin() + H - hw.first);
  int loop_cnt = -1;
  while (true)
  {
    loop_cnt += 1;
    bool didnt_change = true;
    int cnt;
    for (int i = H - 1; i >= 0; --i)
    {
      cnt = 0;
      int before = -1;
      for (int j = 0; j < W; ++j)
      {
        if (board.at(j).at(i) == -1)
        {

          if (cnt >= K)
          {
            didnt_change = false;
            ans += pow(2, loop_cnt) * cnt * board.at(j - 1).at(i);
            for (int k = 0; k < cnt; ++k)
            {
              board.at(j - 1 - k).erase(board.at(j - 1 - k).begin() + i);
            }
          }
          before = -1;
          cnt = 0;
        }
        else if (board.at(j).at(i) == before)
        {
          cnt += 1;
        }
        else
        {
          before = board.at(j).at(i);
          if (cnt >= K)
          {
            didnt_change = false;
            ans += pow(2, loop_cnt) * cnt * board.at(j - 1).at(i);
            for (int k = 0; k < cnt; ++k)
            {
              board.at(j - 1 - k).erase(board.at(j - 1 - k).begin() + i);
            }
          }
          cnt = 1;
        }
      }
      if (cnt >= K)
      {
        didnt_change = false;
        ans += pow(2, loop_cnt) * cnt * board.at(W - 1).at(i);
        for (int k = 0; k < cnt; ++k)
        {
          board.at(W - 1 - k).erase(board.at(W - 1 - k).begin() + i);
        }
      }
    }
    if (didnt_change)
    {
      break;
    }
  }
  return ans;
}

int main()
{
  cin >> H >> W >> K;
  vector<vector<int>> board(W, vector<int>(2 * H, - 1));

  for (int i = 0; i < H; ++i)
  {
    string row;
    cin >> row;
    for (int j = 0; j < W; ++j)
    {
      board.at(j).at(H - 1 - i) = (int)(row.at(j)) - 48;
    }
  }
  int ans = 0;
  for (int i = 0; i < W; ++i)
  {
    for (int j = 0; j < H; ++j)
    {
      ans = max(ans, check_point(board, {j + 1, i + 1}));
    }
  }
  cout << ans << endl;
}


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

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	ll N;
	cin >> N;
	vector<ll> A(N);
	for(int i = 0; i < N; i ++){
		cin >> A[i];
	}
	ll tmp = 0;
	for(int i = 0; i < N; i ++){
		tmp = (A[i] - tmp / 2) * 2;
	}
	tmp /= 2;
	for(int i = 0; i < N; i ++){
		cout << tmp;
		if(i == N - 1){
			cout << endl;
			break;
		}
		cout << " ";
		tmp = A[i] - tmp / 2;
		tmp *= 2;
	}

	return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define int long long
#define F first
#define S second
#define mp make_pair
using namespace std;

int n;
int val[2][100100];
pair<int, int> all[200200];
long long ans = 0;
int stat[100100];
vector< pair<int, int> > un;

signed main(){
	cin >> n;
	rep(i, n){
		cin >> val[0][i] >> val[1][i];
		all[i*2] = mp(val[0][i], i + n);
		all[i*2 + 1] = mp(val[1][i], i);
	}
	sort(all, all + 2*n);
	rep(i, n){
		ans += all[i].F;
		stat[all[i].S % n] |= (1 << (all[i].S/n));
	}
	for(int i = n; i < n*2; i++) un.push_back(all[i]);
	sort(un.begin(), un.end());
	int cnt00, cnt01, cnt10, cnt11;
	cnt00 = cnt01 = cnt10 = cnt11 = 0;
	rep(i, n){
		cnt00 += (stat[i] == 0);
		cnt01 += (stat[i] == 1);
		cnt10 += (stat[i] == 2);
		cnt11 += (stat[i] == 3);
	}
	if(cnt00) cout << ans << endl;
	else {
		if(!cnt01 || !cnt10){
			cout << ans << endl;
		} else {
			long long mn = 0x3f3f3f3f3f3f3f3f, s1 = 0, s2 = 0;
			rep(i, n){
				if(stat[i] == 1) s1 += (val[0][i] - val[1][i]);
				if(stat[i] == 2) s2 += (val[1][i] - val[0][i]);
			}
			mn = min(s1, s2);
			rep(i, n){
				int pos = 0;
				if(un[pos].S % n == i) pos++;
				mn = min(mn, un[pos].F - val[(stat[i]-1) ^ 1][i]);
			}
			cout << ans + mn << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 7924
import sys
import copy
#import math
#import itertools
#import numpy as np
#import re

def func(x,m):
    return x**2%m

N,X,M=[int(c) for c in input().split()]
myset = {X}
mydict = {X:0}
A = []
A.append(X)
s = X
i = 0
i_stop = i
#i=0は計算したので1から
for i in range(1,N):
    A.append(func(A[i-1],M))
    if A[i] in myset:
        i_stop = i
        break
    myset.add(A[i])
    mydict[A[i]] = i
    s+=A[i]
    if i == N-1:
        print(s)
        sys.exit(0)
    if A[i] == 0:
        print(s)
        sys.exit(0)

if i!=0:
    #最後にA[i]が出現したのは？
    A_repeat = A[mydict[A[i_stop]]:i_stop]
    s+=((N-1)-(i_stop-1))//len(A_repeat)*sum(A_repeat)

    for k in range(((N-1)-(i_stop-1))%len(A_repeat)):
        s+=A_repeat[k]

print(s) 

Measured memory_bytes: 17948
#include<bits/stdc++.h>
using namespace std;
#define llong long long
#define pii pair<llong,int>
#define fi first
#define se second

int n;
pii a[1000100];
llong d[1000100];
int siz[1000100];
llong cd;

struct data{
	int to,nxt;
}mp[2000200];
int head[1000100],cnt;
void link(int x,int y)
{
	mp[++cnt].to=y;
	mp[cnt].nxt=head[x];
	head[x]=cnt;
}
struct UFS{
	int fa[1000100];
	void reset(){for(int i=1;i<=n;++i)fa[i]=i;}
	int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
	bool merge(int x,int y)
	{
		int fx=find(x),fy=find(y);
		if(fx==fy)return 1;
		fa[fx]=fy;
		return 0;
	}
}ufs;
int ed[1000100][2];
void dfs(int x,int fa,int nd)
{
	cd+=nd;
	for(int i=head[x];i;i=mp[i].nxt)
		if(mp[i].to!=fa)
			dfs(mp[i].to,x,nd+1);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%lld",&a[i].fi),a[i].se=i;
	sort(a+1,a+n+1);
	for(int i=1;i<=n;++i)d[i]=a[i].fi,siz[i]=1;
	ufs.reset();
	for(int i=n;i>1;--i)
	{
//		cout<<endl;
//		cout<<"i: "<<i<<endl;
		int np=a[i].se;
		llong nd=d[i]+siz[np]-(n-siz[np]);
		int p=lower_bound(d+1,d+n+1,nd)-d;
		if(d[p]!=nd)puts("-1"),exit(0);
		p=a[p].se;
//		cout<<"np: "<<np<<" siz: "<<siz[np]<<" d: "<<d[i]<<" nd: "<<nd<<" p: "<<p<<endl;
		link(p,np);link(np,p);
		ed[i-1][0]=p,ed[i-1][1]=np;
		siz[p]+=siz[np];
		if(ufs.merge(np,p))puts("-1"),exit(0);
	}
	dfs(a[1].se,0,0);
	if(cd!=d[1])puts("-1"),exit(0);
	for(int i=1;i<n;++i)printf("%d %d\n",ed[i][0],ed[i][1]);
	return 0;
}


Measured memory_bytes: 12036
from collections import Counter
from scipy import misc
n = int(input())
s = [list(input()) for _ in range(n)]

ss = []
for i in range(n):
    a = sorted(s[i])
    a = ''.join(a)
    ss.append(a)

ss = Counter(ss)
ans = 0
n = len(ss)
k = ss.keys()
for i in k:
    if ss[i] == 1:
        continue
    if ss[i] >= 2:
        ans += round(float(misc.comb(ss[i],2)))
print(int(ans))

Measured memory_bytes: 51556
//submit
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

//にぶたんでよくね？
int main(){
    ll n,q;cin>>n>>q;
    vector<tuple<ll,ll,ll>> v;
    rep(i,n){
        ll s,t,x;
        cin>>s>>t>>x;
        v.push_back(make_tuple(-x,max(0ll,s-x),max(0ll,t-x)));
    }
    sort(ALL(v));
    vector<ll> d(q);//sort済み
    rep(i,q){
        cin>>d[i];
    }
    vector<vector<ll>> im(q+100);
    for(auto i:v){
        int l=lower_bound(ALL(d),get<1>(i))-d.begin();
        int r=upper_bound(ALL(d),get<2>(i)-1)-d.begin();
        im[l].push_back(-get<0>(i));
        im[r].push_back(get<0>(i));
    }
    set<ll> imos;
    for(ll i=0;i<q;i++){
        for(ll j=0;j<im[i].size();j++){
            if(im[i][j]>0){
                imos.insert(im[i][j]);
            }
            if(im[i][j]<0){
                imos.erase(-im[i][j]);
            }
        }
        if(imos.empty()){
            cout<<-1<<endl;
        }
        else{
            cout<<(*imos.begin())<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 29804
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
    int n,m;
    cin >> n >> m;
    if(n*2 > m){
        cout << m/2 << endl;
    }
    else{
        m -= n*2;
        m /= 4;
        cout << n + m << endl;
    }
    return 0;
}

Measured memory_bytes: 256
let
  N = parse(Int, readline())
  restToScore = []
  for i=1:N
    R, S = map(x -> x, split(readline()))
    push!(restToScore, (i, R, parse(Int, S)))
  end
  sort!(restToScore, by=x->(x[2], -x[3]))
  for i=1:N println(restToScore[i][1]) end
end

Measured memory_bytes: 115480
fun main(args: Array<String>) {
    abc113c()
}

fun abc113c() {
    val (n, m) = readLine()!!.split(" ").map { it.toLong() }
    val pyList = (1..m).map { readLine()!!.split(" ") }
        .mapIndexed { index, list -> Triple(index.toLong(), list[0], list[1]) }
        .sortedBy { triple -> triple.third.toLong() }

    val addedCount: MutableMap<String, Long> = mutableMapOf()
    val answer = pyList.map { triple: Triple<Long, String, String> ->
        val count = (addedCount[triple.second] ?: 0) + 1
        addedCount[triple.second] = count
        Triple(
            triple.first,
            triple.second.padStart(6, '0'),
            count.toString().padStart(6, '0')
        )
    }.sortedBy { it.first }.map { it.second + it.third }

    println(answer.joinToString(separator = System.lineSeparator()))
}


Measured memory_bytes: 159792
import itertools
N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]
ans = 0
for I in itertools.permutations(range(N)):
    for i in range(N-1):
        ans += ((xy[I[i+1]][0]-xy[I[i]][0])**2+(xy[I[i+1]][1]-xy[I[i]][1])**2)**0.5
for i in range(1,N+1):
    ans /= i
print(ans)

Measured memory_bytes: 42220
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  cin>>s;
  n=s.length();
   vector<ll>v(n+1,0);
   ll rig=0,lef=0;
   rep(i,0,n)
   {
     if(s[i]=='<') rig++;
     else rig=0;
     v[i+1]=rig;
   }
   per(i,n-1,-1)
   {
     if(s[i]=='>') lef++;
     else lef=0;
    v[i]=max(v[i],lef);
   }
   rep(i,0,n+1) k+=v[i];
   cout<<k;
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
 //  cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 7724
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

// const int maxn = 
// const int mo = 1e9 + 7;

int n, m;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> m;
	vector<int> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];

	vector<pair<int, int> > d(m);
	for (int i = 0; i < m; ++i)
		cin >> d[i].second >> d[i].first;
	
	sort(a.begin(), a.end());
	sort(d.rbegin(), d.rend());

	int j = 0;
	long long ans = 0;
	for (int i = 0; i < n; ++i) {

		if (j < m && d[j].second == 0)
			++j;

		if (j >= m) {
			while (i < n) {
				ans += a[i];
				++i;
			}

			break;
		}

		if (d[j].first > a[i]) {
			--d[j].second;
			ans += d[j].first;
		} else {
			ans += a[i];
		}
	}
	
	cout << ans << endl;

	return 0;
}

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

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


Measured memory_bytes: 256
using System;

namespace ITP1_1_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, h, m, s;
            a = int.Parse(Console.ReadLine());
            h = a / 3600;
            b = a % 3600;
            m = b / 60;
            s = b % 60;
            Console.WriteLine("{0}:{1}:{2}", h, m, s);
        }
    }
}

Measured memory_bytes: 9140
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int pqr[3];
int fom(string h);
int main(){
  string h;
  while(getline(cin,h)){
    if(h == "."){break;}
    int ans = 0;
    for(int i=0; i<27; i++){
      pqr[0] = i%3;
      pqr[1] = (i/3)%3;
      pqr[2] = (i/9)%3;
      if(fom(h) == 2){ans++;}
    }
    cout <<ans<<endl;
  }
  return 0;
}
int fom(string h){
  int one,two,dow,an;
  bool f = false;
  one = two = dow = an = -1;
  for(int i=0; i<h.size(); i++){
    if(h[i] == '0'){dow = 0;}
    else if(h[i] == '1'){dow = 1;}
    else if(h[i] == '2'){dow = 2;}
    else if(h[i] == 'P'){dow = pqr[0];}
    else if(h[i] == 'Q'){dow = pqr[1];}
    else if(h[i] == 'R'){dow = pqr[2];}
    else if(h[i] == '-'){f = (f+1)%2;}
    else if(h[i] == '+'){an = 0;}
    else if(h[i] == '*'){an = 1;}
    else if(h[i] == '('){
      int j,dps = 0;
      for(j = 1; j+i<h.size(); j++){
	if(h[j+i] == ')'){
	  if(dps != 0){dps--;}
	  else{break;}
	}
	if(h[j+i] == '('){dps++;}
      }
      dow = fom(h.substr(i+1,j-1));
      i = i+j;
    }
    if(dow != -1){
      if(f){dow = 2-dow;}
      if(one == -1){one = dow;}
      else{two = dow;}
      dow = -1;
      f = 0;
    }
    if(one != -1 && two != -1){
      if(an == 0){one = max(one,two);}
      if(an == 1){one = min(one,two);}
      an = -1;
      two = -1;
    }
  }
  return one;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;
vii v[100000];
int n;
int x,y; 
long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int ans[100000];
bool used[100000];
void dfs(int x,int fc){
	used[x]=true;
	vii ne;
	int res=0;
	rep(i,sz(v[x])){
		if(used[v[x][i].fr])
		continue;
		res++;
		if(res==fc)
		res++;
		ans[v[x][i].se]=res;
		ne.pb(v[x][i]);
	}
	rep(i,sz(ne))
	dfs(ne[i].fr,ans[ne[i].se]);
}
int main(){
	cin>>n;
	rep(i,n-1){
		cin>>x>>y;
		x--,y--;
		v[y].pb(mp(x,i));
		v[x].pb(mp(y,i));
	}
	int ans1=0;
	rep(i,n)
	ans1=max(ans1,(int)sz(v[i]));
	cout<<ans1<<"\n";
	rep(i,n)
	if(!used[i])
	dfs(i,-1);
	rep(i,n-1)
	cout<<ans[i]<<"\n";
	re 0;
}


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

int main(){
  string str;
  int a[100000]={0};
  int querys[100000][2];
  int q, n;
  
  cin >> n >> q;
  cin >> str;

  for (int i=0;i<q;i++){
    cin >> querys[i][0] >> querys[i][1];
  }

  for (int i=1;i<n;i++){
    if (str[i-1]=='A' && str[i]=='C')
      a[i] = a[i-1]+1;
    else
      a[i] = a[i-1];
  }

  for (int i=0;i<q;i++)
    cout << a[querys[i][1]-1] - a[querys[i][0]-1] << endl;
  cout << endl;

  return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define mp make_pair
#define f first
#define s second
 
#define all(s) s.begin(),s.end()
#define spresent(s,v) ((s).find(v)!=s.end())
#define present(s,v) (find(all(s),v)!=s.end())
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL)
 
#define fill_1d(a,val) fill(a,a+sizeof(a)/sizeof(a[0]),val)
#define fill_2d(a,val) fill(&a[0][0],&a[0][0]+sizeof(a)/sizeof(a[0][0]),val)
#define fill_nd(a,p2f,val) fill(p2f,p2f+sizeof(a)/sizeof(*p2f),val)
 
#define dout(i,s) cout<<"Case #"<<i<<": "<<s<<"\n"
 
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
 
typedef struct node{
	ll val,more=0,less=0;
	bool operator <(const node& a){
		return val<a.val;
	}
}node;
 
const int sz= 1e5+5;
const int M = 998244353;

vi prime;

void seive(int n){
	int sqn = sqrt(n), sq2n = sqrt(sqn);

	bool isprime[sqn+1];
	memset(isprime,1,sizeof(isprime));

	for(int i=2;i<=sq2n;++i){
		if(isprime[i])
			for(int j=i<<1;j<=sqn;j+=i)
				isprime[j]=0;
	}
	for(int i=2;i<=sqn;++i)
		if(isprime[i])
			prime.pb(i);

	// finding primes in [i+1,i+sqn]; i is a multiple of sqn
	for(int i=sqn;i<n;i+=sqn){
		memset(isprime,1,sizeof(isprime));
		sq2n = sqrt(i+sqn);
		for(int p: prime){
			if(p>sq2n)
				break;
			for(int j=(i/p+1)*p;j<=i+sqn;j+=p)
				isprime[j-i]=0;
		}
		for(int j=1;j<=sqn;++j)
			if(isprime[j])
				prime.pb(j+i);
	}
}

ll pow_mod(ll base, ll pow){
	ll ans = 1;
	while(pow){
		if(pow&1)
			ans = ans*base%M;
		base = base*base%M;
		pow>>=1;
	}
	return ans;
}

ll fac[200005];
ll inv_fac[200005];

void factorial(int n){
	fac[0] = fac[1] = 1;
	for(int i=2;i<=n;++i)
		fac[i] = fac[i-1]*i%M;

	inv_fac[n] = pow_mod(fac[n],M-2);
	for(int i=n-1;i>=0;--i){
		inv_fac[i] = inv_fac[i+1]*(i+1)%M;
	}
}

ll multinomial(vi& list){
	ll sum = 0, ans = 1;
	for(int i=0;i<list.size();++i){
		sum+=list[i];
		ans = ans*inv_fac[list[i]]%M;
	}
	ans = ans*fac[sum]%M;
	return ans;
}

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


int main() {
	ll n;
	cin>>n;
	vi pow;
	for(int i=2;i<=sqrt(n);++i){
		if(n%i==0){
			int cnt=0;
			while(n%i==0){
				++cnt;
				n/=i;
			}
			pow.pb(cnt);
		}
	}
	int ans=0;
	if(n>1)
		++ans;
	for(int i=0;i<pow.size();++i)
		ans+= (-1 + sqrt(1+8*pow[i]))/2;
	cout<<ans;










	return 0;
}

Measured memory_bytes: 3756
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#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 FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int A[3];
    FOR(i,0,3)
        cin >> A[i];
    sort (A, A+3);
    cout << A[2] - A[0] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
using Graph = vector<vector<int>>;

signed main(){
  int N, A, B;
  cin >> N >> A >> B;
  
  int ans = N/(A+B)*A;
  if( N%(A+B) != 0 ) ans += min(N%(A+B), A);
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int MAX = 100000;
int A[MAX];
int partition(int p , int r)
{
	int x = A[r];
	int i =  -1, k = 0;
	for(int k = 0 ;  k< r; k++)
	{
		if(x>=A[k])
		{
			i++;
			int t = A[k];
			A[k] = A[i];
			A[i] = t;
		}						
	}
	int t = A[i+1]; A[i+1] = x; A[r] = t;
	return i+1;
	
}

int main()
{
	int n;
	cin >> n;
	for(int i = 0 ;  i< n ; i++) cin >> A[i];
	int q = partition(0,n-1);
	
	for(int i = 0 ;  i< n ; i++) 
	{
		if(i) cout << " ";
		
		if(i == q)
			cout <<"[";
		cout << A[i];
		if(i == q)
			cout <<"]";
	}
	cout << endl;
		
}

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


typedef long long ll;


int main() {
	int X, Y, A, B, C;
	cin >> X >> Y >> A >> B >> C;

	vector<ll> p(A), q(B), r(C);
	for (int i = 0; i < A; ++i) cin >> p[i];
	for (int i = 0; i < B; ++i) cin >> q[i];
	for (int i = 0; i < C; ++i) cin >> r[i];

	sort(p.rbegin(), p.rend());
	sort(q.rbegin(), q.rend());
	sort(r.rbegin(), r.rend());

	// guard
	p.push_back(0);
	q.push_back(0);
	r.push_back(0);

	int x = 0, y = 0, z = 0;
	ll ans = 0;
	while (x + y + z < X + Y) {
		ll red = p[x]; if (x >= X) red = 0;
		ll green = q[y]; if (y >= Y) green = 0;
		ll cless = r[z];
		
		ll eat = max(red, green); eat = max(eat, cless);
		if (eat == red) {
			ans += red; ++x;
		} else if (eat == green) {
			ans += green; ++y;
		} else {
			ans += cless; ++z;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6020
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>

int solve(int N, std::vector<int> D)
{
    N++;
    D.emplace_back(0);
    
    if (N > 24) {
        return 0;
    }
    
    std::vector<int> cnt(13);
    for (int i = 0; i < N; i++) {
        cnt[D[i]]++;
        if (cnt[D[i]] == 3) {
            return 0;
        }
    }

    if (N > 12) {
        return 1;
    }
    
    int ret = 0;
    for (int i = 0; i < (1 << N); i++) {
        std::vector<int> d(N, 0);
        for (int j = 0; j < N; j++) {
            if (i >> j & 1) {
                d[j] = D[j] % 24;
            } else {
                d[j] = (24 - D[j]) % 24;
            }
        }
        
        int score = 10000000;
        for (int j = 0; j < N; j++) {
            for (int k = j + 1; k < N; k++) {
                int min, max;
                std::tie(min, max) = std::minmax(d[j], d[k]);
                
                int diff = std::min((max - min) % 24, (24 - (max - min)) % 24);                
                score = std::min(score, diff);
            }
        }

        
        ret = std::max(ret, score);
    }
    
    return ret;
}

int main()
{
    int N;
    std::cin >> N;
    
    std::vector<int> D(N);
    for (int i = 0; i < N; i++) {
        std::cin >> D[i];
    }
    
    std::cout << solve(N, D) << std::endl;

    return 0;
}


Measured memory_bytes: 256
import numpy as np
import sys

def gcd(p, q):
    if p < q:
        p, q = q, p
    while q > 0:
        p, q = q, p%q
    return p

n, m = map(int, input().split())
a = np.array([int(x) for x in input().split()])

k = a[0]
for i in range(1, n):
    k = k*a[i]//gcd(k, a[i])

b = a//2
while True:
    p = b%2
    if all(p):
        break
    elif any(p):
        print(0)
        sys.exit()
    else:
        b //= 2
        continue

a //= 2
k = a[0]
for i in range(1, n):
    k = k*a[i]//gcd(k, a[i])
print(1+(m-k)//(2*k) if m >= k else 0)

Measured memory_bytes: 23280
#include <iostream>
using namespace std;
void bsort(int *n1, int *n2, int *n3)
{
	if(*n1 > *n2) {
	int tmp = *n1;
	*n1 = *n2;
	*n2 = tmp;
	}
	if(*n1 > *n3){
	int tmp = *n1;
	*n1 = *n3;
	*n3 = tmp;
	}
	if(*n2 > *n3){
	int tmp = *n2;
	*n2 = *n3;
	*n3 = tmp;
	}
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	bsort(&a, &b, &c);
	cout << a << " " << b << " " << c << endl;
	return 0;
}



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

mydict=[[0 for _ in range(3)]for _ in range(n)]

for	x in range(1,n+1):
	a,b=input().split()

	mydict[x-1][0]=a
	mydict[x-1][1]=-int(b)
	mydict[x-1][2]=x

mydict.sort(key=lambda x:(x[0],x[1]))

#print(mydict)

for x in range(n):
	print(mydict[x][2])

Measured memory_bytes: 3064
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

public class Main implements Runnable {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    public void run() {
        String s = sc.next();
        int k = sc.nextInt();
        Set<String> set = new HashSet<>();
        for (int i = 0; i < s.length(); i++) {
            for (int j = 1; j <= k; j++) {
                if (i + j > s.length()) {
                    continue;
                }
                set.add(s.substring(i, i + j));
            }
        }
        PriorityQueue<String> q = new PriorityQueue<>(set);
        for (int i = 0; i < k-1; i++) {
            q.poll();
        }
        System.out.println(q.poll());
    }
}


Measured memory_bytes: 25940
from collections import defaultdict
dd = defaultdict(int)

ma=0

N=int(input())
for i in range(N):
    S=input()
    dd[S]+=1
    if dd[S]>ma:
        ma=dd[S]
       
    
ans=[]   
for k,v in dd.items():
    if v==ma:
        ans.append(k)
        
ans.sort()

for i in range(len(ans)):
    print(ans[i])





Measured memory_bytes: 95320
def main():
    # 個数を入力
    num = int(input())
    a = list(int(i) for i in input().split())

    print(*a)
    insertSort(a)

def insertSort(A):
    for i in range(1, len(A)):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        print(*A)

if __name__ == "__main__":
    main()


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


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

    s[5]=' ';
    s[13]=' ';

    cout<<s<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    int N, K;
    scan(K, N);
    if (500 * K < N) {
        print("No");
    } else {
        print("Yes");
    }

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque
n, m = map(int, input().split())
G = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
T = [-1]*n
que = deque()
que.append(0)
while que:
    v = que.popleft()
    for nv in G[v]:
        if T[nv] == -1:
            T[nv] = v+1
            que.append(nv)
print("Yes")
print(*T[1:], sep="\n")

Measured memory_bytes: 38608
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int h, w, d;
char c[525][525];
string col = "RGBYRGBY";

int main()
{
	cin >> h >> w >> d;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			c[i][j] = 'a';
		}
	}

	if (d%2==0) {
		int n = d / 2;
		for (int i = 0; i < d; i++) {
			int s;
			s = i / 2;
		
			int j = 0;

			while (1) {
				int ope = 0;
				int k = 0, m = i + j*d;
				while (k < h&&m >= 0) {
					if (j % 2 == 0 && m < w) {

						int n = d / 2;
						if (((k-s+2*d) / n) % 2 == 0)c[k][m] = col[0];
						else c[k][m] = col[2];
						//c[k][m] = col[0];

						ope++;
					}
					else if (j % 2 == 1 && m < w) {

						int n = d / 2;
						if (((k-s+2*d) / n) % 2 == 0)c[k][m] = col[1];
						else c[k][m] = col[3];
						//c[k][m] = col[1];

						ope++;
					}
					k++; m--;
				}
				if (ope == 0)break;
				j++;
			}
		}
	}
	if (d%2==1) {
		for (int i = 0; i < d; i++) {
			c[0][i] = col[0];
			int j = 0;

			while (1) {
				int ope = 0;
				int k = 0, m = i + j*d;
				while (k < h&&m >= 0) {
					if (j % 2 == 0 && m < w) {
						c[k][m] = col[0];
						ope++;
					}
					else if (j % 2 == 1 && m < w) {
						c[k][m] = col[1];
						ope++;
					}
					k++; m--;
				}
				if (ope == 0)break;
				j++;
			}
		}

		for (int i = w - 1; i >= max(w - 1 - d + 1, 0); i--) {
			int icol;
			if (c[0][i] == col[0]) icol = 0;
			else icol = 1;
			int j = 0;
			while (1) {
				int ope = 0;
				int k = 0, m = i - j*d;
				while (k < h&&m <= w - 1) {
					if (j % 2 == 0 && m >= 0) {
						if (c[k][m] == col[1 - icol])c[k][m] = col[icol + 2];
						ope++;
					}
					else if (j % 2 == 1 && m >= 0) {
						if (c[k][m] == col[icol])c[k][m] = col[3-icol];
						ope++;
					}
					k++; m++;
				}
				if (ope == 0)break;
				j++;
			}
		}


	}
	
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << c[i][j];
		}
		cout << endl;
	}
	return 0;
	
}

Measured memory_bytes: 768
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
#include <bitset>
#include <string>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define all(x) (x).begin(),(x).end()
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

int main() {
  int N, K; cin >> N >> K;
  int ans;
  if (N>=13) cout << K << endl;
  else if (N<=5) cout << 0 << endl;
  else cout << K/2 << 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 n = Integer.parseInt(sc.next());
    long[] a = new long[n+1];
    long[] b = new long[n+1];
    long ans1 =0, ans2 =0,total =0;
    
    //a[1]を+とするケース
    for (int i =1; i<=n; i++) {
      a[i] = Long.parseLong(sc.next());
      b[i] = a[i];
      total += a[i];
      if (i % 2 == 1 && total <=0) {
        long p = 1 - total;
        ans1 += p; 
        total -= a[i]; 
        a[i] += p; 
        total += a[i]; 
      }
      if (i % 2 == 0 && total >=0) {
        long p = 1 + total;
        ans1 += p; 
        total -= a[i]; 
        a[i] -= p; 
        total += a[i]; 
      }
    }
    
    total =0;
    
     //a[1]を-とするケース
    for (int i =1; i<=n; i++) {
      total += b[i];
      if (i % 2 == 0 && total <=0) {
        long p = 1 - total;
        ans2 += p;
        total -= b[i];
        b[i] += p;
        total += b[i];
      }
      if (i % 2 == 1 && total >=0) {
        long p = 1 + total;
        ans2 += p;
        total -= b[i];
        b[i] -= p;
        total += b[i];
      }
      
    }   
    System.out.print(Math.min(ans1,ans2));
  }
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    map<int, bool> sheet;
    int answer = 0;

    while (n--)
    {
        int x;
        cin >> x;
        if (sheet[x])
            sheet[x] = 0;
        else
            sheet[x] = 1;
    }

    for (auto number : sheet)
        if (number.second)
            answer++;

    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 8116
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define pr pair<int,int>
signed main()
{
    SPEED;
    int n;
    cin>>n;
    int a[n],ans=1;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    if(a[0]==0)
    {
        cout<<0;
        return 0;
    }
    for(int i=0;i<n;++i)
    {
        if (ans > (1000000000000000000 / a[i])) 
        {
           cout<<-1;
           return 0;
        }
    ans*=a[i];
   }
    cout<<ans;
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  char C;
  cin >> C;
  C++;
  cout << C << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//do {
//    print(v);
//  } while (std::next_permutation(v.begin(), v.end()));


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

	int N,M;
	cin >> N >> M;
	int ma[9] = { 2,5,5,4,5,6,3,7,6 };
	VI A(M);
	REP(i, M) cin >> A[i];
	SORT(A);
	VI dp(N + 1);
	dp[0] = 0;

	eFOR(i,1, N) {
		int cnt = INF * -1;
		for (int j = M - 1; j >= 0; j--) {
			if (i - ma[A[j]-1] >= 0)
				 cnt=max(cnt,dp[i - ma[A[j]-1]] + 1);
		}
		dp[i] = cnt;
	}
	//eREP(i, N)cout << dp[i];
	int R = dp[N];
	int match = N;
	//cout << endl;
	while (match > 0) {
		
		for (int i = M - 1; i >= 0; i--) {
			if (dp[match - ma[A[i]-1]] == R - 1 && match-ma[A[i]-1]>=0) {
				cout << A[i];// << " " << match << endl;;
				match -= ma[A[i]-1];
				R--;
				//cout << " " << match<<" "<<R<<" "<<dp[match - ma[A[0] - 1]] <<endl;
				break;
			}
		}
		
	}
	cout << endl;
	return 0;
}




















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

int main()
{
   ll n;
   cin>>n;
   vector<ll> arr(n);
   ll sum{}, mini{LONG_MAX};
   ll negcount{};
   for(ll i=0;i<n;i++)
   {
      cin>>arr[i];
   }
   for(auto i = arr.begin(); i != arr.end();i++)
   {
      sum += abs(*i);
      mini = min(mini, abs(*i));
      if(*i < 0)
         negcount++;
   }
   if(negcount%2 != 0)
      sum -= 2*mini;
   cout<<sum;
   return 0;
}


Measured memory_bytes: 4004
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vl;
 
ll n, a, b;
 
int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n >> a >> b;
	if ((n == 1 && a != b) || (a > b)) {
		cout << 0;
		return 0;
	}
	if (a == b) {
		n--;
	}	else {
		n -= 2;
	}
	cout << n * b - n * a + 1;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long int ll;

int main(){

    fastio ;

    ll n,m,x,y;
    

    cin >> n >> m;

    vector<ll> indegree(n+5);
    vector<ll> dist(n+5);
    vector<ll> adj[n+5];
    
    
    for(ll i = 0 ; i < m; i++){
        cin >> x >> y;
        indegree[y]++;
        adj[x].push_back(y);
    }

    queue<ll> q;

    for(ll i = 1; i <= n; i++) if(indegree[i] == 0) q.push(i);

    while(!q.empty()){
        ll j = q.front();
        q.pop();

        for(auto e : adj[j]){
            indegree[e]--;
            dist[e] = max(dist[e] , dist[j]+1);
            if(indegree[e] == 0) q.push(e);
        }
    }

    ll best = 0;
    for(ll i = 1; i <= n; i++) best = max(best , dist[i]);

    cout << best;
}




Measured memory_bytes: 7296
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;
inline void keep_window_open(){char ch; cin >> ch;}

int main(){
    int n;
    cin >> n;
    vector<double> a;
    for(int i = 0;i<n;++i){
        int temp;
        cin >> temp;
        a.push_back(1.0/temp);
    }
    double sum = 0.0;
    for(double d:a)sum+=d;
    cout << 1.0/sum<< endl;
    return 0;
}

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

int main(void){
  string s;
  cin >> s;
  int count = 0;
  if(s[0] == '1'){count++;}
  if(s[1] == '1'){count++;}
  if(s[2] == '1'){count++;}
  cout << count << endl;
}

Measured memory_bytes: 256
def main():
    MOD = 998244353

    N, S = map(int, input().split())
    *A, = map(int, input().split())

    dp = [0] * (S + 1)
    ans = 0
    for x in A:
        dp[0] += 1
        for j in range(S, x - 1, -1):
            dp[j] = (dp[j] + dp[j - x]) % MOD
        ans = (ans + dp[S]) % MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define MOD 1000000007 
#define MOD1 998244353
#define ll long long int
#define db double
#define endl "\n"
#define INF 1000000000000000000
#define INF1 1000000000
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define debx cout<<" X "<<endl;
#define deby cout<<" Y "<<endl;
#define debz cout<<" Z "<<endl;
#define deb(x) cout << '>' << #x << ':' << x << endl;
using namespace std;
 
ll mpow(ll a, ll b){
    if(!b)
        return 1;
    ll temp=mpow(a,b/2);
    temp=(temp*temp)%MOD;
    if(b%2)
        return (a*temp)%MOD;
    return temp;
}
ll mod_in(ll n){
    return mpow(n,MOD-2);
}
ll cl(ll a, ll b){
    if(a%b)
        return 1+a/b;
    return a/b;
}
ll dig(ll n){
    if(!n)
        return 0;
    return 1 + dig(n/10);
}
ll calc(ll n ){
    if(n<1)
        return 1;
    return n* calc(n-2);
}
void dfs(vector<ll>adj[], ll u, bool v[], ll h[], ll d[], ll par[]){
    ll ht = 0, y = 0;
    for(ll i=0 ; i<adj[u].size() ; i++){
        if(v[adj[u][i]])
            continue;
        v[adj[u][i]] = 1;
        par[adj[u][i]] = u;
        h[adj[u][i]] = 1 + h[u] ;
        dfs(adj,adj[u][i],v,h,d,par);
        y = max(y, d[adj[u][i]] + 1);
    }
    d[u] = y;
}
int main(){
    // fastio
    ll n,u,v;
    cin>>n>>u>>v;
    vector<ll> adj[n+5];
    for(ll i=1 ; i<n ; i++){
        ll x,y;
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    ll h[n+5]={0}, d[n+5]={0};
    h[v] = 0;
    bool vis[n+5] = {0};
    ll par[n+5] = {0};
    vis[v] = 1;
    par[v] = v;
    dfs(adj, v, vis, h, d, par);
    ll maxx = 0;
    ll curr = u;
    ll id;
    ll ct = 0;
    while(par[curr] != curr){
        // cout<<"XX "<<curr<<" "<<ct<<" "<<h[curr]<<endl;
        ll steps = h[curr];
        ll rem = d[curr] ;
        ll A_in = h[curr] - ct ;
        /*if(d[curr]%2 == 0){
           *- if(A_in%2 == rem%2){
                steps += d[curr] - 1 ;
            }
            else{
                steps += d[curr] - 2 ;
            }*/
        // }
    /*    else{
            if(A_in%2 == rem%2){
                steps += d[curr] - 2;
            }
            else{
                steps += d[curr] - 1;
            }
        } */
        steps += d[curr] - 1;
        if(maxx<steps && h[curr]>ct){
            maxx = steps ;
            id = curr ;
        }
        curr = par[curr];
        ct++;
    }
    // cout<<"X "<<id<<endl;
    ll ans = maxx ;
    cout<<maxx<<endl;
}


Measured memory_bytes: 16000
# abc110_a.py
# https://atcoder.jp/contests/abc110/tasks/abc110_a

# A - Maximize the Formula /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# あなたは子供にゲームをプレイさせ、その結果に応じてお小遣いをあげることにしました。
# そのゲームの内容は以下の通りです。
#     1以上 9 以下の整数 1 つが書かれた整数パネル 3 枚と + が書かれた演算子パネル 1枚がある
#     これら 4枚のパネルを横一列に並べて X+Yの形の数式を作る (すなわち、演算子パネルを端に置くことはできない)
#     数式を計算した結果と同じ値のお小遣いをあげる

# ゲームで使用する各整数パネルの値 A,B,Cが与えられるので、あげることになり得るお小遣いの最大値を求めてください。

# 制約
#     入力はすべて整数である
#     1≤A,B,C≤9

# 入力
# 入力は以下の形式で標準入力から与えられる。
# A B C

# 出力
# あげることになり得るお小遣いの最大値を出力せよ。

# 入力例 1
# 1 5 2

# 出力例 1
# 53

# 52+1 と並べたときにあげることになるお小遣いは 53となりこれが最大です。

# 入力例 2
# 9 9 9

# 出力例 2
# 108

# 入力例 3
# 6 6 7

# 出力例 3
# 82


def calculation(lines):
    # N = int(lines[0])
    a, b, c = list(map(int, lines[0].split()))
    result = max(a, b, c) * 9 + a + b + c
    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['1 5 2']
        lines_export = [53]
    if pattern == 2:
        lines_input = ['9 9 9']
        lines_export = [108]
    if pattern == 3:
        lines_input = ['6 6 7']
        lines_export = [82]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int maxn = 10;
const int mod = 1e9+7;

using namespace std;

int h,w,k;

void solve(){
	cin>>h>>w>>k;
	int black_qtd=0,ans=0;
	vector<vector<char>> grid(h,vector<char>(w));
	for(int i=0;i<h;++i){
		for(int j=0;j<w;++j){
			cin>>grid[i][j];
			black_qtd+=grid[i][j]=='#';
		}
	}
	for(int i=0;i<(1<<h);++i){
		vector<vector<char>> tmp = grid;
		for(int x=0;x<h;++x){
			if(i&(1<<x)){
				for(int c=0;c<w;++c)
					tmp[x][c]= '*';
			}
		}
		for(int j=0;j<(1<<w);++j){
			vector<vector<char>> aux = tmp;
			for(int x=0;x<w;++x){
				if(j&(1<<x)){
					for(int r=0;r<h;++r)
						aux[r][x] = '*';
				}
			}
			int cnt=0;
			for(int r=0;r<h;++r){
				for(int c=0;c<w;++c){
					cnt+=aux[r][c]=='#';
				}
			}
			ans+=(cnt==k);
		}
	}
	cout<<ans<<endl;
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3656
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL H, W, h, w;
	in >> H >> W >> h >> w;

	out << (H - h)*(W - w) << std::endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	hl := make([]int, n+2)
	for i := 1; i < n+1; i++ {
		sc.Scan()
		h, _ := strconv.Atoi(sc.Text())
		hl[i] = h
	}

	ans := 0
	for i := maxi(hl); i > 0; i = maxi(hl) {
		l, r := rangeLR(hl, i)
		c := hl[i] - max(hl[l-1], hl[r+1])
		for j := l; j <= r; j++ {
			hl[j] -= c
		}
		ans += c
	}

	fmt.Println(ans)
}

func rangeLR(hl []int, i int) (int, int) {
	j := i - 1
	for hl[j] == hl[i] {
		j--
	}
	l := j + 1

	j = i + 1
	for hl[j] == hl[i] {
		j++
	}
	r := j - 1
	return l, r
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func maxi(l []int) int {
	max := 0
	j := 0
	for i, v := range l {
		if v > max {
			max = v
			j = i
		}
	}
	return j
}


Measured memory_bytes: 640
d = {'m':1000,'c':100,'x':10,'i':1}
k = ['i','x','c','m']
def digit(s):
    r,p = 0,1
    for x in s:
        if x.isdigit(): p = int(x)
        else:
            r += p*d[x]
            p = 1
    return r

for _ in range(int(input())):
    a,b = input().split()
    s = digit(a)+digit(b)
    r = []
    for i,x in enumerate(reversed(str(s))):
        if x!='0': r += [x+k[i]] if x!='1' else [k[i]]
    print(*reversed(r),sep='')

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

int main() {
  string str1, str2, str3;
  cin >> str1 >> str2 >> str3;
  char c1 = str1.at(0);
  char c2 = str2.at(0);
  char c3 = str3.at(0);
  cout << c1 <<c2 << c3 << endl;
}

Measured memory_bytes: 256