akhauriyash/Code-Regression huggingface dataset:
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1] * n

  def find(self, x):
    if self.parents[x] < 0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self, x, y):
    x = self.find(x)
    y = self.find(y)

    if x == y:
      return

    if self.parents[x] > self.parents[y]:
      x, y = y, x

    self.parents[x] += self.parents[y]
    self.parents[y] = x

  def size(self, x):
    return -self.parents[self.find(x)]

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

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()}

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
  
N, M = map(int, input().split())
uf = UnionFind(N)

for _ in range(M):
  x,y,z = map(int, input().split())
  uf.union(x-1,y-1)
  
print(uf.group_count())

Measured memory_bytes: 81732
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct modint{
    using i64=int_fast64_t;
    i64 a;
    static constexpr i64 MOD=1e9+7;
    modint(){a=0;}
    modint(i64 a_){
        a=a_%MOD;
        if(a<0) a+=MOD;
    }
    modint inv()const{
        i64 n=1,m=MOD-2,A=a;
        while(m){
            if(m&1)(n*=A)%=MOD;
            (A*=A)%=MOD;
            m>>=1;
        }
        modint y(n);
        return y;
    }
    bool operator==(const modint& x){
        return a==x.a;
    }
    bool operator!=(const modint& x){
        return a!=x.a;
    }
    modint& operator=(const modint& x){
        a=x.a;
        return *this;
    }
    modint operator+(const modint& x){
        modint y;
        y.a=a+x.a;
        if(y.a>MOD) y.a-=MOD;
        return y;
    }
    modint operator-(const modint& x){
        modint y;
        y.a=a-x.a;
        if(y.a<0) y.a+=MOD;
        return y;
    }
    modint operator*(const modint& x){
        modint y;
        y.a=(a*x.a)%MOD;
        return y;
    }
    modint operator/(const modint& x){
        modint y;
        y.a=(a*x.inv().a)%MOD;
        return y;
    }
    modint& operator+=(const modint& x){
        a+=x.a;
        if(a>=MOD) a-=MOD;
        return *this;
    }
    modint& operator-=(const modint& x){
        a-=x.a;
        if(a<0) a+=MOD;
        return *this;
    }
    modint& operator*=(const modint& x){
        (a*=x.a)%=MOD;
        return *this;
    }
    modint& operator/=(const modint& x){
        (a*=x.inv().a)%=MOD;
        return *this;
    }
};
istream& operator>>(istream &in,modint& x){
    int_fast64_t a_;
    in>>a_;
    modint y(a_);
    x=y;
    return in;
}
ostream& operator<<(ostream &out,const modint& x){
    out<<x.a;
    return out;
}
modint pwr(int_fast64_t a,int_fast64_t b){
    modint _;
    int_fast64_t n=1,A=a;
    while(b){
        if(b&1) (n*=A)%=modint::MOD;
        (A*=A)%=modint::MOD;
        b>>=1;
    }
    _.a=n;
    return _;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n;
    in>>n;
    vector<ll> a(n);
    for(auto&i:a) in>>i;
    ll c;
    modint ans{};
    fr(j,60){
        c=0;
        fr(i,n){
            if((a[i]>>j)&1) ++c;
        }
        ans+=modint(2*c*(n-c))*modint(1ll<<j);
    }
    ans/=2;
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<queue>
#include<vector>
#include<tuple>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()
bool comparator(P a, P b) {
	return a.first / a.second < b.first / b.second;
}

int main() {
	string s;
	cin >> s;
	int ans = 0;
	int max = 0;
	rep(i, 3) {
		if (s[i] == 'R') {
			ans++;
			max = ans;
		}
		if (s[i] == 'S') {
			ans = 0;
		}

	}
	cout << max << endl;
}


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

int main() {
  char s;
  cin >> s;
  if(s=='a' || s=='i' || s=='u' || s=='e' || s=='o'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
}


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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
const long long INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << (a ^ b ^ c) << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int n, pts;
  cin >> n >> pts;
  vector<int> x_lst, y_lst;
  vector<int> x_sorted, y_sorted;
  for (int i=0; i<n; i++){
    int x, y;
    cin >> x >> y;
    x_lst.push_back(x);
    y_lst.push_back(y);
    x_sorted.push_back(x);
    y_sorted.push_back(y);
  }
  sort(x_sorted.begin(), x_sorted.end());
  sort(y_sorted.begin(), y_sorted.end());
  int minX, minY, maxX, maxY;
  long long min_area = -1ll; // infinity
  // sort pairs of x and y's by other coordinate
  for (int x1=0; x1<n; x1++){
    for (int y1=0; y1<n; y1++){
      for (int x2=x1+1; x2<n; x2++){ // x1+1 because it's not the same point
        for (int y2=y1+1; y2<n; y2++){
          minX = x_sorted[x1]; // lst needs to be sorted so maxX > minX
          minY = y_sorted[y1];
          maxX  = x_sorted[x2];
          maxY = y_sorted[y2];
          int points = 0; 
          for (int i=0; i<n; i++){
            if (x_lst[i] >= minX && x_lst[i] <= maxX){
              if (y_lst[i] >= minY && y_lst[i] <= maxY){
                points++;
              }
            }
          }

          long long area = (long long)(maxX-minX)*(maxY-minY);
          if (points >= pts){
            if (min_area == -1){
              min_area = area;
            }else{
              if (area < min_area){
                min_area = area;
              }
            }
          }
        }
      }
    }
  }
  cout << min_area;
  return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)
i = 0
T = []
while i <= N-2:
    if S[i] == 'B' and S[i+1] == 'C':
        T.append('D')
        i += 1
    else:
        T.append(S[i])
    i += 1

T = "".join(T)

N = len(T)
ans = 0
l = 0
while l < N:

    if T[l] == 'B' or T[l] == 'C':
        l += 1
        continue
    
    r = l
    tmp = []
    while r < N and (T[r] == 'A' or T[r] == 'D'):
        tmp.append(T[r])
        r += 1
    
    M = len(tmp)
    D_count = [0]*(M+1)
    for i in range(M-1, -1, -1):
        D_count[i] = D_count[i+1]
        if tmp[i] == 'D':
            D_count[i] += 1
    
    for i in range(M):
        if tmp[i] == 'A':
            ans += D_count[i]
    
    if r == N:
        break
    else:
        l = r+1

print(ans)





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


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    REP(i, 1, 50000) {
        if ((int)(i * 1.08) == N) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char c[101];int k=0;
	gets(c);
	int len=strlen(c);
	for(int i=0;i<=len-1;i++)
	{
		if(c[i]=='C')
		k=1;
		if(c[i]=='F'&&k==1)
		{
			printf("Yes");
			return 0;
		}
	}
		
	printf("No");
	return 0;
		
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int a, b, c;
    cin >> a >> b >> c;

    if ((a < c && b > c) || (a > c && b < c)) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 256
h, n = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]

dp = [0] * (h+max(a for a,b in ab))
for i in range(1, len(dp)):
    dp[i] = min(dp[i-a]+b for a, b in ab)
print(min(dp[h:]))


Measured memory_bytes: 3664
#include <cstring>
#include <algorithm>
#include <cstdio>

using std::sort;
const int N = 100010;
int _w;

int n, l, t, x[N], w[N], y[N];

bool all2() {
	for( int i = 1; i <= n; ++i )
		if( w[i] == 1 ) return false;
	return true;
}
void solve2() {
	t %= l;
	for( int i = 1; i <= n; ++i )
		printf( "%d\n", (x[i] - t + l) % l );
}

void solve1( int s ) {
	int go = 0;
	for( int i = 1; i <= n; ++i )
		if( w[i] == 2 ) {
			int d = (x[i] - x[s] + l) % l;
			int tt = t * 2;
			if( tt > d ) {
				tt -= d, ++go;
				go += tt/l;
				if( tt % l == 0 ) --go;
			}
		}
	go %= n;
	int end = s + go;
	if( end > n ) end -= n;
	int pos;
	t %= l;
	for( int i = 1; i <= n; ++i ) {
		if( w[i] == 1 ) {
			y[i] = (x[i] + t) % l;
		} else {
			y[i] = (x[i] - t + l) % l;
		}
		if( i == s ) pos = y[i];
	}
	sort(y+1, y+n+1);
	for( int i = 1; i <= n; ++i )
		if( y[i] == pos ) {
			s = i;
			break;
		}
	s -= end-1;
	if( s < 1 ) s += n;
	for( int i = 0; i < n; ++i ) {
		int p = s+i;
		if( p > n ) p -= n;
		printf( "%d\n", y[p] );
	}
}

int main() {
	_w = scanf( "%d%d%d", &n, &l, &t );
	for( int i = 1; i <= n; ++i )
		_w = scanf( "%d%d", x+i, w+i );
	if( all2() ) solve2();
	else {
		for( int i = 1; i <= n; ++i )
			if( w[i] == 1 ) {
				solve1(i);
				break;
			}
	}
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int R,C,K;
    cin>>R>>C>>K;
    /*vector<pair<P,ll>> item(K);
    rep(i,K){
        cin>>item.at(i).first.first>>item.at(i).first.second>>item.at(i).second;
    }*/
    vector<vector<ll>> Item(R,vector<ll>(C));
    rep(i,K){
        int r,c;
        ll v;
        cin>>r>>c>>v;
        --r;--c;
        Item[r][c]=v;
    }
    vector<vector<vector<ll>>> dp(5,vector<vector<ll>>(R+1,vector<ll>(C+1)));
    dp[0][0][0]=0;
    rep(gyou,R){
        rep(retsu,C){
            for(int ko=3;ko>=0;ko--){
                if(Item[gyou][retsu]>0){
                    chmax(dp[ko+1][gyou][retsu],dp[ko][gyou][retsu]+Item[gyou][retsu]);
                }
            }
            rep(ko,4){
                chmax(dp[ko][gyou][retsu+1],dp[ko][gyou][retsu]);
                chmax(dp[0][gyou+1][retsu],dp[ko][gyou][retsu]);
            }
        }
    }
    ll ans=dp[0][R-1][C-1];
    rep(i,4){
        chmax(ans,dp[i][R-1][C-1]);
    }
    cout<<ans<<endl;
}

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

using namespace std;

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

	int n;
	cin >> n;

	vector<int> x;
	x.resize(n);

	vector<int> y;
	y.resize(n);

	vector<pair<long double, int> > p;
	p.resize(n);

	for(int i = 0; i < n; ++i) {
		cin >> x[i] >> y[i];
		p[i] = {atan2(y[i], x[i]), i};
	}

	sort(p.begin(), p.end());

	long double ans = 0;

	for(int i = 0; i < n; ++i) {
		long double sx = 0;
		long double sy = 0;
		for(int j = i; j < n + i; ++j) {
			sx += x[p[j % n].second];
			sy += y[p[j % n].second];
			ans = max(ans, sqrt(sx * sx + sy * sy));
		}
	}

	cout << fixed << setprecision(10);

	cout << ans << '\n';

	return 0;
}

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

bool val[1000000];
int  pos[1000000];

int main()
{
	int a,b;
	while(scanf("%d%d", &a,&b), (a||b))
	{
		memset(val, 0, sizeof(val));
		int cnt=0;
		while(1)
		{
			a%=b;
			
			if(a==0)
			{
				printf("%d %d\n", cnt, 0);
				break;
			}
			
			bool g=false;
			
			if(val[a])
			{
				printf("%d %d\n", pos[a], cnt-pos[a]);
				g=true;
				break;
			}
			
			if(g) break;
			
			val[a]=1;
			pos[a]=cnt;
			
			a*=10;
			cnt++;
		}
	}
}

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


void solve(std::string c){
	if((c[0]=='a')||(c[0]=='i')||(c[0]=='u')||(c[0]=='e')||(c[0]=='o')){
		cout << "vowel" << endl;
	}else{
		cout << "consonant" << endl;
	}

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string c;
    std::cin >> c;
    solve(c);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define tii tuple<int,int,int>
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}

int main(){
    int n=in();
    vec l(n);
    rep(i,n)l[i]=in();
    ll ans=0;
    sort(ALL(l));
    vec cnt(2010);
    cnt[0]=0;
    int tmp=0;
    for(int i=1;i<2010;i++){
        cnt[i]=cnt[i-1];
        while(l[tmp]<=i){
            if(tmp<n-1){
                tmp++;
                cnt[i]++;
            }else break;
        }
        if(i>=l[n-1])cnt[i]=n;
    }
    
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans+=cnt[l[i]+l[j]-1]-j-1;
        }
    }
    cout<<ans<<endl;
}



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

const int MOD = (int)1e9+7;

int main(){
	vector<int> a(5);
	int k;
	for(int i=0;i<5;i++)	cin >> a.at(i);
	cin >> k;
	
	if(a.at(4)-a.at(0)>k){
		cout << ":(" << endl;
		return 0;
	}
	cout << "Yay!" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;

#define MOD 998244353


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

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}
  
  

int main(){
    ll h,a;
    cin>>h>>a;
    cout<<h/a + bool(h%a != 0)<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

int main(){
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for(int i=1; i<N; i++) { //2つの部分文字列の開始位置j,j+iの距離
    int cnt = 0;
    rep(j, N-i) {
      if(cnt < i && S[j] == S[j+i]) { 
        cnt++;
        chmax(ans, cnt);
      }
      else
        cnt = 0;
    }
  }
  cout << ans << endl;
  return 0;
}

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


int main() {
  
  int K, X; cin >> K >> X;
  
  int count = X - K + 1;
  
  for (int i = 0; i < 2 * K - 1; i++) {
    cout << count;
    count++;
    if ( i != 2 * K - 2) cout << " ";
  }
  
  
}

Measured memory_bytes: 256
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
from itertools import combinations, product
#import bisect# lower_bound etc
#import numpy as np
def run():
    N,K = map(int, read().split())
    k = int(math.log(N, 10))
    s = N // (10 ** k)

    tmp1, tmp2, div = 1, 1, 1
    for i in range(K-1):
        tmp1 *= k-i
        div *= i+1
        tmp2 *= 9
    ret = tmp1//div * tmp2
    ret *= s-1

    tmp1 *= k - (K-1)
    tmp2 *= 9
    div *= K

    ret += tmp1 * tmp2 // div
    lis = range(k)
    nums = range(1,10)
    base = s * 10 ** k

    for A in combinations(lis, K-1):
        for X in product(nums, repeat = K-1):
            tmp = base
            for a,x in zip(A,X):
                tmp += 10 ** a * x
            if tmp <= N:
                ret += 1
    print(ret)



if __name__ == "__main__":
    run()

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int x,n,xx;
	cin>>x>>n;
	int arr[102];
	for(long long int a=0;a<102;a++){
		arr[a]=0;
	}
	while(n--){
		cin>>xx;
		arr[xx]++;
	}
	long long int l=-1,r;
	for(long long int i=x-1;i>=0;i--){
		if(arr[i]==0){
			l=i;
			break;
		}
	}
	for(long long int j=x;j<102;j++){
		if(arr[j]==0){
			r=j;
			break;
		}
	}
	long long int aa=abs(x-r);
	long long int b=abs(x-l);
	if(aa<b){
		cout<<r;
	}
	else{
		cout<<l;
	}
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll K;
  cin>>K;
  
if(K%7==0) {
K/=7;
}
  ll L=9*K;
  
ll am=1;
  ll ans;

  for(ll i=1;i<100000000;i++) {
    am*=10;
   if(am%L==1) {
   cout<<i<<endl;
    return 0;
  }
    am%=L;
  }
  
 cout<<-1<<endl;

}
    



Measured memory_bytes: 3592
n = gets.to_i
a = Array.new(n){ Complex.rect(*gets.split.map(&:to_f)) }

ans = 0
cnt = 0
a.permutation(n) do |perm|
  perm.each_cons(2) do |i,j|
    ans += (i-j).abs
  end
  cnt += 1
end
puts ans / cnt

Measured memory_bytes: 1916
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

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

	int N;
	cin >> N;

	int price = N * 800;
	price -= (N / 15) * 200;

	cout << price;

	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  int ans = 1e9;
  for (int i = 0; i < s.size() - 2; i++) {
    ans = min(ans, abs(753 - atoi((s.substr(i, 3)).c_str())));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3652
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
using namespace std;
ll psum[200005];
signed main()
{
    fast;
    
    ll n,k,i,ans=0;
    cin>>n>>k;
    ll a[n+2];
    map<ll,ll> ma;
    for(i=1;i<=n;i++)
    {
    	cin>>a[i];
    	psum[i] = (psum[i-1]%k + a[i]%k)%k;
    }
    for(i=1;i<=n;i++)
    {
    	psum[i] = ((psum[i] - i)%k + k)%k;
    }
    for(i=0;i<=n;i++)
    {
    	
    	if(i>=k)
    	{
    		ma[psum[i-k]]--;
    	}
    	ans += ma[psum[i]];
    	ma[psum[i]]++;
    }
    cout<<ans;

}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);
#define eps 1e-9



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;


int power(int a,int b){
    int r=1;
    while(b){
        if(b & 1){
            r=r*a;
            b--;
        }
        a=a*a;
        b>>=1;
    }
    return r;
}


int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>k;

	vi v;

	rf(i,32,1){
        int l=1;
        int r=10;
        while(r-l>1){
            int mid=(l+r)/2;
            int x=power(i,mid);
            if(x>k) r=mid;
            else{
                v.pb(x);
                l=mid;
            }
        }
	}

	auto z=max_element(v.bb,v.ee);

	cout<<*z<<endl;
}



Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define INF 300
int main() {
  int h, w;
  cin >> h >> w;
  int d[h][w];
  char maze[h][w];
  rep(i,h)
    cin >> maze[i];
  rep(i, h)
    rep(j, w)
      d[i][j] = INF;
  d[0][0] = (maze[0][0] == '#' ? 1 : 0);
  rep(i,h)
  {
    rep(j,w)
    {
      if (i == 0 && j == 0) {
        continue;
      }
      if(i>0) d[i][j] = min(d[i][j], d[i - 1][j]+(maze[i][j] == '#' &&maze[i - 1][j] != maze[i][j]));
      if(j>0) d[i][j] = min(d[i][j], d[i][j - 1]+(maze[i][j] == '#' &&maze[i][j - 1] != maze[i][j]));
    }
  }
  cout << d[h - 1][w - 1];
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long     ll;
const ll big=2e6+5;

#define endl "\n";
ll a[106];
int main()
{ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x,n=0;
    cin>>x>>n;
    if(n==0){cout<<x; return 0;}
bool b=true;
set <int> s;
for(int i=0;i<n;++i){
    cin>>a[i];
     s.insert(a[i]);}
     ll i=0,j=0;
  while(b){
    if(s.find(x-i)==s.end()){cout<<(x-i);return 0;}
  else if(s.find(x+j)==s.end()){cout<<(x+j);return 0;}
  j++;i++;
  }

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <map>
#define MN 250005

const long long mod = 213668850274623167;
const long long base = 257;
char s[MN];
long long c[MN];
long long fac[MN], inv[MN];
std::map<long long, int> mp;

long long mul(long long a, long long b)
{
	a = (a + mod) % mod;
	b = (b + mod) % mod;
	return (a * b - (long long)((long double) a / mod * b) * mod + mod) % mod;
}

long long qpow(long long x, long long p)
{
	long long ans = 1;
	while(p)
	{
		if(p & 1) ans = mul(ans, x);
		x = mul(x, x); p >>= 1;
	}
	return ans;
}

void add(int x, int o, long long &now)
{
	long long u;
	if(x < 0) u = inv[-x];
	else u = fac[x];
	now = (mul(u, o) + now) % mod;
}

int main()
{
	int n; scanf("%d", &n);
	scanf("%s", s);
	long long p = 0, now = 0;
	inv[1] = qpow(base, mod - 2);
	fac[0] = 1; fac[1] = base;
	for(int i = 2; i <= n; i++) inv[i] = mul(inv[i - 1], inv[1]), fac[i] = mul(fac[i - 1], fac[1]);
	for(int i = 0; i < n; i++)
	{
		if(s[i] == '<') p--;
		if(s[i] == '>') p++;
		if(s[i] == '+') add(p, 1, now);
		if(s[i] == '-') add(p, -1, now);
	}
	long long e = now; p = 0; now = 0;
	mp[e]++;
	long long ans = 0;
	for(int i = 0; i < n; i++)
	{
		if(s[i] == '<') p--;
		if(s[i] == '>') p++;
		if(s[i] == '+') add(p, 1, now);
		if(s[i] == '-') add(p, -1, now);
		long long u;
		if(p < 0) u = inv[-p];
		else u = fac[p];
		ans += mp[now];
		mp[(mul(e, u) + now ) % mod]++;
	}
	printf("%lld\n", ans);
	return 0;
} 

Measured memory_bytes: 35840
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000

#define init_value Inf

template <typename T>
struct segtree{
	//元データx[i]はv[n+i]
	//v[i]の親はv[i/2],子はv[i*2]とv[i*2+1]
	vector<T> v;
	int n;
	
	segtree(vector<T> &x){
		n=1;
		while(true){
			if(n>=x.size())break;
			n*=2;
		}
		v.resize(2*n,init_value);
		
		for(int i=0;i<x.size();i++){
			v[n+i]=x[i];
		}
		for(int i=n-1;i>=0;i--){
			v[i]=func(v[i*2],v[i*2+1]);
		}
	}
	
	
	void update(int x,T val){
		x+=n;
		v[x]=val;
		while(true){
			x=(x)/2;
			v[x]=func(v[x*2],v[x*2+1]);
			if(x<=0)break;
		}
	}
	
	//区間[l,r)におけるクエリ処理
	T query(int l,int r){
		T res = init_value;
		l+=n;r+=n;
		while(true){
			if(l%2==1){
				res=func(v[l],res);
				l++;
			}
			if(r%2==1){
				res=func(v[r-1],res);
				r--;
			}
			if(l>=r)break;
			l/=2;r/=2;
		}
		return res;
	}
	T func(T a,T b){
		return min(a,b);
	}
	
	void show(){
		int n = 1;
		for(int i=1;i<v.size();i++){
			for(int j=0;j<n;j++){
				if(j!=0)cout<<' ';
				cout<<v[i+j];
			}
			cout<<endl;
			i+=n-1;
			n*=2;
		}
	}
	
};

int main(){
	
	int N;
	cin>>N;
	
	vector<long long> a(N);
	for(int i=0;i<N;i++)cin>>a[i];
	
	segtree<long long> seg(a);
	
	vector<pair<int,int>> V(N);
	
	for(int i=0;i<N;i++){
		int ok = i;
		int ng = -1;
		while(abs(ok-ng)>1){
			int mid = (ok+ng)/2;
			long long m = seg.query(mid,i+1);
			if(m==a[i])ok=mid;
			else ng=mid;
		}
		V[i].first = ok;
		
		ok = i;
		ng = N;
		while(abs(ok-ng)>1){
			int mid = (ok+ng)/2;
			long long m = seg.query(i,mid+1);
			if(m==a[i])ok=mid;
			else ng=mid;
		}
		V[i].second = ok;
		
	}
	
	long long ans = 0;
	
	for(int i=0;i<N;i++){
		ans += a[i]*(i-V[i].first+1)*(V[i].second-i+1);
		//cout<<V[i].first<<','<<V[i].second<<endl;
	}
	
	cout<<ans<<endl;
	
	return 0;
}


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

int main(){
  int n,m,x;
  cin>>n>>m>>x;
  vector<int> num(m);
  for(int &x:num){
    cin>>x;
  }
  int count=0,i=0;
  while(num.at(i)<x){
    count++;
    i++;
  }
  if(count<=m/2) cout<<count;
  else cout<<m-count;
  cout<<endl;
}

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

static const int MAX = 100;
static const long long INFTY = (1LL << 32);

int n;
long long d[MAX][MAX];

void floyd()
{
    for (int k = 0; k != n; ++k)
    {
        for (int i = 0; i != n; ++i)
        {
            if (d[i][k] == INFTY) continue;
            for (int j = 0; j != n; ++j)
            {
                if (d[k][j] == INFTY) continue;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main()
{
    int e, u, v, c;
    cin >> n >> e;

    for (int i = 0; i != n; ++i)
    {
        for (int j = 0; j != n; ++j)
        {
            d[i][j] = ( (i == j) ? 0 : INFTY );
        }
    }

    for (int i = 0; i != e; ++i)
    {
        cin >> u >> v >> c;
        d[u][v] = c;
    }

    floyd();

    bool negative = false;
    for (int i = 0; i != n; ++i) if (d[i][i] < 0) negative = true;

    if (negative)
    {
        cout << "NEGATIVE CYCLE" << endl;
    }
    else
    {
        for (int i = 0; i != n; ++i)
        {
            for (int j = 0; j != n; ++j)
            {
                if (j) cout << " ";
                if (d[i][j] == INFTY) cout << "INF";
                else cout << d[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define LL long long
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
static const LL INF = 1LL<<61LL;
static const int MAX_N = 1<<18;
typedef pair<int,int> PII;

int dat[MAX_N*2];

class Segment{
    public :
        int n;
        void inti(int n_){
            n=1;
            while(n<n_)n*=2;
            rep(i,n*2-1)dat[i]=INT_MAX;
        }

        void update(int k,int a){
            k+=n-1;
            dat[k]=a;
            while(k>0){
                k=(k-1)/2;
                dat[k]=min(dat[k*2+1],dat[k*2+2]);
            }
        }

        int query(int a,int b,int k,int l,int r){
            if(a<=l&&r<=b)return dat[k];
            if(r<=a||b<=l)return INT_MAX;
            else {
                int vl=query(a,b,k*2+1,l,(l+r)/2);
                int vr=query(a,b,k*2+2,(l+r)/2,r);
                return min(vl,vr);
            }
        }
};


int main(){
    Segment St;
    int N,Q;
    cin>>N>>Q;
    St.inti(N);
    rep(i,Q){
        int com,x,y;
        cin>>com>>x>>y;
        if(!com)St.update(x,y);
        else cout<<St.query(x,y+1,0,0,St.n)<<endl;
    }
    return 0;
}

Measured memory_bytes: 2188
#include <bits/stdc++.h>
#define mp make_pair
#define sqr(x) (x)*(x)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=100007;
const ll inf=0x3f3f3f3f;
const int mod=998244353;
#define rep(i,x,y) for(auto i=(x);i<=(y);++i)
#define dep(i,x,y) for(auto i=(x);i>=(y);--i)
ll read(){
    ll x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int main(){
    ll A=read(),B=read(),N=read();
    ll x=min(N,B-1);
    cout<<(ll)((__int128)A*x/B+(__int128)A*(x/B));
    return 0;
}

Measured memory_bytes: 3624
#!/usr/bin/env python3
m = int(input())
d = [None] * m
c = [None] * m
s = 0
for i in range(m):
    d[i], c[i] = map(int, input().split())
    s += d[i] * c[i]
ans = sum(c) - 1 + (s - 1) // 9
print(ans)


Measured memory_bytes: 12516
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

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


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N; 
  std::string S; std::cin >> S;

  int ans = 0;
  char c = '\0';
  rep(i,N){
    if ( c != S[i] ) {
      ans++;
      c = S[i];
    } 
  }
  std::cout << ans << std::endl;
  return 0;
}


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

int n, r, p, c;
int h[51];

int main() {
  while(cin>>n>>r,n|r) {
    for(int i=1;i<=n;++i) {
      h[i] = n-i+1;
    }
    for(int i=0;i<r;++i) {
      cin>>p>>c;
      rotate(h+1, h+p, h+p+c);
    }
    cout << h[1] <<endl;
  }
  return 0;
}

Measured memory_bytes: 1184
#include<stdio.h>

int fb[50];

int fib( int n ) {
  if ( n == 1 || n==0 )
    return fb[ n ] = 1;
  if ( fb[ n ] != -1 )
    return fb[ n ];
  return fb[ n ] = fib( n-1 ) + fib( n-2 );
}
int main() {

  int i, n;
  scanf("%d", &n);
  for( i=0; i<50; i++)
    fb[ i ] = -1;
  printf("%d\n", fib( n ));

  return 0;

}
 
  

Measured memory_bytes: 596
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 //  freopen("input.txt","r",stdin);
 //  freopen("output.txt","w",stdout);
    int a,b;
    cin>>a>>b;
    int ans = 0;
    if(b==1)
    {
        cout<<0;
        return 0;
    }
    if(a>=b)
    {
        ans =1;
    }    
    else
    {
        int tot = 0;
        while(tot<b)
        {
            ans++;
            if(tot+a>=b)
                tot+=a;
            else
                tot+=(a-1);
        }
    }
    cout<<ans;
    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for(auto &i:a)cin >> i;
	int cnt = 0;
	for(int i = 0;i<n;i++)
	{

		if(i%2==0&&a[i]%2==1)cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	lli n;
	map<string, lli> memo;
	cin >> n;
	rep(i,n){
		string s;
		cin >> s;
		memo[s] += 1;
	}

	int maxv = 0;
	for(const auto& x : memo){
		int v = x.second;
		if(maxv < v) maxv = v;
	}
	for(auto it = memo.begin(); it != memo.end(); it++){
		if(it->second == maxv){
			cout << it->first << endl;
		}
	}
	return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

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

bool is_prime(int n){
    if(n < 2) return false;
    else if(n == 2) return true;
    else if(n % 2 == 0) return false;

    for(int i = 3; i <= sqrt(n); i += 2){
        if(n % i == 0){
            return false;
        }
    }

    return true;
}

int main(void){
    int q;
    cin >> q;

    int a[100005], sum = 0;
    for(int i = 0; i < 100005; ++i){
        if(is_prime(i) && is_prime((i+1)/2)) sum++;
        a[i] = sum;
    }

    vector<int> ans(q);
    for(int i = 0; i < q; ++i){
        int l, r;
        cin >> l >> r;
        ans[i] = a[r] - a[l-1];
    }

    for(int i = 0; i < q; ++i){
        cout << ans[i] << "\n";
    }

//    for(int i = 1; i < 10; ++i){
//        cout << i << " " << a[i] << "\n";
//    }

    return 0;
}


Measured memory_bytes: 4116
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    string s; cin >> s;
    int cnt=0;
    rep(i, s.length()/2){
        if(s[i] != s[s.length() - i - 1]){
            s[s.length() - 1] = s[i];
            cnt++;
        }
    }
    cout << cnt;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    h,w,m = LI()
    hw = LIR(m)
    # h, w, m = [3 * 10 ** 5] * 3
    # hw = [(i, i) for i in range(3 * 10 ** 5)]
    dh = defaultdict(int)
    dh1 = defaultdict(int)
    dw = defaultdict(int)
    dw1 = defaultdict(int)
    ma = defaultdict(int)
    for hi, wi in hw:
        dh[hi] += 1
        dw[wi] += 1
        ma[(hi, wi)] = 1
    maxh = max(dh.values())
    maxw = max(dw.values())
    for key, value in dh.items():
        if value == maxh:
            dh1[key] = maxh
    for key, value in dw.items():
        if value == maxw:
            dw1[key] = maxw
    for kh, vh in dh1.items():
        for kw, vw in dw1.items():
            if ma[(kh, kw)] == 0:
                print(vh + vw)
                return
    print(vh + vw - 1)
    
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 242268
k = int(input())
a = list(reversed(list(map(int, input().split()))))

l, r = 2, 2
for x in a:
    lb = max((l + x - 1) // x, 1)
    rb = r // x
    if rb < lb:
        print(-1)
        quit(0)
    l, r = lb * x, rb * x + x - 1

print(l, r)



Measured memory_bytes: 14252
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
	    int a = sc.nextInt();
	    int b = sc.nextInt();
	    int price = 10*b;
	    boolean flag = false;
	    for(int i = 0; i < 10; i++) {
	    	if((int)((price+i)*0.08) == a) {
	    		System.out.println(price+i);
	    		flag = true;
	    		break;
	    	}
	    }
	    if(flag == false) {
	    	System.out.println(-1);
	    }

	}

}

Measured memory_bytes: 21972
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#include<map>
#include<iomanip>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<double,double>;
using vvi = vector<vector<int> >;
using vvll =  vector<vector<ll> >;
const ll maximanhattan = 1e9 + 1;

bool pair_second(pll a, pll b){
    return a.second < b.second;
}

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
    int N;cin>>N;
    //vector<pll> point(N);
    vector<ll> right(N), left(N);
    REP(i,N){
        ll x,y; cin>>x>>y;
        right[i] = x + y;
        left[i] = (1e9 - x) + y;

    }
    sort(ALL(right));
    sort(ALL(left));
    ll ans = max(right[N-1] - right[0], left[N-1] - left[0]);
    cout << ans << endl;

}



Measured memory_bytes: 6300
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.stream.Stream;
import java.util.Collection;
import java.util.Scanner;
import java.util.Collections;
import java.util.stream.Collectors;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        pushpush solver = new pushpush();
        solver.solve(1, in, out);
        out.close();
    }

    static class pushpush {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long[] a = new long[n];

            for (int i = 0; i < n; i++) {
                a[i] = in.nextLong();
            }

            List<Long> list = new ArrayList<>();
            boolean is_odd = true;
            for (int i = 0; i < n; i++) {
                if (is_odd) {
                    list.add(a[i]);
                } else {
                    list.add(0, a[i]);
                }
                is_odd = !is_odd;
            }

            if (n % 2 != 0) {
                Collections.reverse(list);
            }
            out.print(list.stream().map(Object::toString).collect(Collectors.joining(" ")));


        }

    }
}



Measured memory_bytes: 78884
// clang-format off
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort(all(x), greater<>())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
#define INF 1e9;
#define LINF 1e18;
template<class T>bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
// clang-format on

void solve(std::string s) {
  ll n = s.size();
  ANS(s[0] << n - 2 << s[n - 1]);
}

// clang-format off
int main() {
  std::string s;
  std::cin >> s;
  solve(s);
  return 0;
}


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

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

int main() {
  ll n, ans = INF, a;

  cin >> n;
  vector<ll> sum(n);
  cin >> a;
  sum[0] = a;
  for (ll i = 1; i < n; ++i) {
    cin >> a;
    sum[i] += sum[i - 1] + a;
  }
  if (n > 2) {
    for (int i = 1; i < n - 1; ++i)
      ans = min(ans, abs(sum[n - 1] - 2 * sum[i]));
  } else {
    ans = abs(sum[1] - 2 * sum[0]);
  }
  cout << ans << endl;
  return 0;
}


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

const int INF = 1001001001;

int main()
{
    int n, m;
    int coins[21];
    cin >> n >> m;
    for(int i=0;i<m;++i) cin >> coins[i];
    int dp[50001] = {};
    for(int i=1;i<n+1;++i) dp[i] = INF;

    for(int i=0;i<m;++i)
    {
        for(int j=1;j<n+1;++j)
        {
            if(j >= coins[i])
                dp[j] = min(dp[j], dp[j - coins[i]] + 1);
        }
    }

    cout << dp[n] << endl;

}



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

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int main() {
    int N;
    cin >> N;
    int64_t ans = 0;
    for(int i=0; i<N; i++){
        int x;
        cin >> x;
        add(ans, x * power_mod(x+1, i) % MOD * power_mod(2, N-i-1));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define pf push_front
#define ll long long
using namespace std;
void TxtRead(){
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
}
void TheTime(){
    ios_base::sync_with_stdio(false);
	cin.tie();
}
const int N = 1e5+5;
const ll INF = 1e9+5;
const ll MOD = 1e9+7;
const double PI = 3.141592653589793116;

int n;
int ar[N], dp[N];

int main()
{
    //TxtRead();
    TheTime();

	scanf("%d", &n);
	for(int i=1; i<=n; i++){
		scanf("%d", &ar[i]);
	}
	
	memset(dp, '?', sizeof(dp));
	dp[1]=0;
	for(int i=2; i<=n; i++){
		dp[i]=min({dp[i], dp[i-1]+abs(ar[i]-ar[i-1]), 
			dp[i-2]+abs(ar[i]-ar[i-2])});
	}
	
	printf("%d\n", dp[n]);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define LL long long
const int MAXN = 505;
using namespace std;

int N, K, a[MAXN], b[MAXN];

bool test(int m) {
//	cout << "Test " << m << '\n';
	LL sum = 0;
	for (int i = 0; i < N; i++) {
		b[i] = a[i] % m;
		sum += b[i];
	}
	
	LL pref = 0;
	sort(b, b + N);
	for (int i = 0; i < N - 1; i++) {
		pref += b[i];
		LL cost = max((LL) (N - i - 1) * m - sum + pref, pref);
//		cout << "Get " << cost << '\n';
		if (cost <= K) {
			return true;
		}
	}
	
	return false;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int sum = 0;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		sum += a[i];
	}
	
	int ans = 1;
	for (int i = 1; i * i <= sum; i++) {
		if (sum % i == 0) {
			if (test(i)) ans = max(ans, i);
			if (test(sum / i)) ans = max(ans, sum / i);
		}
	}
	
	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 256