akhauriyash/Code-Regression huggingface dataset:
def rotateDice(direction: str, dice: dict) -> dict:
    if direction == 'S':
        dice['S'], dice['F'], dice['N'], dice['B'] = dice['F'], dice['N'], dice['B'], dice['S']
    elif direction == 'E':
        dice['E'], dice['F'], dice['W'], dice['B'] = dice['F'], dice['W'], dice['B'], dice['E']
    elif direction == 'W':
        dice['W'], dice['F'], dice['E'], dice['B'] = dice['F'], dice['E'], dice['B'], dice['W']
    elif direction == 'N':
        dice['N'], dice['F'], dice['S'], dice['B'] = dice['F'], dice['S'], dice['B'], dice['N']
    return dice


dice_list = list(map(int, input().split()))
dice = {'FSEWNB'[i]: dice_list[i] for i in range(6)}
for c in input():
    dice = rotateDice(c, dice)
print(dice['F'])



Measured memory_bytes: 5612
using System;
using System.Linq;
using System.Collections.Generic;
 class ProgramD
    {
        static void Main(string[] args)
        {
            
            string input = Console.ReadLine();
            int n = int.Parse(input);

            string[] L = Console.ReadLine().Split();
            int count = 0;
            int[] Li = new int[n];

            for(int i = 0; i < n;i++)
                Li[i] = int.Parse(L[i]);
            
            Array.Sort(Li);

            for(int i = n -1; i > 1 ;i--)
            {
                int a = Li[i];

                for(int j = i - 1; j >= 0;j--)
                {
                    int b = Li[j];

                    for(int k = j - 1; k >= 0;k--)
                    {
                
                
                        int c = Li[k];

                        if(a < c + b)
                            count++;
                        else
                            continue;
                    }


                }
            }

            Console.WriteLine(count);
                
        }
    }

Measured memory_bytes: 13176
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H - h) * (W - w) << endl;
    return 0;
}

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

pair<int, int> p[510];
int ans[250010], beh[510];

int main() {
	int N;
	cin >> N;
	for(int i=0; i<N; ++i){
		int x;
		cin >> x;
		p[i]=make_pair(x, i+1);
	}
	sort(p, p+N);
	for(int i=0; i<N; ++i){
		ans[p[i].first]=p[i].second;
		int cnt=1;
		for(int j=1; j<p[i].first && cnt<p[i].second; ++j){
			if(ans[j]==0){
				ans[j]=p[i].second;
				++cnt;
			}
		}
		if(cnt<p[i].second){
			cout << "No" << endl;
			return 0;
		}
	}
	int ys=0;
	for(int i=1; i<=N*N; ++i){
		if(p[ys].first==i){
			beh[p[ys].second]=N-p[ys].second;
			++ys;
		}
		if(ans[i]==0){
			for(int j=1; j<=N; ++j){
				if(beh[j]>0){
					ans[i]=j;
					--beh[j];
					break;
				}
			}
			if(ans[i]==0){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	cout << ans[1];
	for(int i=2; i<=N*N; ++i) cout << ' ' << ans[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 2176
// 6/30 解き直し
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main() {
    int N, M;
    cin >> N >> M;

    // vector<int> A(N), B(N);
    // rep(i, N) cin >> A[i] >> B[i];
    // vector<P> J(N);
    vector<P> J;
    rep(i, N) {
        int a, b;
        cin >> a >> b;
        // J[i] = P(a, b);
        // cout << a << ", " << b << endl;
        J.push_back({a, b});
    }
    // rep(i, N) printf("J[%d] = %d, %d\n", i, J[i].first, J[i].second);
    sort(J.begin(), J.end());

    int res = 0;
    priority_queue<int> q;
    int id = 0;

    rep(i, M) {
        // M-1日後から決めていく。

        // a[i] <= i + 1の仕事のb[i]をqに追加する。
        while (J[id].first <= i+1) {
            q.push(J[id].second);
            id++;
            if (id>=N) break;
        }

        // キューに要素があれば追加する。
        if (!q.empty()) {
            res += q.top();
            q.pop();
        }
    }

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

Measured memory_bytes: 4744
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

const ll mod = 1e9 + 7;

template<class C>
inline int SZ(const C& c) {
  return c.size();
}

inline ll mul(ll a, ll b) {
  return ((a % mod) * (b % mod)) % mod;
}
ll prod(const vector<ll>& v) {
  ll res = 1;
  for (ll x: v) res = mul(res, x);
  return res;
}

ll solve(const int n, int k) {
  vector<ll> pos, neg;
  bool zero = false;
  for (int i = 0; i < n; i++) {
    ll x; cin >> x;
    if (x == 0) {
      zero = true;
      continue;
    }
    (x > 0 ? pos : neg).push_back(llabs(x));
  }
  // ascending
  sort(pos.begin(), pos.end());
  // descending
  sort(neg.rbegin(), neg.rend());

  if (SZ(pos) + SZ(neg) < k) return 0;

  if (n == k) {
    return mul(prod(pos), prod(neg)) * (SZ(neg) % 2 == 0 ? 1 : -1);
  }

  if (pos.empty()) {
    if (k % 2 == 0) {
      return prod(vector<ll>(neg.begin(), neg.begin() + k));
    } else {
      if (zero) return 0;
      return -prod(vector<ll>(neg.rbegin(), neg.rbegin() + k));
    }
  }

  if (SZ(neg) % 2 == 1) {
    neg.pop_back();
  }

  if (SZ(pos) + SZ(neg) < k) return 0;

  priority_queue<ll, vector<ll>, greater<ll>> neg2;
  for (int i = 0; i < SZ(neg); i += 2) {
    neg2.push(neg[i] * neg[i + 1]);
  }

  ll ans = 1;
  if (k & 1) {
    ans = mul(ans, pos.back());
    pos.pop_back();
    k--;
  }
  k/=2;

  while (SZ(neg2) > k) {
    neg2.pop();
  }
  while (SZ(neg2) < k) {
    ll a = pos.back(); pos.pop_back();
    ll b = pos.back(); pos.pop_back();
    neg2.push(a * b);
  }

  while (SZ(pos) >= 2) {
    ll a = pos.back(); pos.pop_back();
    ll b = pos.back(); pos.pop_back();
    if (a * b > neg2.top()) {
      neg2.pop();
      neg2.push(a * b);
    }
  }

  while (!neg2.empty()) {
    ans = mul(ans, neg2.top() % mod);
    neg2.pop();
  }

  return ans;
}

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n, k; cin >> n >> k;
  ll res = solve(n, k);
  res = ((res % mod) + mod) % mod;
  cout << res << endl;

  return 0;
}


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

signed main(void)
{
	int sum, ans, n, m;
	cin >> n;
	int t[n];
	sum = 0;
	rep(i, n)
	{
		cin >> t[i];
		sum += t[i];
	}
	cin >> m;
	pair<int, int> p[m];
	rep(i, m)
	{
		cin >> p[i].first >> p[i].second;
		p[i].first--;
	}
	rep(i, m)
	{
		ans = sum;
		ans -= t[p[i].first];
		ans += p[i].second;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int l,r;
    cin>>l>>r;
    int a = l/2019, b = r/2019;
    if (l==0||(b>=a+1)||(b==a&&l%2019==0)){
        cout<<0<<endl;
      	return 0;
    }
    int mini = 2019;
    for (int i=l;i<r;i++){
        for (int j=i+1;j<=r;j++){
            mini = min(mini, ((i%2019)*(j%2019))%2019);
        }
    }
    cout<<mini<<endl;
    
    return 0;
}

Measured memory_bytes: 256
/*input
2
ip cc
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}


int main(){
	IOS;
	int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(c==a+1) cout<<1;
  else cout<<0;
	return 0;
}


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

INT main()
{
	int n; cin>>n;
	vector<int> a(n),b(n),c(n);
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	for(int i=0;i<n;i++) cin>>c[i];	

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());
	int ans=0;
	for(int i=0;i<n;i++){
		int k = b[i];

		auto l = upper_bound(a.begin(), a.end(),k-1);
		int left = l-a.begin();

		auto r = lower_bound(c.begin(), c.end(),k+1);
		int right = c.end()-r;

		ans += left*right;
	}	

	cout<<ans;
}

Measured memory_bytes: 2560
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
    private static final BigDecimal TWO = BigDecimal.valueOf(2);

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        BigDecimal n = BigDecimal.valueOf(sc.nextLong());
        // スペース区切りの整数の入力
        BigDecimal a = BigDecimal.valueOf(sc.nextLong());
        BigDecimal b = BigDecimal.valueOf(sc.nextLong());

        BigDecimal count;
        if ((b.subtract(a)).remainder(TWO).compareTo(BigDecimal.ZERO) == 0) {
            count = (b.subtract(a)).divide(TWO);
        } else {
            if (extAbs(a, n).compareTo(extAbs(b, n)) == 1) {
                // 入れ替える
                BigDecimal tmp = a;
                a = n.subtract(b).add(BigDecimal.ONE);
                b = n.subtract(tmp).add(BigDecimal.ONE);
            }

            count = a.subtract(BigDecimal.ONE);
            a = BigDecimal.ONE;
            b = b.subtract(count);

            while (b.subtract(a).remainder(TWO).compareTo(BigDecimal.ZERO) != 0) {
                count = count.add(BigDecimal.ONE);
                b = b.subtract(BigDecimal.ONE);
            }

            count = (b.subtract(a)).divide(TWO).add(count);
        }
        // 出力
        System.out.println(count);
    }

    private static BigDecimal extAbs(BigDecimal t, BigDecimal n) {
        if (t.compareTo(n.divide(TWO)) == -1) {
            return t;
        }
        return n.subtract(t).add(BigDecimal.ONE);
    }
}

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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n =0;
	string s;
	cin>>s;
	for(int i=0;i<(int)s.size();i++){
		if( s[i] == '+') n++;
		else n--;
	}
	cout<<n;
	
	return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

ll n;
lvector layer(n+1),pat(n+1);

ll f(ll a,ll b) {
  if(a==0) return (b<=0)?0:1;
  else if(b<=1+layer[a-1]) return f(a-1,b-1);
  else return pat[a-1]+1+f(a-1,b-2-layer[a-1]);
}

int main() {
 
  ll n,x;cin>>n>>x;
  layer.resize(n+1),pat.resize(n+1);
  layer[0]=1,pat[0]=1;
  for(ll i=1;i<=n;++i) {
    layer[i]=1+layer[i-1]+1+layer[i-1]+1;
    pat[i]=pat[i-1]+1+pat[i-1];
  }
  ll ans=f(n,x);
  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans;
ll A,B,N, x;

void solve(){
    
    x = min(B - 1, N);
    cout << floor((A*x)/B) - A * floor(x/B) << endl;
}

int main(){
    cin >> A >> B >> N;

    solve();
}


Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define pb push_back
#define __ ios_base::sync_with_stdio(false); cin.tie(NULL);
const ll N = 1e7+7 ;
ll d[N] ;
void seive() {

    for (ll i = 1 ; i<= N; i++) {
        for (ll j = i ; j<=N ; j+=i) d[j]++ ;
    }

}

int main() {
//    __

    seive() ;
    ll n ;
    cin >> n ;
    ll ans = 0 ;
    for (ll i =1 ; i<= n ; i++) ans+= (i*d[i]) ;
    cout << ans << endl ;
    return 0 ;
}





Measured memory_bytes: 81744
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define ll long long
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0)
#define sz(a) (a).size()
#define triple pair<pill, ll>
using namespace __gnu_pbds;
using namespace std;
typedef gp_hash_table<int, short, hash<int>, equal_to<int>, direct_mod_range_hashing<int>, linear_probe_fn<>, hash_standard_resize_policy<hash_prime_size_policy, hash_load_check_resize_trigger<true>, true>> gp;
 
const ll N = 3e5 + 10;
const ll big = 1e18;
const ll block = 800;
const ll mod = 1e6;
 
ll n, m, q;
pill h[N], w[N];
map<pill, ll> mp;
 
set<ll> cnc[N];
 
int main() {
	cin >> n >> m >> q;
	while(q--) {
		ll x, y;
		cin >> x >> y;
		h[x].s = x;
		w[y].s = y;
		h[x].f++, w[y].f++;
		cnc[x].insert(y);
		mp[{x, y}]++;
	}
	sort(h + 1, h + n + 1);
	sort(w + 1, w + m + 1);
	ll ans = 0;
	ll mx = h[n].f;
	set<ll> p2;
	vector<ll> p1;
	for(int i = n; i > 0; i--) 
		if(h[n].f == h[i].f)
			p1.pb(h[i].s);
	for(int i = m; i > 0; i--) 
		if(w[m].f == w[i].f)
			p2.insert(w[i].s);
	for(auto u : p1) {
		vector<ll> x;
		for(auto v : cnc[u]) {
			if(p2.count(v))
				x.pb(v), p2.erase(v);
		}
		if(p2.size())
			cout << h[n].f + w[m].f, ex;
		for(auto v : x)
			p2.insert(v);
	}
	cout << h[n].f + w[m].f - 1;
}
 
/*
 
*/

Measured memory_bytes: 76220
n = int(input())
a = list(map(int, input().split()))
print(*a)
for i in range(1, n):
  v = a[i]
  j = i - 1
  while j >= 0 and a[j] > v:
    a[j+1] = a[j]
    j -= 1
  a[j+1] = v
  print(*a)


Measured memory_bytes: 5980
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
//#define INF 1100000000000000000LL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=2050;
//ここまでテンプレ
int main() {
	int a,b;
	cin>>a>>b;
	//最短距離行列
	int d[SIZE][SIZE]={};
	//行列の初期化
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			if(i==j)
				d[i][j]=0;
			else
				d[i][j]=INF;
		}
	}
	//辺の情報を受け取る
	//ノード番号は0-indexedに直す
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			cin>>d[i][j];
		}
	}
	//ワーシャルフロイド
	for(int k=0;k<10;k++){
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
	int ans=0;
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			int n;
			cin>>n;
			ans+=d[n][1];
		}
	}
	cout<<ans<<endl;
    return 0;
}

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

int main(){
    int a,b;
    cin>>a>>b;

    if((a==1&&b==2) || (a==2&&b==1)) cout<<3<<endl;
    else if((a==2&&b==3) || (a==3&&b==2)) cout<<1<<endl;
    else cout<<2<<endl;

    return 0;
}

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

using namespace std;

int main(){
    long long int a,b;
    long long int counter=0;
    cin>>a>>b;

    long long int d[b+5];
    long long int k[a+5];
    long long int A[a+5]={};

    for(int i=0;i<b;i++){
        cin>>d[i];
        for(int j=0;j<d[i];j++){
            cin>>k[j];
            A[k[j]]++;
        }
    }

    for(int i=0;i<a+5;i++){
        if(A[i]!=0){
            counter++;
        }
    }

    cout<<a-counter<<endl;
}

Measured memory_bytes: 3608
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = new List<int>();
            for (int i = 0; i < N; i++)
            {
                A.Add(int.Parse(Console.ReadLine()));
            }

            var tmp = A.OrderByDescending(i => i).Take(2).ToList();
            var max = tmp[0];
            var next = tmp[1];

            foreach (var a in A)
            {
                Console.WriteLine(a == max ? next : max);
            }
        }
    }
}


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

int main()
{

    ll N;
    cin>>N;
    ll sm=0,need,pre=0;

    ll now=26;
    ll len=1;
    while(N>now)
    {
        N-=now;
        now*=26;
        len++;
    }
    string ch(len,'0');
    N--;
    for(ll i=len-1; i>=0; i--)
    {
        ch[i]=(N%26)+'a';
        N/=26;
    }
    for(ll i=0; i<len; i++)
    {
        cout<<ch[i];
    }
}



Measured memory_bytes: 3624
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX = 50;

int H, W;
char field[MAX][MAX];
int dist[MAX][MAX];

int main() {
  cin >> H >> W;
  int white = 0;
  rep(i,H) {
    rep(j,W) {
      cin >> field[i][j];
      dist[i][j] = -1;
      if (field[i][j] == '.') ++white;
    }
  }

  queue<pii> que;
  que.push(pii(0,0));
  dist[0][0] = 0;
  while (!(que.empty())) {
    pii p = que.front();
    que.pop();
    for (int i = 0; i < 4; ++i) {
      int x = p.fi + dx[i], y = p.sc + dy[i];
      if (0 <= x && x < H && 0 <= y && y < W && field[x][y] != '#' && dist[x][y] < 0) {
        dist[x][y] = dist[p.fi][p.sc]+1;
        que.push(pii(x,y));
      }
    }
  }

  if (dist[H-1][W-1] < 0) {
    cout << -1 << endl;
  } else {
    cout << white - dist[H-1][W-1] - 1 << endl;
  }
}



Measured memory_bytes: 256
N = int(input())
ab = [list(map(int, input().split())) for i in range(N)]
cd = [list(map(int, input().split())) for i in range(N)]
count = 0

ab.sort(key=lambda x: x[1])
ab.reverse()
cd.sort()

for i in range(N):
    for j in range(N):
        if ab[j][0] < cd[i][0] and ab[j][1] < cd[i][1]:
            count += 1
            ab[j] = [200, 200]
            break
        
print(count)


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 1000000
typedef pair<ll,ll> P;
vector<P> v;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll n;
    cin>>n;
    for(int i=0;i<n;i++){
	ll l,r; cin>>l>>r;
	v.push_back(make_pair(l,r));
    }
    sort(v.begin(),v.end());
    ll ans=0;
    multiset<ll> La,Lb,Ra,Rb;
    for(int i=0;i<n;i++){
	Lb.insert(v[i].first);
	Rb.insert(v[i].second);
    }
    for(int i=0;i<n;i++){
	Lb.erase(Lb.find(v[i].first)); La.insert(v[i].first);
	Rb.erase(Rb.find(v[i].second)); Ra.insert(v[i].second);
	
	ll res=0;
	auto it1=La.end(); it1--; res+=max(0LL,*Ra.begin()-*it1+1);
	auto it2=Lb.end(); it2--; res+=max(0LL,*Rb.begin()-*it2+1);
	chmax(ans,res);
	
	La.erase(La.find(v[i].first)); Lb.insert(v[i].first);
	Ra.erase(Ra.find(v[i].second)); Rb.insert(v[i].second);
    }
    
    for(int i=0;i<n-1;i++){
	Lb.erase(Lb.find(v[i].first)); La.insert(v[i].first);
	Rb.erase(Rb.find(v[i].second)); Ra.insert(v[i].second);
	
	ll res=0;
	auto it1=La.end(); it1--; res+=max(0LL,*Ra.begin()-*it1+1);
	auto it2=Lb.end(); it2--; res+=max(0LL,*Rb.begin()-*it2+1);
	chmax(ans,res);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 11248
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Dynamic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            long sum = 0;
            for (long i = 1; i <= N; i++)
            {
                if(i % 3 == 0 || i % 5 == 0)
                {

                }
                else
                {
                    sum += i;
                }
            }
            Console.WriteLine(sum);
        }
    }
}


//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 27484
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod=1e9+7;
ll dp[2000000];
int main()
{
   ll n;
   cin>>n;
   ll a[n+1],b[n+1],i;
   for(i=0;i<n;i++)
   {
       cin>>a[i]>>b[i];
   }
   ll flag=0;
   for(i=0;i<n-2;i++)
   {
       if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2])
          flag=1;
   }
   if(flag==0)
    cout<<"No"<<endl;
   else
    cout<<"Yes"<<endl;
    



}


Measured memory_bytes: 3632
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll imos[31][100010];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,C;
cin>>n>>C;
for(int i=0;i<n;i++){
    int a,b,c;
    cin>>a>>b>>c;
    a--;c--;
    imos[c][a]++;
    imos[c][b]--;
}
for(int i=0;i<C;i++)for(int j=1;j<=100000;j++)imos[i][j]+=imos[i][j-1];
int ans=0;
for(int i=0;i<=100000;i++){
    int cnt=0;
    for(int j=0;j<C;j++)if(imos[j][i])cnt++;
    ans=max(ans,cnt);
}
cout<<ans<<endl;
}

Measured memory_bytes: 23680
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int a,b;
    scanf("%d%d", &a, &b);
    if((a+b)%2==0) {
        printf("%d\n", (a+b)/2);
    }
    else {
        printf("IMPOSSIBLE\n");
    }



    return 0;
}


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

int main(){

  int x, y, z;

  while(cin >> x >> y >> z, x|y|z){

    int max_s = -1;
    for(int i = 1; i <= z; i++){
      int prev1 = i * (100 + x) / 100;
      int next1 = i * (100 + y) / 100;
      for(int j = 1; j <= z; j++){
        int prev2 = j * (100 + x) / 100;
        int next2 = j * (100 + y) / 100;
        if(prev1 + prev2 == z){
          max_s = max(max_s, next1+next2);
        }
      }
    }
    cout << max_s << endl;
  }
  return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
using namespace std;

int f(int n)
{
        string s=to_string(n);
        int hoge=s.size();
        int res=0;
        rep(i,hoge)
        {
                res+=s[i]-'0';
        }
        return res;
}

main()
{
        int n,a,b; cin>>n>>a>>b;
        int cnt=0;
        rep(i,n)
        {
                int t=f(i+1);
                if(a<=t&&t<=b)cnt+=i+1;
        }
        cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
const int inf = 1e+9;

const ll mod = 1000000007;

int main() {
	ll n, m, x;

	cin >> n >> m >> x;

	ll a[n][m];
	ll c[n];

	rep(i, n) {
		cin >> c[i];
		rep(j, m) {
			cin >> a[i][j];
		}
	}
	ll min_cost = 100000000000; 

	for (int i = 0; i < (1 << n) ; i++) {
		ll cur = i;
		ll cost = 0;
		vector<ll> t(m, 0);
		ll index = 0;
		while(cur > 0) {
			if ((cur & 1) == 1) {
				cost += c[index];
				for(int j = 0; j < m; j++) {
					t[j] += a[index][j];
				}
			}
			cur = cur >> 1;
			index++;
		}
		bool is_ok = true;
		rep(j, m) {
			if (t[j] < x) {
				is_ok = false;
				break;
			}
		}
		if (is_ok) {
			min_cost = min(min_cost, cost);
		}
	}
	if (min_cost == 100000000000) {
		cout << -1 << endl;
		return 0;
	}

	cout << min_cost << endl;
	
	return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    string res;
    for (int i = 0; i < s.size(); i += 2) {
        res.push_back(s.at(i));
    }
    cout << res << '\n';
}

Measured memory_bytes: 592
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

R,G,B,N =[int(x) for x in input().split()]
a = 0
for i in range(N//R+1):
    for j in range(((N-(i*R))//G)+1):
        if (N -i*R-j*G)%B == 0:
            a += 1
                       
           

print(a)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>

using namespace std;

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

    int sum = 1;
    for (int i = 1; i < N; i++) {
        for (int j = 0; j < i; j++) {
            if (H[j] > H[i]) break;
            if (j == i - 1) sum++;
        }
    }
    cout << sum << endl;

    return 0;
}


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

inline char to_char(int i) {
    if (0 <= i && i <= 9) return '0'+i;
    if (10 <= i && i <= 36) return 'A'+i-10;
    return '?';
}

int main() {
    int N, M, Q;
    while (cin >> N >> M >> Q) {
        if ( ! N) break;

        vector<vector<int>> ST(N, vector<int>(Q+1, 0)), BT(M, vector<int>(Q+1, 0));
        for (int i=0; i<Q; ++i) {
            string S, B;
            cin >> S >> B;
            for (int j=0; j<(int)S.size(); ++j) {
                ST[j][i+1] = ST[j][i] ^ (S[j]-'0');
            }
            for (int j=0; j<(int)B.size(); ++j) {
                BT[j][i+1] = B[j]-'0';
            }
        }

        map<vector<int>,int> sw;
        for (int i=0; i<N; ++i) {
            if (sw.count(ST[i])) sw[ST[i]] = -1;
            else sw[ST[i]] = i;
        }

        for (int i=0; i<M; ++i) {
            cout << to_char(sw[BT[i]]);
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 7252
n = int(input())
p1 = 0
p2 = 0

for i in range(n):
    w1, w2 = map(str, input().split())
    #print(w1, w2)
    size = min(len(w1), len(w2))
    #print('#',size)
    
    if w1 == w2:
        p1 = p1 + 1
        p2 = p2 + 1
        #print(i,'a   ', p1, p2)
        
    elif w1[0:size] == w2[0:size]:
        if len(w1) < len(w2):
            p2 = p2 + 3
        else:
            p1 = p1 + 3
        #print(i,'b   ', p1, p2)
        
    else:
        for j in range(size):
            #print(j, w1[j])
            if ord(w1[j]) == ord(w2[j]):
                pass
            elif ord(w1[j]) < ord(w2[j]):
                p2 = p2 + 3
                #print('     ',p1,p2)
                break
            else:
                p1 = p1 + 3
                break
        #print(i, 'c   ', p1, p2)

print(p1, p2)


Measured memory_bytes: 5592
N,K = list(map(int,input().split()))

if K % 2 != 0:
    print( (N // K) ** 3)
    exit()
elif K == 2:
    if N % 2 == 0:
        print(((N // 2) ** 3) * 2)
    else:
        print(((N // 2) ** 3) + ((N // 2)+ 1) ** 3)
else:
    num =  N // (K // 2)
    if num % 2 == 0:
        print(((num // 2) ** 3) * 2)
    else:
        print(((num // 2) ** 3) + ((num // 2)+ 1) ** 3)





Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int K,N;
  cin >> K >> N;

  int A1;
  cin >> A1;
  int Aa,Ab;
  Aa=A1;
  int Amax=0;
  for(int i=1;i<N;i++){
    cin >> Ab;
    Amax=max(Amax,Ab-Aa);
    Aa=Ab;
  }
  Amax=max(Amax,A1+K-Aa);

  cout << K-Amax << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, const char *argv[])
{
  int n;
  cin >> n;
  vector<int> hs(n);
  for (int i = 0; i < n; i++) {
    cin >> hs[i];
  }

  int ans = 0, cnt = 0, i = 0;
  while (i < hs.size() - 1) {
    if (hs[i] >= hs[i + 1]) {
      cnt++;
    } else {
      ans = max(ans, cnt);
      cnt = 0;
    }

    i++;
  }

  cout << max(ans, cnt) << "\n";
  
}

Measured memory_bytes: 640
#include <cstdio>

#define INF 0x3f3f3f3f

int a[100][100];
int n,m;
int c[100100][2];
int step[100][100];

const int xp[] = {0,0,1,-1};
const int yp[] = {1,-1,0,0};

bool in(int x,int y)
{
	return x>=1 && x<=n && y>=1 && y<=m;
}

int main()
{
	scanf("%d %d\n",&n,&m);

	int num = 0;
	for (int i = 1; i<=n; i++)
	{
		for (int j = 1; j<=m; j++)
		{
			scanf("%c",&a[i][j]);
			if (a[i][j]=='.')
				num++;
			step[i][j] = INF;
		}
		getchar();
	}
	
	int head=1,tail = 1;
	c[1][0] = 1;
	c[1][1] = 1;
	step[1][1] = 1;

	while (head<=tail)
	{
		int x = c[head][0],y = c[head][1];
		//printf("!%d %d\n",x,y);

		for (int i = 0; i<4; i++)
			if (in(x+xp[i],y+yp[i]))
				if ( (step[x][y] + 1 < step[x+xp[i]][y+yp[i]] ) && a[x+xp[i]][y+yp[i]]=='.' )
				{
					step[x+xp[i]][y+yp[i]] = step[x][y] + 1;
					c[++tail][0] = x + xp[i];
					c[tail][1] = y + yp[i];
				}
		head++;
	}
	if (step[n][m]==INF)
		printf("-1");
	else printf("%d",num - step[n][m]);

}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))

e=[]
a.sort(reverse=True)
for i in range(len(a)-1):
  if a[i] == a[i+1] and a[i] not in e:
    e.append(a[i])
    if len(e) == 2:
      break
e.sort(reverse=True)

c4 = 0
for i in e:
  if a.count(i)>=4:
    c4=i
    break

if c4 == 0 and len(e)<2:
  print(0)
elif c4 == 0 and len(e)>=2:
  print(e[0]*e[1])
elif c4 > 0 and len(e)<2:
  print(c4**2)
else:
  print(max(c4**2,e[0]*e[1]))

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

signed main() {
  ios::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;

  vector<int> cnt(K);
  for (int i = 1; i < N + 1; ++i) {
    ++cnt[i % K];
  }

  if (K & 1) {
    int64_t ans = 1LL * cnt[0] * cnt[0] * cnt[0];
    cout << ans << endl;
  } else {
    int64_t ans = 1LL * cnt[0] * cnt[0] * cnt[0];
    ans += 1LL * cnt[K / 2] * cnt[K / 2] * cnt[K / 2];
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
mod = 10**9+7
 
s = input()
n = len(s)
 
dp = [0]*13
dp[0] = 1
 
for i in range(n):
  dp2 = [0]*13  
  for j in range(10):
    if s[i] == '?' or s[i] == str(j):
      for k in range(13):
        dp2[(k*10 + j)%13] += dp[k]
        dp2[(k*10 + j)%13] %= mod
        
  dp = dp2
 
print(dp[5])

Measured memory_bytes: 74040
#include <iostream>

using namespace std;

int main() {
    int A, B, K; cin >> A >> B >> K;
    for(int i = min(A, B); i > 0; i--) {
        if(A % i | B % i) continue;
        else {
            K--;
            if(K==0) {
                cout << i << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 888
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        n:usize,
        a:[usize;n]
    }
    let mut xorsum = 0;
    for i in 0..n{
        if i == 0 {
            xorsum = a[i];
        } else {
            xorsum = xorsum ^ a[i];
        }
    }

    for i in 0..n {
        let z = a[i] ^ xorsum;
        println!("{}", z);
    }
}


Measured memory_bytes: 6332
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  n=parse(Int,*(split(readline())...))
  println(isqrt(n)==sqrt(n) ? "Yes" : "No")
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


Measured memory_bytes: 158240
//This code was made by Chinese_zjc_.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<queue>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
int n,m,a,ans;
bool c[500];
signed main()
{
	std::ios::sync_with_stdio(false);
	cin>>m>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>a;
		c[a]=true;
	}
	for(int i=1;i<=200;++i)
	{
		if(!c[i]&&abs(m-ans)>abs(m-i))
		{
			ans=i;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using ll=long long;
using namespace std;

int main(){
    int N;
    cin>>N;
    vector<int> A(N);
    vector<int> B(N);

    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    for(int j=0;j<N;j++){
        cin>>B[j];
    }


/*
    int apt=0;
    int bpt=0;
    int maxD=0;
    int cnt;
    for(int i=1;i<=N;i++){
        cnt=0;
        while(apt<N && A[apt]<=i){
            apt++;
            cnt++;
        }
        if(maxD<(apt-bpt)){
            maxD=(apt-bpt);
        }
        while(bpt<N && B[bpt]<=i){
            bpt++;
            cnt++;
        }
        if(cnt>N){
            cout<<"No"<<endl;
            return 0;
        }
    }
    */

    vector<int> C(N+1,0);
    vector<int> D(N+1,0);
    for(int i=0;i<N;i++){
        C[A[i]]++;
        D[B[i]]++;
    }
    for(int i=1;i<N+1;i++){
        if(C[i]+D[i]>N){
            cout<<"No"<<endl;
            return 0;
        }
    }
    for(int i=1;i<N+1;i++){
        C[i]+=C[i-1];
        D[i]+=D[i-1];
    }

    int maxD=0;
    for(int i=1;i<N+1;i++){
        if(maxD<C[i]-D[i-1]){
            maxD=C[i]-D[i-1];
        }
    }

    cout<<"Yes"<<endl;


    for(int i=0;i<N;i++){
        cout<<B[(i+N-maxD)%N]<<" ";
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 6428
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<int>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin>>n;
    V v(n);
    rep(i,0,n) cin>>v[i];
    int a=v[0];
    int ans=1;
    rep(i,0,n){
        if(a==2){
            cout<<ans<<"\n";
            return 0;
        }
        a=v[a-1];
        ans++;
    }
    cout<<-1<<"\n";
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  if ((A == B && B != C) || (A == C && A != B) || (B == C && B != A)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

typedef pair<int,int> P;

template <int N = 100010>
struct UF{
	int par[N],r[N];
	UF(){
		for(int i = 0 ; i < N ; i ++){
			par[i] = i;
			r[i] = 0;
		}
	}
	int find(int x){
		if(par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	bool same(int x,int y){
		return find(x) == find(y);
	}
	void unit(int x,int y){
		if(same(x,y))return;
		x = find(x);
		y = find(y);
		if(r[x] < r[y]){
			par[x] = y;
		}
		else {
			par[y] = x;
			if(r[x] == r[y]){
				r[x] ++;
			}
		}
	}
};

int main(){
	static int n,k,l;
	static int p[100010],q[100010];
	static int r[100010],s[100010];
	scanf("%d%d%d",&n,&k,&l);
	for(int i = 0 ; i < k ; i ++){
		scanf("%d%d",&p[i],&q[i]);
	}
	for(int i = 0 ; i < l ; i ++){
		scanf("%d%d",&r[i],&s[i]);
	}
	
	UF<200010> uf[2];
	for(int i = 0 ; i < k ; i ++){
		uf[0].unit(p[i],q[i]);
	}
	for(int i = 0 ; i < l ; i ++){
		uf[1].unit(r[i],s[i]);
	}
	
	static map<P,int> cnt;
	for(int i = 1 ; i <= n ; i ++){
		cnt[P(uf[0].find(i),uf[1].find(i))] ++;
	}
	for(int i = 1 ; i <= n ; i ++){
		printf("%d%c",cnt[P(uf[0].find(i),uf[1].find(i))],(i==n)?'\n':' ');
	}
}

Measured memory_bytes: 16768
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())

ans = 0
select = [False] * N
for i in range(N):
    if i >= K:
        if T[i-K] == T[i]:
            if select[i-K]:
                continue
    if T[i] == "r":
        ans += P
    elif T[i] == "s":
        ans += R
    else:
        ans += S
    select[i] = True
print(ans)


Measured memory_bytes: 50416
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n = int(input())
hhh = get_nums_l()

next = 999999999999
for i in range(n-1,-1, -1):
    now = hhh[i]
    if now > next:
        if (now - next) >= 2:
            print("No")
            exit()
        else:  
            next = now-1
    elif now == next:
        next = now
    else:
        next = now
print("Yes")


Measured memory_bytes: 63836
e1,a1,b1=input().split()
e2,a2,b2=input().split()
e3,a3,b3=input().split()
e4,a4,b4=input().split()
e5,a5,b5=input().split()
e6,a6,b6=input().split()
e7,a7,b7=input().split()
e8,a8,b8=input().split()
e9,a9,b9=input().split()

print(e1,int(a1)+int(b1),int(a1)*200+int(b1)*300)
print(e2,int(a2)+int(b2),int(a2)*200+int(b2)*300)
print(e3,int(a3)+int(b3),int(a3)*200+int(b3)*300)
print(e4,int(a4)+int(b4),int(a4)*200+int(b4)*300)
print(e5,int(a5)+int(b5),int(a5)*200+int(b5)*300)
print(e6,int(a6)+int(b6),int(a6)*200+int(b6)*300)
print(e7,int(a7)+int(b7),int(a7)*200+int(b7)*300)
print(e8,int(a8)+int(b8),int(a8)*200+int(b8)*300)
print(e9,int(a9)+int(b9),int(a9)*200+int(b9)*300)


Measured memory_bytes: 5604
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <functional>
#include <cmath>
#include <cstdint>
#include <mutex>
#include <thread>
#include <bitset>

using namespace std;
typedef long long int ll;

int main(void)
{	
	ll n;
	ll sum = 0;
	ll h;
	cin >> n;

	ll x;
	cin >> x;
	h = x;
	for (ll i = 1; i < n; i++)
	{	
		cin >> x;
		if (h > x)
		{
			sum += h - x;
		}
		else
		{
			h = x;
		}
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

void solve(){
    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    REP(i,N) cin >> H[i];
    vector<vector<int>> G(N);
    REP(i,M){
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    int ans = 0;
    REP(i,N){
        int ma = H[i];
        bool ok = true;
        for(auto nv : G[i]){
            if(H[nv] >= ma){
                ok = false;
                break;
            }
        }
        if(ok) ans++;
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}


Measured memory_bytes: 8740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi; 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int mod = 1e9+7;
const int maxn =2005; 
const int inf = 0x3f3f3f3f;
ll dp[maxn][maxn];
pair<ll,int> a[maxn];
ll cal(pair<ll,int> a,int pos) {
	return a.fi*abs(a.se-pos);
}
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	int n;
	cin>>n;
	rep(i,1,n) {
		cin>>a[i].fi;
		a[i].fi=-a[i].fi;
		a[i].se=i;
	}
	sort(a+1,a+1+n);
	rep(i,1,n) {
		a[i].fi=-a[i].fi;
		rep(j,0,i-1) {
			int l=j,r=i-1-j;
			dp[l+1][r]=max(dp[l+1][r],dp[l][r]+cal(a[i],l+1));
			dp[l][r+1]=max(dp[l][r+1],dp[l][r]+cal(a[i],n-r));
		}
	}
	ll ans=0;
	rep(i,0,n) ans=max(ans,dp[i][n-i]);
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 26268
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    H1, M1, H2, M2, K = read_values()
    m1 = H1 * 60 + M1
    m2 = H2 * 60 + M2
    print(m2 - m1 - K)


if __name__ == "__main__":
    main()



Measured memory_bytes: 9856
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

ll D, T, S;

signed main(){
    cin >> D >> T >> S;
    if(D <= T*S) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3660
#include <stdio.h>

int minnum(int a,int b){
	if(a > b)return b;
	else return a;
}

int main(void){
	int a,b,k;
	int res[100];
	int c=0;
	scanf("%d %d %d",&a ,&b ,&k);
	int min = minnum(a,b);
	for(int i=1;i<=min;i++){
		if(a % i == 0 && b % i == 0){
			res[++c] = i;
		}
	}
	printf("%d\n",res[c-k+1]);
	return 0;
}

Measured memory_bytes: 128