akhauriyash/Code-Regression huggingface dataset:
import math

N = int(input())
A = list(map(int, input().split()))

mod = 10**9+7

primes = [0]*(10**6+1)

def prime_fac(n):
  temp = n
  Flag = True
  for i in range(2, int(math.sqrt(n)) + 1):
    if temp % i == 0:
      cnt = 0
      while temp % i == 0:
        cnt += 1
        temp //= i
      primes[i] = max(primes[i], cnt)
      Flag = False
  if temp != 1:
    primes[temp] = max(primes[temp], 1)
  if Flag:
    primes[n] = max(primes[n], 1)

for a in A:
  prime_fac(a)

LCM = 1
for p, i in enumerate(primes):
  if i:
    LCM *= pow(p, i, mod)
    LCM %= mod

ans = 0
for a in A:
  ans += LCM * pow(a, mod-2, mod) % mod
  ans %= mod

print(ans)

Measured memory_bytes: 77364
import gc
n, k = map(int, input().split())
k2 = k * 2
b = [[0] * (k * 3) for _ in range(k * 3)]
for i in range(n):
    x, y, c = input().split()
    x = int(x) % k2
    y = int(y) % k2
    if c == 'W':
        x = (x + k) % k2

    b[x][y] += 1
    if x < k:
        b[x + k2][y] += 1
    if y < k:
        b[x][y + k2] += 1
    if x < k and y < k:
        b[x + k2][y + k2] += 1

b_cs = [[0] * (k * 3 + 1) for _ in range(k * 3 + 1)]
for i in range(k * 3):
    for j in range(k * 3):
        b_cs[i + 1][j +
                    1] = b_cs[i + 1][j] + b_cs[i][j + 1] - b_cs[i][j] + b[i][j]


def func_b(x, y):
    return b_cs[x + k][y + k] - b_cs[x + k][y] - b_cs[x][y + k] + b_cs[x][y]


# print('black')
# print(*b, sep='\n')
# print(*b_cs, sep='\n')

ans = 0
for i in range(k):
    for j in range(k):
        cand = 0
        cand += func_b(i, j)
        cand += func_b(i + k, j + k)
        # print(i, j, cand)
        ans = max(ans, cand)

        cand = 0
        cand += func_b(i + k, j)
        cand += func_b(i, j + k)
        # print(i, j, cand)
        ans = max(ans, cand)

print(ans)


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

int main() {
 long long d[21][21],y1,y2,c1,d1;
 int i,j,k,m,n,a1,b1,x1,x2;
 cin >> n;
 for (i=1;i<=n;i++) for (j=1;j<=n;j++) if (i==j) d[i][j]=0; else d[i][j]=99999999999999;
 cin >> m;
 for (i=0;i<m;i++) {
	 scanf("%d,%d,%lld,%lld",&a1,&b1,&c1,&d1);
     d[a1][b1]=c1; d[b1][a1]=d1;
 }
 scanf("%d,%d,%lld,%lld",&x1,&x2,&y1,&y2);
 for (k=1;k<=n;k++) for (i=1;i<=n;i++) for (j=1;j<=n;j++) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
 cout << y1-y2-d[x1][x2]-d[x2][x1] << endl;
 return 0;	
}

Measured memory_bytes: 1236
n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

sum = a.inject(:+)
cnt = 0
a.each do |num|
  if num >= sum / (4 * m).to_f
    cnt += 1
  end
end
if cnt >= m
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<string> W(N);
  for(int i=0;i<N;i++){
    cin>>W.at(i);
  }
  bool ok = true;
  for(int i=0;i+1<N;i++){
    string s = W.at(i);
      string t = W.at(i+1);
    for(int j=i+1;j<N;j++){
      if(W.at(i)==W.at(j) || s.at(s.size()-1)!=t.at(0)){
        ok = false;
      }
    }
  }
  if(ok){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
int main()
{
 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ld a,b,n;
  cin>>a>>b>>n;
  if(b<=n)
  {
      cout<<(long long int)(floor((a*(b-1))/b)-floor((b-1)/b)*a)<<'\n';
  }
  else
  {
      cout<<(long long int)(floor((a*(n))/b)-floor((n)/b)*a)<<'\n';
  }
   
   
  return 0;
}

Measured memory_bytes: 3800
#!/usr/bin/env python3
#B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b,c,d = LI()
if math.ceil(c / b) <= math.ceil(a / d):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 65628
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }

int main() {
  int n,w; cin >>n >>w;
  vector<ll> weight(n), value(n);
  rep(i, n) cin >>weight.at(i) >>value.at(i);
  vector<vector<ll>> dp(n+1, vector<ll>(w+1, 0));

  for (int i=0; i<n; i++){
    for (int j=0; j<=w; j++){
      chmax(dp.at(i+1).at(j), dp.at(i).at(j));
      if (j + weight.at(i) <= w) chmax(dp.at(i+1).at(j+weight.at(i)), dp.at(i).at(j) + value.at(i));
    }
  }

  cout <<dp.at(n).at(w) <<endl;
}

Measured memory_bytes: 80256
h, w = map(int, input().split())


def solve_ll(a, b):
    x, y = divmod(a, 3)
    X = [x]*3
    for i in range(y):
        X[i] += 1
    s1, s2, s3 = map(lambda x: x*b, X)
    return s1-s3


def solve_T(a, b):
    INF = 10**18
    res = INF
    for x in (b//3, -(-b//3)):
        s1 = x*a
        y = b-x
        x1, x2 = a//2, (a+1)//2
        s2, s3 = x1*y, x2*y
        Ss = (s1, s2, s3)
        res = min(res, max(Ss)-min(Ss))
    return res


ans = min(solve_T(h, w), solve_T(w, h), solve_ll(h, w), solve_ll(w, h))
print(ans)


Measured memory_bytes: 9220
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


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

	ll N, K, R, S, P;
	string T;
	cin >> N >> K >> R >> S >> P >> T;
	
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		if (i < K) {
			if (T[i] == 'r')ans += P;
			if (T[i] == 's')ans += R;
			if (T[i] == 'p')ans += S;
		}
		else {
			if (T[i] == T[i - K]) {
				T[i] = 'Z';
				continue;
			}
			else {
				if (T[i] == 'r')ans += P;
				if (T[i] == 's')ans += R;
				if (T[i] == 'p')ans += S;
			}
		}
	}
	puts(ans);

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
    cin>>n;
    
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    
    int dp[n];
    
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1] + abs(a[i]-a[i-1]), dp[i-2] + abs(a[i]-a[i-2]));
    }
    
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 4364
#include <iostream>
using namespace std;
int main() {

    int a,b,big;
    cin>>a>>b;
    int add=a+b;
    int m=a*b;
    int s=a-(b);
    if (add>m&&add>s)
    {big=add;}
    else if (m>s&&m>add)
    {big=m;}
    else if (s>add&&s>m)
    {big=s;}
    cout<<big;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>

//#define int long long

using namespace std;

void Main()
{
	int N, A, B;
	cin >> N >> A >> B;
	cout << min(A * N, B) << endl;
}

int32_t main()
{
	Main();
	return 0;
}

/*
void sample()
{
	vector<int> v;
	sort(v.begin(), v.end());
	sort(v.begin(), v.end(), greater<int>());

}
*/



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

int main() {
  int a,b,x,y;
  cin>>a>>b>>x>>y;
  x-=a;
  y-=b;
  rep(i,x) cout<<"R";
  rep(i,y) cout<<"U";
  rep(i,x) cout<<"L";
  rep(i,y+1) cout<<"D";
  rep(i,x+1) cout<<"R";
  rep(i,y+1) cout<<"U";
  cout<<"LU";
  rep(i,x+1) cout<<"L";
  rep(i,y+1) cout<<"D";
  cout<<"R";
  
}


Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

ll func(vl &A, vvvl &DP, ll s, ll e, ll now) {
  if (s == e) {
    return A[s] * ((now * 2) - 1);
  } else if (DP[s][e][now] != llINF)
    return DP[s][e][now];
  else if (now == 1) {
    return DP[s][e][now] = max(func(A, DP, s + 1, e, 0) + A[s],
                               func(A, DP, s, e - 1, 0) + A[e]);
  } else {
    return DP[s][e][now] = min(func(A, DP, s + 1, e, 1) - A[s],
                               func(A, DP, s, e - 1, 1) - A[e]);
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vector<ll> A(N);
  vvvl DP = VVVL(N + 1, N + 1, 2, llINF);
  REP(i, N) {
    ll a;
    cin >> a;
    A[i] = a;
  }
  cout << func(A, DP, 0, N - 1, 1) << endl;

  return 0;
}


Measured memory_bytes: 493696
#include<stdio.h>

int main(){
    int x,y,z = 0;
    scanf("%d%d",&x,&y);
    int a[x];
    for(int i = 0;i < x;i++){
        scanf("%d",&a[i]);
    }
    for(int i = 0;i < x;i++){
        for(int j = x - 1;j > i;j--){
            if(a[j] < a[j - 1]){
                z = a[j];
                a[j] = a[j - 1];
                a[j - 1] = z;
            }
        }
    }
    int max = 0;
    for(int i = 0;i < x;i++){
        if(y < a[i]) break;
        else if(i == x - 1 && y != a[i]) break;
        y -= a[i];
        max++;
    }
    printf("%d\n",max);
}

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

typedef long long LL;

const int N = 3e5;
const LL MOD = 1e9+7;

inline LL dmod(LL x){
	return x%MOD;
}

LL fakto[N+5];

void pre(){
	fakto[0] = 1LL;
	for(int i=1;i<=N;i++){
		fakto[i] = dmod(fakto[i-1]*(LL)(i));
	}
	return;
}

LL fe(LL x, LL y){
	if(y==0) return 1LL;
	LL ret = fe(x,y/2);
	ret = dmod(ret*ret);
	if(y&1){
		ret = dmod(ret*x);
	}
	return ret;
}

LL nCr(LL x, LL y){
	LL tmp = dmod(fakto[y]*fakto[x-y]);
	tmp = fe(tmp,MOD-2);
	tmp = dmod(tmp*fakto[x]);
	return tmp;
}

LL step(int x, int y, int a, int b){
	int dx = a-x;
	int dy = b-y;
	int tot = dx+dy;
	return nCr(tot,dx);
}

int h,w,a,b;
int main(){
	pre();
	cin >> h >> w >> a >> b;
	LL ret = 0LL;
	for(int i=1;i<=h-a;i++){
		LL tmp = step(1,1,i,b);
		tmp = dmod(tmp*step(i,b+1,h,w));
		ret = dmod(ret+tmp);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int INT_MAX_SQRT = sqrt(INT_MAX);
int pwi(int x, int p) {
    if (p == 0) return 1;
    if (p == 1) return x;
    int tmp = pwi(x, p / 2);
    if (tmp > INT_MAX_SQRT) return 0;  // overflow
    if (p % 2 == 0)
        return tmp * tmp;
    else
        return tmp * tmp * x;
}

long LONG_MAX_SQRT = sqrt(LONG_MAX);
long pwl(long x, long p) {
    if (p == 0) return 1;
    if (p == 1) return x;
    long tmp = pwl(x, p / 2);
    if (tmp > LONG_MAX_SQRT) return 0;  // overflow
    if (p % 2 == 0)
        return tmp * tmp;
    else
        return tmp * tmp * x;
}

using P = pair<long, int>;

int main() {
    long A;
    double B;
    cin >> A >> B;
    long b = B * 100 + 0.5;

    cout << A * b / 100 << endl;

    return 0;
}


Measured memory_bytes: 3708
#include <iostream>

using namespace std;

int main() {

  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;
    int t;

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

      cin >> t;

      if(t < 10) a[0]++;
      else if(t < 20) a[1]++;
      else if(t < 30) a[2]++;
      else if(t < 40) a[3]++;
      else if(t < 50) a[4]++;
      else if(t < 60) a[5]++;
      else a[6]++;

    }

    for(int i=0;i<7;i++) {

      cout << a[i] << endl;

    }


  }

  return 0;

}

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

int main(){
    int a;
    int b;
    char op;
    
    while(1){
        cin >> a >> op >> b;
        
        if (op == '+'){
            cout << a + b <<endl;
        }
        else if (op == '-'){
            cout << a - b <<endl;
        }
        else if (op == '*'){
            cout << a * b <<endl;
        }
        else if (op == '/'){
            cout << a / b <<endl;
        }
        else if (op == '?')break;
        
    }
    
    return 0;
}


Measured memory_bytes: 3056
def resolve():
    '''
    code here
    '''
    L, R = [int(item) for item in input().split()]
    aL, bL = divmod(L, 2019)
    aR, bR = divmod(R, 2019)

    if bL == 0:
        res = 0
    elif aL < aR:
        res = 0
    elif aL == aR:
        res = 2019
        for i in range(bL,bR):
            for j in range(bL+1,bR+1):
                res = min(res, i*j%2019)

    print(res)
if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3064
#include <iostream>

int main() {
  int A, B, C;
  std::cin >> A >> B >> C;
  if(A > B + C) {
    std::cout << 0 << std::endl;
  } else {
    std::cout << (B + C) - A << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long  n,m,sum;
	cin>>n>>m;
	if(n>m/2) 
	{
		cout<<m/2<<endl;
		return 0;
	}
	sum+=n;
	m-=2*n;
	sum+=m/4;
	cout<<sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N;
  if(N&1)Out(0);
  else{
    lli k=10;
    while(N>=k){
      sum+=N/k;
      k*=5;
    }
    Out(sum);
  }
}

Measured memory_bytes: 256
while True:
    n,k=map(int,input().split())
    if n==0 and k==0:
        break
    x=[]
    for i in range(n):
        x.append(int(input()))
    s=sum(x[0:k])
    max=s
    for i in range(k,n):
        s=int(s+x[i]-x[i-k])
        if max<s:
            max=s
    print(max)


Measured memory_bytes: 9868
using System;

namespace agc024_b
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			int[] x = new int[n];
			for (int i = 0; i < n; i++)
			{
				x[int.Parse(Console.ReadLine()) - 1] = i;
			}
			int max = 1; int len = 1;
			for (int i = 1; i < n; i++)
			{
				if (x[i] > x[i - 1]) len++;
				else { max = Math.Max(max, len); len = 1; }
			}
			Console.WriteLine(n - Math.Max(max, len));
		}
	}
}

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


int main() {
    int n, k, ans = 0;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++)cin >> a.at(i);
    sort(a.begin(), a.end());
    for (int i = 0; i < k; i++) {
        ans += a.at(i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long[] list = new long[n];

        int odd = 0;
        int even = 0;
        int four = 0;

        for (int i = 0; i < n; i++) {
            list[i] = sc.nextLong();
            if (list[i] % 2 == 0) {
                if (list[i] % 4 == 0) {
                    four++;
                } else {
                    even++;
                }
            } else {
                odd++;
            }
        }

        if (n % 2 == 0) {
            System.out.println(four >= odd ? "Yes" : "No");
        } else {
            System.out.println(four >= odd - 1 ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 50384
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int l,r;
bool flag[100010];
int cnt[100010];
int main(){
	memset(cnt,0,sizeof(cnt));
	flag[0]=1;
	flag[1]=1;
	for(int i=2;i<=100000;i++){
		if(!flag[i]){
			for(int j=i+i;j<=100000;j+=i){
				flag[j]=1;
			}
		}
	}
	for(int i=2;i<=100000;i++){
		if(!flag[i]&&!flag[(i+1)/2]){
			cnt[i]=cnt[i-1]+1;
		}
		else cnt[i]=cnt[i-1];
	}
	int t;
	cin>>t;
	while(t--){
		int l,r;
		cin>>l>>r;
		cout<<cnt[r]-cnt[l-1]<<endl;
	}
	return 0;
}


Measured memory_bytes: 4120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    int N;
    cin >> N;
    vector<bool> flag(10010,false);
    for(int i=2;i*i<10001;i++) flag[i*i]=true;
    For(n,1,N+1){
        ll cnt=0;
        for(int a=1;a*a<n;a++){
            for(int b=1;a*a+a*b+b*b<n;b++){
                for(int c=sqrt(n-(a*a+a*b+b*b));a*a+a*b+b*b+a*c+b*c+c*c>=n;c--){
                    if(a*a+a*b+b*b+a*c+b*c+c*c==n){
                        cnt++;
                        //cout << n << " " << a << " " << b << " " << c;
                        break;
                    }
                }
            }
        }
        cout << cnt << endl;
    }
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 3492
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;
using System.Threading;

class Program
{
    static void Main(string[] args)
    {
        int[] arr = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        int h = arr[0];
        int w = arr[1];
        int[] dh = { 0, 1, 0, -1 };
        int[] dw = { -1, 0, 1, 0 };
        var ans = 0;
        var list = new List<char[]>();
        for(int i = 0; i < h; i++)
        {
            list.Add(Console.ReadLine().ToCharArray());
        }
        for(int i = 0; i < h; i++)
        {
            for(int j = 0; j < w; j++)
            {
                if (list[i][j] == '#') continue;
                var res = 0;
                var que = new Queue<(int h, int w, int dis)>();
                bool[,] boolMap = new bool[h, w];
                que.Enqueue((i, j, 0));
                boolMap[i, j] = true;
                while (que.Count() > 0)
                {
                    var nq = que.Dequeue();
                    for(int k = 0; k < 4; k++)
                    {
                        int nh = nq.h + dh[k];
                        int nw = nq.w + dw[k];
                        res = Math.Max(res, nq.dis);
                        if(0<=nh && nh < h && 0 <= nw && nw < w)
                        {
                            if (boolMap[nh, nw] || list[nh][nw] == '#') continue;
                            que.Enqueue((nh, nw, nq.dis + 1));
                            boolMap[nh, nw] = true;
                        }
                    }

                }
                ans = Math.Max(ans, res);
            }
        }
        Console.WriteLine(ans);
       
    }

  



}

   

Measured memory_bytes: 28620
#include <algorithm>
#include <cassert>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
#include <tuple>

using namespace std;


typedef pair<int, int> Location;
typedef queue<Location> LocationQueue;

LocationQueue que;

#define N 1000
char field[N][N];
int levels[N][N] = {0};
bool visited[N][N] = {false};

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

int solve(int h, int w) {
  /*
  cout << h << " " <<  w << " " << endl;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cout << field[i][j];
    }
    cout << endl;
  }
  */
  Location loc;
  int i0, j0, i, j, level;
  int max_level = 0;

  while(que.size()){
    loc = que.front(); que.pop();
    i0 = loc.first; j0 = loc.second;
    level = levels[i0][j0];

    if (i0 > 0){
      i = i0 - 1;
      j = j0;
      if(!visited[i][j]
          && (field[i][j] == '.'))
      {
        field[i][j] = '#';
        visited[i][j] = true;
        que.push(make_pair(i,j));
        levels[i][j] = level + 1;
        max_level = max(max_level, level+1);
      }
    }
    if (i0 < h - 1){
      i = i0 + 1;
      j = j0;
      if(!visited[i][j]
          && (field[i][j] == '.'))
      {
        field[i][j] = '#';
        visited[i][j] = true;
        que.push(make_pair(i,j));
        levels[i][j] = level + 1;
        max_level = max(max_level, level+1);
      }
    }
    if (j0 > 0){
      i = i0;
      j = j0 - 1;
      if(!visited[i][j]
          && (field[i][j] == '.'))
      {
        field[i][j] = '#';
        visited[i][j] = true;
        que.push(make_pair(i,j));
        levels[i][j] = level + 1;
        max_level = max(max_level, level+1);
      }
    }
    if (j0 < w - 1){
      i = i0;
      j = j0 + 1;
      if(!visited[i][j]
          && (field[i][j] == '.'))
      {
        field[i][j] = '#';
        visited[i][j] = true;
        que.push(make_pair(i,j));
        levels[i][j] = level + 1;
        max_level = max(max_level, level+1);
      }
    }

//    for(int n = 0; n < 4; n++){
//        i = i0 + dx[n];
//        j = j0 + dy[n];
//
//        if (i >= 0 && i <= h - 1 && j >= 0 && j <= w -1 &&
//            !visited[i][j]
//            && (field[i][j] == '.'))
//        {
//          field[i][j] = '#';
//          visited[i][j] = true;
//          que.push(make_pair(i,j));
//          levels[i][j] = level + 1;
//          max_level = max(max_level, level+1);
//        }
//    }
  }

  return max_level;
}

int main(int argc, char const *argv[]) {
  int h, w;
  char c;

  cin >> h;
  cin >> w;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> c;
      field[i][j] = c;
      if (c == '#') {
        que.push(make_pair(i, j));
        visited[i][j] = true;
      }
    }
  }

  cout << solve(h, w);

  return 0;
}


Measured memory_bytes: 11008
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		for (;;) {
			int n = sc.nextInt();
			if (n == 0)
				return;
			HashMap<String, Integer> stoi = new HashMap<String, Integer>();
			HashMap<Integer, String> itos = new HashMap<Integer, String>();
			for (int i = 0; i < n; i++) {
				String s = sc.next();
				int p = sc.nextInt();
				stoi.put(s, p);
				itos.put(p, s);
			}

			int m = sc.nextInt();
			HashMap<String, ArrayList<String>> mix = new HashMap<String, ArrayList<String>>();
			for (int i = 0; i < m; i++) {
				String s = sc.next();
				int o = sc.nextInt();
				ArrayList<String> l = new ArrayList<String>();
				for (int j = 0; j < o; j++)
					l.add(sc.next());
				mix.put(s, l);
			}

			for (int i = 0; i < 2; i++) {
				for (int j = 0; j < m; j++) {
					for (String key : mix.keySet()) {
						int cost = 0;
						for (int k = 0; k < mix.get(key).size(); k++) {
							cost += stoi.get(mix.get(key).get(k));
						}
						if (cost < stoi.get(key)) {
							stoi.put(key, cost);
						}
					}
				}
			}
			System.out.println(stoi.get(sc.next()));
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 36884
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
class Dice {
	int a[7];
public:
	Dice(int b,int c,int d,int e,int f,int g) {
		a[1] = b, a[2] = c, a[3] = d, a[4] = e, a[5] = f, a[6] = g;
	}
	void roll(string s) {
		for (int i = 0; i < s.size(); i++) {
			int k = a[1];
			switch (s[i]) {
			case 'E':
				a[1] = a[4], a[4] = a[6], a[6] = a[3], a[3] = k;
				break;
			case 'N':
				a[1] = a[2], a[2] = a[6], a[6] = a[5], a[5] = k;
				break;
			case 'W':
				roll("E"); roll("E"); roll("E");
				break;
			case 'S':
				roll("N"); roll("N"); roll("N");
				break;
			}
		}
	}
	void print_top() {
		cout << a[1] << endl;
	}
};
signed main() {
	int a[6];
	for (int i = 0; i < 6; i++) cin >> a[i];
	Dice dice(a[0], a[1], a[2], a[3], a[4], a[5]);
	string s;
	cin >> s;
	dice.roll(s);
	dice.print_top();
}


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

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;

    vector<long long> a(N);
    vector<long long> tmp_a(N);
    long long money = 0;
    long long min_money = 15000000000;
    vector<long long> tmp;
    long long current_max_height;
    int count = 0;

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

    for(int biti = 0; biti < (1<<(N-1)); biti++) {
        tmp_a = a;
        money = 0;
        tmp = {};

        for(int i = 0; i < N-1; i++) {
            if(biti & (1<<i)) {
                tmp.push_back(i);
            }
        }

        for(int i : tmp) {
            current_max_height = *max_element(tmp_a.begin(), tmp_a.begin() + (i+1));
            if(tmp_a[i+1] <= current_max_height) {
                money += current_max_height - tmp_a[i+1] + 1;
                tmp_a[i+1] = current_max_height + 1;
            }
        }

        count = 1;
        for(int i = 1; i < N; i++) {
            current_max_height = *max_element(tmp_a.begin(), tmp_a.begin() + i);
            if(tmp_a[i] > current_max_height) {
                count++;
            }
        }

        if(count == K) {
            min_money = min(min_money, money);
        }
    }

    cout << min_money << endl;
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    ll n;
    vector <ll> a(5);
    cin >> n;
    ll mi = 10000000000000000;
    rep(i,0,5) {
        cin >> a[i];
        mi = min(mi, a[i]);
    }
    cout << (n + mi -1)/mi +4 << endl;

}

Measured memory_bytes: 3164
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using V = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 10e9+7LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs
 
void solve()
{
    IN(n);
    ll s = 0;
    reps(i, 1, n+1)
    {
        if (i % 3 != 0 && i % 5 != 0) s += i;
    }
    cout << s << endl;
}
 
int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);
 
    solve();
 
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  ll n,d;
  cin >> n >> d;
  int ans = 0;
  rep(i,n){
    ll x,y;
    cin >> x >> y;
    ll dist = x*x + y*y;
    if(dist <= d*d) ans ++;
  }
  cout << ans << endl;
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if ((A <= C && C <= B) || (B <= C && C <= A)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3576
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);
    string s;
    cin >> s;
    for (int i = 0; i < s.size() - 1; i++) {
        if (s.substr(i, 2) == "AC") {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, a, b) for (int i = a; i <= b; ++i)
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll n, m;
namespace Manacher_Algorithm {
	const int maxn = 1e5 + 5; // 预设为原串长度
	int len = 1; // manacher 预处理后字符串的长度
	char stk[maxn << 1]; // manacher预处理字符串 需要2倍空间+1

	void init(string s) { // 初始化stk
		stk[0] = '*'; len = 1;
		for (int i = 0; i < s.length(); ++i) {
			stk[len++] = s[i];
			stk[len++] = '*';
		}
	}

	int Manacher() { // 返回最长回文子串长度
		vector<int> rad(len << 1); // 存储每个点作为对称中心可拓展的最大半径
		int md = 0; // 最远回文串对称中心下标
		for (int i = 1; i < len; ++i) {
			int& r = rad[i] = 0;
			if (i <= md + rad[md])
				r = min(rad[2 * md - i], md + rad[md] - i);
			while (i - r - 1 >= 0 && i + r + 1 < len &&
				stk[i - r - 1] == stk[i + r + 1]) ++r;
			if (i + r >= md + rad[md]) md = i;
		}
		int res = 0;
		for (int i = 0; i < len; ++i)
			if (rad[i] > res)
				res = rad[i];
		return res;
	}
}
using namespace Manacher_Algorithm;
int main() {
	string s;
	io(); cin >> s;
	init(s);
	int len = s.length();
	if (Manacher() != len) cout << "No";
	else {
		string sa = s.substr(0, (len - 1) >> 1);
		init(sa);
		if (Manacher() != sa.length()) cout << "No";
		else {
			string sb = s.substr((len + 1) >> 1, (len - 1) >> 1);
			init(sb);
			if (Manacher() != sb.length()) cout << "No";
			else cout << "Yes";
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(int i=init;i<(int)(n);i++)
#define repd(i,n,init) for(int i=(int)(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)

int main()
{
    int N;
    cin >> N;
    repi(i,10,1){
        repi(j,10,1){
            if(i * j == N){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int main(){
    int W,H,n;
    cin >> W >> H >> n;
    vector<int> X(n),Y(n),a(n);
    rep(i, 0, n) cin >> X[i] >> Y[i] >> a[i];

    int x = 0, y = 0, w = W, h = H;
    rep(i, 0, n){
        if(a[i] == 1) x = max(X[i], x);
        if(a[i] == 2) w = min(X[i], w);
        if(a[i] == 3) y = max(Y[i], y);
        if(a[i] == 4) h = min(Y[i], h);
    }

    if(w - x >= 0 && h - y >= 0){
        int s = (w - x)*(h - y);
        cout << s << endl;
    }else cout << 0 << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  vector<int> m(1e6 + 1, 1<<30);
  const int n = 500;
  for (int x = 0; x < n; x++) {
    for (int y = 0; y < n; y++) {
      for (int z = 0; z < n; z++) {
        int t = x+y*y+z*z*z;
        if (t <= 1e6) {
          m[t] = min(m[t], x+y+z);
        }
      }
    }
  }
  int e;
  while (true) {
    cin >> e;
    if (e == 0) break;
    cout << m[e] << endl;
  }
}



Measured memory_bytes: 10516
#include<bits/stdc++.h>
typedef long long ll;
typedef long long INT;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define ALL(x) x.begin(),x.end()

#define INF (int)1e9 //10^9:∞
#define LLINF (long long)1e12
#define MOD (int)1e9+7 //10^9+7:合同式の法
#define PI 3.141592653589

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int> >
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int> >
#define VPII vector<pair<int,int> >

#define DDD fixed<<setprecision(1)

using namespace std;
/*........................................Define functions.........................................*/

set<int> factors(int n) {
	set<int> ret;

	for (int i = 1; i * i <= n; i++) {//まずは素因数だけ追加
		if (n % i == 0) {ret.insert(i); ret.insert(n / i);}
	}
	return ret;
}

/*....................................Define global variables .....................................*/



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


	int N;
	cin >> N;
	VI A(N);
	REP(i, N)cin >> A[i];
	sort(ALL(A));
	if (N == 1) {cout << A[0] << endl; return 0;}


	set<int> f1, f2;
	f1 = factors(A[0]);
	f2 = factors(A[1]);

	set<int> st;

	for (auto m : f1) {
		st.insert(m);
	}
	for (auto m : f2) {
		st.insert(m);
	}

	set<int> ans_list;

	for (auto s : st) {
		int n = 0;

		for (auto v : A) {
			if (v % s == 0) {n++;}
		}
		if (n == N - 1 || n == N)ans_list.insert(s);
	}


	auto itr = ans_list.end(); itr--;
	int ans = *itr;


	cout << ans << endl;




	return 0;
}






Measured memory_bytes: 3700
def main():
    from itertools import accumulate
    N, K = (int(i) for i in input().split())
    while N != 0 or K != 0:
        A = [int(input()) for i in range(N)]
        S = list(accumulate([0] + A))
        ans = 0
        for i in range(N-K+1):
            cur = S[i+K] - S[i]
            ans = max(ans, cur)
        print(ans)
        N, K = (int(i) for i in input().split())


if __name__ == '__main__':
    main()



Measured memory_bytes: 14352
#include <iostream>

using namespace std;

int main(void) {
	string pre,suf;
	pre = suf = "";
	for (int i = 0; i < 4; ++i) {
		char c;
		cin >> c;
		if (i < 2) {
			pre += c;
		}
		else {
			suf += c;
		}
	}

	string res = "NA";
	if (pre == "00" || suf == "00") {
		if (pre == "00" && suf != "00" && suf < "13") {
			res = "YYMM";
		}
		else if (suf == "00" && pre != "00" && pre < "13") {
			res = "MMYY";
		}
	}
	else {
		if (pre < "13" && suf < "13") {
			res = "AMBIGUOUS";
		}
		else if (pre < "13") {
			res = "MMYY";
		}
		else if (suf < "13") {
			res = "YYMM";
		}
	}

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


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
typedef pair<int, int> P;

void solve(char trump) {
    vector<vector<string> > C(4, vector<string>(13));
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 13; j++) {
            cin >> C[i][j];
        }
    }
    int EW = 0, NS = 0;
    int leader = 0;
    for (int i = 0; i < 13; i++) {
        vector<pair<int, P> > now_trick;
        for (int j = 0; j < 4; j++) {
            char now_c = C[j][i][0], now_suit = C[j][i][1];
            int number;
            if (now_c >= '2' && now_c <= '9') {
                number = now_c - '0';
            }
            else if (now_c == 'T') number = 10;
            else if (now_c == 'J') number = 11;
            else if (now_c == 'Q') number = 12;
            else if (now_c == 'K') number = 13;
            else number = 14;
            int priority;
            if (now_suit == trump) priority = 2;
            else if (now_suit == C[leader][i][1]) priority = 1;
            else priority = 0;
            now_trick.push_back(make_pair(priority, P(number, j)));
        }
        sort(now_trick.rbegin(), now_trick.rend());
        int winner = now_trick[0].second.second;
        if (winner == 0 || winner == 2) NS++;
        else EW++;
        leader = winner;
    }
    if (EW > NS) cout << "EW " << EW - 6 << endl;
    else cout << "NS " << NS - 6 << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    char trump;
    while (true) {
        cin >> trump;
        if (trump == '#') break;
        solve(trump);
    }
    return 0;
}


Measured memory_bytes: 3128
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>

using namespace std;
#define vsort(v) sort(v.begin(), v.end());
#define vsort_reverse(v) sort(v.begin(), v.end(), greater<int>());
#define bsearch(v, n) binary_search(v.begin(), v.end(), n)
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int A, B, C, K;
	cin >> A >> B >> C >> K;
	vector<int> v;
	v.push_back(A);
	v.push_back(B);
	v.push_back(C);

	for(int i = 0; i < K; i++) {
		vsort_reverse(v);
		v[0] *= 2;
	}
	int rslt = 0;
	for(int i = 0; i < 3; i++) {
		rslt += v[i];
	}
	cout << rslt << endl;
}


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

int main() {
	int n;
	cin >> n;
	vector<int> side(n);
	int sum = 0;
	for(int i=0 ; i<n ; i++){
		cin >> side[i];
		sum += side[i];
	}
	sort(side.begin(),side.end());
	sum -= side[n-1];
	if(sum > side[n-1]){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner cin = new Scanner(System.in);
		
		int L,M,N,A,i;
		
		while(true)
		{
			L = cin.nextInt();
			if(L==0) { break; }
		
			for(i=0,A=0; i<12; i++)
			{	
				M = cin.nextInt();
				N = cin.nextInt();
		
				L -= (M-N);
				if(L<=0 && A==0) { A=i+1; }
			}
			
			if(A>0)
			{
				System.out.println(A);
			}
			else
			{
				System.out.println("NA");
			}
		}
	}
}

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

int main(){
	int N;
	cin>>N;
	vector<int>T(N);
	int Tsum=0;
	rep(i,N){
		cin>>T.at(i);
		Tsum+=T.at(i);
	}
	int M;
	cin>>M;
	vector<int>P(M);
	vector<int>X(M);
	//int psum=0;
	rep(i,M){
		cin>>P.at(i)>>X.at(i);
		//psum+=T.at(i);
	}
	rep(i,M){
		cout<<Tsum-(T.at(P.at(i)-1)-X.at(i))<<endl;
		//cout<<Tsum;
	}
return 0;}

/*compile
g++ code.cpp
./a.out
run*/

Measured memory_bytes: 256
N,K = map(int,input().split())
H = list(map(int,input().split()))
dp = [0]*N
for j in range(1,N):
  dp[j] = dp[j-1]+abs(H[j]-H[j-1])
for i in range(0,N+1):
  for j in range(K+1):
    if i+j <= N-1:
      dp[i+j] = min(dp[i+j],dp[i]+abs(H[i+j]-H[i]))
print(dp[N-1])

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

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi > 
#define IOS ios_base::sync_with_stdio(false),cin.tie(NULL)
const int N=500003;
int main()
{
	ll n,k;
	cin>>n>>k;
	ll res=0;
	for(ll i=n+1;i>=k;i--)
	{
		res+=(n+1-i)*i%mod;
		res+=1;
		
		res%=mod;
	}
	cout<<res<<"\n";
	return 0;
}

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

static const int N_MAX=100000;

int log2fl(int n);

int main(){
  //declare
  int N,M;
  int a,idx;
  int s;
  unsigned long long int ans=0;
  vector<int> A[30];

  //input
  cin >> N >> M;
  for (int i=0; i<N ; i++){
    cin >> a;
    idx=log2fl(a);
    A[idx].push_back(a);
  }

  //solve
  for (int j=29 ; j>0 ; j--){
    s=A[j].size();
    if (s==0){
      continue;
    }

    if (s<=M){
      for (int i=0 ; i<s ; i++){
        a=A[j].back();
        A[j].pop_back();
        A[j-1].push_back(a>>1);
      }
      M-=s;
    }
    else{
      sort(A[j].begin(),A[j].end());
      for (int i=0 ; i<M ; i++){
        a=A[j].back();
        A[j].pop_back();
        A[j-1].push_back(a>>1);
      }
      M=0;
      break;
    }
  }

  //out
  if (M>0){
    if (N<M){
      ans=0;
    }
    else{
      ans=N-M;
    }
  }
  else{
    for (int j=29 ; j>=0 ; j--){
      s=A[j].size();
      for (int i=0 ; i<s ; i++){
        ans+=A[j].back();
        A[j].pop_back();
      }
    }
  }

  cout << ans;
}


int log2fl(int n){
  int ret=0;
  n>>=1;
  while(n>0){
    n>>=1;
    ret++;
  }
  return ret;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    map<ll,ll> mp;
    ll n = N;
    for(ll i=2;i*i<=N;i++){
        while(n%i==0){
            n /= i;
            mp[i]++;
        }
    }
    if(n!=1) mp[n]++;
    int ans = 0;
    for(auto& x:mp){
        int c = 0;
        int a = 1;
        while(c+a<=x.second){
            ans++;
            c += a;
            a++;
        }
    }
    cout << ans << "\n";
}

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

#define maxn 500010
#define fo(i,a,b) for(register int (i)=(a);(i)<=(b);++(i))
#define rd read()
#define int long long
const int mod=1e9+7;
map<int,int>f;
int read() {
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9') {
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return x*f;
}
void wr(int x) {
	if(x>9)wr(x/10);
	putchar(x%10+48);
}
int work(int x)
{
	if(f[x]!=0)return f[x];
	return f[x]=(work(x/2)+work((x-1)/2)+work((x-2)/2))%mod;
}
signed main() {
    f[0]=1;f[1]=2;
    int n=rd;
    wr(work(n));
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
 
 
int main()
{
    int n,i;
    scanf("%d %d",&n,&i);
    int ans=n-i+1;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256