akhauriyash/Code-Regression huggingface dataset:
#coding:utf-8

"""
自分の解答。これだとTLEになってしまったので、復習をします
from collections import Counter
S = str(input())
T = str(input())

for i in range(len(S)+1):
	s = str(S[i:i+1])
	t = str(T[i:i+1])
	S = S.replace(s,'A').replace(t,s).replace('A',t)

answer = 'No'

if S == T:
	answer = 'Yes'
	
print(answer)
"""

"""
対応表を作るイメージ。
azzel→appleにするのには
a a
z p
e i
l e
という変化を回せればおっけー

#初期値-1で、要素26コの対応表をつくる
start = [-1]*26
goal = [-1]*26
print(start)

"""


S = str(input())
T = str(input())

#辞書型を使ってみる。defaultdictは便利らしい。どこがかはちょっとよく分からなかった。
from collections import defaultdict
s = defaultdict(int)
t = defaultdict(int)


for i in S:
	s[i] += 1

for j in T:
	t[j] += 1

#辞書型をソートできるsoted()を使う。
#values()で辞書型のkey valueのvalueだけを取り出している。

ss = sorted(s.values())
tt = sorted(t.values())

if ss == tt:
	print('Yes')
else:
	print('No')
		
	














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

int main (void){
    string weather;
    cin >> weather;
    if (weather == "Sunny"){
        cout << "Cloudy" << endl;
    }else if(weather == "Cloudy"){
        cout << "Rainy" << endl;
    }else{
        cout << "Sunny" << endl;
    }
    return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divCeil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << A << endl; exit(0);}

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N), B(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  for (ll i = 0; i < N; i++)
  {
    cin >> B.at(i);
  }

  ll a = 0, b = 0;
  for (ll i = 0; i < N; i++)
  {
    if (A.at(i) < B.at(i))
    {
      a += divCeil(B.at(i) - A.at(i), 2);
      b += (B.at(i) - A.at(i)) % 2;
    }
    else
    {
      b += A.at(i) - B.at(i);
    }
  }

  cout << ((a >= b) ? "Yes" : "No") << endl;
  cerr << a << " " << b << endl;
}

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

int main() {
  int N, M, L, R;
  cin >> N >> M;
  vector<int> LLL(M);
  vector<int> RRR(M);
  
  for (int i = 0; i < M; i++){
    cin >> L >> R;
    LLL.at(i) = L;
    RRR.at(i) = R;
  }

  sort(LLL.begin(), LLL.end());
  sort(RRR.begin(), RRR.end());
  
  if (RRR.at(0) - LLL.at(M-1) < 0)
    cout << 0 << endl;
  else
    cout << RRR.at(0) - LLL.at(M-1) + 1 << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int N;
    cin >> N;
    if (N < 105) {
        cout << 0 << endl;
    } else if (N < 135) {
        cout << 1 << endl;
    } else if (N < 165) {
        cout << 2 << endl;
    } else if (N < 189) {
        cout << 3 << endl;
    } else if (N < 195) {
        cout << 4 << endl;
    } else {
        cout << 5 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] X = new int[N];
        for(int i = 0; i < N; i++) X[i] = Integer.parseInt(sc.next());
        int result = 10000000;
        for(int i = 1; i <= 100; i++ ) {
            int sum = 0;
            for(int j = 0; j < N; j++) sum += (X[j] - i) * (X[j] - i);
            result = Math.min(result, sum);
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 21588
#include <iostream>

using namespace std;
typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  char s[3];
  cin >> s;
  if(s[1] == 'B') cout << "ARC" << endl;
  if(s[1] == 'R') cout << "ABC" << endl;


  return 0;
}


Measured memory_bytes: 3068
#include<stdio.h>
#include<stdlib.h>
int main(){

int N;
scanf("%d",&N);
int P[N],Q[N];
int calc[]={5040,720,120,24,6,2,1,0};

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

int check(int sq[])
{
  int ans=0;
  for (int i = 0; i < N; i++)
  {
    int counter=0;
    for (int j = 0;j < i; j++)
    {
      if (sq[j]<sq[i]){counter++;}
    }
    ans += calc[7-(N-1)+i]*(sq[i]-1 - counter);
  }
  return ans;
}

printf("%d",abs(check(P)-check(Q)));

return 0;

}



Measured memory_bytes: 1648
# -*- coding: utf-8 -*-
"""
Created on Sat May  2 22:58:08 2020

@author: Kei
"""

import numpy as np
import itertools

N,M,Q = map(int,input().split())

temp = list(range(1,M+1))
A = list(itertools.combinations_with_replacement(temp, N))


#s = [[0]*4]*Q
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q

for i in range(0,Q):
#    print(i)
    a[i],b[i],c[i],d[i] = map(int,input().split())
    

max_point = 0
    
for i in range(0,len(A)):
    point = 0
    for j in range (0,Q):
        if A[i][b[j]-1]-A[i][a[j]-1] == c[j]:
            point += d[j]
    max_point = max(point,max_point)
    

#4 6 10
#2 4 1 86568
#1 4 0 90629
#2 3 0 90310
#3 4 1 29211
#3 4 3 78537
#3 4 2 8580
#1 2 1 96263
#1 4 2 2156
#1 2 0 94325
#1 4 3 94328
#        
print(max_point)
        

Measured memory_bytes: 39540
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(x) cout << fixed << setprecision(x);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
 
 
int main(){
  ll A,V,B,W,T;
  cin >> A >> V;
  cin >> B >> W;
  cin >> T;
  if(V*T - W*T >= abs(A-B)){
    cout << "YES" << endl;
  }
  else{
   cout << "NO" << endl;
  }
}
  

Measured memory_bytes: 3588
k, n = map(int, input().split())
a = list(map(int, input().split()))
p1 = a[0]
md = -9999999999999999999999999999999
for i in a[1:]:
	md = max(md, i - p1)
	p1 = i
md = max(md, a[0] + k - a[-1])
print(k - md)

Measured memory_bytes: 26436
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a = gi();
    int b = gi();
    for (int i = 1; i < 1010; i++) {
        int ta = i*8/100;
        int tb = i/10;
        if (ta == a && tb == b) {
            printf("%d\n", i);
            return 0;
        }
    }

    printf("-1\n");

    return 0;
}


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

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

  string S;
  cin >> S;
  
  bool result = true;
  if (N % 2 == 0) {
    for (int i = 0; i < N/2; i++) {
      if (S.at(i) != S.at(N/2 + i)) {
        result = false;
      }
    }
  } else {
    result = false;
  }
  
  if (result) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  
}

Measured memory_bytes: 256
n=int(input())
l=[int(x) for x in input().split()]
f1={}
f2={}
for i in range(1,len(l)+1):
	if i-l[i-1] in f1:
		f1[i-l[i-1]]+=1
	else:
		f1[i-l[i-1]]=1
	if l[i-1]+i in f2:
		f2[l[i-1]+i]+=1
	else:
		f2[l[i-1]+i]=1

c=0
#print(f1)
#print(f2)
for u,v in f1.items():
	c+=f2.get(u,0)*v
print(c)


Measured memory_bytes: 146008
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int N, Q;
    cin >> N >> Q;

    string S;
    cin >> S;

    vector<int> ruiseki(N + 1, 0);
    for (int i = 0; i < N - 1; ++i)
    {
        if (S[i] == 'A' && S[i + 1] == 'C')
        {
            ruiseki[i + 1] = ruiseki[i] + 1;
        }
        else
        {
            ruiseki[i + 1] += ruiseki[i];
        }
    }

    int left, right;
    for (int i = 0; i < Q; i++)
    {
        cin >> left >> right;
        left--;
        right--;
        cout << ruiseki[right] - ruiseki[left] << endl;
    }
    return (0);
}

Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

bool dp[5001][5001]; //dp[city][life] ::= cost

class State{
public:
  short city;
  int cost;
  short life;
  State(short _ci,int _co,short _l) :
    city(_ci),cost(_co),life(_l) {}
  bool operator<(const State& s) const {
    return cost < s.cost;
  }
  bool operator>(const State& s) const {
    return cost > s.cost;
  }
};

struct Taxi{
  int cost;
  short life;
  Taxi() : cost(0),life(0) {}
  Taxi(int _c,short _l) : cost(_c), life(_l) {}
};

int main(){
  int total_cities;
  int total_roads;
  while(~scanf("%d %d",&total_cities,&total_roads)){
    Taxi taxi[5001];
    memset(dp,false,sizeof(dp));
    vector<short> roads[5001];

    for(int city_idx = 0; city_idx < total_cities; city_idx++){
      int cost;
      short life;
      scanf("%d %hd",&cost,&life);
      taxi[city_idx] = Taxi(cost,life);
    }

    for(int road_idx = 0;road_idx < total_roads;road_idx++){
      short from,to;
      scanf("%hd %hd",&from,&to);
      from--; to--;
      roads[from].push_back(to);
      roads[to].push_back(from);
    }
    
    priority_queue<State,vector<State>,greater<State> > que;
    que.push(State(0,0,0));

    int res = INF;
    while(!que.empty()){
      State s = que.top();
      que.pop();
      if(dp[s.city][s.life]) continue;

      dp[s.city][s.life] = true;
      // cout << s.city << endl;
      if(s.city == total_cities - 1){
        res = min(res,s.cost);
        break;
      }

      for(int i=0; i < roads[s.city].size(); i++){
        short next_city = roads[s.city][i];
        if(s.life == 0){
          //have to ride
          int next_cost = s.cost + taxi[s.city].cost;
          short next_life = taxi[s.city].life - 1;
          if(!dp[next_city][next_life]){
            que.push(State(next_city,next_cost,next_life));
          }
        }
        else{
          //ride
          int next_cost = s.cost + taxi[s.city].cost;
          short next_life = taxi[s.city].life - 1;
          if(!dp[next_city][next_life]){
            que.push(State(next_city,next_cost,next_life));
          }

          //don't ride
          next_cost = s.cost;
          next_life = s.life - 1;
          if(!dp[next_city][next_life]){
            que.push(State(next_city,next_cost,next_life));
          }
        }
      }
    }

    printf("%d\n",res);
  }
}

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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main()
{
	ll k, a, b;
	cin >> k >> a >> b;
	ll ans = k+1;
	ll bis = 1;
	if(b > a)
	{
		if(a+1 <= k)
		{
			bis = b;
			k -= a+1;
			if(k%2) bis++;
			ll z = k/2;
			bis += z*(b-a);
			ans = max(ans, bis);
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
//あらためて見るとこの問題全然わからない

//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int a[2][200000], b[2][200000];
	int kazuA[29] = {}, kazuB[29] = {};
	rep(i, N) {
		a[0][i] = getint(); 
		rep(j, 28) kazuA[j] += a[0][i] >> j & 1;
	}
	rep(i, N) {
		b[0][i] = getint();
		rep(j, 28) kazuB[j] += b[0][i] >> j & 1;
	}
	int kotae = 0;
	rep(i, 29) {
		int p = i & 1;

		int kazu[2];
		kazu[0] = 0;
		kazu[1] = N - kazuA[i];
		rep(j, N) a[!p][kazu[a[p][j] >> i & 1]++] = a[p][j];
		kazu[0] = 0;
		kazu[1] = N - kazuB[i];
		rep(j, N) b[!p][kazu[b[p][j] >> i & 1]++] = b[p][j];

		int kari = 0;
		int d = (1 << i) - 1;
		int d2 = 1 << i;
		int k1 = kazu[0];
		int k2 = N;
		rep(j, N - kazuA[i]) {
			while (k1 > 0 && (a[!p][j] & d) + (b[!p][k1 - 1] & d) >= d2) k1--;
			while (k2 > kazu[0] && (a[!p][j] & d) + (b[!p][k2 - 1] & d) >= d2) k2--;
			kari ^= k1 ^ k2;
		}
		k1 = kazu[0];
		k2 = N;
		for (int j = N - kazuA[i]; j < N; j++) {
			while (k1 > 0 && (a[!p][j] & d) + (b[!p][k1 - 1] & d) >= d2) k1--;
			while (k2 > kazu[0] && (a[!p][j] & d) + (b[!p][k2 - 1] & d) >= d2) k2--;
			kari ^= N ^ k1 ^ k2;
		}

		kotae += (kari & 1) << i;
	}
	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i < 4; i++) {
    if (S[i] == '+') {
      ans++;
    } else {
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
N, Y = map(int, input().split())
an_i = an_m = an_k = -1
for i in range(N + 1):
    for m in range(N - i + 1):
        k = N - i - m
        if (10000 * i + 5000 * m + 1000 * k) == Y:
            an_i, an_m, an_k = i, m, k
print(str(an_i) + ' ' + str(an_m) + ' ' + str(an_k))

Measured memory_bytes: 3060
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import itertools
import math
import sys

INF = float('inf')


def solve(N: int):
    h, p, b = 'h', 'p', 'b'
    return [p, p, h, b, h, h, p, h, p, h][N % 10] + 'on'


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    print(solve(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 70212
#include <bits/stdc++.h>
#include <string.h>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
//#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define INF (int)1e15
#define MOD 1000000007
//#define N 12
#define sz 1000*1000



int main(){

 int n; cin>>n;
 vector<int>a(n),b(n);

  for(int i=0;i<n;i++)
      cin>>a[i]>>b[i];

  vector<pair<int,int>>v(n);

  for(int i=0;i<n;i++){
      v[i].first = a[i]+b[i];
      v[i].second = a[i]-b[i];
  }

  sort(v.begin(),v.end());

  int maxi = INT_MIN,cnt=0;

  for(int i=0;i<n;i++){
      if(maxi <= v[i].second){

         cnt++;
       maxi = v[i].first;
      }
  }

  cout<<cnt<<endl;

return 0;
}

Measured memory_bytes: 4772
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<math.h>
#include<set>
#include<iomanip>
#include<stdio.h>
#include<deque>
#include<stack>
#include<map>
#include<queue>
#include<cstring>
#define M 1000000007
#define pb push_back
#define mp make_pair
#define int long long
using namespace std;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string S;
	cin>>S;
	int n=S.length(),i,j;
	int pos[n],x=-1;
	for(i=0;i<n;i++)
	{
		if(S[i]=='R')
		{
			if(x<i)
			{
				for(j=i+1;j<n;j++)
				{
					if(S[j]=='L')
					{
						x=j;
						break;
					}
				}
			}
			pos[i]=x;
		}
	}
	x=n;
	for(i=n-1;i>-1;i--)
	{
		if(S[i]=='L')
		{
			if(x>i)
			{
				for(j=i-1;j>-1;j--)
				{
					if(S[j]=='R')
					{
						x=j;
						break;
					}
				}
			}
			pos[i]=x;
		}
	}
	int o[n]={0};
	for(i=0;i<n;i++)
	{
		int p=abs(i-pos[i]);
		if(p&1)
		{
			if(S[i]=='R')
				o[pos[i]-1]++;
			else
				o[pos[i]+1]++;
		}
		else
			o[pos[i]]++;
	}
	for(i=0;i<n;i++)
		cout<<o[i]<<' ';
	cout<<endl;
}

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

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
#define N 5005
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int a[3],b[3];
ll dp[N*N],n;
vector<pair<int,int> > p;
ll Solve(int n){
	memset(dp,~0x3f,sizeof(dp));
	dp[0]=0;
	ll ans=0;
	for(auto x:p){
		int v=x.first,w=x.second;
		for(int i=v;i<=n;++i){
			dp[i]=max(dp[i],dp[i-v]+w);
		}
	}
	for(int i=n;i>=0;--i){
		ans=max(ans,n-i+dp[i]);
	}
	return ans;
}
int main(){
	n=read();
	for(int i=0;i<3;++i)a[i]=read();
	for(int i=0;i<3;++i)b[i]=read();
	if(a[0]-b[0]>a[1]-b[1])swap(a[0],a[1]),swap(b[0],b[1]);
	if(a[1]-b[1]>a[2]-b[2])swap(a[1],a[2]),swap(b[1],b[2]);
	if(a[0]-b[0]>a[1]-b[1])swap(a[0],a[1]),swap(b[0],b[1]);
	if(a[0]<b[0]){
		if(a[1]<b[1]){
			if(a[2]<b[2]){
				for(int i=0;i<3;++i){
					p.emplace_back(a[i],b[i]);
				}
				n=Solve(n);
			}
			else{
				p.emplace_back(a[0],b[0]);
				p.emplace_back(a[1],b[1]);
				n=Solve(n);
				n=n%b[2]+n/b[2]*a[2];
			}
		}
		else{
			n=n%a[0]+n/a[0]*b[0];
			p.emplace_back(b[1],a[1]);
			p.emplace_back(b[2],a[2]);
			n=Solve(n);
		}
	}
	else{
		for(int i=0;i<3;++i){
			p.emplace_back(b[i],a[i]);
		}
		n=Solve(n);
	}
	printf("%lld\n",n);
	return 0;
}



Measured memory_bytes: 199428
S = list(input())
N = len(S) + 1#Nは文字列lの長さ
INF = 10 ** 8

l = [INF] * N

if S[0] == "<":
    l[0] = 0

for i in range(1,N-1):
    if S[i-1] == "<" and S[i] == "<":
        l[i] = l[i-1] + 1
    elif S[i-1] == ">" and S[i] == "<":
        l[i] = 0
    #print(l)

if S[N-2] == "<":
    l[N-1] = l[N-2] + 1
else:
    l[N-1] = 0

for i in range(1,N-1):
    if S[-i] == ">" and S[-i-1] == ">":
        l[-i-1] = l[-i] + 1
    elif S[-i] == ">" and S[-i-1] == "<":
        l[-i-1] = 1 + max(l[-i],l[-i-2])
    #print(l)

if S[0] == ">":
    l[0] = l[1] + 1

print(sum(l))

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

#define int long long int 

int32_t main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    map<int,int> m;
    for(int i=0;i<n;i++)
    {
      cin>>a[i];
       m[a[i]]++;
    }
    priority_queue<int> p;
    for(auto i:m)
    {
        auto [x,y]=i;
        p.push({-y});
    }
    int ans=0;
    while(p.size()>k)
    {
        auto count=p.top();
        p.pop();
        //cout<<count<<endl;
        ans-=count;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 19148
#include <bits/stdc++.h>
using namespace std;
int N;
int main() {
    cin >> N;
    int total = 0;

    for(int i = 1; i <= N; ++i) {
        if(to_string(i).length() % 2 == 1) {
            total++;
        } 
    }

    cout << total << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;


int main()
{

    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if (u == s)
        a--;
    else
        b--;
    cout << a _ b;
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

vector<string> extract(const string& s, const set<char>& st) {
  vector<string> res;
  int sz = s.size(), l = 0, r = 0;
  while (l < sz) {
    while (r < sz && (st.find(s[r]) != st.end())) r++;
    if (l != r) res.emplace_back(s.substr(l, r - l));
    l = ++r;
  }
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  set<char> st;
  for (int i = 0; i < 10; i++) {
    st.insert(i + '0');
  }

  string s;
  int ans = 0;
  while (getline(cin, s)) {
    auto v = extract(s, st);
    for (auto i : v) {
      ans += stoi(i);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3244
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 200005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll n,k,h[MAXN],a[MAXN];
struct SegTree
{
    ll ans[4*MAXN];
    void pushup(ll k)
    {
        ans[k]=max(ans[k*2],ans[k*2+1]);
    }
    void update(ll k,ll l,ll r,ll p,ll v)
    {
        if(l==r) {ans[k]=v; return;}
        ll mid=(l+r)/2;
        if(p<=mid) update(k*2,l,mid,p,v); else update(k*2+1,mid+1,r,p,v);
        pushup(k);
    }
    ll query(ll k,ll l,ll r,ll x,ll y)
    {
        if(l>y||x>r) return 0;
        if(l>=x&&r<=y) return ans[k];
        ll mid=(l+r)/2;
        return max(query(k*2,l,mid,x,y),query(k*2+1,mid+1,r,x,y));
    }
}seg;
vector<int> v;
ll dp[MAXN];
int main()
{
    scanf("%lld",&n);
    for(ll i=1;i<=n;i++) scanf("%lld",&h[i]);
    for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(ll i=1;i<=n;i++) v.push_back(h[i]);
    sort(v.begin(),v.end());
    for(ll i=1;i<=n;i++) h[i]=lower_bound(v.begin(),v.end(),h[i])-v.begin()+1;
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        dp[i]=seg.query(1,1,n,1,h[i])+a[i];
        ans=max(ans,dp[i]);
        seg.update(1,1,n,h[i],dp[i]);
    }
    printf("%lld\n",ans);
    return 0;
}



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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());
        double[][] dp = new double[n + 1][n + 2];

        for (int i = 1; i <= n; i++) {
            double p = Double.parseDouble(st.nextToken());

            if (i == 1) {
                dp[1][0] = 1 - p;
                dp[1][1] = p;
            }
            else {
                dp[i][0] = dp[i - 1][0] * (1 - p);

                for (int j = 1; j < i; j++) {
                    dp[i][j] = dp[i - 1][j] * (1 - p) + dp[i - 1][j - 1] * p;
                    dp[i][j + 1] = dp[i - 1][j] * p + dp[i - 1][j + 1] * (1 - p);
                }
            }
        }

        double sum = 0;

        for (int i = n / 2 + 1; i <= n; i++)
            sum += dp[n][i];

        System.out.println(sum);
    }
}


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

using namespace std;

int main()
{
	int num[101] = {0};
	int data, max = -1;
	vector<int> mode;

	while (cin >> data)
	{
		if(cin.eof())	break;

		num[data]++;
	}

	for (int i=1; i<101; i++)
	{
		if(num[i] > max){
			max = num[i];
			mode.clear();
			mode.push_back(i);
		}
		else if(num[i] == max){
			mode.push_back(i);
		}
	}

	vector<int>::iterator numit = mode.begin();
	for (;numit != mode.end(); numit++)
	{
		cout << *numit << endl;
	}

	return 0;
}

Measured memory_bytes: 1212
// A - ∴ (Therefore)
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	set<int> s{0,1,6,8};
	if(s.find(N%10) != s.end()) puts("pon");
	else if(N%10 == 3) puts("bon");
	else puts("hon");
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
vector<int>vec;
//map<int,int>mp;
int main()
{

  int i,j,n,t,a,b,c;
  string s;
  cin>>a;
  n=sqrt(a);
  cout<<n*n<<"\n";


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 5;

int n , a[N] , b[N];
LL sum = 0;
int main() {
    scanf("%d" , &n);
    for (int i = 0 ; i < n ; ++ i) {
        scanf("%d" , &a[i]);
        sum += a[i];
    }
    LL w = 1LL * n * (n + 1) / 2;
    if (sum % w) {
        puts("NO");
        return 0;
    } else {
        LL t = sum / w; a[n] = a[0];
        for (int i = 0 ; i < n ; ++ i) {
            if (a[i] < t || a[i] > (LL)t * n) {
                puts("NO");
                return 0;
            }
            b[i] = a[i + 1] - a[i] - t;
            if (b[i] % n) {
                puts("NO");
                return 0;
            }
        }
    }
    puts("YES");
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#define int long long
using namespace std;
long long x,k,d;
int fzx_abs(int x) {
        return x<0 ? -x : x;
}
int fzx_min(int x,int y) {
        return x>y ? y : x;
}
signed main()
{
        scanf("%lld %lld %lld",&x,&k,&d);
        x=fzx_abs(x);
        int kk=fzx_min(x/d,k);
        k-=kk;
        x-=kk*d;
        if (k>0 && k&1) x=fzx_min(fzx_abs(x-d),fzx_abs(x+d));
        cout<<x<<"\n";
        return 0;
}


Measured memory_bytes: 3720
/*
  mail: mleautomaton@foxmail.com
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=200010;
int a[N],n,b[N],len,sum[N],bl[N];
int main(){
	n=gi();for(int i=1;i<=n;i++)a[i]=gi();
	for(int i=n;i;i--){
		if(sum[i]%2!=a[i]){
			sum[i]++;bl[i]++;
			for(int j=1;j*j<=i;j++){
				if(i%j==0){
					sum[j]++;
					if(j*j!=i)sum[i/j]++;
				}
			}
			sum[i]--;
		}
	}
	for(int i=1;i<=n;i++)
		if(bl[i])
			b[++len]=i;
	printf("%d\n",len);
	for(int i=1;i<=len;i++)printf("%d%c",b[i],i==len?'\n':' ');
	return 0;
}


Measured memory_bytes: 3584
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL-1
double EPS=1e-9;
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef complex<double> P;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
int n;
vector<ll> a;
const int BT = 1 << 18 ;
int MA=214514;
struct segtree {//BT = size
    vector<int> seg;

	void init() {
	seg.resize(BT * 2);
	rep(i, BT * 2 - 1) seg[i] =MA;
    }

    void add(int pos, int x) {//posにxを追加,0-index nodeも0-index
		pos += BT - 1;
		seg[pos] = x;
		
		while (pos > 0) {
			pos = (pos - 1) / 2;
			seg[pos] = min(seg[pos * 2 + 1], seg[pos * 2 + 2]);
		}
    }

    int minQ(int a, int b, int k = 0, int l = 0, int r = BT) {//[a,b)に対するクエリ
		if (b <= l || r <= a) return MA;//交差しない
		if (a <= l && r <= b) return seg[k];//被覆する
		return min(minQ(a, b, k * 2 + 1, l, (l + r) / 2), minQ(a, b, k * 2 + 2, (l + r) / 2, r));
	}

}segm; 
int main(){
	cin>>n;
	int x;
	segm.init();
	for(int i=0;i<n;i++){
		cin>>x;
		a.pb((ll)x);
		segm.add(i,x);
	}
	ll ans=0;
	//cout<<segm.minQ(0,1)<<endl;
	for(int i=0;i<n;i++){
		int l=0,r=n,p=i,q=i;
		int cnt=25;
		while(cnt--){
			int rmid=(q+r)/2,lmid=(l+p)/2;
			if(segm.minQ(i,rmid+1)<a[i]){
				r=rmid;
			}else{
				q=rmid;
			}
			
			if(segm.minQ(lmid,i+1)<a[i]){
				l=lmid;
			}else{
				p=lmid;
			}
		}
		//cout<<p<<" "<<r<<endl;
		ll R,L;
		R=(ll)(r-i);
		L=(ll)(i-p+1);
		ans+=R*L*a[i];
	}
	cout<<ans<<endl;
	
}
/*3 5 0 3
0 1 1
1 2 1
2 3 2
0 2 3
1 3 2*/


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

int main(void) {
  int n;
  cin >> n;
  int a[n];
  int s = 0;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    s ^= a[i];
  }
  for(int i = 0; i < n; i++) {
    int ans = s ^ a[i];
    cout << ans << " ";
  }
  cout << endl;
  return 0;
}


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

using namespace std;

int main() {
    string s; cin>>s;
    regex re("([ACGT]+)");

    auto iter = s.cbegin();
    auto end = s.cend();

    size_t max_length=0;
    smatch m;
    while (regex_search(iter, end, m, re)) {
        max_length = max(m.str().length(), max_length);
        iter = m[0].second;
    }

    cout << max_length << endl;

    return 0;
}

Measured memory_bytes: 384
N,*H=`dd`.split.map &:to_i
B=[0]*2**19
N.times{|i|j=k=H[i]
r=0
1while(r=[r,B[j]+H[N+i]].max;j&=j-1)>0
(B[k]=r;k+=k&-k)while B[k]&.<r}
p B.max

Measured memory_bytes: 57872
def main():
    N = int(input())
    if N < 357: return 0

    cur = ["3", "5", "7"]
    count = 0
    while cur:
        temp = []
        for s in cur:
            if "3" in s and "5" in s and "7" in s:
                count += 1
            for c in "357":
                if int(c+s) <= N:
                    temp.append(c+s)
        cur = temp
    return count

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 4828
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef pair<LL,LL>PL;
const LL INF=1e18;
int A[1234567];
bool chk[20];
int N;
void dnc(int s,int e,int f,int l)
{
    int L=e-s;
    int i,j;
    int p=(f^l)&-(f^l);
    for(i=0;i<N;i++)
        if((1<<i)==p)
            break;
    chk[i]=true;
    A[s]=f;
    if(s==e)
        return;
    for(i=1;i<L>>1;i++)
    {
        j=i&-i;
        for(int k=0;1<<k<=j;k++)
            if(chk[k])
                j<<=1;
        A[s+i]=A[s+i-1]^j;
    }
    j=A[s+i-1]^p;
    dnc(s+i,e,j,l);
    return;
}
int a,B,P,i;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>N>>a>>B;
    P=a^B;
    if(__builtin_popcount(P)&1^1)
        return cout<<"NO"<<endl,0;
    cout<<"YES"<<endl;
    dnc(0,1<<N,a,B);
    for(i=0;i<1<<N;i++)
        cout<<A[i]<<' ';
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1536
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        var ans = new long[N + 1];
        for (int x = 1; x < Sqrt(N)+1; x++)
        {
            for (int y = 1; y < Sqrt(N)+1; y++)
            {
                for (int z = 1; z < Sqrt(N)+1; z++)
                {
                    long num = x * x + y * y + z * z + x * y + y * z + z * x;
                    if (num > N) break;
                    else ans[num]++;
                }
            }
        }
        for (int i = 1; i < N+1; i++)
        {
            WriteLine(ans[i]);
        }
    }
}


Measured memory_bytes: 27360
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int hpi,hpm,R,C,T,S,n[1010],P,p[19],x,y,dy[]={0,1,0,-1},dx[]={1,0,-1,0},dp[1<<12];
char a[110][110],d[1010],c;
map<char,int> M,m;

int tc;
int main(){
	m['R']=0,m['D']=1,m['L']=2,m['U']=3;
	while(cin>>hpi>>hpm&&hpi){tc++;
		vi v;
		cin>>R>>C;
		rep(i,R)cin>>a[i];
		cin>>T;
		rep(i,T)cin>>c>>y,M[c]=y;
		cin>>S;
		rep(i,S)cin>>d[i]>>n[i];
		cin>>P;
		rep(i,P)cin>>p[i];
		y=x=0;
		rep(i,S){
			rep(j,n[i]){
				y+=dy[m[d[i]]],x+=dx[m[d[i]]];
				if(M[a[y][x]])v.pb(M[a[y][x]]);
			}
		}
		fill(dp,dp+(1<<P),-INF);
		dp[0]=hpi;
		rep(i,v.sz)rep(j,1<<P)if(dp[j]>0){
			rep(k,P)if(!(j&1<<k)){
				dp[j|1<<k]=max(dp[j|1<<k],min(hpm,dp[j]+p[k]));
			}
			dp[j]-=v[i];
		}
		cout<<(dp[(1<<P)-1]>0||!v.sz?"YES":"NO")<<endl;
	}
}

Measured memory_bytes: 948
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    string s;
    cin >> s;

    int a, z;
    a = z = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A') {
            a = i;
            break;
        }
    }
    for (int i = s.size() - 1; i >= 0; i--) {
        if (s[i] == 'Z') {
            z = i;
            break;
        }
    }

    cout << z - a + 1 << endl;

    return 0;
}


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

typedef long long int ll;

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

    ll ans = 0LL;
    for (int i = 0; i < N-1; i++) {
        ans += (ans / (K-1)) + 1;
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
    bool ans = true;
    int n; cin >> n;
    int h[n];
    rep(i,n) cin >> h[i];
    int ma = 1;
    rep(i,n){
        ma = max(ma,h[i]);
        if(ma >= h[i] + 2) ans = false;
    }
    cout << ((ans)? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 640
O = input()
E = input()
while True:
    if len(O)!=0:
        print(O[0],end='')
        O = O[1:]
    if len(E)!=0:
        print(E[0],end='')
        E = E[1:]
    if len(O)==0 and len(E)==0:
        print()
        break

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

int main(void){
  int x, a, b;
  cin>>x>>a>>b;
  int ans=x-(x-a)%b;
  cout<<x-ans<<endl;
  return 0;
}

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

int main() {
	int n;
	cin>>n;
	
	long sum = 0;
	for(int i=1; i<=n; ++i){
		for(int j=1; j<=n; ++j){
			for(int k=1; k<=n; ++k){
				sum += __gcd(__gcd(i,j), k);
			}
		}
	}
	
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

#define rep(i, a) for (int i = 0; i < (a); i++)
#define ll long long

int N;
int d[55], cnt[13];
vector<int> v;

int diff(ll mask) {
  int res = 12;
  rep(i, 25) {
    if (!(mask & (1LL << i))) continue;
    for (int j = i + 1; j < 25; j++) {
      if (!(mask & (1LL << j))) continue;
      int d = (i - j + 24) % 24;
      res = min(res, min(d, 24 - d));
    }
  }
  //printf("%d, %llx\n", res, mask);
  return res;
}

int dfs(int i, ll mask) {
  int res = 0;
  if (i > v.size() - 1) return diff(mask);

  if (!(mask & (1LL << v[i]))) {
    res = max(res, dfs(i + 1, mask | (1LL << v[i])));
  }
  if (!(mask & (1LL << (24 - v[i])))) {
    res = max(res, dfs(i + 1, mask | (1LL << (24 - v[i]))));
  }
  return res;
}

int solve(){
  if (cnt[0] > 0) return 0;
  rep(i, 13) if (cnt[i] >= 3) return 0;
  rep(i, 13) rep(j, cnt[i]) v.push_back(i);

  return dfs(0, 1);
}

int main(void) {
  cin >> N;
  rep(i, N) cin >> d[i], cnt[d[i]]++;
  
  cout << solve() << endl;

  return 0;
}


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

typedef long long ll;

int main() {
    int N, M, A, B, ans;
    cin >> N >> M;
    ans = N - 1;
    dsu d(N);
    rep(i, M) {
        cin >> A >> B;
        A--;
        B--;
        if (!d.same(A, B)) ans--;
        d.merge(A, B);
    }
    cout << ans << "\n";
}

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

int num[2];

int main()
{
    string S;
    cin >> S;
    for(auto &p : S) ++num[p-'A'];
    if(num[0] == 0 || num[1] == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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


typedef long long nyan;
typedef pair<nyan,nyan> P;
typedef pair<P,P> P2;

nyan r,c;
int n;

P p1[100010];
P p2[100010];


bool on_edge(nyan a,nyan b)
{
	return a == 0 || a == r || b == 0 || b == c;
}


nyan edge_point(P p)
{
	if(p.second == 0)
	{
		return p.first;
	}
	if(p.first == r)
	{
		return r + p.second;
	}
	if(p.second == c)
	{
		return r + c + r - p.first;
	}
	if(p.first == 0)
	{
		return r + c + r + c - p.second;
	}
	return -1;
}

vector<nyan> xs,ys;

int imos[800010];

int main()
{
	cin >> r >> c >> n;


	xs.push_back(0);
	xs.push_back(r);
	ys.push_back(0);
	ys.push_back(c);

	for(int i = 0;i < n;i++)
	{
		cin >> p1[i].first >> p1[i].second >> p2[i].first >> p2[i].second;

		xs.push_back(p1[i].first);
		xs.push_back(p2[i].first);
		ys.push_back(p1[i].second);
		ys.push_back(p2[i].second);
	}

	sort(xs.begin(),xs.end());
	sort(ys.begin(),ys.end());

	xs.erase(unique(xs.begin(),xs.end()),xs.end());
	ys.erase(unique(ys.begin(),ys.end()),ys.end());
	
	r = xs.size() - 1;
	c = ys.size() - 1;

	vector<P> e_set;
	
	for(int i = 0;i < n;i++)
	{
		int x1,y1,x2,y2;

		x1 = lower_bound(xs.begin(),xs.end(),p1[i].first) - xs.begin();
		y1 = lower_bound(ys.begin(),ys.end(),p1[i].second) - ys.begin();

		x2 = lower_bound(xs.begin(),xs.end(),p2[i].first) - xs.begin();
		y2 = lower_bound(ys.begin(),ys.end(),p2[i].second) - ys.begin();


		if(on_edge(x1,y1) && on_edge(x2,y2))
		{
			int e1 = edge_point(P(x1,y1));
			int e2 = edge_point(P(x2,y2));
			if(e1 > e2) swap(e1,e2);
          e_set.push_back(P(e1,e2));
			imos[e1]++;
			imos[e2 + 1]--;
		}
	}

	for(int i = 1;i < r * 2 + c * 2;i++)
	{
		imos[i] += imos[i - 1];
	}

	for(P e_s : e_set)
	{
		if(imos[e_s.first] != imos[e_s.second])
		{
			cout << "NO" << endl;
			return 0;
		}
	}



	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 13284
H,W,M = [int(x) for x in input().split()]
hw = []
hNum = [0]*H
wNum = [0]*W

for i in range(M):
    h,w = [int(x) for x in input().split()]
    hw.append([h,w])
    hNum[h-1]+=1
    wNum[w-1]+=1

hmax = max(hNum)
hMaxList = []
wmax = max(wNum)
wMaxList = []

for i in range(H):
    if(hmax == hNum[i]):
        hMaxList.append(i)
for i in range(W):
    if(wmax == wNum[i]):
        wMaxList.append(i)

ans = wmax + hmax
count = 0
for i in hw:
    if(hNum[i[0]-1] == hmax and wNum[i[1]-1] == wmax):
        count += 1
if(hNum.count(hmax) * wNum.count(wmax) == count):
    ans -= 1
print(ans)


Measured memory_bytes: 82492
from collections import deque
import sys
input = sys.stdin.readline

def main():
    N, Q = map(int, input().split())
    edges = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        edges[b-1].append(a-1)
        edges[a-1].append(b-1)

    counts = [0]*N
    for _ in range(Q):
        p, x = map(int, input().split())
        counts[p-1] += x

    parent_nodes = deque()
    parent_nodes.append(0)
    visited_nodes = set()
    while parent_nodes:
        parent = parent_nodes.popleft()
        if parent in visited_nodes:
            continue
        visited_nodes.add(parent)
        for child in edges[parent]:
            if child in visited_nodes:
                continue
            counts[child] += counts[parent]
            parent_nodes.append(child)

    print(' '.join(list(map(str, counts))))

if __name__ == "__main__":
    main()

Measured memory_bytes: 73736
#include <cstdio>

int A, V;
int B, W;
int T;

int main() {
  scanf("%d%d%d%d%d", &A, &V, &B, &W, &T);
  if (V <= W) {
    puts("NO");
    return 0;
  }
  int D = A < B ? B - A : A - B;
  if (D <= 1ll * T * (V - W)) {
    puts("YES");
  } else {
    puts("NO");
  }
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <regex>
#ifdef _DEBUG
#include "debug.h"
#endif
#define int ll
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#ifdef int
#define INF (LLONG_MAX / 2)
#else
#define INF (INT_MAX / 2)
#endif
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-9)
#define mkpr make_pair
#define mktp make_tuple
#define var auto
#define self (*this)
#define in :
#define True true
#define False false
#define None nullptr
#define is ==
#define is_not !=
#define AST(exp, msg) if(!(exp)){EPR((msg))} assert((exp));
#define TAST(exp, msg) if(!(exp)){EPR((msg))} while(!(exp)){}
#define EPR(msg) cerr << (msg) << endl;
#define DBLEQ(a, b) (abs((a) - (b)) < EPS)
#define fst first
#define scd second
#define out &
#define tv(tp, i) get<i>(tp)
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>;
using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>;
const int MGN = 10; const int ARYSZ_MAX = (int)1e7;



int32_t main(int32_t argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef _DEBUG
    vs args(argv, argv+argc);
    string sample = make_sample(args, 3);
    ifstream ifs(sample); cin.rdbuf(ifs.rdbuf());
#endif


    int X,Y, A,B,C; cin>>X>>Y>>A>>B>>C;
    vl P(A); REP(i,A) cin>>P[i];
    vl Q(B); REP(i,B) cin>>Q[i];
    vl R(C); REP(i,C) cin>>R[i];

    sort(P.rbegin(), P.rend());
    sort(Q.rbegin(), Q.rend());

    priority_queue<ll> pq_r, pq_g, pq_t;
    REP(i,X) pq_r.push(P[i]);
    REP(i,Y) pq_g.push(Q[i]);
    REP(i,C) pq_t.push(R[i]);
    pq_r.push(-1);
    pq_g.push(-1);
    pq_t.push(-1);

    ll ans = 0;
    //int x=0, y=0;
    REP(i, X+Y) {
        ll rd = pq_r.top();
        ll gr = pq_g.top();
        ll tr = pq_t.top();

        if (rd >= max(gr, tr)) {
            ans += rd;
            pq_r.pop();
            continue;
        }

        if (gr >= max(rd, tr)) {
            ans += gr;
            pq_g.pop();
            continue;
        }

        if (tr >= max(rd, gr)) {
            ans += tr;
            pq_t.pop();
            continue;
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 5620
#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 n;
    cin>>n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    if(count(a.begin(),a.end(),0)!=0){
        cout<<0<<endl;
        return 0;
    }
    ll ans=1;
    rep(i,n){
        if(a[i]<=(const ll)1e18/ans){
            ans*=a[i];
        }
        else{cout<<-1<<endl; return 0;}
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4000
import copy
h,w,k = map(int,input().split())
c = [[1*(i=="#") for i in list(input())] for j in range(h)]
ans = 0
for i in range(2**h):
    l1 = []
    for i1 in range(h):
        l1.append(i >> i1 & 1)
    for j in range(2**w):
        l2 = []
        for j1 in range(w):
            l2.append(j >> j1 & 1)
        
        c2 = copy.deepcopy(c)
        for i2 in range(h):
            if l1[i2]:
                for j3 in range(w):
                    c2[i2][j3] = 0
        for j2 in range(w):
            if l2[j2]:
                for i3 in range(h):
                    c2[i3][j2] = 0
        s = 0
        for t in range(h):
            s += sum(c2[t])
        if s == k:
            ans += 1

print(ans)

Measured memory_bytes: 9220