akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;

public class Program
{
  

    public void Solve()
    {
        var sc = new Scanner();
        int q = sc.NextInt();
        var sb = new StringBuilder();
        for (int i = 0; i < q; i++)
        {
            int a = sc.NextInt();
            int b = sc.NextInt();
            sb.AppendLine(Query(a, b).ToString());
        }
        
        Console.Write(sb.ToString());
    }

    private long Query(long a, long b)
    {
        if (a > b)
        {
            return Query(b, a);
        }

        if (a == b)
        {
            return (a - 1) * 2;
        }
        
        // (n+1)(m-1) = nm + m - n -1

        long ans = 0;
        // 2回目の順位がBより下

        ans += a - 1;
        
        // 1回目の順位がAより下

        long sq = (long) Math.Sqrt(a * b);
        
        // 2回の順位の和
        long sum;
        if (sq * sq == a * b)
        {
            sum = sq + sq - 1;
        }
        else if (sq * (sq + 1) < a * b)
        {
            sum = sq + sq + 1;
        }
        else
        {
            sum = sq + sq;
        }

        ans += sum - (a + 1);
        
        return ans;
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 13140
//#summon tourist
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vl t(N),v(N);
    ll tsum=0;
    rep(i,N){
        cin >> t[i];
        tsum+=t[i];
    }
    rep(i,N){
        cin >> v[i];
    }
    vl acc0(N+1,0),acc1(N+1,0);
    rep(i,N){
        acc0[i+1]=acc0[i]+t[i];
        acc1[i+1]=acc1[i]+t[N-i-1];
    }
    ld ans=0;
    vector<ld> v0(2*tsum+1,0),v1(2*tsum+1,0);
    ll zone=0;
    rep(i,2*tsum){
        v0[i+1]=min((v0[i]+0.5),(ld)v[zone]);
        if(2*acc0[zone+1]==i+1){
            zone++;
        }
    }
    zone=N-1;
    per(i,2*tsum-1){
        v1[i]=min((v1[i+1]+0.5),(ld)v[zone]);
        if(2*acc1[N-zone]==2*tsum-i){
            zone--;
        }
    }
    /*rep(i,2*tsum+1){
        cout << i << ' ' << v0[i] << ' ' << v1[i] << endl;
    }*/
    rep(i,2*tsum+1){
        ans+=min(v0[i],v1[i]);
    }
    cout << fixed << setprecision(7) << ans/2 << endl;
}
/*
overflow checked
corner case checked
boundary checked
not TLE in worst case checked
*/

Measured memory_bytes: 4536
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <functional>
#include <vector>

using namespace std;

void solve_case();

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

	solve_case();

	return 0;
}

void solve_case() {
	int n, k;

	cin >> n >> k;

	if ((n + 1) / 2 >= k)
		cout << "YES\n";
	else
		cout << "NO\n";
}


Measured memory_bytes: 256
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a,int b){return a*b/gcd(a,b);}

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int N, T;
    cin >> N >> T;
    priority_queue<int, vector<int>, greater<int> > que;
    int a=0;
    rep(i,N)
    {
        int c, t;
        cin >> c >> t;
        if(t<=T)
        {
            que.push(c);
            a=1;
        }
    }
    if(!a)
    {
        cout << "TLE" << endl;
        return;
    }
    cout << que.top() << endl;
}

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

const int max_n = 100005;
vector<int> memo(max_n, -1);

int rec(int n) {
  if (n == 0) return 0;
  if (memo.at(n) != -1) return memo.at(n);

  int res = n;
  for (int i = 1; i <= n; i *= 6) res = min(res, rec(n - i) + 1);
  for (int j = 1; j <= n; j *= 9) res = min(res, rec(n - j) + 1);
  return memo.at(n) = res;
}

int main() {
  int n;
  cin >> n;
  cout << rec(n);
  return 0;
}

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

struct foo {
	int num;
	char c;
};

int main(){
	int n;
	foo a[100], b[100];
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i].c >> a[i].num,b[i] = a[i];
	
	for (int i = 0; i < n - 1; i++) {
		for (int j = n - 1; i < j; j--) {
			foo tmp = a[j];
			if (a[j].num < a[j - 1].num)a[j] = a[j - 1], a[j - 1] = tmp;
		}
	}
	for (int i = 0; i < n - 1; i++)cout << a[i].c << a[i].num << " ";
	cout << a[n - 1].c << a[n - 1].num << endl << "Stable" << endl;

	for (int i = 0; i < n; i++) {
		int minj = i;
		for (int j = i; j < n; j++) {
			if(b[minj].num > b[j].num)minj = j;
		}
		foo tmp = b[minj];
		b[minj] = b[i];
		b[i] = tmp;
	}
	int same;
	for (int i = 0; i < n - 1; i++)cout << b[i].c << b[i].num << " ";
	cout << b[n - 1].c << b[n - 1].num << endl;
	for (int i = 0; i < n && a[i].c == b[i].c; i++)same = i;
	if (same >= n - 1)cout << "Stable" << endl;
	else cout << "Not stable" << endl;

	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define F first
#define S second
#define endl '\n'
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define maxp 22
#define EPS (ld)(1e-18)
#define mod (int)(1e9+7)
#define N (int)(1e6+1)

int freq[N];
int main (){
fastio;

int n;
cin>>n;

int i;
int arr[n];
int gcd=0;

for(i=0;i<n;i++){
    cin>>arr[i];
    freq[arr[i]]++;
    //gcd=__gcd(gcd,arr[i]);
}
sort(arr,arr+n);

int ans=0;
bool p[N];
memset(p,0,sizeof p);
int j;
for(i=0;i<n;i++){
    if(p[arr[i]])
        continue;
    if(freq[arr[i]]==1)
        ans++;
    for(j=arr[i];j<N;j+=arr[i])
        p[j]=true;
}
cout<<ans;



}


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

using namespace std;

#define LL long long
#define reg register
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a)
#define ret(a,b,c) for(reg int a=(b),a##_end_=(c); a<a##_end_; ++a)
#define drep(a,b,c) for(reg int a=(b),a##_end_=(c); a>=a##_end_; --a)

inline int Read() {
	int res=0,f=1;
	char c;
	while(c=getchar(),c<48||c>57)if(c=='-')f=0;
	do res=(res<<3)+(res<<1)+(c^48);
	while(c=getchar(),c>=48&&c<=57);
	return f?res:-res;
}

template<class T>inline bool Min(T &a,T const&b) {
	return a>b?a=b,1:0;
}
template<class T>inline bool Max(T &a,T const&b) {
	return a<b?a=b,1:0;
}

const int N=1e5+5;

int n,flag=1,t,A[N];

int main() {
	n=Read();
	rep(i,1,n)A[i]=Read();
	ret(i,2,n){
		if(A[i]>A[i-1]&&A[i]<A[i+1])t++;
		if(A[i]<A[i-1]&&A[i]>A[i+1])t++;
	}
	printf("%d",t);
}

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

using namespace std;

const int N = 1e5 + 100;

int a[N], mp[N];

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		mp[a[i]]++;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		ans = max(ans, mp[a[i] - 1] + mp[a[i]] + mp[a[i] + 1]);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// N, M, Q
var (
	N          int
	M          int
	Q          int
	a, b, c, d []int
	result     int
)

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func dfs(A []int) {
	if len(A) == N+1 {
		t := 0
		for i := 0; i < Q; i++ {
			if A[b[i]]-A[a[i]] == c[i] {
				t += d[i]
			}
		}
		result = max(result, t)
		return
	}

	A = append(A, A[len(A)-1])
	for A[len(A)-1] <= M {
		dfs(A)
		A[len(A)-1]++
	}
}

func main() {
	defer flush()

	N = readInt()
	M = readInt()
	Q = readInt()
	a = make([]int, Q)
	b = make([]int, Q)
	c = make([]int, Q)
	d = make([]int, Q)
	for i := 0; i < Q; i++ {
		a[i] = readInt()
		b[i] = readInt()
		c[i] = readInt()
		d[i] = readInt()
	}

	dfs([]int{1})
	println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

func readInts(n int) []int {
	result := make([]int, n)
	for i := 0; i < n; i++ {
		result[i] = readInt()
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdoutWriter, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}

func printIntln(v ...int) {
	b := make([]byte, 0, 4096)
	for i := 0; i < len(v)-1; i++ {
		b = append(b, strconv.Itoa(v[i])...)
		b = append(b, " "...)
	}
	b = append(b, strconv.Itoa(v[len(v)-1])...)
	println(string(b))
}


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

ll bubblesort(ll *array,ll size){
    ll cnt=0;
	for(int i = 0; i < size; i++){
		for(int j = 0; j < size; j++){
			if(array[j] > array[j+1]){
				ll number = array[j+1];
				array[j+1] = array[j];
				array[j] = number;
                cnt++;
			}
		}
	}
    return cnt;
}

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    ll N,K;
    cin >> N >> K;
    ll A[N];
    rep(i,N)cin >> A[i];
    ll ten=bubblesort(A,N); 
    ll big=0;
    ll same=N-1;
    for(ll i=N-1;i>=0;i--){
        if(i!=0 && A[i-1]==A[i])continue;
        else{
            big+=(N-1-same)*(same-i+1);
            if(i!=0)same=i-1;
        }
    }
    big=big%mod;
    ten=ten%mod;
    ll ans=(K*(K-1)/2)%mod*big%mod;
    ll plus=ten*K%mod;
    ans=(ans+plus)%mod;
    cout << ans;
}

/*



 */




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int h[N],a,b,ma[N];
int main(){
int n,m,res=0;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d",&h[i]);
for(int i=1;i<=m;i++){
		scanf("%d%d",&a,&b);
		ma[a]=max(ma[a],h[b]);
		ma[b]=max(ma[b],h[a]);

}
for(int i=1;i<=n;i++){
	if(h[i]>ma[i])res++;
}
printf("%d",res);
return 0;
}


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

using ll = long long;

const ll MOD = 1e9 + 7;

ll minv(ll a, ll m = MOD) {
	return a == 1 ? 1 : m - minv(m % a, a) * m / a;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll X, Y, K; cin >> X >> Y >> K;
	ll binom = 1;
	for (ll i = 0; i < K-2; i++) {
		binom = binom * minv(i+1) % MOD * (X * Y - 2 - i) % MOD;
	}
	ll sum = 0;
	for (ll x = 1; x < X; x++) {
		sum += x * (X-x) * Y % MOD * Y % MOD;
	}
	for (ll y = 1; y < Y; y++) {
		sum += y * (Y-y) * X % MOD * X % MOD;
	}
	ll ans = sum % MOD * binom % MOD;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;

int main() {
    int N, M;
    cin >> N >> M;
    Graph G(N);
    for(int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> dist(N, INF);
    queue<int> que;
    dist[0] = 0, que.push(0);
    while(!que.empty()) {
        int v = que.front();
        que.pop();
        for(auto nv : G[v]) {
            if(dist[nv] != INF)
                continue;
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }
    cout << (dist[N - 1] <= 2 ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    return 0;
}


Measured memory_bytes: 13168
from collections import deque
n, m = map(int, input().split())
INF = 100000000

to = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
print('Yes')
q = deque([])
dist = [INF] * n
pre = [-1] * n
dist[0] = 0
q.append(0)

while len(q) > 0:
    v = q.popleft()
    for i in to[v]:
        if dist[i] != INF:
            continue
        dist[i] = dist[v] + 1
        pre[i] = v
        q.append(i)

for i in range(1, n):
    ans = pre[i]
    ans += 1
    print(ans)


Measured memory_bytes: 34820
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }


int main() {
	int a;
	cin >> a;
	put(3 * a * a);
	return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  string s;
  cin >> s;
  
  string y = "YAKI";
  
  rep(i,0,4){
    if(s[i] != y[i] ){

      No;
      return 0;
    }


  }
  
  Yes;
  ret 0;

}

Measured memory_bytes: 256
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
 
using namespace std;

int main(){

	int n;
	cin>>n;

	long long a[300][300];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++) cin>>a[i][j];
	}

	long long res=0;
	for(int u=0;u<n;u++){
		for(int v=u+1;v<n;v++){
			bool important=true;
			for(int w=0;w<n;w++){
				if(w==u || w==v) continue;
				if( a[u][w]+a[w][v] < a[u][v] ){
					cout<<-1<<endl;
					return 0;
				}else if(a[u][w]+a[w][v] == a[u][v]){
					important=false;
				}
			}
			if(important) res+=a[u][v];
		}
	}

	cout<<res<<endl;

	return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

ll N, A, B;

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

  std::cout << std::min(N*A, B) << std::endl;

  return 0;
}

Measured memory_bytes: 256
//---------- begin union_find ----------
#[allow(dead_code)]
mod union_find {
    pub struct UF {
        p: Vec<i32>,
    }
    impl UF {
        pub fn new(n: usize) -> UF {
            UF {p: vec![-1; n] }
        }
        pub fn init(&mut self) {
            for p in self.p.iter_mut() {
                *p = -1;
            }
        }
        pub fn root(&mut self, mut x: usize) -> usize {
            while self.p[x] >= 0 {
                x = self.p[x] as usize;
            }
            x
        }
        pub fn same(&mut self, x: usize, y: usize) -> bool {
            self.root(x) == self.root(y)
        }
        pub fn unite(&mut self, mut x: usize, mut y: usize) -> Option<(usize, usize)> {
            x = self.root(x);
            y = self.root(y);
            if x == y {
                return None;
            }
            if self.p[x] > self.p[y] {
                let s = x;
                x = y;
                y = s;
            }
            self.p[x] += self.p[y];
            self.p[y] = x as i32;
            Some((x, y))
        }
        pub fn get_size(&mut self, x: usize) -> usize {
            let r = self.root(x);
            (-self.p[r]) as usize
        }
    }
}
//---------- end union_find ----------
use std::io::Read;
use std::cmp::min;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let q: usize = it.next().unwrap().parse().unwrap();
    let mut e = vec![];
    let mut dp = vec![1_000_500_000; n];
    for _ in 0..q {
        let a: usize = it.next().unwrap().parse().unwrap();
        let b: usize = it.next().unwrap().parse().unwrap();
        let c: u64 = it.next().unwrap().parse().unwrap();
        e.push((a, b, c));
        dp[a] = min(dp[a], c + 1);
        dp[b] = min(dp[b], c + 2);
    }
    for i in 1..n {
        dp[i] = min(dp[i], dp[i - 1] + 2);
    }
    dp[0] = min(dp[0], dp[n - 1] + 2);
    for i in 1..n {
        dp[i] = min(dp[i], dp[i - 1] + 2);
    }
    dp[0] = min(dp[0], dp[n - 1] + 2);
    for i in 0..n {
        e.push((i, (i + 1) % n, dp[i]));
    }
    e.sort_by_key(|e| e.2);
    let mut u = union_find::UF::new(n);
    let mut sum = 0;
    for (a, b, c) in e {
        if let Some(_) = u.unite(a, b) {
            sum += c;
        }
    }
    println!("{}", sum);
}

fn main() {
    run();
}


Measured memory_bytes: 27252
N,Q = (int(i) for i in input().split())
S = input()
acl = [0] * N
cnt = 0

for j in range(1,N):
  if S[j-1] == 'A' and S[j] == 'C':
    cnt += 1
  acl[j] = cnt
      
for k in range(Q):
  x,y = (int(i)-1 for i in input().split())
  print(acl[y]-acl[x])

Measured memory_bytes: 6212
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll pair<ll,ll>
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 100005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

vector<ll> v[N];
ll ans[N];
void dfs(ll id,ll p1)
{
    ll cnt = 0;
    ll s = 0;
    vector<ll> v1;
    for(auto X:v[id])
    {
        if(X!=p1)
        {
            cnt++;
            dfs(X,id);
            v1.pb(ans[X]);
        }
    }
    sort(all(v1));
    for(auto X:v1)
    {
        s = max(s,X+cnt);
        cnt--;
    }
    ans[id] = s;
}
void solve()
{
    ll n;
    cin >> n;
    for(ll i=2,x;i<=n;i++)
    {
        cin >> x;
        v[x].pb(i);
        v[i].pb(x);
    }
    dfs(1,0);
    cout<<ans[1];
}

int main()
{
    FAST;
    ll t = 1;
   // cin >> t;
    while(t--)
    {
        solve();
    }
}

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

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

    bool s = false;
    while (n) {
        if (n % 10 == 7) s = true;
        n /= 10;
    }

    cout << (s ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());

		if (a + b >= 10) {
			System.out.println("error");
		} else {
			System.out.println(a + b);
		}
	}

}


Measured memory_bytes: 22740
import sys
k=int(input())
if k%2==0 or k%5==0:
    print(-1)
    sys.exit()
else:
    if k%7==0:
        l=(k//7)*9
    else:
        l=9*k
        
    j = 1
    n = 10
    rem = n%l
    while True:
        if rem == 1:
            print(j)
            sys.exit()
        rem = (rem*10)%l
        j+=1

Measured memory_bytes: 63072
#include <iostream>

#include <algorithm>

using namespace std;

int main() {

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    int n, x, y;

    cin >> n >> x >> y;

    x--, y--;

    int ans[n];

    fill(ans, ans+n, 0);

    for (int i = 0; i < n; i++) {

        if (i < x) {

            int t = (x + y + 1) / 2;

            ans[1]++;

            ans[t-i+1]--;

            ans[x-i+1]++;

            ans[x-i+1+y-t]--;

            ans[x-i+2]++;

            ans[x-i+1+n-y]--;

        } else if (i <= y) {

            int t = min(y, i + (y - x + 1) / 2);

            ans[1]++;

            ans[t-i+1]--;

            ans[i-x+1]++;

            ans[i-x+1+y-t]--;

            t = min(i - x + 1, y - i);

            ans[t+1]++;

            ans[t+n-y]--;

        } else {

            ans[1]++;

            ans[n-i]--;

        }

    }

    for (int i = 1; i < n; i++) {

        ans[i] += ans[i-1];

        cout << ans[i] << endl;

    }

    return 0;

}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <numeric>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <numeric>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007

long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }

    ll ans = 0;
    ll sum = 0;
    ll sums = 0;

    ans = 0;

    for (int i = 0; i < n; i++)
    {
        sums += a[i];
        sums %= mod;
    }

    ans += (sums* sums)%mod;

    for (int i = 0; i < n; i++)
    {
        ans -= (a[i] * a[i]) % mod;

        if (ans < 0)
        {
            ans += mod;
        }

        ans %= mod;
    }



    ans= ans*modinv(2, mod);
    ans %= mod;

    cout << ans << endl;
}

/*
int main()
{
    int n;cin >> n;
    vector<ll> a(n);
    vector<ll> b(n-1);
    rep(i,n) {
        cin >> a[i];
    }

    ll ans = 0;
    ll sum = 0;
    for (int i = 1; i < n; i++)
    {
        sum += a[i];  
    }


    int i = 1;
    for(int j = 0; j < n - 1; j++) {
        b[j] = sum;
        sum -= a[i++];
    }

    for(int i = 0; i < n - 1; i++) {
        ans += (b[i]%mod)*(a[i]%mod);
        ans %= mod;
    }



    cout << ans << endl;

}
*/

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

int main(){
    ll n;
    cin >> n;
    vector<int> a(n);
    for(ll i=0; i<n; i++){
        cin >> a.at(i);
    }
    vector<ll> ans(n);
    for(ll i=n-1; i>=0; i--){
        //ans.at(i)を後ろから決める
        ans.at(i) = a.at(i);
        if(ans.at(i) == 0) continue;
        for(ll j=1; j*j<=(i+1); j++){
            if((i+1)%j == 0){
                a.at(j-1) = 1-a.at(j-1);
                ll m = (i+1)/j;
                if(m*m>(i+1) & m!=(i+1)) a.at(m-1) = 1-a.at(m-1);
            }
        }
    }
    ll sum_ball=0;
    for(ll i=0; i<n; i++){
        sum_ball += ans.at(i);
    }
    cout << sum_ball << endl;
    for(ll i=0; i<n; i++){
        if(ans.at(i) == 1){
            cout << i+1 << ' ';
        }
    }
}


Measured memory_bytes: 5616
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>


#define int  long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define pf push_front
#define eb emplace_back //FASTER THAN PUSH BACK!
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define mi multiset<int>
#define mii multiset<pii>
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>


// using namespace __gnu_pbds;
using namespace std;

int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}

int modp(int a,int n)
{
    if(n==0) return 1;
    if(n==1) return a%mod;
    int res=modp(a,n/2);
    if(n%2==0) return (res*res)%mod;
    else return (a*res*res)%mod;
}

vi adj[200005],child(200005,0);
vector<bool> vis(200005,false);


void dfs(int s)
{
    vis[s]=true;
    
    for(int u:adj[s])
    {
        if(!vis[u])
        {
            vis[u]=true;
            dfs(u);
            child[s]++;
        }
    }
}

void solve()
{
    int t,n,m,i,k,l,r,u,v,w,j,s,sum=0,pos=-5,flag=0,count=0;
    string S,T,U;
    
    cin>>n;
    vi a(n+1);
    rep(i,2,n+1)
    {
        cin>>a[i];
        adj[i].pb(a[i]);
        adj[a[i]].pb(i);
    }
    dfs(1);
    rep(i,1,n+1) cout<<child[i]<<"\n";
}




signed main()
{
    #ifndef ONLINE_JUDGE 
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 26588
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
const int M = 100000;
const double pi = 3.141592653589;

int main()
{
	int a, b;
	char c;
	while (1) {
		cin >> a >> c >> b;
		if (c == '?') break;
		if (c == '+') {
			cout << a + b << endl;
		}
		else if (c == '-') {
			cout << a - b << endl;
		}
		else if (c == '*') {
			cout << a*b << endl;
		}
		else if (c == '/') {
			cout << a / b << endl;
		}

	}
	return 0;
}

Measured memory_bytes: 3108
n,a,b=map(int,input().split())
V=list(map(int,input().split()))
V.sort(reverse=True)
A=V[:a]
B=V[:b]
ave=sum(A)/a
print(ave)
C=[[0]*51 for _ in range(51)]
C[0][0]=1
for i in range(50):
    C[i+1][0]=1
    C[i+1][i+1]=1
    for j in range(i):
        C[i+1][j+1]=C[i][j]+C[i][j+1]
if A[0]==A[-1]:
    ans=0
    x=V.count(A[0])
    for i in range(a,b+1):
        if i<=x:
        	ans+=C[x][i]
else:
    x=V.count(A[-1])
    y=A.count(A[-1])
    ans=C[x][y]
print(ans)

Measured memory_bytes: 9264
import java.util.Scanner;

/**
 * Main
 */
public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        int N = s.nextInt();
        String S = s.next();

        String res = "No";

        if (N % 2 == 0)  {
            if (S.substring(N/2).equals(S.substring(0, N/2))) res = "Yes";
        }

        System.out.println(res);
        s.close();
    }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std;

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

	int len = s.size();
	long long int count = 0;

	for (int i = len - 1; i >= 0; i--)
	{
		if (s[i] == 'B')
		{
			count += len - i-1;
			len--;
		}
	}

	printf("%lld", count);
}

Measured memory_bytes: 640
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b,c = LI()
    if min(a,b) < c < max(a,b):
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = I()
    s = S()
    k = I()
    f = s[k-1]
    for i in range(n):
        if s[i] != f:
            print("*",end = "")
        else:
            print(s[i],end = "")
    print()
    return

#C
def C():
    n = I()
    s = S()
    ans = 0
    f = [0]*(n+1)
    for i in range(n):
        f[i+1] = 1 if s[i] == "#" else 0
    for i in range(n):
        f[i+1] += f[i]
    ans = float("inf")
    for i in range(n+1):
        ans = min(ans, f[i]+(n-i)-f[n]+f[i])
    print(ans)
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#G
def G():

    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 66544
#include<stdio.h>
int main(){
  int a,b,i,j,k=0;
  while(1){
    j=0;
    scanf("%d %d",&a,&b);
    if((a==0) && (b==0)){
      break;
    }
    if(k!=0){
      printf("\n");
    }
    k++;

    for(i=a;i<=b;i++){
      if(i%400==0){
	printf("%d\n",i);
	j=1;
      }

      else if((i%4==0) && (i%100!=0)){
	printf("%d\n",i);
	j=1;
      }

    }
    if(j==0){
      printf("NA\n");
    }
  }
  return (0);
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h, n;
  cin >> h >> n;
  while(n--){
    int x;
    cin >> x;
    if((h -= x) <= 0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#define rep(i,n) for(int i = 0; i <(n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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


int main(void) {
	constexpr int AB_MAX = 2, A = 0, B = 0;
	int N, M, a, b, tmp, ans;
	vector<vector<int>> ab;
	int dp[AB_MAX] = {-1,10000000};

	scanf("%d %d", &N, &M);
	int i, j, k;
	rep(i, M) {
		scanf("%d %d", &a, &b);
		vector<int> t;
		t.push_back(a);
		t.push_back(b);
		ab.push_back(t);
	}
	sort(ab.begin(), ab.end());
	ans = 1;
	rep(i, M) {//全部の要望
		a = ab.at(i).at(0);//一旦保持
		b = ab.at(i).at(1);

		//最善を求めていく→dpへ格納
		//前方比較
		if (a >= dp[0]) {//最善より大きい
			if (a >= dp[1]) {//最善の後方と一緒または大きい
				ans++;//最善を一つ進める
				dp[0] = a;
				dp[1] = b;
			}
			//後方比較
			if (b < dp[1]) {//最善より小さい
				dp[1] = b;//最善を狭める
			}
		}
	}

	printf("%d", ans);

	return 0;
}

Measured memory_bytes: 6836
#include <stdio.h>

int main(){
  int n,i,j,min,tmp,num=0,a[100];
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(a[j]<a[min]) min=j;
    }
      tmp=a[i];
      a[i]=a[min];
      a[min]=tmp;
      if(i!=min) num++;
  }

  for(i=0;i<n;i++){
    if(i<n-1) printf("%d ",a[i]);
    else printf("%d\n",a[n-1]);
  }

  printf("%d\n",num);
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
 
#define INT_INF (2 * 1e9)
#define LL_INF  (2LL * 1e18)
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << endl;
#else
#define DBG(X)
#endif
 
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll mod = 1e9 + 7;

void solve()
{
	int n, m;
	vector<int> xs, diff;

	cin >> n >> m;
	xs.resize(m);
	diff.resize(m - 1);

	for(auto& el: xs)
		cin >> el;	

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

	for(int i = 0; i < m - 1; ++i)
		diff[i] = xs[i + 1] - xs[i];

	sort(diff.rbegin(), diff.rend());

	int ans = xs[m - 1] - xs[0];

	for(int i = 0; i < m - 1 && i < n - 1; ++i)
		ans -= diff[i];

	cout << ans << endl;
}

int main(int argc, char** argv)
{
	FAST_IO;
	solve();

	return 0;
}


Measured memory_bytes: 1024
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    char a=s[s.size()-1];
    if(a=='3'){cout<<"bon";}
    else if(a=='0'||a=='1'||a=='6'||a=='8'){cout<<"pon";}
    else{cout<<"hon";}

    return 0;
}


Measured memory_bytes: 3596
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef vector<int> V;
typedef vector<vector<int> > VV;
typedef long long ll;
const int inf = 2e9;
const int mod = 1e9 + 7;
const long double eps = 1e-10;


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

	if ((a<0&&0<b) || a==0 || b==0) {
		cout << "Zero" << endl;
		return 0;
	}

	if (a>0 && b>0) {
		cout << "Positive" << endl;
		return 0;
	}

	if ((abs(a)-abs(b))%2 == 0) {
		cout << "Negative" << endl;
	}
	else cout << "Positive" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b,n;cin>>a>>b>>n;
    ll ans;
    if(n<b-1){
        ans = (a*n/b)-a*(n/b);
    }
    else{
        ans = (a*(b-1)/b)-a*((b-1)/b);
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>

using namespace std;

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

    int card[n];
    for (int i = 0; i < n; ++i) {
        cin >> card[i];
    }
    sort(card, card + n, greater<int>());

    int a = 0, b = 0;
    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0) {
            a += card[i];
        } else {
            b += card[i];
        }
    }
    cout << a - b << endl;
}

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

def factorizaion(n):
    p=2
    fcr=[]
    while p*p<=n:
        while n%p==0:
            fcr.append(p)
            n//=p
        p+=1
    if n>1:
        fcr.append(n)
    return fcr

x=factorizaion(a)
y=factorizaion(b)
print(len(set(x)&set(y))+1)

Measured memory_bytes: 3060
// 自力で実装できるかといわれるとひっかかりそう…
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, y;
  cin >> n >> y;
  int num10k = -1;
  int num5k = -1;
  int num1k = -1;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; (i + j) <= n; j++) {
      if (10000 * i + 5000 * j + 1000 * (n - i - j) == y) {
        num10k = i;
        num5k = j;
        num1k = n - i - j;
      }
    }
  }
  cout << num10k << " " << num5k << " " << num1k << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9+7;

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

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

int main(){

	int h, w;
	char pi[256][256];

	cin >> h >> w;

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

	for(int i = 0; i < h; i++)
		cout << pi[i] << endl << pi[i] << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  long long N, A, B, q, r; cin >> N >> A >> B;
  q = N / (A + B);
  r = N % (A + B);
  if(r > A) r = A;
  cout << q * A + r << endl;
  return 0; 
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const ll inf = 1e18;

struct UnionFind_QFW {
    vector<int> i2g;         // i2g[i]:アイテムiの所属するグループの番号
    /* アイテムの種類を変えたいときは↓を変更 */
    vector<vector<int>> g2i; // g2i[g]:グループgに所属するアイテムたち

    UnionFind_QFW(int n) {
        i2g.resize(n);
        g2i.resize(n);
        for (int i = 0; i < n; i++) {
            i2g[i] = i;
            g2i[i].assign(1, i); // アイテムiを１つ割り当てる
        }
    }

    // 同じグループに所属しているか
    bool same(int ix, int iy) {
        return i2g[ix] == i2g[iy];
    }

    // xの所属するグループとyの所属するグループを結合
    void merge(int ix, int iy) {
        if (same(ix, iy)) return; // 同じグループなら何もしない

        // グループxのアイテム数 > グループyのアイテム数  となるように(※ 一般的なマージテク)
        if (g2i[i2g[ix]].size() < g2i[i2g[iy]].size()) {
            swap(ix, iy);
        }

        // gxの要素数 > gyの要素数
        int gx = i2g[ix];
        int gy = i2g[iy];
        for (int j : g2i[gy]) {
            i2g[j] = gx;
        }

        g2i[gx].insert(g2i[gx].end(), g2i[gy].begin(), g2i[gy].end()); // グループの結合
        g2i[gy].clear();
    }
};

int N,M;
int L[100010];
bool exist[100010];
string ans;
int main(){
    cin >> N >> M;
    ans = "YES";
    UnionFind_QFW uf(M);
    REP(i,0,N){
        int K;
        cin>>K;
        REP(i,0,K){
            cin>>L[i];
            L[i]--;
            exist[L[i]]=true;
        }
        REP(i,0,K-1){
            uf.merge(L[i], L[i+1]);
        }
    }
    vector<int> ex;
    REP(i,0,M){
        if(exist[i]) ex.push_back(i);
    }
    REP(i,0,ex.size()-1){
        if(!uf.same(ex[i],ex[i+1])){
            ans="NO";
            break;
        }
    }
    p(ans);
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  for(int i=0; i < s.size(); i++){
    if(i%2 == 0){
      if(s[i]=='L'){
        cout << "No" << endl;
        return 0;
      }
    }else{
      if(s[i]=='R'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

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

int main(){
  int k,s,ans;
  ans = 0;
  cin >> k >> s;
  for(int i=0; i<k+1; i++){
    for(int j=0; j<k+1; j++){
      if(s-i-j>=0 && s-i-j<=k){
        ans+=1;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


/*
int N;
Graph G;

int main() {
  cin >>N;
  rep(i, N-1){
    int a,b; cin >>a >>b; a--; b--;
    G[a].push_back(b); G[b].push_back(a);
  }
}
*/

int main() {
  vector<int> n(4); rep(i, 4) cin >>n[i];
  string s = "1111";
  rep(i, 4) s[i] = (char)('0' + n[i]);
  sort(all(s));
  cout <<(s == "1479" ? "YES" : "NO") <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	//nを入力
	int a, b, c;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	//計算
	c = c - (a - b);
	if(c < 0){
		c = 0;
	}
	//表示
	printf("%d", c);

	return 0;
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  string s;

  cin >> s;

  bool flag = true;
  FOR (i, 1, s.length()) {
    if (s[i] != '9') flag = false;
  }

  int ans = 0;
  if (flag) {
    REP (i, s.length()) ans += s[i] - '0';
  } else {
    ans = (s.length() - 1) * 9 + (s[0] - '0') - 1;
  }

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


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


int main(void){
	int n, ans;
  cin >> n;
  ans = n;
  for(int i = 1; i<n; i++){
    if(n-i <=(i-1)*i/2){
      ans = i;
      break;
    }
  }
  cout << ans;
  
}


Measured memory_bytes: 3608
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

class Edge
{
public:
    int to, cost;
    Edge(int to, int cost){
        this->to = to;
        this->cost = cost;
    }
};

vector<vector<int> > memo;

int solve(const vector<vector<Edge> >& edges, int curr, int prev, int isBack)
{
    if(edges[curr].size() == 1 && prev != -1)
        return 0;
    if(memo[isBack][curr] != -1)
        return memo[isBack][curr];

    int sum = 0;
    int maxDiff = 0;
    for(unsigned i=0; i<edges[curr].size(); ++i){
        int next = edges[curr][i].to;
        int cost = edges[curr][i].cost;
        if(next == prev){
            sum += cost;
            if(isBack == 1)
                sum += cost;
        }
        else{
            sum += cost + solve(edges, next, curr, 1);
            if(isBack == 0){
                int diff = solve(edges, next, curr, 1) - solve(edges, next, curr, 0);
                maxDiff = max(maxDiff, diff);
            }
        }
    }

    int ret = sum - maxDiff;
    return memo[isBack][curr] = ret;
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<int> p(n+11);
        for(int i=2; i<=n; ++i)
            cin >> p[i];

        vector<vector<Edge> > edges(n+1);
        for(int i=2; i<=n; ++i){
            int d;
            cin >> d;
            edges[i].push_back(Edge(p[i], d));
            edges[p[i]].push_back(Edge(i, d));
        }

        int ret = INT_MAX;
        for(int i=1; i<=n; ++i){
            memo.assign(2, vector<int>(n+1, -1));
            ret = min(ret, solve(edges, i, -1, 0));
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 1360
list = input().split()
M = int(list[0])
D = int(list[1])

cnt = 0
for m in range(1, M+1):
    if D < 22:
        break
    for d in range(22, D+1):
        d10 = d // 10
        d1 = d % 10
        if d1 < 2:
            continue
        if d1 * d10 == m:
            cnt = cnt + 1

print(cnt)

Measured memory_bytes: 3060