akhauriyash/Code-Regression huggingface dataset:
class UnionFind:
    def __init__(self, n):
        self.par = list(range(n + 1))
        self.size = [1] * (n + 1)

    def root(self, x: int) -> int:
        if self.par[x] == x: return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]

    def unite(self, x: int, y: int):
        root_x, root_y = self.root(x), self.root(y)
        if root_x != root_y:
            if self.size[root_x] < self.size[root_y]:
                root_x, root_y = root_y, root_x
            self.size[root_x] += self.size[root_y]
            self.par[root_y] = root_x

    def check(self, x: int, y: int) -> bool:
        root_x, root_y = self.root(x), self.root(y)
        return root_x == root_y


from collections import defaultdict
N, M, K = map(int, input().split())

u = UnionFind(N)

ABm = defaultdict(list)
for _ in range(M):
    a, b = map(int, input().split())
    ABm[a].append(b)
    ABm[b].append(a)
    u.unite(a, b)

CDk = defaultdict(list)
for _ in range(K):
    c, d = map(int, input().split())
    CDk[c].append(d)
    CDk[d].append(c)

ans = []
for i in range(1, N + 1):
    size = u.size[u.root(i)]
    block = 0
    for x in CDk[i]:
        if u.check(x, i): block += 1

    friends = len(ABm[i])
    res = size - block - friends - 1
    ans.append(str(res))

print(" ".join(ans))

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

#define ll long long
#define vi vector<int>
  
using namespace std;                           

int h, n, a[100001], cnt;

int main (){
	cin >> h >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i++){
		cnt+= a[i];
	}
	if(cnt >= h){
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;
const long double PI = (acos(-1));
const ull MOD = 1000000007;


struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> H(N);
    for(int i = 0; i < N; i++) cin >> H[i];
    vector<int> dp(N);
    dp[0] = 0;
    dp[1] = abs(H[1] - H[0]);
    for(int i = 2; i < N; i++){
        int min_n = I_INF;
        for(int j = max(i - K, 0); j < i; j++){
            min_n = min(min_n, abs(H[i] - H[j]) + dp[j]);
        }
        dp[i] = min_n;
    }
    cout << dp.back() << endl;
}

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

int main(){
  int N;
  int count;
  int res;
  cin >> N;

  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  do{
    sort(A.begin(), A.end(),greater<int>());
    while(A[A.size()-1]==0){
      A.pop_back();
    }
    res = A[A.size()-1];
    for(int i=0;i<A.size()-1;i++){
      A[i] = A[i] % res;
    }
  }while(A.size()>1);
  cout << res << endl;
  return 0;
}


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

int main(){
    int a,b,c,d;
    cin >>a>>b>>c>>d;
    int t,o;
    t=(c+b-1)/b;
    o=(a+d-1)/d;
    if(t<=o){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h> 
  
using namespace std; 
typedef long long ll;
 
int main()
{
  
    ll t=1,l;
     // cin>>t;
     l = t;

    while(t--)
    {
       ll x,a,b;
       cin>>x;
       ll ci=100,i=1;
       while(ci<x)
       {
       ci = ci * (pow((1 + .01 ), 1));
       i++;
        }

        cout<<i-1<<endl;
    }
  return 0;
}



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

int main() {
    string S;
    cin >> S;
    
    int plus = 0;
    for (int i=0; i<3; i++) {
        if (S[i] == 'o') plus++;
    }
    
    cout << 700 + plus*100 << endl;
    
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    int a = 0;
    int b = 0;
    int both = 0;
    int base = 0;
    rep(i, n)
    {
        rep(j, 1, s[i].size())
        {
            if (s[i][j - 1] == 'A' && s[i][j] == 'B')
            {
                base++;
            }
        }
        if (s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A')
        {
            both++;
        }
        else if (s[i][0] == 'B')
        {
            b++;
        }
        else if (s[i][s[i].size() - 1] == 'A')
        {
            a++;
        }
    }
    cerr << a << "," << b << "," << both << "," << base << endl;
    ll ans = 0;
    ans += base;
    if (both == 0)
    {
        ans += min(a, b);
    }
    else
    {
        if (a + b > 0)
        {
            ans += min(a, b) + both;
        }
        else
        {
            ans += both - 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAXSIZE 10000000;

bool comp(const pair<string,int> a, const pair<string,int> b) {
  if (a.first != b.first)
    return a.first < b.first; // 高い順に並べたいので演算子を逆に
  else{
      return a.second > b.second;
  }
}

int Dx[6] = { 0, 0, 1, 1,-1,-1};
int Dy[6] = { 1,-1, 1, 0, 0,-1};

//priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
//priority_queue<long long int> PQ1;
int main(){

  long long int A,B,C,D,r,seki,oriC,oriD;

  cin >>A>>B>>C>>D;

  seki = C*D;
  oriC = C;
  oriD = D;

  if( C < D){
    long long int temp;
    temp = C;
    C = D;
    D = temp;
  }
  r = C % D;
  while(r!=0){
    C = D;
    D = r;
    r = C % D;
  }

  cout << (B) - ((B)/oriC + (B)/oriD - (B)/(seki/D)) - ((A-1) - ((A-1)/oriC + (A-1)/oriD - (A-1)/(seki/D)))<<endl;
  return 0;
}

/*Syakutori
while(cin >>b && b)){
      ll t = 1;
      long long int ansS = 1,ansT=0;
      long long int sum = 0;

      for(ll s = 1;s < 50000000;s++){

        while(t <  50000000 && sum+Rsum[t] < b){
          sum += Rsum[t];
          t++;
        }
        if(b == sum+Rsum[t]){
          if(ansT - ansS < t-s){
            ansS = s;
            ansT = t;
          }
          cout <<ansS<<" "<<ansT-ansS + 1<<endl;
          break;
        }
        if(t == s)++t;
        else sum -= Rsum[s];
        }
    }

*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll> >
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define prll(a)                 cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,cur)               lower_bound(all(v),cur)-v.begin()
#define ub(v,cur)               upper_bound(all(v),cur)-v.begin()
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
long long pows(long long a, long long b) {
  long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m=MOD){return powm(a,m-2,m);}
int main()
{
fastIO
ll n,m,i,j,k,x,y,z,t,e,f,p,q,g,l,r,o,w,h,count1=0,prod=1,a,b,c,d,index,x1,x2,y1,y2,diff,ans=0,sum=0,sum1=0,sum2=0,flag=0,flag1=0,flag2=0;
string s,s1,s2;
cin>>n;
for(i=1;i<=1000000;i++)
{
  for(j=1;j<=1000000;j++)
  {
    if(i*j<n)
    {
      ans++;
    }
    else
    {
      break;
    }
  }
}
cout<<ans;
}


Measured memory_bytes: 3648
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    public function next()
    {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(" ", $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }

    public function hasNext()
    {
        return $this->pointer < $this->count;
    }

    public function nextInt()
    {
        return (int)$this->next();
    }

    public function nextDouble()
    {
        return (double)$this->next();
    }
}

class out
{
    public static function printIn($str = "")
    {
        echo $str . PHP_EOL;
    }
}

$sc = new Scanner;

$N = $sc->nextInt();
$L = $sc->nextInt();
$S = [];
for ($i = 0;$i < $N; $i++) {
    $S[] = $sc->next();
}

sort($S);
foreach ($S as $text) {
    echo $text;
}

Measured memory_bytes: 4728
#include <iostream>

using namespace std;

int main() {
    int z,x,c,v;
    cin>>z>>x>>c;
    v=x*z;
    if(v>c){
        cout<<c<<"\n";
    }
    else if(c>v){
        cout<<v<<"\n";
    }
    else{
        cout<<c<<"\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N; cin>>N;
  vector<int>A(N);
  vector<long long>B(N);
  for(int i=0;i<N;i++){cin>>A[i];B[i]=A[i]+(i!=0? B[i-1]:0);}
  long long ans=100000000000000;
  for(int i=0;i<N-1;i++)ans=min(ans,abs(B[i]*2-B[N-1]));
  cout<<ans<<endl;
}

Measured memory_bytes: 5632
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s,t;
    getline(cin,s);
    getline(cin,t);
    int n = s.size();
    int ans = 0;
    for(int i=0;i<n;++i)
    {
        if(s[i]!=t[i])

            ++ans;

    }
    cout << ans << endl;

}


Measured memory_bytes: 3860
-- C
local N = io.read("n")
local INF=N+1
local capa = {}
for i=1,5 do
    capa[i] = io.read("n")
end
-- which edge is bottleneck?
local bn_i = 0
local bn_capa = INF
for i=1,#capa do
    if capa[i] < bn_capa then
        bn_capa = capa[i]
        bn_i = i
    end
end
if bn_capa == INF then
    print(5)
    return
end
local ans
ans = N // bn_capa
if N % bn_capa ~= 0 then
    ans = ans + 1
end
ans = ans + bn_i - 1
ans = ans + 5 - bn_i
print(ans)


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

using namespace std;

#define ll long long
#define ar array



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

	int l,r;
	cin >> l >> r;
	int d;
	cin >> d;
	int ans = 0;
	for(;l<=r;l++){
		if(l%d==0) ans++;
	}	
	cout << ans;
	return 0;
}


Measured memory_bytes: 3544
s = list(input())
#key =s.copy()
#print(s)
a = []
#count = 0

for i in s:
 # print(s)
  if i == 'B' and s.index(i) == 0:
    a = a[:-1]
  elif i == 'B':
    a = a[:-1]
    #del a[-1]
  else:
    a.append(i)
  
    
print(''.join(a))    
    

Measured memory_bytes: 2940
#include <bits/stdc++.h>
 
 
using namespace std;
 
#define re return
#define sz(a) (int)a.size()
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define re return
#define forn(i, n) for (int i = 0; i < int(n); i++)
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef long double ld;
typedef unsigned long long ull;
const ll mod = int(1e9) + 7;
const int ma = 1024 * 1024;

ll n;
vector<ll> a;

int main() {
    iostream::sync_with_stdio(0), cin.tie(0);
    cin >> n;
    ll k = 0;
    bool ok = true;
    while (n >= 10) {
        if (n % 10 < 9) ok = false;
        k += 9;
        n /= 10;
    }
    k += n;
    if (!ok) k--;
    cout << k;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    /* チェックリスト
     * 結果はintの範囲を超えていませんか？(必要な時以外はlongを使いましょう)
     * TLEしそうな処理はありませんか？
     */
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String current = sc.nextLine();
        if(current.equalsIgnoreCase("sunny")){
            System.out.println("Cloudy");
        }else if(current.equalsIgnoreCase("cloudy")){
            System.out.println("Rainy");
        }else if(current.equalsIgnoreCase("rainy")){
            System.out.println("Sunny");
        }
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int k,n,mx=0;
	cin>>n>>k;
	int p[n],sum[n]={};
	for(int i=0;i<n;i++)
	{
		cin>>p[i];
		if(i>0) sum[i]+=(sum[i-1]+p[i]);
			else sum[i]=p[i];
	}
	for(int i=0;i<n-k;i++)
	{
		mx=max(mx,sum[i+k]-sum[i]);
	}
	if(k!=n)
cout<<fixed<<setprecision(10)<<((mx+k)/2.0);
	else cout<<fixed<<setprecision(10)<<(sum[n-1]+k)/2.0;


	return 0;
}

Measured memory_bytes: 1792
N = int(input())
A = [int(input()) for _ in range(N)]

t = [A[0]]
for a in A[1:]:
    if t[-1] >= a:
        t.append(a)
        continue
    ok = len(t) - 1
    ng = -1
    while ok - ng > 1:
        m = (ok + ng) // 2
        if t[m] < a:
            ok = m
        else:
            ng = m
    t[ok] = a
print(len(t))


Measured memory_bytes: 8604
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; ++i)

int main() {
    ll max = 1e18;
    ll sum = 1;
    int n; cin >> n;
    bool fl = false;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) {
        if (a[i]==0) {
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i, n) {
        if (max/sum < a[i]) {
            cout << -1 << endl;
            return 0;
        }
        sum *= a[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

int main(){
  int n,f[10][100], p[11][100];cin>>n;rep(i,n)rep(j,10)cin>>f[j][i];rep(i,n)rep(j,11)cin>>p[j][i];
  int ans = -1000000000;
  rep(i,1<<10){
    int fs[100];rep(j,100)fs[j] = 0;
    int count = 0;
    rep(j,10){
      if(i & (1<<j)){
        count++;
        rep(k,n){
          if(f[j][k]){
            fs[k]++;
          }
        }
      }
    }
    if(count == 0)continue;
    int r = 0;
    rep(i,n){
      r += p[fs[i]][i];
    }
    ans = max(ans, r);
  }
  cout << ans << endl;
}




Measured memory_bytes: 256
#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) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
using Graph = vector<vector<int>>;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"yes"<<endl ;
}
void no(){
  cout <<"no"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m ;
  cin >> n >> m ;
  vint seen(n,0) ;
  vector<queue<int>> gra(n) ;
  stack<int> S ;
  REP(i,m){
    int a, b ;
    cin >>a >> b ;
    gra[a].push(b) ;
    gra[b].push(a) ;
  }
  
  int cnt = 1 ;
  vint num(n,0) ;
  
  S.push(0) ;
  seen[0] = 1 ;
  num[0] = cnt ;
  
  while(!S.empty()){
    int k = S.top() ;
    
    while(1){
      if(gra[k].empty()){
        S.pop() ;
        break ;
      }
      int l = gra[k].front() ;
      if(seen[l]==1){
        gra[k].pop() ;
        continue ;
      }
      else{
        S.push(l) ;
        gra[k].pop() ;
        seen[l] = 1 ;
        num[l] = num[k] ;
        break ;
      }
    }
    
    if(S.empty()){
      REP(i,n){
        if(seen[i]==0){
          S.push(i) ;
          seen[i] = 1 ;
          cnt++ ;
          num[i] = cnt ;
          break ;
        }
      }
    }
  }
  
  int q ;
  cin >> q ;
  REP(i,q){
    int x, y ;
    cin >> x >> y ;
    if(num[x]==num[y]){
      yes() ;
    }
    else{
      no() ;
    }
  }
  
  

  return 0 ;
}




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

using namespace std;

typedef long long ll;

#define newline cout<<"\n"
#define deb(x) cout<<#x<<" "<<x<<endl;

template<typename... T>
void read(T&... args){
    ((cin>>args), ...);
}

template<typename... T>
void write(T... args){
    ((cout<<args<<" "), ...);
}

void printarr(vector<int> &v){
    for(int x: v){
        cout<<x<<" ";
    }
    newline;
}

const int MOD = 1e9+7;
const int nax = 1e7+7;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    int x; cin>>x;
    if(x>=30){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
    
    return 0;
}

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

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

#define pb push_back
#define mp make_pair

#define bg begin()
#define en end()
#define sz size()
#define skip continue
#define all(x) (x).bg, (x),en

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e6 + 17, maxN = 4 * N, D = 1e3 + 17, mod = 1e9 + 7;

int n;
ll a[N], ans, ct;

vector <ll> v[N];

int main() { 
	jyldam;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
    	cin >> a[i];
    	if (!a[i]) {
    		ct++;
    		skip;
    	}
    	v[ct].pb(a[i]);
    }
    for (int i = 0; i <= ct; i++) {
    	ll sum = 0;                  
       	for (auto to : v[i]) {
			sum += to;
    	}    
       	ans += sum / 2;
    }
    cout << ans;        
   	return 0;
}

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

class Main {
	public static void main(String[] $) {
		new Main().run();
	}
	
	int[] p=new int[200000];
	{
		Arrays.fill(p, -1);
	}
	
	int root(int x) {
		return p[x]<0?x:(p[x]=root(p[x]));
	}
	
	void unite(int x,int y) {
		x=root(x);y=root(y);
		if (x!=y) p[x]=y;
	}
	
	boolean equiv(int x,int y) {
		return root(x)==root(y);
	}
	
	void run() {
		var sc=new Scanner(System.in);
		int N=sc.nextInt();
		int Q=sc.nextInt();
		var pw=new PrintWriter(System.out);
		while (Q-->0) {
			int t=sc.nextInt();
			int u=sc.nextInt();
			int v=sc.nextInt();
			if (t==0) unite(u,v);
			else pw.println(equiv(u,v)?1:0);
		}
		pw.flush();
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}


Measured memory_bytes: 60232
#include <stdio.h>
int main(void){


int   r,c,i,j;
static int s[101][101];

scanf("%d%d",&r,&c);

for(i=0;i<=r;i++){
for(j=0;j<c;j++){

scanf("%d", &s[i][j]);

printf("%d ", s[i][j]);
s[i][c] += s[i][j];
s[r][j] += s[i][j];
}

printf("%d\n",s[i][c]);
}



return 0;
}


Measured memory_bytes: 2128
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = mod*mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

int main() {

	ll a, b, c; cin >> a >> b >> c;
	rep(i, 100001) {
		if (a % 2 || b % 2 || c % 2) {
			cout << i << endl; return 0;
		}
		ll d = a / 2, e = b / 2, f = c / 2;
		a = e + f; b = d + f; c = d + e;
	}
	cout << -1 << endl;
	//stop
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include<algorithm>
using namespace std;

int main()
{
    int n,m,X,Y;
    int maxx=-110,my=110;
    cin >> n>>m>>X>>Y;
    int x[n],y[m];
    rep(i,n){
        cin>> x[i];
        maxx=max(maxx,x[i]);
    }
    rep (i,m){
        cin >> y[i];
        my=min(my,y[i]) ;
    }
    maxx=maxx<X?X:maxx;
    my=my>Y?Y:my;
    if(maxx<my){
        cout << "No War";
    }
    else {
        cout << "War";
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#include<cstring>
#include <stack>
#include <numeric>
#include<climits>
#include<cmath>
#include<set>
#include<unordered_set>
#include<iomanip>
#include<queue>
#include<unordered_map>
#define vi vector<float>
#define vl vector<long long>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define loop(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<float,float>
#define umap unordered_map<ll,float>
using namespace std;

#define xx first
#define yy second

bool check(string s, int i, int j) {
	string r = s.substr(i - 1, j - i + 1);
	//cout << r << endl;
	string rev = r;
	reverse(all(rev));

	if (r == rev) {
		return true;
	}

	return false;
}

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

// #ifndef ONLINE_JUDGE
// 	freopen("in.txt", "r", stdin);
// 	freopen("out.txt", "w", stdout);
// #endif

	string s;
	cin >> s;
	int n = s.length();
	string r = s;
	reverse(all(r));

	if (r == s && check(s, 1, (n - 1) / 2) && check(s, (n + 3) / 2, n)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}







	return 0;
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

struct UnionFind {
    private:
    vector<int> par,rank;
    vector<ll> size;
    public:
    UnionFind(int N){
        par.resize(N);
        rank.resize(N,0);
        size.resize(N,1);
        for (int i=0;i<N;i++){
            par[i]=i;
        }
    }
    int root(int x){
        if (par[x]==x){
            return x;
        }
        return par[x]=root(par[x]);
    }
    bool merge(int x, int y){
        x=root(x);
        y=root(y);
        if (x==y){
            return false;
        }
        if (rank[x]<rank[y]){
            swap(x,y);
        }
        if (rank[x]==rank[y]){
            ++rank[x];
        }
        par[y]=x;
        size[x]+=size[y];
        return true;
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    ll Size(int x){
        return size[root(x)];
    }
};

const ll MAX=110000;

int main(){
    ll N;
    cin >> N;
    UnionFind uf(2*MAX);
    rep(i,N){
        int x,y;
        cin >> x >> y;
        uf.merge(x,y+MAX);
    }
    map<int,ll> mx,my;
    rep(i,MAX){
        mx[uf.root(i)]++;
    }
    rep2(i,MAX,2*MAX){
        my[uf.root(i)]++;
    }
    ll ans=0;
    rep(i,2*MAX){
        ans+=mx[i]*my[i];
    }
    cout << ans-N << endl;
}


Measured memory_bytes: 31232
N,M = [int(i) for i in input().split()]
k = max(N,M)
l = min(N,M)
N = k
M = l
mod = 10**9+7
def frac(N):
    ans = 1
    ans1 = 1
    ans2 = 1
    ans3 = 1
    for i in range(2,N+1):
        if i % 3 == 0:
            ans1 *=i
            ans1 %= mod
        if i % 3 == 1:
            ans2 *=i
            ans2 %= mod
        if i % 3 == 2:
            ans3 *=i
            ans3 %= mod
    ans = ans1*ans2*ans3 % mod
    return ans
if N - M > 1:
    print(0)
    exit()
if N == M:
    F = frac(N)
    f = F * F % mod
    print((2*f) % mod)
    exit()
if N == M+1:
    F1 = frac(M)
    F2 = frac(N)
    print((F1*F2) % mod)
    exit()

Measured memory_bytes: 3064
#pragma GCC optimize(2)
#pragma GCC optimize(3)   
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector < ll > vl;
typedef vector < vl > vvl;
typedef pair < ll, ll > pll;
typedef vector < pair < ll, ll > > vpll;
#define kill freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define all(c) c.begin(), c.end()
#define go(c,it) for(auto it=(c).begin(); it!=(c).end(); it++)
#define back(c,it) for(auto it=(c).rbegin(); it!=(c).rend(); it++)
#define fi first
#define se second
#define MOD 998244353
#define Boost() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MOD1 1000000007
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;}a=(a*a)%MOD;b>>=1;}return res;}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
#define oo LLONG_MAX
const ll N = 1e5;

void solve(){
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++){
        ll ans = 0;
        for(ll x = 1;x<=100;x++){
            for(ll y=1;y<=100;y++){
                ll c = (x*x)+(y*y)+(x*y)-i;
                ll b = x+y;
                ll det = (b*b)-(c*4LL);
                ll val = sqrt(det);
                if(det<0||(val*val!=det))continue;
                ll z = -b+val;
                if(z>0&&z%2==0){
                    z/=2LL;
                    if(z>0)ans++;
                }
                z = -b-val;
                if(z>0&&z%2==0){
                    z/=2LL;
                    if(z>0)ans++;
                }
            }
        }
        cout<<ans<<"\n";
    }
}

int main(){
    Boost();
    #ifndef ONLINE_JUDGE 
    kill
    #endif
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
 
 
 
 
 

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

#define MAX 10

int N;
int  p[MAX];

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

	sort( p, p + N );
	int ans = p[N - 1] / 2;
	for( int i = 0; i < N - 1; i++ ) {
		ans += p[i];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
  int n;
  string s,t,a;
  cin>>n>>s>>t;
  for(int i=0;i<n;i++)
  {
    a=a+s[i];
    a=a+t[i];
  }
  cout<<a;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
//		String s = sc.next();
		int n = sc.nextInt();
		int r = sc.nextInt();

		List<Integer> numList = new ArrayList<>();
		List<Long> ansList = new ArrayList<>();

		if(n >= 10) {
			System.out.println(r);
		}else {
			System.out.println(r+100*(10-n));
		}


	}
}


Measured memory_bytes: 21844
let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let ue = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  let shita = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  for i = 1 to n - 1 do
    ue.(i) <- ue.(i) + ue.(i - 1)
  done;
  for i = n - 2 downto 0 do
    shita.(i) <- shita.(i) + shita.(i + 1)
  done;
  Array.init n (fun i -> ue.(i) + shita.(i))
  |> Array.fold_left max 0
  |> Printf.printf "%d\n"

Measured memory_bytes: 512
# abc166 B
n, k = gets.split.map(&:to_i)
a = []

sn = Array.new(n, 0)

k.times  {
  d = gets.to_i
  a << gets.split.map(&:to_i)
}


a.each do |aa|
  aa.each do |x|
    sn[x-1] += 1
  end
end

p sn.count(&:zero?)


Measured memory_bytes: 14364
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<int> q;
    rep(i,n){
        int a;
        cin >> a;
        q.push(a);
    }
    rep(i,m){
        int a = q.top(); q.pop();
        q.push(a/2);
    }
    ll ans = 0;
    rep(i,n){
        ans += q.top(); q.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 3932
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 07/03/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  long long N,A,B; cin>>N>>A>>B;
  auto apb = A+B;
  auto cnt = N/apb;
  auto mod = N%apb;
  long long ans = A*cnt + min(mod, A);
  cout << ans << endl;

  return 0;
}


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

#define vi vector<int>
#define vl vector<long long>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define INF 1e18
#define INFTY 1e9
#define MOD 1e9+7
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

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

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

struct edge {int to, cost;};
vector< vector<edge> > es;
const int MAX_N = 100010;
const int MAX_M = 200010;
int N, M;
int d[MAX_N];
vector< vector <edge> > G;
vector<int> mark;

void dijkstra(int s) {
    priority_queue< P, vector<P>, greater<P> > que;
    d[s] = 0;
    que.push(P(0, s)); //Pには(d[s], s)が入っている
    
    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue; //以前qに入れたノードuのd[u]がuに来る前に更新されてる可能性あり(uが別々のd[u]で同時に複数qにあるかも)
        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                mark[e.to] = v;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}
int main() {
    cin >> N >> M;
    mark.resize(N);
    G.resize(N);
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        G[a].push_back(edge{b, 1});
        G[b].push_back(edge{a, 1});
    }
    REP(i, N) {
        mark[i] = -1;
        d[i] = INF;
    }
    d[0] = 0;
    mark[0] = 0;
    dijkstra(0);
    REP(i, N) {
        if (mark[i] == -1) {
        cout << "No" << endl;
        return 0;
        }
    }
    cout << "Yes" << endl;
    FOR(i, 1, N) {
        cout << mark[i]+1 << endl; 
    }
    return 0;
}

Measured memory_bytes: 13492
<?php

fscanf(STDIN, '%d', $n);

$count = 0;
foreach (range(1, $n, 2) as $num) {
    $mod0 = 0;
    foreach (range(1, $num) as $num2) {
        if ($num % $num2 === 0) {
            $mod0++;
        }
    }
    if ($mod0 === 8) {
        $count++;
    }
}
echo $count."\n";

Measured memory_bytes: 4856
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
//typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;

const int MOD=1000000007;

int main()
{
	string s;
	cin>>s;
	s[3]='8';
	cout<<s<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define in(s) ll s; cin >> s
#define pr(r) cout << r << endl
#define prr(m,n) cout<<m<<" "<<n<<endl
#define prarr(a,i,n) fab(j,i,n) cout << a[j] << " "
#define wh(t) ll t; cin >> t; while(t--)
#define sz(u) u.size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define arr(a,n) vl a(n, 0); fab(i, 0, n) cin >> a[i]
#define prs(u) cout << u << " "
#define fab(i,a,b) for(ll i = a; i < b; i++)
#define fba(i,b,a) for(ll i = b; i >= a; i--)
#define fa(i, x) for(auto i: x)
#define mem(s, j) memset(s, j, sizeof(s))
#define sup ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define ll long long int
#define vl vector<ll>
#define vpl vector<pl>
#define pl pair<ll, ll>
#define pll pair<ll, pl>
#define vvl vector<vl>
#define vvpl vector<vpl>
#define mxe(x) *max_element(x)
#define mne(x) *min_element(x)
#define mp make_pair
#define pb push_back
#define fs first
#define sd second
#define fr front()
#define bk back()
#define rr return
const ll N = (ll)3e5;
const ll inf = (ll)1e18 + 7;
const ll mod = (ll)1e17 + 7;
const ll MX = (ll)1e9 + 7;
const ll MAX = (ll)1e12 + 7;
 
bool rsort1(const pair<ll, ll> &a,const pair<ll, ll> &b) { return (a.first > b.first);}
bool rsort2(const pair<ll, ll> &a,const pair<ll, ll> &b) { return (a.second > b.second);}
bool sort2(const pair<ll, ll> &a,const pair<ll, ll> &b){ return (a.second < b.second);}

vector<char> dir = {'L', 'R', 'U', 'D'};
vl dx = {-1, 1, 0, 0};
vl dy = {0, 0, -1, 1};

void add(ll &x, ll y){
    x = ((x % mod) + (y % mod)) % mod;
}

void mul(ll &x, ll y){
    x = ((x % mod) * (y % mod)) % mod;
}

ll sm(vl a) {
    ll sum = 0;
    for(auto i: a)
        sum += i;
    return sum;
}

ll power(ll x, ll y) 
{ 
    if (y == 0) 
        return 1; 
    else if (y % 2 == 0) 
        return power(x, y / 2) * power(x, y / 2); 
    else
        return x * power(x, y / 2) * power(x, y / 2); 
}
 
bool isPrime(ll p)
{
    for(ll i = 2;i * i <= p; i++)
        if(p % i == 0)
            rr false;
    rr true;
}

ll isPal(string s) {
    string k = s; 
    reverse(all(k));
    if(s == k)
        return 1;
    return 0;
}

ll nCr(ll n, ll k) 
{ 
    if(n < k)
        return 0;
    vl C(k + 1, 0); 
    ll i, j; 
    C[0] = 1; 
    for (i = 1; i <= n; i++) { 
        for (j = min(i, k); j > 0; j--) { 
            add(C[j], C[j - 1]); 
        } 
    }
    return C[k] % mod; 
}

int main()
{
	sup;
    
    ll sum = 0;
    in(n);
    arr(a, n);
    map<ll, ll> ball, val, res;
    fab(i, 0, n) {
        ball[a[i]]++;
    }
    fab(i, 0, n) {
        if(val[a[i]] == 0) {
            val[a[i]] = nCr(ball[a[i]], 2);
            sum += val[a[i]];
        }
    }
    fab(i, 0, n) {
        if(res[a[i]] == 0) {
            res[a[i]] = sum - val[a[i]] + nCr(ball[a[i]] - 1, 2);
            pr(res[a[i]]);
        }
        else {
            pr(res[a[i]]);
        }
    }
    return 0;
}

Measured memory_bytes: 26880
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String str;
		str = sc.next();
		for(int i = 0; i < str.length(); i++){
			System.out.print((char)((str.charAt(i) - 'A' - 3 + 26) % 26 + 'A'));
		}
		System.out.println();
	}
}

Measured memory_bytes: 11000
#include<iostream>
#include<algorithm>
#define ll long long int

using namespace std;

main()
{
	ll a,b,c,k;
	cin>>a>>b>>c>>k;

	ll no=0;
		while(c<=b || c<=a)
	{
		c=c*2;
		k--;
			if(k<0)
		{
			no=1;break;
		}
		
	}	

	
	while(b<=a)
	{
		b=b*2;
		k--;
		if(k<0)
		{
			no=1;break;
		}
	}
	while(c<=b || c<=a)
	{
		c=c*2;
		k--;
			if(k<0)
		{
			no=1;break;
		}
		
	}	
	
	if(no==1)
		{
			cout<<"No"<<endl;
		
		
		}
		else
		cout<<"Yes"<<endl;

	

	
	
}

Measured memory_bytes: 3640
#include<cstdio>
#include<cstring>
#include<vector> 
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod= 998244353; 
int main(){

	ll n;
	scanf("%lld",&n);
	vector<ll> items(n+5,0);
	bool sign=false;
	ll maxn=0;
	for(int i=0;i<n;i++){
		ll t; 
		scanf("%lld",&t);
		maxn=max(maxn,t);
		if((i==0&&t!=0)||(i>0&&t==0)) 
			sign=true;	
		items[t]++;	
	}
	if(sign)
		printf("0");
	else{
		ll k=1;
		ll ans=1;
		
		for(ll i=1;i<=maxn;i++){
			
			for(ll j=0;j<items[i];j++){
				ans*=k ;
				ans%=mod;
			}
			k=items[i];
		}
		printf("%lld",ans);
	}
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 200005
#define ll long long
int n,a[N];
ll s[N],s0[N],sj[N],so[N],ans=0;
ll go[N],bac[N],mx1[N],mx2[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),s0[i]=s0[i-1]+(!a[i]),s[i]=s[i-1]+a[i],sj[i]=sj[i-1]+(a[i]&1),so[i]=so[i-1]+(!(a[i]&1));
	for(int i=1;i<=n;i++)bac[i]=s[i]-sj[i]-s0[i]*2;mx2[n]=bac[n];
	for(int i=n-1;i;i--)mx2[i]=max(mx2[i+1],bac[i]);
	for(int i=1;i<=n;i++)go[i]=s[i]-so[i];mx1[n]=go[n];
	for(int i=n-1;i;i--)mx1[i]=max(mx1[i+1],go[i]);
	ll now=0,pac=0,mx=-(1ll<<60);
	for(int i=1;i<=n;i++)
	{
		now+=a[i]-(!(a[i]&1));
		pac+=a[i]-(a[i]&1)-(!a[i])*2;
		now=max(now,0ll);pac=max(pac,0ll);
		mx=max(mx,pac-s[i]+so[i]);
		ans=max(mx1[i]-go[i]+pac,ans);
		ans=max(mx2[i]-bac[i]+max(now,pac),ans);
		ans=max(mx2[i]-bac[i]+s[i]-so[i]+mx,ans);
	}
	printf("%lld\n",s[n]-ans);
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;


int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
int m=n;
    int ds=0;
    while(n){
        ds+=(n%10);
        n/=10;
    }

    cout<<((m%ds)?"No":"Yes");
    
    
    
    
    
   
    
    
    return 0;
}

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

using namespace std;

int main(){

    int N, M;
    cin >> N >> M;
    vector<int> s(M);
    vector<int> c(M);

    for(int i = 0; i < M; i++){
        cin >> s[i] >> c[i];
    }

    for(int i = 0; i < 1000; i++){
        int digit = 0;
        if(i == 0){
            digit = 1;
        }
        else{
            int temp = i;
            while(temp > 0){
                digit++;
                temp /= 10;
            }
        }

        if(digit != N){
            continue;
        }

        vector<int> num(N);
        if(i == 0){
            num[0] = 0;
        }
        else{
            int temp = i;
            int index = 0;
            while(temp > 0){
                num[index] = temp % 10;
                temp /= 10;
                index++;
            }
        }

        bool isOk = true;
        for(int i = 0; i < M; i++){
            if(num[N - s[i]] != c[i]){
                isOk = false;
                break;
            }
        }
        if(isOk){
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}

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

int main(){
	// sengen
	string s,t;
	// nyuryoku
	cin >> s >> t;
	// keisan
	string sub = t.substr(0,s.size());
	if(sub == s){
		cout << "Yes";
	}else{
		cout << "No";
	}
	// syutsuryoku
}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

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

  int result = 0;
  rep(i, 4) result += S[i]=='+' ? 1 : -1;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -O #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}

import Control.Monad
import Data.List
import Data.Ord
import qualified Data.ByteString.Lazy.Char8 as B
import qualified Data.IntMap as M

readIntLL :: IO [[Int]]
readIntLL = map(unfoldr(B.readInt.B.dropWhile(==' '))).B.lines<$>B.getContents

rsort :: Ord a => [a] -> [a]
rsort = sortBy$flip compare

f :: [Int] -> [Int]
f = (flip map)[[s,g,h]|s<-[1,(-1)],g<-[1,(-1)],h<-[1,(-1)]].(sum.).zipWith(*)

main=do
    [n,m]:xyzs <- readIntLL
    print
        $ head $ rsort $ map (sum . take m . rsort)
        $ transpose $ map f $ take n xyzs


Measured memory_bytes: 2172
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
import java.util.Queue;

public class Main {

	static int N, M;
	static int[][] DATA;

	static Queue<SortByP> queueP = new PriorityQueue<SortByP>();

	static Queue<SortByIndex> queueIndex = new PriorityQueue<SortByIndex>();

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] lineArr = br.readLine().split(" ");
		N = Integer.parseInt(lineArr[0]);
		M = Integer.parseInt(lineArr[1]);

		DATA = new int[M][3];

		for (int i = 0; i < M; i++) {
			lineArr = br.readLine().split(" ");

			queueP.add(new SortByP(Integer.parseInt(lineArr[0]), Integer.parseInt(lineArr[1]), 0, i + 1));
		}

		int currentP = -1;
		int tmpOrder = 0;
		while (queueP.size() > 0) {
			SortByP sp = queueP.poll();

			if (sp.p != currentP) {
				currentP = sp.p;
				tmpOrder = 0;
			}
			tmpOrder++;

			queueIndex.add(new SortByIndex(sp.p, sp.y, tmpOrder, sp.index));
		}

		StringBuffer sb;
		while (queueIndex.size() > 0) {
			SortByIndex si = queueIndex.poll();
			sb = new StringBuffer();

			currentP = si.p;

			String strCurrentP = Integer.toString(currentP);
			int tmp = 6 - strCurrentP.length();

			for (int i = 0; i < tmp; i++) {
				sb.append("0");
			}
			sb.append(strCurrentP);

			tmpOrder = si.order;
			String strTmpOrder = Integer.toString(tmpOrder);
			tmp = 6 - strTmpOrder.length();

			for (int i = 0; i < tmp; i++) {
				sb.append("0");
			}
			sb.append(strTmpOrder);

			System.out.println(sb.toString());
		}

	}
}

class SortByP implements Comparable<SortByP> {
	int p, y, order = 0, index;

	public SortByP(int p, int y, int order, int index) {
		super();
		this.p = p;
		this.y = y;
		this.order = order;
		this.index = index;
	}

	@Override
	public int compareTo(SortByP o) {
		if (this.p - o.p != 0)
			return this.p - o.p;
		else
			return this.y - o.y;
	}

}

class SortByIndex implements Comparable<SortByIndex> {
	int p, y, order = 0, index;

	public SortByIndex(int p, int y, int order, int index) {
		super();
		this.p = p;
		this.y = y;
		this.order = order;
		this.index = index;
	}

	@Override
	public int compareTo(SortByIndex o) {
		return this.index - o.index;
	}

}

Measured memory_bytes: 76720
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define gridif(a,x,b) if((a)<=(x)&&(x)<(b))
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;

int digitsum(int n,int b){
	if(b<2) return -1;
	if(n<b) return n;
	return digitsum(n/b,b)+n%b;
}
int mpow(int a,int x);
int m_inv(int n){return mpow(n,mod-2);}

int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}

signed main(){
    string S;
    cin>>S;
    int ans=0;
    rep(i,S.size()-1) if(S[i]!=S[i+1]) ans++;
    cout<<ans<<endl;
}

int mpow(int a,int x){
	int ans=1;
	while(x>0){
		if(x%2==1) (ans*=a)%=mod;
		(a*=a)%=mod;
		x>>=1;
	}
	return ans;
}

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

using namespace std;
const int M = 1000005;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> cnt(M);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int x : a)
    {
        if (cnt[x] != 0)
        {
            cnt[x] = 2;
            continue;
        }
        for (int i = x; i < M; i += x) cnt[i]++;
    }
    int ans = 0;
    for (int x : a)
    {
        if(cnt[x] == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7988
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Objects;

public class Main {
  public static void main(String[] args ){

    Scanner sc = new Scanner(System.in);

    String S = sc.next();
    List<Character> chList = new ArrayList<Character>();
    List<Integer> intList = new ArrayList<Integer>();

    for (int i = 0; i < S.length(); i++) {
      if (chList.contains(S.charAt(i))){
        int index = chList.indexOf(S.charAt(i));
        intList.set(index, intList.get(index) + 1);
      } else {
        intList.add(1);
        chList.add(S.charAt(i));
      }
    }

    boolean flag = true;
    if (intList.size() != 2) flag = false;
    else if(intList.get(0).intValue() != 2 || intList.get(1).intValue() != 2) flag = false;

    System.out.println(flag ? "Yes" : "No");

  }
}


Measured memory_bytes: 23252