akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 200001
#include<cstring>
using namespace std;
char s[N];
int a[N][26];
int n,len;
int d[N+1],dis[N];
bool bz[N],sig[N];
int main(){
	scanf(" %s",s+1);
	n=strlen(s+1);
	for (int i=n-1;i>=0;i--){
		for (int j=0;j<26;j++)a[i][j]=a[i+1][j];
		a[i][s[i+1]-'a']=i+1;
	}
	for (int i=1;i<=n;i++)dis[i]=n;
	int l=0,r=1;
	bz[0]=1;
	len=n;
	while (l!=r){
		l=l%N+1;
		for (int i=0;i<26;i++){
			if (a[d[l]][i]&&dis[d[l]]+1<dis[a[d[l]][i]]){
				dis[a[d[l]][i]]=dis[d[l]]+1;
				if (!bz[a[d[l]][i]])
					bz[d[r=r%N+1]=a[d[l]][i]];
			}
			if (!a[d[l]][i]){
				len=min(len,dis[d[l]]),sig[d[l]]=1;
			}
		}
		bz[d[l]]=0;
	}
	for (int i=n;i;i--){
		if (sig[i]&&dis[i]==len){
			bz[i]=1;
			continue;
		}
		for (int j=0;j<26;j++)
			if (dis[a[i][j]]==dis[i]+1)bz[i]|=bz[a[i][j]];
	}
	int x=0;
	for (int i=1;i<=len;i++){
		for (int j=0;j<26;j++)
			if (bz[a[x][j]]&&dis[a[x][j]]==dis[x]+1){
				printf("%c",j+'a');
				x=a[x][j];
				break;
			}
	}
	for (int i=0;i<26;i++)
		if (!a[x][i]){
			printf("%c",i+'a');
			break;
		}
	return 0;
}

Measured memory_bytes: 22656
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define boolsize 1000001
#define pi pair<ll,ll>
#define vi vector<ll>
#define vii vector<pi>
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
    for(T x:v)
        cout<<x<<" ";
    cout<<endl;

}
template<typename T>
void showvector1(vector <T> v)
{
    ll n=v.size();
    fo1(i,n-1)
        cout<<v[i]<<endl;

}
template<typename T>
void showset(set <T> s)
{
    for(T x: s)
        cout<<x<<" ";
    cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
    for(auto it=m.begin();it!=m.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
    return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
    if(a.first==b.first)
        return(a.second>b.second);
    return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
    return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
    return !(a%2==b%2);
}
bool isprime(ll x)
{   if(x<=1)
     return false;
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
bool iseven(ll x)
{
    return !(x%2);
}
bool isodd(ll x)
{
    return (x%2);
}
/// check for test case before submitting
bool vfun()
{
            ll n;
            cin>>n;
            vector<pair<ll,ll>> v(n);
            fo(i,n)
            {

                cin>>v[i].sec>>v[i].fst;

            }
            sort(v.begin(),v.end());
            ll t=0;
            fo(i,n)
            {
                if((t+v[i].sec)<=v[i].fst)
                    t+=v[i].sec;
                else
                    return false;
            }
            return true;

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("inputh.txt", "r", stdin);
    freopen("outputh.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0); ///cant use scanf, printf
    cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); /// no scientific output
    ll test=1;
  //  cin>>test;
    while(test--)
    {


         if(vfun())
            cout<<"Yes\n";
         else
            cout<<"No\n";
    }
}
///before sub
/// check for value of zero and single input in array
///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
/// check whether test cases are given or not





Measured memory_bytes: 6360
S = input()
def palindrome(string): return 0 if string==string[::-1] else 1

N = len(S)
flag = False
if palindrome(S) == 0:
    if palindrome(S[:int((N - 1)/2)]) == 0:
        if palindrome(S[int((N + 3)/2 - 1):]) == 0:
            flag = True
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
n = int(input())
s = input()

s = list(s)

k = r = b = g = count = 0

for i in range(len(s)):
    for j in range(i+1,len(s)):
        k = 2*j-i
        if k < n and s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            count += 1    

rbg = s.count("R")*s.count("B")*s.count("G")

print(rbg-count)


Measured memory_bytes: 9220
R = list()
L = list()
N = int(input())
R.append(0)
for i in range(N):
    k = int(input())
    L.append(k)
    if k == 0:
        R.append(len(L))
R.append(N)
S = sum(L)
for i in range(len(R) - 1):
    if sum(L[R[i] : R[i + 1]]) % 2 == 1:
        S = S - 1
print(S // 2)


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

using namespace std;

#define li long long int

const int N = 1e5 + 3;

int n;
li a[N];
li basis[60];

void insertVector(li mask) {
	for (int i = 59; i >= 0; i--) {
		if (!(mask & (1ll << i))) continue;
		if (!basis[i]) {
			basis[i] = mask;
			return;
		}
		mask ^= basis[i];
	}
}

void solve() {
	cin >> n;
	li totXor = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		totXor ^= a[i];
	}
	li oddTimes = 0;
	for (int j = 0; j < 60; j++) {
		if (totXor & (1ll << j)) {
			for (int i = 1; i <= n; i++) {
				if (a[i] & (1ll << j)) {
					a[i] ^= (1ll << j);
				}
			}
			oddTimes |= (1ll << j);
		}
	}
	for (int i = 1; i <= n; i++) {
		insertVector(a[i]);
	}
	li maxXor = 0;
	for (int j = 59; j >= 0; j--) {
		if (!basis[j]) continue;
		if (maxXor & (1ll << j)) continue;
		maxXor ^= basis[j];
	}
	cout << oddTimes + 2 * maxXor;
}

int main() {
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

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

int main ()
{
	int h1, m1, h2, m2, k;
	int ret;
	cin >> h1 >> m1 >> h2 >> m2 >> k;

	ret = ((h2 * 60 + m2) - (h1 * 60 + m1) + 24 * 60) % (24*60) - k;

	cout << ret << endl;
	return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}


int h[SIZE];
int mx[SIZE];
int root[SIZE];

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

    int N, M;
    cin >> N >> M;
    for(int i = 1; i <= N; ++i) {
        cin >> h[i];

    }

    bool f[SIZE];
    for(int i = 1; i <= N; ++i) f[i] = true;
    for(int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        if(h[a] <= h[b]) f[a] = false;
        if(h[b] <= h[a]) f[b] = false;

    }

    int res = 0;
    for(int i = 1; i <= N; ++i) {
        if(f[i]) ++res;

    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 4152
use std::io::Read;
use std::collections::VecDeque;
use std::cmp::max;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut a: Vec<isize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    a.sort();
    let mut ans: isize = 0;
    for i in 0..4 {
        let mut q: VecDeque<isize> = a.clone().into_iter().collect();
        let mut result: VecDeque<isize> = VecDeque::new();
        let mut count: usize = i;
        while !q.is_empty() {
            match count % 4 {
                0 => {
                    result.push_back(q.pop_front().unwrap());
                },
                1 => {
                    result.push_front(q.pop_back().unwrap());
                },
                2 => {
                    result.push_back(q.pop_back().unwrap());
                },
                _ => {
                    result.push_front(q.pop_front().unwrap());
                },
            }
            count += 1;
        }

        let mut s = 0;
        for i in 1..n {
            s += (result[i] - result[i - 1]).abs();
        }
        ans = max(ans, s);
    }
    ans.to_string()
}


Measured memory_bytes: 6292
// Date: 2020-06-21

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

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define IO freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout)
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define D(x) cout << #x << " = " << x << endl;
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int n, a[N];
int main() {
	FIO;
	cin >> n;
	int sum = 0;
	rep(i, 1, n) {
		cin >> a[i];
		sum ^= a[i];
	}
	rep(i, 1, n) {
		cout << (sum ^ a[i]) << " ";
	}

	return 0;
}

Measured memory_bytes: 4444
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    int a;
    std::cin >> a;
    std::cout << a+a*a+a*a*a << "\n";
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod 1000000007
#pragma GCC optimize ("-O3")
#define mod2 998244353
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector <vector <int>>
#define v4096 vector <vector <lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli,lli>
#define m32 map<int,int>
#define m64it map<lli,lli>::iterator
#define m32it map<int,int>::iterator
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ist insert
#define endl "\n"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define p_q priority_queue 
#define min_p_q priority_queue <int,vt <int>,greater <int>>
using namespace std;
using namespace __gnu_pbds; 

template <typename T> 
void DEBUG_ARR(vt<T> a,char c)
{
	f(i,0,a.size())cout<<a[i]<<c;
	cout<<"\n";
}

lli tmod(lli x,lli m){return (x%m+m)%m;}//USE AT YOUR OWN RISK
lli power(lli x, lli y) 
{
    lli res = 1;  
   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1; 
        x = (x*x)%mod;  
    }
    if(res<0)
       res+=mod; 
    return res; 
}
// lli fact[2000009];
// lli ncr(lli n,lli r){
//     lli ans=fact[n];
//     if(r>n)return 0;
//     ans=(ans*power(fact[n-r],mod-2))%mod;
//     ans=(ans*power(fact[r],mod-2))%mod;
//     return ans;
// }

int main() 
{ 
    //fact[0]=1;
    //f(i,1,2000001)fact[i]=(i*fact[i-1])%mod;
    fastio;
    lli n,k;
    cin>>n>>k;
    lli a[n];f(i,0,n)cin>>a[i];
    if(k==n){
        cout<<1<<"\n";
        return 0;
    }
    cout<<1+(n-k-1)/(k-1)+1;
    return 0; 	
}



Measured memory_bytes: 1024
N_M = list(map(int,input().split()))
A = list(map(int,input().split()))

A.sort()

diff = []
for i in range(1,N_M[1]):
    diff.append(A[i] - A[i-1])

diff.sort()
print(sum(diff[::-1][N_M[0]-1:]))

Measured memory_bytes: 13960
unittest
{
	assert( [ "3 3", ".##", ".#.", "##." ].parse.expand.solve == 1 );
	assert( [ "2 2", "#.", ".#" ].parse.expand.solve == 2 );
	assert( [ "4 4", "..##", "#...", "###.", "###." ].parse.expand.solve == 0 );
	assert( [ "5 5", ".#.#.", "#.#.#", ".#.#.", "#.#.#", ".#.#." ].parse.expand.solve == 4 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto hw = input.front.split.to!( long[] );
	auto css = new dchar[][]( hw[ 0 ], hw[ 1 ] );
	foreach( ref cs; css )
	{
		input.popFront;
		cs = input.front.to!( dchar[] );
	}
	return tuple( css );
}

auto solve( dchar[][] css )
{
	auto dp = new long[][]( css.length, css[ 0 ].length );
	foreach( ref dpp; dp ) dpp[] = long.max;
	dp[ 0 ][ 0 ] = ( css[ 0 ][ 0 ] == '#' );
	foreach( y, cs; css )
	{
		foreach( x, c; cs )
		{
			auto pb = ( c == '#' );
			if( y + 1 < dp.length )
			{
				auto nb = ( css[ y + 1 ][ x ] == '#' );
				dp[ y + 1 ][ x ] = min( dp[ y + 1 ][ x ], dp[ y ][ x ] + ( !pb && nb ) );
			}
			if( x + 1 < dp[ y ].length )
			{
				auto nb = ( css[ y ][ x + 1 ] == '#' );
				dp[ y ][ x + 1 ] = min( dp[ y ][ x + 1 ], dp[ y ][ x ] + ( !pb && nb ) );
			}
		}
	}
	return dp[ $ - 1 ][ $ - 1 ];
}


Measured memory_bytes: 508
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <math.h>
#include <string>
#include <math.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;

const ll mod = 1000000007;
const ll INF = 1000000000000;
ll A, B, C;

ll pow_mod(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2 == 1)
	{
		return pow_mod(x, y - 1) * x % mod;
	}
	else
	{
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

int main()
{
	cin >> A >> B >> C;
	if (A - B > C)
	{
		cout << 0 << endl;
	}
	else
	{
		cout << C - (A - B) << endl;
	}

	int www;
	cin >> www;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,ans=0,s[10000],b[10000];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
		b[s[i]]=1;
	}
	for(int i=1;i<=100;i++)ans+=b[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int foo = a * 100 + b * 10 + c;
	if (foo % 4 == 0) {
		printf("YES\n");
	} else {
		printf("NO\n");
	}
}


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

int main() {
    ll x;
    std::cin >> x;
    
    map<ll,bool> ex;
    ex[0] = true;
    
    ll now = 1;
    while(true){
        ex[now*now*now*now*now]=true;
        ex[-now*now*now*now*now]=true;
        if(ex[now*now*now*now*now-x]){
            std::cout << now<<" "<< ((now*now*now*now*now-x<0) ? "-" : "")<<pow(abs(now*now*now*now*now-x),1/5.0) << std::endl;
            return 0;
        }
        now++;
    }
}

Measured memory_bytes: 4252
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>

using namespace std;

void b_k_th_common_divisor(void) {
	int a, b, k;
	cin >> a >> b >> k;
	int ptr = 0;
	int* div;
	div = (int*)calloc(100, sizeof(int));
	for (int i = 1; i <= 100; i++) {
		if (i > a && i > b)break;
		if ((a % i == 0) && (b % i == 0)) {
			div[ptr++] = i;
			
		}
	}

	sort(div, div + 100, greater<int>());

	cout << div[k - 1] << endl;
}

int main()
{
    b_k_th_common_divisor();

    return 0;
}

Measured memory_bytes: 3576
fn main() {
    let v: Vec<i32> = read();
    if v[0] < v[1] && v[1] < v[2] {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    let stdin = std::io::stdin();
    stdin.read_line(&mut buf).unwrap();
    return buf.split_whitespace().flat_map(str::parse).collect();
}


Measured memory_bytes: 5024
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;

/*C++になってるか認したほうがよくない？WOWWOW*/
/*DP使ったほうがよくない？？WOWWOW*/

int main(){
  int N; cin>>N;
  string S; cin>>S;
  if(N<=3){
    cout<<"0"<<endl;
    return 0;
  }
  else{
    ll r, g, b, ans;
    r=count(S.begin(), S.end(), 'R');
    g=count(S.begin(), S.end(), 'G');
    b=count(S.begin(), S.end(), 'B');
    ans=r*g*b;
    for(int i=0; i<N-2; i++){
      for(int j=i; j<N-1; j++){
      	if(2*j-i<N){
        	if(S.at(i)!=S.at(j) && S.at(j)!=S.at(2*j-i) && S.at(2*j-i)!=S.at(i)){
            	ans--;
            }
        }
      }
    }
    cout<<ans<<endl;
    return 0;
  }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const int mod=1e9+7;
#define pb push_back
#define pii pair<ll,ll>
#define pi pair<int ,int> 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i,a,n) for(int i=a;i>=n;i-- )
const int n=1e6;
ll inv[3*n];
ll fact[3*n];
ll infact[3*n];

ll nck(int n,int k){
  return fact[n]*infact[k]%mod*infact[n-k]%mod;
}

int main()
{    
   inv[1]=1;
   REP(i,2,3*n)
   {
       inv[i]=mod-mod/i*inv[mod%i]%mod;
   }
   fact[0]=1;infact[0]=1;
   REP(i,1,3*n)
   {
       fact[i]=((fact[i-1]%mod)*(i%mod))%mod;
       infact[i]=(infact[i-1]*inv[i])%mod;
   }
    
    ll r1,r2,c1,c2;
    cin>>r1>>c1>>r2>>c2;
    cout<<((nck(r2+c2+2,c2+1)-nck(r1+c2+1,c2+1)-nck(r2+c1+1,c1)+nck(r1+c1,c1)%mod+mod)%mod);
  
    return 0;
}

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

int main(){
  int n,x;
  cin >> n >> x;
  vector<int> l(n);
  for(int i=0;i<n;i++){
    cin >> l.at(i);
  }
  int d = 0;
  int count = 0;
  for(int k=0;k<n;k++){
    d = d + l.at(k);
    if(d<=x) count++;
  }
  cout << count+1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define DBG(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll MOD = 1e9+7;
const ll MAX = 1e18*2;

vector<int> g[111111];
int dp[111111];

int dfs(int x){
  if(dp[x]!=-1)return dp[x];
  dp[x]=0;
  for(int i=0;i<g[x].size();i++){
    dp[x]=max(dp[x],dfs(g[x][i])+1);
  }
  return dp[x];
}

int main(){
  int n,m;
  cin>>n>>m;
  fill_n(dp,111111,-1);
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    x--,y--;
    g[x].PB(y);
  }
  int ans=0;
  for(int i=0;i<n;i++){
    ans=max(ans,dfs(i));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 8576
// clang-format off
#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;}
// clang-format on

vector<ll> divisor(ll n) {
    vector<ll> d;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            d.pb(i);
            if (i != n / i) d.pb(n / i);
        }
    }
    sort(all(d));
    return d;
}

ll f(ll n, ll k) {
    while (n % k == 0) n /= k;
    return n % k;
}

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

    vector<ll> x = divisor(n), y = divisor(n - 1);

    int ans = 0;
    for (auto v : {x, y})
        for (ll k : v) {
            if (k == 1) continue;
            if (f(n, k) == 1) ++ans;
        }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 384
def main():
    S = input()[::-1]
    ans = 0
    mods = [0] * 2019
    mods[0] = 1
    current = 0
    x = 1
    for s in S:
        current = (current + x * int(s)) % 2019
        ans += mods[current % 2019]
        mods[current % 2019] += 1
        x = x * 10 % 2019
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9320
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

    // input
    ll N; 
    cin >> N;

    ll count = 0;
    FOR(i, 1, N+1){
        string s = to_string(i);
        if(s.size()%2==1){
            count++;
        }
    }
    p(count);
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> dp(100001,-1);

int back(vector<int> &N, int index){
	if(index+2==N.size()){
		return abs(N[index]-N[index+1]);
	}
	if(index+1==N.size()){
		return 0;
	}
	if(dp[N.size()-index]!=-1)return dp[N.size()-index];
	int a = abs(N[index]-N[index+1]) + back(N,index+1);
	int b = abs(N[index]-N[index+2]) + back(N,index+2);
	
	dp[N.size()-index] = min(a,b);
	return dp[N.size()-index];
}

int main(){
//	10 30 40 20
	int n;
	cin>>n;
	vector<int> N(n);
	for(int i=0;i<n;i++){
		cin>>N[i];
	}
	dp[0]=0;
	dp[1]=abs(N[0]-N[1]);

	cout<<back(N,0);	
}

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

int main()
{
	int A, B, K;
	scanf("%d%d%d", &K, &A, &B);
	
	int distance;
	if(A % K == 0)
		distance = A;
		
	else
		distance = A + K - (A % K);
	
	//printf("distance = %d\n", distance);
	if(A <= distance && distance <= B)
		printf("OK");
		
	else
		printf("NG");
}


Measured memory_bytes: 3752
X, Y, Z, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
C = gets.split.map(&:to_i).sort.reverse

AB = A.product(B).map { |a, b| a + b }.sort.reverse
CAND = []

AB.take(K).each do |ab|
  C.each do |c|
    CAND << ab + c
  end
end

puts CAND.sort.reverse.take(K)


Measured memory_bytes: 165104
H, W = map(int, input().split())
A = [input() for _ in range(H)]

ans = ["#" * (W+2)]
for i in range(H):
    tmp = "#"
    tmp += A[i]
    tmp += "#"
    ans.append(tmp)

ans.append("#" * (W+2))

for i in range(H+2):
    print(ans[i])

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

#include <bits/stdc++.h>

using namespace std;

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

void d_err() {
    cerr << endl;
}

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

template <typename T>
void print(T x) {
    cout << x << endl;
}

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

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

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

void divisor(int n, vector<int>& ret) {
    for(int i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
}

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

    vi A(N);
    REP(i, N) {
        cin >> A[i];
    }

    sort(ALL(A));

    bool m[1000100];
    memset(m, false, sizeof(m));

    ll ans = 0;

    int before = -1;
    FOR(i, 0, N) {
        if (A[i] == before) {
            continue;
        }

        before = A[i];

        if (i < N - 1 ){
            if (A[i] == A[i+1]) {
                m[A[i]] = true;
                continue;
            }
        }

        vector<int> div;
        divisor(A[i], div);

        bool f = true;
        for(auto &e: div) {
            if (m[e]) {
                f = false;
                break;
            }
        }

        if (f) ans++;

        m[A[i]] = true;
    }

    print(ans);
    
}


Measured memory_bytes: 4980
n = int(input())
w = [input() for i in range(n)]
w_set = set(w)
key = 0
if len(w) != len(w_set):
    print("No")
    quit()
else:
    for i in range(1,n):
        key = w[i][0]
        if w[i-1][-1] != key:
            print("No")
            quit()

print("Yes")


Measured memory_bytes: 3060
import sys
import math
from collections import deque
import copy

input = sys.stdin.readline

s = input()
t = input()

dp = [[0 for _ in range(len(t) + 10)] for _ in range(len(s) + 10)]

for i in range(1, len(s)):
    for l in range(1, len(t)):
        if s[i - 1] == t[l - 1]:
            dp[i][l] = max(max(dp[i - 1][l - 1] + 1, dp[i][l - 1]), dp[i - 1][l])
        else:
            dp[i][l] = max(dp[i][l - 1], dp[i - 1][l])
length = dp[len(s) - 1][len(t) - 1]
if length == 0:
    print("")
else:
    ans = ''
    i = len(s) - 1
    l = len(t) - 1
    while i > 0 and l > 0:
        if dp[i-1][l] == dp[i][l] and i >= 1:
            i -= 1
        elif dp[i][l-1] == dp[i][l] and l >= 1:
            l -= 1
        else:
            ans = s[i - 1] + ans
            i -= 1
            l -= 1
    print(ans)


Measured memory_bytes: 120028
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;
typedef long long int ll;

int a[200000];
void solve()
{
	int n, k;
	cin >> n;
	for (int i = 0; i < n-1; i++)
		cin >> k, a[k]++;
	for (int i = 1; i <= n; i++)
		cout << a[i] << endl;
}
int main()
{
//	int t;
//	cin >> t;
//	while (t-- > 0)
		solve();
}


Measured memory_bytes: 4372
import java.util.*;
public class Main{
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for(int i = 0; i < N; i++){
            A[i] = 0;
        }
            for(int i = 1; i <= N; i++){
                int a = sc.nextInt();
                A[a-1] = i;
            }
for(int i =0;i<N;i++){
System.out.print(A[i] + " ");

    }
}
}


Measured memory_bytes: 63508
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define endl "\n"
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
const int N = 2000 + 10;
const ll inf = 1e18 + 10, mod = 1e9 + 7;
int x, n, a, ans, m[300];
int main()
{
    ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("lca_rmq.in", "r", stdin);
    //freopen("lca_rmq.out", "w", stdout);
    cin >> x >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a;
        m[a] = 1;
    }
    for(int i = x; i <= x + 200; i++)
        if(!m[i])
        {
            ans = i;
            break;
        }
    for(int i = x; i >= 0; i--)
        if(!m[i] && x - i <= ans - x)
        {
            ans = i;
            break;
        }
    cout << ans;
}

















Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
constexpr int sz = 524288;
int n,q,t,l,r;
char s[500005], c[5];
struct SegTree{
	bitset<sz*2> dat;
	void set(int x, bool b){
		dat[x += sz] = b;
		while(x /= 2) dat[x] = dat[x*2] || dat[x*2+1];
	}
	bool query(int a, int b, int k = 1, int l = 0, int r = sz){
		if(r <= a || b <= l) return false;
		if(a <= l && r <= b) return dat[k];
		return query(a,b,k*2,l,(l+r)/2) || query(a,b,k*2+1,(l+r)/2,r);
	}
} sg[26];
int main(){
	scanf("%d\n%s%d", &n,s,&q);
	rep(i,n) sg[s[i]-'a'].set(i,true);
	rep(i,q){
		scanf("%d", &t);
		if(t == 1){
			scanf("%d%s", &l, c);
			l--;
			sg[s[l]-'a'].set(l,false);
			sg[c[0]-'a'].set(l,true);
			s[l] = c[0];
		}else{
			scanf("%d%d", &l, &r);
			l--;
			int ans = 0;
			rep(j,26) if(sg[j].query(l,r)) ans++;
			printf("%d\n",ans);
		}
	}
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


int main(){
  int n;
  ll k;
  cin >> n >> k;
  vector<pair<int,int>> list;
  REP(i,n){
    int a,b;
    cin >> a >> b;
    list.push_back(make_pair(a,b));
  }
  sort(list.begin(), list.end());
  ll c=0;
  for(auto itr = list.begin(); itr != list.end(); itr++){
    //cout << itr->first << " " << itr->second << endl;
    c += itr->second;
    if(c >= k){
      cout << itr->first << endl;
      exit(0);
    }
  }
}





Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define LINF 1001001001001001001
typedef long long ll;
using namespace std;
int main() {
	int n, sw;
	cin >> n >> sw;
	vector<int> w(n), v(n);
	for (int i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
	}
	vector<vector<ll>> dp(n + 10, vector<ll>(100010, LINF));
	dp[0][0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 100010; j++) {
			if (j + v[i] < 100010) {
				dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
			}
			dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
		}
	}
	ll ans = 0;
	for (int i = 100009; i >= 0; i--) {
		if (dp[n][i] <= sw) {
			ans = i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 90332
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

template<typename T>
inline bool chmin(T& x, T a) {
	if (x >= a) { x = a; return true; }
	return false;
}

template<typename T>
inline bool chmax(T& x, T a) {
	if (x <= a) { x = a; return true; }
	return false;
}

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

	ll A, B, C, K; cin >> A >> B >> C >> K;

	ll ans = 0;
	
	ll x = min(K, A);
	K -= x;
	ans += x;

	x = min(K, B);
	K -= x;

	x = min(K, C);
	ans -= x;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3180
package main

// https://atcoder.jp/contests/agc006/tasks/agc006_a
//

import (
	"fmt"
)

func solve(n int, s, t string) {

	match := 0

	for i := 0; i < n; i++ {
		if s[i] == t[0] {
			for j := 1; ; j++ {
				if i+j >= n {
					match = j
					break
				}
				if s[i+j] != t[j] {
					match = 0
					break
				}
			}
			if match != 0 {
				break
			}
		}
	}

	fmt.Printf("%v\n", n*2-match)
}

func main() {
	var a int
	var s, t string

	n, err := fmt.Scanf("%d\n", &a)
	if err != nil || n != 1 {
		fmt.Println(n, err)
	}
	n, err = fmt.Scanf("%s\n", &s)
	if err != nil || n != 1 {
		fmt.Println(n, err)
	}
	n, err = fmt.Scanf("%s\n", &t)
	if err != nil || n != 1 {
		fmt.Println(n, err)
	}

	solve(a, s, t)
}


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

int main(){

  int N,M;
  int sum = 0, count = 0;
  vector<int> A;
  cin >> N >> M;
  A.resize(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];
    sum += A[i];
  }
  for(int i = 0; i < N; i++){
    if(A[i] >= (float)sum/(4*M)) count ++;
  }
  if(count >= M) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  20190801lesson
//
//  Created by Priscilla Leang on 8/1/19.
//  Copyright 漏 2019 Priscilla Leang. All rights reserved.
//

#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int f, m, a, b, c;
    string s;
    bool b1 = false;
    bool b2 = false;
    bool b3 = false;
    
    
    f = 0;
    cin>>a>>b>>c;
    int a1[a];
    for (int i = 0; i< a; i++){
        cin>>a1[i];
    }
    
    for (int i = 0; i< a; i++){
        for (int j = 1; j<=b; j+= a1[i]){
            f++;
        }
    }
    cout << f+c;
    
    
    
    
    return 0;
}

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

int selectionSort(int A[], int N){
    //cout << "bubbleSort() has calleed\n";
    int i, j, t, sw = 0, mini;
    for(i=0; i<N-1; i++){
        mini = i;
        for(j=i; j<N; j++){
            if(A[j] < A[mini]) mini = j;
        }
        swap(A[i], A[mini]);
        if(i != mini) sw++;
    }
    return sw;
}
    
int main(void){
    int A[100], N, i, sw;
    cin >> N;
    for(int i=0; i<N; i++) cin >> A[i];
    
    sw = selectionSort(A, N);
    
    for(int i=0; i<N; i++){
        if (i) cout << " ";
        cout << A[i];
    }
    cout << "\n";
    
    cout << sw << "\n";
    
    return 0;    
}


Measured memory_bytes: 3096
n, m = map(int, input().split())

sc = [list(map(int, input().split())) for i in range(m)]


for i in range(1000):
    i = str(i)
    x = 0
    if len(i) == n:
        for s, c in sc:
            if i[s-1] != str(c):
                x = 1
                break
        if x == 0:
            print(i)
            exit()

print(-1)

Measured memory_bytes: 38256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define PI 3.141592653589793238
#define INF 1050000000

using vi = vector<int>;


int main() {

	string s;

	cin >> s;

	int ans = 0;

	for (int i = 0; i < 4; i++)
	{
		if (s[i] == '+') {
			ans++;
		}
		else {
			ans--;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
const int N=10000005;
const int MOD=998244353;
int n;
long long pw2[N],pw3[N];
long long fac[N],inv[N];
long long ksm(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b&1) res=res*a%MOD;
		a=a*a%MOD,b>>=1;
	}
	return res;
}
void init(int n=10000000)
{
	pw2[0]=1;
	for(int i=1;i<=n;i++)
		pw2[i]=pw2[i-1]*2%MOD;
	pw3[0]=1;
	for(int i=1;i<=n;i++)
		pw3[i]=pw3[i-1]*3%MOD;
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%MOD;
	inv[n]=ksm(fac[n],MOD-2);
	for(int i=n;i>=1;i--)
		inv[i-1]=inv[i]*i%MOD;
	return;
}
long long C(int n,int m)
{
	if(m>n) return 0;
	else return fac[n]*inv[m]%MOD*inv[n-m]%MOD;
}
int main()
{
	init();
	scanf("%d",&n);
	long long ans=pw3[n];
	long long res=0;
	for(int i=n/2+1;i<=n;i++)
		res=(res+C(n,i)*pw2[n-i]%MOD)%MOD;
	for(int i=n/2+1;i<=n;i++)
		res=(res+C(n,i)*pw2[n-i]%MOD)%MOD;
	ans=(ans-res+MOD)%MOD;
	printf("%lld",ans);
	return 0;
}

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

int ze(int);

int main(){
  long long sum;
  int N;
  int i;

  cin>>N;

  vector<int> a(N);

  for(i=0;i<N;i++)
  cin>>a.at(i);

  int cnt=0;
  for(i=0;i<N;i++){
    if(a.at(i)<0)
    cnt++;
  }

  sum=0;
  for(i=0;i<N;i++)
  sum+=ze(a.at(i));
  // cout<<sum<<endl;

  if(cnt%2!=0){
    // cout<<"syori"<<endl;
    int min=1000000000;
    int d;
    for(i=0;i<N;i++){
      d=ze(a.at(i));
      if(min>d)
      min=d;
    }
    sum-=min*2;
  }

  cout<<sum<<endl;

}

int ze(int a){
  if(a<0)
  a*=(-1);
  return a;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(void) {
  int x,y;
  scanf("%d %d",&x,&y);
  int tmp;
  
  if(x<y) {
    tmp=x;
    x=y;
    y=tmp;
  }
  int r=x%y;
  while(r!=0) {
    x=y;
    y=r;
    r=x%y;
  }
  printf("%d\n",y);
  return 0;
}


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

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

print(res)


Measured memory_bytes: 3060
x,y,z,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
BC=[]
ABC=[]
for b in range(y):
    for c in range(z):
        BC.append(B[b]+C[c])
A.sort(reverse=True)
BC.sort(reverse=True)

for a in range(x):
    for bc in range(min(k,y*z)):
        ABC.append(A[a]+BC[bc])
ABC.sort(reverse=True)
for i in range(k):
    print(ABC[i])

Measured memory_bytes: 141780
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <set>

#define DEBUG 0

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

using namespace std;


int main(){
	lli n;
	vector<lli> v;
	for(int i=0;i<3;i++){
		lli tmp;
		cin>>tmp;
		v.push_back(tmp);
	}

	sort(v.begin(),v.end());
	cout<< v[2]- v[0]<<endl;

	return 0;

}

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

using namespace std;

#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{
    FAST();
    int i,k,l;
    string s;
    cin >> k >> s;
    l=s.size();
    if(l <= k)cout << s;
    else cout << s.substr(0,k)+"...";
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  int k;
  cin >> k >> s;
  
  
  
  
  if(s.size() <= k ){
    cout << s << endl;
    return 0;
  }
 
  else {
    for (int i=0; i < k ; i++){
    cout << s.at(i) ;
    }
    cout << "..." << endl;
    return 0;
  }
  
 
  
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define il inline
#define int long long
const int N=1e5+5;

int n,a[N],du[N];
int to[N+N],nx[N+N],hd[N],sze;

il void add(int u,int v){to[++sze]=v,nx[sze]=hd[u],hd[u]=sze,du[v]++;}

il bool dfs(int u,int F)
{
	int i,v,x=0,y=0,o=0;
	for (i=hd[u]; i; i=nx[i]) if ((v=to[i])!=F)
	{
		if (!dfs(v,u)) return 0;
		o=1,x+=a[v],y=std::max(y,a[v]);
	}
	if (!o) return 1;
	if (a[u]>x||a[u]<x-a[u]||a[u]<y) return 0;
	return a[u]-=x-a[u],1;
}

signed main()
{
	scanf("%lld",&n); int i,u,v;
	for (i=1; i<=n; i++) scanf("%lld",a+i);
	for (i=1; i<n; i++) scanf("%lld%lld",&u,&v),add(u,v),add(v,u);
	if (n==2) return puts(a[1]==a[2]?"YES":"NO"),0;
	
	for (i=1; i<=n; i++) if (du[i]==1) return puts(dfs(i,0)?"YES":"NO"),0;
	
	return 0;
}

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

using namespace std;

using ll = long long;

const ll MOD = 998244353;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

constexpr int MAXV = 1000000;

ll sum[MAXV + 1];
bool is_comp[MAXV + 1];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    int maxv = 0;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        maxv = max(maxv, a[i]);
        (sum[a[i]] += a[i]) %= MOD;
        (ans += MOD - a[i]) %= MOD;
    }

    for (int i = 1; i <= maxv; i++) {
        // if (is_comp[i]) continue;
        for (int j = i; (j += i) <= maxv; ) {
            // is_comp[j] = true;
            (sum[i] += sum[j]) %= MOD;
        }
    }

    for (int i = 1; i <= maxv; i++) {
        (sum[i] *= sum[i]) %= MOD;
    }

    for (int i = maxv; i >= 1; --i) {
        // if (is_comp[i]) continue;
        for (int j = i; (j += i) <= maxv; ) {
            (sum[i] += MOD - sum[j]) %= MOD;
        }        
    }

    for (int i = 1; i <= maxv; i++) {
        (ans += sum[i] * modpow(i, MOD - 2) % MOD) %= MOD;
    }
    (ans *= (MOD + 1) / 2) %= MOD;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 8832
#include <stdio.h>

int main()
{
	int N, K, L[50];
	int i, j, temp;
	int sum;

	scanf("%d %d", &N, &K);
	for(i = 0; i < N; i++) {
		scanf("%d", &L[i]);
	}

	for(i = 0; i < N; i++) {
		for(j = N - 1; j > i; j--) {
			if(L[i] < L[j]) {
				temp = L[j];
				L[j] = L[i];
				L[i] = temp;
			}
		}
	}
	
	sum = 0;
	for(i = 0; i < K; i++) {
		sum += L[i];
	}
	
	printf("%d\n", sum);		
			
	return(0);
}


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

int main()
{
	int n;
	scanf("%d", &n);
	int a[n+10];
	int i;
	for(i=0; i<n; i++)
	{
		scanf("%d", &a[i]);
	}
	int ans=0;
	for(i=0; i<n; i++)
	{
		ans += a[i]-1;
	}
	
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] a) throws IOException{

		String strLine ="";
		BufferedReader stdReader =
				new BufferedReader(new InputStreamReader(System.in));

		String t = null;

		while  ((strLine = stdReader.readLine()) != null) {
			t = strLine;
		}
		;

		StringBuffer sb = new StringBuffer(t);
		strLine = sb.reverse().toString();

			System.out.println(strLine);


	}

}

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

int main(){
    long N;
    cin >> N;
    vector<long> A(N);
    long m(numeric_limits<long>::min()), maxdex(-1), c(0);
    for(auto& i : A){
        scanf("%ld", &i);
        if(m < i){
            m = i;
            maxdex = c;
        }
        ++c;
    }
    swap(A[N - 1], A[maxdex]);
    nth_element(A.begin(), A.begin(), A.end() - 1, [&m](auto a, auto b){return a * (a - m) < b * (b - m);});
    cout << A[N - 1] << " " << A[0] << endl;
}

Measured memory_bytes: 1024
import sys

XYZ= list(sys.stdin.readline().rstrip().split(" "))

TOTAL_LEN  = int(XYZ[0])
ONE_OCCUPY= int (XYZ[1])
GAP= int(XYZ[2])


MIDDLE = TOTAL_LEN - 2*GAP

HOW_MANY = 0

while MIDDLE > 0:
    MIDDLE = MIDDLE - ONE_OCCUPY
    if MIDDLE == 0:
        HOW_MANY = HOW_MANY + 1
    elif MIDDLE < 0:
        break
    else:
        HOW_MANY = HOW_MANY + 1
        MIDDLE = MIDDLE - GAP
#ANSWER = int(MIDDLE / (ONE_OCCUPY + GAP))
#ANSWER = int(TOTAL_LEN / (ONE_OCCUPY + 2*GAP))

print(HOW_MANY)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<l_l> vpl;
typedef vector<string> vs;
typedef pair<l_l,ll> lll;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=1;i<=(n);i++)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
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(){
    string s;cin>>s;
    ll cnt=0;
    ll ans=0;
    rep(i,3){
        if(s[i]=='R')cnt++;
        else{
            chmax(ans,cnt);
            cnt=0;
        }
    }
    chmax(ans,cnt);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string.h>

using namespace std;

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

int main() {
  char S[(int)1e5];
  if (scanf("%s", S));
  int N = strlen(S);

  int A = 0, B = 0, C = 0;
  REP(i, N) {
    if (S[i] == 'a') ++A;
    if (S[i] == 'b') ++B;
    if (S[i] == 'c') ++C;
  }
  if (max(A, max(B, C)) - min(A, min(B, C)) <= 1) {
    printf("YES\n");
  } else
    printf("NO\n");
  return 0;
}


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

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

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

    int sun = 0;
    int i;
    for(i=1; i<=N; i++)
    {
        sun += i;
        if(sun >= N) break;
    }
    for(int j=1; j<=i; j++)
    {
        if(j != sun - N) cout << j << '\n';
    }

    return 0;
}

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

typedef long long LL;

LL bin(LL a, LL b, LL p) {
	LL res = 1;
	for (; b; b>>=1, a=a*a%p)
		if (b & 1)
			res = res * a % p;
	return res;
}
const int N = 1e5+50;
int q, a[N], c[N];
int n;


int main(int argc, char const *argv[])
{
	scanf("%d", &n);
	LL s = 0;
	for (int i=0; i<n; ++i) {
		scanf("%d", &a[i]);
		s += a[i];
		c[a[i]] ++;
	}

	scanf("%d", &q);
	for (int i=0; i<q; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		s += (y-x) * c[x];
		c[y] += c[x];
		c[x] = 0;
		printf("%lld\n", s);
	}
	
	return 0;
}


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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

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

   double a=(double)l/3;
   double ans=a*a*a;

   cout<< std::fixed << std::setprecision(15)<<ans<<endl;

   return 0;
}


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

int main(){
	int most, n;
	int array[101] = {0};
	most = 0;
	while(cin >> n){
		array[n]++;
		if(most < array[n]){
			most = array[n];
		}
	}
	for(int i=1; i<=100; i++){
		if(array[i] == most){
			cout << i << endl;
		}
	}
	return 0;
}

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

#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; while(t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;

template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << "\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

const int N = 1e6+5;
const int mod = 1e9+7;

int n;
LL dp[N][2][2];
vi tmp;
LL dfs(int len, bool con1, bool con9){
    if(len == n){
        //if(con1 && con9) dbg_out(tmp);
        return con1 && con9;
    }
    if(dp[len][con1][con9] != -1) return dp[len][con1][con9];
    LL res = 0;
    for(int i = 0; i <= 9; ++i){
        //tmp.push_back(i);
        res = (res + dfs(len+1, con1|(i == 0), con9|(i == 9)) )%mod;
        //tmp.pop_back();
    }
    return dp[len][con1][con9] = res;
}

void solve(){
    cin >> n;
    memset(dp, -1, sizeof dp);
    cout << dfs(0, 0, 0)%mod << "\n";
}

int main()
{
    Fast;
    //louisfghbvc{
        solve();
    //}
    return 0;
}


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

int a, b;
int main(){
//  ios::sync_with_stdio(0), cin.tie(0);
#ifndef ONLINE_JUDGE
//  freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
  cin >> a >> b;
  if(a + b == 15) puts("+");
  else if(a * b == 15) puts("*");
  else puts("x");
  return 0;
}


Measured memory_bytes: 256