akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

int main()
{
    lint N, M;
    string S, T;
    cin >> N >> M >> S >> T;
    lint cand = N * M / __gcd(N, M);

    lint gcd = __gcd(N, M);
    REP(i, gcd)
    {
        if (S[N / gcd * i] != T[M / gcd * i])
        {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << cand << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

string s;

int main() {
	cin >> s;
	rep(i, 3) {
		if (s[i] == '1')s[i] = '9';
		else s[i] = '1';
	}
	cout << s << endl;
	getchar();
	getchar();
	return 0;
}

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

using namespace std;

#define int long long
#define PB push_back
#define INF (1LL<<61LL)

typedef pair<int, int> pii;

int N, L, a[100005], dx[] = {-1, 1};
bool flg[100005];

int cal(int x) {
  int res = L - a[x], temp = 0;
  for (int i = 0; i < 2; ++i) {
    if (a[x] < a[x + dx[i]]) continue;
    temp = max(temp, cal(x + dx[i]));
  }

  return res + temp;
}

signed main() {
  fill(a, a + 100005, INF);
  cin >> N >> L;
  for (int i = 1; i <= N; ++i)
    cin >> a[i];

  int maxt = 0;
  for (int i = 1; i <= N; ++i) {
    int count = 0;
    for (int j = 0; j < 2; ++j) {
      if (a[i + dx[j]] < a[i]) {
	count++;
      }
    }

    if ((count == 2) || (((i == 1) || (i == N)) && (count == 1)))
      maxt = max(maxt, cal(i));
  }

  cout << maxt << endl;
  
  return 0;
}

Measured memory_bytes: 4284
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		if (s.charAt(0) != 'A'){
			System.out.println("WA");
			return;
		}
		int cCnt = 0;
		int cIndex = 0;
		for (int i = 2; i < s.length() -1; i++){
			char c = s.charAt(i);
			if (c == 'C'){
				cCnt++;
				cIndex = i;
			}
		}
		if (cCnt != 1){
			System.out.println("WA");
			return;
		}
		for (int i = 1; i < s.length(); i++){
			if (i != cIndex){
				if (!Character.isLowerCase(s.charAt(i))){
					System.out.println("WA");
					return;
				}
			}
		}
		System.out.println("AC");
	}
}

Measured memory_bytes: 23764
while 1:
    n, p = map(int, input().split())
    if n == 0:
        break

    wan = p
    candi = [0] * n
    cnt = 0
    while 1:
        turn = cnt % n
        if wan > 0:
            candi[turn] += 1
            wan -= 1
        else:
            wan += candi[turn]
            candi[turn] = 0

        if candi[turn] == p:
            break
        cnt += 1

    print(turn)



Measured memory_bytes: 5596
package main

import (
	"fmt"
	"bufio"
	"os"
	"strings"
	"strconv"
)
var input = bufio.NewScanner(os.Stdin)

func get() string {
	input.Scan()
	return input.Text()
}
func getStr(v string) string{
	i , _ := strconv.Atoi(v)
	i = i - 1
	s := strconv.Itoa(i)
	return s
}

func main () {
	name := strings.Split(get(), " ")
	count := strings.Split(get(), " ")
	catched := get()
	m := map[string]string{name[0]:count[0], name[1]:count[1] }
	m[catched] = getStr(m[catched])
	fmt.Printf("%s %s\n",m[name[0]],m[name[1]])
}

Measured memory_bytes: 640
fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map{it.toInt()}
    val a = readLine()!!.split(" ").map{it.toLong()}

    val b = a.map {
        var k = it
        var cnt = 0
        while(k % 2 == 0L) {
            cnt++
            k /= 2L
        }

        cnt
    }.sorted()

    if (b.first() != b.last()) {
        println(0)
        return
    }

    var l = 1L

    for (i in a.indices) {
        l = lcm(l, a[i])

        if (l > 2 * M) {
            println(0)
            return
        }
    }

    val m = l / 2

    println(1 + (M - m) / l)
}

tailrec fun gcd(x: Long, y: Long): Long = if (y == 0L) x else gcd(y, x % y)

/**
 * Calculate the least common multiple of `x` and `y`
 */
fun lcm(x: Long, y: Long): Long = x / gcd(x, y) * y


Measured memory_bytes: 56884
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

int n;
int a[100004], b[100004], c[100004];
ll  cb[100004], cc[100004];

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) cin >> b[i];
	for (int i = 0; i < n; ++i) cin >> c[i];
	sort(a, a + n);
	sort(b, b + n);
	sort(c, c + n);
	for (int i = 0; i < n; ++i) {
		cb[i + 1] += lower_bound(a, a + n, b[i]) - a;
		cb[i + 2] = cb[i + 1];
	}
	for (int i = 0; i < n; ++i) {
		cc[i] += cb[lower_bound(b, b + n, c[i]) - b];
		cc[i + 1] = cc[i];
	}
	cout << cc[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 2944
import java.util.Scanner;

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

        int a = scan.nextInt();
        int b = scan.nextInt();

        if(a >= 10 || b >= 10){
            System.out.println("-1");
        }else{
            System.out.println(a * b);
        }
    }
}


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

#define L(X) ((X)*2)
#define R(X) ((X)*2+1)
#define P(X) ((X)/2)

void maxHeapify(int *h, int sz, int i){
  int t,mx = i;
//  cout << "MH: " << i << " ";
  if (L(i)<=sz && h[mx]<h[L(i)]) mx = L(i);
  if (R(i)<=sz && h[mx]<h[R(i)]) mx = R(i);
//  cout << mx << endl;
  if (mx!=i){
    t = h[i]; h[i] = h[mx]; h[mx] = t;
    if (L(mx)<=sz) maxHeapify(h,sz,mx);
  }
}

void update(int *h, int sz){
  for (int i=P(sz); i>=1; i=P(i)) maxHeapify(h,sz,i);
}

int main(void){
  int h[2000010];
  string query;
  int t, sz=0;
  
  while (cin >> query){
    if (query[2]=='d') break; // end
    if (query[0]=='i'){ // insert
      cin >> t;
      h[++sz] = t;
      update(h,sz);
    } else { // extract max
      cout << h[1] << endl;
      h[1] = h[sz--];
      update(h,sz);
    }
  }   
  return 0;
}


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

using namespace std;

int main()
{
    stack<int> st;

    int a;

    cin >> a;
    st.push(a);

    while (cin >> a) {
        if (a) st.push(a);
        else { cout << st.top() << endl; st.pop(); }
    }
}

Measured memory_bytes: 1200
a, b = map(int, input().split())

if a <= 0 <= b:
    print("Zero")
elif 0 < a <= b:
    print("Positive")
elif a < 0 and 0 < b:
    if a % 2 == 0:
        print("Positive")
    else:
        print("Negative")
else:
    if (b - a) % 2 == 0:
        print("Negative")
    else:
        print("Positive")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
//const ll MOD = 1e9+7;
const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

//mod-int構造体
//計算量 加減乗算:O(1)、除算:O(log(MOD))、K乗:O(log(K))

template<ll mod> struct Mod_Int{
    ll x;
    Mod_Int() {}
    Mod_Int(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod){}

    Mod_Int &operator += (const Mod_Int &p) {
        x = (x + p.x) % mod;
        return *this;
    }

    Mod_Int &operator -= (const Mod_Int &p) {
        x = (x + mod - p.x) % mod;
        return *this;
    }

    Mod_Int &operator *= (const Mod_Int &p) {
        x = (x * p.x) % mod;
        return *this;
    }

    Mod_Int &operator /= (const Mod_Int &p) {
        *this *= p.inverse();
        return *this;
    }

    Mod_Int operator -() const {return Mod_Int(-x);}

    Mod_Int operator + (const Mod_Int &p) const {return Mod_Int(*this) += p;}

    Mod_Int operator - (const Mod_Int &p) const {return Mod_Int(*this) -= p;}

    Mod_Int operator * (const Mod_Int &p) const {return Mod_Int(*this) *= p;}

    Mod_Int operator / (const Mod_Int &p) const {return Mod_Int(*this) /= p;}

    bool operator == (const Mod_Int &p) const {return x == p.x;}

    bool operator != (const Mod_Int &p) const {return x != p.x;}

    Mod_Int pow (ll n) const{
        Mod_Int now = *this, ret = 1;
        while(n > 0){
            if(n & 1) ret *= now;
            now *= now, n >>= 1;
        }
        return ret;
    }

    Mod_Int inverse () const{
        return pow(mod-2);
    }
};

using mint = Mod_Int<MOD>;
const int MAX_N = 1e7;
mint fac[MAX_N+1], ifac[MAX_N+1];

void init(){
    fac[0] = 1;
    rep2(i, 1, MAX_N){
        fac[i] = fac[i-1]*mint(i);
    }
    ifac[MAX_N] = fac[MAX_N].inverse();
    rep3(i, MAX_N-1, 0){
        ifac[i] = ifac[i+1]*(i+1);
    }
}

mint comb(mint n, mint k){
    return fac[n.x]*ifac[n.x-k.x]*ifac[k.x];
}

mint perm(mint n, mint k){
    return fac[n.x]*ifac[n.x-k.x];
}

int main(){
    int N;
    cin >> N;
    init();
    mint tw = 2, th = 3, ans = th.pow(N), now = 1;
    rep(i, N/2){
        now *= 2;
        ans -= comb(N, i)*now;
    }
    cout << ans.x << endl;
}

Measured memory_bytes: 156544
def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)

import numpy as np

def solve(N, A):
    # dp[n][k] := n 人目まで見て左に k 人送ったときの最大値
    A_order = np.argsort(-A)
    dp = np.zeros((N+2, N+2), dtype=np.int64)
    for n in range(1, N+1):
        idx_A = A_order[n-1]
        a = A[idx_A]
        for k in range(n+1):
            dp[n, k] = max(
                dp[n-1, k-1] + a * abs(idx_A-(k-1)) if k>0 else 0,  # 左に送る
                dp[n-1, k] + a * abs(idx_A-(N-n+k)) if k<n else 0,  # 右に送る
            )
    return dp[N].max()

numba_compile([
    [solve, "i8(i8,i8[:])"],
])

N = int(input())
A = np.array(input().split(), dtype=np.int64)
ans = solve(N, A)
print(ans)


Measured memory_bytes: 58060
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0)
#define sz(a) (a).size()


using namespace std;

const ll N = 1e3;
const ll big = 1e18;
const ll block = 800;
const ll mod = 1e6;

ll n, x;

int main() {
    speed;
	cin >> n >> x;
	cout << 3 * (n - __gcd(n, x));
}

/*
	Code written by
	Codeforces : I_Love_Trott
	mail : dzhon.snoudin@mail.ru
*/



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, m, x; 
  cin >> n >> m >> x;

  vector<vector<int>> catalog(n, vector<int>(m+1));
  for (int i = 0; i < n; i++){
    for (int j = 0; j < m+1; j++){
      cin >> catalog.at(i).at(j);
    }
  }

  int min = 0;
  for (int bit = 0; bit < (1<<n); bit++){
    vector<int> skill(m, 0);
    int cost = 0;
    for (int i = 0; i < n; i++){
      if (bit & (1<<i)) {
        cost += catalog.at(i).at(0);
        for (int j = 0; j < m; j++){
	  skill.at(j) += catalog.at(i).at(j+1);
	} 
      }
    }
    int min_skill  = *min_element(skill.begin(), skill.end());
//    cout << "min_skill: " << min_skill << endl;
//    cout << "cost: " << cost << endl;
//    cout << "min: " << min << endl;
    if (min_skill < x) {
      continue;
    } else if ( min != 0 && min <= cost ) {
      continue;
    } else {
      min = cost;
    }
//    cout << "min (new): " << min << endl;

  }

  if (min != 0){
    cout << min; 
  } else {
    cout << -1;
  }

}


Measured memory_bytes: 3580
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;


	void doIt() {
		int n = sc.nextInt();
		int k = sc.nextInt();
		int cnt = 0;
		for(int i = 0; i < n; i++)
			if(sc.nextInt() >= k)cnt++;
		System.out.println(cnt);
		
	}

	public static void main(String[] args) {
		new Main().doIt();
	}
}


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

int main(){
  int n, a, b;
  int p[110];
  cin >> n >> a >> b;

  int x = 0, y = 0, z = 0;
  for(int i = 0;i < n;i++){
    cin >> p[i];
    if(p[i] <= a){
      x++;
    }else if(p[i] <= b){
      y++;
    }else{
      z++;
    }
  }

  cout << min(x, min(y, z)) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll> > vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge> > Graph;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    ll N;
    cin>>N;
    if(N==7||N==5||N==3)
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
}


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

#define fastIO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0);
#define endl '\n'
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define MP make_pair
#define inf INT_MAX
#define minf INT_MIN

typedef long long int lli;

ofstream outfile;
ifstream infile;

int main()
{
	infile.open("input.txt");
	outfile.open("output.txt");

	fastIO;
	int n, a;
	int n_numbers[100002], i, tot = 0, sat2= 0;

	cin >> n;
	for(i = 1; i <= 100000; ++i)
		n_numbers[i] =0;

	for(i = 0; i < n; ++i)
	{
		cin >> a;
		n_numbers[a] ++;
	}

	for(i = 1; i <= 100000; ++i)
	{
		if(n_numbers[i])
		{
			//cout << i << " "<< n_numbers[i] << "\n";
			if(n_numbers[i]%2)
				++tot;
			else
				++sat2;
		}
		
	}
	if( !(sat2%2))
		tot += sat2;
	else
		tot += (sat2-1);

	cout << tot << "\n";
}	

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=200005,INF=1<<30;

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

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    ll ans=1;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    sort(all(A));
    
    for(int i=0;i<N;i++){
        ans*=gcd(A[i],i);
        ans%=mod;
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long  
int main(){
	int N;
	long long L[100];
	cin >> N;
	L[0]=2;
	L[1]=1;
	for(int i=2;i<=N;i++){
	    L[i]=L[i-1]+L[i-2];
	}
	cout << L[N] << endl;
	return 0;
}

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

int main()
{
    int li[3];
    cin >> li[0] >> li[1] >> li[2];
    sort(li, li+3);
    if(li[0]==li[1] and li[1]!=li[2]){
        cout << "Yes\n";
    }
    else if(li[0]!=li[1] and li[1]==li[2]){
        cout << "Yes\n";
    }
    else
        cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
use std::io;
use std::cmp;

fn digits_sum(v: i64) -> i64 {
    v.to_string().chars().map(|x| x.to_digit(10).unwrap() as i64).sum()
}

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();

    stdin.read_line(&mut buf).unwrap();

    let n: i64 = buf.trim().parse().unwrap();
    let len: u32 = buf.len() as u32;
    let head: i64 = buf[..1].parse().unwrap();

    if n < 10 {
        println!("{}", n);
    } else {
        let x = head * 10i64.pow(len-2)-1;
        println!("{}", cmp::max(digits_sum(n), digits_sum(x)));
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <stack>
#include <set>

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

int k = 0;

void dfs(vector<vector<int>> &G, int u, int p, vector<int> &e, int n){
    e[k++] = u;
    for(auto v : G[u]){
        if(v == p) continue;
        dfs(G,v,u,e,n);
        e[k++] = u+n;
    }
    e[k++] = u+2*n;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<int> c(n);
    rep(i,n) cin >> c[i], c[i]--;
    vector<vector<int>> G(n);
    rep(i,n-1){
        int u,v; cin >> u >> v; u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    vector<int> euler(3*n);
    dfs(G,0,-1,euler,n);
    vector<ll> prec(n,-1), color(k), wild(n,0), sum(k+1,0), s(n,0);
    vector<vector<ll>> cnt(n);
    vector<vector<int>> st(n);
    rep(i,k) color[i] = c[euler[i]%n];
    rep(i,k) sum[i+1] = sum[i] + (euler[i] < n);
    for(int i=0; i<k; i++){
        if(euler[i] < n){
            if(st[color[i]].empty()){
                if(prec[color[i]%n] != -1){
                    wild[color[i]] += sum[i] - sum[prec[color[i]]+1];
                }else{
                    wild[color[i]] += sum[i];
                }
            }else{
                s[st[color[i]].back()] += sum[i] - sum[prec[color[i]]+1];
            }
            st[color[i]].push_back(euler[i]);
        }
        else if(n <= euler[i] && euler[i] < 2*n){
            ll pb = sum[i] - sum[prec[color[i]]+1] + s[st[color[i]].back()];
            cnt[st[color[i]].back()].push_back(pb);
            s[st[color[i]].back()] = 0;
        }else{
            ll pb = sum[i] - sum[prec[color[i]]+1] + s[st[color[i]].back()];
            cnt[st[color[i]].back()].push_back(pb);
            s[st[color[i]].back()] = 0;
            st[color[i]].pop_back();
        }
        prec[color[i]] = i;
    }
    vector<ll> ans(n,n*(n+1)/2);
    rep(i,n){
        wild[i] += sum[k] - sum[prec[i]+1];
    }
    rep(i,n){
        for(auto j : cnt[i]){
            ans[c[i]] -= j * (j+1) / 2;
        }
    }
    rep(i,n){
        ans[i] -= wild[i] * (wild[i] + 1) / 2;
    }
    rep(i,n) cout << ans[i] << "\n";
}

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

int main(){
	int N; cin >> N;
	char S[N];
	for (int i=0; i<N; i++) cin >> S[i];

	for (int i=0; i<N; i++){
		if (S[i] == 'Y'){
			cout << "Four" << endl;
			return 0;
		}
	}

	cout << "Three" << endl;
}


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

int main(){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if(0 <= x - r && 0 <= y - r && x + r <= W && y + r <= H)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;    
    return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>

using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b >>c;
  int count = 0;

  for(int i=0; i<c; i++){
    b = b - a;
    if(b<0) break;
    else count++;
  }
  cout << count <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int n,i,j,q,count=0;
    int S[10000],T[500];

    scanf("%d",&n);

for(i=0;i<n;i++){
    scanf("%d",&S[i]);
}

scanf("%d",&q);

for(i=0;i<q;i++){
    scanf("%d",&T[i]);
}

for(j=0;j<q;j++){
    i=0;
    S[n]=T[j];
    while(S[i]!=T[j]){
        i++;
    }
    if(i!=n) count++;
}

printf("%d\n",count);

return 0;

}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;
int main(){
    
int N,K;
cin >> N >> K;
int A;
map<int,int>kind;
multimap<int,int>value;
for(int i=0;i<N;i++){
    cin >> A;
    if(kind.count(A)==0){
        kind.insert(make_pair(A,1));//Aの値、その数
    }
    else{
        auto iter=kind.find(A);
        (iter->second)++;
    }
}

for(auto iter=kind.begin();iter!=kind.end();iter++){
    value.insert(make_pair(iter->second,iter->first));
}
//種類の数順位に並び替える。
int ans;

if(K>=kind.size()){
    ans=0;
}
else{
    auto iter=value.begin();
    for(int i=0;i<kind.size()-K;i++){
    ans+=iter->first;
    iter++;
    }
}

cout << ans <<endl;
 return 0;
}
/*





*/

Measured memory_bytes: 18944
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
int k=0,n=0, m=0, l=0,a=0, b=0, c=0, d=0,e=0,ans=0,ans2=0,x=0,y=0;
string s,t,S;
signed main() {
    vector<int> A(5);
    //cin >> x >> y;
    //cin >> s >> t;
  cin>>s;
  if(s=="A"){
  cout << "T";
  }else if(s=="C"){
    cout<<"G";
}else if(s=="G"){
  cout << "C";
}else{
  cout <<"A";
}
}

Measured memory_bytes: 3548
import java.util.*;

public class Main {
    public static void main(String[] args) {
        int N;
        int[] Pi = null;
        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            Pi = new int[N];
            for (int i = 0; i < N; i++) {
                Pi[i] = sc.nextInt();
            }
        }
        int result = 0;
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < Pi.length; i++) {
            if(Pi[i] < min){
                result++;
                min = Pi[i];
            }
        }
        System.out.println(result);
    }
}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 500011; 
int a[maxn];
int bit[maxn];
int n;

struct pas { 
	int l, r, idx; 
}; 

bool cmp(pas x, pas y) { 
	return x.r < y.r; 
} 


void update(int idx, int val) { 
	for (; idx <= n; idx += idx&-idx) {
		bit[idx] += val;
	}
} 

int query(int idx) { 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) {
		sum += bit[idx]; 
	}
	return sum; 
} 

void solve(pas queries[], int q) 
{
	
	int last_visit[maxn]; 
	memset(last_visit, -1, sizeof(last_visit)); 

	int ans[q]; 
	int cnt = 0; 
	for (int i=0; i<n; i++) { 
		if (last_visit[a[i]] != -1) {
			update (last_visit[a[i]] + 1, -1); 
		}

		last_visit[a[i]] = i; 
		update(i + 1, 1);

		while (cnt < q && queries[cnt].r == i) { 
			ans[queries[cnt].idx] = query(queries[cnt].r + 1) - query(queries[cnt].l); 
			cnt++; 
		} 
	} 

	for (int i=0; i<q; i++) 
		cout << ans[i] << endl; 
} 

pas que[maxn];

int main() { 
	int q;
	scanf("%d %d",&n,&q);
	int i;
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}

	for(i=0;i<q;i++){
		scanf("%d %d",&que[i].l, &que[i].r);
		que[i].l--; que[i].r--;
		que[i].idx = i;
	}
	
	sort(que, que+q, cmp); 
	solve(que, q); 
	return 0; 
} 


Measured memory_bytes: 17344
//aclbc_d.cpp
//Sat Sep 26 21:11:01 2020

#include <bits/stdc++.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

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

ll seg[1100000],nodenum;

void init(ll n){
	nodenum = 1;
	while (nodenum<n){
		nodenum*=2;
	}
	fill(seg,seg+nodenum*2-1,0);
}

void update(ll index, ll num){
	index += nodenum-1;
	seg[index] = num;
	while (index>0){
		index = (index-1)/2;
		seg[index] = max(seg[index*2+1],seg[index*2+2]);
	}
}

//[a,b)の区間の最大値を求める。b側が開放なのに注意。mainで呼ぶときはbの方は1足す。
ll query(ll a, ll b, ll k, ll l, ll r){
	if (r<=a || b<=l){
		return 0;
	}
	if (a<=l && r<=b){
		return seg[k];
	}else {
		ll val1 = query(a,b,k*2+1,l,(l+r)/2);
		ll val2 = query(a,b,k*2+2,(l+r)/2,r);
		return max(val1,val2);
	}
}

int main(){
	ll n,z;
	cin >> n >> z;

	init(300100);

	ll a[n];
	rep(i,n) cin >> a[i];

	rep(i,n){
		ll l = max(0LL,a[i]-z);
		ll r = min(nodenum-1,a[i]+z);
		ll tmp = query(l,r+1,0,0,nodenum)+1;
		update(a[i],tmp);
//		cout << a[i] << " " << tmp << endl;
//		cout << l << " " << r << " " << query(0,11,0,0,nodenum) << endl;
	}

	cout << query(0,300100,0,0,300100)<< endl;
//	printf("%.4f\n",ans);
}


Measured memory_bytes: 14172
#include <stdio.h>
#include <stdlib.h>

int main(){
	int dis[5],k;
	scanf("%d",&dis[0]);
	scanf("%d",&dis[1]);
	scanf("%d",&dis[2]);
	scanf("%d",&dis[3]);
	scanf("%d",&dis[4]);
	scanf("%d",&k);
	for (int i=0;i<4;i++){
		for (int j=i;j<5;j++){
			if (abs(dis[i]-dis[j])>k) {
				printf(":(\n");
				return 0;
			}
		}
	}
	printf ("Yay!\n");
	return 0;
}

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

void solve(int s, int g){
	if(s <= 5){
		if(s < g){
			for(int i = s; i < g; i++){
				printf("%d ", i);
			}
			printf("%d\n", g);
		}else{
			for(int i = s; i > g; i--){
				printf("%d ", i);
			}
			printf("%d\n", g);
		}
	}else{
		if(s < g){
			for(int i = s; i < g; i++){
				printf("%d ", i);
			}
			printf("%d\n", g);
		}else if(g <= 5){
			for(int i = s; i <= 9; i++){
				printf("%d ", i);
			}
			for(int i = 5; i > g; i--){
				printf("%d ", i);
			}
			printf("%d\n", g);
		}else{
			for(int i = s; i <= 9; i++){
				printf("%d ", i);
			}
			for(int i = 5; i > 0; i--){
				printf("%d ", i);
			}
			for(int i = 0; i < g; i++){
				printf("%d ", i);
			}
			printf("%d\n", g);
		}
	}
}

int main(void){
	int n, s, g;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d %d", &s, &g);
		solve(s, g);
	}
  return 0;
}

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

int main() {
  char a;
  cin >> a;
  if (islower(a)) cout << 'a' << '\n';
  else cout << 'A' << '\n';
  return 0;
}

Measured memory_bytes: 3504
#include<stdio.h>
int main(void){
  int n;
  scanf("%d",&n);
  int a[n],b[n],c[n-1],sum=0;
  for(int i=0;i<n;i++){
	scanf("%d",&a[i]);
  }
  for(int i=0;i<n;i++){
	scanf("%d",&b[i]);
    sum+=b[i];
  }
  for(int i=0;i<n-1;i++){
	scanf("%d",&c[i]);
  }
  for(int i=0;i<n-1;i++){
    if(a[i+1]-a[i]==1)sum+=c[a[i]-1];
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 128
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll n,k,s;cin>>n>>k>>s;
    if(s==1000000000){
        for(ll i=0;i<k;i++)
            cout<<s<<" ";
        for(ll i=0;i<n-k;i++)
            cout<<s-1<<" ";
        cout<<endl;
    }
    else{
    for(ll i=0;i<k;i++)
        cout<<s<<" ";
    for(ll i=0;i<n-k;i++)
        cout<<s+1<<" ";
    cout<<endl;
    }
    
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------









Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
//typedef pair<long long,long long> P;
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n,ma,mb;
  cin>>n>>ma>>mb;
  int a[n],b[n],c[n];
  REP(i,n){
    cin>>a[i]>>b[i]>>c[i];
  }
  
  vector<vector<vector<int>>> dp(n,vector<vector<int>>(401,vector<int>(401,-1)));
  REP(k,n){
    dp[k][0][0]=0;
  }
  REP(k,n){
    if(k==0){
      dp[k][a[k]][b[k]]=c[k];
      continue;
    }
    for(int i=0;i<=400;i++){
      for(int j=0;j<=400;j++){
        if(i<a[k] || j<b[k]){
          dp[k][i][j] = dp[k-1][i][j];
        }
      }
    }
    for(int i=a[k];i<=400;i++){
      for(int j=b[k];j<=400;j++){
        if(dp[k-1][i][j] == -1 && dp[k-1][i-a[k]][j-b[k]] != -1){
          dp[k][i][j] = dp[k-1][i-a[k]][j-b[k]]+c[k];
        }else if(dp[k-1][i][j] != -1 && dp[k-1][i-a[k]][j-b[k]] != -1){
          dp[k][i][j] = min(dp[k-1][i][j],dp[k-1][i-a[k]][j-b[k]]+c[k]);
        }else if(dp[k-1][i][j] != -1 && dp[k-1][i-a[k]][j-b[k]] == -1){
          dp[k][i][j] = dp[k-1][i][j];
        }else{
          continue;
        }
      }
    }
  }
  int x = min(400/ma,400/mb);
  int res=-1;
  REPP(i,x){
    if(dp[n-1][ma*i][mb*i]==-1){
      continue;
    }else if(res==-1){
      res = dp[n-1][ma*i][mb*i];
    }else{
      res = min(res,dp[n-1][ma*i][mb*i]);
    }
  }
  cout<<res<<endl;
  return 0; 
}


Measured memory_bytes: 26624
import math

a = [int(i) for i in input().split()]
if a[1] != 0:
    b = [int(i) for i in input().split()]
else:
    b = []


suu = 0
hik=math.inf
tas=math.inf
while True:
    if a[0]-suu not in b:
        hik = a[0]-suu
        break
    
    if a[0]+suu not in b:
        tas = a[0]+suu
        break
    
    suu+=1

if tas == math.inf:
    print(hik)
else:
    print(tas)

Measured memory_bytes: 9232
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
    int n,A[1000];
    while(1){
        cin >> n;
        if(n==0) break;
        double sum = 0.0;
        for(int i=0;i<n;i++){
            cin >> A[i];
            sum += A[i];
        }
        double ave = 1.0*sum/n;
        sum = 0.0;
        for(int i=0;i<n;i++){
            sum += pow(A[i]-ave,2);
        }
        printf("%.5f\n",sqrt(sum/n));
    }
    return 0;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in", "r", stdin);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 3 != 0 && i % 5 != 0) {
      ans += i;
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3644
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <complex>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cerr<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;

struct State{
	int x,y,t,w;
	State(){}
	State(int x,int y,int t,int w):x(x),y(y),t(t),w(w){}
	bool operator<(const State& s)const{return w<s.w;}
	bool operator>(const State& s)const{return w>s.w;}
};

int main()
{
	int dx[]={0,1,1,0,-1,-1,0};
	int dy[]={1,0,-1,-1,-1,0,0};
	for(int sx,sy,gx,gy;cin>>sx>>sy>>gx>>gy;){
		int n; cin>>n;
		vi xs(n),ys(n);
		rep(i,n) cin>>xs[i]>>ys[i];
		int lx,ly; cin>>lx>>ly;
		
		vvi bad(2*lx+1,vi(2*ly+1));
		rep(i,n) bad[lx+xs[i]][ly+ys[i]]=1;
		
		vvvi dist(2*lx+1,vvi(2*ly+1,vi(6,INFTY)));
		priority_queue<State,vector<State>,greater<State> > pq;
		pq.push(State(sx,sy,0,0));
		while(pq.size()){
			State cur=pq.top(); pq.pop();
			if(dist[lx+cur.x][ly+cur.y][cur.t]!=INFTY) continue;
			dist[lx+cur.x][ly+cur.y][cur.t]=cur.w;
			int dir=abs(cur.x)*abs(cur.y)*cur.t%6;
			rep(k,7){
				int nx=cur.x+dx[k],ny=cur.y+dy[k];
				if(k!=0 && k!=3 && k!=6) ny+=cur.x&1;
				if(abs(nx)>lx || abs(ny)>ly || bad[lx+nx][ly+ny]) continue;
				pq.push(State(nx,ny,(cur.t+1)%6,cur.w+(k!=dir)));
			}
		}
		int res=*min_element(all(dist[lx+gx][ly+gy]));
		cout<<(res==INFTY?-1:res)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 4464
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)       for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF                 (int)2e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef long long           ll;
typedef pair<ll, ll>        P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	int N;
	ll P;
	string S;
	cin >> N >> P >> S;

	ll ans = 0;
	reverse(ALL(S));
	if (P == 2 || P == 5) {
		REP(i, N) {
			int keta = S[i] - '0';
			if (keta % P == 0) {
				ans += N - i;
			}
		}
	} else {
		vector<ll> ketaAmari(N, 0);
		ll amariOne = 1;
		REP(i, N) {
			amariOne %= P;
			ketaAmari[i] = amariOne;
			amariOne *= 10;
		}

		ll amari = 0;
		map<ll, ll> mp;
		mp[0]++;
		REP(i, N) {
			int keta = S[i] - '0';
			amari += keta * ketaAmari[i];
			amari %= P;
			mp[amari]++;
		}

		for (auto mpOne : mp) {
			ans += mpOne.second * (mpOne.second - 1) / 2;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2564
#include <iostream>
#include <cstdio>
#include <iomanip>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>

#include <numeric>
#include <algorithm>
#include <functional>

#include <cctype>

#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(unsigned int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                                                  it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))

typedef long long ll;
typedef complex<double> P;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};
const double EPS = 1e-9;
const int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

int main(){

    while(true){

        int N;
        cin >> N;
        if(N == 0) break;
        vector<set<int> > V(N);
        rep(i,N){
            int M;
            cin >> M;
            rep(j,M){
                int p;
                cin >> p;
                V[i].insert(p);
            }
        }
        int K;
        cin >> K;
        vector<int> R;
        rep(i,K){
            int k;
            cin >> k;
            R.push_back(k);
        }
        int ret = -1;
        bool ok = false;
        rep(i,N){
            bool ook = true;
            rep(j,K){
                if(V[i].find(R[j]) == V[i].end()) ook = false;
            }
            if(ook){
                if(ret == -1){
                    ret = i+1;
                    ok = true;
                }else{
                    ok = false;
                }
            }
        }
        cout << (ok?ret:-1) << endl;
    }
    return 0;
}

Measured memory_bytes: 1644
c = []
for i in range(3):
    c.append(list(map(int, input().split())))

flag = 1

for i in range(1, 3):
    if (c[0][0] - c[0][1] != c[i][0] - c[i][1]):
        flag = 0
    if (c[0][1] - c[0][2] != c[i][1] - c[i][2]):
        flag = 0
    if (c[0][2] - c[0][1] != c[i][2] - c[i][1]):
        flag = 0
if flag == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

import java.util.*;

public class Main {

    static long gcd(long a,long b) {
        long temp;
        while ((temp=a%b)!=0) {
            a=b;
            b=temp;
        }
        return b;
    }

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int T = in.nextInt();
        for (int i=0;i<T;i++) {
            long A = in.nextLong();
            long B = in.nextLong();
            long C = in.nextLong();
            long D = in.nextLong();
            if (A<B || D<B) {
                out.println("No");
                continue;
            }
            if (gcd(B, D)==1) {
                if (B-1<=C) out.println("Yes");
                else out.println("No");
                continue;
            } else {
                long GCD = gcd(B, D);
                // out.println("GCD"+GCD);
                if (A<C) {
                    A+=D*(C-A+D-1)/D;
                }
                // out.println(A);
                // long ok = 0;
                // long ng = 5000000000000000000;
                // while (Math.abs(ok-ng)>1) {
                //     long mid = (ok+ng)/2;
                //     if (A-GCD*mid>C) ok=mid;
                //     else ng=mid;
                // }
                long ok = (A-C)/GCD;
                if ((A-C)%GCD==0) ok--;
                // out.println("ok"+ok);
                long value = A-GCD*ok-B;
                if (value>=0) out.println("Yes");
                else out.println("No");
                // long yy = (A-C)*GCD/B;
                // long ff = A-B/GCD*yy;
                // out.println(yy);
                // out.println(ff);
            }
        }

        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}


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

int main() {
	int N;
	cin >> N;
	int sum = 0;
	for (int i = 0; i < N; i++) {
		int l, r;
		cin >> l >> r;
		sum += r - l + 1;
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
program ABC151C
    implicit none
    integer::N,M
    integer::p
    character(2)::S
    logical,allocatable,dimension(:)::AC
    integer,allocatable,dimension(:)::cntWA
    integer::ACcnt,Pen
    integer::i
    read*,N,M
    allocate(AC(N),cntWA(N))
    AC=.false.
    cntWA=0
    do i=1,M
        read*,p,S
        if(S=="AC")then
            AC(p)=.true.
        else
            if(AC(p))cycle
            cntWA(p)=cntWa(p)+1
        endif
    end do
    ACcnt=0;Pen=0
    do i=1,N
        if(AC(i))then
            ACcnt=ACcnt+1
            Pen=Pen+cntWA(i)
        endif
    end do
    print"(i0,A,i0)",ACcnt," ",Pen
end program ABC151C

Measured memory_bytes: 1024
let rec solve n =
    let rec _solve n a b c =
        if n <= 0
        then max a (max b c)
        else
            let (x, y, z) = Scanf.scanf " %d %d %d" (fun x y z -> (x, y, z)) in
            let a1 = x + max b c in
            let b1 = y + max c a in
            let c1 = z + max a b in
            _solve (n - 1) a1 b1 c1 in
    _solve n 0 0 0;;


let () =
    let n = Scanf.scanf "%d" (fun x -> x) in
    print_int (solve n);
    print_newline ();;


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Sort(v) sort(v.begin(),v.end(),[](int a, int b) { return a > b; })

typedef long long ll;

int main() {
    ll X,Y,A,B,C;
    cin>>X>>Y>>A>>B>>C;
    vector<ll> p(A),q(B),r(C);
    rep(i,A) cin>>p[i];
    rep(i,B) cin>>q[i];
    rep(i,C) cin>>r[i];
    Sort(p);Sort(q);Sort(r);
    ll ans = 0;
    rep(i,X) ans+=p[i];
    rep(i,Y) ans+=q[i];
    ll  xx=X-1,yy=Y-1,zz=0;
    while(xx>=0 || yy>=0){
        if(xx>=0 && yy>=0){
            if(p[xx]<q[yy] && p[xx]<r[zz]){
                ans-=p[xx];ans+=r[zz];
                xx--;
            }
            else if(p[xx]>=q[yy] && q[yy]<r[zz]){
                ans-=q[yy];ans+=r[zz];
                yy--;
            }
        }else if(xx<0 && q[yy]<r[zz]){
            ans-=q[yy];ans+=r[zz];
            yy--;
        }else if(yy<0 && p[xx]<r[zz]){
            ans-=p[xx];ans+=r[zz];
            xx--;
        }else break;
        zz++;
        if(zz==C) break;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main(){
    int H, W;
    while(true){
        cin >> H >> W;
        if(H == 0 && W == 0)
            break;


            for (int i = 0; i < W; i++){
            cout << "#";
            }
            cout << endl;

            for (int i = 0; i < H - 2; i++){
                cout << "#";
                    for (int i = 0; i < W - 2; i++){
                     cout << ".";
                    }
                cout << "#" << endl;
            }
            for (int i = 0; i < W; i++){
            cout << "#";
            }
            cout << endl << endl;
    }
}


Measured memory_bytes: 3092