akhauriyash/Code-Regression huggingface dataset:
use std::collections::HashMap;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
  }

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
  }

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    // 3
    // 1 2
    // 1 3
    // 1 4
    // のようなタイプ
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
  }

fn solve() {
    input! {
        n: usize,
        m: usize,
        history: [(usize, String);m]
    }

    let mut penalty = 0;
    let mut correct = 0;

    let mut correct_array = vec![0; n + 1];
    let mut penalty_array = vec![0; n + 1];

    for i in 0..m {
        if history[i].1 == "AC" {
            if correct_array[history[i].0] == 0 {
                // WAからACに
                correct_array[history[i].0] = 1;
                correct += 1;
                penalty += penalty_array[history[i].0];
                //println!("{} {:?}", history[i].0, penalty_array[history[i].0]);
            }
        } else {
            if correct_array[history[i].0] == 0 {
                // WA
                penalty_array[history[i].0] += 1;
            }
        }
        //println!("{:?}", penalty_array);
    }
    //println!("{:?}", correct_array);

    println!("{} {}", correct, penalty);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 12668
import sys
input = sys.stdin.readline

N, H = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]

tmp = 0
for a, b in AB:
    tmp = max(tmp, a)

AB.sort(key = lambda x: x[1], reverse = True)

count = 0
for a, b, in AB:
    if b > tmp:
        H -= b
        count += 1
        if H <= 0:
            print (count)
            exit()
    else:
        break

count += (H + tmp - 1) // tmp
print (count)
        

Measured memory_bytes: 18040
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        Map<Integer, Integer> map = IntStream.range(0, n)
                .map(i -> scanner.nextInt())
                .boxed()
                .collect(Collectors.groupingBy(i -> i, Collectors.reducing(0, e -> 1, Integer::sum)));
        System.out.println(map.entrySet().stream()
                .mapToInt(entry -> entry.getValue() + map.getOrDefault(entry.getKey() - 1, 0) + map.getOrDefault(entry.getKey() + 1, 0))
                .max()
                .getAsInt());
    }
}

Measured memory_bytes: 65396
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())

ans = ["" for _ in range(K)]
for i in range(N):
    ans[i%K] += T[i]

score = ""

for a in ans:
    for i in range(len(a)):
        if i == 0:
            score += a[i]
            continue
        else:
            if a[i] == score[-1]:
                score += "?"
            else:
                score += a[i]
    score += "?"
final = 0

for i in range(len(score)):
    if score[i] == "r":
        final += P
    if score[i] == "p":
        final += S
    if score[i] == "s":
        final += R

print(final)


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    int a,b;
    cin >> a >> b;
    cout << (a+b)%24 << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<string> board;
    for(int i=0;i<n;++i){
        string s;
        cin >> s;
        board.push_back(s);
    }

    int ans = 0;
    for(int a=0;a<n;++a){
        bool ok = true;
        for(int i=0;i<n;++i){
            for(int j=0;j<n;++j){
                if(i == j)continue;
                if(board[(i+a)%n][j] != board[(j+a)%n][i]){
                    ok = false;
                    i = j = n;
                }
            }
        }
        if(ok)ans += n;
    }

    cout << ans << endl;

    return 0;
}


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

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 1000000007
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define maxn 200005

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());



int n,m,k;
int mat[20][2005];
int reg[20];
int sum[20];
int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m >> k;
    ff(i,0,n-1){
        string x;
        cin >> x;
        ff(j,0,m - 1)mat[i][j] = x[j] - '0';
    }
    int res = 1e9;
    ff(i,0,(1<<n) - 1){
        int tmpres = 0;
        int br = 0;
        ff(st,0,n-1){
            reg[st] = br;
            if((1<<st) & i){
                br++;
                tmpres++;
            }
        }
        bool first = 1;
        bool nmz = 0;
        ff(j,0,n - 1)sum[j] = 0;
        ff(j,0,m - 1){
            ff(r,0,n - 1){
                sum[reg[r]] += mat[r][j];
            }
            bool bad = 0;
            ff(r,0,br){
                if(sum[r] > k)bad = 1;
            }
            if(bad && first){
                //cout << j << endl;
                //return 0;
                nmz = 1;
                break;
            }
            if(bad){
                first = 1;
                tmpres++;
                ff(r,0,n-1)sum[r] = 0;
                j--;
            }
            else first = 0;
        }
        //cout << nmz << " " << tmpres << endl;
        //return 0;
        if(!nmz)res = min(res, tmpres);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int N;
  cin>>N;
  vector<string> S(N);
  rep(i,N) cin>>S[i];
  rep(i,N) sort(all(S[i]));
  sort(all(S));
  ll cnt=0,ans=0;
  rep(i,N){
    if(i){
      if(S[i]==S[i-1]) cnt++;
      else cnt=0;
      ans+=cnt;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 7296
#include <iostream>
#include <climits>

int main(int argc, char *argv[])
{
  int n;
  std::cin >> n;
  int r[n];
  for (int t = 0; t <= n - 1; t++)
  {
    std::cin >> r[t];
  }
  int max;
  int min;
  max = INT_MIN;
  min = r[0];
  for (int j = 1; j <= n - 1; j++)
  {
    max = std::max(max, r[j] - min);
    min = std::min(min, r[j]);
  }
  std::cout << max << std::endl;

  return 0;
}


Measured memory_bytes: 3896
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdio.h>
#include<string.h>
using namespace std;

long long n;
int main()
{
    scanf("%lld",&n);
    long long temp=sqrt(n)+1;
    for(int i=temp; i>=1; i--)
    {
        if(n%i==0)
        {
            printf("%lld",n/i+i-2);
            //cout<<n/i+i-2;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
N,T = (int(i) for i in input().split())
result = list()
for ii in range(N):
    c,t = (int(i) for i in input().split())
    if t <= T:
        result.append(c)
    else:
        continue
if result:
    result.sort()
    print(result[0])
else:
    print("TLE")

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

struct P {
  int x, y;
  P(int x, int y) : x(x), y(y) {}
};

int n;
double x[9],y[9];
//using P=pair<int,int>;
vector<P> p;
P vec0(1,0);
double minx=1<<30;

double norm(P v) { // 長さを返す
  return sqrt(v.x * v.x + v.y * v.y);
}

double calc_deg(P cur, P nxt, P v) {
  auto u = P{nxt.x - cur.x, nxt.y - cur.y};
  auto ip = v.x * u.x + v.y * u.y; // 内積
  return acos(ip / norm(v) / norm(u)) / 2 / acos(-1) * 360;
}

int main(){
    vector<int> a;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>x[i]>>y[i];
        p.push_back(P(x[i],y[i]));
        a.push_back(i);
    }
    do{
        P posv={1,0};
        P posp={0,0};
        double temp=0;
        for (int i=0; i<n; i++){
            temp+=calc_deg(posp,p[a[i]],posv);
            posv.x=p[a[i]].x-posp.x; posv.y=p[a[i]].y-posp.y;
            posp=p[a[i]];
        }
        P vec1={0,0};
        temp+=calc_deg(posp,vec1,posv);
        minx=(minx<temp)?minx:temp;
    }while(next_permutation(a.begin(), a.end()));
    printf("%.8lf\n",minx);
    return 0;
}


Measured memory_bytes: 3412
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main(){
	int min = 999;
	string s;
	cin >> s;
	for (int i = 0; i < s.size() - 2; i++){
		if (abs(753 - ((s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + s[i + 2] - '0')) < min)
			min = abs(753 - ((s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + s[i + 2] - '0'));
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int c,n,m,s,d;

int main(){
    while(true){
	scanf("%d%d%d%d%d",&c,&n,&m,&s,&d);
	if(c==0||n==0||m==0||s==0||d==0) break;
	int rosen[101][101] = {10000000};
	int dp[11][101];
	REP(i,101)REP(j,101) rosen[i][j] = 10000000;
	REP(i,11)REP(j,101) dp[i][j] = 10000000;
	REP(i,m){
	    int a,b,f;
	    cin >> a >> b >> f;
	    rosen[a][b] = f;
	    rosen[b][a] = f;
	}
	int ans = 10000000;
	vector<bool>  used(n+1,false);
	queue<int> q;
	queue<int> th;
	dp[c][s] = 0;
	q.push(s);
	th.push(c);
	while(!q.empty()){
	    int p = q.front();
	    int t = th.front();
	    q.pop();
	    th.pop();
	    FOR(i,1,n+1){
		if(dp[t][i] > dp[t][p] + rosen[p][i]){
		    dp[t][i] = dp[t][p] + rosen[p][i];
		    q.push(i);
		    th.push(t);
		}
		if(t>0&&dp[t-1][i] > dp[t][p] + rosen[p][i]/2){
		    dp[t-1][i] = dp[t][p] + rosen[p][i]/2;
		    q.push(i);
		    th.push(t-1);
		}
	    }
	}
	REP(i,c+1){
	    if(dp[i][d] > 0)
		ans = min(ans,dp[i][d]);
	}
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1340
#include <cmath>
#include <string>
#include <iostream>

int main() {
    int N, K;

    std::cin >> N >> K;

    int power = 1;
    while (true) {
        if (N < std::pow(K, power)) {
            break;
        }
        ++power;
    }

    std::cout << power << std::endl;

    return 0;
}

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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;

#define MAX_N 1000000

signed main() {
	ll h, w; cin >> h >> w;
	vector<vector<ll>> v(h, vector<ll>(w));
	ll su = 0;
	rep(i, h)rep(j, w) {
		cin >> v[i][j];
		su += v[i][j];
	}
	rep(i, h) {
		ll wsu = 0;
		rep(j, w) {
			cout << v[i][j] << " ";
			wsu += v[i][j];
		}
		cout << wsu << endl;
	}
	rep(j, w) {
		ll hsu=0;
		rep(i, h) {
			hsu += v[i][j];
		}
		cout << hsu << " ";
	}
	cout << su << endl;
}


Measured memory_bytes: 3248
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    ll N;

    cin >> N;

    ll A[N];
    ll a;

    for(ll i = 0; i < N; i++){
        A[i] = 0;
    }
    for(ll i = 0; i < N - 1; i++){
        cin >> a;
        A[a - 1]++;
    }

    for(ll i = 0; i < N; i++){
        cout << A[i] << endl;
    }

    return 0;
}


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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    string S; 
    cin>>S;
    int point = 0;
    REP(i, 0, S.size()){
        if(S[i] == '?') S[i] = 'D';
    }
    cout << S << endl;
}

Measured memory_bytes: 3752
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    S = input()
    l = len(S)

    while True:
        l -= 2
        first = S[:l // 2]
        second = S[l // 2: l]
        if first == second:
            return print(l)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61376
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;
#define ll long long
#define FOR(i, n, m) for(int i=n; i<m; ++i)

int main(){
  ll A, B;
  cin >> A >> B;
  
  if((A*B)%2==0) cout << "No" << endl;
  else cout << "Yes" << endl;

      
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    double ans = 0.0;
    int N, K; cin >> N >> K;
    for(int i = 1; i <= N; i++){
        int ci = 0;
        int val = i;
        while(val < K){
            ci++;
            val*=2;
        }
        //cout << ci << endl;
        ans += 1.0/(1 << ci);
    }
    ans /= N;
    printf("%.10f\n", ans);
    return 0;
}

Measured memory_bytes: 256
use std::fmt::Write;
use std::io::*;

fn bubble_sort<T: PartialOrd>(slice: &mut [T]) -> usize {
	let mut change = 0;
	let mut flag = true;

	while flag {
		flag = false;

		for j in (1..slice.len()).rev() {
			if slice[j] < slice[j - 1] {
				slice.swap(j, j - 1);
				flag = true;
				change += 1;
			}
		}
	}

	change
}

fn main() {
	let input = {
		let mut buf = vec![];
		stdin().read_to_end(&mut buf);
		unsafe { String::from_utf8_unchecked(buf) }
	};
	let mut lines = input.split('\n');

	let n = lines.next().unwrap().parse().unwrap();

	let mut vec = Vec::with_capacity(n);
	let iter = lines.next().unwrap().split(' ').map(|s| s.parse::<u32>().unwrap());
	vec.extend(iter);

	let cnt = bubble_sort(&mut vec);

	let mut res = format!("{}", vec[0]);
	for v in &vec[1..] {
		write!(res, " {}", v);
	}
	println!("{}", res);
	println!("{}", cnt);
}



Measured memory_bytes: 5032
def ascan; gets.split.map(&:to_i); end


# B[L-1]P[L-1]B

@memo = {}
@memomax = {}
# return: [total, numP]
def solve(n, x)
    if @memo.size > 1000
        @memo.each{|e| p e}
        exit
    end
    return [0, 0] if x <= 0
    return [1, 1] if n == 0
    return [1, 0] if x == 1
    
    key = [n,x]
    return @memo[key] if @memo[key]
    return @memo[[n, @memomax[n]]] if @memomax[n] && @memomax[n] <= x
    
    
    total1, np1 = solve(n-1, x-1)
    return @memo[key] = [total1+1, np1] if total1 >= x-1
    total2, np2 = solve(n-1, x-1-total1-1)
    return @memo[key] = [total2+1+total1+1, np2+1+np1] if total2 >= x-1-total1-1
    
    t = 1+total2+1+total1+1
    @memomax[n] = t
    return @memo[[n, t]] = [t, np2+1+np1]
end


p solve(*ascan)[1]

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const long long mod = 1000000007;
// auto mod int
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

// combination mod prime
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main(){
    int x, y;
    cin >> x >> y;
    if (2*y-x>=0 && (2*y-x)%3==0) {
        combination cb(x);
        ll c = (2*y-x)/3;
        mint ans = cb((x+c)/2, c);
        cout << ans << endl;
    }
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 18840
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    string a, b; cin >> a >> b;
    a += b;

    int A = atoi(a.c_str());

    bool ans = false;
    for (int i = 0; i*i <= A; i++) {
        if (i*i == A) {
            ans = true;
        }
    }

    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


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

int main() {
  int N, A;
  cin >> N;
  vector<int>  B(N,0);
  rep(i, N-1){
    cin >> A;
    B.at(A-1)++;
  }
  rep(i, N) cout << B.at(i) << endl;
}

Measured memory_bytes: 4008
#include<bits/stdc++.h>
#define For(i,a,b) for(i=a;i<b;i++)
#define pb push_back
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<long long>  
#define vd vector<double>
#define pi (int,int)
#define vpi vector<pair<int,int>>
#define vs vector<string>
#define mp make_pair
#define ll long long
#define vc vector<char>
#define rng(x) x.begin(),x.end()
#define B(x) x.begin()
#define E(x) x.end()
#define F first
#define S second
#define me max_element
#define ne min_element
#define pi 3.1415926536
using namespace std;
int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  
  int c=0,max=0,i;
  string s;
  cin>>s;
  For(i,0,3)
  {
    if(s[i]=='R') 
    {
      c++;
      continue;
    }
    else
    {
      if(c>max) max=c;
      c=0;
    }
  }
  if(c>max) max=c;
  cout<<max;
  return 0;
}


        

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    string S, T, U;
    int A, B;
    cin >> S >> T >> A >> B >> 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;

long long n;
vector<long long> a;

long long solve();
long long myabs(long long x) { return max(x, -x); }

int main() {
  cin >> n;
  a.resize(n);
  for(int i = 0; i < n; ++i) {
    cin >> a[i];
    a[i] -= i + 1;
  }
  sort(a.begin(), a.end());
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0, now = 0;
  for(int i = 0; i < n; ++i) {
    ans += myabs(a[i] - a[n / 2]);
    // if(n / 2 - 1 >= 0) now += myabs(a[i] - a[n / 2 - 1]);
  }
  // if(n / 2 - 1 < 0) return ans;
  return ans; // min(ans, now);
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    string S; cin >> S;
    int L = 0, R = 0;
    string s1, s2;
    rep(i, N) {
        if (S[i] == '(') L++;
        else R++;
        if (L - R < 0) {
            s1 += '(';
            L++;
        }
        //cout << L << " " << R << endl;
    }
    rep(i, L - R ) s2 += ')';
    cout << s1 << S <<s2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;

int main() {
    int n;
    cin>>n;
    int a,b;
    cin>>a>>b;
   
    long long ans= 0;
    long long curr = 0;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        if(i>1){
            int dist = abs(curr-x);
            if(1LL*dist*a>b){
                ans+=b;
            }else{
                ans+=1LL*dist*a;
            }
        }
        curr = x;
    }
    cout<<ans<<endl;
}

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

#define N 55

int n, a[N], val[N], b[N];

int pos[2][N], cnt[N], c[N], L[N], R[N];
int nxt[N];

int main() {
	scanf("%d", &n);
	int MAX = (1<<n);
	for (int i = 0; i < n; i ++) scanf("%d", &a[i]);
	for (int i = 0; i < n; i ++) scanf("%d", &b[i]);
	int ans = 1e9;
	for (int sta = 0; sta < MAX; sta ++) {
		int CNT = __builtin_popcount(sta);
		if (CNT&1) continue;
		memset(cnt, 0, sizeof cnt);
		for (int i = 0; i < n; i ++) {
			if (sta&(1<<i)) val[i] = b[i], c[i] = 1;
			else val[i] = a[i], c[i] = 0;
			cnt[val[i]] ++;
		}
		for (int i = 2; i <= 50; i ++) cnt[i] += cnt[i-1];
		for (int i = 1; i <= 50; i ++) {
			L[i] = cnt[i-1], R[i] = cnt[i]-1;
			pos[1][i] = L[i]&1 ? L[i] : L[i]+1;
			pos[0][i] = L[i]&1 ? L[i]+1 : L[i];
		}
		bool flag = 0;
		for (int i = 0; i < n; i ++) {
			int cur = val[i];
			if (pos[i+c[i]&1][cur] <= R[cur]) {
				nxt[i] = pos[i+c[i]&1][cur];
				pos[i+c[i]&1][cur] += 2;
			}
			else {
				flag = 1;
				break;
			}
		}
		if (flag) continue;
		int rlt = 0;
		for (int i = 0; i < n; i ++) {
			int pos = -1;
			for (int j = i; j < n; j ++) if (nxt[j] == i) {
				pos = j;
				break;
			}
			rlt += pos - i;
			for (int j = pos; j > i; j --) nxt[j] = nxt[j-1];
		}
		ans = min(ans, rlt);
	}
	cout << (ans == (int)1e9 ? -1 : ans) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(){
	long long l,r;
	cin >> l >> r;
	if(r - l>2019){
		cout << 0 << endl;
		return 0;
	}
	long long i,j,ans = 2019;
	for(i=l;i<=r;i++){
		for(j=i + 1;j<=r;j++){
			long long x = i%2019,y = j%2019;
			ans = min(ans,x*y%2019);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s); sys.stdout.write('\n')
def wi(n): sys.stdout.write(str(n)); sys.stdout.write('\n')
def wia(a, sep=' '): sys.stdout.write(sep.join([str(x) for x in a])); sys.stdout.write('\n')


import heapq

def solve(n, a):
    a = sorted(a, reverse=True)
    ans = 0

    h = [-a[0]]
    heapq.heapify(h)

    for i in range(1, n):
        p = heapq.heappop(h)
        ans += -p
        heapq.heappush(h, -a[i])
        heapq.heappush(h, -a[i])

    return ans


def main():
    n = ri()
    a = ria()
    wi(solve(n, a))


if __name__ == '__main__':
    main()


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

using namespace std;
#define ll long long
const int N = 1e5 + 5, mod = 1e9 + 7;
int dp[101][N];
int a[101], n;
int prefix_sum[N];

int k;

void build(int indx) {
    prefix_sum[0] = dp[indx][0];
    for (int i = 1; i <= k; i++)prefix_sum[i] = (prefix_sum[i - 1] + dp[indx][i]) % mod;
}

int get(int L, int R) {
    if (L == 0) return prefix_sum[R];
    return (prefix_sum[R] - prefix_sum[L - 1] + mod) % mod;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    dp[n][0] = 1;
    build(n);
    for (int indx = n - 1; indx >= 0; indx--) {
        for (int candies = k; candies >= 0; candies--) {
            int &res = dp[indx][candies];
            int R = candies, L = max(0, candies - a[indx]);
            res = get(L, R);
        }
        build(indx);
    }

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


Measured memory_bytes: 39680
#include <bits/stdc++.h>
using namespace std;
 int main() {
int a,b,c;cin>>a>>b>>c;
string s="NO";
   for(int i=1;i<=b;i++)
   {
     if((a*i-c)%b==0)
     {
       s="YES";
       break;
     }
   }
   cout<<s;
 }
       
    



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

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(string, s);
    CIN(int, K);

    set<string> S;

    for (int i = 0; i < s.size(); i++) {
        string temp = "";
        for (int j = 0; j < K && i+j < s.size(); j++) {
            temp += s[i+j];
            S.insert(temp);
        }
    }

    auto i = S.begin();
    advance(i, K - 1);
    cout << *i << "\n";

    return 0;
}

Measured memory_bytes: 1664
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd_int(void){
  int x;
  rd(x);
  return x;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
int len;
char res[100];
int main(){
  int Lj4PdHRW;
  int KL2GvlyY = rd_int();
  for(Lj4PdHRW=(0);Lj4PdHRW<(KL2GvlyY);Lj4PdHRW++){
    res[len++] = 'A';
    res[len++] = 'C';
    res[len++] = 'L';
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200926-1

// --- original code ---
// int len;
// char res[100];
// {
//   REP(rd_int()){
//     res[len++] = 'A';
//     res[len++] = 'C';
//     res[len++] = 'L';
//   }
//   wt(res);
// }


Measured memory_bytes: 3640
#include "iostream"
#include "vector"
#include "array"
#include "string"
#include "algorithm"
#include "queue"

using namespace std;

#define REP(i,j) for(int i = 0;i < j; i++)
const int INF = 1 << 30;

//A
int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	int ans = b;
	if (a + b >= c) ans += c;
	else ans += a + b + 1;
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys



def main():
    
    while True:
        n,m = map(int, sys.stdin.readline().split())
        if n == 0 and m == 0:
            break

        # input
        hs = []
        for i in range(n):
            h = int(sys.stdin.readline())
            hs.append(h)

        ws = []
        for i in range(m):
            w = int(sys.stdin.readline())
            ws.append(w)

        # bucket
        bhs = [0] * 1500010
        for i in range(n):
            sz = 0
            for j in range(i, n):
                sz += hs[j]
                bhs[sz] += 1
        
        ans = 0
        for i in range(m):
            sz = 0
            for j in range(i, m):
                sz += ws[j]
                ans += bhs[sz]

        print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 42816
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    uint64_t H;
    intmax_t ans = 0;

    scanf("%" SCNu64, &H);

    for (size_t i = 1; i < 64; i++) {
        if ((H & ~((UINT64_C(1) << i) - 1)) == 0) {
            for (size_t j = 0; j < i; j++) {
                ans += UINT64_C(1) << j;
            }
            break;
        }
    }

    printf("%jd\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int ans=700;
	for(int i=0;i<3;i++)
	 {
	 	if(s[i]=='o')
	 	 ans+=100;
	 }
	 cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define MOD 1000000007
#define ll long long
#define ld long double
#define int ll
#define pb push_back
#define ii pair<int,int>
#define llll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<ii>
#define vllll vector<llll>
#define ff first
#define ss second
#define INF 1000000000
#define HINF 1000000000000000
#define mem(a,b) memset(a,b,sizeof(a))
#define arrin(x,n) int x[n]; for(int o=0;o<n;o++) cin>>x[o]
#define arrout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<'='<<x<<endl
#define deb2(x,y) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<endl
#define deb3(x,y,z) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<" "<<#z<<'='<<z<<endl
#define debarr(arr,n) for(int o=0;o<n;o++) deb2(o,arr[o])
#define IO freopen("input.txt", "r", stdin); freopen("output.txt", "w+", stdout)
const double pi = 3.14159265358979323846;

ll power(ll a, ll b){//a^b
    ll res=1;
    //a=a%MOD;
    while(b>0){
        if(b&1)
		{res=(res*a);
		//res%=MOD;
		b--;}
        a=(a*a);
        //a%=MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int C(int n,int k)
{
	int ans=1;
	if(k>n-k)
	k=n-k;
	for(int i=1;i<=k;i++)
	ans*=(n-i+1),ans/=i;
	return ans;
}

void solve()
{

	int i=0,j=0,k=0,m,n,p,sum=0,cnt=0;
	cin>>n;
	arrin(arr,n);
	
	for(int x: arr)
	{
	    (sum+=cnt*x)%=MOD;
	    (cnt+=x)%=MOD;
	}
	
	cout<<(sum)%MOD;
	
	
	
	
	 
}
int32_t main() {
    fast
    //IO;
	//cout<<fixed<<setprecision(6);
    //test
    {
        
        solve();
		
		      
    }
    return 0;
}
  

Measured memory_bytes: 5216
N = int(input())
A = [(int(i)) for i in input().split()]
cnt = 0
for i in range(len(A)):
  if A[i] < 0:
    cnt += 1
    A[i] *= -1
A = sorted(A)
if cnt%2==0:
  print(sum(A))
else:
  print(sum(A)-2*A[0])

Measured memory_bytes: 14284
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
using namespace std;

#define N  100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        string s,t;
        cin>>s>>t;
        ll ans=0;
        for(int i=0;i<3;i++)
        {
        	if(s[i]==t[i])
        		ans++;
        }
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int A, B, ans;
int age;

int main()
{
	scanf("%d", &age);
	if(age == 1) printf("Hello World");
	if(age == 2) 
	{
		scanf("%d %d", &A, &B);
		ans = A + B;
		printf("%d", ans);
	}
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef complex<ld> PT;
typedef pair<PT, PT> LS;
#define F first
#define S second
#define X real()
#define Y imag()

inline int in(){int x, y; y = scanf("%d", &x); return x; }

const int N = -1;
const ld EPS = 1e-12;

const int LEFT = 0, RIGHT = 1, BACK = 2, FRONT = 3, ON = 4;

inline bool Geq(ld a, ld b){ return a + EPS > b; }
inline bool Grt(ld a, ld b){ return a > b + EPS; }
inline bool Leq(ld a, ld b){ return a < b + EPS; }
inline bool Lss(ld a, ld b){ return a + EPS < b; }
inline bool Equ(ld a, ld b){ return Geq(a, b) && Geq(b, a); }

istream& operator>> (istream& is, complex<ld>& p){
	ld val;
	is >> val;
	p.real(val);
	is >> val;
	p.imag(val);
	return is;
}

ld dot(PT a, PT b){ return real(conj(a)*b); }
ld cross(PT a, PT b){ return imag(conj(a)*b); }
ld sqlen(PT a){ return dot(a, a); }
ld len(PT a){ return sqrt(sqlen(a)); }

PT proj(PT a, PT b, PT c){
	b -= a, c -= a;
	return a + b*real(c/b);
}

PT reflect(PT a, PT b, PT c){
	b -= a, c -= a;
	return a + conj(c/b)*b;
}

PT rotate(PT a, PT b, ld theta){
	return (b-a)*polar<ld>(1, theta) + a;
}

int relpos(PT a, PT b, PT c){
	b -= a, c -= a;
	c /= b;
	if (Grt(c.imag(), 0)) return RIGHT;
	if (Lss(c.imag(), 0)) return LEFT;
	if (Lss(c.real(), 0)) return BACK;
	if (Grt(c.real(), 1)) return FRONT;
	return ON;
}

int side(PT a, PT b, PT c){
	b -= a, c -= a;
	ld cr = (c/b).Y;
	return Grt(cr, 0) ? 1 : (Lss(cr, 0) ? -1 : 0);
}

//If LineSegments Intersect
bool intersect(PT a, PT b, PT c, PT d){
	int as = side(c, d, a), bs = side(c, d, b), cs = side(a, b, c), ds = side(a, b, d);
	if (as && as == bs || cs && cs == ds) return false;
	else if (as || bs || cs || ds) return true;
	for (int j = 0; j < 2; j++, swap(a, c), swap(b, d)){
		ld mx = min(a.X, b.X), Mx = max(a.X, b.X), my = min(a.Y, b.Y), My = max(a.Y, b.Y);
		for (int k = 0; k < 2; k++, swap(c, d))
			if (Geq(c.X, mx) && Leq(c.X, Mx) && Geq(c.Y, my) && Leq(c.Y, My))
				return true;
	}
	return false;
}

//LineSegments Intersection (intersect is true)
PT intersection(PT a, PT b, PT c, PT d){
	ld c1 = cross(b-a, c-a), c2 = cross(b-a, d-a);
	return (c1*d - c2*c)/(c1-c2);
}

ld distLSP(PT a, PT b, PT c){
	int pos = relpos(a, b, proj(a, b, c));
	if (pos == BACK) return len(c-a);
	if (pos == FRONT) return len(c-b);
	b -= a, c -= a;
	return abs(imag(c/b))*len(b);
}

ld distLS(PT a, PT b, PT c, PT d){
	if (intersect(a, b, c, d)) return 0;
	return min(min(distLSP(a, b, c), distLSP(a, b, d)), min(distLSP(c, d, a), distLSP(c, d, b)));
}

int main(){	
	cout << setprecision(10) << fixed;
	for (int i = in(); i; i--){
		PT a, b, c, d;
		cin >> a >> b >> c >> d;
		cout << distLS(a, b, c, d) << '\n';;
	}
	return 0;
}


Measured memory_bytes: 3332
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int n,p;
  string s;
  cin>>n>>p>>s;

  ll ans=0;

  if(p==2){
    rep(i,n){
      if((s[i]-'0')%2==0) ans+=i+1;
    }
    cout << ans << endl;
    return 0;
  }
  if(p==5){
    rep(i,n){
      if((s[i]-'0')%5==0) ans+=i+1;
    }
    cout << ans << endl;
    return 0;
  }

  vector<ll> q(p);
  q[0]=1;
  ll now=0;
  ll ju=1;
  for(int i=n-1;i>=0;i--){
    now+=((s[i]-'0')*ju);
    now%=p;
    q[now]++;
    ju=(ju*10)%p;
  }

  rep(i,p){
    ans+=q[i]*(q[i]-1)/2;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int k, n;
    cin >> k >> n;
    vi a(n);
    for (int& i : a)
        cin >> i;
    int res = LLONG_MIN;
    for (int i = 0; i < n - 1; i++)
        res = max(res, abs(a[i + 1] - a[i]));
    res = max(res, k + a[0] - a[n - 1]);
    cout << k - res << endl;
    GAME_OVER;
}

Measured memory_bytes: 1792
use proconio::*;
use proconio::marker::Usize1;
use std::collections::BinaryHeap;

fn my_pop(heap: &mut BinaryHeap<(usize, usize, usize)>, charge: &mut [usize]) -> Option<(usize, usize, usize)> {
    while let Some(x) = heap.pop() {
        if charge[x.2] > 0 {
            heap.push((x.0 - charge[x.2], x.1, x.2));
            charge[x.2] = 0;
        }
        else {
            return Some(x);
        }
    }

    None
}

fn solve() -> Option<Vec<usize>> {
    input!{
        n: usize,
        a: [Usize1; n],
        b: [Usize1; n],
    }

    let mut cnt_a = vec![0usize; n];
    let mut cnt_b = vec![0usize; n];

    for i in 0..n {
        cnt_a[a[i]] += 1;
        cnt_b[b[i]] += 1;
    }

    let mut heap = BinaryHeap::new();
    for i in 0..n {
        if cnt_b[i] == 0 {
            continue;
        }
        heap.push((cnt_a[i], cnt_b[i], i));
    }

    let mut charge = vec![0; n];
    let mut ans = Vec::new();
    for i in 0..n {
        let tmp = my_pop(&mut heap, &mut charge);
        if tmp.is_none() {
            return None;
        }
        let tmp = tmp.unwrap();
        if a[i] == tmp.2 {
            let tmp2 = my_pop(&mut heap, &mut charge);
            if tmp2.is_none() {
                return None;
            }
            let tmp2 = tmp2.unwrap();
            ans.push(tmp2.2);
            if tmp2.1 != 1 {
                heap.push((tmp2.0, tmp2.1-1, tmp2.2));
            }
            heap.push(tmp);
        }
        else {
            ans.push(tmp.2);
            if tmp.1 != 1 {
                heap.push((tmp.0, tmp.1-1, tmp.2));
            }
        }
        charge[a[i]] += 1;
    }

    Some(ans)

    
}

fn main() {
    if let Some(ans) = solve() {
        println!("Yes");
        for i in 0..ans.len() {
            if i > 0 {
                print!(" ");
            }
            print!("{}", ans[i]+1);
        }
        println!("");
    }
    else {
        println!("No");
    }
}


Measured memory_bytes: 18736
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define REP(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define sort(vec) sort(vec.begin(),vec.end())
#define reverse(vec) reverse(vec.begin(),vec.end())
string s;
int b=0,ans=0;
signed main(){
    cin>>s;
    int l=s.size();
    rep(i,l){
        if(s[i]=='B')b++;
        else ans+=b;
    }
    cout<<ans<<endl;
    return 0;
}

    

Measured memory_bytes: 640
n = gets.chomp.to_i
h = {}
n.times do 
  a = gets.chomp.split(" ")
  if a[0] == "insert"
    h[a[1]] = 1
  end
  if a[0] == "find"
    if h[a[1]] == 1
      puts "yes"
    else
      puts "no"
    end
  end
end

Measured memory_bytes: 48748
# -*- coding: utf-8 -*-

abcd = list(input())
a = abcd[0]
b = abcd[1]
c = abcd[2]
d = abcd[3]

#bit全探索
n = 3
arr = [0] * n
for i in range(2 ** n):
    for j in range(n):
        if((1&i>>j) == 1):
            arr[j] = 1
        else:
            arr[j] = 0
    #ここに処理
    ia,ib,ic,id = int(a),int(b),int(c),int(d)
    if arr[0] == 0 and arr[1] == 0 and arr[2] == 0:
        if ia + ib + ic + id == 7:
            print(a + "+" + b + "+" + c + "+" + d + "=7")
            break
    if arr[0] == 1 and arr[1] == 0 and arr[2] == 0:
        if ia - ib + ic + id == 7:
            print(a + "-" + b + "+" + c + "+" + d + "=7")
            break
    if arr[0] == 0 and arr[1] == 1 and arr[2] == 0:
        if ia + ib - ic + id == 7:
            print(a + "+" + b + "-" + c + "+" + d + "=7")
            break
    if arr[0] == 1 and arr[1] == 1 and arr[2] == 0:
        if ia - ib - ic + id == 7:
            print(a + "-" + b + "-" + c + "+" + d + "=7")
            break
    if arr[0] == 0 and arr[1] == 0 and arr[2] == 1:
        if ia + ib + ic - id == 7:
            print(a + "+" + b + "+" + c + "-" + d + "=7")
            break
    if arr[0] == 1 and arr[1] == 0 and arr[2] == 1:
        if ia - ib + ic - id == 7:
            print(a + "-" + b + "+" + c + "-" + d + "=7")
            break
    if arr[0] == 0 and arr[1] == 1 and arr[2] == 1:
        if ia + ib - ic - id == 7:
            print(a + "+" + b + "-" + c + "-" + d + "=7")
            break
    if arr[0] == 1 and arr[1] == 1 and arr[2] == 1:
        if ia - ib - ic - id == 7:
            print(a + "-" + b + "-" + c + "-" + d + "=7")
            break

Measured memory_bytes: 3192
/// Kazuki Hoshino
/// Lost July

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 998244353
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple

ll n, b, a, k, ans, fac[303030];

ll modpow(ll x, ll y){
if(y==0)return 1%mod;
ll u = modpow(x, y/2);
u = u*u%mod;
if(y%2)u = u*x%mod;
return u;
}

ll nc(ll x){
ll temp = modpow(fac[x], mod-2);
temp = temp*fac[n]%mod;
ll t = modpow(fac[n-x], mod-2);
temp = temp*t%mod;
return temp%mod;
}


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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

cin >> n >> a >> b >> k;
fac[0]=1;
rep(i, 1, 300030){
    fac[i]=fac[i-1]*i%mod;
}

rep(i,0, n){

    ll temp = k - i*a;
    if(temp%b==0 && temp/b <=n && temp>=0 ){
        temp = nc(i);
        temp = temp*nc( (k- (i*a))/b)%mod;
        ans = (ans+temp)%mod;
        //cout << ans << endl;
    }

}
cout << ans%mod << endl;

return 0;}


Measured memory_bytes: 2560