akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(a, b) for(int a = 0; a < b; a++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//shuffle(permutation.begin(), permutation.end(), rng);
//uniform_int_distribution<int>(l, r)(rng);

ll rek(ll a, ll b) {
	if (b == 0) return -a;
	ll now = 2 * (a / b) * b + rek(b , a % b);
	return now; 
}

ll n, x;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> x;
	cout << n + rek(n - x, x) << '\n';
}

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

int main() {
	string s1("");
	int l, i, out, ans = 0;
	while (cin >> s1) {
		out = 0;
		l = s1.size();
		for (i = 0; i < l / 2; i++) {
			if (s1.at(i) != s1.at(l - i - 1)) {
				out = 1;
				break;
			}
		}
		if (out == 0) {
			ans = ans + 1;
		}
	}
	cout << ans << endl;
	return 0;

}



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

using namespace std;
using ll = long long;

template <int MOD>
struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
    constexpr Fp operator+(const Fp& r) const noexcept {
        return Fp(*this) += r;
    }
    constexpr Fp operator-(const Fp& r) const noexcept {
        return Fp(*this) -= r;
    }
    constexpr Fp operator*(const Fp& r) const noexcept {
        return Fp(*this) *= r;
    }
    constexpr Fp operator/(const Fp& r) const noexcept {
        return Fp(*this) /= r;
    }
    constexpr Fp& operator+=(const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator-=(const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator*=(const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator/=(const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator==(const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator!=(const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator<<(ostream& os,
                                         const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD>& a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

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

    mint output = 1;
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    } else if (N == 2) {
        cout << 2 << endl;
        return 0;
    }

    for (int i = 1; i <= N; i++) {
        output *= 10;
    }
    mint tmp = 1;
    for (int i = 1; i <= N; i++) {
        tmp *= 9;
    }
    output -= tmp * 2;
    tmp = 1;
    for (int i = 1; i <= N; i++) {
        tmp *= 8;
    }
    output += tmp;

    cout << output << endl;

    return 0;
}


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

using namespace std;

const long long p = 998244353;
vector<long long> fact;

long long inv(long long x) {
	long long e = p - 2;
	long long result = 1;
	while(e != 0) {
		if(e % 2 == 1) {
			result *= x;
			result %= p;
		}
		e /= 2;
		x *= x;
		x %= p;
	}
	return result;
}

long long comb(long long n, long long r) {
	return (((fact[n] * inv(fact[n - r])) % p) * inv(fact[r])) % p;
}

int main(void) {
	long long N, A, B, K;
	cin >> N >> A >> B >> K;
	fact = vector<long long>(N + 1, 1);
	for(int n = 1; n <= N; ++n) {
		fact[n] = (fact[n - 1] * n) % p;
	}
	long long result = 0;
	for(long long i = 0; i <= N && i * A <= K; ++i) {
		if((K - i * A) % B != 0) continue;
		long long j = (K - i * A) / B;
		if(N < j) continue;
		result += comb(N, i) * comb(N, j);
		result %= p;
	}
	result %= p;
	cout << result << '\n';
	return 0;
}



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

int main(){
  int d,n;
  cin >> d >> n;
  if(n==100) n=101;
  if(d==0) cout << n << endl;
  if(d==1) cout << n*100 << endl;
  if(d==2) cout << n*10000 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <queue>
#include <map>
#include <list>
//#include <bits/stdc++.h>


using namespace std;

#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
typedef long long ll;

int main(){
    int a, b, mx, mn;
    cin >> a >> b;
    mx = max(a,b);
    mn = min(a,b);
    cout << mx+max(mx-1,mn) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "YES" : "NO";
}

int main(){
    string s; cin >> s;
    
    int dif = 10000;
    
    rep(i,s.length()-2){
    	int a = s[i]-'0';
    	int b = s[i+1]-'0';
    	int c = s[i+2]-'0';
    	
    	int x = 100*a + 10*b + c;
    	
    	if(abs(753-x)<dif) {
    		dif = abs(753-x);
    	}
    }
    
    cout << dif << endl;
}









Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0167
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                int n = RInt();
                if (n == 0) break;

                int[] a = new int[n];
                for (int i = 0 ; i < n ; i++)
                {
                    a[i] = RInt();
                }
                Console.WriteLine(BubbleSort(a));
            }
        }

        /// <summary>
        /// バブルソート
        /// </summary>
        /// <param name="array">対象配列</param>
        /// <returns>交換回数</returns>
        public static int BubbleSort(int[] array)
        {

            int swapTimes = 0;
            bool flg = true;
            while (flg)
            {
                flg = false;
                for (int i = array.Count() - 1 ; i > 0 ; i--)
                {
                    if (array[i] < array[i - 1])
                    {
                        int tmp = array[i];
                        array[i] = array[i - 1];
                        array[i - 1] = tmp;
                        swapTimes++;
                        flg = true;
                    }
                }
            }
            return swapTimes;
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



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

#define int long long

#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))
#define upp(a,b) upper_bound(all(a),(b))
#define fill(i,n) memset(i,n,sizeof i)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N,K;
int a[10010];
int sum[10010];
vint vcnt;
int cnt;
int cntcnt,x;
int ans=0,now=0;



signed main() {
    IOS();
    cin>>N>>K;
    rep(i,0,N){
        cin>>a[i];
        sum[i+1]=sum[i]+a[i];
    }
    rep(i,0,N)rep(j,i+1,N+1){
        x=sum[j]-sum[i];
        vcnt.pb(x);
    }
    sort(all(vcnt));
    rrep(i,0,40+1){
        now=0;
        now|=ans;
        now|=(1ll<<i);
        cnt=0;
        for(auto e:vcnt){
            if((e&now)==now)cnt++;
        }
        if(cnt>=K)ans|=now;
    }
    cout<<ans<<endl;
    
    
    return 0;
}

Measured memory_bytes: 5616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEsL 2e9
#define PIE 3.1415a926535

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 GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

int n,m;
vector<int> s, c;

bool is_ok(string str){
    if (str.size() != n)
        return false;
    for(int i=0; i< m;i++) if (str[s[i]] != (char)(c[i]+'0')) return false;
    return true;
}

int main(){
    cin >> n >> m;
    s.resize(m);
    c.resize(m);
    for(int i=0;i< m;i++) cin >> s[i] >> c[i], s[i]--;
    for(int i=0;i<1000;i++){
        stringstream o; o << i;
        string stri = o.str();
        if(is_ok(stri)) {cout << stri << endl; return 0;}
        
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	s := wordScanner()

	var n, a, b int
	scanInts(s, &n, &a, &b)

	fmt.Println(min(a*n, b))
}

func wordScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return s
}

func scanInts(s *bufio.Scanner, vals ...*int) {
	for i := range vals {
		s.Scan()
		n, _ := strconv.Atoi(s.Text())
		*vals[i] = n
	}
}

func scanStrings(s *bufio.Scanner, vals ...*string) {
	for i := range vals {
		s.Scan()
		*vals[i] = s.Text()
	}
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main()
{
    int n,ans=0;
    cin>>n;
    vector<int> a(n),b(n);
    for(int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    for(int i = 0; i < n; i++)
    {
        cin>>b[i];
    }
    
    for(int d = 0; d < n; d++)
    {
        int tmp=0;
        for(int i = 0; i < n; i++)
        {
            if(i<=d) tmp+=a[i];
            if(d<=i) tmp+=b[i];
        }
        ans=max(ans,tmp);
    }
    

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans_list = []
k = 0
while k <= a:
  m = 0
  while m <= b:
    n =0
    while n <= c:
      hoge = k*500+m*100+n*50
      ans_list.append(hoge)
      n += 1
    m += 1
  k += 1
print(ans_list.count(x))

Measured memory_bytes: 8404
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,k,l[55],ans=0;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	    cin>>l[i];
	sort(l,l+n);
	reverse(l,l+n);
	for(int j=0;j<k;j++)
	    ans+=l[j];
	cout<<ans;
	return 0;
}

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

int main() {

  int n;
  cin >> n;

  vector<string>a(n),b(n);
  for(int i=0; i<n; i++){
    cin >> b[i];
  }
  
  for(int i=0; i<n; i++){
    for(int j=n-i; j>=1; j--){
      string s = to_string(j);
      if(b[j-1]==s){
        a[n-i-1]=s;
        for(int k=j-1; k<n-i-1; k++){
          b[k]=b[k+1];
        }
        b[n-i-1]="0";
        break;
      }
    }
  }
  
  for(int i=0; i<n; i++){
    if(b[i]!="0"){
      cout << -1 << endl;
      return 0;
    }
  }

  for(int i=0; i<n; i++){
    cout << a[i] << endl;
  }
}

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

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

	int n, m;
	cin >> n >> m;
	int a[m+1];
	for(int i=1; i<=n; i++){
		a[i] = 0;
	}
	pair<int, int> p[50];
	for(int i=0; i<m; i++){
		cin >> p[i].first >> p[i].second;
	}
	sort(p, p+m);

	for(int i=0; i<m-1; i++){
		if(p[i].first == p[i+1].first && p[i].second != p[i+1].second){
			cout << "-1";
			return 0;
		}
	}
	if(p[0].first == 1 && p[0].second == 0){
		if(n>1){
			cout << "-1";
			return 0;
		}
		else{
			cout << "0";
			return 0;
		}
	}

	for(int i=0; i<m; i++){
		a[p[i].first] = p[i].second;
	}
	if(a[1] == 0 && n>1) a[1] = 1;

	for(int i=1; i<=n; i++){
		cout << a[i];
	}

    return 0;
}


Measured memory_bytes: 256
from collections import Counter

mod = 10 ** 9 + 7
N = int(input())
X = list(map(int,input().split()))
L = [0] * N
for i in range(N-1):
    L[i+1] += L[i]
    if X[i] > L[i] * 2:
        L[i+1] += 1

for i in range(N):
    L[i] = i - L[i]

d = Counter(L)
ans = 1
tmp = 0
for i in range(10 ** 5):
    tmp += d[i]
    if tmp == 0:
        break
    ans *= tmp
    ans %= mod
    tmp -= 1
print(ans)

Measured memory_bytes: 21808
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll n,m; cin >> n >> m;
	vl h(n); rep(i,n) cin >> h[i];
	vvl G(n);
	rep(i,m){
		ll u,v; cin >> u >> v; u--; v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	ll ans = 0;
	rep(i,n){
		bool flag = true;
		for(auto v : G[i]){
			if(h[i] <= h[v]) flag = false;
		}
		if(flag) ans++;
	}
	cout << ans << endl;
}

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

import sys


class Die:
    def __init__(self, pips):
        self.pips = pips

    def move_die(self, direction):
        if direction == 'N':
            tmp = self.pips[0]
            self.pips[0] = self.pips[1]
            self.pips[1] = self.pips[5]
            self.pips[5] = self.pips[4]
            self.pips[4] = tmp
            del tmp
        elif direction == 'S':
            tmp = self.pips[0]
            self.pips[0] = self.pips[4]
            self.pips[4] = self.pips[5]
            self.pips[5] = self.pips[1]
            self.pips[1] = tmp
            del tmp
        elif direction == 'E':
            tmp = self.pips[0]
            self.pips[0] = self.pips[3]
            self.pips[3] = self.pips[5]
            self.pips[5] = self.pips[2]
            self.pips[2] = tmp
            del tmp
        elif direction == 'W':
            tmp = self.pips[0]
            self.pips[0] = self.pips[2]
            self.pips[2] = self.pips[5]
            self.pips[5] = self.pips[3]
            self.pips[3] = tmp
            del tmp

    def spin_die_clockwise(self):
        tmp = self.pips[1]
        self.pips[1] = self.pips[2]
        self.pips[2] = self.pips[4]
        self.pips[4] = self.pips[3]
        self.pips[3] = tmp
        del tmp


def init_die():
    pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
    die = Die(pips)

    return die


def roll_die(die):
    directions = list(sys.stdin.readline().strip('\n'))

    for direction in directions:
        die.move_die(direction)

    return die


def question_rightside(die):
    q = int(sys.stdin.readline().strip('\n'))

    for question in range(q):
        q_pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]

        if q_pips[0] == die.pips[1]:
            die.move_die('N')
        elif q_pips[0] == die.pips[2]:
            die.move_die('W')
        elif q_pips[0] == die.pips[3]:
            die.move_die('E')
        elif q_pips[0] == die.pips[4]:
            die.move_die('S')
        elif q_pips[0] == die.pips[5]:
            die.move_die('N')
            die.move_die('N')

        while die.pips[1] != q_pips[1]:
            die.spin_die_clockwise()

        print(die.pips[2])


def main():
    die = init_die()
    question_rightside(die)


if __name__ == '__main__':
    main()

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 100005;
const int MOD = 1000000007;

int n;

map <int, int> mp;

int main() {

	FAST;

	cin >> n;
	for (int i = 2; i <= n; i ++) {
		int m = i;
		for (int j = 2; j * j <= i; j ++) {
			if (m % j == 0) {
				while (m % j == 0) {
					mp[j] ++;
					m /= j;
				}
			}
		}
		if (m != 1) mp[m] ++;
	}
	int ans = 1;
	for (auto p : mp) {
		ans = 1LL * ans * (p.second + 1) % MOD;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let n=read::<usize>();
    let m=read::<usize>();
    println!("{}",(n-2)/(m-1)+1)
}


Measured memory_bytes: 4476
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

from functools import reduce
from fractions import gcd
import collections

a,b = map(int,input().split())

aaa = reduce(gcd,[a,b])

c = collections.Counter(prime_factorize(aaa))
cnt = 0
for i in c:
  cnt += 1
print(cnt+1)

Measured memory_bytes: 5128
from collections import defaultdict
N = int(input())
d = defaultdict(int)

for i in range(N):
    S = input()
    # ソートして一般化する
    S = sorted(S)
    str = ""
    for s in S:
        str += s
    d[str] += 1

# 足し上げる
ans = 0
for k in d.keys():
    num = d[k]
    ans += num*(num-1)//2

print(ans)

Measured memory_bytes: 18232
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int a,b,c;
  cin>>a>>b>>c;
  if(a <= c && c <= b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
function main (s) {
	s=s.split(" ");
	for(var i=0;i<3;i++)s[i]=parseInt(s[i]);
    console.log((Math.abs(s[0]-s[1])<Math.abs(s[0]-s[2]))?"A":"B");
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
class UnionFind:
    def __init__(self, n):
        self.nodes = n
        self.parents = [i for i in range(n)]
        self.sizes = [1] * n
        self.rank = [0] * n

    def find(self, i): # どの集合に属しているか（根ノードの番号）
        if self.parents[i] == i:
            return i
        else:
            self.parents[i] = self.find(self.parents[i]) # 経路圧縮
            return self.parents[i]

    def unite(self, i, j): # 二つの集合を併合
        pi = self.find(i)
        pj = self.find(j)
        if pi != pj:
            if self.rank[pi] < self.rank[pj]:
                self.sizes[pj] += self.sizes[pi]
                self.parents[pi] = pj
            else:
                self.sizes[pi] += self.sizes[pj]
                self.parents[pj] = pi
                if self.rank[pi] == self.rank[pj]:
                    self.rank[pi] += 1
    def same(self, i, j): # 同じ集合に属するかを判定
        return self.find(i)==self.find(j)

    def get_parents(self): # 根ノードの一覧を取得
        for n in range(self.nodes): # findで経路圧縮する
            self.find(n)
        return self.parents


N, M = map(int, input().split())
AB = []
B = []
for m in range(M):
    a, b = map(int, input().split())
    AB.append((a-1,b-1))

ans = []
score = N * (N-1) // 2
uf = UnionFind(N)
for a, b in AB[::-1]:
    ans.append(score)
    if uf.same(a,b):
        pass
    else:
        pa = uf.find(a)
        pb = uf.find(b)
        score -= uf.sizes[pa] * uf.sizes[pb]
        uf.unite(a,b)    

for score in ans[::-1]:
    print(score)
    




Measured memory_bytes: 24884
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 500100;

ll cnt;
ll n, a, b;

int main() {
	cin>>n;

	ll result = 0LL;
	for(int i=1;i<=n;i++) {
		result += i * (n - i + 1);
	}
	for(int i=0;i<n-1;i++) {
		cin>>a>>b;
		if(a > b) swap(a, b);
		result -= a * (n - b + 1);
	}
	cout<<result<<"\n";
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

const int MAX_N = 1e5+20;
int N;
ll x[MAX_N];
ll l[MAX_N];
int dp[MAX_N];

void solve()
{
	vector<pair<ll,ll>> p;
	for(int i=0;i<N;++i) p.emplace_back(x[i]-l[i], x[i]+l[i]);
	sort(p.begin(), p.end(), [](const pair<ll,ll>&p1, const pair<ll, ll>&p2){return p1.second<p2.second;});
	int pre=-INF;
	int ans = 0;
	for(auto x : p){
		if(x.first >= pre){
			ans++;
			pre = x.second;
		}
	}
	cout << ans << '\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	for(int i=0;i<N;++i){
		cin >> x[i] >> l[i];
	}
	solve();
	return 0;
}

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

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

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

    int ans = 0;
    int status = 0; // 0-first 1-ambiguous 2-ascending 3-descending
    for(int i = 0; i < n; i++){
        if(status == 0){
            status = 1;
            continue;
        }else if(status == 1){
            if(a[i-1] < a[i])       status = 2;
            else if(a[i-1] > a[i])  status = 3;
        }else if(status == 2){
            if(a[i-1] > a[i]){
                ans++;
                status = 1;
            }
        }else if(status == 3){
            if(a[i-1] < a[i]){
                ans++;
                status = 1;
            }
        }
    }
    ans++;

    cout << ans << endl;

    return 0;
}

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

import math
import cmath

A, B, H, M = map(int, input().split())

def rate_to_arg(rate):
    return - 2 * math.pi * rate

short_rate = (H * 60 + M) / 720
long_rate = M / 60

short = 0 + A * 1j
short *= cmath.rect(1.0, rate_to_arg(short_rate))

long = 0 + B * 1j
long *= cmath.rect(1.0, rate_to_arg(long_rate))

print("{:.20f}".format(abs(long - short)))




Measured memory_bytes: 9424
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = 5*1e3+5;

int n;
string s;
long long hs[N], p = 37, mod = 1e9+7, pp[N];
long long hs2[N], p2 = 31, pp2[N];

long long fast_pow(long long x, long long y) {
	long long ret = 1;
	for(;y;y>>=1) {
		if(y&1) ret=ret*x%mod;
		x=x*x%mod;
	}
	return ret;
}

long long givehs(int l, int r) {
	long long ret = hs[r];
	if(l) ret = (ret-hs[l-1]+mod)%mod;
	long long div = pp[n-1-r];
	return ret*div%mod;
}

long long givehs2(int l, int r) {
	long long ret = hs2[r];
	if(l) ret = (ret-hs2[l-1]+mod)%mod;
	long long div = pp2[n-1-r];
	return ret*div%mod;
}


bool check(int len) {
	map<pair<long long, long long>, pair<int, int> > mp;
	if(len==0) return true;
	for(int i=0;i<n;i++) {
		if(i+len-1 >= n) break;
		long long now = givehs(i, i+len-1);
		long long now2 = givehs2(i, i+len-1);
		pair<long long, long long> go = make_pair(now, now2);
		pair<int, int> x = make_pair(1e7, -1);
		if(mp.count(go)) x = mp[go];
		x.first = min(x.first, i);
		x.second = max(x.second, i);
		mp[go] = x;
	}
	for(auto x : mp) {
		if(x.second.first+len-1<x.second.second) return true;
	}
	return false;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	cin >> s;
	pp[0] = 1;
	pp2[0] = 1;
	for(int i=1;i<N;i++) {
		pp[i] = pp[i-1]*p%mod;
		pp2[i] = pp2[i-1]*p2%mod;
	}
	long long pw = p;
	hs[0] = s[0] - 'a' + 1;
	for(int i=1;i<n;i++) {
		hs[i] = (hs[i-1] + (s[i]-'a'+1)*pw%mod)%mod;
		pw = pw*p%mod;
	}
	pw = p2;
	hs2[0] = s[0] - 'a' + 1;
	for(int i=1;i<n;i++) {
		hs2[i] = (hs2[i-1]+(s[i]-'a'+1)*pw%mod)%mod;
		pw=pw*p2%mod;
	}
	int l = 0, r = n;
	int ans = 0;
	while(l <= r) {
		int m = (l+r) / 2;
		if(check(m)) {
			ans = m;
			l = m + 1;
		}
		else r = m-1;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 768
#include<stdio.h>
#include<string.h>
#define n 3

typedef struct{
    int A[n][n];
}puzzle;

int X[4]={0,1,0,-1};
int Y[4]={1,0,-1.0};

puzzle p;

int huri();
int dfs(int, int, int, int, int);
void target(puzzle);

int main(){
    int i,j,k,x,y,t;
    puzzle T;
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            scanf("%d",&p.A[i][j]);
            if(p.A[i][j]==0){
                x=j;
                y=i;
            }
        }
    }
    T=p;
    for(i=1;i<46;i++){
        p=T;
        t=dfs(x,y,i,0,-1);
        if(t!=-1){
            printf("%d\n",t);
            break;
        }
    }
    return 0;
}

int huri(){
    int i,j,sum=0,s,t;
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(p.A[i][j]==0)continue;
            t=(p.A[i][j]-1)/n-i;
            s=(p.A[i][j]-1)%n-j;
            if(s<0)sum=sum-s;
            else sum=sum+s;
            if(t<0)sum=sum-t;
            else sum=sum+t;
        }
    }
    return sum;
}
int dfs(int s, int t, int max, int count, int r){
    int i,tmp,x,y,time,l;
    l=huri();
    if(l==0)return count;
    else if(count+l>max)return -1;
    for(i=0;i<4;i++){
        x=s+X[i];
        y=t+Y[i];
        if((x<0||n<=x||y<0||3<=y)||(i==(r+2)%4 && r!=-1))continue;
        tmp=p.A[t][s];
        p.A[t][s]=p.A[y][x];
        p.A[y][x]=tmp;
        time=dfs(x,y,max,count+1,i);
        if(time != -1)return time;
        tmp=p.A[t][s];
        p.A[t][s]=p.A[y][x];
        p.A[y][x]=tmp;
    }
    return -1;
}


Measured memory_bytes: 2144
def main(argv)
  (n, x) = gets.chomp.split(' ').map(&:to_i)
  a = gets.chomp.split(' ').map(&:to_i)
  a.sort!

  s = a.reduce(:+)
  if s == x then
    puts n.to_s
    return
  elsif s < x then
    puts (n - 1).to_s
    return
  end

  # s > x
  cs = [0] * (n + 1)
  n.times { |i| cs[i + 1] = cs[i] + a[i] }
  puts (cs.select{|c| c <= x}.size - 1).to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    int N,T;cin>>N>>T;
    int A[100010];
    for(int i=0;i<N;i++)cin>>A[i];
    //M[i]:A[i]からA[N-1]の最大値
    int M[100010];
    M[N]=0;
    int i=N-1;
    while(i>=0){
        M[i]=max(M[i+1],A[i]);
        i--;
    }
    int ans=0,m=-2*pow(10,9);
    for(int i=0;i<N-1;i++){
        int s=M[i+1]-A[i];
        if(s>m){
            ans=1;
            m=s;
        }
        else if(s==m)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
N , H = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]

from operator import itemgetter
from math import ceil
AB.sort(key = itemgetter(1),reverse = True)

cut = max(AB,key = itemgetter(0))[0]
count = 0
for a,b in AB:
    if b < cut or H <= 0:
        break
    H -= b
    count += 1
if H > 0:
    count += ceil(H/cut)
    print(count)
else:
    print(count)

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

int main() {
  
  int N=0;
  
  cin >> N;
  
  if(N%2==0) {
    
    cout << (N/2)-1 << endl;
    
  } else {
    
    cout << N/2 << endl;
    
  }
  
  return 0;
  
}

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

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

const ll linf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };
const ll atcoder = 1e9 + 7;

#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define rep(i,n) for(int i= 0;i<n;i++)

ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

bool f[100010] = { false };
int a[100010];

int main(){
	
	int n;
	cin >> n;
	rep(i, n)cin >> a[i];
	int i = 1,cnt = 0;

	while(1){
		if (f[2] == true)break;
		else if (f[i] == true) {
			pr(-1);
			return 0;
		}
		f[i] = true;
		i = a[i -1];
		cnt++;
	}

	pr(--cnt);

	//system("pause");
	return 0;
}

Measured memory_bytes: 768
fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let s: String = std::io::Read::bytes(stdin.lock())
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    s.parse().ok().expect("error")
}

fn main() {
    let n: u32 = input();
    let k: u32 = input();
    println!("{}", if n % k == 0 { 0 } else { 1 });
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  map<char,char>m;
  m['A']='T';
  m['T']='A';
  m['C']='G';
  m['G']='C';
  char b;
  cin>>b;
  cout<<m[b]<<endl;

  return 0;
}


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

int main() {
  double n,k;
  cin>>n>>k;
  double answer=0,p=1;
  int m;
  for(int i=1;i<n+1;i++){
    if(i>=k){
      answer+=1;
    }
    else{
      m=i;
      while(m<k){
        m*=2;
        p/=2;
      }
      answer+=p;
      p=1;
    }
  }
  cout<<fixed<<setprecision(12);
  cout<<answer/n<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long co[100010] = { 0 };
int main() {
#define int long long
	long long n;
	cin >> n;
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		sum += a;
		co[a]++;
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int b, c;
		cin >> b >> c;
		cout << sum + (c - b) * co[b] << endl;
		sum += (c - b) * co[b];
		co[c] += co[b];
		co[b] = 0;
	}
	return 0;
}

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

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

	int ans = 0;
	if(s.at(0) == '1') ans++;
	if(s.at(1) == '1') ans++;
	if(s.at(2) == '1') ans++;

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const double pie = 3.14159265358979;

int main(){
    int n;
    cin >> n;
    vector<int> D(n);
    int ans = 0;
    for(int i = 0; i < n; i++) cin >> D[i];
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            ans += D[i] * D[j];
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define REP(i,n) for(int i=0;i<n;i++)

int main()
{
    int W, H, N;
    cin >> W >> H >> N;

    int max_x=W, max_y=H, min_x=0, min_y=0;
    int x, y, a;
    REP(i, N)
    {
        cin >> x >> y >> a;

        if (a == 1)
        {
            min_x = max(x, min_x);
        }
        else if (a == 2)
        {
            max_x = min(x, max_x);
        }
        else if (a == 3)
        {
            min_y = max(y, min_y);
        }
        else if (a == 4)
        {
            max_y = min(y, max_y);
        }
    }

    int width = max_x - min_x;
    if (width < 0) width = 0;
    int height = max_y - min_y;
    if (height < 0) height = 0;

    cout << width*height << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)

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

    ll x,y;int c=0;
    cin >> x >> y;
    for (ll i=x;i<=y;i*=2) c++;
    cout << c << endl;

    
}




Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int n,a[SZ],g[SZ];
int main()
{
	scanf("%d",&n); int ans=0;
	for(int i=1;i<=n;++i) scanf("%d",a+i);
	for(int i=1<<29;i;i>>=1)
	{
		for(int j=1;j<=n;++j)
		{
			if(a[j]<=i) continue; ++j;
			while(a[j]==i+i) ++j; ++ans;
		}
		for(int j=1;j<=n;++j)
			a[j]=min(a[j],i);
	}
	printf("%d\n",ans);
}


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

int main() {
  int s;
  cin >> s;
  string n=to_string(s);
  if((n[0]==n[1]&&n[1]==n[2])||(n[1]==n[2]&&n[2]==n[3]))
    cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
t,_,s=open(0).read().partition('\n')
h,w=map(int,t.split())
d={}
d[3]=h//2*(w//2)
d[0]=h%2and w%2
d[1]=(h*w-d[3]*4-d[0])//2
for i in set(s)-{'\n'}:
  i=s.count(i)
  for j in[3,1,0]:
    while d[j]and i>j:
      i-=j+1
      d[j]-=1
print('YNeos'[any(t for t in d.values())::2])

Measured memory_bytes: 3064
N, M = map(int, input().split(' '))

x = map(int, input().split(' '))

if not M >= N:
    print(0)
    exit()

x_list = sorted(x)

distance_list = []

for i in range(0, M-1):
    distance = x_list[i+1] - x_list[i]
    distance_list.append(distance)

result = sum(sorted(distance_list)[::-1][N-1:])
print(result)


Measured memory_bytes: 13968
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        Dictionary<string, int> id = new Dictionary<string, int>();
        int[] price = new int[n];
        for (int i = 0; i < n; i++)
        {
            var ax = Console.ReadLine().Split();
            id.Add(ax[0], i);
            price[i] = int.Parse(ax[1]);
        }
        UnionFind uf = new UnionFind(n);
        int m = int.Parse(Console.ReadLine());
        for (int i = 0; i < m; i++)
        {
            var st = Console.ReadLine().Split();
            uf.TryUnite(id[st[0]], id[st[1]]);
        }
        long res = 0;
        foreach (var group in Enumerable.Range(0, n).GroupBy(x => uf.Find(x)))
        {
            res += group.Min(x => price[x]) * group.Count();
        }
        Console.WriteLine(res);
    }
}


class UnionFind
{
    public int Size { get; private set; }
    public int GroupCount { get; private set; }
    public IEnumerable<int> AllRepresents => Parent.Where((x, y) => x == y);
    int[] Sizes;
    int[] Parent;
    public UnionFind(int count)
    {
        Size = count;
        GroupCount = count;
        Parent = new int[count];
        Sizes = new int[count];
        for (int i = 0; i < count; i++) Sizes[Parent[i] = i] = 1;
    }
    public bool TryUnite(int x, int y)
    {
        int xp = Find(x);
        int yp = Find(y);
        if (yp == xp) return false;
        if (Sizes[xp] < Sizes[yp]) { var tmp = xp; xp = yp; yp = tmp; }
        GroupCount--;
        Parent[yp] = xp;
        Sizes[xp] += Sizes[yp];
        return true;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int GetSize(int x) => Sizes[Find(x)];
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int Find(int x)
    {
        while (x != Parent[x]) x = (Parent[x] = Parent[Parent[x]]);
        return x;
    }
}



Measured memory_bytes: 20896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  int R, C, K; cin >> R >> C >> K;
  vector<vector<ll>> A(R, vector<ll>(C, 0));
  rep(k,K){
    int r, c; ll v;
    cin >> r >> c >> v;
    r--;c--;
    A[r][c]=v;
  }
  vector<vector<vector<ll>>> dp(R+1, vector<vector<ll>>(C+1, vector<ll>(4, 0)));
  dp[0][0][0]=0;
  dp[0][0][1]=A[0][0];
  rep(r,R){
    rep(c,C){
      if(r==0&&c==0) continue;
      // tate
      if(r)rep(i,4) chmax(dp[r][c][0], dp[r-1][c][i]);
      if(r)rep(i,4) chmax(dp[r][c][1], dp[r-1][c][i]+A[r][c]);
      // yoko
      if(c)rep(i,3) chmax(dp[r][c][i+1], dp[r][c-1][i]+A[r][c]);
      if(c)rep(i,4) chmax(dp[r][c][i], dp[r][c-1][i]);
    }
  }
  ll ans = 0;
  rep(i,4){
    chmax(ans, dp[R-1][C-1][i]);
  }
  cout << ans << endl;
  return 0;
}


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

#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;

int main(int argc, char *argv[]) {
    string s;
    cin >> s;

    if (s.at(0) == s.at(1) || s.at(1) == s.at(2) || s.at(2) == s.at(3)) MSG("Bad")
    else MSG("Good")
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	map<string,int>rel;
	while(n--)
	{
		string s;
		cin>>s;
		rel[s]++;
	}
	int mx=0;
	for(auto var : rel)
	{
		mx=max(mx,var.second);
	}
	for(auto var : rel)
	{
		if(var.second==mx)
		 cout<<var.first<<"\n";
	}
	return 0;
	
}

Measured memory_bytes: 19232
#include <iostream>
#include <string>
 
int main(int argc, char* argv[]) {
  std::string str;
  int countACGTLength = 0;
  int maxACGTLength = 0;
  int str_i = 0; 

  std::cin >> str;

  for(str_i = 0; str_i < (int)str.length();  str_i++)
  {
    if( (str[str_i]=='A') ||
        (str[str_i]=='C') ||
        (str[str_i]=='G') ||
        (str[str_i]=='T') )
    {
      countACGTLength++;
      maxACGTLength = std::max(countACGTLength, maxACGTLength);
    }
    else
    {
      countACGTLength = 0;
    }
  }
  std::cout << maxACGTLength << std::endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

class Program
{
    public void Proc()
    {
        int n = int.Parse(Console.ReadLine());
        String[] inpt = Console.ReadLine().Split(' ');
        // inpt = "2 5 1 3 2 3 0".Split(' ');

        int[] arr = new int[n];
        int[] ans = new int[n];

        int maxVal = int.MinValue;
        for (int i = 0; i < n; i++)
        {
            arr[i] = int.Parse(inpt[i]);
            maxVal = Math.Max(maxVal, arr[i]);
        }

        int[] numCnt = new int[maxVal + 1];
        for (int i = 0; i < numCnt.Length; i++)
        {
            numCnt[i] = 0;
        }

        for (int i = 0; i < n; i++)
        {
            numCnt[arr[i]]++;
        }

        for (int i = 1; i < numCnt.Length; i++)
        {
            numCnt[i] = numCnt[i] + numCnt[i - 1];
        }

        for (int i = 0; i < n; i++)
        {
            ans[numCnt[arr[i]]-1] = arr[i];
            numCnt[arr[i]]--;
        }

        System.Text.StringBuilder ansText = new StringBuilder();
        for (int i = 0; i < n; i++)
        {
            if (i > 0)
            {
                ansText.Append(" ");
            }
            ansText.Append(ans[i]);
        }
        Console.WriteLine(ansText.ToString());
    }


    static void Main(string[] args)

    {

        Program prg = new Program();
        prg.Proc();

    }
}

Measured memory_bytes: 263980
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1e9+7;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int n,dist[101010];

int bfs(){
  priority_queue<pint,vector<pint>,greater<pint>> pq;
  pq.push({1,1});
  dist[1]=1;
  while(pq.size()){
    pint p=pq.top();
    pq.pop();
    int d=p.first,now=p.second;
    if(dist[now]<d)continue;
    int next=(now+1)%n;
    if(dist[next]>d+1){
      dist[next]=d+1;
      pq.push({d+1,next});
      }
    next=(now*10)%n;
    if(dist[next]>d){
      dist[next]=d;
      pq.push({d,next});
      }
    }
  return dist[0];
  }      

int main(){
  cin>>n;
  rep(i,n)dist[i]=inf;
  cout<<bfs()<<endl;
  return 0;
  }

Measured memory_bytes: 1276