akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class UnionFind():
    def __init__(self):
        self.__table = {}
        self.__size = defaultdict(lambda: 1)

    def __root(self, x):
        if x not in self.__table:
            self.__table[x] = x
        elif x != self.__table[x]:
            self.__table[x] = self.__root(self.__table[x])

        return self.__table[x]

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

    def union(self, x, y):
        x = self.__root(x)
        y = self.__root(y)
        if x != y:
            self.__size[y] += self.__size[x]
            self.__table[x] = y

    def size(self, x):
        return self.__size[self.__root(x)]

    def num_of_group(self):
        g = 0
        for k, v in self.__table.items():
            if k == v:
                g += 1
        return g


@mt
def slv(N, M, XYZ):
    uf = UnionFind()
    v = set()
    for x, y, _ in XYZ:
        uf.union(x, y)
        v.add(x)
        v.add(y)

    ans = uf.num_of_group() + N - len(v)
    return ans


def main():
    N, M = read_int_n()
    XYZ = [read_int_n() for _ in range(M)]
    print(slv(N, M, XYZ))


if __name__ == '__main__':
    main()


Measured memory_bytes: 50492
#![allow(unused_imports)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

fn main() {
    let _n = read!(usize);
    let t: Vec<usize> = read![[usize]];
    let m = read!(usize);
    let px: Vec<(usize, usize)> = read![usize, usize; m];

    for i in 0..m {
        let s: usize = t
            .iter()
            .enumerate()
            .map(|(k, x)| if px[i].0 == k + 1 { px[i].1 } else { *x })
            .sum();
        println!("{}", &s);
    }
}


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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const ll MOD = 1e9 + 7;
int main(){
    fIO
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);

    int n;
    cin >> n;

    int A[n + 5] = {};
    for(int i = 1; i <= n; i++) {
        cin >> A[i];
    }

    ll pre[n + 5] = {};
    for(int i = 1; i <= n; i++) {
        pre[i] += pre[i - 1] + (ll) A[i];
        pre[i] %= MOD;
    }


    ll ans = 0;
    for(int i = 2; i <= n; i++) {
        ans += pre[i - 1] * A[i];
        ans %= MOD;
    }

    cout << ans;
}








Measured memory_bytes: 5984
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String s = stdIn.next();
		char[] words = s.toCharArray();
		int min = 0;
		int max = 0;
		for(int i = s.length()-1; i >= 0; i--) {
			if(words[i] == 'A') {
				min = i;
			}
		}
		for(int i = 0; i < s.length(); i++) {
			if(words[i] == 'Z') {
				max = i;
			}
		}
		System.out.println(max-min+1);

	}

}

Measured memory_bytes: 27780
from fractions import gcd
a,b,c,d=map(int,input().split())

lcm=c*d//gcd(c,d)

divc=(b//c) - ((a-1)//c)
divd=(b//d) - ((a-1)//d)
divcd=(b//lcm) - ((a-1)//lcm)
print((b-a+1)-(divc+divd-divcd))

Measured memory_bytes: 5048
#include <bits/stdc++.h>
#define optimize ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define INF 2000000020LL
#define ALL(x) x.begin(), x.end()
#define UNIQUE(c) (c).resize(unique(ALL(c)) - (c).begin())
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define POS(n, x) (lower_bound(ALL(n), x) - (n).begin())
#define ll long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define PB push_back
#define EB emplace_back
#define MOD 1000000007
#define PRIME 101 
#define MAXN 200020
#define MAXL 23
#define endl '\n'

using namespace std;

// (1 + sqrt(5)) / 2
const ld GOLDEN_RATIO = 1.6180339887498949025257388711906969547271728515625;
const ld PI = 2.0 * acos(0.0);
const int BLOCK = 333;

int dp[MAXN];
vi grafo[MAXN];

int solve(int u)
{
	if(dp[u] != -1) return dp[u];

	int ans = 0;

	for(auto v : grafo[u])
		ans = max(ans, 1 + solve(v));

	return dp[u] = ans;
}

int main(int argc, char const *argv[])
{
	optimize;
	
	memset(dp, -1, sizeof dp);

	int N, M, u, v;

	cin >> N >> M;

	while(M--)
	{
		cin >> u >> v;

		grafo[u].PB(v);
	}

	int ans = 0;

	for(int i = 1; i <= N; i++)
		ans = max(ans, solve(i));

	cout << ans << endl;

	return 0;
}

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

int main(){
    int A,B;
    cin >> A >> B;
    char c[A+B+1];
    for(int i=0;i<A+B+1;i++){
        cin >> c[i];
    }
    bool flag=1;
    for(int i=0;i<A+B+1;i++){
        if(i==A){
            if(c[i]!='-'){
                flag=0;
            }
        }
        else{
            if(c[i]=='-'){
                flag=0;
            }
        }
    }
    if(flag)
    cout << "Yes" << endl;
    else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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; }

int main() {
    int n; cin >> n;
    vector<string> v(n);
    rep(i, n) cin >> v[i];

    int ans = 0;
    for (auto s: v) {
        rep(i, s.size() - 1) {
            if (s[i] == 'A' && s[i+1] =='B') ans++;
        }
    }

    int c1 = 0, c2 = 0, c3 = 0;
    for (auto s: v) {
        if (s.front() == 'B' && s.back() == 'A') c1++;
        if (s.front() == 'B' && s.back() != 'A') c2++;
        if (s.front() != 'B' && s.back() == 'A') c3++;
    }

    if (c1 == 0) ans += min(c2, c3);
    else {
        if (c2 + c3 > 0) ans += c1 + min(c2, c3);
        else ans += c1 - 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 768
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    int x = n;
    int s = 0;
    while (x != 0)
    {
        s += x % 10;
        x /= 10;
    }
    if (n % s == 0)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


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

#define ll long long
#define ull unsigned long long
#define vii vector<int>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define pldld pair<long long double, long long double>
#define ff first
#define ss second
#define pb push_back
#define read freopen("alu.txt","r",stdin);
#define write freopen("vorta.txt","w",stdout);
#define fastio ios::sync_with_stdio(false); cin.tie(NULL);
#define PI 2*acos(0.0)
#define DEBUG(x) cerr << #x << " = " << x << endl

const int MAX = 1e6 + 5, MOD = 1e9 + 7  , MAXLG = log2(MAX)+1;
const ll inf = 1e18 + 5;

int arr[MAX];
ll sum[MAX];
int main(){

    fastio;
    int n;
    ll k;
    cin>>k>>n;
    vector<ll>v;
    for(int i=0; i<n; i++){
        ll val;
        cin>>val;
        v.pb(val);
    }
    sort(v.begin(), v.end());
    for(int i=0; i<n; i++){
        ll val = k + v[i];
        v.pb(val);
    }

    sum[0] = 0;
    for(int i=1; i<v.size(); i++) sum[i] = v[i] - v[i-1];
    for(int i=1; i<v.size(); i++){
        sum[i] += sum[i-1];
    }

    ll ans = inf;
    for(int i=n-1; i<v.size(); i++) ans = min(ans, sum[i] - sum[i-n+1]);

    cout<<ans<<"\n";
}


Measured memory_bytes: 8556
#include<cstdio>

using namespace std;

int main(){
	for(int n;scanf("%d",&n),n;){
		int cnt[10]={};
		while(n--){
			int a;	scanf("%d",&a);
			cnt[a]++;
		}
		for(int i=0;i<10;i++){
			for(int j=0;j<cnt[i];j++)	putchar('*');
			puts(cnt[i]?"":"-");
		}
	}
	return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cerr << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

class unionfind {
	vector<int> par;

public:
	void init(int n) {
		par.resize(n);

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

	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return ;
		par[y] = x;
	}

	bool same(int x, int y) { return (find(x) == find(y)); }
} uf;

const double INF = 1e9;

using Data = pair<pii, ll>;
const int maxn = 200010;

Data node[maxn];

int main() {
	int N; cin >> N;
	uf.init(N);

	V<int> P(N, -1), V(N);

	for (int i = 1; i < N; ++i) {
		cin >> P[i];
		--P[i];
	}

	priority_queue<pair<double, int>> que;

	rep(i, N) {
		cin >> V[i];
		node[i] = mp(mp(V[i], 1 - V[i]), 0ll);
		if (i) {
			que.push(mp((V[i] == 0 ? INF : 0), i));
		}
	}

	while (!que.empty()) {
		auto t = que.top(); que.pop();
		int v = t.se;

		int id = uf.find(v);
		int pid = uf.find(P[v]);

		if (id == pid) continue;

		Data nx = mp(mp(node[id].fi.fi + node[pid].fi.fi, node[id].fi.se + node[pid].fi.se), node[id].se + node[pid].se + (ll)node[pid].fi.fi * node[id].fi.se);
		uf.unite(pid, id);
		node[pid] = nx;

		if (P[v] != 0) {
			que.push(mp(nx.fi.fi == 0 ? INF : (double)nx.fi.se / nx.fi.fi, pid));
		}
	}
	cout << node[0].se << endl;

	return 0;
}

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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<int, int> P;
typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;
#define ret() return 0;

bool contain(set<char> &s, char a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

class CumulativeSum {
    vector<ll> numbers;
    vector<ll> sums;

public:
    CumulativeSum(int n) {
        numbers.resize(n);
        sums.resize(n);
    }

    void set(int i, ll value) {
        numbers[i] = value;
    }

    ll getSum(int i) {
        if (i == -1) return 0;
        if (i == sums.size()) return 0;
        return sums[i];
    }

    ll getSectionSum(int start, int end) {
        return getSum(end) - getSum(start - 1);
    }

    void calculate() {
        for (int i = 0; i < numbers.size(); i++) {
            sums[i] = getSum(i - 1) + numbers[i];
        }
    }

};

int main() {
    ll l, r;
    cin >> l >> r;

    for (ll i = l; i <= r; i++) {
        if (i % 2019 == 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    ll ans = INF;
    for (ll i = l; i <= r; i++) {
        for (ll j = i + 1; j <= r; j++) {
            ll now = (i * j) % 2019;
            cmin(ans, now);
        }
    }

    cout << ans << endl;
}



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

int main() {

    int n, m; cin >> n >> m;
    int sum = 0;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (4 * m * a[i] < sum) continue;
        cnt++;
    }
    if (m <= cnt) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

 
  char c;
  cin >> c;
  if(c >= 'a' && c <= 'z') cout << "a" << endl;
  else cout << "A" << endl;

  return 0;

}





Measured memory_bytes: 3036
N = int(input())
S = []
for i in range(N):
  S_tmp, P_tmp = input().split()
  P_reverse = chr(100 - int(P_tmp))
  S.append(S_tmp + str(P_reverse) + '_' + str(i+1))
for i in range(N):
  S_sort = sorted(S)
  print(S_sort[i].split('_')[-1])

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrepa(i,a,n) for(int i=(n)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1e9+7

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main(){
   
    int n;cin>>n;
    vi h(n);rep(i,n)cin>>h[i]; 
    
    vi dp(n+1,INT32_MAX);
    dp[0]=0;

    rep(i,n-1){
        dp[i+1] = min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
        dp[i+2] = min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
    }

    cout << dp[n-1] << endl;
    
    return 0;
}

Measured memory_bytes: 1024
type ABC(stream:System.IO.TextReader) =
  member this.Scan1 f = stream.ReadLine() |> f
  member this.Scan2 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1]))
  member this.Scan3 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2]))
  member this.Scan4 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2], a.[3]))
  member this.ScanVecH f = stream.ReadLine().Split() |> Array.map f
  member this.ScanVecV n f = [| for i in 1..n -> stream.ReadLine() |> f |]
  member this.ScanMatrix n f  = [ for i in 1..n do yield stream.ReadLine().Split() |> Array.map f ]
  member this.ScanCharMatrix n = [| for i in 1..n -> stream.ReadLine().ToCharArray() |]
  member this.Close () = stream.Close()

let util = ABC(stdin)

let a,b = util.Scan2 int

if b % a = 0
then printfn "%d" (a+b)
else printfn "%d" (b-a)

Measured memory_bytes: 11996
#include <iostream>
#include <vector>
#include <queue>
#include<map>
#include<algorithm>
#include<set>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<=n;i++)
#define ALL(a) a.begin(),a.end()
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
typedef long long int ll;
int main() {
    int n, m, k; cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n - k) {
        if (a[i] >= a[i + k]) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define ll long long
#define foru(i,a,n) for(int i=(a); i<=(n); i++)
#define ford(i,n,a) for(int i=(n); i>=(a); i--)
using namespace std;
const int N = 111;
typedef pair<int,int> ii;
ll n, a[N], d[N], vt, amax;
vector <ii> cnt;
int main(){
    cin >>n;
    foru(i,1,n) cin >>a[i];
    vt = 1; amax = a[1];
    foru(i, 1, n) if(abs(a[i])>amax){
        vt = i;
        amax = abs(a[i]);
    }
    foru(i, 1, n) a[i] += a[vt];
    foru(i, 1, n) cnt.push_back(ii(vt,i));
    if(a[vt]>0){
        foru(i, 1, n-1) cnt.push_back(ii(i, i+1));
    }
    else{
        ford(i, n, 2) cnt.push_back(ii(i, i-1));
    }
    ///Print result
    cout <<cnt.size() <<"\n";
    for(int i=0; i<cnt.size(); ++i)
        cout <<cnt[i].first <<" " <<cnt[i].second <<"\n";
    return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())

    ans = 0
    for i in range(1, n//2 + 1):
        ans += i * (n//i) * (n//i + 1) // 2

    ans += (n + n//2 + 1) * (n - n//2) // 2

    print(ans)

main()

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

using namespace std;

#define llong long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}

template<typename T> T my_lcm(T a, T b){
	return a * b / my_gcd(a, b);	
}

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    unsigned llong a, b, c, d;
    cin >> a >> b >> c >> d;
    unsigned llong k1 = ceil((long double)a / (long double)c), k2 = b / c;
    unsigned llong k = k2 - k1 + (llong)1;
    // cout << k << endl;
    unsigned llong t1 = ceil((long double)a / (long double)d), t2 = b / d;
    unsigned llong t = t2 - t1 + (llong)1;
    // cout << t << endl;
    unsigned llong p1 = ceil((long double)a / (long double)my_lcm(c, d)), p2 = b / my_lcm(c, d);
    unsigned llong p = p2 - p1 + (llong)1;
    // cout << p << endl;

    unsigned llong ans = (b - a) + (unsigned llong)1 - (k + t - p);
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
a=input().split(" ")
M=int(a[0])
D=int(a[1])
list=[]
count=0
for p in range(4,M+1):
    list.append(p)
for q in range(22,D+1):
    d10=q//10
    d1=q-d10*10
    if d1>=2 and d10>=2:
        if d1*d10 in list:
            count+=1
print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include<cstdlib>


#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for (int i = 0; i < v.size(); ++i) cout << v[i] << c;

typedef long long ll;
using namespace std;

int main()
{
     ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
     int n,i,k,l,c=0,d,p,nl,np;
    int a[51],b;
   cin>>n;
   vector<int> v(n);

   REP(i,n)
   {
    cin>>v[i];

   }
   REP(i,n)
   {
       if(v[i]!=i+1)c++;

   }

   if(c==2 || c==0)cout<<"YES";
   else cout<<"NO";





}

Measured memory_bytes: 3656
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

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

        int n = Integer.parseInt(scan.next());
        int m = Integer.parseInt(scan.next());

        Integer[] a = new Integer[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(scan.next());
        }

        scan.close();

        int sum = 0;
        for (int i : a) {
            sum += i;
        }

        int border = (sum + (4 * m) - 1) / (4 * m);

        Arrays.sort(a, Collections.reverseOrder());

        if (a[m - 1] >= border) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using ll = long long;
#define ull unsigned ll
#define endl "\n"
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(),(v).end()
#define mst(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<int, pii>
#define mt make_tuple
#define eb emplace_back
using namespace std;

const int N = 5e5 + 5, mod = 1e9 + 7;
const int inf = 1e9;
void solve(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int j;
        cin >> j;
        if(i % 2 == 0 && j % 2 == 1){
            ans++;
        }
    }
    cout << ans << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);//cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll t,p;
    t=1;
    //cin>>t;
    for(p=1;p<=t;p++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3632
N=int(input())
S=str(input())
ans=S.count('R')*S.count('G')*S.count('B')

for i in range(N-2):
  for j in range(i+1,N-1):
    if S[i]==S[j]:
      continue
    if 2*j - i < N:
      if S[2*j - i] != S[i] and S[2*j - i] != S[j]:
        ans-=1
print(ans)


Measured memory_bytes: 9088
#include<iostream>
using namespace std;
int main(void){
  int a,b;
  string s;
  cin >> a >> b;
  for(int i = 1;i <= a;i++){
    for(int j = 0;j < b;j++){
      cin >> s;
      if(s == "snuke"){
        cout << (char)('A'+j) << i; 
      }
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fr first
#define sc second
#define mk make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const double eps = 0.000000001;
const int MOD = 1000000009;
const int N = 100005;
int main()
{
      int n, mn = 100000, mx = 0;
      cin >> n;
      for (int i = 1; i <= n; i ++)
      {
            int a;
            cin >> a;
            mn = min(a, mn);
            mx = max(mx, a);
      }
      cout << mx - mn << endl;
      return 0;
}






















Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;

const int MOD = 1000000007;
const int INF = 1000000000;

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


int V; //頂点数
vector<vector<int>> G;

int dfs(int v, vector<bool> visited){
    bool allVisit = true;
    REP(i, V) if(!visited[i]) allVisit = false;
    if(allVisit) return 1;

    int ret = 0;
    for(auto& e : G[v]){
        if(visited[e]) continue;
        visited[e] = true;
        ret += dfs(e, visited);
        visited[e] = false;
    }

    return ret;
}

int main(){
    int m; cin >> V >> m;
    G.resize(V);
    REP(i, m){
        int a, b; cin >> a >> b;
        --a; --b;
        G[a].PB(b); G[b].PB(a);
    }
    vector<bool> visited(V, false);
    visited[0] = true;
    cout << dfs(0, visited) << "\n";
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


ll ptr[100005];
ll sz[100005];
vl ans;
ll getGroup(ll x){
  if(ptr[x] == x) return x;
  else return getGroup(ptr[x]);
}

void joinGroups(ll a, ll b){

  ll tA = getGroup(a);
  ll tB = getGroup(b);
  if(tA == tB){
    ans.pb(ans[ans.size()-1]);
    return;
  }
  if(sz[tA] < sz[tB]) swap(tA,tB);
  if(ans.size() == 0)
    ans.pb(sz[tA]*sz[tB]);
  else
    ans.pb(ans[ans.size()-1] + sz[tA]*sz[tB]);
  sz[tA] += sz[tB];
  ptr[tB] = tA;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ans.pb(0);
    ll n,m;
    cin >> n >> m;
    ll a[m],b[m];
    FOR(i,1,n+1){ ptr[i] = i; sz[i] = 1;}
    FOR(i,1,m+1) cin >> a[i] >> b[i];
    FORd(i,1,m+1) joinGroups(a[i],b[i]);

    ll sum = n*(n-1)/2;
    ll cnt = 1;
    for(auto it=ans.crbegin(); it !=ans.crend(); it++ )
    {
      if(cnt == 1){
        cnt++;
        continue;
      }
      cout << sum - *it << endl;
    }
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 5364
#include <cstdio>
using namespace std;

const int M = 2e5 + 5;
int a[M], n;
long long ans;

int main() {
	scanf("%d", &n);
	scanf("%d", &a[1]);
	for (int i = 1; i < n; i ++) {
		scanf("%d", &a[i + 1]);
		if (a[i + 1] < a[i]) {
			ans += (long long)a[i] - a[i + 1];
			a[i + 1] = a[i];
		}
	}
	printf("%lld", ans);
	return 0;
}

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

const int MAX_N = 3e5+10;
int H, W, M;
int a[MAX_N], b[MAX_N];
int row[MAX_N], col[MAX_N];

void solve()
{
	for(int i=0;i<M;++i){
		row[a[i]]++, col[b[i]]++;
	}
	const int MAXR = *max_element(row,row+H);
	const int MAXC = *max_element(col,col+W);
	// if there is a blank spot where row[i] == MAXR && col[j] == MAXC
	set<pair<int,int>> points;
	for(int i=0;i<M;++i) points.emplace(a[i],b[i]);
	vector<int> R, C;
	for(int i=0;i<H;++i)if(row[i]==MAXR)R.push_back(i);
	for(int i=0;i<W;++i)if(col[i]==MAXC)C.push_back(i);
	if((ll)R.size() * (ll)C.size() > M){
	    cout<<MAXR+MAXC;
	    return;
	}
	for(auto x : R)for(auto y : C){
		if(!points.count(make_pair(x,y))){
			cout<<MAXR+MAXC;
			return;
		}
	}
	cout<<MAXR+MAXC-1<<'\n';
}

int main()
{
	cin >> H >> W >> M;
	for(int i=0;i<M;++i){
		cin >> a[i] >> b[i];
		a[i]--, b[i]--;
	}
	solve();
	return 0;
}

Measured memory_bytes: 26128
from math import ceil
from itertools import product


def main():
    d, g = map(int, input().split())
    g //= 100
    p = [0] * d
    c = [0] * d
    r = [0] * d
    for i in range(d):
        _p, _c = map(int, input().split())
        _c //= 100
        p[i] = _p
        c[i] = _c
    ans = sum(p)
    for m in product((0, 1), repeat=d):
        t = 0
        a = 0
        for i in range(d):
            if m[i] == 1:
                t += p[i] * (i + 1) + c[i]
                a += p[i]
        for i in range(d - 1, -1, -1):
            if m[i] == 1:
                continue
            pi = p[i] * (i + 1)
            if t + pi >= g:
                a += ceil(max(g - t, 0) / (i + 1))
                break
            t += pi + c[i]
            a += p[i]
        ans = min(a, ans)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <cstring>
#include <iomanip>
#include<queue>
#include<set>
#include<stack>
#include<fstream>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007


int main()
{
	string T;
	cin>>T;
	int N;
	N=T.size();

	REP(i,0,N){
		if(T[i]!='P'&&T[i]!='D'){
			T[i]='D';
		}
	}
	cout<<T<<endl;

	
	return 0;
	
}

Measured memory_bytes: 3720
H,W = map(int,input().split())
_input = []
for i in range(H):
    row = list(map(str,input().split()))
    _input.append(list(row[0]))

for i in range(2*H):
    row = ""
    for j in range(W):
        row += _input[int(i/2)][j]
    print(row)

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

struct UnionFind{
    vector<int> par;
    UnionFind(int N) : par(N){
        for(int i = 0; i < N; i++){
            par[i] = -1;
        }
    }
    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        else{
            if(par[rx] > par[ry]) swap(rx, ry);
            par[rx] += par[ry];
            par[ry] = rx;
       }
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    void check(){
        for(auto x : par){
            cout << x << " ";
        }
        cout << endl;
    }
};

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

    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    for(int i = 0; i < m; i++){
        int x, y, z;
        cin >> x >> y >> z;
        uf.unite(x - 1, y - 1);
    }

    set<int> st;
    for(int i = 0; i < n; i++){
        st.insert(uf.root(i));
    }

    cout << st.size() << endl;

    return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
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 h, w;
    cin >> h >> w;
    string grid[h];
    for (int i = 0; i < h; i++) {
        cin >> grid[i];
    }
    ll dp[h + 1][w + 1];
    for (ll i = 0; i < h + 1;i++){
        for (ll j = 0; j < w + 1;j++){
            dp[i][j] = INF;
        }
    }

        dp[0][0] = (grid[0][0] == '#' ? 1 : 0);
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                //下行く
                if(i!=h-1)chmin(dp[i + 1][j], dp[i][j] + ((grid[i+1][j] == '#' and grid[i][j] == '.') ? 1 : 0));
                //右行く
                if(j!=w-1)chmin(dp[i][j + 1], dp[i][j] + ((grid[i][j+1] == '#' and grid[i][j] == '.') ? 1 : 0));
            }
        }
    cout << dp[h-1][w-1] << endl;
}


Measured memory_bytes: 3632
#include<stdio.h>

int main (void){
	
	int b,r,g,c,s,t;
	int gain;
	int use;
	
	for(;;){
	scanf("%d %d %d %d %d %d",&b,&r,&g,&c,&s,&t);
	if(b==0 && r==0 && g==0 && c==0 && s==0 && t==0)break;
	gain = b*15 +r*15 +g*7 + c*2 + (b*5+r*3)*15;
	
	use = (t-s)*3 - (b*5+r*3);
	
	printf("%d\n",gain-use+100);
	}
return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <math.h>
#include <fstream>
#include <algorithm>
#include <functional>


using namespace std;

int main()
{
char a;

cin>>a;
if(a=='A')cout<<'T';
if(a=='T')cout<<'A';
if(a=='C')cout<<'G';
if(a=='G')cout<<'C';



}	


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

dp=[[0,0] for i in range(n)]
b=300
c=0
y=1000
for i in range(0,n-1):
  if a[i]>b:#売る
    j=i+1
    by=0
    while j<n:
      if a[j]<a[i]:
        by=1
        break
      elif a[j]>a[i]:
        break
      j+=1
    if by==1:
      y+=c*a[i]
      c=0
      b=a[i]
  elif a[i]<b and c==0:#買う
    j=i+1
    by=0
    while j<n:
      if a[j]>a[i]:
        by=1
        break
      elif a[j]<a[i]:
        break
      j+=1
  
    if by==1:
      c+=(y//a[i])
      y-=(y//a[i])*a[i]
      
      b=a[i]
print(y+c*a[n-1])
    
    
      
    
   
     

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define updiv(a, b) ((a + b - 1) / b)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  set<int> se;
  rep(i, 0, n) {
    int a;
    cin >> a;
    se.insert(a);
  }
  cout << se.size() << '\n';
  return 0;
}

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

int main()
{
  int ans = 0;
  vector<int> a(5);
  for (int i = 0; i < 5; i++)
  {
    cin >> a.at(i);
    if(a.at(i) == 0){
      ans = i;
    }
  }
  cout << ans +1 << endl;
}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {

    private enum hon {
        HON_2(2),

        HON_4(4),

        HON_5(5),

        HON_7(7),

        HON_9(9);

        private int m_iHon;

        hon(int i) {
            m_iHon = i;
        }
    }

    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        String sInput = sc.nextLine();
        String[] sInputArray = sInput.split("");
        String sCompVal = sInputArray[sInput.length() - 1];
        int iComp = Integer.parseInt(sCompVal);

        String sResult = "";
        for (hon h : hon.values()) {
            if (h.m_iHon == iComp) {
                sResult = "hon";
            }
        }

        if (!sResult.isEmpty()) {
            System.out.print(sResult);
            return;
        }

        if (3 == iComp) {
            sResult = "bon";
        } else {
            sResult = "pon";
        }

        System.out.print(sResult);

    }
}


Measured memory_bytes: 35820
import sys
n = int(sys.stdin.readline()[:-1])
S = [int(x) for x in (sys.stdin.readline()[:-1].split())]
q = int(sys.stdin.readline()[:-1])
T = [int(x) for x in (sys.stdin.readline()[:-1].split())]

count = 0
for t in T:
    l = 0
    h = n - 1
    while l <= h:
        half = (h + l) // 2
        if S[half] == t:
            count += 1
            break
        elif S[half] < t:
            l = half + 1
        else:
            h = half - 1

print(count)

Measured memory_bytes: 18888
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check

const long long MOD = 1000000007;

void solve(std::string S){
    reverse(ALL(S));
    ll N = S.length();
    vector<vll> dp(N, vll(13, 0));
    ll base = 1;
    REP(j, 13){
        if(S[0]== '?'){
            REP(p, 10){
                dp[0][p] = 1;
            }
        }
        else{
            ll p = S[0]-'0';
            dp[0][p] = 1;
        }
    }

    for(ll i= 1; i< N; i++){
        base = (base * 10) % 13;
        REP(j, 13){
            if(S[i] == '?'){
                REP(p, 10){
                    ll a = (p*base) % 13;
                    dp[i][j] = (dp[i][j] + dp[i-1][(j-a+13)%13]) % MOD;
                }
            }
            else{
                ll p = S[i]-'0';
                ll a = (p*base) % 13;
                dp[i][j] = dp[i-1][(j-a+13)%13];
            }
        }
    }
    cout << dp[N-1][5] << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 13696
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datA, datB, datC, datD) = readLine.split(" ").map(_.toInt)
    val onTime = math.max(datA, datC)
    val offTime = math.min(datB, datD)
    val ans = if (offTime < onTime) 0
    else offTime - onTime
    println(ans)
  }
}


Measured memory_bytes: 25532
import math
Q = int(input())

li = [0]
cnt = 0
for i in range(3, 10**5+1, 2):
  flag = True
  for j in range(2, int(math.sqrt(i))+1):
    if i % j == 0:
      flag = False
  for j in range(2, int(math.sqrt((i+1)//2)+1)):
    if ((i+1)//2) % j == 0:
      flag = False
  if flag:
    cnt += 1
  li.append(cnt)
  
for i in range(Q):
  l, r = map(int, input().split())
  if l == 1:
    ans = li[r//2]
  else:
    ans = li[r//2] - li[l//2-1]
  print(ans)

Measured memory_bytes: 9628
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
 
using namespace std;
 
#define DEBUG(x) // cerr << #x << " = " << x << endl
 
const int INF = (int)1e9;
 
int main() {
	int N, M, S, T; cin >> N >> M >> S >> T;
	S--, T--;
	vector<vector<int> > E(N);
	for(int i = 0; i < M; i++) {
		int a, b; cin >> a >> b;
		a--, b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
 
	queue<int> Q;
 
	vector<int> distS(N, INF);
	vector<int> distSumS(N, 0);
 
	Q.push(S);
	distS[S] = 0;
	distSumS[0]++;
	while(!Q.empty()) {
		int cur = Q.front(); Q.pop();
		for(int i = 0; i < (int)E[cur].size(); i++) {
			int to = E[cur][i];
			if(distS[cur] + 1 < distS[to]) {
				Q.push(to);
				distS[to] = distS[cur] + 1;
				distSumS[distS[to]]++;
			}
		}
	}
 
	for(int i = 0; i < N; i++) {
		// cerr << "distS[" << i << "]=" << distS[i] << endl;
		// cerr << "distSumS[" << i << "]=" << distSumS[i] << endl;
	}
 
	Q = queue<int>();
	vector<int> distT(N, INF);
	vector<int> distSumT(N, 0);
 
	Q.push(T);
	distT[T] = 0;
	distSumT[0]++;
	while(!Q.empty()) {
		int cur = Q.front(); Q.pop();
		for(int i = 0; i < (int)E[cur].size(); i++) {
			int to = E[cur][i];
			if(distT[cur] + 1 < distT[to]) {
				Q.push(to);
				distT[to] = distT[cur] + 1;
				distSumT[distT[to]]++;
			}
		}
	}
 
	for(int i = 0; i < N; i++) {
		// cerr << "distT[" << i << "]=" << distT[i] << endl;
		// cerr << "distSumT[" << i << "]=" << distSumT[i] << endl;
	}
 
	int minDist = distS[T];
	DEBUG(minDist);
	long long ans = 0;
	for(int i = 0; i <= minDist - 2; i++) {
		ans += (long long)distSumS[i] * (long long)distSumT[minDist - i - 2];
	}
	cout << ans << endl;
}

Measured memory_bytes: 9156
fn main() {
    proconio::input! {
        s: usize,
    }

    let m = 1000000007;

    let mut dp = vec![0 as usize; s + 1];
    dp[0] = 1;

    for i in 3..=s {
        if i >= 1 { dp[i] += dp[i - 1]; }
        if i >= 3 { dp[i] += dp[i - 3]; }
        dp[i] %= m;
    }

    println!("{}", dp[s]);
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    vector<P> v;
    int mi = INF;
    map<int, int> mp;
    for (int i = 0; i < m; i++) {
        int c, d;
        cin >> c >> d;
        chmin(d, mi);
        chmin(mi, d);
        if (mp.count(c)) {
            chmin(mp[c], d);
        } else {
            mp[c] = d;
        }
    }
    for (auto p : mp) {
        v.push_back(P(p.first, p.second));
    }
    int id = v.size();
    id--;
    priority_queue<ll, vector<ll>, greater<ll>> q;
    ll ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        while (id >= 0 && v[id].first > a[i]) {
            id--;
        }
        ans += b[i];
        q.push(b[i]);
        if (id >= 0 && q.size() >= v[id].second) {
            ans -= q.top();
            q.pop();
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 10420
N, L = map(int, input().split())
lst = []

for i in range(N):
  lst.append(L + (i+1) - 1)
  
if L >= 0:
  print(sum(lst)-lst[0])
elif L+N-1 >= 0:
  print(sum(lst))
else:
  print(sum(lst) - lst[N-1])


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int n = 0;  //数字の個数
    vector<int>a;   //各数字の配列
    int buff = 0;
    int cheak = 0;  //2で割り切れたか
    int shift = -1;   //シフトの回数

    //数字入力
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> buff;
        a.push_back(buff);
    }

    //shift確認
    do {
        for (int j = 0; j < n; ++j) {
            if (a[j] % 2 != 0) {
                cheak = 1;
                break;
            } else{
                a[j] = a[j] /2;
            }
        }
        shift += 1;
    }while (cheak == 0);
    cout << shift;
    return 0;
}

Measured memory_bytes: 256