akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC         optimize("O3")
#include            <bits/stdc++.h>
#include            <ext/pb_ds/assoc_container.hpp>
#include            <ext/pb_ds/tree_policy.hpp>
#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define mp          make_pair
#define mem(x,i)    memset(x,i,sizeof(x))
#define ff          first
#define ss          second
#define popcount(x) __builtin_popcount(x)
#define all(x)      x.begin(),x.end()
#define Case(t)     for(int ks=1;ks<=t;ks++)
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define D(x)        cerr<< __LINE__ <<": "<< #x << " = "<<(x) <<'\n';
#define endl        '\n'

using namespace std;
using namespace __gnu_pbds;

using ll  = long long;
using ld  = long double;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;

const int INF    = 0x3f3f3f3f;
const ll LL_INF  = 0x3f3f3f3f3f3f3f3f;
const double PI  = acos(-1);
const double eps = 1e-4;
const int mod    = 1e9+7;
const int mx     = 5e5+5;
template <typename T>  using orderedSet =
    tree<T, null_type, less_equal<T>,
    rb_tree_tag, tree_order_statistics_node_update>;//find_by_order,order_of_key*/

/*------------------------------Graph Moves----------------------------*/
//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

//ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(; b; b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
/*----------------------BitMask-----------------------------------------*/
//inline int setBit(int N,int pos){return N=N | (1<<pos);}
//inline int resetBit(int N,int pos){return N= N & ~(1<<pos);}
//inline bool checkBit(int N,int pos){return (bool) (N& (1<<pos));}

int main()
{
    int n;
    cin>>n;
    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];
    int ans=0;
    for(int i=0;i<n;i++)
    {
        ans+=max(0,a[i]-b[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3608
#! /usr/bin/python
# -*- coding: utf-8 -*-

L = "qwertasdfgzxcvb"
s = raw_input()
while s != "#":
    cnt = 0
    if s[0] in L:
        cur = "L"
    else:
        cur = "R"
    for i in range(len(s)):
        if s[i] in L:
            if cur != "L":
                cnt += 1
            cur = "L"
        else:
            if cur == "L":
                cnt += 1
            cur = "R"
    print cnt
    s = raw_input()

Measured memory_bytes: 4216
#include <bits/stdc++.h>
using namespace std;
int s[800001], la[800001];
void upd(int id, int v){
	la[id] = v, s[id] = v;
}
void prop(int id, int l, int r){
	if (la[id] == 0) return;
	int mid = (l + r) / 2;
	upd(id * 2, la[id]);
	upd(id * 2 + 1, la[id] + mid - l + 1);
	la[id] = 0;
}
void update(int id, int l, int r, int L, int R, int v){
	if (r < L || R < l){
		return;
	}else if (L <= l && r <= R){
		upd(id, v);
		return;
	}
	prop(id, l, r);
	int mid = (l + r) / 2;
	update(id * 2, l, mid, L, R, v);
	update(id * 2 + 1, mid + 1, r, L, R, v + mid - l + 1);
	s[id] = min(s[id * 2], s[id * 2 + 1]);
}
int query(int id, int l, int r, int L, int R){
	if (r < L || R < l){
		return 2147483647;
	}else if (L <= l && r <= R){
		return s[id];
	}
	prop(id, l, r);
	int mid = (l + r) / 2;
	int t1 = query(id * 2, l, mid, L, R);
	int t2 = query(id * 2 + 1, mid + 1, r, L, R);
	return min(t1, t2);
}
int main(){
	int n, m, x, y, l = 0;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++){
		scanf("%d %d", &x, &y), x--, y--;
		if (x <= l){
			l = max(l, y + 1);
		}else{
			update(1, 0, m - 1, x, y, query(1, 0, m - 1, x - 1, x - 1) + 1 - x);
		}
		if (l == m) printf("-1\n");
		else printf("%d\n", query(1, 0, m - 1, l, m - 1) + i + 1);
	}
}

Measured memory_bytes: 7904
from collections import defaultdict
b = defaultdict(int)
r = defaultdict(int)
ans = defaultdict(int)

n = int(input())
for i in range(n):
  s = input()
  b[s] += 1

m = int(input())
for i in range(m):
  s = input()
  r[s] += 1

for e in b.keys(): 
  if e in r.keys():
    ans[e] = b[e] - r[e]
  else:
    ans[e] = b[e]

p = ans.values()
p = list(p)
p.append(0)
print(max(p))

Measured memory_bytes: 3316
#include<stdio.h>

#define MAX_N 100

int n;
int p[MAX_N];

int main(void)
{
	int cnt, i, j;
	
	scanf( "%d", &n );
	
	for( i=0; i<n; i++ ) {
		scanf( "%d", &p[i] );
	}
	
	for( i=1; ; i++ ) {
	
		cnt = 0;
		for( j=0; j<n; j++ ) {
			if ( p[j] >= i ) cnt++;
		}
		
		if ( cnt < i ) break;
	}
	
	printf( "%d\n", i-1 );
	
	return 0;
}

Measured memory_bytes: 1860
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();

    if n == 1 {
        return "0".to_string();
    }

    let mut ans: usize = 0;
    let mc = mod_comb::ModComb::init(MOD, n + 5);
    let mut e = mod_pow(8, n - 2);
    let einv = modinv(8, MOD as isize) as usize;
    let mut t = 2 * 2;
    for k in 2..=n {
        ans =  (ans + ((mc.calc(n, k) * ((e * (t - 2)) % MOD)) % MOD)) % MOD;
        e *= einv;
        e %= MOD;
        t *= 2;
        t %= MOD;
    }
    ans.to_string()
}

const MOD: usize = 1_000_000_007;

fn mod_pow(a: usize, b: usize) -> usize {
    let mut result = 1;
    for _ in 0..b {
        result = result * a % MOD;
    }
    return result
}

fn modinv(mut a: isize, mut m: isize) -> isize {
    let mut b = m;
    let mut u = 1;
    let mut v = 0;
    while b != 0 {
        let t: isize = a / b;

        a -= t * b;

        let temp = a;
        a = b;
        b = temp;

        u -= t * v;
        let temp = u;
        u = v;
        v = temp;
    }
    u %= m;
    if u < 0 {
        u += m;
    }
    return u;
}

mod mod_comb {
    pub struct ModComb {
        modulo: usize,
        fac: Vec<usize>,
        finv: Vec<usize>,
    }

    impl ModComb {
        pub fn init(modulo: usize, max: usize) -> ModComb {
            let mut fac = vec![1; max];
            let mut finv = vec![1; max];
            let mut inv = vec![1; max];
            for i in 2..max {
                fac[i] = fac[i - 1] * i % modulo;
                inv[i] = modulo - inv[modulo % i] * (modulo / i) % modulo;
                finv[i] = finv[i - 1] * inv[i] % modulo;
            }
            ModComb {
                modulo,
                fac,
                finv,
            }
        }

        pub fn calc(&self, n: usize, k: usize) -> usize {
            if n < k {
                return 0;
            }
            self.fac[n] * (self.finv[k] * self.finv[n - k] % self.modulo) % self.modulo
        }
    }
}


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

int main(){
  int64_t N,ans = 0;
  cin >> N;
  vector<int> a(3 * N);
  for (int i = 0; i < (3 * N); i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for (int i = 1; i < (2 * N); i += 2){
    ans += a.at(i); 
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
	queue<LL> q;

	for(LL i=1;i<=9;i++)
		q.push(i);

	vector<LL> ans;

	while(ans.size()<2e5)
	{
		LL n=q.front();
		ans.push_back(n);
		q.pop();

		LL m=n%10;
		
		if(m>0) q.push(n*10+m-1);
		if(m<9) q.push(n*10+m+1);
		q.push(n*10+m);
	}

	sort(ans.begin(),ans.end());
	int k;cin>>k;
	cout<<ans[k-1];

	return 0;
}

Measured memory_bytes: 4976
import java.util.Scanner;

//Rock, Paper, Scissors
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int k = sc.nextInt();
			if(k==0)break;
			int[] h = new int[5];
			h[0] = k;
			boolean[] u = new boolean[4];
			u[k] = true;
			for(int i=1;i<5;i++){
				k = sc.nextInt();
				h[i] = k;
				u[k] = true;
			}
			int c = 0;
			for(int i=1;i<=3;i++)if(u[i])c++;
			if(c==1||c==3){
				for(int i=0;i<5;i++)System.out.println(3);
			}
			else if(!u[1]){
				for(int i=0;i<5;i++)System.out.println(h[i]==2?1:2);
			}
			else if(!u[2]){
				for(int i=0;i<5;i++)System.out.println(h[i]==3?1:2);
			}
			else{
				for(int i=0;i<5;i++)System.out.println(h[i]==1?1:2);
			}
		}
	}
}

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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	int N, ans = 0;
	
	cin >> N;
	
	int L[N];
	
	rep(i, N)
		cin >> L[i];
		
	sort(L, L + N);
	
	rep(i, N){
		int k = i;
		for(int j=i+1; j<N; j++){
			while(k < N && L[k] < L[i] + L[j])
				k++;
			ans += max(0, k - (j + 1));
		}
	}
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
#define MAXN 200000
#define LL long long
LL read(){
    LL x=0,F=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*F;
}
char s[MAXN+5];
int n,ans,cnt,flag;
char pre;
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	int i;pre='0';
	for(i=1;i<=n;i++)
	if(s[i]==pre){pre='0';flag=1;}
	else {if(!flag)pre=s[i];flag=0;ans++;}
	printf("%d",ans);
}

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

import sys
sys.setrecursionlimit(300000)

MOD = 1000000007  # type: int

def get_fraction_mod(numerator, denominator):
    '''
        returns numerator / denominator (mod MOD)
    '''
    inv = pow(denominator, MOD - 2, MOD)
    return numerator * inv % MOD

def make_facts(n):
    '''
        make factorials
        0!(=1), 1!, 2!, 3! .... n!
    '''
    fact = [1]
    for i in range(n):
        fact.append((fact[i] * (i + 1)) % MOD)
    return fact

def make_combs_(n, k):
    '''
        make [C(0, k), C(1, k), C(2, k) ..... C(n, k)]
    '''
    fact = [1] * (n + 1)
    for i in range(2, n + 1):
        fact[i] = (fact[i - 1] * i) % MOD

    ret = [0] * (n + 1)
    for i in range(k, n + 1):
        a = fact[i]
        b = (fact[k] * fact[i - k]) % MOD
        ret[i] = get_fraction_mod(a, b)
    return ret

def solve(N: int, K: int, A: "List[int]"):
    A.sort()
    combs = make_combs_(N, K - 1)
    mins = 0
    maxs = 0
    for i in range(N):
        mins += combs[N - i - 1] * A[i]
        mins %= MOD
        maxs += combs[i] * A[i]
        maxs %= MOD
    ret = maxs - mins
    ret %= MOD
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()


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

int main(){
  string s, t, u;
  int a, b;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if(s == u){
    cout << a-1 << ' ' << b << endl;
  }else{
    cout << a << ' ' << b-1 << endl;
  }
  return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N; cin >> N;
    string direction; cin >> direction;

    vector<i64> CL(N + 1, 0);
    vector<i64> CR(N + 1, 0);
    REP(i, N) {
        CL[i + 1] = CL[i] + (direction[i] == 'W');
        CR[i + 1] = CR[i] + (direction[N - 1 - i] == 'E');
    }

    i64 min_n = N + 1;
    REP(i, N) {
        chmin(min_n, CL[i] + CR[N - i - 1]);
    }
    cout << min_n << endl;

    return 0;
}

Measured memory_bytes: 5396
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) {
			break;
		}
		vector<vector<int>> v(n, vector<int>(n));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> v[i][j];
			}
		}
		// vertical sum
		vector<int> vert(n);
		for (int i = 0; i < n; i++) {
			vert[i] = 0;
			for (int j = 0; j < n; j++) {
				vert[i] += v[i][j];
			}
		}
		// horizon sum
		vector<int> hori(n);
		for (int i = 0; i < n; i++) {
			hori[i] = 0;
			for (int j = 0; j < n; j++) {
				hori[i] += v[j][i];
			}
		}
		// all sum
		int sum = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				sum += v[i][j];
			}
		}

		for (int i = 0; i < n; i++) {
			cout << setw(5) << right << v[i][0];
			for (int j = 1; j < n; j++) {
				cout << setw(5) << right << v[i][j];
			}
			cout << setw(5) << right << vert[i] << endl;
		}
		cout << setw(5) << right << hori[0];
		for (int i = 1; i < n; i++) {
			cout << setw(5) << right << hori[i];
		}
		cout << setw(5) << right << sum << endl;
	}
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector <long> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    a.erase(unique(a.begin(),a.end()),a.end());
    if(n!=a.size()){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 1792
import numpy as np
import sys
read = sys.stdin.read
 

D = int(input())
CS = np.array(read().split(), np.int32)
C = CS[:26]
S = CS[26:].reshape((-1, 26))
del CS
 
last = np.zeros((26, ))
ans = []


def getContestType_at_d(d):
    s = -10000000
    for i in range(26):
        mask = np.ones((26, ))
        mask[i] = 0
        score = S[d][i] - np.sum(C * (d + 1 - last) * mask)
        score -= np.sum(C * (min(365, d + 13) + 1 - last))
        if s < score:
            s = score
            t = i
 
    last[t] = d + 1
 
    return t + 1, s
#score = 0
for d in range(D):
    t, _ = getContestType_at_d(d)
    ans.append(t)
    #score += s
    #print('score:', score)
 
 
print('\n'.join(map(str, ans)))

Measured memory_bytes: 27688
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# N = int(input())
# A,B,C = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]

N = int(input())
W = [int(x) for x in input().split()]

ans = float("INF")
for i in range(N - 1):
    s1 = sum(W[0:i + 1])
    s2 = sum(W[i + 1:])
    ans = min(ans, abs(s1 - s2))

print(ans)


Measured memory_bytes: 3944
import sys
from heapq import heapify, heappushpop

read = sys.stdin.read
readline = sys.stdin.readline

X, Y, A, B, C = map(int, readline().split())
p = list(map(int, readline().split()))
q = list(map(int, readline().split()))
r = [0] + list(map(int, readline().split()))
p.sort()
q.sort()
r.sort()
heap_p = p[-X:]
heap_q = q[-Y:]
heapify(heap_q)
heapify(heap_p)
while r[-1] > heap_p[0] or r[-1] > heap_q[0]:
    if heap_q[0] < heap_p[0]:
        heappushpop(heap_q, r.pop())
    else:
        heappushpop(heap_p, r.pop())

print(sum(heap_p) + sum(heap_q))


Measured memory_bytes: 22720
package main

import "fmt"

func main() {
	var n, a, b, i int64
	fmt.Scan(&n)
	fmt.Scan(&a)
	fmt.Scan(&b)
	x := make([]int64, n)
	for i=0; i<n; i++ {
		fmt.Scan(&x[i])
	}
	var result int64 = 0
	for i=1; i<n; i++ {
		if a * (x[i] - x[i-1]) > b {
			result += b
		} else {
			result += a * (x[i] - x[i-1])
		}
	}
	fmt.Printf("%v\n", result)
}

Measured memory_bytes: 5504
def cinr(w, h, x, y, r)
  a = w-r
  b = h-r
  if x <= a && x >= r && y <= b && y >= r
    puts "Yes"
  else
    puts "No"
  end
end

w,h,x,y,r = gets.split(' ').map(&:to_i)
cinr(w,h,x,y,r)

Measured memory_bytes: 8712
#include<bits/stdc++.h>
using namespace std;
int dd(double a){
  if(a<165)return 0;
  if(a<170)return 1;
  if(a<175)return 2;
  if(a<180)return 3;
  if(a<185)return 4;
  return 5;
}
int main(){
  int n,d[6]={};
  cin>>n;
  double h;
  for(int i=0;i<n;i++)
    cin>>h,d[dd(h)]++;
  for(int i=0;i<6;i++){
    cout<<i+1<<':';
    for(int j=0;j<d[i];j++)cout<<'*';
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
template <typename T>
T pow(T a, ll n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}
 
template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
 
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
 
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};
 
using mint = ModInt<1000000007>;
using Graph = vector<vector<int>>;
Graph G;
/*------------------------------------------------------------------*/
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll sum = 0;
    _rep(i, 1, n){
        if(a[i - 1] > a[i]){
            sum += a[i - 1] - a[i];
            a[i] = a[i - 1];
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 4740
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

int main(){
   int n;
   cin >> n;
   vector<int> h(n);
   int MAX = 0,cnt=0;
   rep(i,n){
      cin >> h[i];
      if(!i)continue;
      
      if(h[i-1]>=h[i]) cnt++;
      else if(h[i-1]<h[i]){
         MAX = max(MAX,cnt);
         cnt=0;
      }
      if(i==n-1){
         MAX = max(MAX,cnt);
      }
   }
   cout << MAX <<endl;


   return 0;
}

Measured memory_bytes: 640
def bubblesort(N,A):
    flag = 1
    counta = 0
    while flag:
        flag = 0
        for j in range(N-1,0,-1):
            if A[j] < A[j-1]:
                A[j],A[j-1] = A[j-1],A[j]
                flag = 1
                counta += 1
    print(" ".join(map(str,A)))
    print(counta)

bubblesort(int(input()),list(map(int,input().split())))

            


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
     
    int n,k;cin>>n>>k;
    int a[n],ans[n]={0};
    for(int i=0;i<n;i++)cin>>a[i];
    ans[n-1]=0;
    for(int i=n-2;i>=0;i--){
        int x=1000'000'001;
        for(int j=1;j<=k&&i+j<n;j++)
        x=min(ans[i+j]+abs(a[i+j]-a[i]),x);
        ans[i]=x;
    }
    cout<<ans[0];
}

Measured memory_bytes: 1024
def main():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))
    cnt = 0
    D = 0
    bounds = [D]
    for a in A:
        D += a
        bounds.append(D)

    for b in bounds:
        if b <= X:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法
#define JUUHATI 1000000000000000000 
#define JUUHATIPLUS 1000000000000000001 

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    ll X ,ans500,ans5;
    cin >> X;

    ans500 = X / 500;
    X -= ans500 * 500;
    ans5 = X / 5;

    cout << 1000 * ans500 + 5 * ans5 << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;

template <typename T>
struct SegmentTree{
    typedef function<T(T,T)> F;
    int n;
    F f;
    T unit;
    vector<T> dat;
    SegmentTree(){};
    SegmentTree(int newn,F f,T t):f(f),unit(t){
        init(newn);
    }
    SegmentTree(const vector<T> &v,F f,T t):f(f),unit(t){
        int n_ = v.size();
        init(n_);
        for(int i=0;i<n_;i++)dat[n+i]=v[i];
        for(int i=n-1;i;i--){
            dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
        }
    }

    void init(int n_){
        n=1;
        while(n<n_)n<<=1;
        dat.assign(n<<1,unit);
    }
    /*void build(const vector<T> &v){
        int n_=v.size();
        init(n_);
        for(int i=0i<n_;i++)dat[n+i]=v[i];
        for(int i=n-1;i;i--)
            dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
    }*/
    void update(int k,T x){
        dat[k+=n]=x;
        while(k>>=1)
            dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
    }
    T query(int a,int b){
        T vl=unit,vr=unit;
        for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1){
            if(l&1)vl=f(vl,dat[l++]);
            if(r&1)vr=f(dat[--r],vr);
        }
        return f(vl,vr);
    }

};

ll n,q;
SegmentTree<ll>seg;
string s;

unsigned long long popcount(unsigned long long x) {
  x = ((x & 0xaaaaaaaaaaaaaaaaUL) >> 1) +
      (x & 0x5555555555555555UL);
  x = ((x & 0xccccccccccccccccUL) >> 2) +
      (x & 0x3333333333333333UL);
  x = ((x & 0xf0f0f0f0f0f0f0f0UL) >> 4) +
      (x & 0x0f0f0f0f0f0f0f0fUL);
  x = ((x & 0xff00ff00ff00ff00UL) >> 8) +
      (x & 0x00ff00ff00ff00ffUL);
  x = ((x & 0xffff0000ffff0000UL) >> 16) +
      (x & 0x0000ffff0000ffffUL);
  x = ((x & 0xffffffff00000000UL) >> 32) +
      (x & 0x00000000ffffffffUL);
  return x;
}

int main(void){
    cin>>n>>s>>q;
    auto f = [] (long long l, long long r) { return l | r; };
    seg = SegmentTree<ll>(n,f,0);
    for(ll i=0;i<n;i++){
        seg.update(i,(1LL<<s[i]-'a'));
    }
    for(ll i=0;i<q;i++){
        int x;
        cin>>x;
        if(x==1){
            ll index;
            char c;
            cin>>index>>c;
            seg.update(index-1,1LL<<(c-'a'));
        }
        else{
            ll l,r;
            cin>>l>>r;
            cout<<popcount(seg.query(l-1,r))<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 9092
using System;
using System.Collections.Generic;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var d = new Dictionary<string,int>();
            var p = Console.ReadLine();
            d.Add(p,1);

            var f = true;
            for(var i = 1; i < n; i++){
                var s = Console.ReadLine();
                if(d.ContainsKey(s)){
                    f = false;
                }else{
                    d.Add(s,1);
                }

                if(p[p.Length-1] != s[0]){
                    f = false;
                }
                p = s;
            }

            Console.WriteLine(f ? "Yes" : "No");
        }
    }
}


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

const int MAX_N = 100005;

int N;
int A[MAX_N];

int main()
{
  cin >> N;
  int Sum = 0;
  A[0] = 0;
  for(int i = 1; i <= N; i++) {
    cin >> A[i];
    Sum += abs(A[i-1] - A[i]);
  }
  A[N+1] = 0;

  Sum += abs(A[N]);

  for(int i = 1; i <= N; i++) {
    int tmp = Sum;
    tmp -= abs(A[i-1] - A[i]);
    tmp -= abs(A[i] - A[i+1]);
    tmp += abs(A[i-1] - A[i+1]);
    cout << tmp << endl;
  }

  return 0;
}

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

int main() {
	int a[10010];
	int b[10010];
	int i2, i3 = 0;
	for (int i = 0;i<10010;i++) {
		cin >> a[i];
		cin >> b[i];
		if (a[i] == 0 && b[i] == 0) {
			i2 = i;
			break;
		}
	}
	while (i3 < i2) {
		for (int i4 = 0;i4 < a[i3];i4++) {
			if (i4 % 2 == 1) {
				for (int i5 = 0;i5 < b[i3];i5++) {
					if (i5 % 2 == 1) {
						cout << "#";
					}
					if (i5 % 2 == 0) {
						cout << ".";
					}
				}
				cout << endl;
			}
			else if (i4 % 2 == 0) {
				for (int i5 = 0;i5 < b[i3];i5++) {
					if (i5 % 2 == 1) {
						cout << ".";
					}
					if (i5 % 2 == 0) {
						cout << "#";
					}
				}
				cout << endl;
			}
		}
		cout << endl;
		i3++;
	}
	return 0;
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void uniq(vector<int> &vec){sort(vec.begin(), vec.end());vec.erase(unique(vec.begin(), vec.end()), vec.end());}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){start();COMinit();
    int n,m,k,ans;
    cin>>n>>m>>k;
    int x=( (n*n)%MOD * ((m-1)*m*(m+1)/6)%MOD )%MOD;
    int y=( (m*m)%MOD * ((n-1)*n*(n+1)/6)%MOD )%MOD;
    ans=(COM(n*m-2,k-2)*(x+y))%MOD;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 12160
a=gets.to_i
b=gets.to_i
c=gets.to_i

n=gets.to_i
ans=0
i=0
(a+1).times{
    j=0
    (b+1).times{
        k=0
         (c+1).times{
             
             if  i*500+j*100+k*50==n
                 ans+=1
             end
             
         k+=1    
         }
        
      j+=1  
    }
    
    
    
    
    
    
    i+=1
    
    
    
    }
    
puts ans


Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  c -= b;
  b -= a;
  if(c == b){
    cout << "YES\n";
    return 0;
  }
  cout << "NO\n";
}

Measured memory_bytes: 3636
#include <utility>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <iostream>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;
int main() {
    ll a,b,n;
    cin >> a >> b >> n;
    cout << a*min(n,b-1)/b;
    return 0;
}

Measured memory_bytes: 3632
import math
from collections import deque
from collections import defaultdict

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

n,m,x = readInts()
a = readInts()
forzero = len([i for i in a if i<x])
forend = len(a)-forzero

print(min(forzero,forend))

Measured memory_bytes: 3444
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

	int n = N % 10;
	if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
	{
		cout << "hon" << endl;
		return 0;
	}
	else if (n == 0 || n == 1 || n == 6 || n == 8)
	{
		cout << "pon" << endl;
		return 0;
	}

	cout << "bon" << endl;

	return 0;
}

Measured memory_bytes: 3028
A, B, C, D = map(int, input().split())

def lcm(x, y):
    return x * y // gcd(x, y)
def gcd(x, y):
    if y== 0:
        return x
    else:
        return gcd(y, x % y)
A -= 1
# A-1以下でC, Dで割り切れる数
a = (A // C + A // D) - A // lcm(C, D)
# B以下でC, Dで割り切れる数
b = (B // C + B // D) - B // lcm(C, D)

print(B-A-(b-a))


Measured memory_bytes: 3060
s = input()
i = len(s) - 1
if s[i] == '2' or \
    s[i] == '4' or \
    s[i] == '5' or \
    s[i] == '7' or \
    s[i] == '9':
    print('hon')
elif s[i] == '0' or \
    s[i] == '1' or \
    s[i] == '6' or \
    s[i] == '8':
    print('pon')
else:
    print('bon')

Measured memory_bytes: 9132
#include<iostream>
#include<cstdio>
#include<cstring>
char a[100001];
int main(int argc,char*argv[]){
	gets(a);
	int n = strlen(a);
	int t = 19260817;
	for(int i = 0; i <= n - 1; i ++){
		if(a[i] ==  'C') t = i;
		if(a[i] ==  'F' && i > t){
			printf("Yes");
			return 0;
		} 
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define repm(i, a, b) for(int i = (a); i >= (b); i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える




int main(){
    int n;
    cin >> n;
    
    int a = n/100;
    int b = n%100 /10;
    int c = n%10;

    bool tmp = a == 7 || b == 7 || c == 7;

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

Measured memory_bytes: 3652
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1073741824
#pragma GCC optimization ("O3")
using namespace std;
const int N = 100*1000+5;
#define all(x) begin(x),end(x)
int main()
{
   
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long long int t,a,k,l = 0;
    cin >> t >> a >> k;
    if(k <= t)
    {
        cout << t-k << " " << a;
        return 0;
    }
    else
    {
        cout << 0 << " " << max(l,a-(k-t));
        return 0;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct RollingHash
{
  vector< unsigned > hashed, power;
  RollingHash(const string& s, unsigned _base = 1000000007)
  {
    _base = _base;
    int sz = s.size();
    hashed.assign(sz + 1, 0);
    power.assign(sz + 1, 0);
 
    power[0] = 1;
    for(int i = 0; i < sz; i++) {
      power[i + 1] = power[i] * _base;
    }
    for(int i = 0; i < sz; i++) {
      hashed[i + 1] = (hashed[i] + s[i]) * _base;
    }
  }
  unsigned get(int l, int r) // [l, r)
  {
    return((hashed[r] - hashed[l] * power[r - l]));
  }
};

int main()
{
  int N, M;
  scanf("%d %d", &N, &M);
  char S[300001];
  scanf(" %s", S);
  RollingHash hash1(S), hash2(S, 1e9+9);
  vector< tuple< unsigned, unsigned > > poyo;
  int l = 0, r = 1;
  while(M--) {
    scanf("%s", S);
    if(S[0] == 'R') {
      if(S[1] == '+') ++r;
      else --r;
    } else {
      if(S[1] == '+') ++l;
      else --l;
    }
    poyo.emplace_back(hash1.get(l, r), hash2.get(l, r));
  }
  sort(poyo.begin(), poyo.end());
  poyo.erase(unique(poyo.begin(), poyo.end()), poyo.end());
  printf("%d\n", poyo.size());
}

Measured memory_bytes: 12088
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int const MD=int(1e9)+7;
int const MAXNM=220000;

inline int madd(int x,int y) {
	if (x+y<MD) return x+y; else return x+y-MD;
}
inline int msub(int x,int y) {
	if (x-y>=0) return x-y; else return x-y+MD;
}
inline int mmul(int x,int y) {
	return int(ll(x)*y % MD);
}
int mpow(int x,int y) {
	int res=1;
	while (y>0) {
		if (y%2) res=mmul(res,x);
		x=mmul(x,x);
		y/=2;
	}
	return res;
}
inline int minv(int x) {
	return mpow(x,MD-2);
}

int fact[MAXNM];
int invfact[MAXNM];
void mfact_init() {
	fact[0]=invfact[0]=1;
	rep(i,1,MAXNM) {
		fact[i]=mmul(fact[i-1],i);
		invfact[i]=minv(fact[i]);
	}
}
inline int mcomb(int x,int y) {
	if (x<y) return 0;
	return mmul(fact[x],mmul(invfact[x-y],invfact[y]));
}

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

	mfact_init();

	int N,M,K;
	cin>>N>>M>>K;
	
	int res=0;
	rep(dx,1,N) res=madd(res,mmul(dx,mmul(N-dx,mmul(M,M))));
	rep(dy,1,M) res=madd(res,mmul(dy,mmul(M-dy,mmul(N,N))));
	res=mmul(res,mcomb(N*M-2,K-2));
	
	cout<<res<<"\n";
}


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

int main()
{
  int i=0;
  char a;
  while(1){
    scanf("%c",&a);
    if('a'<=a && a<='z')printf("%c",a-32);
    else if('A'<=a && a<='Z')printf("%c",a+32);
    else cout<<a;
    if(a=='\n')break;
  }
  return 0;
}

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

struct UnionFind {
    vector<int> par, s;

    UnionFind(int n) : par(n), s(n, 1) {
        for(int i = 0; i < n; i++) par[i] = i;
    }

    int root(int n) {
        return par[n] == n ? n : root(par[n]);
    }

    void unite(int n, int m) {
        n = root(n);
        m = root(m);
        if (n == m) return;
        if (s[n] < s[m]) swap(n, m);
        s[n] += s[m];
        par[m] = n;
    }

    int size(int n) {
        return s[root(n)];
    }

    bool same(int n, int m) {
        return root(n) == root(m);
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> p(n);
    for(auto& e : p){
        cin >> e;
        e--;
    }
    UnionFind un(n);
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y, x--, y--;
        un.unite(x, y);
    }
    int cnt = 0;
    for (int i = 0; i < n; i++){
        if(un.same(i, p[i])) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1408
def calc_max_biscuit(K,A,B):
    #ビスケットを売り買いして得る儲けが1以下なら、K回ポケットを叩いた結果を返す。
    hit_only = 1+K
    sell_and_buy = 0
    if B-A<1:
        print(hit_only)
    else:
        K -= (A-1)
        if K%2==0:
            sell_and_buy = A + int(K/2)*(B-A)
        else:
            sell_and_buy = A + int(K/2)*(B-A)+1
        print(max(sell_and_buy, hit_only))
        
K, A, B = list(map(int, input().split()))
calc_max_biscuit(K,A,B)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, k, s;
  cin >> n >> k >> s;
  int m = 1000000000;
  rep(i, n) {
    if(k > 0) {
      cout << s << ' ';
      k--;
    } else {
      if(s == m)
        cout << 1 << ' ';
      else
        cout << m << ' ';
    }
  }
  cout << endl;
}

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

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

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

    ll a,b,c,d;
    cin >> a >> b >> c >> d;

    ll ans = 0;

    for (ll i = 0; i <= 99; i++){
        if (a <= i && i < b && c <= i && i < d){
            ans++;
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 3624
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef _DEBUG

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 105
#define MAX_M 55
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	// WF("output.txt");
	DF("err.txt");

	int r;
	scanf("%d", &r);
	printf("%d\n", 3 * r* r);
	return 0;
}

Measured memory_bytes: 256
n=int(input())
ab = [[0,0,0]]
for _ in range(n):
    a, b, c = (int(x) for x in input().split())
    if abs(ab[-1][0]-a) >= abs(ab[-1][1]-b)+abs(ab[-1][2]-c) and abs(abs(ab[-1][0]-a)-abs(ab[-1][1]-b)-abs(ab[-1][2]-c))%2==0:
        ab.append([a,b,c])
    else:
        print('No')
        exit()
print('Yes')

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

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

const int cys=1000000007;
int n,k,cnt; ll ans=1;
ll fac[155],inv[155],f[75],nxt[75][2],now[2],a[75],b[75];
char s[75];
bool vis[75];

ll mod(ll x){return x>=cys?x-cys:x;}
ll C(ll x,ll y){return x<y?0:fac[x]*inv[y]%cys*inv[x-y]%cys;}

ll qpow(ll x,ll p){
	ll ret=1;
	for(;p;p>>=1,x=x*x%cys) if(p&1) ret=ret*x%cys;
	return ret;
}

ll getans(){
	memset(vis,0,sizeof(vis));
	int pl=0,num=0;
	for(int i=1;i<=cnt;i++) if(f[i]==1) num++;
	for(int i=1;i<=cnt;i++){
		pl=nxt[pl][0];
		if(pl>k) return 0;
		a[i]=pl,vis[pl]=1;
	}
	for(int i=1;i<=cnt-num;i++){
		int tmp=nxt[a[i]][1];
		while(vis[tmp]) tmp=nxt[tmp][1];
		if(tmp>k) return 0;
		b[i]=tmp,vis[tmp]=1;
	}
	int now=cnt-num,pcnt=f[now];
	while(f[now]==2) now--,pcnt=f[now];
	for(int i=k;i>=1;i--){
		if(vis[i]) continue;
		if(i<b[now]) return 0;
		pcnt--;
		if(pcnt==2) now--,pcnt=f[now];
		if(!now) break;
	}
	if(pcnt>2) return 0;
	int rnum=num,bnum=0,wnum=cnt-1,all=n;
	for(int i=1;i<=cnt-num;i++) rnum+=f[i]-2,bnum+=f[i]-1;
	all-=rnum+bnum+wnum;
	if(all<0) return 0;
	ll res=fac[cnt],lst=1;
	for(int i=1;i<=cnt;i++) if(f[i]!=f[i-1]&&i>1) res=res*inv[i-lst]%cys,lst=i;
	res=res*inv[cnt+1-lst]%cys;
	return res*C(all+rnum+bnum+wnum+(cnt-num)*2+1,rnum+bnum+wnum+(cnt-num)*2+1)%cys;
}

void dfs(int now,int sum,int all,bool tp){
	if(all>n) return;
	if(!tp) ans=mod(ans+getans());
	if(!sum||!now) return;
	for(int i=0;i<=sum/now;i++){
		dfs(min(now-1,sum-i*now),sum-i*now,all+i*(now==1?1:2*now-3),i==0?1:0);
		f[++cnt]=now;
	}
	cnt-=sum/now+1;
}

int main(){
	n=readint(); k=readint();
	fac[0]=inv[0]=1;
	for(int i=1;i<=150;i++) fac[i]=fac[i-1]*i%cys;
	inv[150]=qpow(fac[150],cys-2);
	for(int i=149;i>=1;i--) inv[i]=inv[i+1]*(i+1)%cys;
	scanf("%s",s+1);
	now[0]=now[1]=k+1;
	for(int i=k;i>=0;i--){
		nxt[i][0]=now[0],nxt[i][1]=now[1];
		if(s[i]=='r') now[0]=i;
		else now[1]=i;
	}
	dfs(k,k,0,1);
	printf("%lld\n",ans);
	return 0;
}

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

class UnionFind{
    public:
        vector<ll> par;
        vector<ll> siz;

    UnionFind(ll sz_):par(sz_),siz(sz_,1){
        rep(i,sz_)par[i] =i;
    }
    
    void init(ll sz_){
        par.resize(sz_);
        siz.assign(sz_,1);
        rep(i,sz_)par[i] =i;
    }
    
    ll root(ll x){
        while(par[x] != x){
            x = par[x] = par[par[x]];
        }
        return x;
    }
    
    bool unite(ll x,ll y){
        x = root(x);
        y = root(y);
        if(x == y) return false;
        if(siz[x] < siz[y]) swap(x,y);
        siz[x] += siz[y];
        par[y] = x;
        return false;
    }
    
    bool issame(ll x,ll y){return root(x) == root(y);}
    
    ll size(ll x){return siz[root(x)];}
};

ll N,M;
int main(void){
    cin >> N >> M;
    pair <ll,ll> br[M];
    rep(i,M) cin >> br[i].first >> br[i].second;
    ll ans[M];
    UnionFind UT(N);
    ans[M-1] = N*(N-1)/2;
    for(ll i=0;i<M-1;i++){
        ll A =br[M-i-1].first-1,B=br[M-i-1].second-1;
        if(UT.root(A) == UT.root(B)) ans[M-2-i] = ans[M-1-i];
        else ans[M-2-i] = ans[M-1-i] - UT.size(A)*UT.size(B);
        UT.unite(A,B);
    }
    rep(i,M)cout << ans[i] << endl;
}

Measured memory_bytes: 5248
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int d,n;
    while(cin>>d>>n)
    {
        int x=1;
       for(int i=1;i<=d;i++)
        x=x*100;
        n=n+n/100;
       cout<<n*x<<endl;
    }
    return 0;
}


Measured memory_bytes: 256