akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;
int n,m,k,x,y,l,r,u,d;

int lr[500000];
int ud[500000];
int lrt,udt;
int lr_flag[500000];
int ud_flag[500000];
char s1[500000];
char s2[500000];

bool lr_l()
{
    int nowy = y;
    for (int i=0; i<lrt; ++i)
    {
        if (lr_flag[i]==1)
        {
            if (lr[i]==-1)
                nowy-=1;
        }else
        if (lr_flag[i]==0)
        {
            if (lr[i]==1 && nowy!=m)
                nowy+=1;
        }
        if (nowy<=0) return 0;
    }
    return 1;
}
bool lr_r()
{
    int nowy = y;
    for (int i=0; i<lrt; ++i)
    {
        if (lr_flag[i]==1)
        {
            if (lr[i]==1)
                nowy+=1;
        }else
        if (lr_flag[i]==0)
        {
            if (lr[i]==-1 && nowy!=1)
                nowy-=1;
        }
        if (nowy>m) return 0;
    }
    return 1;
}
bool ud_u()
{
    int nowx = x;
    for (int i=0; i<udt; ++i)
    {
        if (ud_flag[i]==1)
        {
            if (ud[i]==-1)
                nowx-=1;
        }else
        if (ud_flag[i]==0)
        {
            if (ud[i]==1 && nowx!=n)
                nowx+=1;
        }
        if (nowx<=0) return 0;
    }
    return 1;
}
bool ud_d()
{
    int nowx = x;
    for (int i=0; i<udt; ++i)
    {
        if (ud_flag[i]==1)
        {
            if (ud[i]==1)
                nowx+=1;
        }else
        if (ud_flag[i]==0)
        {
            if (ud[i]==-1 && nowx!=1)
                nowx-=1;
        }
        if (nowx>n) return 0;
    }
    return 1;
}
void check()
{
    
    int t1 =lr_l();
    int t2 =lr_r();
    int t3 =ud_u();
    int t4 =ud_d();
    if (t1&t2&t3&t4)
        cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

int main()
{
    cin>>n>>m>>k;
    cin>>x>>y;
    l = y;
    r = m-y+1;
    u = x;
    d = n-x+1;
    for (int i=1; i<=k; ++i)
        cin>>s1[i];
    for (int i=1; i<=k; ++i)
        cin>>s2[i];
    for (int i=1; i<=k; ++i)
    {
        if (s1[i]=='L')
        {
            lr[lrt]=-1;
            lr_flag[lrt]=1;
            lrt++;
        }
        if (s1[i]=='R')
        {
            lr[lrt]=1;
            lr_flag[lrt]=1;
            lrt++;
        }
        if (s1[i]=='U')
        {
            ud[udt]=-1;
            ud_flag[udt]=1;
            udt++;
        }
        if (s1[i]=='D')
        {
            ud[udt]=1;
            ud_flag[udt]=1;
            udt++;
        }
        if (s2[i]=='L')
        {
            lr[lrt]=-1;
            lr_flag[lrt]=0;
            lrt++;
        }
        if (s2[i]=='R')
        {
            lr[lrt]=1;
            lr_flag[lrt]=0;
            lrt++;
        }
        if (s2[i]=='U')
        {
            ud[udt]=-1;
            ud_flag[udt]=0;
            udt++;
        }
        if (s2[i]=='D')
        {
            ud[udt]=1;
            ud_flag[udt]=0;
            udt++;
        }
    }
    check();

    
    return 0;
}



Measured memory_bytes: 7552
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder
{
    public static class Program
    {
        static void Main()
        {
            var cnt = Console.ReadLine().ToCharArray().Distinct().Count();
            Console.WriteLine(cnt == 2 ? "Yes" : "No");
        }
    }
}


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

using namespace std;

int main() {
	
	ios_base :: sync_with_stdio(0); cin.tie(NULL);

	int N, M;
	cin >> N >> M;

	vector<int> H (N);	
	for(int &x : H)
		cin >> x;

	vector< vector<int> > g(N);

	for(int i = 0; i < M; ++i) {
		int a, b; cin >> a >> b;
		--a; --b;

		g[a].push_back(b);
		g[b].push_back(a);
	}

	int ans = 0;

	for(int u = 0; u < N; ++u) {
		bool ok = true;

		for(int v : g[u]) {

			if (H[u] > H[v])
				continue;
			ok = false;
			break;
		}

		ans += ok;
	}

	cout << ans << '\n';


	return 0;	
}

Measured memory_bytes: 8728
s = str(input())

ans = 0
if len(s) % 2 == 0:
    n = int(len(s) / 2)
    for i in range(n):
        if s[len(s) - i - 1] != s[i]:
            ans += 1
else:
    n = int(len(s) // 2)
    for i in range(n):
        if s[len(s) - i - 1] != s[i]:
            ans += 1

print(ans)


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

int arr[3];

int main()
{

    for (int i = 0; i < 3; i++)
    {
        cin>>arr[i];
    }

    sort(arr,arr+3);

    if (arr[0]==arr[1] && arr[1]!=arr[2])
    {
        cout<<"Yes";
    }else if (arr[0]!=arr[1] && arr[1]==arr[2])
    {
        cout<<"Yes";
    }else
    {
        cout<<"No";
    }
    
    
    
    
}

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

using Graph = vector<vector<int>>;

int solve(auto& G, auto S, auto T) {
  using Memo = pair<int, int>;
  set<Memo> d;

  using Node = tuple<int, int, int>;
  priority_queue<Node, vector<Node>, greater<Node>> q;

  q.emplace(0, 0, S);

  while(!q.empty()) {
    int cost, step, u;
    tie(cost, step, u) = q.top();
    q.pop();

    if(u == T && step == 0) return cost;

    Memo memo = {step, u};
    if(d.count(memo)) continue;
    d.emplace(memo);

    for(auto v: G[u]) {
      if(step < 2) q.emplace(cost, step + 1, v);
      else         q.emplace(cost + 1, 0, v);
    }
  }

  return -1;
}

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

  Graph G(N);
  for(auto i = 0; i < M; ++i) {
    int u, v;
    cin >> u >> v;
    --u; --v;
    G[u].emplace_back(v);
  }

  int S, T;
  cin >> S >> T;
  --S; --T;

  cout << solve(G, S, T) << endl;
}


Measured memory_bytes: 19712
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int p[30];
int x[30];
int dp[1<<20];
int main(){
	int a;scanf("%d",&a);
	while(a>=0){
		if(a%7==0){
			printf("Yes\n");return 0;
		}a-=4;
	}
	printf("No\n");
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<map>
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<time.h>
#include<limits.h>
#include<unordered_map>
#include<set>
#include<queue>
#include <iomanip>
using namespace std;
#define inf LLONG_MAX
const int N = 2e5 + 7;
#define int long long
void solve() {
    string s, t; cin >> s >> t;
    int c = 0;
    for (int i = 0; i < s.size(); i ++) {
        if (s[i] != t[i]) c ++;
    }
    cout << c;
}

int32_t main() {
        solve();

}


Measured memory_bytes: 3912
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };


int main() {
	char S[10];
	scanf("%s", &S);

	int count = 0;

	int len = strlen(S);

	for (int i = 0; i < len; i++) 
		if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T')S[i] = '0';
	
	for (int i = 0; i < len; i++) {
		int temp = 0;
		if (S[i] == '0')
			for (int j = i; j < len; j++) {
				if (S[j] == '0')temp++;
				else break;
			}
		count = max(count, temp);
	}

	printf("%d", count);

}

/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
・文字列の＜＜スペル＞＞は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

Measured memory_bytes: 128
import java.util.*

fun search(a: MutableList<Int>, x: Int, l: Int, r: Int): Int {
    if (1 >= r - l) {
        return l
    } else {
        val m = (l + r) / 2
        if (a[m] >= x) {
            return search(a, x, l, m)
        } else {
            return search(a, x, m, r)
        }
    }
}


fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    val a = Array<Int>(n, { cin.nextInt() })
    
    val roots: MutableList<Int> = mutableListOf(a[0])
    for (i in 1..n-1) {
        val k = search(roots, a[i], -1, roots.size)
        if (k == -1) {
            roots.add(0, a[i])
        } else {
            roots[k] = a[i]
        }
    }

    println(roots.size)
}

Measured memory_bytes: 52728
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;    
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;    
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

constexpr char BR = '\n';


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

constexpr int CONTEST_SIZE = 26;
constexpr int DAY_MAXSIZE = 365;

int calc_score(int *r, const int c[CONTEST_SIZE], const int s[DAY_MAXSIZE][CONTEST_SIZE], int t[DAY_MAXSIZE], int D = DAY_MAXSIZE)
{
    int score = 0;
    int last[CONTEST_SIZE] = {};
    for (int d = 0; d < D; d++)
    {
        int con = t[d];
        score += s[d][con];
        last[con] = d+1;
        for (int i = 0; i < CONTEST_SIZE; i++)
        {
            score -= c[i] * (d+1 - last[i]);
        }
        if (r) r[d] = score;
    }
    return score;
}

int main()
{
    int D; io >> D;
    int c[CONTEST_SIZE];
    int s[DAY_MAXSIZE][CONTEST_SIZE];
    for (int i = 0; i < CONTEST_SIZE; i++)
        io >> c[i];
    for (int d = 0; d < D; d++)
        for (int c = 0; c < CONTEST_SIZE; c++)
            io >> s[d][c];
    
    int t[DAY_MAXSIZE];

    for (int d = 0; d < D; d++)
    {
        auto it_max = max_element(s[d], s[d] + CONTEST_SIZE);
        t[d] = distance(s[d], it_max) + 1;
    }

    //int score = calc_score(nullptr, c, s, t ,D);
    //io << score << BR;

    for (int d = 0; d < D; d++)
        io << t[d] << BR;
}


Measured memory_bytes: 3856
#include<bits/stdc++.h>
using namespace std;
int n, m, i;
int main()
{
    cin >> n >> m;
    int x, y;
    for(i=1;i<=10000;i++)
    {
        x = i*0.08;
        y = i*0.10;
        if(x==n && y==m)
            break;
    }
    if(x==n && y==m)
        cout << i << endl;
    else
        cout << -1 << endl;
}


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

using namespace std;

#define pb push_back
#define rep(i,a) for(int i = 0; i < a; i++)

int main(void){
  int num,l;
  int ans;
  while(cin>>num>>l,num+l){
    vector<int> a;
    a.pb(num);
    int index = 0,j;
    bool flag = true;
    while(flag){
      vector<int> dig(l);
      int tmp = a[index];
      for(int i = 0 ; i < l ; i ++){
	dig[i] = tmp % 10 ;
	tmp /= 10;
      } 
      sort(dig.begin(),dig.end());
      
      int maxa = 0 ,mina = 0;
      for(int i = 0 ; i < l ; i ++){
	mina = mina * 10 + dig[i];
	maxa = maxa * 10 + dig[l - i - 1];
      }
      a.pb(maxa-mina);
      index++;
      
      rep(i,index){
	if(a[index] == a[i]){
	  flag = false;
	  j = index;
	  ans = i;
	  break;
	}
      }
    }
    cout<<ans<<" "<<a[index]<<" "<<index-ans<<endl;
  }
}

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

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    int a[m];
    for (int i = 0; i < m; i++) cin >> a[i];

    int count = 0;
    for (int i = 0; i < m; i++) {
        if (a[i] < x)
            count ++;
        else
            break;
    }
    int ans = min(count, m-count);
    cout << ans << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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 h, w;
vvi c(10,vi(10));
int a[205][205];

int main () {
  cin >> h >> w;
  rep(i,10)rep(j,10) cin >> c[i][j];
  rep(i,h)rep(j,w) cin >> a[i][j];

  vvi dist = c;
  rep(k,10)rep(i,10)rep(j,10) chmin(dist[i][j], dist[i][k]+dist[k][j]);

  int ans = 0;
  rep(i,h)rep(j,w) {
    if (a[i][j] == -1) continue;
    ans += dist[a[i][j]][1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int red = 0;
        int white = 0;
        for (int i=0;i<n;i++){
            if (s.charAt(i)=='R')red++;
            else white++;
        }
        int proR = 0;
        int proW = 0;
        for (int i=0;i<red;i++){
            if (s.charAt(i)=='W')proW++;
        }
        for (int i=red;i<n;i++){
            if (s.charAt(i)=='R')proR++;
        }
        System.out.println(Math.min(proR,proW));
    }
}


Measured memory_bytes: 31332
import sys

N = int(input())
A = sorted(list(map(int, input().split())), reverse = True)

mstack = []
stack = [0]
for a in A:
    if a == stack[-1]:
        mstack.append(a)
        stack.pop()
        if len(mstack) >= 2:
            print(mstack[-1] * mstack[-2])
            sys.exit()
    else:
        stack.append(a)
print(0)


Measured memory_bytes: 14224
N, M = [int(_) for _ in input().split()]
S = input()
T = input()


def gcd(x, y):
    if x < y:
        return gcd(y, x)
    elif y == 0:
        return x
    else:
        return gcd(y, x % y)


g = gcd(N, M)
if (g == 1 and S[0] == T[0]) or S[::N // g] == T[::M // g]:
    print(N * M // g)
else:
    print(-1)


Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
int main(void){
    // Your code here!
    int k, a, b;
    scanf("%d%d%d", &k, &a, &b);
    printf(((b / k) - (a / k) || a % k == 0 || b % k == 0) ? "OK\n" : "NG\n");
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
int a,b[10001];
int main()
{
	for(int i=1;i<=3;i++)
	  {
	  	cin>>a;
	  	b[a]++;
	  }
	if(b[5]==2&&b[7]==1)
	  cout<<"YES";
	else
	  cout<<"NO";
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
found = set()
f = 0
for i in l:
  if i <= 399:
    found.add("灰色")
  elif i <= 799:
    found.add("茶色")
  elif i <= 1199:
    found.add("緑色")
  elif i <= 1599:
    found.add("水色")
  elif i <= 1999:
    found.add("青色")
  elif i <= 2399:
    found.add("黄色")
  elif i <= 2799:
    found.add("橙色")
  elif i <= 3199:
    found.add("赤色")
  else:
    f += 1
if len(found) == 0:
  print(1, min(f, 8))
else:
  print(len(found), len(found) + f)


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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

void doit(){
    ll a, b , c, d;
    cin >> a >> b >> c >> d;
    ll ans = -8e18;
    ans = max({a*c,a*d,b*c,b*d});
    cout << ans << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
   //  cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


Measured memory_bytes: 3648
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long N;
  cin >> N;

  long S = 0;
  long a = N;

  while (a) {
    S += a % 10;
    a /= 10;
  }

  puts(N % S == 0 ? "Yes" : "No");
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int N;
    cin >> N;
    vi s(N);
    rep(i,N) cin>>s[i];

    ll mx = accumulate(all(s),0ll);

    if(mx%10){
        cout << mx << endl;
    }else{
        ll mn = 200;
        rep(i,N) if(s[i]%10!=0){
            chmin(mn,s[i]);
        }

        if(mn % 10 == 0){
            cout << 0 << endl;
            return 0;
        }

        cout << mx - mn << endl;
    }
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=0,ans=0,a,b,c,cmp,data,m,h,x,y,xcmp=0,ycmp=0,sum=0;

string s,w;

vector<int> z;

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

       cin  >> n >> y;
      for(int i=0;i<=n;i++){
          for(int j=0;j<=n-i;j++){
              for(int k=0;k<=n-i-j;k++){
                  if(10000*i+5000*j+1000*k==y && i+j+k==n){
                      cout << i << " " << j << " " << k << endl;
                      return 0;
                  }
              }
          }
      }
       cout << -1 << " " << -1 << " " << -1 << endl;
return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;




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

		return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  string S;
  cin>>S;
  int N=S.size();

  ll ans=0;
  ll num=0;
  for(int i=0;i+1<N;i++){
    if(S[i]=='A') num++;
    else if(S[i]=='B'&&S[i+1]=='C'){
      ans+=num;
      i++;
    }else num=0;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 640
n, m = map(int, input().split())
order = [list() for _ in range(n)]
ans = [""] * m

for i in range(m):
    p, y = map(int, input().split())
    order[p-1].append((i, y))
    ans[i] += str(p).zfill(6)

for o in order:
    o.sort(key=lambda x: x[1])
    for i in range(len(o)):
        ans[o[i][0]] += str(i+1).zfill(6)

for a in ans: print(a)


Measured memory_bytes: 41104
card = []
for i in range(3):
    row = list(map(int,input().split()))
    card.append(row)

n = int(input())
ans = False

for i in range(n):
    b = int(input())
    for  j in range(3):
        if b in card[j]:
            card[j][card[j].index(b)] = 0

def judge(lst):
    return lst == [0,0,0]

for i in range(3):
    ans |= judge(card[i])
for i in range(3):
    ans |= judge([card[j][i] for j in range(3)])
ans |= judge([card[i][i] for i in range(3)])
ans |= judge([card[i][2-i] for i in range(3)])

print("Yes" if ans else "No")

Measured memory_bytes: 9184
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	double h;
	double mi = (double)inf, ma = 0;
	while (cin >> h) {
		mi = min(mi, h);
		ma = max(ma, h);
	}

	printf("%.6f\n", ma - mi);
}


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

class Program
{
    static void Main(string[] args)
    {
        var input = int.Parse(Console.ReadLine());
        var array = Console.ReadLine().Split(' ');

        var minusDict = new Dictionary<int, long>();
        var plusDict = new Dictionary<int, long>();


        for (var i = 0; i < input; i++)
        {
            if (minusDict.ContainsKey(int.Parse(array[i]) - (i + 1)))
            {
                minusDict[int.Parse(array[i]) - (i + 1)] += 1;
            }
            else
            {
                minusDict.Add(int.Parse(array[i]) - (i + 1), 1);
            }

            if (plusDict.ContainsKey(int.Parse(array[i]) + (i + 1)))
            {
                plusDict[int.Parse(array[i]) + (i + 1)] += 1;
            }
            else
            {
                plusDict.Add(int.Parse(array[i]) + (i + 1), 1);
            }

        }

        long ans = 0;

        foreach(var n in plusDict)
        {
            if(minusDict.ContainsKey(n.Key * -1))
            {
                ans += n.Value * minusDict[n.Key * -1];
            }
        }


        Console.WriteLine(ans);
        Console.ReadLine();
    }

}



Measured memory_bytes: 52628
#include<iostream>
#include<cmath>

using namespace std;

int main(void){
    int n,a,f=1;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a;
        if(a%2==0){
            if((a%3)&&(a%5)){
                f = 0;
                cout << "DENIED";
                break;
            }
        }
    }
    if(f){
        cout << "APPROVED";
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();

		long answer = 0;

		long l_num_befbef = -1;
		long l_num_bef    = 2;
		long now_num = 0;

		for(int i = 0; i < N; i++) {
			now_num = l_num_bef + l_num_befbef;
			l_num_befbef = l_num_bef;
			l_num_bef = now_num;

			answer = now_num;
		}

		System.out.println(answer);
	}

}


Measured memory_bytes: 21460
#include <iostream>
#include <string>

using namespace std;

int main(){
    int K;
    cin>>K;
    string buf;
    cin>>buf;
    if (buf.size()<=K) cout<<buf<<endl;
    else {
        for(int i=0;i<K;i++) cout<<buf[i];
        cout<<"..."<<endl;
    }
    return 0;
}

Measured memory_bytes: 3628
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val a = (1..n).map { sc.nextInt() }

  val size4 = a.filter { it % 4 == 0 }.size
  val sizeOdd = a.filter { it % 2 != 0 }.size

  if (sizeOdd <= size4) {
    println("Yes")
    return
  }
  if (sizeOdd <= size4 + 1 && sizeOdd + size4 == n) {
    println("Yes")
    return
  }


  println("No")

}


Measured memory_bytes: 62040
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    vector<int> P(N), min_P(N);

    rep(i, N) {
        cin >> P[i];
    }

    int m = P[0];
    min_P[0] = m;
    repd(i, 1, N) {
        m = min(m, P[i]);
        min_P[i] = m;
    }

    int ans = 0;
    rep(i, N) {
        if (min_P[i] >= P[i]) ans++;
    }

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

Measured memory_bytes: 1792
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;

int main() {
	
	int A, B, C;
	int ans;
	
	scanf("%d", &A);
	scanf("%d", &B);
	scanf("%d", &C);
	
	if(A * C > B){
		ans = B / A;
	}else{
		ans = C;
	}
	
	printf("%d", ans);
	
	return 0;
	
}


Measured memory_bytes: 128
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


a,b,q = list(map(int, input().split()))
s = [int(input()) for _ in range(a)]
t = [int(input()) for _ in range(b)]
from bisect import bisect_left as bl
ls = [None]*a
lt = [None]*b
for i in range(a):
    ind = bl(t, s[i])
    v = float("inf")
    if ind<b:
        v = min(v, abs(t[ind]-s[i]))
    if ind>0:
        v = min(v, abs(t[ind-1]-s[i]))
    ls[i] = v
for i in range(b):
    ind = bl(s, t[i])
    v = float("inf")
    if ind<a:
        v = min(v, abs(s[ind]-t[i]))
    if ind>0:
        v = min(v, abs(s[ind-1]-t[i]))
    lt[i] = v
ans = [None]*q
for i in range(q):
    x = int(input())
    v = float("inf")
    ind = bl(s, x)
    if ind<a:
        v = min(v, abs(s[ind]-x)+ls[ind])
    if ind>0:
        v = min(v, abs(s[ind-1]-x)+ls[ind-1])
    ind = bl(t, x)
    if ind<b:
        v = min(v, abs(t[ind]-x)+lt[ind])
    if ind>0:
        v = min(v, abs(t[ind-1]-x)+lt[ind-1])
    ans[i] = v
write("\n".join(map(str, ans)))

Measured memory_bytes: 102476
#include <bits/stdc++.h>
#include<iostream>
#include<queue>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
  int N,a,b,c,d;
  cin>>N;
  a=N/1000;
  b=(N-(a*1000))/100;
  c=(N-(b*100)-(a*1000))/10;
  d=(N-(c*10)-(b*100)-(a*1000))/1;
  if(a+b+c+d==7){
    cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<'='<<7<<endl;
    exit(0);
  }
  if(a+b-c+d==7){
    cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<'='<<7<<endl;
    exit(0);
  }
  if(a+b+c-d==7){
    cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<'='<<7<<endl;
    exit(0);
  }
  if(a+b-c-d==7){
    cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<'='<<7<<endl; 
    exit(0);
  }
  if(a-b+c+d==7){
    cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<'='<<7<<endl; 
    exit(0);
  }
  if(a-b-c+d==7){
    cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<'='<<7<<endl;
    exit(0);
  }
  if(a-b+c-d==7){
    cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<'='<<7<<endl; 
    exit(0);
  }
  if(a-b-c-d==7){
    cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<'='<<7<<endl; 
    exit(0);
  }
}

Measured memory_bytes: 256
s = [int(s) for s in list(input())]

odd = sum(s[::2])
even = sum(s[1::2])
if even >= odd:
    ans = len(s)//2-even+odd
elif len(s) % 2 == 1:
    ans = len(s)//2-odd+even+1
else:
    ans = len(s)//2-odd+even
print(ans)


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

using namespace std;

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

    int ans = 0;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] != s[s.length() - 1 - i]) ans++;
    }
    cout << ans / 2 << endl;
    return 0;
}


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

#define chmin(x, y) x = min(x, y)

// 入力
int n;
vector<long long> a;
// dp[left][right] := 区間 [left,right) におけるコストの最小値
vector<vector<long long>> dp(405, vector<long long>(405, -1));
// スライムの大きさの累積和
long long S[405];

// メモ化再帰
long long memo_rec(int left, int right){
    if(dp[left][right] != -1)   return dp[left][right];
    if(right - left == 1)   return dp[left][right] = a[left];
    if(right - left < 1)    return 0;   // これは必要なわけではない

    long long res = numeric_limits<long long>::max();
    for(int pos = left + 1; pos < right; ++pos){
        long long tmp = 0;
        if(pos - left > 1)  tmp += memo_rec(left, pos) + S[pos] - S[left];
        else    tmp += memo_rec(left, pos);
        if(right - pos > 1) tmp += memo_rec(pos, right) + S[right] - S[pos];
        else    tmp += memo_rec(pos, right);
        chmin(res, tmp);
    }
    return dp[left][right] = res;
}

int main(){
    cin >> n;
    a.resize(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        S[i+1] = S[i] + a[i];
    }
    cout << memo_rec(0, n) << endl;
}

Measured memory_bytes: 4952
#include <iostream>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

int main(){
  int n;
  int p;
  int a[100];
  int b[100];
  int flag = 0;
  int i = 0;
  int pp;
  while(cin >> n >> p){
    pp = p;
    for(int j = 0;j < n;j++){
      a[j] = 0;
    }
    i = 0;
    flag = 0;
    if(n == 0 && p == 0){
      break;
    }
    while(flag == 0){
      if(p > 0){
        a[i] += 1;
        p -= 1;
      }else{
        p = a[i];
        a[i] = 0;
      }
      if(a[i] == pp){
        cout << i << endl;
        flag = 1;
      }
      i++;
      if(i == n){
        i = 0;
      }
    }
  }
}
  

Measured memory_bytes: 3080
import java.util.Map.Entry;
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int n = sc.nextInt();
		long ans = 0;
		for(int i = 0; i <= 262144; i++){//19682; i++){
			int a = i;
			StringBuilder S = new StringBuilder();
			int num0 = 0;
			int num1 = 0;
			int num2 = 0;
			int num3 = 0;
			while(true){
				if(a%4 == 1){
					num1++;
					S.append(3);
				}else if(a%4 == 2){
					num2++;
					S.append(5);
				}
				else if(a%4 == 3){
					num3++;
					S.append(7);
				}else{
					num0++;
					S.append(0);
				}
				if(a / 4 == 0) break;
				a /= 4;
			}
			
			if(num0 >= 1) continue;
			if(num1 == 0 || num2 == 0 || num3 == 0) continue;
			S.reverse();
			//System.out.println(i + " " + S + " " + num1 + " " + num2 + " " + num3);
			if(Integer.parseInt(S.toString()) > n) continue;
			ans++;
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}


Measured memory_bytes: 40180
#!usr/bin/env python3

import sys


def main():
    w = sys.stdin.readline().lower().strip('\n')
    s = 0

    for line in sys.stdin:
        if line == 'END_OF_TEXT':
            break
        s += line.lower().split().count(w)

    print(s)


if __name__ == '__main__':
    main()

Measured memory_bytes: 7356
#include <stdio.h>
#include <string.h>
int main(){
  char s[10];
  scanf("%s",s);
  int c[10],cc=0;
  int ccc=0;
  int i=0;
  for(i=0;i<strlen(s);i++){
  	if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C'){
      c[i]=1;
      while(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C'){
        i++;
        cc++;
      }
      ccc=(ccc<=cc)?cc:ccc;
      cc=0;
  	}else{
      c[i]=0;
    }
  }
  printf("%d",ccc);
  return 0;
}

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

#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}

namespace roll{
    using H = __int128;
    constexpr H mod = 5559077746424707ll;
                     //0123456789
    constexpr H p[] = {14414443,
                       1000000007,
                       90001};
    constexpr int MX = 1123456;
    H hs[3][MX];
    H rh[3][MX];
    template<int m = 1>
    void build(const string s){
        const int n = s.size();
        REP(i,m){
            hs[i][0] = 0;
            rh[i][0] = 1;
            REP(i,m)REP(j,n){
                hs[i][j+1] = (hs[i][j]*p[i] + s[j])%mod;
                rh[i][j+1] = (rh[i][j]*p[i])%mod;
            }
        }
    }
    template<int m = 1>
    H get(const int l,const int r){
        H ret = 0;
        REP(i,m){
            ret ^= (mod+hs[i][r] - hs[i][l] * rh[i][r-l]%mod)%mod;
        }
        return ret;
    }
}
typedef roll::H H;
int n,m;
int main(){
    string s,t;
    cin>>s>>t;
    n=s.size();
    m=t.size();
    roll::build(t);
    H base = roll::get(0,m);
    roll::build(s);
    LL ret=0;
    map<H,int> memo;
    REP(i,n-m+1){
        H x =(roll::mod+roll::get(i,i+m)-base)%roll::mod;
        //DEBUG cout<<(LL)x<<endl;
        memo[x]++;
    }
    string u(m,'b'-'a');
    roll::build(u);
    REP(i,m){
        int pos = m-i-1;
        H diff =(roll::mod +roll::get(0,pos+1) - roll::get(0,pos))%roll::mod;
        FOR(k,'a','z'+1)if(k!=t[i]){
            H td = (roll::mod+diff*k%roll::mod-diff*t[i]%roll::mod)%roll::mod;
            //DEBUG cout<<(char)(k)<<(char)(t[i])<<" "<<(LL)(td)<<endl;

            if(memo.count(td)){
                ret+=memo[td];
            }
        }
        FOR(k,'A','Z'+1)if(k!=t[i]){
            H td = (roll::mod+diff*k%roll::mod-diff*t[i]%roll::mod)%roll::mod;
                        
            if(memo.count(td)){
                ret+=memo[td];
            }
        }

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

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

using namespace std;

struct UnionFind {
  UnionFind(int32_t n)
      : parent(vector<int32_t>(n, 0)), size(vector<int32_t>(n, 0)) {
    for (int i = 0; i < n; i++) {
      parent[i] = i;
      size[i] = 1;
    }
  }

  int32_t Root(int32_t a) {
    if (parent[a] == a) {
      return a;
    } else {
      return parent[a] = Root(parent[a]);
    }
  }

  bool IsSame(int32_t a, int32_t b) { return Root(a) == Root(b); }

  void Unite(int32_t a, int32_t b) {
    a = Root(a);
    b = Root(b);

    if (a == b) return;

    if (size[a] > size[b]) {
      parent[b] = a;
      size[a] += size[b];
      size[b] = 0;
    } else {
      parent[a] = b;
      size[b] += size[a];
      size[a] = 0;
    }
  }

  int32_t Size(int a) { return size[Root(a)]; }

  vector<int32_t> parent;
  vector<int32_t> size;
};  // struct UnionFind

UnionFind u1(200010), u2(200010);

int main() {
  int N, K, L;
  cin >> N >> K >> L;
  for (int i = 0; i < K; i++) {
    int p, q;
    cin >> p >> q;
    p--;
    q--;
    u1.Unite(p, q);
  }
  for (int i = 0; i < L; i++) {
    int p, q;
    cin >> p >> q;
    p--;
    q--;
    u2.Unite(p, q);
  }

  unordered_map<int64_t, int> counts;
  for (int v = 0; v < N; v++) {
    int64_t h = (int64_t)u1.Root(v) << 32 | (int64_t)u2.Root(v);
    counts[h]++;
  }
  for (int v = 0; v < N; v++) {
    int64_t h = (int64_t)u1.Root(v) << 32 | (int64_t)u2.Root(v);
    printf("%d%c", counts[h], (v != N - 1) ? ' ' : '\n');
  }

  return 0;
}


Measured memory_bytes: 11464
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()

    for a in range(1, 3500):
        for b in range(a, 3500):
            t1 = N * a * b
            t2 = 4 * a * b - N * (a + b)
            if t2 == 0:
                continue
            else:
                c = t1 / t2
                if c.is_integer() and 1 <= c and c <= 3500:
                    print(a, b, int(c))
                    exit()


if __name__ == '__main__':
    main()


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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 1e9 + 7;
const ll MAXN = (ll) 2e5 + 10;
const ll INF = (ll) 2242545357980376863;
const ld EPS = (ld) 1e-8;

vector<ll> V;
ll mn[MAXN];


int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	memset(mn, 31, sizeof mn);
	ll H, W, n;
	cin >> H >> W >> n;
	ll x, y;
	for(int i = 0;i<n;i++){
		cin >> x >> y;
		mn[x] = min(mn[x], y);
	}
	mn[H+1] = 0;
	x = 1;
	y = 1;
	ll ans = 0;
	while(true){
		//debug(x); debug(y);
		ans ++;
		x++;
		if(mn[x] <= y) break;
		if(mn[x] > y + 1) y++;
	}
	cout << ans;
	return 0;
}


/*
                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/



Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <numeric>
#include <type_traits>
#include <limits>
#include <random>

using namespace std;

using ll = long long;

#define rep(i,N) for(long long i = 0;i < (long long)N; ++i)

int N, ans;

int dfs(int n) {
	if (n > N) return 0;
	bool flag[3] = { false, false, false };
	string str = to_string(n);
	rep(i, str.length()) {
		if (str[i] == '3') flag[0] = true;
		if (str[i] == '5') flag[1] = true;
		if (str[i] == '7') flag[2] = true;
	}
	if (flag[0] && flag[1] && flag[2]) { 
		ans++;
	}

	if (n <= 100000000 && n <= N) {
		dfs(n * 10 + 3);
		dfs(n * 10 + 5);
		dfs(n * 10 + 7);
	}
	return 0;
}


int main() {
	cin >> N;
	dfs(0);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    long long ans=0;
    cin>>n;
    for(int i=0; i<=n; i++)
    {
        if(i%3!=0 && i%5!=0)
        {
            ans+=i;
        }

    }
     cout<<ans<<endl;
}


Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;

int main(void) {
	int n;
	int t[1001], a[1001];
	long long int p, q;
	long long int w, e;

	cin >> n;
	FOR(i, 1, n) {
		cin >> t[i] >> a[i];
	}
	p = t[1];
	q = a[1];

	FOR(i, 2, n) {
		if (p%t[i] == 0) {
			w = p / t[i];
		}
		else {
			w = p / t[i] + 1;
		}
		if (q%a[i] == 0) {
			e = q / a[i];
		}
		else {
			e = q / a[i] + 1;
		}
		w = max(w, e);
		p = t[i] * w;
		q = a[i] * w;
	}

	cout << p + q << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin >> N >> M;
  int n=0;
  for (int i=0;i<M;i++){
    cin >> n;
    N -= n;
  }
  if (N < 0){
    cout << -1 << endl;
  }
  else{
    cout << N << endl;
  }
}

Measured memory_bytes: 3584