akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define mod 1000000007;

typedef long long ll; 
typedef pair<int, int> ii; 
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

// Prll fn to prll array



int main(){
	ll n;
	cin >> n;
	vi ar(n);
	for(ll i=0;i<n;i++) cin >> ar[i];

	map<ll,ll> M;
	map<ll,ll> res;
	map<ll,ll>::iterator itr;

	for(ll i=0;i<n;i++) M[ar[i]]++;
	ll tot = 0;
	for(itr=M.begin();itr!=M.end();itr++){
		ll y = itr->second;
		if(y>=2) tot+=(y*(y-1)/2);
		// cout << itr->first << " " << itr->second << endl;
	}
	// cout << tot << endl;
	for(itr=M.begin();itr!=M.end();itr++){
		ll y = itr->second;
		if(y<=1){
			res[itr->first]=tot;
			continue;
		}
		ll z = y*(y-1)/2;
		ll j = 0;
		if(y>=3){
			j = (y-1)*(y-2)/2;
		}
		res[itr->first]=tot-z+j;
		// cout << res[itr->first] << " " <<z << " " <<  j <<" " << itr->first << " " << itr->second << endl;
	}

	for(ll i=0;i<n;i++){
		cout << res[ar[i]] << endl;
	}

	return 0;
}

Measured memory_bytes: 18176
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


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


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


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


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


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


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


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


def mt(f):
    import time

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

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

    return wrap


@mt
def slv(N, A):
    ans = 0
    A = [list(reversed(a)) for a in A]

    s1 = set()
    s2 = set()

    def update(i):
        if not A[i-1]:
            return

        d = A[i-1][-1]
        n = (min(i, d), max(i, d))
        if n not in s1:
            s1.add(n)
        else:
            s2.add(n)
            s1.remove(n)

    for i in range(1, N+1):
        update(i)

    while s2:
        ans += 1
        for k in tuple(s2):
            a, b = k
            A[a-1].pop()
            A[b-1].pop()
            update(a)
            update(b)
            s2.remove(k)


    for a in A:
        if a:
            return -1
    return ans


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


if __name__ == '__main__':
    main()


Measured memory_bytes: 46452
#include <stdio.h>

int main(void)

{
int a, b, c, min, nut, max;

scanf("%d %d %d", &a, &b, &c);

if(a >= b)
{
if(b >= c)
{
min = c;
max = a;
nut = b;
}
else
{
min = b;
if(a >= c)
{
max = a;
nut = c;
}
else
{
max = c;
nut = a;
}
}
}
else
{
if(a >= c)
{
min = c;
nut = a;
max = b;
}
else
{
if(c < b)
{
min = a;
nut = c;
max = b;
}
else
{
max = c;
nut = b;
min = a;
}
}
}
printf("%d %d %d\n", min, nut, max);

return 0;

}



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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++ i)
#define ALL(r) r.begin(), r.end()
#define DUP(x, y) (((x) + (y) - 1) / (y))
#define YES puts("YES")
#define NO puts("NO")
#define Yes puts("Yes")
#define No puts("No")
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end())

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

constexpr int MAX_N = 105;
constexpr int MAX_V = 100500;
ll dp[MAX_N][MAX_V];

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

void Main() {
    int N, W;
    cin >> N >> W;
    vll w(N), v(N);
    rep(i, N)cin >> w[i] >> v[i];

    rep(i, MAX_N)rep(j, MAX_V)dp[i][j] = INF;
    dp[0][0] = 0;

    rep(i, N) {
        rep(sum_v, MAX_V) {
            if (sum_v - v[i] >= 0)chmin(dp[i + 1][sum_v], dp[i][sum_v - v[i]] + w[i]);
            chmin(dp[i + 1][sum_v], dp[i][sum_v]);
        }
    }

    ll ans = 0;
    rep(i, MAX_V) {
        if (dp[N][i] <= W) {
            ans = i;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    //std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}



Measured memory_bytes: 82688
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin>>a;
  vector<int> vect(3);
  for(int i=0;i<3;i++){
    vect.at(2-i)=a%10;
    a=a/10;
    if(a==0){
      break;
    }
  }
  
  for(int i=0;i<3;i++){
    if(vect.at(i)==1){
      vect.at(i)=9;
    }else{
      vect.at(i)=1;
    }
  }
  
  cout<<vect.at(2)+10*vect.at(1)+100*vect.at(0)<<endl;
 // cout<<vect.at(2)+10*vect.at(1)+100*vec
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String x;
		int total;
		while(true){
			x = sc.next();
			if (x.equals("0")){
				break;
			}
			total = 0;
			for (int i = 0; i < x.length(); i++){
				total += Integer.parseInt("" + x.charAt(i));
			}
			System.out.println(total);
		}
	}
}

Measured memory_bytes: 18772
import numpy as np

N = int(input())
A = [int(i) for i in input().split()] 
Acnt = 0
for i in range(N):
	if A[i] < 0:
		Acnt += 1

if Acnt % 2 == 1:
	print(np.sum(np.abs(A)) - np.min(np.abs(A))*2)
elif Acnt % 2 == 0:
	print(np.sum(np.abs(A)))


Measured memory_bytes: 23292
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main()
{
    int n;
  cin>>n;
    ll x, d;
    cin>>x>>d;
    if(d==0){
        if(x==0){
            cout<<1<<endl;
        }else{
            cout<<n+1<<endl;
        }
        return 0;
    }
    ll l[200020], r[200020];
    for(ll i=0; i<=n; i++){
        l[i]=(2*i-n)*x-(ll)n*(n-1)/2*d+i*(i-1)*d;
        r[i]=(2*i-n)*x+(ll)n*(n-1)/2*d-(n-i)*(n-i-1)*d;
      if(l[i]>r[i]) swap(l[i], r[i]);
     //cout<<l[i]<<" "<<r[i]<<endl;
    }
    map<ll, vector<P>> mp;
    d=abs(d);
    for(int i=0; i<=n; i++){
        ll s=(l[i]%(2*d)+2*d)%(2*d);
        mp[s].push_back({l[i], r[i]});
    }
    for(auto &p:mp) sort(p.second.begin(), p.second.end());
    ll ans=0;
    for(auto p:mp){
        ll y=p.second[0].first, z=p.second[0].second;
        for(int i=1; i<p.second.size(); i++){
            if(z<p.second[i].first){
                ans+=(z-y)/(2*d)+1;
                y=p.second[i].first, z=p.second[i].second;
            }else{
                z=max(z, p.second[i].second);
            }
        }
        ans+=(z-y)/(2*d)+1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 25216
#include<bits/stdc++.h>
const int MN=100000+5,P=1000000007;
using namespace std;
typedef long long ll;
template<typename T>inline T&IN(T&in){
	in=0;char c=getchar();int f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))in=in*10+c-'0',c=getchar();
	return in*=f;
}
int n,ans;char c[MN];
int vis[MN];
void input(){
	IN(n);scanf("%s",c+1);ans=1;
	for(int i=1;i<=n;++i)vis[c[i]]++;
	for(int i=0;i<26;++i)ans=(ll)ans*(vis[i+'a']+1)%P;
	printf("%d\n",(ans-1)%P);
}
int main(){
	input();
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;

LL A,B,T;
int N;
LL h[100000];

bool BS(LL t){
    LL s=0;
    for(int i=0;i<N;i++){
        s+=max(0LL,(h[i]-t*B+T-1)/T);
    }
    if(s<=t) return true;
    else return false;
}

int main(){
    cin >> N;
    cin >> A >> B;
    for(int i=0;i<N;i++){
        cin >> h[i];
    }
    T=A-B;
    LL l=1,r=1e9;
    while(1){
        LL t=(r+l)/2;
        if(BS(t)){
            if(r-l==1){
                cout << l << endl;
                return 0;
            }
            r=t;
        }
        else{
            if(r-l==1){
                cout << r << endl;
                return 0;
            }
            l=t;
        }
    }
    return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	
	int N, X, Y;

	cin >> N >> X >> Y;
	--X, --Y;
	vector<int> res(N);

	forn(st, N)
	{
		vector<int> dist(N, N);
		vector<int> q(1, st);
		dist[st] = 0;
		forn(qq, q.size())
		{
			int act = q[qq];
			if (act > 0 && dist[act - 1] == N)
			{
				dist[act - 1] = dist[act] + 1;
				res[dist[act - 1]]++;
				q.push_back(act - 1);
			}
			if (act < N - 1 && dist[act + 1] == N)
			{
				dist[act + 1] = dist[act] + 1;
				res[dist[act + 1]]++;
				q.push_back(act + 1);
			}
			if (act == X && dist[Y] == N)
			{
				dist[Y] = dist[X] + 1;
				res[dist[Y]]++;
				q.push_back(Y);
			}
			if (act == Y && dist[X] == N)
			{
				dist[X] = dist[Y] + 1;
				res[dist[X]]++;
				q.push_back(X);
			}
		}
	}

	forn(i, N-1)
		cout << res[i+1]/2 << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define INF 1<<30
using namespace std;
int main(){
	//ツ渉可甘コツ可サ
	int n; cin>>n;
	int id[n],d[n],a[n],prev[1<<n][n],w[1<<n],ans[n];
	rep(i,n)cin>>id[i]>>d[i]>>a[i];
	rep(i,1<<n){
		w[i]=0; rep(j,n)w[i]+=i&(1<<j)?2*a[j]:0;
	}
	int t[1<<n][n],mn=INF,mni; rep(i,1<<n)rep(j,n)t[i][j]=INF;
	//TSP
	queue<pair<int,int> > F;
	rep(i,n)F.push(mp(1<<i,i)),t[1<<i][i]=0;
	while(!F.empty()){
		int s=F.front().first,c=F.front().second,ns; F.pop();
		rep(i,n)if(!((1<<i)&s)){
			ns=s|(1<<i); int tt=t[s][c]+(d[i]>d[c]?d[i]-d[c]:d[c]-d[i])*(7+w[s]);
			if(t[ns][i]>tt)F.push(mp(ns,i)),t[ns][i]=tt,prev[ns][i]=c;
		}
	}
	rep(i,n)if(mn>t[(1<<n)-1][i])mn=t[(1<<n)-1][i],mni=i;
	ans[0]=mni;
	for(int i=1,s=(1<<n)-1;i<n;i++)ans[i]=prev[s][ans[i-1]],s^=1<<ans[i-1];
	rep(i,n)cout<<id[ans[n-i-1]]<<(i<n-1?" ":"\n");
	return 0;
}

Measured memory_bytes: 6016
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll A, B, K;
    cin >> A >> B >> K;
    for (ll i = 0; i < K; i++) {
        if (i % 2 == 0) {
            if (A % 2 == 1) {
                A--;
            }
            A /= 2;
            B += A;
        } else {
            if (B % 2 == 1) {
                B--;
            }
            B /= 2;
            A += B;
        }
    }

    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
    const int MAX =200002;
const int MOD =1000000007;

     signed main(){
     string n;
     cin>>n;
     int ans=0;
     for(int i=0;i<n.size();i++)ans=(ans+(n[i]-'0'))%9;
     if(ans)cout<<"No"<<endl;
     else cout<<"Yes"<<endl;

     }


 


 






    





      

        


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

int N;

int main(){
	scanf("%d", &N);
	int max = -1;
	int max_i;
	for(int i = 1; i <= N; i++){
		int div_2 = i;
		int cnt = 0;
		while(div_2 % 2 == 0){
			div_2 /= 2;
			cnt++;
		}
		//printf("%d:%d\n", i, cnt);
		if(cnt > max){
			max = cnt;
			max_i = i;
		}
	}
	printf("%d\n", max_i);
	return 0;
}


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

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

template<typename Tn> Tn lcm(Tn a, Tn b)
{
	return a / gcd(a, b) * b;
}

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

int n;
int a[100001];
map<int, int> m;
vi b;

int main()
{
    ci >> n;
    rep(i, n) {
	ci >> a[i];
	if(a[i] % 2 == 0) cnt++;
    }

    if(n == cnt) co << "second" << en;
    else co << "first" << en;
    
    return 0;
}


Measured memory_bytes: 640
n, c, k = map(int, input().split())
t = sorted([int(input()) for _i in range(n)])+[float('inf')]

b = 0
time = t[0]
count = 0
for i in range(n+1):
    if t[i] > time+k or count == c:
        b += 1
        time = t[i]
        count = 0
    count += 1
print(b)

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

#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define FOR(i,l,r) for(long long i=l; i<r; i++)
#define FOR_REV(i,r,l) for(long long i=r; i>=l; i--)
#define pb push_back
#define mp make_pair

int main()
{
    long double circum;
    ll r;

    cin>>r;

    circum = (long double)(2*22*r)/(long double)7;

    cout<<setprecision(10)<<circum<<endl;
}


Measured memory_bytes: 3792
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    if(a%2==0){
      if(a%3!=0&&a%5!=0){
        cout << "DENIED" << endl;
        exit(0);
      }
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}


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

using namespace std;

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

int main(){
  int n; cin >> n;
  vector<int> h(n); int i; rep(i, n) cin >> h[i];
  
  vector<int> cost(n);
  cost[0] = 0; cost[1] = abs(h[1] - h[0]);
  for(int i = 2; i < n; i++) cost[i] = min(cost[i - 1] + abs(h[i] - h[i - 1]), cost[i - 2] + abs(h[i] - h[i - 2]));
  
  cout << cost[n - 1] << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define de_x(x) cout<<"debug_val: "<<x<<endl;
#define de_ve(x) for(auto it: x) cout<<it<<" ";
#define rep(i,a,n) for (int i=a;i<n;i++)
#define rep_(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef double db;
std::mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x ; }
const ll MOD=1e9 +7;
ll ksm(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int _;
/*
 *
 *
 *
 *
 */
int main(){
    int n,m,d;cin>>n>>m>>d;
    int cnt =0;
    for(int i =n;i<=m;i++) if(i%d == 0 )cnt++;
    cout<<cnt<<endl;
}

Measured memory_bytes: 3636
/*#### bits/stdc++.h */
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<iostream>
#include<string>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<deque>
#include<queue>
#include<utility>
#include<algorithm>
#include<bitset>
using namespace std;
/*####*/

bitset<4000001> B;
int main(){
	int sum=0,n,x;
	B.set(0);
	scanf("%d",&n);
	for(int i=0; i<n; i++){
		scanf("%d",&x);
		B |= B << x;
		sum += x;
	}
	sum = (sum + 1)/2;
	while(!B.test(sum))sum++;
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int x;
  char str[2];
  int a=0,b=0,o=0,ab=0;
  while(scanf("%d,%s\n",&x,str)==2) {
    string s(str);
    if (s == "A") a++;
    if (s=="B") b++;
    if (s=="O") o++;
    if (s=="AB") ab++;
  }
  printf("%d\n%d\n%d\n%d\n",a,b,ab,o);
}

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

int H, W;
char tile[101][101];

void magi(int y, int x);

int main()
{
  while (scanf("%d%d", &H, &W), W || H){
    for (int i = 0; i < H; i++){
      scanf("%s", tile[i]);
    }
    magi(0, 0);
  }

  return (0);
}

void magi(int y, int x)
{
  if (tile[y][x] == '.'){
    printf("%d %d\n", x, y);
  }
  else if (tile[y][x] == '0'){
    puts("LOOP");
  }

  if (0 <= x + 1 && x + 1 <= W - 1 && tile[y][x] == '>'){
    tile[y][x] = '0';
    magi(y, x + 1);
  }
  if (0 <= x - 1 && x - 1 <= W - 1 && tile[y][x] == '<'){
    tile[y][x] = '0';
    magi(y, x - 1);
  }
  if (0 <= y + 1 && y + 1 <= H + 1 && tile[y][x] == 'v'){
    tile[y][x] = '0';
    magi(y + 1, x);
  }
  if (0 <= y - 1 && y - 1 <= H - 1 && tile[y][x] == '^'){
    tile[y][x] = '0';
    magi(y - 1, x);
  }
}

Measured memory_bytes: 1232
n = int(input())
A = list(map(int, input().split()))
A = sorted(A)
ans = 0


def q(k):
    if A[k] < A[i] + A[j]:
        return True
    else:
        return False


for i in range(n):
    for j in range(i + 1, n):
        l = j
        r = n
        while r - l > 1:
            mid = (l + r) // 2
            if q(mid):
                l = mid
            else:
                r = mid
        ans += (l - j)


print(ans)


Measured memory_bytes: 73532
#include<bits/stdc++.h>
        #include<chrono>
         
        using namespace std;
        using namespace std::chrono;
         
        /// ----------------------------- (Debug) ------------------------------
        #define sim template < class c
        #define ris return * this
        #define dor > debug & operator <<
        #define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
        sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
        sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
        struct debug {
        #ifndef ONLINE_JUDGE
        eni(!=) cerr << boolalpha << i; ris; }
        eni(==) ris << range(begin(i), end(i));}
        sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
        sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
        #else
        sim dor(const c&) { ris; }
        #endif
        };
        vector<char*> tokenizer(const char* args) {
            char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
            vector<char*> v({token});
            while(token = strtok(NULL,", ")) v.push_back(token);
            return reverse(v.begin(), v.end()), v;
        }
        void debugg(vector<char*> args) { cerr << "\b\b "; }
        template <typename Head, typename... Tail>
        void debugg(vector<char*> args, Head H, Tail... T) {
            debug() << " [" << args.back() << ": " << H << "] ";
            args.pop_back(); debugg(args, T...);
        }
        #define harg(...) #__VA_ARGS__
        #ifndef ONLINE_JUDGE
        #define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
        #else
        #define dbg(...) { }
        #endif
        /// -----------------------------------------------------------------------
         
         
        typedef long long ll;
        typedef vector<int> vi;
        typedef pair<int,int> pi;
        typedef vector<pi> vpi; 
        #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
        #define F first
        #define S second
        #define PB push_back
        #define EB emplace_back
        #define MP make_pair
        #define print(x) cout << x << "\n";
        #define REP(i,a,b) for(i=a;i<=b;i++)
        #define RAP(i,a,b) for(i=a;i>=b;i--)
        #define spa <<" "<<
        #define all(x) (x).begin(), (x).end()
        int mod=1000000007;
        const int MX=0x3f3f3f3f;
         
        int main(){
            IOS;
            int n,i;
            cin>>n;
            int a[n];
            REP(i,0,n-1) cin>>a[i];
            map<ll,int> mp;
            ll ans=0;
            REP(i,0,n-1){
                if(mp.find(i-a[i])!=mp.end()) ans+=mp[i-a[i]];
                mp[i+a[i]]++;
            }  
            cout<<ans;
            return 0;
        } 

Measured memory_bytes: 16908
object Main extends App {
  val n = scala.io.StdIn.readInt()
  val aInput = scala.io.StdIn.readLine()
  val aArray = aInput.split(" ").map(_.toInt).toVector
  var result = 0
  var index = 1
  aArray.foreach { a =>
    if(index == a) {
      index += 1
    } else {
      result += 1
    }
  }
  if (result == n) {
    println(-1)
  } else {
    println(result)
  }
}

Measured memory_bytes: 58712
import java.util.List;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;

class Node {
    Integer id;
    Integer parentId;
    Integer depth;
    Integer type;
    List<Integer> childrenIds;
}


class Main {
    static Map<Integer, Node> nodes = new HashMap<>();

    static final Map<Integer, String> types = new HashMap<Integer, String>() {
      {
          put(1, "root");
          put(2, "internal node");
          put(3, "leaf");
      }
    };

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

        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            Integer id = sc.nextInt();
            int m = sc.nextInt();

            Node node = nodes.get(id);
            if (node == null) {
                node = new Node();
                node.id = id;
                node.type = 1;
                node.depth = 0;
                node.parentId = -1;
                nodes.put(id, node);
            } else if (m != 0) {
                node.type = 2;
            } else {
                node.type = 3;
            }

            Node parentNode = nodes.get(node.parentId);
            if (parentNode != null) {
                node.depth = parentNode.depth + 1;
            }

            List<Integer> childrenIds = new ArrayList<>();

            for (int j = 0; j < m; j++) {
                Integer childrenId = sc.nextInt();
                Node childrenNode = nodes.get(childrenId);
                if (childrenNode == null) {
                    childrenNode = new Node();
                    childrenNode.id = childrenId;
                    nodes.put(childrenId, childrenNode);
                }
                childrenNode.parentId = node.id;
                childrenNode.depth = new Integer(node.depth.intValue() + 1);
                if (childrenNode.childrenIds == null || childrenNode.childrenIds.isEmpty()) {
                    childrenNode.type = 3;
                } else {
                    childrenNode.type = 2;
                }
                childrenIds.add(childrenId);
            }
            node.childrenIds = childrenIds;
        }

        for (Integer i = 0; i < n; i++) {
            Node node = nodes.get(i);
            System.out.printf("node %d: parent = %d, depth = %d, %s, [%s]\n",
                    node.id,
                    node.parentId,
                    node.depth,
                    types.get(node.type),
                    node.childrenIds.stream().map(elm -> elm.toString()).collect(Collectors.joining(", ")));
        }
    }
}



Measured memory_bytes: 200472
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int a,b;
    cin>>a>>b;
    if(a>=13)cout<<b<<endl;
    else if(a<=5)cout<<0<<endl;
    else cout<<b/2<<endl;
}

Measured memory_bytes: 256
import fractions

def euclid(x, y):
    return (x * y) // fractions.gcd(x, y)

def dif(x, C, D):
    return x - (x//C) - (x//D) + (x//(euclid(C, D)))

def main():
    A, B, C, D = map(int, input().split())
    return dif(B, C, D) - dif((A-1), C, D)

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 5052
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/*Atcoder用
 * 		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int a = Integer.parseInt(tmp[0]);
		int b = Integer.parseInt(tmp[1]);
		int c = Integer.parseInt(tmp[2]);


		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String get = br.readLine();
		char[] s = get.toCharArray();
		for(char c:s)System.out.println(c);

		List<Integer> ls = new ArrayList<Integer>();
		String[] tmp = br.readLine().split(" ");
		for (int n = 0; n < N; n++) {
			ls.add(Integer.parseInt(tmp[n]));
		}
 */

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int N = Integer.parseInt(tmp[0]);
		int K = Integer.parseInt(tmp[1]);

		List<Integer> ls = new ArrayList<Integer>();
		String[] foo = br.readLine().split(" ");
		//for (int n = 0; n < N; n++) {
			//ls.add(Integer.parseInt(foo[n]));
		//}

		int ans = 0;
		if((N-1)%(K-1) != 0){
			ans = (int)Math.floor((N-1)/(K-1));
			ans++;
		}else{
			ans = (int)((N-1)/(K-1));
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 34900
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int a[123456];
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	int gcd=a[0];
	for(int i=1;i<n;i++)
	{
		gcd=__gcd(gcd,a[i]);
		if(gcd==1)
			break;
	}
	cout<<gcd<<endl;
	return 0;
}
//求解每一位的最小值，用辗转相除法，求最大公约数 
//f题 

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int dp[100001];
int h[100001];
int main()
{
  int n, k; cin >> n >> k;
  for (int i = 1; i <= n; i++)
  {
    cin >> h[i];
    dp[i] = 2e9 + 7;
  }
  dp[1] = 0;
  for (int i = 1; i <= n; i++)
  {
    for (int j = 1; j <= k; j++)
    {
      if (i + j <= n) dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
    }
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string s;
    cin>>s;
    int ans1=0,ans2=0;
    for(int i=0; i<s.length(); ++i){
        if(i%2==0){
            if(s[i]=='1'){
                ans1++;
            }
            else{
                continue;
            }
        }
        else{
            if(s[i]=='0'){
                ans1++;
            }
            else{
                continue;
            }
        }
    }

    for(int i=0; i<s.length(); ++i){
        if(i%2==0){
            if(s[i]=='0'){
                ans2++;
            }
            else{
                continue;
            }
        }
        else{
            if(s[i]=='1'){
                ans2++;
            }
            else{
                continue;
            }
        }
    }
    cout<<min(ans1,ans2)<<endl;
}

Measured memory_bytes: 512
n = int(input())

a = [1] * (n+1)
ans = 1
for i in range(2, n+1):
  a[i] += 1
  for j in range(i*2, n+1, i):
    a[j] += 1
  ans += i * a[i]
#print(a)
print(ans)

Measured memory_bytes: 145984
#include <iostream>
using namespace std;
int main(){
  int n,p,i,m,a=0,I;
  int box[100]={};
  while(1){
    cin>>n>>p;
    a=0;
    if(n==0&&p==0) break;
    else{
      while(1){

	for(i=0;i<n;i++){
	  m=i;
	 
	  if(p>0){
	    box[m]+=1;
	    p-=1;
	  }
	  else if(p==0){
	    for(I=0;I<n;I++){
	      if(box[I]==0) a++;
	    }
	    if(a==n-1) {
	      break;
	    }
	    else {
	      p=box[m];
	      box[m]=0;
	      a=0;
	    }
	  }
	}
	if(a==n-1) break;
      }
      if(m-1<0){
	m=n;
      }
      cout<<m-1<<endl;
          } 
    for(i=0;i<n;i++){
      box[i]=0;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#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()
{
    int R, G, B, K;
    cin >> R >> G >> B >> K;
    bool ok = false;
    rep(i, K)
    {
        if (B <= R || B <= G)
            B *= 2;
        else if (G <= R)
            G *= 2;
        // cout << R << " " << G << " " << B << " " << i << endl;
        if (G > R && B > G)
            ok = true;
    }
    if (ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int r,d,x;
    cin >> r >> d >> x;
    rep(i,10){
        x = r*x - d;
        cout << x << endl;
    }

}


Measured memory_bytes: 256
#include <stdio.h>

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

int main(void)
{
    int n;
    long long t, ans = 1LL;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &t);
        ans *= t / gcd(ans, t);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,num,count=0;
  map<long long,int> a;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>num;
    if(a[num]==0)a[num]++;
    else a[num]--;
  }
  for(auto itr=a.begin();itr!=a.end();itr++){
    if(itr->second==1)count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 6528
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
# gcd
from fractions import gcd
# 切り上げ，切り捨て
from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
from collections import Counter
import math
from functools import reduce
# input関係の定義
# fin = open('in_2.txt', 'r')
# sys.stdin = fin
#
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


def solve(n: int, p: "List[int]"):
    cnt = 0
    for i in range(1, n - 1):
        if (p[i - 1] - p[i]) * (p[i + 1] - p[i]) < 0:
            cnt += 1
    print(cnt)


def main():

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


if __name__ == '__main__':
    main()


Measured memory_bytes: 66156
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
struct point
{
    ll x, y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n,k;
    cin>>n>>k;
    ve <ll> arr(n);
    rep (i,0,n)
    {
        cin>>arr[i];
    }
    sort(all(arr));
    ll ans=0;
    rep (i,0,k)
    {
        ans+=arr[i];
    }
    cout<<ans<<"\n";
}


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define A first
#define B second
#define MOD 1000000007

typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;

int mulmd(ll a, ll b){
    ll ret = (a * b) % MOD;
    return (int)ret;
}

inline int power(ll x, ll y, int p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = mulmd(res, x);
        y = y >> 1;
        x = mulmd(x, x);
    }
    return (int)res;
}

int submd(ll a, ll b){
    ll ret = a - b;
    if(ret < 0){
        ret += MOD;
    }
    return (int)ret;
}

int addmd(ll a, ll b){
    ll ret = (a + b) % MOD;
    return (int)ret;
}

int invPow(ll a){
    return power(a, MOD - 2, MOD);
}

const int N = 1e5 + 5;

int arr[N];
int b[N];

/**
    Check out for boundary cases, (n = 1 or n = 0)
    check for integer overflow

**/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    REP(i, n) cin >> arr[i];
    b[n - 1] = 0;
    int ans = 0;
    FORD(i, n - 2, 0){
        if(arr[i] >= arr[i + 1]){
            b[i] = b[i + 1] + 1;
        }
        else {
            b[i] = 0;
        }
        ans = max(ans, b[i]);
    }
    cout << ans;

}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);
    lli n,m,M=1000000007;
    cin>>n>>m;
    string s[n];
    lli i,j,dp[n][m];
    memset(dp,0LL,sizeof(dp));
    dp[0][0]=1;
    
    for(i=0;i<n;i++) cin>>s[i];
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(s[i][j]=='.')
            {
                if(i>0 && s[i-1][j]=='.')
                dp[i][j]=(dp[i][j]+dp[i-1][j])%M;
                
                if(j>0 && s[i][j-1]=='.')
                dp[i][j]=(dp[i][j]+dp[i][j-1])%M;
            }
        }
    }
    
    cout<<dp[n-1][m-1];
    return 0;
}

Measured memory_bytes: 9088
/*
 * B.cpp
 *
 *  Created on: 2020/06/21
 *      Author: admin
 */


#include <iostream>
#include <algorithm>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))


using namespace std;


int main (){
	long N,K;
	cin >> N >> K;
	long array[N];
	for (int i=0; i<N; i++){
		cin >> array[i];
	}
	sort(array, array + SIZE_OF_ARRAY(array));

	long res = 0;
	for(int i=0; i<K; i++){
		res += array[i];
	}
	cout << res;
}




Measured memory_bytes: 3604
#include"bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long INT;
double PI = 3.14159265;


const long long INF = 1LL << 60;

int main() {
    double r;

    cin >> r;
    
    cout << 2.0*PI*r<< endl;

    return 0;
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
int n,arr[100009],dp[100009];
int bt(int id)
{
    int &ret=dp[id];
    if(ret!=1000000009)return ret;
    ret = 0;
    if(id+1 < n) ret = bt(id+1) + abs(arr[id]-arr[id+1]);
    if(id+2 < n) ret = min(ret,bt(id+2)+abs(arr[id]-arr[id+2]));
    return ret;
}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    for(int i=0;i<100009;i++)
    {
        dp[i]=1000000009;
    }
    cout<<bt(0);
}





Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

using DV = vector<vector<ll>>;

using pqg = priority_queue<ll,vector<ll>, greater<ll> >; // 1,3,5..
using pql = priority_queue<ll,vector<ll> >; //5, 3, 1...

using pqg_p = priority_queue<P,vector<P>, greater<P> >; // 1,3,5..
using pql_p = priority_queue<P,vector<P> >; //5, 3, 1...

#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 F first
#define S second
#define PB push_back
#define MP make_pair

#define ALL(a)  (a).begin(),(a).end()

struct edge { ll from,to,cost; };

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

  int V,E,r;

  cin >> V >> E;

  edge e[E];

  REP(i,E) {
    ll a,b,c;
    cin >> a >> b >> c;

    e[i].from = a-1;
    e[i].to = b-1;
    e[i].cost = -c;
  }




  ll d[V]; //最短


  ll inf = 100000000000000;
  
  REP(i,V) d[i] = inf;
  d[0] = 0;

  REP(v,V-1) {
    bool update = false;
    REP(i,E) {
      edge _e = e[i];
      if (d[_e.from] != inf && d[_e.to] > d[_e.from] + _e.cost) {
        d[_e.to] = d[_e.from] + _e.cost;
        update = true;
      }
    }
    if (!update) break;
  }

  bool negative[V];
  REP(v,V) negative[v] = false;

  REP(v,V) {
    REP(i,E) {
      edge _e = e[i];
      if (d[_e.from] != inf && d[_e.to] > d[_e.from] + _e.cost) {
        d[_e.to] = d[_e.from] + _e.cost;
        negative[_e.to] = true;
      }
      if(_e.from) _e.to=true;
    }
  }
      

  if (negative[V-1]) cout << "inf" << endl;
  else cout << -d[V-1] << endl;

}


Measured memory_bytes: 3656
open System

let n, m, q =
    let l = Console.ReadLine().Split(' ') |> Array.map int
    l.[0], l.[1], l.[2]

let abcd =
    [ 1 .. q ]
    |> List.map (fun _ ->
        let l = Console.ReadLine().Split(' ') |> Array.map int
        l.[0], l.[1], l.[2], l.[3])


let ans =
    let total (arr: int List) =
        [ 0 .. q - 1 ]
        |> List.map (fun i ->
            let a, b, c, d = abcd.[i]
            if arr.[b - 1] - arr.[a - 1] = c then d else 0)
        |> List.sum

    let rec dfs (l: int List) =
        if l.Length = n then
            total l
        else
            let len = l.Length

            let h =
                if len = 0 then 1 else l.[len - 1]
            [ h .. m ]
            |> List.map (fun i -> dfs (l @ [ i ]))
            |> List.max

    dfs []

ans |> printfn "%d"


Measured memory_bytes: 43152
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let line = readInts()
    let n = line[0]
    let a = line[1]
    let b = line[2]
    
    var ans = 0
    for i in 0...n {
        let x = i.description.reduce(0) { $0 + Int(String($1))! }
        if a <= x && x <= b {
            ans += i
        }
    }
    
    print(ans)
}

main()


Measured memory_bytes: 8208
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}

using namespace std;
typedef long long int llint;

int main (void) {
	string s; cin >> s;
	int count = 0;
	int result = 0;
	bool alreadyVisit = false;
	for (auto it = s.begin (); it != s.end (); it++) {
		if (*it == 'A' && !alreadyVisit) {
			count = 0;
			alreadyVisit = true;
		}

		count ++;
		if (*it == 'Z') {
			result = count;
		}
	}

	cout << result << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define oo (long long)1e18
#define ll long long
#define setdp memset(dp,-1,sizeof(dp))
const ll mod = 1e9+7;
void _IOS(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);}
#define PI 3.14159265359
int n,m;
int x,y,xs,ys;
ll a[2003];
ll b[2003];
bool vis[1009][1009];
int ans[1000004];
// 10 min for problem A : 15
// 15 min for problem B :
// 30 min for problem C :
int main()
{
   // freopen ("jumping.in","r",stdin);
   _IOS();
    cin>>n;
    if(n>=30)
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 3576
w = list(input())
j = 0
ans = 0

if(len(w)%2 != 0):
    print('No')
else:
    for i in range(len(w)):
        j = w.count(w[i])
        if(j%2 == 0 and i == len(w)-1):
            print('Yes')
            break
        elif(j%2 != 0):
            print('No')
            break

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef uint64_t ll;

ll memo[51][51];

ll nCr(int n, int k) {
  if(k < 0 || k > n) return 0;
  if(memo[n][k]) return memo[n][k];
  if(n == 0) return memo[n][k] = 1;
  if(k == 0 || k == n) return memo[n][k] = 1;
  ll res = 0;
  res = nCr(n - 1, k) + nCr(n - 1, k - 1);
  return memo[n][k] = res;
}

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  vector<ll> v(N);
  REP(i,N) cin >> v[i];
  sort(ALL(v));

  long double ave = 0;
  REP(i, A) ave += v[N - 1 - i];
  ave /= A;

  auto itr = equal_range(ALL(v), v[N - A]);
  int cnt = itr.second - itr.first;

  int used = N - (itr.second - v.begin());

  REP(i,51)REP(j,51) memo[i][j] = 0;

  ll res = 0;
  if(v[N - A] == v[N - 1]) {
    for(int i = A; i <= B; ++i) {
      res += nCr(cnt, i);
    }
  }else{
    res = nCr(cnt, A - used);
  }
  cout << fixed << setprecision(10) << ave << endl;
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 384
S = input()
P = 10**9+7
d = [[0 for j in range(4)] for i in range(len(S)+1)]

d[len(S)][3] = 1
#d[len(S)][0--2] = 0
for i in range(len(S)-1,-1,-1):
	d[i][3] = ((3 if S[i] == "?" else 1) * d[i+1][3])%P
	d[i][2] = ((3 if S[i] == "?" else 1) * d[i+1][2])%P
	d[i][2] += (1 if S[i] == "C" or S[i] == "?" else 0) * d[i+1][3]
	d[i][1] = ((3 if S[i] == "?" else 1) * d[i+1][1])%P
	d[i][1] += (1 if S[i] == "B" or S[i] == "?" else 0) * d[i+1][2]
	d[i][0] = ((3 if S[i] == "?" else 1) * d[i+1][0])%P
	d[i][0] += (1 if S[i] == "A" or S[i] == "?" else 0) * d[i+1][1]
print(d[0][0] % P)


Measured memory_bytes: 28484
/*
ID: jerrywcy
TASK: AtCoder ABC 103 Problem D
LINK: https://abc103.contest.atcoder.jp/tasks/abc103_d
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

int n,m;
pair<int,int> p[100010];

int main()
{
	cin>>n>>m;
	int i,j;
	for (i=1;i<=m;i++)cin>>p[i].first>>p[i].second;
	
	sort(p+1,p+m+1);
	
	int l=p[1].first,r=p[1].second;
	int cnt=1;
	for (i=2;i<=m;i++){
		if (p[i].first>=r){
			l=p[i].first;
			r=p[i].second;
			cnt++;
		}
		else {
			l=p[i].first;
			r=min(r,p[i].second);
		}
	}
	cout<<cnt<<endl;

	return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main(){
  string w;
  string t;
  cin >> w;
  int i;
  for(i=0;i<w.size();i++) {
    if('A'<=w[i]&&w[i]<='Z') w[i]+='a'-'A';
  }
  int o=0;
  cin >> t;
  while(t!="END_OF_TEXT"){
   
    for(i=0;i<t.size();i++) {
      if('A'<=t[i]&&t[i]<='Z') t[i]+='a'-'A';
    }
    if(w==t) o++;
    cin >> t;
  }
  cout << o << endl;
}


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

using namespace std;
typedef long long ll;

int func(){
    cin.tie(0); ios_base::sync_with_stdio(false);
	string S;
	cin >> S;

    int n = count(S.begin(), S.end(), S[0]);
    if(n != 2) return 0;
    
    if(S[0] != S[1]){
        n = count(S.begin(), S.end(), S[1]);
        if(n != 2) return 0;
    }else if(S[0] != S[2]){
        n = count(S.begin(), S.end(), S[2]);
        if(n != 2) return 0;
    }else{
        n = count(S.begin(), S.end(), S[3]);
        if(n != 2) return 0;
    }
    return 1;
}

int main(){
    if(func())
	    cout << "Yes" << "\n";
    else
        cout << "No" << "\n";
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <map>
#include <chrono>

int main() {
    int n;
    std :: cin >> n;

    int64_t arr[n];
    uint64_t prefix = 0;

    for(auto& i : arr) {
        std :: cin >> i;

        prefix ^= i;
    }

    for(auto& i : arr) i = prefix ^ i;

    std :: cout << arr[0];
    for(int i = 1 ; i < n ; i++) std :: cout << ' ' << arr[i];
    std :: cout << '\n';
}

Measured memory_bytes: 4724
#include<bits/stdc++.h>
using namespace std;
int main(){
  char c;
  cin >> c;
  if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
    cout << "vowel"<< endl;
  }
  else
    cout << "consonant" << endl;
}

Measured memory_bytes: 256