akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <deque>
//#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
int main()
{
    ll a,b;
    cin>>a>>b;
    if(b-a+1>=2019)
    {
        cout<<"0"<<endl;
        return 0;
    }
    a%=2019,b%=2019;
    ll ans=9999999990999;
    for(ll i=min(a,b);i<max(a,b);i++)
    {
        for(ll j=i+1;j<=max(a,b);j++)
            ans=min(ans,i*j%2019);
    }
    cout<<ans%2019<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
befor = 0
count = 0

for i in A:
    if befor == 0:
        count += B[i-1]
        befor = i
        continue

    if befor == i - 1:
        count += B[i-1] + C[befor-1]
        befor = i
    else:
        count += B[i-1]
        befor = i

print(count)

Measured memory_bytes: 3064
from itertools import combinations as cmb
import copy
n, k = map(int, input().split())
A = list(map(int, input().split()))
highest = [A[0]] * n
for i in range(1, n):
  highest[i] = max(A[i], highest[i-1])

def cost_calc(pattern):
  cost = 0
  max_height_re = 0
  A_copy = copy.copy(A)
  for num in pattern:
    cost += max(max_height_re, highest[num]) - A[num]
    max_height_re = max(max_height_re, highest[num]) + 1
  return cost

max_val = float("inf")
for pattern in cmb(range(n), k):
  max_val = min(max_val, cost_calc(pattern))
print(max_val)

Measured memory_bytes: 41708
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

const long long MOD = 1000000007LL;
const long long INF = 1e18;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

struct chash {
    static uint64_t splitmix64(uint64_t x) {x += 0x8e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf54876d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
    size_t operator()(pair<uint64_t,uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);}
};

long long fac[3000006];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int x, y; cin >> x >> y;

    fac[1] = fac[0] = 1;
    for(int i = 2; i <= 3000003; ++i){
        fac[i] = fac[i - 1] * i % MOD;
    }
    long long tot = 0;
    for(int j, i = 0; i <= x; ++i){
        j = x - 2 * i;
        if(i + j * 2 == y && j >= 0 && i >= 0){
            // choose(n + k, k)
            tot += fac[i + j] * fast_exp(fac[j], MOD - 2) % MOD * fast_exp(fac[i], MOD - 2) % MOD;
        }
    }

    cout << tot;

    return 0;

}


Measured memory_bytes: 23680
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

N=II()
INL=LI()
RES=[0]*(N+1)
cnt = 0
for i in range(N, 0, -1):
    pt = 2*i
    sm = 0
    while pt <= N:
        sm += RES[pt]
        pt += i
    if (not sm & 1 and INL[i-1]) or (sm & 1 and not INL[i-1]):
        cnt += 1
        RES[i] = 1

print(cnt)
if cnt:
    for i in range(N+1):
        if RES[i]: print(i, end=' ')
    print('')


Measured memory_bytes: 65128
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long


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

    int n,m;cin >> n >> m;
    vector<int> a(n);

    for(int i = 0;i < n;i ++) cin >> a.at(i);

    sort(a.begin(),a.end(),greater<int>());

    int sum = 0;
    for(int i = 0;i < n;i ++){
        sum += a.at(i);
    }

    if(a.at(m-1) * 4 * m >= sum) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split())) + [0]

ans = 0
temp = 0
for i in range(N+1):
        if B[i] + temp > A[i]:
                temp = B[i] - max(A[i] -temp,0)
                ans += A[i]
        else:
                ans += B[i] + temp
                temp = 0
print(ans)

Measured memory_bytes: 18476
#include<iostream>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<cmath>

using namespace std;

int main(int argc, char const *argv[])
{
    char ch;
    int rec[26] = {};
    char str[1201];
    while(cin >> ch){
        ch = tolower(ch);
        if(isalpha(ch)) rec[ch - 'a']++;
    }

    for (int i = 0; i < 26; ++i)
    {
        printf("%c : %d\n",'a'+i,rec[i]);
    }

    return 0;
}

Measured memory_bytes: 1124
import math

inputs = input().split()
a, b, h, m = int(inputs[0]), int(inputs[1]), int(inputs[2]), int(inputs[3])

c = abs((h + m / 60) / 12 - m / 60) * 360
result = math.sqrt((a ** 2 + b ** 2) - (2 * a * b) * math.cos(math.radians(c)))
print(result)

Measured memory_bytes: 9396
#include <iostream>
#include <cassert>
#include <cstring>
#include <vector>
#include <string>


using namespace std;

vector<vector<long long int> > dp;
vector<vector<short> > dir;
string s1,s2;


long long int find(int i, int j){
    //cout << i << " " << j << "\n";
    if(dp[i][j]!=-1) return dp[i][j];

    else if(i==s1.length() && j==s2.length()){
        dp[i][j] = 0;
        dir[i][j] = 3;
        return dp[i][j];
    }
    else if(i==s1.length()){
        dp[i][j] = find(i,j+1);
        dir[i][j] = 0;
        return dp[i][j];
    }
    else if(j==s2.length()){
        dp[i][j] = find(i+1,j);
        dir[i][j] = 1;
        return dp[i][j];
    }
    else if(s1[i]==s2[j]){
        dp[i][j] = 1 + find(i+1,j+1);
        dir[i][j] = 2;
        return dp[i][j];
    }
    else{
        long long int dir0 = find(i,j+1);
        long long int dir1 = find(i+1,j);
        if(dir0 > dir1){
            dp[i][j] = dir0;
            dir[i][j] = 0;
        }
        else{
            dp[i][j] = dir1;
            dir[i][j] = 1;
        }
        return dp[i][j];
    }
}

int main(){
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int t;
    t=1;
    while(t--){
        cin >> s1 >> s2;
        int n1 = s1.length();
        int n2 = s2.length();
        //cout << "Read\t";
        dp = vector<vector<long long int>> (n1+1,vector<long long int> (n2+1,-1));
        dir = vector<vector<short>> (n1+1,vector<short> (n2+1,0));
        //cout << "done init\n"; 
        find(0,0);
        //cout << "done find\n";
        int i=0;
        int j=0;

        /*for(auto v : dp){*/
            //for(auto e : v){
                //cout << e << "\t";
            //}
            //cout << "\n";
        //}
        //cout << "\n";
        //for(auto v : dir){
            //for(auto e : v){
                //cout << e << "\t";
            //}
            //cout << "\n";
        //}


        vector<char> out;
        while(i<n1 && j<n2){
            switch(dir[i][j]){
                case 0:
                    j++;
                    break;
                case 1:
                    i++;
                    break;
                case 2:
                    out.push_back(s1[i]);
                    i++;
                    j++;
                    break;
            }
        }
        for(auto c : out) cout << c;
        cout << "\n";
    }
    return 0;
}



Measured memory_bytes: 91700
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int k[10010] = {};
	for (int n; cin >> n&&n;) {
		int cnt = 0;
		rep(i, 0, n) { cin >> k[i]; if (k[i])cnt++; }
		if (*max_element(k, k + n) <= 1) {
			cout << "NA" << endl;
			continue;
		}
		cout << cnt + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;





signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	int k; cin >> k;
	set<string>tmp;
	rep(i, s.size()) {
		for (int j = 1; j <= k && i + j <= s.size(); j++) {
			tmp.insert(s.substr(i, j));
		}
	}
	int now = 0;
	for (auto itr = tmp.begin(); itr != tmp.end(); itr++) {
		now++;
		if (now == k) {
			cout << *itr << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;


int N,A,B;
int pre[5005][2],res[5005];
int dp[5005][2];
int mod_pow(int x,int y,int m=mod){
	int res=1;
	while(y>0){
		if(y&1)(res*=x)%=m;
		(x*=x)%=m;
		y>>=1;
	}
	return res;
}
signed main(){
	cin>>N>>A>>B;
	if(A>B)swap(A,B);
	pre[0][0]=1;
	pre[0][1]=1;
	res[0]=1;
	rep(i,N){
		if(i)res[i]=(pre[i][0]+pre[i][1])%mod;
		REP(j,N-i+1){
			rep(k,2){
				if(!(!k&&j<A))(pre[i+j][k^1]+=pre[i][k])%=mod;
			}
		}
	}

	dp[0][0]=1;dp[0][1]=1;
	rep(i,N){
		REP(j,min(N-i+1,A))(dp[i+j][0]+=dp[i][1])%=mod;
		REP(j,min(N-i+1,B)){
			if(!i||i+j==N)
				(dp[i+j][1]+=dp[i][0]*res[j-1])%=mod;
			else
				(dp[i+j][1]+=dp[i][0]*(j==1?1:res[j-2]))%=mod;
		}
	}
	cout<<(mod_pow(2,N)-dp[N][0]-dp[N][1]+2*mod)%mod<<endl;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
int main() {
  
  int N,K;
  cin>>N>>K;
  
  vector<long long> H(N);
  for(int i=0;i<N;i++){
    cin>>H[i];
  }
  sort(H.begin(),H.end());
  
  long long ans=0;
  for(int i=0;i<N-K;i++){
    ans+=H[i];
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 4820
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
if N >= M:
    print(0)
    exit()
diff = []
for i in range(1, len(X)):
    diff.append(X[i]-X[i-1])
diff.sort(reverse=True)
total = sum(diff)
for i in range(N-1):
    total -= diff[i]
print(total)

Measured memory_bytes: 13960
solv xs = go xs [] 0 where
  go [] _ n = n
  go (x:xs) [] n = go xs [x] n
  go ('0':xs) ss@(s:ss') n
    | s=='0' = go xs ('0':ss) n
    | otherwise = go xs ss' (n+2)
  go ('1':xs) ss@(s:ss') n
    | s=='1' = go xs ('1':ss) n
    | otherwise = go xs ss' (n+2)

main = do
  s <- getLine
  print $ solv s


Measured memory_bytes: 7548
N = int(input())
H = list(map(int, input().split()))
ans = 0

while max(H) > 0:
    grp = [[]]
    for i, h in enumerate(H):
        if h == 0:
            if len(grp[-1]) > 0:
                grp.append([])
        else:
            grp[-1].append((i, h))
    for g in grp:
        if len(g) == 0:
            continue
        mi = min([h for _, h in g])
        ans += mi
        for i, _ in g:
            H[i] -= mi

print(ans)

Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod1 1000000007
#define mod2 1000000009
int getTheAnswer() {
    return 42;
}

using namespace std;
using ll=long long;

class DAlterAltar {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        int n;
        cin>>n;
        string s;
        cin>>s;
//        int a[n]={0};
        int r=0,w=0;
        int len=s.length();
        for (int i=0;i<len;i++){
            if (s[i]=='R'){
                r++;
//                a[i]=a[i-1];
            }
            else{
                w++;
            }
        }
        int cost=w,val=0;
        for (int i=len-w;i<len;i++){
            if (s[i]=='R'){
                val++;
            }
        }
        cout<<min(cost,val);
	}
};


int main() {
	DAlterAltar solver;
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3732
#include<math.h>
#define DATA 20

int main(){
	int data,i;
	double x1[DATA], x2[DATA], x3[DATA], y1[DATA], y2[DATA], y3[DATA];
	double a1[DATA], a2[DATA], b1[DATA], b2[DATA], c1[DATA], c2[DATA], px[DATA], py[DATA],r[DATA];

	scanf("%d", &data);

	for (i = 0; i < data; i++)
		scanf("%lf %lf %lf %lf %lf %lf", &x1[i], &y1[i], &x2[i], &y2[i], &x3[i], &y3[i]);

	for (i = 0; i < data; i++){
		a1[i] = 2 * (x2[i] - x1[i]);
		b1[i] = 2 * (y2[i] - y1[i]);
		c1[i] = pow(x1[i], 2) - pow(x2[i], 2) + pow(y1[i], 2) - pow(y2[i], 2);
		a2[i] = 2 * (x3[i] - x1[i]);
		b2[i] = 2 * (y3[i] - y1[i]);
		c2[i] = pow(x1[i], 2) - pow(x3[i], 2) + pow(y1[i], 2) - pow(y3[i], 2);

		px[i] = (b1[i] * c2[i] - b2[i] * c1[i]) / (a1[i] * b2[i] - a2[i] * b1[i]);
		py[i] = (c1[i] * a2[i] - c2[i] * a1[i]) / (a1[i] * b2[i] - a2[i] * b1[i]);
		

		r[i] = sqrt(pow(x1[i] - px[i], 2) + pow(y1[i] - py[i], 2));
	}

	for (i = 0; i < data; i++)
		printf("%.3f %.3f %.3f\n", px[i], py[i], r[i]);


	return 0;
}

Measured memory_bytes: 664
N =int(input())
List = []
for _ in range(N):
  A, B = map(int, input().split())
  List.append([A,B])
List = sorted(List,key=lambda x: x[1],reverse = True)
Limit = List[0][1]
for item in List:
  Limit = min(item[1],Limit) - item[0]
  if Limit < 0:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 39856
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  vector<int> a(n);
  vector<int> num(100001,0);
  rep(i,n){
    cin>>a[i];
    num[a[i]]++;
  }
  sort(a.begin(),a.end());
  int sum=0;
  rep(i,100001){
    if(num[i]>1){
      sum+=num[i]-1;
    }
  }
  int res=n;
  if(sum%2==0){
    res-=sum;
  }
  else{
    res-=sum+1;
  }
  cout<<res<<"\n";
  return 0;
}


Measured memory_bytes: 1792
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
d_min = 99999
ans = 0
for i in range(n):
    d = abs(t - a - h[i] * 0.006)
    if d < d_min:
        d_min = d
        ans = i + 1
print(ans)


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

int main() {
  
  long long H,N;
  cin >> H >> N;
  vector<long long> A(N);
  for(long long i=0;i<N;i++){
    cin >> A[i];
  }

  // sort(A.begin(),A.end());
  // reverse(A.begin(),A.end());

  for(long long i=0;i<N;i++){
    // cout << A[i] << " ";
    H-=A[i];
  }

  if(H>0){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x <<": "<<x<<"\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
//using template <class T>vec = vector<T>;
template <class T> using Vec = std::vector<T>;
template <class T = int> T in(){T x; cin>>x;return(x);}
template <class T > void print(T& x){cout<<x<<"\n";}
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N=in();
  cout <<3*N*N<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long long INF = 1e18;
//const ll mod = 1000000007;
ll N;
string S;
map<char, ll> mp;

int main() {
    cin >> N >> S;
    ll ans = 0;
    for(auto c : S) {
        mp[c]++;
    }
    ans = mp['R'] * mp['G'] * mp['B'];
    for(int i = 0; i < N; i++) {
        for(int j = 1; j <= N; j++) {
            ll a = i;
            ll b = i + j;
            ll c = b + j;
            if(c < N) {
                if(S[a] != S[b] and S[b] != S[c] and S[a] != S[c]) ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s ; cin>>s;
    int co = 0;
    for(int i = 0; i < s.size(); ++i)if(s[i] == 'o')co++;
    int baki = 15 - (int)s.size();
    puts((co + baki >= 8)?"YES":"NO");
}


Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    A = []
    for _ in range(M):
        a, b = map(int, input().split())
        A.append((a,b))

    sort_A = sorted(A)
    left = 0
    right = N
    cnt = 1
    for i in range(M):
        left = max(sort_A[i][0],left)
        right = min(sort_A[i][1], right)
        if left >= right:
            cnt += 1
            right = sort_A[i][1]

    print(cnt)


    



if __name__ == "__main__":
    main()

Measured memory_bytes: 55384
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int n; cin >> n;
	if (n == 1) {
		cout << " Hello World" << endl;
	}
	else {
		int a, b; cin >> a >> b;
		cout << a + b << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
	int N;
	cin >> N;
	int count = 0;
for(int i = 0; i < N; ++i){
		int l, r;
		cin >> l >> r;
		count += r - l + 1;
	}
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int a,b,c; cin>>a>>b>>c;
    if(a+b>=c) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define w(t) int t;cin>>t;while(t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int,int>
#define vi vector<int>
#define umapi unordered_map<int,int>
#define INF 1000000007
#define PI 3.14159265
const int mod=998244353;
using namespace std;
using namespace __gnu_pbds;

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

void FIO(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
}
bool cmp(int a, int b){
	return a>b;
}
int32_t main(){
	
	FIO();
	
		string s;cin>>s;
		if(s[2]==s[3]&&s[4]==s[5])
			cout<<"Yes";
		else
			cout<<"No";
	
	return 0;
	
		
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <math.h>

#define MAX 10000

int main(void){

  int A[MAX];
  int i,j;
  int count=0;
  int flag;
  int n=0;
  
  scanf("%d",&count);
  for(i=0;i<count;i++)
    scanf("%d",&A[i]);
  
  for(i=0;i<count;i++){
    flag=0;
    for(j=2;j<=sqrt(A[i]);j++){
      if(A[i] % j == 0){
	flag++;
	break;
      }
    }

    if(flag==0)
      n++;
  }
  printf("%d\n",n);

  return 0;

}

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

typedef long long int ll;
typedef vector<int> vi;            typedef vector<ll> vl;
typedef vector<vi> vvi;         typedef vector<vl> vvl;
typedef pair<int, int>     pii;    typedef pair<ll, ll> pll;
typedef vector<pii> vii;         typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 998244353
#define F first
#define S second
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define in insert
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
const ll INFL = 1e18;
const int INFI = 1e9;
#ifdef KARAN
    #include "../../trace.h"
#else
    #define trace(args...)
#endif

ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}
ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
    while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

void solve(){
    ll n; cin>>n;
    vl a(n); vl b(n);
    forn(i, n) cin>>a[i]>>b[i];
    sort(all(a));
    sort(all(b));
    if(n%2==1)
        cout<<b[n/2] - a[n/2] + 1<<endl;
    else
        cout<<b[n/2-1] + b[n/2] - a[n/2] - a[n/2-1] + 1<<endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifdef KARAN
        freopen("inp.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        freopen("err.txt", "w", stderr);
    #endif
    // init();
    int t=1;
    while(t--)
        solve();
}

Measured memory_bytes: 6368
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
#include<map>
#include<queue>

using namespace std;

int main(void) {
	int n;
	cin >> n;
	if (n % 2 == 0) {
		cout << (float)1 / 2 << endl;
	}
	else {
		cout << (float)((n + 1) / 2) / n << endl;
	}
	
	return 0;
}

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

using namespace std;

const int N=1e6+3;

const double eps=1e-9;

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef long long ll;

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

const int mod=1e9+7;

int n,a[N],b[N],m,k,q,u,v,x,y,tc,l,r,c,ans;

char s[N],grid[N];

void IO(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("test.txt","r",stdin);
	#endif
}

int cnt[2050];

int main(){
	//IO();
	scanf("%s",s);
	int n = strlen(s);
	reverse(s,s+n);
	cnt[0] = 1;
	ll ans = 0;
	ll pre = 0;
	int pw = 1;
	for(int i = 0 ; s[i] ; i++){
		pre = pre + (s[i]-'0') * pw;
		pre %= 2019;
		pw = pw * 10 % 2019;
		ans += cnt[pre]++;
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 3928
#include <iostream>


using namespace std;
int N, M;
const int MAX_N= 31, MAX_M = 31;
int K[MAX_M], A[MAX_N][MAX_M], B[MAX_M];

int main() {

	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> K[i];
		for (int j = 0; j < K[i]; j++) {
			cin >> A[i][j];
			B[A[i][j]-1]++;
		}
	}

	int ans = 0;
	for (int i = 0; i < M; i++) {
		if (B[i] == N) {
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
def  caracal(H):
    k = 0
    n_sum = 0
    while H >n_sum :
        n_sum += 2**k    
        # print("n_sum : k ",n_sum,k)
        k +=1
    
    return n_sum


H = input()
H = int(H)
# H =12
print(caracal(H))

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

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

    sort(a, a + N, greater<int>());
    int alice = 0;
    int bob = 0;
    for (int i = 0; i < N; ++i) {
        if (i % 2 == 0) {
            alice += a[i];
        }
        else {
            bob += a[i];
        }
    }
    cout << alice - bob << endl;
}


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

int main(){
    using namespace std;
    size_t N;
    cin >> N;
    string s;
    cin >> s;
    vector<unsigned long> A(N + 1), B(N + 1), C(N + 1);
    transform(s.begin(), s.end(), A.begin() + 1, [](auto c){return c == 'W';});
    transform(s.begin(), s.end(), B.begin(), [](auto c){return c == 'E';});
    partial_sum(A.begin(), A.end(), A.begin());
    partial_sum(B.rbegin(), B.rend(), B.rbegin());
    transform(A.begin(), A.end(), B.begin(), C.begin(), plus<>());
    cout << *min_element(C.begin(), C.end()) << endl;
}

Measured memory_bytes: 7684
#include <iostream>
#include <algorithm>

using namespace std;

int count;

int collatz(int n, int count){
  if(n == 1){
    return count;
  }
  else if(n % 2 == 0){
    return collatz(n / 2, count + 1);
  }
  else{
    return collatz(n * 3 + 1, count + 1);
  }
}


int main(){
  int n;


  while(true){
    cin >> n;
    if(!n) break;
    cout << collatz(n, 0) << endl;
  }

  return 0;
}
    

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

int main() {
  int n, k;
  cin >> n >> k;

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    ans += 2*min(x, (k-x));
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    cout << n * n * n << endl;


}

Measured memory_bytes: 256
a,b,c,d=input()
count=0

if(a==b):
    count+=1
    if(c==d and a!=c):
        count+=1
elif(a==c):
    count+=1
    if(b==d and a!=b):
        count+=1
elif(a==d):
    count+=1
    if(b==c and a!=b):
        count+=1

if(count==2):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int k = in.nextInt();
		String s = in.next();
		if(s.length()>k){
          String new_s = s.substring(0,k);
		System.out.println(new_s + "...");
		}else{
			System.out.println(s);
		}
	}
}


Measured memory_bytes: 38628
//#pragma warning disable

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

public class Test
{
    public static void Main()
    {
        var N = long.Parse(Console.ReadLine());

        var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

        var nums = new long[100010];  // 最初は -1, 最後が 10001

        foreach (var x in a)
        {
            nums[x + 1]++;
        }

        long max = 0;

        for (int i = 0; i < nums.Length - 2; i++)
        {
            max = Math.Max(max, nums[i] + nums[i + 1] + nums[i + 2]);
        }

        Console.WriteLine(max);

    }
}

Measured memory_bytes: 20064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define repr(i,n) for(int i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  
  vector<int> vec(n);
  string ans = "Yes";
  rep(i,n){
    int h;
    cin >> h;
    vec.at(i) = h;
  }
  
  repr(i,n){
    if(i == n-1) continue;
    if(vec.at(i) > vec.at(i+1) + 1){
      ans = "No";
      break;
    }
    if(vec.at(i) == vec.at(i+1) + 1){
      vec.at(i) -= 1;
    }
    
  }
  
  cout << ans << endl;
}



Measured memory_bytes: 640
n, x, y = map(int, input().split())
x -= 1
y -= 1

def main():
    ans = {}
    for i in range(1, n):
        ans[i] = 0

    for i in range(0, n - 1):
        for j in range(i + 1, n):
            ans[solve(i, j)] += 1

    for k in range(1, n):
        print(ans[k])

def solve(i, j):
    """
    最短距離を計算する
    O(1)
    """

    dist = min(abs(i - j), abs(x - i) + abs(y - j) + 1, abs(y  -i) + abs(x - j) + 1)

    return dist

if __name__ == '__main__':
    main()

Measured memory_bytes: 48092
//بسم الله الرحمن الرحيم
//* In The Name 0f ALLAH *//* The Most Beneficent *//* The Most Merciful *//*
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define el << endl
#define PI 3.141592653589793238
#define _test_ int t; cin >> t; while(t--)
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define file() freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }
int dx[]={0,0,+1,-1,+1,-1,-1,+1};
int dy[]={+1,-1,0,0,+1,-1,+1,-1};
///*......................*//* LET'S BEGIN (-_^) *//*............................///
const int mx=1e5+123;
ll b,ans;

void _case_()
{
    int k;
    cin >> k;
    for(int i=1;i<=k;i++)
        for(int j=1;j<=k;j++)
            for(int p=1;p<=k;p++)
                ans+=__gcd(i,__gcd(j,p));
    cout << ans el;
}

int main()
{
    //file();
    optimize();
    //_test_
        _case_();

    return 0;
}

///////////*  N A Y E M  *///////////

Measured memory_bytes: 3668
#include <stdio.h>
#include <math.h>
 
int main(void)
{
    float x1, y1, x2, y2, x3, y3;
    float a, b, c;
    float xp, yp, r;
    float S;
    int n;
     
    scanf("%d", &n);
     
    while (n){
        scanf("%f %f %f %f %f %f", &x1, &y1, &x2, &y2, &x3, &y3);
         
        a = (x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1);
        b = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
        c = (x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2);
        a = sqrt(a);
        b = sqrt(b);
        c = sqrt(c);
        r = a * b * c;   
        r /= sqrt( (a+b+c) * (-a+b+c) * (a-b+c) * (a+b-c) );
        xp = ((y1 - y3) * (y1 * y1 - y2 * y2 + x1 * x1 -x2 * x2) - (y1 - y2) * (y1 * y1 - y3 * y3 + x1 * x1 - x3 * x3)) / (2 * (y1 - y3) * (x1 - x2) -2 * (y1 - y2) * (x1 - x3));
        yp = ((x1 - x3) * (x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2) - (x1 - x2) * (x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3)) / (2 * (x1 - x3) * (y1 - y2) -2 * (x1 - x2) * (y1 - y3));
         
        printf("%.3f %.3f %.3f\n", xp, yp, r);
        n--;
    }
    return (0);
}

Measured memory_bytes: 660
/** Author: Dwai
 *  Omae wa mou shindeiru!
**/

#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define fr(i,a,b) for (i = a; i <= b; i++)
#define frr(i,a,b) for (i = a; i >= b; i--)
#define rep(i,n) for (i = 0 ; i < n; i++)
#define repr(i,n) for (i = n - 1; i >= 0; i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define flushinput   cin.ignore(numeric_limits<streamsize>::max(),'\n');

void debug_out() { cerr << endl; }

void clock_out(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}

void fileio(){
  freopen("/home/dwai/Desktop/cp/input.txt","r", stdin);
  freopen("/home/dwai/Desktop/cp/output.txt", "w", stdout);
  freopen("/home/dwai/Desktop/cp/debug.txt", "w", stderr);
}

void ofileio(){
  freopen("input.txt","r", stdin);
  freopen("output.txt", "w", stdout); 
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define fio() fileio()
#define ofio() fileio()
#define clock() clock_out()
#else
#define debug(...) 42
#define fio() 42
#define ofio() ofileio()
#define clock() 42
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef map<ll,ll> mll;

int IT_MAX = 1 << 20;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

void solve(){
	string s,t;
	cin>>s>>t;

	ll n=s.length();
	ll m=t.length();

	ll dp[n+1][m+1];
	memset(dp,0,sizeof(dp));

	ll i,j;
	fr(i,1,n)
	{
		fr(j,1,m)
		{
			if(s[i-1]==t[j-1])
			{
				dp[i][j]=1+dp[i-1][j-1];
			}
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	i=n,j=m;
	string res="";

	while(i>0 && j>0)
	{
		if(dp[i][j]==dp[i-1][j])
		{
			i--;
		}
		else if(dp[i][j]==dp[i][j-1])
		{
			j--;
		}
		else
		{
			i--;
			j--;
			res+=s[i];
		}
	}

	reverse(all(res));

	cout<<res;
}

int main(){
	//fio();
	fast

	solve();
	return 0;
}

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

using ll = long long;

#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl

#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 all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

set<ll> primes;
vector<bool> is_prime;

const int N_MAX = 100000;

void era(int n) {
  int p = 0;
  is_prime.resize(n + 1, true);
  is_prime.at(0) = false;
  is_prime.at(1) = false;
  for (int i = 2; i <= n; i++) {
    if (is_prime.at(i)) {
      primes.insert(i);
      for (int j = 2 * i; j <= n; j += i) is_prime.at(j) = false;
    }
  }
}

void solve(ll Q, std::vector<ll> l, std::vector<ll> r) {
  vector<int> c(N_MAX + 2);

  era(N_MAX);
  for (int i = 3; i <= N_MAX; i += 2) {
    if (is_prime.at(i) && is_prime.at((i + 1) / 2)) c.at(i)++;
  }
  for (int i = 3; i <= N_MAX; i++) {
    c.at(i) += c.at(i - 1);
  }

  rep(i, Q) { cout << c.at(r.at(i)) - c.at(l.at(i) - 1) << endl; }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll Q;
  scanf("%lld", &Q);
  std::vector<ll> l(Q);
  std::vector<ll> r(Q);
  for (int i = 0; i < Q; i++) {
    scanf("%lld", &l[i]);
    scanf("%lld", &r[i]);
  }
  solve(Q, std::move(l), std::move(r));
  return 0;
}


Measured memory_bytes: 5540
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**1
gosa = 1.0 / 10**9
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    a,b,c,d = LI()
    t = min(b,d) - max(a,c)
    if t > 0:
        return t

    return 0



print(main())



Measured memory_bytes: 5588
include Math

until (n = $<.gets.to_i).zero?
  points = Array.new(n) { Complex(*$<.gets.split(",").map(&:to_f))  }
  ym = points.map(&:imaginary).max
  start_po = po0 = points.find {|po| po.imaginary == ym}
  prev_arg = PI
  result = loop do
    points = (points - [start_po] + [po0]).uniq
    idx = points.map.with_index {|po, i| [po - start_po, i]}
      .reject {|pos| pos.first == 0}
      .sort_by {|pos| a = pos.first.angle + PI - prev_arg; a >= 0 ? a : a + 2 * PI}
      .first.last
    selected = points[idx]
    points.select! {|po| po != start_po}
    if selected == po0
      break points.size - 1
    else
      prev_arg = (selected - start_po).angle + PI
      start_po = selected
    end
  end
  puts result
end


Measured memory_bytes: 7020
#include <stdio.h>

int n, A[50];

// 入力値のMから選んだ要素を引いていく再帰関数
int solve(int i, int m) {
    if(m==0) return 1;
    if(i>=n) return 0;
    int res = solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}

int main(void) {
    int q, M, i;

    scanf("%d", &n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);
    scanf("%d",&q);
    for(i=0;i<q;i++) {
        scanf("%d", &M);
        if(solve(0,M)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 2068
#include <bits/stdc++.h>
//#define int long long

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

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

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

    int n; cin >> n;
    LL ans = 1;
    REP(i, n){
        LL t;
        cin >> t;
        ans = ans / __gcd(ans, t) * t;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b;   //a,bは新しい予約の開始時刻と終了時刻
    int N;      //元々ある予約の個数
    int s[100], f[100];
    //while(true){
        int c=0;
        cin >> a >> b;
        cin >> N;
        for(int i=0; i<N; i++){
            cin >> s[i] >> f[i];
            if((s[i]<=a&&a<f[i])||(s[i]<b&&b<f[i])||(a<=s[i]&&f[i]<=b))
                c++;
        }
        if(c>=1)
            cout << "1" << endl;
        else
            cout << "0" << endl;
    //}

}


Measured memory_bytes: 3100
unuse = gets.chomp.to_i
sum = 0
ans = 0
gets.chomp.split.map do |i|
  i = i.to_i
  ans += (sum * i)
  sum += i
end
# sum = 0
# (s-1).times do |cnt|
#   sum += num[cnt]*num[cnt+1..s-1].sum
# end
#puts sum % (7 + 10**9)
puts ans % (7 + 10**9)

Measured memory_bytes: 35856
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt(), D = sc.nextInt();
		System.out.println(Math.max(0, Math.min(B, D) - Math.max(A, C)));
	}
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
int main(){
    int n; cin >> n;
    vector<long> a(n), b(n);
    REP (i, n) cin >> a[i] >> b[i];
    long ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (b[i] > 1) {
            a[i] += ans;
            if (a[i] % b[i] != 0) ans += b[i] - a[i] % b[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>

int main()
{
	int n;
	std::cin >> n;
	
	int *R = new int[n];
	
	for (int t=0; t<n; t++) {
		std::cin >> R[t];
	}
	int max_profit = R[1] - R[0];
	int min = R[0], max = R[0];
	for (int i=1; i<n ;i++) {
		if (R[i] - R[i-1] < 0) {
			if (min > R[i]) min = max = R[i];
			if (max_profit < R[i] - R[i-1]) max_profit = R[i] - R[i-1];
		}
		else {
			if (max < R[i]) max = R[i];
			if (max_profit < R[i] - min) max_profit = R[i] - min;
		}
	}
	std::cout << max_profit << std::endl;
	
	delete[] R;
	
	return 0;
}




Measured memory_bytes: 3632
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <stack>
using namespace std;
typedef long long int lli;
const long long int MaxN=200005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
	lli dp[1005][1005];
	char mat[1005][1005];
	void solve(){
		lli N,M,i,j,p,q;
		cin>>N>>M;
		for(i=1;i<=N;i++){
			for(j=1;j<=M;j++){
				cin>>mat[i][j];
			}
		}	
		dp[1][1]=1;
		for(i=1;i<=N;i++){
			for(j=1;j<=M;j++){
				if(mat[i][j]=='#')continue;
				if(i==1&&j==1)continue;
				dp[i][j]=dp[i-1][j]+dp[i][j-1];
				dp[i][j]=dp[i][j]%mod;
			}
		}
		cout<<dp[N][M]<<"\n";
	}
int main(){
	//cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,j,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
	
}


Measured memory_bytes: 12196
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int A, B;

int main(){
    cin >> A >> B;
    
    if (A == 1 && B == 2) {
      cout << "3";
    } else if (A == 1 && B == 3) {
      cout << "2";
    } else if (A == 2 && B == 1) {
      cout << "3";
    } else if (A == 2 && B == 3) {
      cout << "1";
    } else if (A == 3 && B == 1) {
      cout << "2";
    } else {
      cout << "1";
    }
    return 0;
}


Measured memory_bytes: 256
n=int(input())
s=input()
ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            flag=[0,0,0]
            for index in range(n):
                if flag[0]==0 and flag[1]==0 and  s[index]==str(i):
                    flag[0]=1
                elif flag[0]==1 and flag[1]==0 and s[index]==str(j):
                    flag[1]=1
                elif flag[0]==1 and flag[1]==1 and s[index]==str(k):
                    ans+=1
#                     print(i,j,k)
                    break
                else:
                    continue
print(ans)

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

int main() {
	int N = 0, W = 0, S = 0, E = 0;
	string s;
	cin >> s;

	rep(i, s.size()) {
		if (s[i] == 'N') N++;
		else if (s[i] == 'W') W++;
		else if (s[i] == 'S') S++;
		else if (s[i] == 'E') E++;
	}

	if ((N + S == 0 || N >= 1 && S >= 1) && (W + E == 0 || W >= 1 && E >= 1))
		cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256