akhauriyash/Code-Regression huggingface dataset:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n = I()
        aa = [LI() for _ in range(n)]
        t = [0] * 100003
        for a,b in aa:
            t[a] += 1
            t[b+1] -= 1
        s = 0
        r = 0
        for i in range(100002):
            s += t[i]
            if i-1 <= s:
                r = i - 1
        rr.append(r)
        break

    return '\n'.join(map(str, rr))


print(main())




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

int main()
{
    string s;
    cin >> s;
    int a = (s[0] - '0') * 10 + (s[1] - '0'), b = (s[2] - '0') * 10 + (s[3] - '0');
    if(12 < a || 0 == a)
    {
        if(1 <= b && 12 >= b) cout << "YYMM";
        else cout << "NA";
    }
    else
    {
        if(1 <= b && 12 >= b) cout << "AMBIGUOUS";
        else cout << "MMYY";
    }
    cout << endl;
}

Measured memory_bytes: 256
N,W=map(int,input().split())

w=[]
v=[]

for i in range(N):
	ww,vv=map(int,input().split())
	w+=[ww]
	v+=[vv]
V=sum(v)

dp=[[float('inf')]*(V+1) for i in range(N+1)]
dp[0][0]=0
res=0
for i in range(N):
	for j in range(V+1):
		if j-v[i]>=0:
			dp[i+1][j]=w[i]+dp[i][j-v[i]]
		dp[i+1][j]=min(dp[i][j],dp[i+1][j])


for j in range(V+1):
	if dp[N][j]<=W:
		res=j
print(res)

	

Measured memory_bytes: 312016
#include <iostream>
using namespace std;
int main(void){
    
    int a,b,c;
    
    for(int i = 0; i < 4; i++){
        cin >>a>>b;
        
        if(a == 1){
            c = 6000 * b;
        }else if(a == 2){
            c = 4000*b;
        }else if(a == 3){
            c = 3000*b;
        }else if(a == 4){
            c = 2000*b;
        }
        
        cout<<c<<endl;
    }
    
}



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

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

    long long int ans = 1;

    for(int b=1; b<=40; b++){
        for(int p=2; p<=10; p++){
            long long int N=1;
            for(int i=1; i<=p; i++){
                N *= b;
            }
            if(N<=X){
                ans = max(ans, N);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 998244353;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M) % M;
}

int main() {
    int N;
    cin >> N;
    vector<P> vec(N);
    for(int i = 0;i < N;i++) {
        int A;
        cin >> A;
        A--;
        vec.at(i) = P(A,i + 1);
    }
    sort(vec.begin(),vec.end());
    vector<int> ret(N * N,-1);
    bool ret2 = true;
    for(int i = 0;i < N;i++) {
        ret.at(vec.at(i).first) = vec.at(i).second;
        int cnt = vec.at(i).second - 1;
        for(int j = 0;j < vec.at(i).first;j++) {
            if(cnt == 0) {
                break;
            }
            if(ret.at(j) == -1) {
                ret.at(j) = vec.at(i).second;
                cnt--;
            }
        }
        if(cnt != 0) {
            ret2 = false;
        }
    }
    reverse(vec.begin(),vec.end());
    for(int i = 0;i < N;i++) {
        ret.at(vec.at(i).first) = vec.at(i).second;
        int cnt = N - vec.at(i).second;
        for(int j = N * N - 1;j > vec.at(i).first;j--) {
            if(cnt == 0) {
                break;
            }
            if(ret.at(j) == -1) {
                ret.at(j) = vec.at(i).second;
                cnt--;
            }
        }
        if(cnt != 0) {
            ret2 = false;
        }
    }
    if(ret2 == false) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
        for(int i = 0;i < N * N;i++) {
            cout << ret.at(i) << " ";
        }
        cout << endl;
    }
}

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

int main()
{
  string S;
  cin >> S;
  bool ans = false;
  char c;
  for (int i = 0; i < 3; i++)
  {
    if (S[i] == S[i + 1])
    {
      ans = true;
      break;
    }
  }
  string s = ans ? "Bad" : "Good";
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int a;
    int b;
    cin >> a;
    cin >> b;
    if ( a < b ) {
        cout <<"a < b"<< endl;
    } 
    if (a > b ) {
        cout << "a > b" << endl;
    }
    if ( a == b ) {
        cout << "a == b"<< endl;
    }

}

Measured memory_bytes: 1156
s = input()
s_ls = [i for i in s]
count = 0
for i in range(len(s)-1):

    if s_ls[i] == s_ls[i+1]:
        count += 1
        if s_ls[i+1] == '1':
            s_ls[i+1] = '0'
        else:
            s_ls[i+1] = '1'
print(count)

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

bool even(int x) {
    return x % 2 == 0;
}

bool odd(int x) {
    return !even(x);
}

int N, M;
int A[50];

int _4 = 0, _2 = 0, _1 = 0;
void precompute() {
    for(int i = 0;i < 26;i++) {
        _4 += A[i]/4;
        A[i] = A[i]%4;
        _2 += A[i]/2;
        A[i] = A[i]%2;
        _1 += A[i];
    }
}

int main() {
   // freopen("input.in","r",stdin);
//    freopen("output.out","w",stdout);

    cin >> N >> M;
    string s;
    for(int i = 0;i < N;i++) {
        cin >> s;
        for(char ch : s) {
            A[ch-'a']++;
        }
    }

    precompute();
    if(even(N) and even(M)) {
        if(4*_4 == N*M) {
            cout << "Yes" <<endl;
        } else {
            cout<<"No"<<endl;
        }

        return 0;
    }

    if(even(N) and odd(M)) {
        if(4*_4+2*_2 == N*M and 2*_2 <= N) {
            cout << "Yes" <<endl;
        } else {
            cout<<"No"<<endl;
        }

        return 0;
    }

    if(even(M) and odd(N)) {
        if(4*_4+2*_2 == N*M and 2*_2 <= M) {
            cout << "Yes" <<endl;
        } else {
            cout<<"No"<<endl;
        }

        return 0;
    }

    if(_1 == 1 and _2*2 <= (N+M-2)) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    int sum = 0;
    vector<int> a(m);
    for (int i = 0; i < m; i++) {
        cin >> a.at(i);
        sum += a.at(i);
    }
    int ans;
    if (sum > n) {
        cout << -1 << endl;
        return 0;
    }
    else cout << n - sum << endl;
}


Measured memory_bytes: 3632
use proconio::input;

fn main() {
    input! {
        x: isize, y: isize
    }
    for i in 0..=100 {
        let j = x - i;
        if j < 0 {
            continue;
        }
        if i * 2 + j * 4 == y {
            println!("Yes");
            return;
        }
    }
    println!("No");
}


Measured memory_bytes: 2108
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

//変数
ll A,B,C,X;
vector<ll> vec;


//解法
void solve() {
	ll ans=0;
  	for (int i=0;i<=A;i++) {
      if (500*i>X) break;
      for (int j=0;j<=B;j++) {
        if (500*i+100*j>X) break;
        for (int k=0;k<=C;k++) {
          if (500*i+100*j+50*k > X) break;
          if (500*i+100*j+50*k == X) ans++;
        }
      }
    }
  
  cout << ans;
  
	return;
}

int main() {
	//入力

	cin >> A>>B>>C>>X;

	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,j,k) for(int i=j;i<k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define ll long long
#define ull unsigned long long int
#define ld long double
//Make sure no overflow problems
#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define mp make_pair
#define endl '\n'
#define x first
#define y second
#define VAR(i,n) __typeof(n) i = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define FORDEACH(i,c) for( VAR(i,(c).rbegin()),i!=(c).rend();i++)
#define REP(i,n) FOR(i,0,n)
#define mod 1000000007
#define MEM(a, b) memset(a, (b), sizeof(a))
#define addmod(a,b,mod) (a%mod + b%mod)%mod
#define submod(a,b,mod) (a%mod - b%mod + mod)%mod
//const long long INFLL = (ll)INF * (ll)INF;
const ld EPS = 10e-9;
const int MAX = 1e6;


int main(){
    ios_base:: sync_with_stdio(0); 
    cin.tie(0);
    
    int a, b, c;
    cin >> a >> b >> c;
    swap(a,b);
    swap(a,c);
    cout << a << " " << b << " " << c << endl;
    return 0;
}

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

typedef pair<int,int> P;

int main(){
	int n,m;
	vector<P> vec;
	cin >> n >> m;
	for(int i = 0;i < m;i++){
		int a,b;
		cin >> a >> b;
		vec.push_back(P(a,-b));
	}
	sort(vec.begin(),vec.end());
	if(vec[0].first != 1){
		cout << "Impossible" << endl;
		return 0;
	}
	int now = -vec[0].second,pos = 1;
	for(int ans = 1;;ans++){
		if(now == n){
			cout << ans << endl;
			break;
		}
		int ma = 0;
		while(pos < m && vec[pos].first <= now + 1){
			ma = max(ma,-vec[pos].second);
			pos++;
		}
		if(ma <= now){
			cout << "Impossible" << endl;
			break;
		}
		now = ma;
	}
	return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<priority_queue<ll>> ques(N);
    for (int i = 0; i < N; i++) {
        int t, d;
        cin >> t >> d;
        t--;
        ques[t].push(d);
    }

    vector<ll> tops, others;
    for (auto& que : ques) {
        if (!que.empty()) {
            tops.push_back(que.top());
            que.pop();
        }
        while (!que.empty()) {
            others.push_back(que.top());
            que.pop();
        }
    }

    sort(tops.begin(), tops.end(), greater<ll>());
    sort(others.begin(), others.end(), greater<ll>());
    for (int i = 1; i < (int)tops.size(); i++) {
        tops[i] += tops[i - 1];
    }
    for (int i = 1; i < (int)others.size(); i++) {
        others[i] += others[i - 1];
    }

    ll ans = 0;
    for (ll i = 1; i <= min((ll)K, (ll)tops.size()); i++) {
        if ((int)others.size() < K - i) {
            continue;
        }
        ll temp = i * i;
        temp += tops[i - 1];
        if (K - i - 1 >= 0) {
            temp += others[K - i - 1];
        }
        ans = max(ans, temp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 7672
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int ans;
    int l, r;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='A'){
            l=i;
            break;
        }
    }
    for(int j=s.size()-1; j>0; j--){
        if(s[j]=='Z'){
            r=j;
            break;
        }
    }
    cout << r-l+1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>  
#include<cmath>
#include<string>
#include<stack>
#include<queue> 
#include<algorithm>
#include<stdlib.h> 
#include<ctime>
using namespace std;
int main(){ 
	int arr[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int n;
	cin>>n;
	cout<<arr[n-1];
	
}




Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define mkp make_pair
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;

int solve(){
    int n;
    cin>>n;
	set<int> q[n+1];
	rep(i,0,n-1){
		int a,b;
		cin>>a>>b;
		q[a].insert(b);
		q[b].insert(a);
	}
	ll sum=0,ans=0;
	repd(i,n,1){
		auto p=q[i].upper_bound(i);
		if(p==q[i].end()){
		    sum+=n-i+1;
			ans+=sum;
		}
		else{
			sum+=*p-i;
			p++;
			while(p!=q[i].end()){
			    sum=sum-(n-*p+1);
		        p++;
		    }
		ans+=sum;
		}
// 		cout<<i<<" "<<ans<<" "<<sum<<endl;
	}
	cout<<ans<<endl;
	return 0;
}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


Measured memory_bytes: 31700
import sys
from heapq import heappush, heappushpop

Q = int(input())
high = []
low = []
sum_dh, sum_dl = 0, 0
sum_b = 0
buf = []

for qi, line in enumerate(sys.stdin):
    q = list(map(int, line.split()))
    if len(q) == 1:
        x = -low[0]
        ans_l = x * len(low) - sum_dl
        ans_h = sum_dh - x * len(high)
        buf.append('{} {}\n'.format(x, ans_l + ans_h + sum_b))
    else:
        _, a, b = q
        sum_b += b
        if len(low) == len(high):
            h = heappushpop(high, a)
            heappush(low, -h)
            sum_dh += a - h
            sum_dl += h
        else:
            l = -heappushpop(low, -a)
            heappush(high, l)
            sum_dl += a - l
            sum_dh += l

print(''.join(buf))


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

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

    vector<string> s(N);

    rep(i,N)
        cin >> s[i];
        
    

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

    rep(i,N)
        cout << s[i];

    cout << endl;



    return 0;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>

using namespace std;

int A[200000];


int main()
{
    int N, i, Xor;

    scanf("%d", &N);
    Xor = 0;
    for(i = 0; i < N; ++i){
        scanf("%d", &A[i]);
        Xor ^= A[i];
    }
    for(i = 0; i < N; ++i)
        printf("%d ", Xor ^ A[i]);

    return 0;
}


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

constexpr int MAX_LEN = 1e5;
constexpr int DIVISOR = 13;
constexpr int MOD = 1e9+7;

long dp[MAX_LEN+1][DIVISOR];

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

  dp[S.length()][0] = 1;

  int mul{1};
  for (int i = S.length()-1; i >= 0; --i) {
    if (S[i] == '?') {
      for (int v{}; v < 10; ++v) {
        for (int j{}; j < DIVISOR; ++j) {
          dp[i][(v*mul+j)%DIVISOR] += dp[i+1][j];
          dp[i][(v*mul+j)%DIVISOR] %= MOD;
        }
      }
    } else {
      int v = S[i] & 0xF;
      for (int j{}; j < DIVISOR; ++j) {
        dp[i][(v*mul+j)%DIVISOR] += dp[i+1][j];
        dp[i][(v*mul+j)%DIVISOR] %= MOD;
      }
    }
    mul *= 10;
    mul %= DIVISOR;
  }

  cout << dp[0][5] << endl;
  return 0;
}


Measured memory_bytes: 10624
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <stdlib.h>
#include <stdio.h>

using namespace std;

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 my_abs_A(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

int my_abs_B(long long num,long long numb) {
    if (num - numb >= 0)
        return num - numb;
    else
        return -1 * (num - numb);
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

int main() {
    int N;
    cin >> N;
    int ans = 0;
    vector<int> retu(N);
    for (int i = 0; i < N; i++) {
        cin >> retu.at(i);
        ans = ans + retu.at(i);
    }
    sort(retu.begin(), retu.end());
    int moto = ans;
    for (int j = 0; j < N; j++) {
        if (ans % 10 != 0) {
            moto = 114514;
            break;
        }
        else if(retu.at(j)%10 != 0){
            ans = ans - retu.at(j);
            break;
        }
    }
    if (moto == ans) {
        ans = 0;
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	m := scanInt()

	fmt.Fprintln(wr, pow(2, m)*100*(n-m)+pow(2, m)*1900*m)
}

func pow(a, n int) int {
	res := 1
	for n > 0 {
		if n&1 == 1 {
			res *= a
		}
		a *= a
		n >>= 1
	}
	return res
}


Measured memory_bytes: 640
n,k=map(int,input().split())
a=list(map(int,input().split()))
import fractions
a.sort()
#9,4,3>7
#9-(9-4-3)
#9 ;6 3 >5
if k in a:
    print("POSSIBLE")
    exit()

if k>a[-1]:
    print("IMPOSSIBLE")
    exit()

if a[0]==1:
    print("POSSIBLE")
    exit()

flag=0
gg = fractions.gcd(a[0], a[1])

for item in a[1:]:
    if item%gg!=0:
        flag=1

if flag==1:
    print("POSSIBLE")
    exit()
else:
    if k%gg==0:
        print("POSSIBLE")
        exit()
    else:
        print("IMPOSSIBLE")
        exit()




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

using namespace std;

int main(){

	int ans;

	int a[4],kake,op[4];

	string temp;

	cin >>temp;

	for(int i=0; i<4; i++){
		a[i] = temp[i] -'0';
		
		
	}
		

	for(int x=0;  x<8; x++){


		int sum =0;

		string s;

		s+=(char)('0'+a[0]);

		sum =a[0];

		for(int i=0; i<3; i++){
			if(x&(1<<i)){

				sum+=a[i+1];
				s += '+';
				s+=(char)('0'+a[i+1]);

			}

			else {
				sum -=a[i+1];
				s +='-';
				s+=(char)('0'+a[i+1]);
			}

			if(sum ==7 && i==2){

				
				cout <<s<<"=7"<<endl;
				return 0;
			}

		}
	}



		
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))
P = [(A[i], 1) for i in range(N)]
for j in range(M):
    B, C = map(int, input().split())
    P.append((C, B))
P.sort(reverse=True)
ans, cnt = 0, N
for v, c in P:
    use = min(c, cnt)
    ans += use*v
    cnt -= use
print(ans)

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);


template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll HIGHINF = (ll)1e18;
const ll LOWINF = (ll)1e15;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	int N; cin >> N;
	V<int> a(N); REP(i,N) cin >> a[i];
	int ans = 1;
	for(int i = 1; i < N; ++i){
		int flg = 1;
		for(int j = 0; j < i; ++j){
			if(a[j]>a[i]) flg = 0;
		}
		ans += flg;
	}
	cout << ans << endl;

	
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
using ll = long long;
int main(){
    ll h,w,ans;
    cin >> h >> w;
    
    if(h%3==0)  ans=0;
    else    ans=w;
    if(w%3==0)  ans=0;
    else    ans=min(ans,h);

   for(ll i=1;i<h;i++){
        ll s1 = i*w;
        ll s2 = (h-i)*(w/2); 
        ll s3 = (h-i)*((w+1)/2);
        ll num =  max(abs(s1-s3),max(abs(s1-s2),abs(s2-s3)));
        ans=min(ans,num);
    }

    for(ll i=1;i<w;i++){
        ll s1 = i*h;
        ll s2 = (w-i)*(h/2); 
        ll s3 = (w-i)*((h+1)/2);
        ll num =  max(abs(s1-s3),max(abs(s1-s2),abs(s2-s3)));
        ans=min(ans,num);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    string s;
    cin >> s;

    const int n = (int)s.size();

    string t = s;
    REVERSE(t);

    bool ok = s == t;

    t = s.substr(0, n / 2);
    REVERSE(t);

    ok &= s.substr(0, n / 2) == t;

    t = s.substr(n / 2 + 1, n / 2);
    REVERSE(t);

    ok &= s.substr(n / 2 + 1, n / 2) == t;

    if(ok){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    cout << flush;

    return 0;
}

Measured memory_bytes: 256
while True:
    L=lambda:list(map(int,input().split()))
    k,x=L()
    if x>=0 and x<=100 and k>=1 and k<=100:
        break
c =[]
for i in range(x-k+1,x+k,1):
    c.append(i)
c = [str(int) for int in c]
print(' '.join(c))

Measured memory_bytes: 3064
a = [input() for i in range(3)]
l = ['a', 'b', 'c']
L = ['A', 'B', 'C']
x = 0
while 1:
    if len(a[x]) == 0:
        break
    next = l.index(a[x][0])
    a[x] = a[x][1:]
    x = next
print(L[x])


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define mo 1000000007
#define ll long long
#define N 200005
using namespace std;
vector<int> e[N];
int vis[N],du[N],fa[N],sz[N];
int q[N],t,nq[N],n;
ll power(ll x,ll y){
	ll s=1;
	for (;y;y/=2,x=1ll*x*x%mo)
		if (y&1) s=1ll*s*x%mo;
	return s;
}
ll solve(int rt){
	t=1; q[1]=rt; vis[rt]=1;
	for (int h=1;h<=t;h++){
		int x=q[h]; du[x]=0;
		sz[x]=1; fa[x]=0;
		for (int i=0;i<e[x].size();i++){
			int to=e[x][i];
			if (!vis[to]){
				q[++t]=to;
				vis[to]=1;
			}
		}
	}
	int ecnt=0;
	for (int i=1;i<=t;i++)
		for (int j=0;j<e[q[i]].size();j++)
			du[e[q[i]][j]]++,ecnt++;
	if (ecnt/2!=t) return 0;
	int nt=0;
	for (int i=1;i<=t;i++)
		if (du[q[i]]==1) nq[++nt]=q[i];
	for (int h=1;h<=nt;h++){
		int x=nq[h];
		for (int i=0;i<e[x].size();i++){
			int to=e[x][i];
			if (--du[to]){
				fa[x]=to;
				if (du[to]==1)
					nq[++nt]=to;
				else rt=to;
			}
		}
	}
	for (int x=rt;;){
		for (int i=0;i<e[x].size();i++)
			if (du[e[x][i]]>1&&fa[e[x][i]]!=x){
				fa[x]=e[x][i]; x=e[x][i];
				break;
			}
		if (x==rt) break;
	}
	ll ans=1;
	for (int i=1;i<=nt;i++){
		int x=nq[i];
		ans=ans*sz[x]%mo;
		if (x<fa[fa[x]]) sz[fa[x]]+=sz[x];
	}
	for (int x=rt;;){
		if (x>fa[fa[x]]){
			rt=fa[x];
			break;
		}
		x=fa[x];
		if (x==rt) return 0;
	}
	for (int x=rt;;){
		ans=ans*sz[x]%mo;
		if (x<fa[fa[x]]) sz[fa[x]]+=sz[x];
		x=fa[x]; if (x==rt) break;
	}
	return power(ans,mo-2);
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n*2;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		e[x].push_back(y+n);
		e[y+n].push_back(x);
	}
	ll ans=1;
	for (int i=1;i<=n*2;i++)
		ans=ans*i%mo;
	for (int x=1;x<=n*2;x++)
		if (!vis[x]){
			ll s=solve(x);
			for (int i=1;i<=t;i++){
				int x=q[i]; vis[x]=0;
				reverse(e[x].begin(),e[x].end());
			}
			ans=ans*(s+solve(x))%mo;
		}
	printf("%lld",ans);
}

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

#define mod 1000000007
#define int long long int
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define vs vector<string>
#define fi first
#define se second
#define psb push_back
#define ppb pop_back
#define fio ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(v) v.begin(),v.end()
#define endl "\n"

const int maxn=2e5+5;
int x[maxn],h[maxn];
int pref[maxn];

int32_t main()
{
	int n,d,a;
	cin>>n>>d>>a;
	vpii v(n);
	for(auto &p:v)
		cin>>p.fi>>p.se;
	sort(all(v));
	for(int i=0;i<n;i++)
		x[i]=v[i].fi,h[i]=v[i].se;

	int ans=0,sum=0,val,need;
	for(int i=0;i<n;i++)
	{
		sum+=pref[i];
		val=h[i]+sum;
		if(val<=0)
			continue;
		need= (val+a-1)/a;
		ans+=need;
		int j=upper_bound(x+i+1,x+n,x[i]+2*d)-x;
		pref[i+1]-=need*a;
		pref[j]+=need*a;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 8064
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
#include<list>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//int型0~9を文字0~9に変換
char int_to_char(int c) {
	if (c == 0) return '0';
	if (c == 1) return '1';
	if (c == 2) return '2';
	if (c == 3) return '3';
	if (c == 4) return '4';
	if (c == 5) return '5';
	if (c == 6) return '6';
	if (c == 7) return '7';
	if (c == 8) return '8';
	if (c == 9) return '9';
	else return'x';
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x, int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / (int)pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}
//ord桁のstring型2進数をint型10進数に変換する
int rep_binary(string x, int ord)
{
	int res = 0;
	for (int i = 0; i < ord; i++)
	{
		if (x[i] == '1') res += (int)pow(2, ord - 1 - i);
	}
	return res;
}
//xとyのビットごとの排他的論理和
template<class T> T XOR(T x, T y)
{
	T n = 0;
	while (max(x, y) > pow(2, n)) n++;
	T ans=0;
	for (int i = 0; i <= n; i++)
	{
		T x1 = (x % (T)pow(2, i + 1)) / (T)pow(2, i);
		T y1 = (y % (T)pow(2, i + 1)) / (T)pow(2, i);
		if (x1 != y1) ans += (T)pow(2, i);
	}
	return ans;
}

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



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

	int a = S.length();

	bool x = true;

	for (int i = 0; i < S.length(); i++)
	{
		if (i % 2 == 0 && S[i] != 'h') x = false;
		else if (i % 2 == 1 && S[i] != 'i') x = false;
	}

	if (a % 2 == 0 && x) cout << "Yes" << endl;
	else cout << "No";
		 
	return 0;
}

Measured memory_bytes: 256
X,K,D = gets.split.map(&:to_i)

if (X < 0)
  if (X + K*D <= 0)
    puts (X + K*D).abs
  else
    if (K - (-X.to_f/D).ceil).even?
      puts (X + (-X.to_f/D).ceil*D).abs
    else
      puts (X + (-X.to_f/D).ceil*D - D).abs
    end
  end
else
  if (X - K*D > 0)
    puts (X - K*D).abs
  else
    if (K - (X.to_f/D).ceil).even?
      puts (X - (X.to_f/D).ceil*D).abs
    else
      puts (X - (X.to_f/D).ceil*D + D).abs
    end
  end
end


Measured memory_bytes: 14256
#include<iostream>

char c[3] = ")]";

bool search(char* s,int* i){
	int b = 0;
	if(s[(*i)] == '[')
		b = 1;
	for((*i)++; s[(*i)] != '.'; (*i)++){
		if(s[(*i)] == c[b])
			return true;
		else if(s[(*i)] == c[1-b])
			return false;
		else if(s[(*i)] == '(' || s[(*i)] == '[')
			if(!search(s, i))
				return false;
	}
	return false;
}

int main(){
	using std::cout;
	char input[128];
	int i;
	for(;;){
		std::cin.getline(input, sizeof(input));
		if(input[0] == '.')
			return 0;
		for(i=0; input[i] != '.'; i++){
			if(input[i] == '(' || input[i] == '['){
				if(!search(input, &i))
					goto NO;
			}else if(input[i] == ']' || input[i] == ')')
				goto NO;
		}
		std::cout << "yes\n";
		continue;
NO:;
		std::cout << "no\n";
	}
}

Measured memory_bytes: 840
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Holiday[] holidays = new Holiday[n];
		for (int i = 0; i < n; i++) {
		    holidays[i] = new Holiday(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt()); 
		}
		int min = Integer.MAX_VALUE;
		for (int i = 1; i <= 360; i++) {
		    int max = 0;
		    for (int j = 0; j < n; j++) {
		        max = Math.max(max, holidays[j].getCrowded(i));
		    }
		    min = Math.min(min, max);
		}
		System.out.println(min);
	}
	
	static class Holiday {
	    int start;
	    int end;
	    int value;
	    
	    public Holiday(int month, int day, int time, int value) {
	        start = (month - 1) * 30 + day;
	        end = start + time - 1;
	        if (end > 360) {
	            end -= 360;
	        }
	        this.value = value;
	    }
	    
	    public int getCrowded(int target) {
	        if (start > end) {
	            if (target <= end || target >= start) {
	                return value;
	            }
	        } else {
	            if (start <= target && target <= end) {
	                return value;
	            }
	        }
	        int v1;
	        if (target < start) {
	            v1 = Math.max(0, value - (start - target));
	        } else {
	            v1 = Math.max(0, value - (360 + start - target));
	        }
	        int v2;
	        if (end < target) {
	            v2 = Math.max(0, value - (target - end));
	        } else {
	            v2 = Math.max(0, value - (360 + target - end));
	        }
	        return Math.max(v1, v2);
	    }
	}
}



Measured memory_bytes: 27304
from itertools import combinations_with_replacement

n = int(input())
res = [0] * n
for x, y, z in combinations_with_replacement(range(1, int(n**0.5)), 3):
    if (val := x**2 + y**2 + z**2 + x*y + y*z + z*x) > n:
        continue
    if (l := len(set([x, y, z]))) == 1:
        res[val-1] += 1
    elif l == 2:
        res[val-1] += 3
    else:
        res[val-1] += 6
print('\n'.join(map(str, res)))


Measured memory_bytes: 9768
#include<algorithm>
#include<iostream>
#include<vector>
#include<string.h>
using namespace std;
int main()
{
    string n;
    cin >> n;

    int len = n.size() - 1;

    if(n[len] == '3')
    {
        cout << "bon" << endl;
    }
    else if(n[len] == '0' || n[len] == '1' || n[len] == '6'|| n[len] == '8')
    {
        cout << "pon" << endl;
    }else
    {
        cout << "hon" << endl;
    }

    return 0;
}


Measured memory_bytes: 3636
// ref: https://img.atcoder.jp/abc123/editorial.pdf

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int64 next(const vector<int64>& v, uint idx){
    return (idx<v.size() ? v[idx] : v[v.size()-1] );
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    uint X, Y, Z, K; cin >> X >> Y >> Z >> K;
    vector<int64> vA(X); for(uint i=0; i<X; ++i){ cin >> vA[i]; } sort(vA.begin(), vA.end(), greater<int64>());
    vector<int64> vB(Y); for(uint i=0; i<Y; ++i){ cin >> vB[i]; } sort(vB.begin(), vB.end(), greater<int64>());
    vector<int64> vC(Z); for(uint i=0; i<Z; ++i){ cin >> vC[i]; } sort(vC.begin(), vC.end(), greater<int64>());
    
    vector<int64> vK(K);
    for(uint x=0; x<X; ++x){
        for(uint y=0; y<Y; ++y){
            for(uint z=0; z<Z; ++z){
                if((x+1)*(y+1)*(z+1)>K){ continue; }
                vK.push_back( vA[x]+vB[y]+vC[z] );
            }
        }
    }
    
    sort(vK.begin(), vK.end(), greater<int64>());
    for(uint i=0; i<K; ++i){ cout << vK[i] << endl; }
    
    return 0;
}

Measured memory_bytes: 1960
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define rep(i,a,b) for(int i = (a) ; i <= (b) ; i++)
#define per(i,a,b) for(int i = (a) ; i >= (b) ; i--)
#define mem(a) memset(a,0,sizeof(a))
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const int INF = 1e9 + 10;
const LL mod = 2019;
const int maxn = 1e5 + 7;

inline int read() {
    char c = getchar();
    int x = 0, f = 1;
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + (c - '0');
        c = getchar();
    }
    return x * f;
}

int head[maxn << 1];
struct Edge {
    int to, next;
}edge[maxn << 1];
int tot;

void init() {
    memset(head, -1, sizeof(head));
    tot = 0;
}

void addedge(int u, int v) {
    edge[tot].to = v;
    edge[tot].next = head[u];
    head[u] = tot++;
}

LL qpow(LL a, LL b, LL p) {
    LL res = 1;
    while (b) {
        if (b & 1) res = (res * a) % p;
        a = (a * a) % p;
        b >>= 1;
    }
    return res;
}

char s[maxn];
LL cnt[maxn];

int main() {
    while(~scanf("%s",s)) {
        int len = strlen(s);
        LL ans = 0;
        mem(cnt);
        LL sum = 0;
        cnt[0] = 1;
        rep(i,0,len-1) {
            sum = (sum * 10 + (s[i] - '0')) % mod;
            LL val = (qpow(10LL,len-i-1,mod) * (sum % mod)) % mod;
            cnt[val]++;
        }
        rep(i,0,mod-1) {
            ans += cnt[i] * (cnt[i] - 1) / 2;
        }
        plld(ans);
    }
    return 0;
}


Measured memory_bytes: 4800
#include <iostream>
#include <cstdio>

using namespace std;

int main(void){
  int N,M,X,tmp=0;
  int A[100];
  scanf("%d %d %d",&N,&M,&X);
  for(int i=0;i<M;++i){
    scanf("%d",&A[i]);
    if(A[i]<X){
      tmp++;
    }
  }
  printf("%d\n",min(tmp,M-tmp));
  return 0;
}


Measured memory_bytes: 256
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

int64 mod = pow(10, 9) + 7;
int64 ans;

void P(int64 n, int64 m) {
    rep(i, m) ans = (ans * (n - i)) % mod;
}

int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int64 n, k;
    scanf("%lld %lld", &n, &k);
    vector<vector<int>> adj(n);
    rep(i, n - 1) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    ans = k;
    vector<int> tree(n);
    tree[0] = 0;
    stack<int> dfs;
    vector<bool> visited(n, false);
    dfs.push(0);
    int depth = 0;
    while(!dfs.empty()) {
        int x = dfs.top();
        dfs.pop();
        visited[x] = true;
        int cdepth = depth;

        int64 m = 0;
        for (auto v : adj[x]) {
            if (!visited[v]) {
                tree[v] = x;
                m++;
                dfs.push(v);
                depth++;
            } else {
                depth--;
            }
        }
        P(k - 1 - (cdepth == 0 ? 0 : 1), m);
        cerr << '\n';
    }


    cout << ans << '\n';

    return 0;
}



Measured memory_bytes: 6904
using System;
using System.Linq;
using System.Numerics;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split(' ').Select(s=>BigInteger.Parse(s)).ToList();
            if(2*NM[0]>=NM[1])
            {
                Console.WriteLine(NM[1]/2);
                return;
            }
            Console.WriteLine(((NM[0]*2)+NM[1]) / 4);
        }
    }
}


Measured memory_bytes: 11604
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Pine1999
 */

#include <bits/stdc++.h>
#ifndef ATCODER_DSU_HPP
#define ATCODER_DSU_HPP 1

#include <algorithm>
#include <cassert>
#include <vector>

namespace atcoder {

// Implement (union by size) + (path compression)
// Reference:
// Zvi Galil and Giuseppe F. Italiano,
// Data structures and algorithms for disjoint set union problems
    struct dsu {
    public:
        dsu() : _n(0) {}
        dsu(int n) : _n(n), parent_or_size(n, -1) {}

        int merge(int a, int b) {
            assert(0 <= a && a < _n);
            assert(0 <= b && b < _n);
            int x = leader(a), y = leader(b);
            if (x == y) return x;
            if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
            parent_or_size[x] += parent_or_size[y];
            parent_or_size[y] = x;
            return x;
        }

        bool same(int a, int b) {
            assert(0 <= a && a < _n);
            assert(0 <= b && b < _n);
            return leader(a) == leader(b);
        }

        int leader(int a) {
            assert(0 <= a && a < _n);
            if (parent_or_size[a] < 0) return a;
            return parent_or_size[a] = leader(parent_or_size[a]);
        }

        int size(int a) {
            assert(0 <= a && a < _n);
            return -parent_or_size[leader(a)];
        }

        std::vector<std::vector<int>> groups() {
            std::vector<int> leader_buf(_n), group_size(_n);
            for (int i = 0; i < _n; i++) {
                leader_buf[i] = leader(i);
                group_size[leader_buf[i]]++;
            }
            std::vector<std::vector<int>> result(_n);
            for (int i = 0; i < _n; i++) {
                result[i].reserve(group_size[i]);
            }
            for (int i = 0; i < _n; i++) {
                result[leader_buf[i]].push_back(i);
            }
            result.erase(
                    std::remove_if(result.begin(), result.end(),
                                   [&](const std::vector<int>& v) { return v.empty(); }),
                    result.end());
            return result;
        }

    private:
        int _n;
        // root node: -1 * component size
        // otherwise: parent
        std::vector<int> parent_or_size;
    };

}  // namespace atcoder

#endif  // ATCODER_DSU_HPP

//#include "../library/fenwicktree.hpp"
//#include "../library/modint.hpp"
//#include "../library/segtree.hpp"

using namespace std;
using namespace atcoder;

void ADisjointSetUnion(std::istream& in, std::ostream& out) {
    int n, q;
    in >> n >> q;
    dsu d(n);
    while (q--) {
        int t, u, v;
        in >> t >> u >> v;
        if (t) out << d.same(u, v) << '\n';
        else d.merge(u, v);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    class Solver {
    public:
        static void solve(std::istream& in, std::ostream& out) {
            return ADisjointSetUnion(in, out);
        }
    };
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    Solver::solve(in, out);
    return 0;
}

Measured memory_bytes: 3948
#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define repj(begin, end) for (j=begin;j<end;j++)
#define init(arr, end, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
typedef long long int ll;
const int inf = 1000000000;
const int mod = 1000000007;
const int nil = -1;
ll n;
char c[26] = {'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y'};
stack<ll> digits;

int main() {
    scanf(" %lld", &n);
    while (n > 0) {
        ll mod = n%26;
        digits.push(mod);
        if (mod!=0) n -= mod;
        else n -= 26;
        n /= 26;
    }
 
    while (digits.size() > 0) {
        ll i = digits.top(); digits.pop();
        printf("%c", c[i]);
    }
    printf("\n");
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/a.in", "r", stdin);
//  freopen("../IO/a.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}

void solve(std::istream &in, std::ostream &out) {
  int n, x;
  in >> n >> x;
  vector<int> a(n), b(n, numeric_limits<int>::max());
  for (int &i : a) in >> i;
  int64_t ans = numeric_limits<int64_t>::max();
  for (int i = 0; i < n; ++i) {
    int64_t cost = (int64_t) x * i;
    for (int j = 0; j < n; ++j) {
      b[j] = min(b[j], a[(n + j - i) % n]);
      cost += b[j];
    }
    ans = min(ans, cost);
  }
  out << ans << ' ';
}

Measured memory_bytes: 3672