akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>

double d(int x1, int y1, int x2, int y2){
	return sqrt(pow(x2-x1,2)+pow(y2-y1,2));
}
int main(void){
	int n;
	scanf("%d",&n);
	int x[n],y[n];
	long double sum=0.0;
	for(int i=0; i<n; i++){
		scanf("%d %d",&x[i],&y[i]);
	}
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			sum+=d(x[i],y[i],x[j],y[j]);
		}
	}
	printf("%Lf\n",sum*2/n);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using ll = long long;
int main() {
    ll n;
    std::vector<ll> vec;
    std::cin >> n;
    for (ll i = 1; i*i <= n; i++) {
        if (n % i == 0) {
            ll p = n / i;
            vec.push_back(p+i-2);
        }
    }
    std::cout << (*std::min_element(vec.begin(), vec.end())) << std::endl;
}

Measured memory_bytes: 384
x,y = map(int,input().split())
count = 0
for a in range(x+1):
  if 2*a + 4*(x-a) == y:
    count += 1
    break
  else:
    count += 0
    
if count == 0 :
  print("No")
else:
  print("Yes")
    

Measured memory_bytes: 9164
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll Q;
ll q[200000], a[200000], b[200000];
const int MAX_N=300000;
map<ll,ll> f, invf;
struct BIT{
    //1-indexed
    int bit[MAX_N+1], n;
    ll bit2[MAX_N+1];
    
    void init(int x){
        n=x;
    }
    
    int sum1(int i){
        int s=0;
        while(i>0){
            s+=bit[i];
            i-=i&-i;
        }
        return s;
    }
    
    ll sum2(int i){
        ll s=0;
        while(i>0){
            s+=bit2[i];
            i-=i&-i;
        }
        return s;
    }
    
    void add(int i, int x){
        ll c=invf[i];
        while(i<=n){
            bit[i]+=x;
            bit2[i]+=c;
            i+=i&-i;
        }
    }
};

BIT bit;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>Q;
    ll c=0;
    set<ll> s;
    rep(i,0,Q){
        cin>>q[i];
        if(q[i]==1){
            cin>>a[i]>>b[i];
            s.insert(a[i]);
        }
    }
    int cnt=1;
    for(auto in: s){
        f[in]=cnt;
        invf[cnt]=in;
        cnt++;
    }
    bit.init(cnt+10);
    int res=0;
    ll sum=0;
    rep(i,0,Q){
        if(q[i]==1){
            c+=b[i];
            ll u=f[a[i]];
            bit.add(u,1);
            res++;
            sum+=a[i];
        }
        else{
            ll ng=0, ok=cnt;
            while(ok-ng>1){
                ll mid=(ok+ng)/2;
                if(bit.sum1(mid)>=(res+1)/2) ok=mid;
                else ng=mid;
            }
            ll X=bit.sum2(ok);
            cout << invf[ok]<< " "<<c+abs(X-invf[ok]*bit.sum1(ok)-(sum-X-invf[ok]*(res-bit.sum1(ok))))<<"\n";
        }
    }
}

Measured memory_bytes: 27136
#pragma GCC optimize("Ofast")
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

const long long INF_L = 1e17+7;
const long long INF_I = 1e9+7;
const long long MOD = 1e9+7;
const double EPS = 1e-8;
const double PI=acos(-1);

using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n,m;
	cin >> n >> m;
	//vector<pair<int,int>> pa(m);
	vector<pair<pair<int,int>,int>> pa(m);
	
	for(int i=0;i<m;i++){
		cin >> pa[i].first.first >> pa[i].first.second;
		pa[i].second=i;
	}
	
	sort(pa.begin(),pa.end());
	
	vector<string> ans(m,"");
	int cnt=1;
	for(int i=0;i<m;i++){
		if(pa[i].first.first==pa[i+1].first.first){
			pa[i].first.second=cnt;
			cnt++;
		}else{
			pa[i].first.second=cnt;
			cnt=1;
		}
	}
	
	for(int i=0;i<m;i++){
		string a=to_string(pa[i].first.first);
		string b=to_string(pa[i].first.second);
		for(int j=0;j<6-a.size();j++){
			ans[pa[i].second]+='0';
		}
		ans[pa[i].second]+=a;
		for(int j=0;j<6-b.size();j++){
			ans[pa[i].second]+='0';
		}
		ans[pa[i].second]+=b;
	}
	
	for(int i=0;i<m;i++){
		cout << ans[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 7368
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
const int max_w = 1e3 + 5;
const int max_p = 1e2 + 5;
char S[max_w][max_w],P[max_w][max_w],s_bit[max_w][max_w],p_bit[max_w][max_w],backup[max_w][max_w];

typedef unsigned long long ull;
const int b0 = 233;
ull b[max_p * max_p],h1[max_w][max_w],h2[max_w];



//编码转化
int get_val(char x){
    if(x>= 'A' && x <= 'Z') return x-'A';
    if( x>= 'a' && x <= 'z') return 26 + x -'a';
    if( x >= '0' && x <= '9') return 52 + x-'0';
    if(x == '+') return 62;
    if(x == '/') return 63;
}

//转化为01矩阵
void change_bit(int n, int m, char (&s)[max_w][max_w], char (&e)[max_w][max_w]){
    for(int i = 1; i <= n; i++){
        int cnt = 0;
        for(int  j = 1; s[i][j]; j++){
            int val = get_val(s[i][j]);
            for(int k = 5; k >= 0; k--){
                if(val & (1 <<k)) e[i][++cnt] = '1';
                else e[i][++cnt] = '0';
            }
        }
    }
}

int main(){
    int w, h,p;

    while(scanf("%d%d%d",&w, &h, &p) && w && h && p){
        for(int i = 1;i <= h; i++)  scanf("%s", S[i] + 1);
        for(int i = 1; i <= p; i++)  scanf("%s",P[i] + 1);
        change_bit(h,w,S,s_bit);
        change_bit(p,p,P,p_bit);


        set<ull> se;
        //预处理小图hash值 8种情况
        for(int t = 1; t <= 8; t++){

            if(t == 5){//翻转
                memcpy(backup,p_bit, sizeof(p_bit));
                for(int i = 1; i <= p; i++){
                    for(int j = 1; j <= p; j++){
                        p_bit[i][p - j + 1] = backup[i][j];
                    }
                }
            }

            ull hap = 0;
            for(int i = 1; i <= p; i++){
                for(int j = 1; j<= p; j++){
                    hap = hap *b0 + p_bit[i][j] -  '0';
                }
            }
            se.insert(hap);

            memcpy(backup,p_bit,sizeof(p_bit));
            for(int i = 1; i <= p; i++){//逆时针旋转
                for(int j = 1; j <= p; j++){
                    p_bit[p - j + 1][i] = backup[i][j];
                }
            }
        }

        int ans = 0;

        //初始化前缀哈希值
        b[0] = 1;
        for(int i = 1; i < max_p*max_p; i++){
            b[i] = b[i-1]*b0;
        }
        
        //匹配 二维哈希 计算大图hash值
        for(int i = 1; i <= h; i++){//行hash
            for(int j = 1; j <= w; j++){
                h1[i][j] = h1[i][j-1]*b0 + s_bit[i][j]-'0';
            }
        }
        for(int j = p; j <= w; j++){
            for(int i = 1; i <= h; i++){//计算匹配小矩阵的行hash值
                h2[i] = h1[i][j] - h1[i][j-p] * b[p];
            }

            for(int i = 1; i<= h;i++){//计算匹配小矩阵的列hash值
                h2[i] += h2[i-1]*b[p];
            }

            for(int i = p; i <= h; i++){
                ull ha = h2[i] - h2[i - p]* b[p*p];//小矩阵hash总值
                if(se.find(ha) != se.end()) ans++;
            }
        }
        cout << ans <<endl;

    }
    

    return 0;
}



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

int main()
{
  int N, M;
  cin >> N >> M;
  vector<bool> can_travel_to_1(N);
  vector<bool> can_travel_to_N(N);

  rep(i, M)
  {
    int a, b;
    cin >> a >> b;
    if (a == 1)
      can_travel_to_1[b - 1] = true;
    if (b == N)
      can_travel_to_N[a - 1] = true;
  }

  string ans = "IMPOSSIBLE";

  rep(i, N)
  {
    if (can_travel_to_1[i] && can_travel_to_N[i])
      ans = "POSSIBLE";
  }

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

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

using namespace std;

int main()
{
    int R;
    cin>>R;
    if(R<1200)
    {
        cout<<"ABC"<<endl;
    }
    else if(R<2800)
    {
        cout<<"ARC"<<endl;
    }
    else
    {
        cout<<"AGC"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
//If you are reading this then you are at wrong place.
#include<bits/stdc++.h>
#define mod 1000000007
#define lli long long int
using namespace std;
bool prime [1000001];
void debug(lli a){cout<<a<<endl;}
lli sieve(lli a){memset(prime,true,sizeof(prime));lli p,i;for(p=2;p*p<=a;p++){if(prime[p]==true){for(i=p*2;i<=a;i+=p)prime[i]=false;}}return 0;}
lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli find_max(lli __a,lli __b){return __a^((__a^__b) & -(__a<__b));}
lli add(lli __a,lli __b,lli MOD){lli x = (__a+__b)%MOD; return x; }
lli mul(lli a,lli b,lli MOD){lli x = (a*b)%MOD; return x; }
lli sub(lli a,lli b,lli MOD){lli x = (a-b+MOD)%MOD; return x; }
lli div(lli a,lli b,lli MOD){lli x = a;lli y = powermod(b,MOD-2,MOD);lli res = (x*y)%MOD;return res;}
int main()
{
	//ifstream cin("testcase.txt");
	//ofstream cout("output.txt");	
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);	
	cout.precision(20);
	lli t,i,j;
	//cin>>t;
	//memset(dp, -1, sizeof dp);
	t=1;
	lli counter1=0;
	while(t--)
	{
		counter1++;
		int a,b;
		cin>>a>>b;
		int c=a+b;
		if(a%3==0 || b%3==0 || c%3==0)
		{
			cout<<"Possible"<<endl;
			return 0;
		}
		cout<<"Impossible"<<endl;
		
		//cout<<"Case #"<<counter1<<" ";
		//cout<<endl;	
	}	
}


Measured memory_bytes: 892
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N+2];
        A[0] = 0;
        for (int i = 1; i < N+1; i++) {
                A[i] = sc.nextInt();
        }
        A[N+1] = 0;
        int[] abs = new int[N+1];
        for (int i = 0; i < N+1; i++) {
            abs[i] = Math.abs(A[i]-A[i+1]);
        }
        int cost = Arrays.stream(abs).sum();
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i < N+1; i++) {
            int beforeAbs = abs[i]+abs[i-1];
            int nowAbs = Math.abs(A[i+1]-A[i-1]);
            sb.append(cost-beforeAbs+nowAbs+"\n");
        }
        System.out.println(sb);
    }    
}


Measured memory_bytes: 60640
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#define MAX_N 100010
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
int b[31][MAX_N];
int main()
{
int i;
int j;
int N;
int C;
int s;
int t;
int c;
int iMax;
int iCnt;
	ios::sync_with_stdio( false );

	cin >> N;
	cin >> C;
	for( i = 1; i <= N; i++ )
	{
		cin >> s;
		cin >> t;
		cin >> c;
		for( j = s - 1; j < t; j++ )
			b[ c ][ j ] = true;
	}

	iMax = 0;
	for( j = 1; j <= MAX_N; j++ )
	{
		iCnt = 0;
		for( i = 1; i <= C; i++ )
		{
			if( b[ i ][ j ] ) iCnt++;
		}

		if( iMax < iCnt ) iMax = iCnt;
	}

	cout << iMax << endl;

	return 0;
}


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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "

string toLower(string s) {
  string ans = s;
  rep0(i, s.size()) {
    ll temp = s[i] - 'A';
    if (temp >= 0 && temp <26) {
      ans[i] = s[i] - 'A' + 'a';
    }
  }
  return ans;
}

int main() {
  string W;
  cin >> W;
  W = toLower(W);

  int ans = 0;
  while (true) {
    string T;
    cin >> T;
    if (T == "END_OF_TEXT") break;

    T = toLower(T);
    if (T == W) ans++;
  }

  cout << ans << BR;
  return 0;
}


Measured memory_bytes: 3132
N = int(input())

X = [3, 5, 7, 11, 13, 17]
D = []

for i in range(len(X)-2):
  for j in range(i+1, len(X)-1):
    t = X[i]*X[i]*X[i]*X[j]
    if t <= N:
      D.append(t)
    for k in range(j+1, len(X)):
      t = X[i]* X[j] * X[k]
      if t <= N:
        D.append(t)
      else:
        break
    
print(len(D))


Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>

int main(void)
{
    int num[5];
    int tmp;
    int i, j;

    memset(num,0,sizeof(num));

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

/*
3 6 9 7 5

6 3 9 7 5
9 3 6 7 5
9 3 6 7 5
9 3 6 7 5

9 6 3 7 5
9 7 3 6 5
9 7 3 6 5

9 7 6 3 5
9 7 6 3 5

9 7 6 5 3
 */
   
    for (i = 0;i < 4;i++){
        for (j = i + 1;j < 5;j++){
            if (num[i] < num[j]){                
                tmp = num[i];
                num[i] = num[j];
                num[j] = tmp;
            }
        }
    }

    for (i = 0;i < 4;i++){
        printf("%d ", num[i]);
    }

    printf("%d\n", num[4]);

    return 0;
}

Measured memory_bytes: 0
n, m ,c = map(int, input().split())
b = list(map(int, input().split()))
a = []
for i in range(n):
    aa = list(map(int, input().split()))
    a.append(aa)

s = 0
cnt = 0
for i in range(n):
    for j in range(m):
        s += a[i][j]*b[j]
    if s + c > 0:
        cnt += 1
        s = 0
    else:
        s = 0

print(cnt)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define MOD 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define all(c) (c).begin(),(c).end()
#define ss second
#define MAXX 9000000000000000000
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> > 
#define vvpi vector<vector<pair<int,int> > >
#define Inp(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define Out(a,n,ch) for(int i=0;i<n;i++)cout<<a[i]<<ch;cout<<endl;

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	
	int n,x,t;
	cin>>n>>x>>t;
	cout<<(int)(t*(ceil(float(n)/x)));
	return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD = 1e9 + 7;
const int N = 52;
vector<int> ve;
char ar[N + 5];
int n;
int main(){
	scanf("%d", &n);
	scanf("%s", ar);
	for(int i = 0;i < n;){
		if(i < n - 1 && ar[i] == ar[i + 1]){
			ve.push_back(2);
			i += 2;
		}
		else{
			ve.push_back(1);
			i += 1;
		}
	}
	LL now = 3;
	for(int i = 1;i < (int)ve.size(); ++i){
		if(ve[i] == 2 && ve[i-1] == 2){
			now *= 3;
		}
		else if(ve[i] == 2 && ve[i-1] == 1){
			now *= 2;
		}
		else if(ve[i] == 1 && ve[i-1] == 1){
			now *= 2;
		}
		now %= MOD;
	}
	if(ve[0] == 2){
		now <<= 1;
		now %= MOD;
	}
	printf("%lld\n", now);
	return 0;
}

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

using namespace std;
const int N = 1e5 + 5;
int dp[N][2];
vector <int> g[N];

void dfs(int v, int p = 0) {
    for (int u : g[v]) if (u != p) dfs(u, v), dp[v][0] += dp[u][1];
    for (int u : g[v]) if (u != p) dp[v][1] = max(dp[v][1], dp[v][0] - dp[u][1] + dp[u][0] + 1);
}
int main() {
    int n; cin >> n;
    if (n % 2 == 1) return cout << "First\n", 0;
    for (int i = 0; i < n - 1; i++) {
        int u, v; cin >> u >> v;
        g[u].push_back(v), g[v].push_back(u);
    }
    dfs(1);
    if (dp[1][1] == n/2) cout << "Second\n";
    else cout << "First\n";

    return 0;
}


Measured memory_bytes: 6656
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let a: i64 = read();
    let b: i64 = read();
    let c: i64 = read();
    if c <= a + b {
        println!("No");
    } else if 2 * (a * b + b * c + c * a) < a.pow(2) + b.pow(2) + c.pow(2) {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
import Data.Maybe
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- スペース区切り整数の入力
    [a, b, c] <- words <$> getLine
    -- 出力
    putStrLn . show $ (if b == "+" then (read a) + (read c) else (read a) - (read c))


Measured memory_bytes: 508
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<cmath>
using namespace std;
typedef long long LL;
#define maxn (50002)
int seq[3],k;
int main()
{
    cin>>seq[0]>>seq[1]>>seq[2];
    sort(seq,seq+3);
    cin>>k;
    while(k--) seq[2]*=2;
    cout<<seq[0]+seq[1]+seq[2]<<endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/ruby
Z=10**9+7
def d(x,y) x.zip(y).reduce(0){|s,(a,b)|s+a*b} end
def mul(x,y)
	y=y.transpose
	[[d(x[0],y[0])%Z,d(x[0],y[1])%Z],[d(x[1],y[0])%Z,d(x[1],y[1])%Z]]
end
def pow(x,y)
	z=1
	while y>0
		z=z*x%Z if y%2>0
		x=x*x%Z
		y/=2
	end
	z
end
H,W,K=gets.split.map(&:to_i)
if K==0
	p 1
	exit
end
K-=1
M=$<.map{|e|e.chomp.chars}
c=M.count{|s|s[0]=='#'&&s[-1]=='#'}
d=M.transpose.count{|s|s[0]=='#'&&s[-1]=='#'}
if c>0&&d>0
	p 1
	exit
end
a=b=0
M.each{|s|W.times{|i|
	a+=1 if s[i]=='#'
}}
if c==0&&d==0
	p pow(a,K)
	exit
end
if d>0
	c,d=d,c
	M=M.transpose
	H,W=W,H
end
M.each{|s|W.times{|i|
	b+=1 if i<W-1&&s[i]=='#'&&s[i+1]=='#'
}}

#848924
a=a*pow(c,Z-2)%Z
b=b*pow(c,Z-2)%Z
if a==1
	B=(1-b*(K%Z))%Z
else
	C=(1-b*pow(a-1,Z-2))%Z*pow(a,K)%Z
	B=(C+b*pow(a-1,Z-2))%Z
end
p B*pow(c,K)%Z

Measured memory_bytes: 97020
#include <iostream>    // cin, cout
#include <string>    // string, stoi, to_string
#include <algorithm>    // sort, lower_bound, heap, min, next_permutation 
#include <functional>    // greater, less
#include <vector>    // vector
#include <stack>    // stack
#include <queue>    // queue
#include <list>    // list
#include <map>    // map
#include <set>    // set
#include <tuple>    // tuple
#include <bitset>    // bitset
#include <cstdio>  // fopen, printf, scanf, puts
#include <cmath>    // sin, exp, log, pow, sqrt
#include <iomanip>    // setfill, setbase

using namespace std;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30));
const long long linf = (1LL<<60);

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    n %= 100;
    n %= 10;
    if(n == 3) cout << "bon" << endl;
    else if(n==0 || n==1 || n==6 || n==8) cout << "pon" << endl;
    else cout << "hon" << endl;
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<ll,ll>;
#define For(i,a,b)  for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF (2e9)
#define EPS (1e-6)
#define int ll
#ifdef LOCAL_TEST
#define debug(...) do{\
	cerr<<__PRETTY_FUNCTION__<<" - "<<__LINE__<<\
	" : ("#__VA_ARGS__<<") = ";\
	_OUT(__VA_ARGS__);\
}while(0)
template<typename T>void _OUT(T x){cerr<<x<<endl;}
template<typename T,typename...I>void _OUT(T x,I ...tail){cerr<<x<<", ";_OUT(tail...);}
#else
#define debug(...)
#endif
void INIT(){
#ifdef LOCAL_TEST
	freopen("D:\\input.in","r",stdin);
	freopen("D:\\output.out","w",stdout);
	freopen("D:\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
}

ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll fpow(ll b,ll p){
	b%=MOD;
	ll ans=1;
	while(p>0){
		if(p&1) ans=(ans*b)%MOD;
		p/=2;
		b=(b*b)%MOD;
	}
	return ans;
}

int32_t main() {
	INIT();
	//code...
	int n; cin>>n;
	ll d; cin>>d; d=d*d;
	ll x,y,ans=0;
	while(n--){
		cin>>x>>y;
		if(x*x+y*y<=d) ans++;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 123, MOD = 1e9 + 7;
int n, a[N], inv[N], rev[N], fact[N], used[N];

int C(int x, int y) {
	if (x > y) return 0;
	return ((ll)fact[y] * rev[y - x] % MOD) * rev[x] % MOD;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	inv[1] = rev[0] = fact[0] = 1;
	for (int i = 1; i < N; i++) {
		if (i > 1) {
			int x = (i - MOD % i) % i;
			inv[i] = (ll)inv[x] * ((MOD + x) / i) % MOD;
		}
		rev[i] = (ll)rev[i - 1] * inv[i] % MOD;
		fact[i] = (ll)fact[i - 1] * i % MOD;
	}
	cin >> n;
	int sides = -1;
	for (int i = 1; i <= n + 1; i++) {
		cin >> a[i];
		if (used[a[i]]) {
			sides = (n + 1) - i + used[a[i]] - 1;
		}
		used[a[i]] = i;
	}
	for (int i = 1; i <= n + 1; i++) {
		cout << (C(i, n + 1) - C(i - 1, sides) + MOD) % MOD << '\n';
	}
}


Measured memory_bytes: 5544
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  
  if(b-c>=0) co("delicious");
  else if(a+b-c>=0) co("safe");
  else co("dangerous");
  
  return 0;
}


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

struct P
{
    int x,y;

    bool operator<(const P &a)const{
        if(x!=a.x)
              return x>a.x;
        return y>a.y;
    }

};

vector<int> v[111111],v1;

//bitset<4001000> b;
int i,n,d,m,k,a,b,c,h;

int o[1];
int l[3111][3115];
int j[1];
int e;


//int dx[10]={2,2,-2,-2,1,1,-1,-1},dy[10]={1,-1,1,-1,2,-2,2,-2};

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[311111];
stack<int> s;
//set<int> s[222][22];
//priority_queue<P> q;
queue<int> q;
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
/*
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
unordered_map<long long, int, custom_hash> safe_map;
*/
//list<int> l;

string r,r1;
//char r[2];
//deque<int> de;
//srand((int)time(NULL));
/*bool as(P a,P b)
{
    if(a.x!=b.x)
    return a.x<b.x;
    return a.y<b.y;
}*/



bool as(P a,P b)
{
    if(a.x!=b.x)
        return a.x<b.x;
    return a.y<b.y;

}

int f(int n,int m)
{
    if(n==r.size()||m==r1.size()) return 0;
    if(l[n][m]>=0) return l[n][m];
    l[n][m]=max(f(n+1,m),f(n,m+1));
    if(r[n]==r1[m]) l[n][m]=max(l[n][m],f(n+1,m+1)+1);
    return l[n][m];
}

void g(int n,int m)
{
    if(n==r.size()||m==r1.size()) return;
    if(r[n]==r1[m]&&(f(n+1,m+1)+1>f(n+1,m)&&f(n+1,m+1)+1>f(n,m+1)))
    {
        printf("%c",r[n]);
        g(n+1,m+1);
        return;
    }
    if(f(n+1,m)>f(n,m+1)) g(n+1,m);
    else g(n,m+1);
}

int main()
{
    memset(l,-1,sizeof(l));
    cin>>r;
    cin>>r1;
    g(0,0);
}





Measured memory_bytes: 41600
import java.io.BufferedReader
import java.util.*

fun main() = abc175b()

@OptIn(ExperimentalStdlibApi::class)
fun abc175b() = SimpleFastIOWithToken_abc175b().exec {
    val n = readInt()
    val lList = LongArray(n) { readLong() }.sortedArray()

    var answer = 0L

    for (i in 0 until n) for (j in i + 1 until n) for (k in j + 1 until n) {
        val a = lList[i]
        val b = lList[j]
        val c = lList[k]
        if (a + b > c && a != b && b != c) answer++
    }

    println(answer)
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType", "MemberVisibilityCanBePrivate", "ClassName")
private class SimpleFastIOWithToken_abc175b(private val separator: String = System.lineSeparator()) {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private var st: StringTokenizer = StringTokenizer("")
    private val sb: StringBuilder = StringBuilder()
    private fun prepareNext() = run { if (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) }

    fun readString(): String = run { prepareNext() }.run { st.nextToken() }
    fun readInt(): Int = Integer.valueOf(readString())
    fun readLong(): Long = java.lang.Long.valueOf(readString())

    fun println(): Unit = run { sb.append(separator) }
    fun print(any: Any): Unit = run { sb.append(any) }
    fun println(any: Any): Unit = run { sb.append(any.toString() + separator) }

    fun exec(action: SimpleFastIOWithToken_abc175b.() -> Unit) {
        var t: Throwable? = null
        Thread(null, { action() }, "solve", 128 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, t1 -> t = t1 } }
            .apply { start() }.join()
        t?.let { throw it }
        kotlin.io.print(sb)
    }

    fun readLine(): Nothing = error("readLine is disabled.")
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 38684
// This code wrote by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
using namespace std;
template <class t> inline void read(t &s)
{
	s=0;
	reg int f=1;
	reg char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	s*=f;
	return;
}
signed main(void)
{
	string s;
	int k;
	cin>>k>>s;
	if((int)s.length()<=k)
		cout<<s<<endl;
	else
	{
		for(int i=0;i<k;++i)
			cout<<s[i];
		cout<<"..."<<endl;
	}
	return 0;
}




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


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
using namespace std;
int main() {
	vector<long long int>a(4);
	long long int m = 0;
	for (int i = 0; i < 4; i++)cin >> a[i];
	m = a[0] * a[2];
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			if (a[i] * a[j + 2] > m) {
				m = a[i] * a[j + 2];
			}
		}
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int N; cin >> N;
    int x[N], y[N];
    rep(i, N) {
        cin >> x[i] >> y[i];
    }
    map<Pint, int>m;
    int maxv = 0;
    rep(i, N) {
        rng(j, i + 1, N) {
            m[mp(x[j] - x[i], y[j] - y[i])]++;
            m[mp(x[i] - x[j], y[i] - y[j])]++;
            maxv = max(maxv, m[mp(x[j] - x[i], y[j] - y[i])]);
            maxv = max(maxv, m[mp(x[i] - x[j], y[i] - y[j])]);
        }
    }
    cout << N - maxv << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main(){
	rep(i, 9) rep(j, 9) printf("%dx%d=%d\n", i + 1, j + 1, (i + 1) * (j + 1));
	
	return 0;
}

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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int main(){
	string s;
	cin >> s;
	int l = 0;
	for(int i = 0; i < s.length(); i++) l += (s[i] == 'x');
	printf(l < 8 ? "YES" : "NO");
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
i = 1
if 0 in a:
    i = 0
else:
    for j in range(n):
        if i >= 0:
            i = i * a[j]
        if i > 10 ** 18:
            i = -1
print(int(i))

Measured memory_bytes: 21632
x, y = map(lambda x: int(x), input().split(' '))

mass = []

if(y > 0):
    mass = list(map(lambda x: int(x), input().split(' ')))

d = 1000
j = -1

for i in range(0, 102):
    if(not i in mass):
        if(abs(x - i) < d):
            d = abs(x - i)
            j = i

print(j)

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

int main() {
  int N,K;
  cin >> N >> K;
  int d = 0;
  
  for (int i = 0;i < N;i++) {
    int x;
    cin >> x;
    
    if (x * 2 < K) {
      d += x;
    }
    
    else {
      d += K - x;
    }
    
  }
  
  cout << d * 2 << endl;
 
}


Measured memory_bytes: 256
K = int(input())
a = ['1','2','3','4','5','6','7','8','9']
if K <= 9:
    print(K)
    exit()


cnt = 9
while True:
    a_tmp = []
    for s in a:
        for t in range(max(0, int(str(s[-1])) - 1), min(9, int(str(s[-1])) + 1) + 1):
            a_tmp.append(s+str(t))
            cnt += 1
            if cnt == K:
                print(s+str(t))
                exit()
    a = a_tmp




Measured memory_bytes: 8596
#include <iostream>

int main() {
  uint32_t A = 0, B = 0, C = 0, X = 0, Y = 0;
  std::cin >> A >> B >> C >> X >> Y;

  uint32_t price = 0;
  uint32_t min_vol = (X <= Y) ? X : Y;
  if (C * 2 <= A + B) {
    price += min_vol * C * 2;
    X -= min_vol;
    Y -= min_vol;
  }
  price += X * (C * 2 <= A ? C * 2 : A) + Y * (C * 2 <= B ? C * 2 : B);

  std::cout << price << std::endl;

  return 0;
}

Measured memory_bytes: 256
def m(L,R):
 T=[]
 for l in L[::-1]:
  while R and R[-1]>l:T+=[R.pop()]
  T+=[l]
 return R+T[::-1]
def d(A):
 l=len(A);global c;c+=l
 s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A
c=0
n=int(input())
print(*d(list(map(int,input().split()))))
print(c-n)


Measured memory_bytes: 61648
#include <bits/stdc++.h>
#define INT(name) int name; scanf("%d",&name);
#define VINT(name,n) vector<int> name(n); for(int i = 0;i < n;i++) scanf("%d",&name[i]);

using namespace std;

int main(int argc, char const *argv[]){
	for(int i = 1;i <= 9;i++){
		for(int j = 1;j <= 9;j++){
			printf("%dx%d=%d\n",i,j,i*j);
		}
	}
	return 0;
}

Measured memory_bytes: 1096
#include <stdio.h>

int main(void)
{
    int a, b, c, i, count;
    count = 0;
    
    scanf("%d%d%d", &a, &b, &c);
    
    for(i = a; i <= b; i++)
    {
        if(c % i == 0)
        {
            count++;
        }
    }
    
    printf("%d\n", count);
    
    return 0;
}

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

#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ll long long int
 
using namespace std;


int freq[100001];
	     
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	ll sum=0;
	int a[n];
	for(int i=0;i<n;i++)
	{
	     cin>>a[i];
	     sum+=a[i];
	     freq[a[i]]++;
	}
	int q;
	cin>>q;
	while(q--)
	{
	     int b,c;
	     cin>>b>>c;
	     int cnt=freq[b];
	     freq[b]-=cnt;
	     freq[c]+=cnt;
	     ll res=sum;
	     res+=((c*cnt)-(b*cnt));
	     cout<<res<<"\n";
	     sum=res;
	}
	return 0;
}

Measured memory_bytes: 4420
N = gets.to_i

a = gets.split.map(&:to_i)
diff = []

N.times do |i|
  diff << a[i] - (i + 1)
end

diff.sort!

def calc(d, b)
  sum = 0
  d.each_with_index do |dd, i|
    sum += (dd - (b + (i + 1))).abs
  end
  sum
end

if diff.size.odd?
  puts calc(a, diff[diff.size / 2])
else
  n1 = calc(a, diff[diff.size / 2])
  n2 = calc(a, diff[diff.size / 2 - 1])
  puts [n1, n2].min
end


Measured memory_bytes: 19904
#include <bits/stdc++.h>
#define sc scanf
#define ll long long
#define pb push_back
#define TIME ios_base::sync_with_stdio(0)
using namespace std;

const ll INF = 1e16 + 1;
const ll N = 2e5 + 5;
const ll mod = 1e9 + 7;
const long double eps = 1E-7;

int res;
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    for ( int i=0; i<s.size(); i++ ){
        if ( i == n ){
            cout << "...";
            break;
        }
        cout << s[i];
    }
}


Measured memory_bytes: 3628
/*****/

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

//#define int long long

using namespace std;
using ll = long long;
using ld = long double;
using vecll = vector<ll>;

#define nextline() (std::cerr << "\n")
#define debug(x) (#x " : " + (x))
#define debug_cout(x) (std::cerr << #x << " : " <<  (x) << "\n")
#define debug_tabcout(n, x) (std::cerr << strMulti("\t",n) << #x << " : " <<  (x) << "\n")
#define debug_headcout(h, x) (std::cerr << h << " : " <<  (x) << "\n")
#define debug_tabheadcout(n, h, x) (std::cerr << strMulti("\t",n) << h << " : " <<  (x) << "\n")

#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 rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
constexpr int INF = 2000000100;
constexpr ll DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> T divup(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
#define diup(a, b) (a % b == 0 ? a / b : a / b + 1)
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
template<class T> T math_C(T m, T n) { T ret = mathP(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
template<class T> bool compare_by_b(pair<T, T> a, pair<T, T> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }
template<class T> T math_gcd(T a, T b) { a = abs(a); b = abs(b); if (a < b) { std::swap(a, b); } T tmp; while (b != 0) { tmp = b; b = a % b; a = tmp; } return a; }
template<class T> T math_lcm(T a, T b) { a = abs(a); b = abs(b); if (a > b) { std::swap(a, b); } if (a == 1) { return b; } T i = a; while (i % b != 0) { i += a; } return i; }

/*****/

void Main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a <= c && c <= b)
		cout << "Yes";
	else
		cout << "No";
}

/*****/

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

	std::cout << std::fixed << std::setprecision(10);


	/*
	while (true)
	{
		Main();
		cout << endl;
	}
	//*/


	Main();

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
#define rep(i,a,b) for(re int i=a,i##end=b; i<=i##end; i++)
#define drep(i,a,b) for(re int i=a,i##end=b; i>=i##end; i--)
#define repp(i,a,b) for(re int i=a,i##end=b; i<i##end; i++)
#define drepp(i,a,b) for(re int i=a,i##end=b; i>i##end; i--)
#define Erep(i,x) for(int i=head[x]; ~i; i=Edge[i].nxt)
#define ll long long
#define debug(x) cerr<<#x<<" = "<<x<<endl
#define lowbit(x) (x&-x)
#define ms(x,a) memset(x,a,sizeof x)
using namespace std;
template <class T> inline bool Max(T &x, T y){
	return x<y?x=y,1:0;
}
template <class T> inline bool Min(T &x, T y){
	return x>y?x=y,1:0;
}
template <class T> inline T rd() {
	static char ch;static bool neg;
	static T x=0;
	for(ch=neg=0;ch<'0' || '9'<ch;neg|=ch=='-',ch=getchar());
	for(x=0;'0'<=ch && ch<='9';(x*=10)+=ch-'0',ch=getchar());
	return x=(neg?-x:x);
}
const int mod=1e9+7,oo=1e9;

int main(){
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
	int a=rd<int>(),b=rd<int>(),c=rd<int>();
	if(c>=a-b) printf("%d\n",c-(a-b));
	else puts("0");
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
using namespace std;

int main(void){
        int i,j;
        string s;
        int len;
        int a[2019];
        int d[1344];
        long long ans, ll;

        cin >> s;
        len = s.size();
        reverse(s.begin(), s.end() );
//printf("done\n");
        d[0] = 1;
        for(i=1;i<1344;i++){
                d[i] = (d[i-1]*10)%2019;
        }
//printf("d[5] = %d\n", d[5]);
        for(i=0;i<2019;i++){
                a[i] = 0;
        }
        
        j = s[0]-'0';
        a[j]++;
//printf("len = %d\n",len);
        for(i=1;i<len;i++){
                j = (j + (s[i]-'0')*d[i%1344]) % 2019;
                a[j]++;
//  printf("a[%d]++, i%1344 = %d, s[i]*d[i%1344]=%d*%d\n", j, i%1344, s[i], d[i%1344]);              
        }
        a[0]++;
        ans = 0;
        for(i=0;i<2019;i++){
                ll = a[i];
                ans += (ll-1) * ll /2;
        }
        printf("%lld\n", ans);
        return 0;
}


Measured memory_bytes: 3856
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var wi = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var min = 100;
            var aggregated = new int[n + 1];
            for (var i = 1; i <= wi.Length; i++)
            {
                aggregated[i] = wi[i - 1] + aggregated[i - 1];
            }

            var index = 0;
            while (true)
            {
                var left = aggregated[index];
                var right = aggregated[aggregated.Length - 1] - aggregated[index];
                min = Math.Min(min, Math.Abs(right - left));
                if (left >= right) break;
                index++;
            }
            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 13396
//R<3S
#include <bits/stdc++.h>
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first 
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(x) for(auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define invect(data,n) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);}
#define inset(data,n) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);}
#define ll long long
#define int long long
#define ld long double 
#define pii std::pair<int, int> 
#define pll std::pair<ll, ll>  
#define vi vector<int>  
#define vl vector<ll>
#define vvi vector<vi > 
#define vii vector<pii >
#define mii map<int,int>
#define mll map<ll,ll>
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


using namespace std;

void solve()
  {

	int a,b,n;
	cin>>a>>b>>n;
	int x=min(b-1,n);
	int ans=(a*x);
	ans/=b;
	cout<<ans;
	
  }



signed main()
{
   FAST
   int t;
   t=1;
   //cin>>t;
   while(t--)
    {
        solve();
    }


   return 0;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << "=" << x << ","
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b-1);i>=a;--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define lowbit(x) x&(-x)
const int N = 20000;
const int M = 1e9+7;


ll f(ll a,ll b,ll x){
	return a*x/b-a*(x/b);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
	ll a,b,n;
	cin>>a>>b>>n;
	ll ans=0;
	// for (int i=0; i<=n; i++){
	// 	cout<<f(a,b,i)<<endl;
	// }
	ans=f(a,b,min(b-1,n));
	ans=max(ans,f(a,b,0LL));
	cout<<ans;
}


Measured memory_bytes: 3632
n,W = map(int, input().split())
wv = []
w1,v1 = map(int, input().split())
wv.append([0,v1])
for i in range(n-1):
  w,v = map(int, input().split())
  w -= w1
  wv.append([w,v])
dp = [[[-(10 ** 18)] * 301 for j in range(n+1)] for i in range(n+1)]
dp[0][0][0] = 0
for key,(wi,vi) in enumerate(wv):
  for num in range(key+1):
    for weight in range(3 * key + 1):
      dp[key+1][num][weight] = max(dp[key+1][num][weight],dp[key][num][weight])
      dp[key+1][num+1][weight+wi] = max(dp[key+1][num+1][weight+wi],dp[key][num][weight] + vi)
ans = 0
for k,i in enumerate(dp):
  for num,v in enumerate(i[:k+1]):
    res = W - num * w1
    if res < 0:
      continue
    ans = max(ans,max(v[:min(res+1,301)]))
print(ans)

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

int main()
{
  int N;
  cin >> N;
  if (N % 10 == 3) cout << "bon" << endl;
  else if (N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8) cout << "pon" << endl;
  else cout << "hon" << endl;
}


Measured memory_bytes: 3636
import enum


def main():
    N = int(input())
    dp = [[] for _ in range(N)]
    for i in range(N):
        abc = list(map(int, input().split()))
        if i == 0:
            dp[0] = abc
        else:
            for k, v in enumerate(abc):
                vals = []
                for j in range(3):
                    if k != j:
                        vals.append(dp[i-1][j])
                dp[i].append(v + max(vals))

    print(max(dp[-1]))


if __name__ == '__main__':
    main()


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

int main() {
    int N;
    while (cin >> N, N) {
        for (int i = 0; i < N; i++) {
            int x, y, z;
            cin >> x >> y >> z;
            if (max(max(x, y), z) == 100) {
                cout << "A" << endl;
            }
            else if ((x + y) / 2 >= 90) {
                cout << "A" << endl;
            }
            else if ((x + y + z) / 3 >= 80) {
                cout << "A" << endl;
            }
            else if ((x + y + z) / 3 >= 70) {
                cout << "B" << endl;
            }
            else if ((x + y + z) / 3 >= 50 && max(x, y)>=80) {
                cout << "B" << endl;
            }
            else {
                cout << "C" << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3092
#include "bits/stdc++.h"

#define pb push_back
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

using namespace std;
using ll = long long;

void solve() {
}

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

  int n;
  int dplen = 0;
  int dp[kMax5];
  vector<int> a;
  cin >> n;
  rep(i, 0, n - 1) {
    int a_i;
    cin >> a_i;
    a.pb(kInfI - a_i);
  }

  mmst(dp);

  rep(i, 0, n - 1) {
    int idx = upper_bound(dp, dp + dplen, a[i]) - dp;
    dp[idx] = a[i];
    if (idx + 1 > dplen) {
        dplen = idx + 1;
    }
  }

  cout << dplen << endl;

  return 0;
}


Measured memory_bytes: 1144
#include <iostream>
#include <map>
using namespace std;
int main(){
        int N,min=10000000,max=0;
        cin >> N;
        map<int,int> counter;
        for(int i=0 ; i<N ; i++ ){
                int x;cin >> x;
                counter[x]++;
                counter[x-1]++;
                counter[x+1]++;
                if(min>x)min=x;
                if(max<x)max=x;
        }
        int count=0;
        for(int i=min-1 ; i<max+1 ; i++ ){
                if(count<counter[i])
                        count=counter[i];
        }
        cout << count << endl;
}

Measured memory_bytes: 4992