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

vector<ll> t;

void build_tree(int v, int l, int r) {
    if (l==r) t[v] = 0;
    else {
        int mid = (l+r)>>1;
        build_tree(2*v, l, mid);
        build_tree(2*v+1, mid+1, r);
        t[v] = max(t[2*v],t[2*v+1]);
    }
}

void update_tree(int v, int l, int r, int pos, ll x) {
    if (l==r) t[v] = x;
    else {
        int mid = (l+r)>>1;
        if (mid>=pos) update_tree(2*v, l, mid, pos, x);
        else update_tree(2*v+1, mid+1, r, pos, x);
        t[v] = max(t[2*v], t[2*v+1]);
    }
}

ll getmax(int v, int l, int r, int sl, int sr) {
    if (sl>sr) return 0ll;
    if (l==sl && sr==r) {
        return t[v];
    } else {
        int mid = (l+r)>>1;
        return max(getmax(2*v, l, mid, sl, min(sr, mid)), getmax(2*v+1, mid+1, r, max(sl, mid+1), sr));
    }
}

int main() {
    int n;
    scanf("%d", &n);
    vector<ll> h(n), a(n);
    for (auto &i: h) scanf("%lld", &i);
    for (auto &i: a) scanf("%lld", &i);
    t.resize(4*n+5);
    build_tree(1, 0, n-1);
    ll mx = 0;
    for (int i=0; i<n; i++) {
        ll temp = getmax(1, 0, n-1, 0, h[i]-1);
        temp += a[i];
        // printf("for height = %lld, temp = %lld\n", h[i], temp);
        mx = max(mx, temp);
        update_tree(1, 0, n-1, h[i]-1, temp);
    }

    printf("%lld\n", mx);
}

Measured memory_bytes: 9600
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        k: isize,
        x: isize,
    }

    let min = x - (k-1);
    let mut max = x + (k-1);
    if max > 1000000 {
        max = 1000000;
    }

    for i in min..max+1 {
        print!("{} ", i);
    }
    println!("");

}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int ans1 = min(a + b, 2 * c) * min(x, y);
    int ans2 = 0;
    if (x > y) {
        ans2 = min(a, 2 * c) * (x - y);
    } else {
        ans2 = min(b, 2 * c) * (y - x);
    }
    cout << ans1 + ans2 << endl;
    return 0;
}


Measured memory_bytes: 256
parseint(x) = parse(Int, x)
readint() = readline() |> parseint

function main()
    n = readint()
    a = [readint() for _ = 1:n]
    s, f = sort(a)[end-1:end]
    for i = 1:n
        println(a[i] == f ? s : f)
    end
end

main()

Measured memory_bytes: 166272
#include "bits/stdc++.h"
using namespace std;

int main() {
    vector< int> v;
    for (int b = 2; b <= 100; ++b) {
        int x = b * b;
        while(x <= 1000) {
            v.emplace_back(x);
            x *= b;
        }
    }
    v.emplace_back(1);
    sort(v.begin(), v.end());
    int n;
    cin >> n;
    auto it = upper_bound(v.begin(), v.end(), n);
    it--;
    cout << (*it) << endl;
}

Measured memory_bytes: 256
'use strict'
const main = (input: string) => {
    const std: string = input.trim();
    const n = ~~std;
    let r = 0;
    for (let i = 1; i <= n i++) {
        if (i.toString().length % 2 == 1) {
            r++;
        } 
    }
    console.log(r);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  


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

 using namespace std;
int N;
int M;
int gcd(int x,int y){
  if(y==0)return x;
  return gcd(y,x%y);
}
int lcm(int x,int y){
  return x/gcd(x,y)*y;
}

int main(){
  cin>>N>>M;
  vector<int>a(N);
  int LCM=1;
  bool zero=false;
  for(int i=0;i<N;i++)cin>>a[i];
  for(int i=0;i<N;i++)a[i]/=2;
  for(int i=0;i<N;i++){
    LCM=lcm(LCM,a[i]);
    if(LCM>M){
      zero=true;
      break;
    }
  }
  
    
 bool zero_2=false;   
 int x=a[0];
  int count=0;
  while(x%2==0){
    count++;
    x/=2;
  }
  
   
    
  if(zero)cout<<0<<endl;
  else{
    for(int i=0;i<N;i++){
      int y=a[i];
      int count2=0;
      while(y%2==0){
        count2++;
        y/=2;
      }
      if(count!=count2)zero_2=true;
    }
   
    if(zero_2)cout<<0<<endl;
    else{
      M-=LCM;
      M/=2;
      int64_t ans=1;
      ans+=M/LCM;
      cout<<ans<<endl;
    }
  }
}
  
    
  
  
  




Measured memory_bytes: 640
n = int(input())
A = [0] + [*map(int, input().split())]
dp_stock = [0]*(n+1)
dp_yen = [0]*(n+1)
dp_yen[0] = 1000
for day in range(1, n+1):
    dp_stock[day] = max(dp_stock[day-1], dp_yen[day-1] // A[day])
    remain = dp_yen[day-1] - dp_stock[day-1]*A[day-1]
    dp_yen[day] = max(dp_yen[day-1], remain + dp_stock[day-1] * A[day])
print(dp_yen[n])


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

using namespace std;
const long long INF = 1LL <<60;  

int main(void){
  long res=0;
  long i,j,k;
  long x,y;
  long n,d;
  
  cin>>n>>d;
  for(i=0;i<n;i++){
    cin>>x>>y;
    if(x*x+y*y<=d*d){
      res++;
    }
  }

  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 3628
// https://atcoder.jp/contests/abc175/tasks/abc175_d
#include <bits/stdc++.h>
using namespace std;
// #define int int64_t
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int N, K;
    cin >> N >> K;
    vector<int> P(N);
    vector<int64_t> C(N);
    for (auto &&x : P) {
        cin >> x;
        x--;
    }
    for (auto &&x : C) {
        cin >> x;
    }

    int64_t ans = -1e12;
    // スタート位置
    REP(i, N) {
        // 循環する要素を求める（Pi != i なので自分自身へループしない）
        vector<int64_t> v;
        for (int j = i;; j = P[j]) {
            v.push_back(C[j]);
            // 開始時点に戻ったら終了
            if (P[j] == i)
                break;
        }
        // 循環する要素の長さ
        int64_t m = v.size();
        // 循環する要素の合計
        auto sum = accumulate(begin(v), end(v), 0LL);
        int64_t cur = 0;
        for (int r = 1; r <= m; ++r) {
            if (r > K)
                break;
            cur += v[r - 1];
            // 先頭からスコアを加算し、残りの長さに対して何回循環するか数える
            ans = max(ans, cur + (K - r) / m * max<int64_t>(sum, 0));
        }
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3764
from collections import deque

n,c,k = map(int, input().split())
tl = []
for _ in range(n):
    t = int(input())
    tl.append(t)


tl.sort()
q = deque(tl)

ans = 0
while q:
    ans += 1
    poped = q.popleft()
    lim = poped + k
    for i in range(c-1):
        if not q:
            break
        next_t = q[0]
        if next_t <= lim:
            q.popleft()
        else:
            break

print(ans)

Measured memory_bytes: 83136
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t,c;
    cin>>n;
    ll arr[n],brr[n];
    for(i=1;i<=n;i++) brr[i-1]=i;
    for(i=0;i<n;i++) cin>>arr[i];
    ll count=0;
    for(i=0;i<n;i++) if(arr[i]!=brr[i]) count++;
    if(count<=2) cout<<"YES";
    else cout<<"NO";
    
}

Measured memory_bytes: 3600
import java.util.Scanner;

class Main {
    
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String input = scanner.next();
        scanner.close();
        if(input.contains("7")){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
    
}

Measured memory_bytes: 27012
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;

int main()
{
	char s[4];
	int n;
	cin >> n;
	double sum = 0.0, k;
	while (n--)
	{
		fflush(stdin);
		fscanf(stdin, "%lf %s", &k, s);
		if (strcmp(s, "BTC") == 0)
			sum += (k/0.1)*38000.0;
		else
			sum += k;
	}
	cout << sum << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	if (a >= 13) {
		printf("%d", b);
	}
	else if ((a >= 6) && (a < 13)) {
		printf("%d", (b >> 1));
	}
	else {
		printf("0");
	}
	printf("\n");
    return 0;
}


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

using namespace std;
typedef long long ll;
const ll INF = 1e9;
// const ll MOD = 1e9 + 7;
const ll MOD = 2019;

int main(){
    ll N, S = 0, S1 = 0;
    cin >> N;
    vector<int> A(N, 0);
    vector<int> res(N, 0);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        S += A[i];
        if (i % 2 == 1)
            S1 += 2 * A[i];
    }
    res[0] = S - S1;
    cout << res[0] << " ";
    for (int i = 1; i < N; i++) {
        res[i] = 2 * A[i - 1] - res[i - 1];
        cout << res[i] << " ";
    }
    cout << endl;
}


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

//#pragma GCC optimize("Ofast")

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int NN = 1e9 + 7;
const int N = 2e5 + 7;
const int M = 26;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 7;
const dl rf = 1e-14;
const int B = sqrt(N);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll n,k;
ll a[N];

bool can( int x )
{
    ll cnt = 0;
    for( int i = 1; i <= n; i++ ){
        cnt += (a[i] + x - 1) / x - 1;
        if( cnt > k )return false;
    }
    return true;
}

void solve1()
{
    cin >> n >> k;
    for( int i = 1; i <= n; i++ ){
        cin >> a[i];
    }
    int l = 1 , r = 1e9;
    while( l < r ){
        int m = (l + r) / 2;
        if( can( m ) )r = m;
        else l = m + 1;
    }
    cout << l;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


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

#define re return
#define pb push_back
#define po pop_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pi 3.14159265359
#define fo(i, n) for(int i = 0; i < n; ++i)
#define ro(i, n) for(int i = n - 1; i >= 0; --i)
#define fill(x, y) memset(x, y, sizeof(x))


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef double D;
typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;

const int maxn = 100;
int g[maxn][maxn];

int main() {
    int n;
    cin >> n;
    fo(i, 2) fo(j, n) cin >> g[i][j];
    fo(i, 2) for (int j = 1; j < n; j++) g[i][j] += g[i][j - 1];
    int ans = 0;
    fo(i, n) {
        ans = max(ans, g[0][i] + g[1][n - 1] - (i ? g[1][i - 1] : 0));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = new List<int>();

            for (int i = 0; i < 5; i++)
            {
                line.Add(int.Parse(Console.ReadLine()));
            }

            var k = int.Parse(Console.ReadLine());

            for (int i = 0; i < 4; i++)
            {
                for (int j = i+1; j < 5; j++)
                {
                    if (Math.Abs(line[i]-line[j]) > k)
                    {
                        Console.WriteLine(":(");
                        return;
                    }
                }
            }

            Console.WriteLine("Yay!");

        }
    }
}


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

int main() {
  long n,k,ans;
  cin >> n >> k;
  vector<long> d(k);
  vector<bool> b(10);
  
  for(long i=0;i<k;i++) cin >> d[i];
  for(long i=0;i<k;i++) b[d[i]]=true;
  for(ans=n;true;ans++) {
    bool a=true;
    for(long i=1;i<=ans;i*=10) if(b[ans/i%10]) a=false;
    if(a) break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <set>

using namespace std;

int N;
char s[105];
set<char> ss;

int main(void)
{
	cin >> N;
	for(int i = 1; i <= N; i++) cin >> s[i];
	
	for(int i = 1; i <= N; i++) ss.insert(s[i]);
	if(ss.size() == 3) cout << "Three" << endl;
	else cout << "Four" << endl;
		
	return 0;
}

Measured memory_bytes: 256
n,b,r = map(int,input().split())

#　商
x = n // (b + r) 

#　余り
y = n % (b + r)


if b == 0:
    print(0)
elif(n <= b):
    print(n)
elif(y == 0):
    print(x * b)
else:
    if y < b:
        print((x * b) + y)
    else:
        print((x * b) + b)


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

int gcd(int x,int y){
    if(y==0)return x;
    x=x%y;
    gcd(y,x);
}
main()
{
    int x,y;
    cin>>x>>y;
    if(x+y==2)cout<<1000000<<endl;
    else if(x>3&&y>3) cout<<0<<endl;
    else if (x>3) cout<<(4-y)*100000<<endl;
    else if (y>3) cout<<(4-x)*100000<<endl;
    else cout<<((4-x)+(4-y))*100000<<endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, m, a[334][334], c[334], t, p, r;
bool s[334];

int main() {
	cin >> n >> m;
	rep(i,n) rep(j,m) cin >> a[i][j];
	fill(s, s+m+1, true);
	rep(i,n) c[a[i][0]]++;
	p = distance(c, max_element(c, c+m+1));
	r = c[p];
	rep(i,m-1) {
		s[p] = false;
		memset(c, 0, sizeof(c));
		rep(j,n) {
			rep(k,m) {
				if (s[a[j][k]]) {
					c[a[j][k]]++;
					break;
				}
			}
		}
		p = distance(c, max_element(c, c+m+1));
		t = c[p];
		chmin(r, t);
	}
	cout << r << ln;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換
int keta(ll n){int ans=0;while(n>0){n /= 10; ans++;}return ans;}
ll _pow(ll a,ll b){ll ans = 1;rep(i,b){ ans *= a;}return ans;}

int main() {
    int n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    string s; cin >> s;
    bool flag = false;
    int count =0;
    //if(s[0] == '.')count++;
    for(int i = a;i < c;i++){
       
        if(s[i] == '#' &&s[i-1] == '#'){
            cout<<"No"<<endl;
            return 0;
        }
        
    }
    for(int i = b;i < d;i++){
       
        if(s[i] == '#' &&s[i-1] == '#'){
            cout<<"No"<<endl;
            return 0;
        }
        
    }
    for(int i = b-2;i <= d;i++){
         if(s[i] == '.'){
            count++;
        }else
        {
            count = 0;
        }
        if(count == 3){
            flag = true;
        }
    }
    if(c<d){
        cout<<"Yes"<<endl;
        return false;
    }else
    {
        if(flag){
    cout<<"Yes"<<endl;
    }else
    {
        cout<<"No"<<endl;
    }
    
    }
    
    return 0;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

//typedef long long ll;
typedef __int128 ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(ll)(n);i>0;i--)
#define REP(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.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 (a>b) { a = b; return 1; } return 0; }
const ll inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);


int main () {
  int n;
  cin >> n;
  ll m = n;
  if (m <= 999) {
    cout << "ABC" << endl;
  }
  else {
    cout << "ABD" << endl;
  }
}


Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
typedef long long ll;
const int Imx=2147483647;
const int mod=1000000007;
const ll Lbg=2e18;
//My own input/output stream
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putsp()
#define putii(x,y) puti(x),putnum(y),putsp()
#define putiii(x,y,z) putii(x,y),putnum(z),putsp()
#define putsi(x) putnum(x),putendl()
#define putsii(x,y) puti(x),putnum(y),putendl()
#define putsiii(x,y,z) putii(x,y),putnum(z),putendl()
inline ll getnum()
{
	register ll r=0;register bool ng=0;register char c;c=getchar();
	while(c!='-'&&(c<'0'||c>'9'))c=getchar();
	if(c=='-')ng=1,c=getchar();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=getchar();
	if(ng)r=-r;return r;
}
template <class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline void putsp(){putchar(' ');}
inline void putendl(){putchar('\n');}
inline char mygetchar(){register char c=getchar();while(c==' '||c=='\n')c=getchar();return c;}
int n,L,T,a[100111],w[100111],b[100111];
int main()
{
	getiii(n,L,T);
	ll cnt=0;
	for(int i=1;i<=n;i++)
	{
		getii(a[i],w[i]);
		if(w[i]==1)
		{
			int t=T;
			t-=L-a[i];
			if(t>=0)
			{
				cnt+=t/L+1;
			}
			b[i]=(a[i]+T)%L;
		}
		else
		{
			int t=T;
			t-=a[i]+1;
			if(t>=0)
			{
				cnt-=t/L+1;
			}
			b[i]=((a[i]-T)%L+L)%L;
		}
	}
	sort(b+1,b+n+1);
	cnt=(cnt%n+n)%n;
	for(int i=cnt+1;i<=cnt+n;i++)
	{
		putsi(b[(i-1)%n+1]);
	}
	return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define debug(x) cerr<<#x<<" = "<<x
#define sp <<"  "
#define el <<endl
#define fgx cerr<<"-----------------------------------"<<endl
#define LL long long
#define M
using namespace std;
namespace IO{
	const int BS=(1<<23)+5; int Top=0;
	char Buffer[BS],OT[BS],*OS=OT,*HD,*TL,SS[20]; const char *fin=OT+BS-1;
	char Getchar(){if(HD==TL){TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);} return (HD==TL)?EOF:*HD++;}
	void flush(){fwrite(OT,1,OS-OT,stdout),OS=OT;}
	void Putchar(char c){*OS++ =c;if(OS==fin)flush();}
	void write(int x){
		if(!x){Putchar('0');return;} if(x<0) x=-x,Putchar('-');
		while(x) SS[++Top]=x%10,x/=10;
		while(Top) Putchar(SS[Top]+'0'),--Top;
	}
	int read(){
		int nm=0,fh=1; char cw=getchar();
		for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
		for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
		return nm*fh;
	}
}using namespace IO;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n=read(),a=read(),b=read();
	printf("%d\n",(n-a+1)*(n-b+1));
	return 0;
}

Measured memory_bytes: 256
import math

List = list(map(int, [input() for _ in range(5)]))
List_t = list(map(lambda x: math.ceil(x / 10) * 10, List))

ans = sum(List_t)
for i in range(5):
    s = sum(List_t[:i]) + sum(List_t[i+1:]) + List[i]
    if s < ans:
        ans = s

print(ans)



Measured memory_bytes: 3060
import numpy as np

N=int(input())
S=input()

d=np.zeros(N)
d[0]=S[1:].count("E")

for i in range(1,N):
    if S[i]=="W" and S[i-1]=="W":
        d[i]=d[i-1]+1
    elif S[i]=="E" and S[i-1]=="W":
        d[i]=d[i-1]
    elif S[i]=="W" and S[i-1]=="E":
        d[i]=d[i-1]
    else:
        d[i]=d[i-1]-1
        
print(int(np.min(d)))

Measured memory_bytes: 15408
N = int(input())
d = [int(input()) for i in range(N)]
cnt=1
a=d[0]
if a==2:
    print(cnt)
    exit()

for _ in range(N):
    a=d[a-1]
    cnt+=1
    if a==2:
        print(cnt)
        exit()
print(-1)

Measured memory_bytes: 80088
#include <bits/stdc++.h>
#define Roc ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ll long long
#define NMAX 100009

using namespace std;
const ll inf = 1e9 + 5;
ll n, G, w[NMAX], p[NMAX], pd[NMAX];
int main()
{
    Roc;
    cin >> n >> G;
    for(ll i = 1; i <= n; ++i)
        cin >> w[i] >> p[i];

    for(ll i = 1; i <= n; ++i)
        for(ll j = G - w[i]; j >= 0; --j)
            if(pd[j] != inf)
                pd[j + w[i]] = max(pd[j + w[i]], pd[j] + p[i]);
    cout << pd[G];
    return 0;
}


Measured memory_bytes: 1024
#import<atcoder/all>
#define f(i)std::cout<<i<<' ';
int n,a;int main(){std::cin>>n>>a;atcoder::scc_graph g(n);for(;std::cin>>n>>a;)g.add_edge(n,a);f(size(g.scc()))for(auto i:g.scc()){f(size(i))for(auto j:i)f(j)}}

Measured memory_bytes: 40104
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#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 pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    string s;
    while (cin >> s && s != "#"){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        VVI f;
        VI r;
        REP(i,s.length()){
            if (s[i] == 'b'){
                r.push_back(1);
            }else if (s[i] > '0' && s[i] <= '9'){
                REP(x,s[i]-'0') r.push_back(0);
            }else{
                f.push_back(r);
                r.clear();
            }
        }
        f.push_back(r);
        int h = f.size(), w = f[0].size();
        f[a-1][b-1] = 0;
        f[c-1][d-1] = 1;
        string ans;
        REP(i,h){
            int x = 0;
            REP(j,w){
                if (f[i][j]){
                    if (x > 0) ans += x + '0';
                    ans += 'b';
                    x = 0;
                }else{
                    x++;
                }
            }
            if (x > 0) ans += x + '0';
            if (i < h-1) ans += '/';
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;

#define rep(countName, left, right, up) for (ll countName = left; countName < right; countName += up)
#define rev(countName, right, left, down) for (ll countName = right - 1; countName >= left; countName -= down)

auto solve1(ll a, ll b, ll c)
{
    string ans = "No";
    ll base = c - a - b;

    if (base > 0)
    {
        if (4 * a * b < base * base)
        {
            ans = "Yes";
        }
    }

    return ans;
}

int main(void)
{
    ll a, b, c;
    cin >> a >> b >> c;
    cout << solve1(a, b, c) << endl;
    return 0;
}

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

ll a,b,x;

map<pair<int,int>, int>color;

const int maxn = 1e5 + 100;

vector<int>graph[maxn];

int mexx(set<int>&s, int beg)
{
    int m = beg;
    while(s.count(m))
        m++;
    return m;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<pair<int,int> >edges;
    for(int i = 1; i < n ; i++)
    {
        int u,v;
        cin >> u >> v;
        edges.push_back({u,v});
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    int ans = 0;

    for(int i = 1; i <= n ; i++)
    {
        set<int>s;
        for(auto &v : graph[i])
        {
            int a = i;
            int b = v;
            if(a > b)
                swap(a,b);
            if(color.count({a,b}))
                s.insert(color[{a,b}]);
        }
        int beg = 1;
        for(auto &v : graph[i])
        {
            int a = i;
            int b = v;
            if(a > b)
                swap(a,b);
            if(color.count({a,b}) == 0)
            {
                int new_color = mexx(s, beg);
                ans = max(ans, new_color);
                beg = new_color;
                s.insert(new_color);
                color[{a,b}] = new_color;
            }
        }
    }

    cout << ans << endl;
    for(auto &e : edges)
    {
        cout << color[e] << endl;
    }


    return 0;
}

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

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    if(n == 0 && m == 0) {
        cout << "0 0" << endl;
        return 0;
    }

    int test = 0;
    for(int i = 0; i < (1 << n); ++i)
        if(i != m) test ^= i;
    

    if(test == m) {
        for(int i = 0; i < (1 << n - 1); ++i)
            if(i != m) cout << i << ' ';
        cout << m << ' ';
        for(int i = (1 << n - 1) - 1; i >= 0; --i)
            if(i != m) cout << i << ' ';
        for(int i = (1 << n - 1); i < (1 << n); ++i)
            if(i != m) cout << i << ' ';
        cout << m << ' ';
        for(int i = (1 << n) - 1; i >= (1 << n - 1); --i)
            if(i != m) cout << i << ' ';
        return 0;
    }

    if(m)
        return cout << -1 << endl, 0;

    for(int i = 0; i < (1 << n); ++i) {
        cout << i << ' ' << i << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int digsum(int a){
	int ans=0;
	while(a){
		ans+=a%10;
		a=a/10;
	}
	return ans;
}

main() {
	//freopen("input","r",stdin);
	int n;
	cin>>n;
 int ans =15555555;
 for(int i=1;i<n;i++){ans=min(digsum(i)+digsum(n-i),ans);}
 	cout<<ans<<endl;
	
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n,k,q;
    cin >> n >> k >> q;
    int a[q];
    int score[n] = {};

    for(int i = 0;i < q;i++)
    {
        cin >> a[i];
        score[a[i] - 1]++;
    }

    for(int i = 0;i < n;i++)
    {
        if(score[i] - q + k > 0)
        {
            cout << "Yes\n";
        }
        else
        {
            cout << "No\n";
        }
    }

    return 0;
}

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

double total_ans=0;

void dfs(int n,vector<bool> &visited, vector<int> &x, vector<int> &y,int now,double kans)
{
    int i;
    bool all_visit=true;
    for(i=0;i<n;i++)
    {
        if(!visited.at(i))all_visit=false;
    }
    if(!all_visit)
    {
        for(i=0;i<n;i++)
        {
            if(!visited.at(i))
            {
                visited.at(i)=true;
                kans += sqrt((x.at(i)-x.at(now))*(x.at(i)-x.at(now))+(y.at(i)-y.at(now))*(y.at(i)-y.at(now)));
                dfs(n,visited,x,y,i,kans);
                kans -= sqrt((x.at(i)-x.at(now))*(x.at(i)-x.at(now))+(y.at(i)-y.at(now))*(y.at(i)-y.at(now)));
                visited.at(i)=false;
            }
        }
        return;
    }
    else
    {
        total_ans+=kans;
        return;
    } 
}

int main()
{
    int n;cin>>n;
    vector<int> x(n);
    vector<int> y(n);
    vector<bool> visited(n,false);
    int i,j;
    for(i=0;i<n;i++)cin>>x.at(i)>>y.at(i);
    for(i=0;i<n;i++)
    {
        visited.at(i)=true;
        dfs(n,visited,x,y,i,0);
        visited.at(i)=false;
    }
    for(i=2;i<=n;i++)
    {
        total_ans=total_ans/i;
    }
    cout<<fixed<<setprecision(10)<<total_ans<<endl;
}


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

int		main(void)
{
	int n, a, b;

	cin >> n >> a >> b;
	int ans = 0;

	for (int i = 1; i <= n; i++)
	{
		int sum = 0;
		int tmp = i;
		while (tmp != 0)
		{
			sum += tmp % 10;
			tmp /= 10;
		}
		if (a <= sum && sum <= b)
			ans += i;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
for h in range(1,3501):
  for n in range(1,3501):
    a = 4 * h * n - N * (h + n)
    if a > 0:
      w,b = divmod(N * h * n, a)
      if b == 0:
        print(h,n,w)
        exit()

Measured memory_bytes: 40668
L = [int(input()) for i in range(5)]
A = [[] for i in range(10)]
ans = 0
for i in range(len(L)) :
    A[L[i] % 10].append(L[i])
cnt = 0
ans = 0
ans += sum(A[0])
cnt += len(A[0])
A.pop(0)
A = list(reversed(A))
for i in range(len(A)) :
    for j in range(len(A[i])) :
        ans += A[i][j]
        if cnt != 4 :
            ans += 10 - (A[i][j] % 10)
            cnt += 1
print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
string s,t,u;
int main(){
	cin>>s>>t;
	int a,b;
	scanf("%d%d",&a,&b);
	cin>>u;
	if(s==u){
		a--;
	}
	else{
		b--;
	}
	printf("%d %d\n",a,b);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

bool fc(int i, const string &s){
  string is;
  while(i != 0){
    is.push_back(i%10 + '0');
    i /= 10;
  }
  rep2(i, is.size(), 3) is.push_back('0');
  reverse(ALL(is));
  // cerr << is << endl;
  int index = 0;
  rep(i, s.size()){
    if(s.at(i) == is.at(index)){
      index++;
      if(index == 3) break;
    }
  }
  return index == 3;
}

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  rep(i, 1000){
    if(fc(i, s) == true) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
	int K,A,B,i;
	string S;
	cin >> K >> A >> B;
	//vector<int> a(N);
	for(i=A;i<=B;++i)
	{
		if (i % K == 0)
		{
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
}

Measured memory_bytes: 3620
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define no_answer return cout << "NO", 0;
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 4e5 + 200;
const long long MNN = 3e3 + 200;
const long long MOD = 1e9 + 7;
const long long INF = 1e13;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int n, k, a[MXN];
llong dp[MNN][MNN][2];

int main () {
    ios;
    cin >> n;
    for(int i = 1; i <= n; i++){
        for(int j = i; j <= n; j++){
            dp[i][j][0] = dp[i][j][1] = -INF;
        }
    }
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        dp[i][i][1] = a[i];
        dp[i][i][0] = -a[i];
    }
    for(int sz = 1; sz <= n - 1; sz++){
        for(int l = 1; l + sz <= n; l++){
            int r = l + sz;
            dp[l][r][0] = min(dp[l][r - 1][1] - a[r], dp[l + 1][r][1] - a[l]);
            dp[l][r][1] = max(dp[l][r - 1][0] + a[r], dp[l + 1][r][0] + a[l]);
        }
    }
    cout << dp[1][n][1];
}


Measured memory_bytes: 151936
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(){
	double a,b,c;
	cin >> a >> b >> c;
	double d = c*M_PI/180;
	double h = b*sin(d);
	double m = sqrt(a*a+b*b-2*a*b*cos(d));
	double s = a*h/2;
	cout << fixed << setprecision(10);
	cout << s << endl;
	cout << a+b+m << endl;
	cout << s/a*2 << endl;
}

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

using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int a, b, c;
	cin >> a >> b >> c;
	
	a -= b;
	c -= a;
	if(c < 0){
		cout << 0;
	} else {
		cout << c;
	}
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
void YN(bool flg){cout<<(flg?"YES":"NO")<<endl;}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<endl;}
void yn(bool flg){cout<<(flg?"yes":"no")<<endl;}
signed main(){
	int n,y; cin>>n>>y;
	int a=-1,b=-1,c=-1;
	rep(i,n+1) rep(j,n+1){
		int k=y-j*5000-i*10000;
		if(k%1000!=0||k<0) continue;
		k/=1000;
		if(i+j+k==n) a=i,b=j,c=k;
	}
	cout<<a<<" "<<b<<" "<<c<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
const ll M = 1e9 + 7;
using namespace std; 

void solve()
{
	ll n,sum=0;
	cin>>n;
	ll a[n];
	map<ll,ll> mp;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		mp[a[i]]++;
		sum+=a[i];
	}
	ll m;
	cin>>m;
	for(ll i=0;i<m;i++)
	{
		ll x,y;
		cin>>x>>y;
		sum-=x*mp[x];
		sum+=y*mp[x];
		ll temp=mp[x];
		mp[y]+=temp;
		mp.erase(x);
		cout<<sum<<endl;
	}
}

int main() 
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}

Measured memory_bytes: 8356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9;

int x, y;

int main(){
	cin>>x>>y;
	bool ok = false;
	for(int i = 0; i <= x; ++i){
		int a = i;
		int b = x - i;
		if(a * 2 + b * 4 == y)ok = true;
	}
	if(ok)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	
	return 0;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
int A[111];

void solve(){
    rep(i,N){
        char c;cin>>c;A[i]=c-'A';
    }

    int S[111]={};
    rep(i,N){
        S[A[i]]++;

        rep(j,26){
            bool ok=true;
            rep(k,26)if(k!=j&&S[k]+N-1-i>=S[j])ok=false;
            if(!ok)continue;
            cout<<(char)(j+'A')<<" "<<i+1<<endl;
            return;
        }
    }
    cout<<"TIE"<<endl;
}

signed main(){
    while(cin>>N,N)solve();
    return 0;
}

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

#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(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
bool p[100009],t[100009];
int ans[100009];
void sieve(){
	p[0]=p[1] = true;
	ans[0]=ans[1]=0;
	repA(i,2,100000){
		ans[i]=ans[i-1];
		if(p[i]) continue;
		if(!p[(i+1)/2]) ans[i]++;
		for(int j = 2*i;j<=100000;j+=i){
			p[j] = true;
		}
	}
}
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	sieve();
	int q;cin>>q;
	rep(i,q){
		int l,r;cin>>l>>r;
		cout<<ans[r]-ans[l-1]<<'\n';
	}
	return 0;
}


Measured memory_bytes: 1152
// Created by AboAbdoMC
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#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 f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 1e5+7;



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

    ll k,ans = 0;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    rep(i,n)
    {
    	repA(j,0,i-1)
    	{
    		if (a[j] > a[i]) ans++;
    	}
    }

    ans = (ans*k)%MOD;
    //3 5
    //db1(ans);
    ll ans2 = 0;
    rep(i,n)
    {
    	rep(j,n)
    	{
    		if (a[j] > a[i]) ans2++;
    	}
    }

    ans2 = ans2*( ((k*(k-1))/2)%MOD )%MOD;
    ans = (ans+ans2)%MOD;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
#define  B   begin()
#define  E   end()
const int N=2e5+3;
string s,p[]={"AC","WA","TLE","RE"};
//vector<int>v;
map<string,int>mp;

int main()
{
    ft
    int t,i,j,n,m,l,r;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>s;
        mp[s]++;
    }
    for(i=0;i<4;i++)
    {
        cout<<p[i]<<" x "<<mp[p[i]]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
int main(){
	int r, g, b, n;
	cin >> r >> g >> b >> n;
	int cnt = 0;
	for(int i = 0; i <= 3000; i++)
		for(int j = 0; j <= 3000; j++){
			int left = n - i * r - j * g;
			if(left < 0) continue;
			if(left % b == 0) cnt++;
		}
	cout << cnt << "\n";
	return 0;
}

Measured memory_bytes: 256
def solve():
    def measurement(a, b, w):
        a_root = root[a]
        b_root = root[b]
        if a_root != b_root:
            a_member = member[a_root]
            b_member = member[b_root]
            offset = w - (weight[b] - weight[a])
            if len(a_member) > len(b_member):
                a_member.extend(b_member)
                for n in b_member:
                    root[n] = a_root
                    weight[n] += offset
            else:
                b_member.extend(a_member)
                for n in a_member:
                    root[n] = b_root
                    weight[n] -= offset
    
    def inquiry(a, b):
        if root[a] == root[b]:
            return weight[b] - weight[a]
        else:
            return 'UNKNOWN'
                    
    import sys
    file_input = sys.stdin.readlines()
    
    while True:
        N, M = map(int, file_input[0].split())
        if N == 0:
            break
        
        root = [i for i in range(N + 1)]
        member = [[i] for i in range(N + 1)]
        weight = [0] * (N + 1)
        
        for line in file_input[1:M+1]:
            if line[0] == '!':
                a, b, w = map(int, line[2:].split())
                measurement(a, b, w)
            else:
                a, b= map(int, line[2:].split())
                print(inquiry(a, b))
        
        del file_input[:M+1]

solve()


Measured memory_bytes: 133984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
ll a[maxn],n;
ll ans=1;
int main(){
	cin >> n;
	for (ll i=1;i<=n;i++){
		cin >> a[i];
		if (a[i]==0) {cout << '0';return 0;}
	}
	for (ll i=1;i<=n;i++){
		ll j=0,k=ans,l=a[i];
		while (k>=10){
			k/=10;
			j++;	
		}
		while (l>=10){
			l/=10;
			j++;	
		}
		if ((j>=18 && k*l!=1)|| (j==17 && k*l>=10)) {cout << "-1";return 0;}
		ans *= a[i];
		if (ans > 1000000000000000000) {cout<<"-1";return 0;}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4372
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    float a= (float)n/1.08;
    int p =(int)a*1.08;
    int q =((int)a+1)*1.08;
    if(p==n)
    {
        cout<<a;
    }
    else if(q==n)
    {
        cout<<(int)a+1;
    }
    else
    {
        cout<<":(";
    }

}

Measured memory_bytes: 3676
#include <iostream>

int main()
{
  	std::string s1, s2, s3;
  	std::cin >> s1 >> s2 >> s3;
  	char x = s1.at(0) - 32, y = s2.at(0) - 32, z = s3.at(0) -32;
  	std::cout << x << y << z;
  	return 0;
}

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

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
	return y ? gcd(y, x%y) : x;  /*yが0でなければgcd、1であればxをかえす*/
}

int main(){
	ll a, b;
	cin >> a >> b;
	ll x= gcd(a, b);
	ll ans = 0;
	for (ll c = 2; c*c <= x; c++){
		if (x % c == 0) {	
			while (x%c == 0){
				x = x / c;
			}
			ans++;
		}
	}

	if (x != 1) {
		ans++;
	}
	ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<list>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<numeric>

using namespace std;

using ll = int64_t;

/// <summary>
/// 単純なcoutの時に使う
/// </summary>
#define co(a) cout<<a<<"\n"


/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define rep(i,a) for(ll i=0; i<a; ++i)
#define reps(i, a, b) for(ll i = a; i < b; ++i)

/// <summary>
/// 迷路等で使う方向のベクトル
/// </summary>
const vector<ll> dx = { 0, 1, 0, -1 }, dy = { 1, 0, -1, 0 };

/// <summary>
/// デバッグ時に使う
/// </summary>
#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

///////////////////////////////////////////////////////////////////////////

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

	ll N, A, B;
	cin >> N >> A >> B;

	

	cout << min((N * A), B) << endl;
}

Measured memory_bytes: 256
import bisect
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()

#和がx以上になる組み合わせの総数を求める関数
def pattern_num_ge_x(x):
    p=0
    for a in A:
        p+=(N-bisect.bisect_left(A, x-a))
    return(p)

#pattern_num_ge_x(x)がM未満になる最小のxを探す(=r)
#lはM以上になる最大のx
l=-1
r=10**10+1
while r-l>1:
    m=(r+l)//2
    if pattern_num_ge_x(m)<M:
        r=m
    else:
        l=m

#和がr以上になる組み合わせの総和を求める(累積和を使用)
S=[0]+list(reversed(A[:]))
for i in range(1,N+1):
    S[i]+=S[i-1]
ans=0
for a in A:
    idx=bisect.bisect_left(A,r-a)
    ans+=a*(N-idx) + S[N-idx]
    M-=(N-idx)

#回数のあまり分lを足す
ans+=l*M

print(ans)

Measured memory_bytes: 56836