akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <map>
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)
#define rrep(i, n) for (auto i = (n); i >= 0; i--)
#define all(cont) begin(cont), end(cont)
#define fn(expr) [&] (auto&& it) { return expr }
#define lam [&] (auto&& it)
using ll = long long;

using namespace std;

template <class It>
map<pair<string, string>, ll> halfs(It start, It last) {
  int len = last - start;
  map<pair<string, string>, ll> res;
  rep (i, 1 << len) {
    auto it = start;
    string s, t;
    rep (j, len) {
      if ((1 << j) & i) s += *it;
      else t += *it;
      ++it;
    }
    res[make_pair(s, t)]++;
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  string s;
  cin >> s;
  auto&& vor = halfs(begin(s), begin(s) + n);
  auto&& hinter = halfs(rbegin(s), rbegin(s) + n);
  ll res = 0;
  for (auto&& p : vor)
    res += p.second * hinter[make_pair(p.first.second, p.first.first)];
  cout << res;
}


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

using namespace std;

int main() {
  int A, B;
  int K;
  cin >> A >> B >> K;
  for (int i = A; i <= min(B, A + K -1); ++i) cout << i << endl;
  for (int i = max(B - K + 1, A + K); i<= B; i++) cout << i << endl;
  return 0;
}



Measured memory_bytes: 256
n    = gets.to_i
ary  = gets.split.map(&:to_i)
cnt1 = 0
cnt2 = 0
cnt4 = 0

ary.each do |i|
  if i % 4 == 0
    cnt4 += 1
  elsif i % 2 == 0
    cnt2 += 1
  else
    cnt1 += 1
  end
end

if (cnt2 == 0 && cnt4 >= cnt1 - 1) || cnt4 >= cnt1
  puts :Yes
else
  puts :No
end


Measured memory_bytes: 8452
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    int A, B;
    cin >> A >> B;
    int diff = B - A;
    cout << 0.5 * diff * ( 1 + diff ) - B << endl;
    return 0;
}

Measured memory_bytes: 256
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let n: usize = sc.read();
    let a: Vec<usize> = sc.vec(n);
    let max: usize = a.iter().cloned().max().unwrap();
    let mut count = vec![0; max + 1];
    for a in a.into_iter() {
        count[a] += 1;
    }

    let candidates = count
        .iter()
        .enumerate()
        .filter(|&(_, &count)| count > 0)
        .map(|(i, _)| i)
        .collect::<Vec<_>>();
    if candidates.len() > 2 {
        println!("No");
        return;
    }

    if candidates.len() == 1 {
        let count = candidates[0];
        if count <= n / 2 || count == n - 1 {
            println!("Yes");
        } else {
            println!("No");
        }
        return;
    }
    let (c1, c2) = (candidates[0], candidates[1]);
    if count[c2] <= 1 || c1 + 1 != c2 {
        println!("No");
        return;
    }

    let different = count[c1];
    let same = count[c2];
    if c2 < different + 1 || different + same / 2 < c2 {
        println!("No");
        return;
    }

    println!("Yes");
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N,M; cin>>N>>M;
    vector<int64_t> A(N);
    rep(n,0,N) cin>>A.at(n);
    map<int64_t,int64_t> mp;
    rep(m,0,M){
        int b,c; cin>>b>>c;
        mp[-c]+=b;
    }

    sort(ToEnd(A));
    int idx=-1;
    auto itr=mp.begin();
    rep(i,0,N){
        if(i-idx>itr->second){
            idx=i-1;
            itr++;
        }
        if(itr==mp.end()) break;
        if(-(itr->first)<A.at(i)) break;

        A.at(i)=-(itr->first);
    }

    int64_t ans=0;
    for(auto a:A) ans+=a;
    cout<<ans<<endl;
}

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

using namespace std;
typedef pair<int, int> pii;

int main(void) {
  int n, m;
  while (cin >> n >> m, n) {
    vector<pii> t(m);
    vector<int> s(m), d(m);
    for (int i = 0; i < m; i++) {
      cin >> t[i].first >> s[i] >> d[i];
      s[i]--, d[i]--;
      t[i].second = i;
    }
    sort(t.begin(), t.end());

    vector<bool> infect(n, false);
    infect[0] = true;
    for (int i = 0; i < m; i++) {
      int tt = t[i].second;
      infect[d[tt]] = infect[d[tt]] | infect[s[tt]];
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
      ans += infect[i];
    }

    cout << ans << endl;
  }

  return 0;
}


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

int main(int argc, const char * argv[]) {
    long long int N;
    cin >> N;
    string s;
    long long int a[5] = {0, 0, 0, 0, 0};
    for (long long int i = 0; i < N; i++) {
        cin >> s;
        if (s[0] == 'M') {
            a[0]++;
        }else if (s[0] == 'A'){
            a[1]++;
        }else if (s[0] == 'R'){
            a[2]++;
        }else if (s[0] == 'C'){
            a[3]++;
        }else if (s[0] == 'H'){
            a[4]++;
        }
    }
    int cnt = 0;
    for (int i = 0; i < 5; i++) {
        if (a[i] != 0) {
            cnt++;
        }
    }
    
    long long int sum = 0;
    if (cnt < 3) {
        cout << sum << endl;
    }else{
        for (int i = 0; i < 5; i++) {
            if (a[i] != 0) {
                for (int j = i + 1; j < 5; j++) {
                    if (a[j] != 0) {
                        for (int k = j + 1; k < 5; k++) {
                            if (a[k] != 0) {
                                long long int x;
                                x = a[i] * a[j] * a[k];
                                sum += x;
                            }
                        }
                    }
                }
            }
        }
        cout << sum << endl;
    }
    return 0;
}



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

int main() {
  int a,b;
  cin>>a>>b;
  
  if(a-2*b>=0)
  cout<<a-2*b<<endl; 
  
  else{
  cout<<0<<endl;
  }

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
	int k ;
	char str[105];
	scanf("%d", &k);
	scanf("%s", &str);
	
	
	int len = strlen(str);
  if (len <= k) {
    printf("%s", str);
  } else { 
    for (int i = 0; i < k; i++) {
      printf("%c", str[i]); 
    }
    puts("...");
  }

  
  return 0;
}

Measured memory_bytes: 1680
from math import floor

a,b = map(int, input().split())

ans = 0
while ans != 100000:
    aq = floor(ans*0.08)
    bq = floor(ans*0.1)
    if (aq==a) and (bq==b):
        break
    else:
        ans+=1
if ans == 100000:
    ans = -1
print(ans)


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

double dp[301][301][301];
long long n;

double recurse(long long one, long long two, long long three)
{

    if(dp[one][two][three]!=0)
    {
        return dp[one][two][three];
    }

    if(one==1&&two==0&&three==0)
    {
        return n;
    }

    double answer=n*1.0/(one+two+three);

    if(three>0)
    {
        answer+=three*1.0/(one+two+three)*recurse(one,two+1,three-1);
    }
    if(two>0)
    {
        answer+=two*1.0/(one+two+three)*recurse(one+1,two-1,three);
    }
    if(one>0)
    {
        answer+=one*1.0/(one+two+three)*recurse(one-1,two,three);
    }

    dp[one][two][three]=answer;

    //cout<<one<<" "<<two<<" "<<three<<" "<<answer<<endl;
    return answer;
}
long long types[4];
int main()
{
    cin>>n;
    long long sushi[n];

    for(int i=0;i<n;i++)
    {
        cin>>sushi[i];
        types[sushi[i]]++;
    }
    for(int i=0;i<=300;i++)
    {
        for(int j=0;j<=300;j++)
        {
            for(int k=0;k<=300;k++)
            {
                dp[i][j][k]=0;
            }
        }
    }
    cout<<fixed<<setprecision(9)<<recurse(types[1],types[2],types[3])<<endl;
}


Measured memory_bytes: 213376
#include <iostream>
using namespace std;
int main(void){
    int n;
    string s;
    cin>>n;
    cin>>s;
    
    for(int i=0; i<s.length(); i++){
        if((s[i]+=n) > 90)
            s[i]-=26;
    }
    
    cout<<s<<endl;
}


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

int main(){
	int N, K, Q;
	cin >> N >> K >> Q;
	
	int point[N];
	for(int i = 0; i < N; i++){
		point[i] = K;
	}

	for(int i = 0; i < Q; i++){
		int A_i;
		cin >> A_i;
		point[A_i-1] += 1;
	}
	
	for(int i = 0; i < N; i++){
		if(point[i] - Q > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	
	return 0;
}

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

int main(){
    long long int N, A, B, X, L;

    cin >> N >> A >> B;

    L = N / (A + B);

    X = L * A;

    if(A - (N - L * (A + B)) < 0){
        X += A;
        cout << X << endl;
        return 0;
    }
    X += A - (N - L * (A + B)) > 0 ? N - (L * (A + B)) : 0;
    
    cout << X << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;
 
 int main(void){
     int N,H,W,count=0;
     cin >> N >> H >> W;
     int A[N+10],B[N+10];
     for(int i=0; i<N; i++){
         cin >> A[i] >> B[i];
     }for(int i=0; i<N; i++){
         if(A[i]>=H && B[i]>=W){
            count+=1;
         }
     }cout << count << endl;
 }

Measured memory_bytes: 256
n = int(raw_input())
ais = map(int, raw_input().split())
ais.sort()
vv= sum(ais)/len(ais)
def g(ais,m):
	s= 0
	for ai in ais: s+=abs(ai - m) **2
	return s
print min([g(ais,m) for m in [vv+dela for dela in [-1,0,+1]]])

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

int main()
{
    string s;
    int a,b,t;
    int aa=0,bb=0;
    cin>>t>>a>>b;

    cin>>s;
    for(int i=0; i<t; i++)
    {

        if(s[i]=='a'&& aa+bb<a+b)
        {
        cout<<"Yes"<<endl;
        aa++;
        }
        else if(s[i]=='b' && aa+bb<a+b && bb<b)
        {
            cout<<"Yes"<<endl;
            bb++;

        }
        else
        {
            cout<<"No"<<endl;
        }

    }
    return 0;
}


Measured memory_bytes: 3748
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

signed main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a;
	for (int i = 0; i < 3 * n; i++) {
		int t;
		cin >> t;
		a.pb(t);
	}
	sort(ALL(a));
	int fr = 0, md = a.size() - 2, bk = n - 1;
	//debug(a.size());
	int ans = 0;
	rep(i,  n) {
		ans += a[md];
		//debug(i);
		//debug(a[i]);
		md -= 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5488
#include<bits/stdc++.h>
using namespace std;
#define N 200010
int a[N],n,delta;
long long ans;
set<int> st;
int main(){
	scanf("%d",&n);a[0]=-1;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]-a[i-1]>1)return puts("-1"),0;
	}
	for(int i=n;i;i--){
		while(st.size()&&*st.begin()<delta)st.erase(st.begin());
		ans+=st.size();
		st.insert(a[i]+delta);
		delta++;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 5760
def count(a,b,k):
    l = a + (k - (a % k)) if a % k != 0 else a
    r = b - (b % k)
    if l > r:
        return 0
    return (r-l)//k+1
def gcd(n,m):
    n,m = max(n,m),min(n,m)
    r = n % m
    while r > 0:
        n,m = m,r
        r = n % m
    return m
def lcm(n,m):
    return n*m//gcd(n,m)
a,b,c,d = map(int,input().split())
print((b-a+1)-count(a,b,c)-count(a,b,d)+count(a,b,lcm(c,d)))


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

int main(){
    string s;
    cin >> s;
    if(((s.find("N") == string::npos) == (s.find("S") == string::npos)) && ((s.find("E") == string::npos) == (s.find("W") == string::npos))) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main( void ) {
	int n, sum, key;
	const char ch[ 9 ][ 6 ] = { ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };

	for ( scanf( "%d ", &n ); n--; putchar( '\n' ) )
		while ( ( key = getchar() ) != '\n' ) {
			if ( key == '0' )
				continue;

			for ( sum = 0; getchar() != '0'; sum++ ) ;

			putchar( ch[ key - '1' ][ sum % strlen( ch[ key - '1' ] ) ] );
		}

	return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define pb push_back
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll a, b, c;
	cin >> a >> b >> c;
	bool success = (a + b) < c;
	if (success) {
		success = 4 * a * b < (c - a - b) * (c - a - b);
	}
	if (success) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

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

char a[10][10];

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

    int i = 0, j = 0;
    while(1){
        a[i][j] = '.';
        if(i == h-1 && j == w-1){
            break;
        }

        if(a[i][j+1] == '#'){
            j++;
        }else if(a[i+1][j] == '#'){
            i++;
        }else{
            break;
        }
    }

    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(a[i][j] == '#'){
                cout << "Impossible" << endl;
                return 0;
            }
        }
    }

    cout << "Possible" << endl;

    return 0;
}






Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0,1,0,-1 };
const ll dy[4] = { -1, 0, 1,0 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

int main() {
	int H, W; cin >> H >> W;
	int N; cin >> N;
	int a[10010];
	REP(i, N)cin >> a[i];
	vector<int>V;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < a[i]; ++j) {
			V.push_back(i + 1);
		}
	}

	int ans[110][110];
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (i % 2 == 0) {
				ans[i][j] = V[i*W + j];
			}
			else {
				ans[i][W - 1 - j] = V[i*W + j];
			}
		}
	}
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}

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

#define mod 1000000007
typedef int integer;
#define int long long
using namespace std;

const int N = 100005;

int n;
int ar[N];



integer main() {
    ios_base::sync_with_stdio(false);

    char c;
    cin >> c;
    c++;
    cout << c << endl;
}



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

typedef long long ll;

int N;
ll A[300030];
ll ans = 0;

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N * 3; i++)
    {
        scanf("%d",&A[i]);
    }
    sort(A,A + N * 3);
    for(int i = 0; i < N; i++)ans += A[2 * i + N];
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2560
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

S = input()

for i in range(1,len(S)):
     if S[i] == S[i-1]:
        print("Bad")
        sys.exit()

print("Good")

Measured memory_bytes: 77596
#include<bits/stdc++.h>
using namespace std;
#define Accepted return 0;
int main()
{
    string s;
    int i,len;
    cin>>s;len=s.length();
    if (len>=4 && s.substr(0,4)=="YAKI") cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    Accepted
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
int W, H, x, y, r;
scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

if (x-r>=0 && x+r<=W && y+r<=H && y-r>=0)
 printf("Yes\n");
else
 printf("No\n");
return 0;
}



Measured memory_bytes: 2144
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; //↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n; cin >> n;
  int cnt = 0;
  for(int i = 1; i <= n; i++){
    int a; cin >> a;
    if((i % 2) && (a % 2)) cnt++;
  }
  cout << cnt << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 3680
#include <cstdio>

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

    int max_L_i = 0;
    for(int i = 0; i < N; i++){
        if(L[max_L_i] < L[i]){
            max_L_i = i;
        }
    }

    int sum_L = 0;
    for(int i = 0; i < N; i++){
        sum_L += L[i];
    }
    
    if(L[max_L_i] < sum_L - L[max_L_i]){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main(void) {
	string str;
	cin >> str;
	int num,sod;
	num = sod = 0;
	int len = (int)str.length();
	for (int i = 0; i < len; ++i) {
		int digit = (int)str[i] - '0';
		num += digit * pow(10,len-i-1);
		sod += digit;
	}
	if (num%sod == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}



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

int main() {
	int n; char p; int x, count = 0;
	cin >> n;
	for(int i=0; i<n; ++i) {
		cin >> p >> x;
		if(p=='(') count += x;
		else count -= x;
		if(count<0) break;
	}
	cout << (count == 0 ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 1160
from collections import Counter

def road_find(a):
    if Road[a] < 0:
        return a
    else:
        return road_find(Road[a])


def train_find(a):
    if Train[a] < 0:
        return a
    else:
        return train_find(Train[a])


def road_union(a, b):
    ag = road_find(a)
    bg = road_find(b)
    if ag == bg:
        return
    if Road[ag] > Road[bg]:
        ag, bg = bg, ag
    Road[ag] += Road[bg]
    Road[bg] = ag
    return


def train_union(a, b):
    ag = train_find(a)
    bg = train_find(b)
    if ag == bg:
        return
    if Train[ag] > Train[bg]:
        ag, bg = bg, ag
    Train[ag] += Train[bg]
    Train[bg] = ag
    return


N, K, L = map(int, input().split())
Road = [-1] * N
Train = [-1] * N

for road in range(K):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    road_union(p, q)

for train in range(L):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    train_union(p, q)

Ans = []
for i in range(N):
    Ans.append((road_find(i),train_find(i)))

Ans_C = Counter(Ans)

for i in range(N):
    print(Ans_C[(road_find(i),train_find(i))])



Measured memory_bytes: 134224
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>


using namespace std;
#define INF 0x3f3f3f3f3f
#define ll long long
#define pr(x) (cerr << #x << ' ' << x << ' ')
#define prln(x) (cerr << #x << ' ' << x << endl)


int main()
{
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
	#endif // LOCAL
	int n, k;
	scanf("%d %d", &n, &k);
	ll ans = 0;
	for (int i = 1; i < n; i += k - 1) {
		++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
s_input = input()
t_input = input()

s = list(s_input)
t = list(t_input)

s.sort()
t.sort(reverse=True)

if(len(s)<=len(t)):
    l = len(s)
else:
    l = len(t)

R = 0
P = 0
for i in range(0, l):
    if(s[i] == t[i]):
        P+=1
    elif(s[i] < t[i]):
        break
    else:
        R=1

if(P==l):
    if(len(s)<len(t)):
        R=0
    else:
        R=1

if(R==0):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  bool K=false;
  bool M=false;
  cin>>S;
  for(int X=0;X<S.size();X++){
    for(int Y=X;Y<S.size();Y++){
      string L="1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111";
      int G=0;
      for(int Z=0;Z<S.size();Z++){
        if(Z>=X && Z<=Y){
          continue;
        }
        else{
          L.at(G)=S.at(Z);
          G++;
        }
      }
      if((L.at(0)=='k'&&L.at(1)=='e'&&L.at(2)=='y'&&L.at(3)=='e'&&L.at(4)=='n'&&L.at(5)=='c'&&L.at(6)=='e'&&L.at(7)=='1')){
        K=true;
        M=true;
        break;
      }
    }
    if(M==true){
      break;
    }
  }
  if(K==true){
    cout<<"YES"<<endl;
  }
  else if(S=="keyence"){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 3548
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var ST = Console.ReadLine().Split(' ');
            var S = ST[0]; var T = ST[1];
            for (int i = 0; i < N; i++)
            {
                Console.Write(S[i]);
                Console.Write(T[i]);
            }
        }
    }
}


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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    if (S[0] == S[1] && S[1] == S[2]) cout << NO << '\n';
    else cout << YES << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
<?php

$n = trim(fgets(STDIN));
$s = trim(fgets(STDIN));
$t = trim(fgets(STDIN));
$j = false;

for ($i = 0; $i < $n; $i++) {
    if (substr($s, $i) == substr($t, 0, $n - $i)) {
        echo $n + $i;
        $j = true;
        break;
    }
}
if (!$j) echo $n * 2;


Measured memory_bytes: 4856
#include<bits/stdc++.h>
using namespace std; 
int main(){
  int l,i,j,b[256]={0},n,r=0;
  char s[256];
  scanf("%d%s",&l,s);
  for(i=1;i<l-1;i++)
  {
    for(j='a';j<='z';j++)
	{
		b[j]=0;
	}
    for(j=0;j<i;j++)
	{
		b[s[j]]=1;
	}
    n=0;
    for(j=i;j<l;j++)
	{
		if(b[s[j]])
		{
			b[s[j]]=0;
			n++;
		}
	}
    r=max(r,n);
  }
  printf("%d\n",r);
  return 0;
}

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

int main(void) {
  int n;
  cin >> n;
  
  int c[2][n];
  for (int i=0; i<2; i++) {
    for (int j=0; j<n; j++) {
      cin >> c[i][j];
    }
  }
  
  int max = 0;
  
  for(int i=0; i<n; i++) {
    int num = 0;
    for (int j=0; j<=i; j++) num += c[0][j];
    for (int j=i; j<n; j++) num +=c[1][j];
    
    if (num > max) max = num;
  }
  
  cout << max << endl;
  
  return 0;
}
         
         
         
         
         

Measured memory_bytes: 256
#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 PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V) \
    for (auto v : (V)) cout << v << ' ';
#define PRINT_ENTER() cout << endl;

/*
Union-Find木
グループ分けを管理するデータ構造。
*/
namespace aigo {
template <typename T = int>
class UnionFind {
   public:
    UnionFind(T n) : _par(n), _size(n, T{1}) {
        for (T i{}; i < n; i++) {
            _par[i] = i;
        }
    }
    // xとyの属する集合を併合
    bool unite(T x, T y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (_size[x] < _size[y]) {
            std::swap(x, y);
        }
        _size[x] += _size[y];
        _par[y] = x;

        return true;
    }

    // xとyがおなじ集合に属するか否か
    // TODO: constメンバに変更したい
    bool isSame(int x, int y) { return root(x) == root(y); }

    T size(T x) { return _size[root(x)]; }

    void print() const {
        for (ssize_t i = 0; i < std::max(_par.size(), _size.size()); i++) {
            std::cout << _par[i] << ", " << _size[i] << std::endl;
        }
    }

   private:
    std::vector<T> _par;
    std::vector<T> _size;
    // root the root of x
    T root(T x) {
        if (_par[x] == x) {
            return x;
        } else {
            return _par[x] = root(_par[x]);  // shrink edges
        }
    }
};
}  // namespace aigo
int main() {
    /* code */
    using namespace aigo;
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind<int> uf(n);
    vector<set<int>> dame(n);

    REP(i, m) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        uf.unite(a, b);
        dame[a].insert(b);
        dame[b].insert(a);
    }
    REP(i, k) {
        int c, d;
        cin >> c >> d;
        --c;
        --d;
        if (!uf.isSame(c, d)) continue;
        dame[c].insert(d);
        dame[d].insert(c);
    }
    REP(i, n) {
        // cout << "[" << uf.size(i) << "] [" << dame[i].size() << "] ";
        int res = uf.size(i) - dame[i].size() - 1;
        cout << res << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 25088
#include<bits/stdc++.h>
using namespace std;
long long int lcm(long long int c, long long int d){
	return (c*d)/__gcd(c,d);
}
int main(){
  
  long long int a, b, c, d;
  scanf("%lld%lld%lld%lld",&a,&b,&c,&d);

  long long int common = lcm(c,d);
  
  long long int prev = (a-1)/c + (a-1)/d - (a-1)/common; 
  long long int total = b/c + b/d - b/common;
  long long int ans = (b-a+1)-(total - prev);
  
  printf("%lld\n",ans);
  
  return 0;
}


Measured memory_bytes: 256
program b
implicit none

integer :: I, L
character(100) :: S

read(*,*) S
S = trim(S)
L = len(S)

do I = 1, L, 2
 if (S(I:I)=="L") then
 write(*,'(a2)') "No"
 stop
 end if
end do

do I = 2, L, 2
 if (S(I:I)=="R") then
 write(*,'(a2)') "No"
 stop
 end if
end do

write(*,'(a3)') "Yes"

end program

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
	cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  cout << a.back() - a.front() << endl;
  return 0;
  
}

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

vector<bool> sf(11);
int main(void){
	int N,M,ans = 0;
	cin >> N >> M;
	int k[15],s[15][15],p[15];
	for(int i=0;i<M;i++){
		cin >> k[i];
		for(int j=0;j<k[i];j++){
			cin >> s[i][j];
			s[i][j]--;
		}
	}
	for(int i=0;i<M;i++)cin>>p[i];
	
	for(int i=0;i< 1<<N;i++){
		fill(sf.begin(),sf.end(),false);
		for(int j=0;j<N;j++){
			if((i>>j)&1){
				sf[j] = true;
			}
		}
		bool flag = true;
		for(int j=0;j<M;j++){
			int cnt = 0;
			for(int a=0;a<k[j];a++){
				if(sf[s[j][a]]==true)cnt++;
			}
			if(cnt%2 == p[j]){
			}else{
				flag = false;
				break;
			}
		}
		if(flag)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static void main(String[] args){
        int N, M;
        PriorityQueue<Integer> A = new PriorityQueue<>((x,y) -> -x+y);
        long total = 0;
        {
            int[] a = in.ii(); N = a[0]; M = a[1];
            a = in.ii();
            for(int i = 0; i < N; i++){
                A.add(a[i]);
                total += a[i];
            }
        }
        for(int i = 0; i < M; i++){
            int x = A.poll();
            total -= x-x/2;
            A.add(x/2);
        }
        out.println(total);
        out.flush();
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        String[] ss(){
            return s().split(" ");
        }

        int i(){
            return Integer.parseInt(s());
        }

        int[] ii(){
            String[] ss = ss();
            int[] ii = new int[ss.length];
            for(int j = 0; j < ss.length; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }

        long l(){
            return Long.parseLong(s());
        }

        long[] ll(){
            String[] ss = ss();
            long[] ll = new long[ss.length];
            for(int j = 0; j < ss.length; j++) ll[j] = Long.parseLong(ss[j]);
            return ll;
        }
    }
}


Measured memory_bytes: 51480
#include<bits/stdc++.h>
using namespace std;
#define F(i,L,R) for(int i=L;i<R;i++)
#define FE(i,L,R) for(int i=L;i<=R;i++)
#define RF(i,l,r) for(int i=r;i>l;i--)
#define RFE(i,l,r) for(int i=r;i>=l;i--)
#define getI(i) scanf("%d",&i)
#define getII(i,j) scanf("%d%d",&i,&j)
#define getIII(i,j,k) scanf("%d%d%d",&i,&j,&k)
#define VgetI(i) int (i);scanf("%d",&(i));
#define VgetII(i,j) int (i),(j);scanf("%d%d",&(i),&(j));
#define VgetIII(i,j,k) int (i),(j),(k);scanf("%d",&(i),&(j),&(k));
#define EoF(n) int(n);while(~getI(n))
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define abs(n) (n>0?n:(-n))
#define INF 2147483647
#define nINF -2147483648
int main(){
	int a,b;
	while(~getII(a,b)){
		if(a%2&&(!(b%2))) b++;
		if((!(a%2))&&b%2) a++;
		printf("%d\n",(a+b)/2);
	}
}


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

#define pan(i,n) for(int i=0;i<n;i++)
#define pans(i,n,a) for(int i=a;i<n;i++)
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define INF 1000000007
#define PI 3.141592653
#define inf 100007
#define P pair<ll,ll>

using namespace std; 

int main(){
    int s,w;
    cin>>s>>w;
    if(w>=s) cout<<"unsafe";
    else cout<<"safe";

}

Measured memory_bytes: 3636
#include<vector>
#include<iostream>
#include<set>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
int n, x, m=0;
set<int>s;
vector<pair<int,int>>v;
int main()
{
	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		cin >> x;
		if (x % 2 == 1 && i % 2 == 1)
			m++;

	}
	cout << m;
}

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

int main(){
    int A,B,M;
    cin >> A >> B >> M;
    vector<int> aa(A);
    vector<int> bb(B);
    int amin = 1e6, bmin = 1e6;
    rep(i,A){
        cin >> aa[i];
        amin = min(amin, aa[i]);
    }
    rep(i,B){
        cin >> bb[i];
        bmin = min(bmin, bb[i]);
    }
    int cmin = amin + bmin;
    rep(i,M){
        int a,b,c;
        cin >> a >> b >> c; a--; b--;
        int sum = aa[a] + bb[b] - c;
        if(sum < cmin) cmin = sum;
    }
    cout << cmin << endl;
    return 0;
}

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

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

    ll X = N / 1.08;
    if((ll)(X * 1.08) == N) {
        cout << X << endl;
    } else if((ll)((X + 1) * 1.08) == N) {
        cout << X + 1 << endl;
    } else {
        cout << ":(" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <numeric>
#include <string>
#include <functional>

long long gcd(long long x,long long y){
    if(x<=0||y<=0){return 0;}
    if(x<y){return gcd(y,x);}
    if(x%y==0){return y;}

    return gcd(y,x%y);
}

using namespace std;

int main(void){
    int N;
    cin>>N;
    vector<long long> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }

    long long ans=A[0];
    for(int i=1;i<N;i++){
        ans=gcd(ans,A[i]);
    }

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie();
    int n, x, t;
    cin>>n>>x>>t;
    if(n%x == 0)    cout<<n/x*t;
    else
    {
        cout<<(n/x + 1)*t;
    }
    
    return 0;
}

Measured memory_bytes: 3648
#ifdef OJ_MISC_OFFLINE

#include "prolog.h"

#else
#define LOG
#define PRINT
#define LCERR
#include <iostream>
auto optimize_cpp_stdio = []() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::setvbuf(stdout, nullptr, _IOFBF, BUFSIZ);
    return 0;
}();
#endif

#include <algorithm>
#include <array>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

namespace {

using namespace std;

int solve() {
    // handle IO here
    int A, B, C;
    cin >> A >> B >> C;
    cout << max(0, C - (A - B)) << '\n';
    return 0;
}

} // anonymous namespace

#ifdef OJ_MISC_OFFLINE

#include "epilog.h"

#else

int main() {
    return solve();
}

#endif


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	string a, b; cin >> a >> b;
	sort(all(a));
	sort(all(b));
	reverse(all(b));
	if (a<b) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void){

    char dow[7][4]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
    char s[4];
    scanf("%s", s);
    int i;
    for(i=0;i<7;i++){
        if(!strcmp(s,dow[i])){
            printf("%d\n",7-i);
        }
    }return 0;


}


Measured memory_bytes: 128
#include"iomanip"
#include"iostream"
#include"limits"
#include"cmath"
#include"vector"
#include"algorithm"
#include"list"
#include"queue"
#include"stack"
#include"set"
#include"unordered_set"
#include"map"
#include"unordered_map"
#include"string"
#include"cstring"
#include"assert.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back
#define mset(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	set<int>fr,to;
	for(int i=0;i<m;++i)
	{
		int a,b;
		cin>>a>>b;
		if(b==n)
		{
			to.insert(a);
		}
		else if(a==1)
		{
			fr.insert(b);
		}
	}
	for(int x:fr)
	{
		if(to.find(x)!=to.end())
		{
			cout<<"POSSIBLE\n";
			return 0;
		}
	}
	cout<<"IMPOSSIBLE\n";
}

Measured memory_bytes: 9600
#include<stdio.h>
int main(){
  int n,i,max,min,a[10000];
  long long int sum;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  max=a[0];
  min=a[0];
  for(i=0;i<n;i++){
    if(min>a[i]){
      min=a[i];
    }
    if(max<a[i]){
      max=a[i];
    }
    sum+=a[i];
  }
  printf("%d %d %lld\n",min,max,sum);

  return 0;
}

Measured memory_bytes: 640
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    int n, a;
    scan(n);
    scan(a);

    writeln(n % 500 <= a ? "Yes" : "No");
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int A,B,C; cin >> A >> B >> C;
    cout << (A<=C && C<=B ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
b = sorted(a)
max_1 = b[-1]
max_2 = b[-2]
for i in range(n):
    if a[i] != max_1:
        print(max_1)
    else:
        print(max_2)


Measured memory_bytes: 14168
//😄😄😄😄😄😄😄😄😄😄😄😄😄
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pi>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define For(i,a,b) for(ll i=a;i<b;i++)
#define endl "\n"
#define debug(x) cout<<"DEBUG------> "<<#x<<" -> "<<x<<endl
#define all(x) x.begin(),x.end()
#define mint map<int,int>

////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////


void solve() {

	int a, b, c; cin >> a >> b >> c;
	int k; cin >> k;
	while (a >= b) {
		b *= 2;
		k--;
	}
	while (b >= c) {
		c *= 2;
		k--;
	}
	if (k >= 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}




////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	//freopen("in.txt", "r", stdin);
	//freopen ("out.txt", "w", stdout);
	//int t; cin >> t;
	//while (t--)
	solve();

	return 0;
}





///////////////////////////////////////////////////////////////////////////////////////////
//What are you doing ???



Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define arep(i, v) for (auto i : v)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline void dump(T& v) {
    irep(i, v) { cout << (*i) << ((i == --v.end()) ? '\n' : ' '); }
}
inline string getline() {
    string s;
    getline(cin, s);
    return s;
}
inline void yn(const bool b) { b ? fin("yes") : fin("no"); }
inline void Yn(const bool b) { b ? fin("Yes") : fin("No"); }
inline void YN(const bool b) { b ? fin("YES") : fin("NO"); }
struct io {
    io() {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;

/* --------------------   ここまでテンプレ   -------------------- */





int main() {
    

    int n;
    cin>>n;
    vll v(n);
    rep(i,n)cin>>v[i];
    ll ans=0;
    ll mx=v[0];
    for(int i=1;i<n;i++){
        if(v[i]>=mx){
            mx=v[i];
        } else {
            ans+=mx-v[i];
        }
    }
    fin(ans);
}


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

int N, M;
vector < int > G[100005];
vector < int > lang[100005];
bool flag[100005] = {};
int dfs(int v)
{
    int ret = 0;
    flag[v] = true;
    for(int i = 0; i < G[v].size(); i++) {
        if(!flag[G[v][i]]) ret += dfs(G[v][i]);
    }
    return (++ret);
}
int main()
{
    cin >> N >> M;
    for(int i = 0; i < N; i++) {
        int K;
        cin >> K;
        for(int j = 0; j < K; j++) {
            int L;
            cin >> L;
            lang[L - 1].push_back(i);
        }
    }

    for(int i = 0; i < M; i++) {
        for(int j = 1; j < lang[i].size(); j++) {
            G[lang[i][j]].push_back(lang[i][j - 1]);
            G[lang[i][j - 1]].push_back(lang[i][j]);
        }
    }

    if(dfs(0) == N) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return (0);
}


Measured memory_bytes: 13176
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define f first
#define s second
#define pb push_back
#define pp push
#define RETURN exit(0)
#define pow(x,y) (int)(pow(x,y))
#define ceil(x) (int)(ceil(x))
#ifndef ONLINE_JUDGE
#define debug(x) cout<<x<<endl;
#else
#define debug(x) 42
#endif
const int MAX=1e4;
const int MOD=1e9+7;
const int MAAX=1e15;
const long double EPS=1e-6;
const int N=1e6;
int power(int x,int y)
{
    if (y == 0)
        return 1;
    int a=power(x,y/2);
    if (y % 2 == 0)
        return a * a % MOD;
    else
        return x * a * a % MOD;
}
long double sq(int x){
    long double s=0,e=x,mid;
    while(e-s>=EPS){
        mid=(s+e)/2;
        if(mid*mid<=x){
            s=mid;
        }
        else{
            e=mid-EPS;
        }
    }
    return s;
}
vector<int> primes;
bool visted[N+5];
void sieve(){
    visted[0]=visted[1]=1;
    for(int i=2;i*i<=N;i++){
        if(visted[i]==0){
            primes.pb(i);
            for(int j=i*i;j<=N;j+=i){
                visted[j]=1;
            }
        }
    }
    for(int i=sqrt(N)+1;i<=N;i++){
        if(visted[i]==0)
            primes.pb(i);
    }
    return;
}



in main()
{
    //freopen("in.in","r",stdin);
    //freopen("out.out","w",stdout);
    int tc=1;
    //sieve();
    //scanf("%lld",&tc);
    while(tc--)
    {
        string s;
        cin>>s;
        int x=-1,y=-1;
        for(int i=0;i<s.size()-1;i++){
            if(s[i]==s[i+1])
                x=i+1,y=i+2;
        }
        if(x==-1){
            for(int i=0;i<s.size()-2;i++){
                if(s[i]==s[i+2])
                    x=i+1,y=i+3;
            }
        }
        cout<<x<<" "<<y<<endl;
    }
    RETURN;
}


Measured memory_bytes: 512
import sys

read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)


def solve():
    n, *a = map(int, read().split())
    a = tuple(a)
    dp = [0] * n ** 2

    for i in range(n):
        dp[i * n + i] = a[i]
    for i in range(n - 2, -1, -1):
        for j in range(i + 1, n):
            L = a[i] - dp[(i + 1) * n + j]
            R = a[j] - dp[i * n + j - 1]
            if L > R:
                dp[i * n + j] = L
            else:
                dp[i * n + j] = R
    return dp[n - 1]


print(solve())


Measured memory_bytes: 110320
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353;
int dp[200100],imos[200100];
signed main(){
  int N,K;
  cin>>N>>K;
  vector<pair<int,int>> A(K);
  for(pair<int,int> &p:A)cin>>p.first>>p.second;
  dp[1]=1;
  for(int i=1;i<=N;i++){
    imos[i]=(imos[i]+imos[i-1])%mod;
    dp[i]=(dp[i]+imos[i])%mod;
    for(pair<int,int> p:A)
      imos[i+p.first]=(imos[i+p.first]+dp[i])%mod,imos[i+p.second+1]=(imos[i+p.second+1]-dp[i]+mod)%mod;
  }
  cout<<dp[N]<<endl;
}

Measured memory_bytes: 6744
#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
const int maxn=2e5+10;

ll arr[maxn],vis[maxn];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll n,k;cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>arr[i];
    int acout=0,cur=1;
    vector<int> v;
    while(1)
    {
        if(vis[cur]) break;
        else
        {
            acout++,vis[cur]=1;v.push_back(cur);cur=arr[cur];
        }
    }
    //for(int i=0;i<v.size();i++) cout<<v[i]<<" ";
    //cout<<"debug "<<cur<<endl;
    int cal=0,i=0;
    if(v.size()>k)
    {
        cout<<v[k]<<endl;return 0;
    }
    while(1)
    {
        if(v[i]!=cur) cal++,acout--,v.erase(v.begin());
        else break; 
    }
    if(cal>0) k-=cal;
   // for(int i=0;i<v.size();i++) cout<<v[i]<<" ";
   // cout<<endl;
   if(acout==0) 
   {
       cout<<v[v.size()-1]<<endl;return  0;
   }
    cout<<v[k%acout]<<endl;
    return 0;
 } 

Measured memory_bytes: 7348