akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main(){
    int a,b,c,j;
    j =0;
    cin >> a >> b >> c;
    for(int i = 0;i <= b-a;i++){
        int n = a + i;
        if(c % n == 0){
            j = j + 1;
        }
    }
    cout << j << endl;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
int main(){
	int maxi=(1<<31);
	int mini=(-1)^(1<<31);
	int n;
	cin>>n;
	for (int i=0;i<n;i++){
		int a;
		cin>>a;
		maxi=max(maxi,a);
		mini=min(mini,a);
	}
	printf ("%d\n",maxi-mini);
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(All(A));
    vector<ll> Asum(N + 1);
    rep(i, N) Asum[i + 1] = Asum[i] + A[i];
    ll res = 1;
    for(int i = N - 1; i >= 0; i--) {
        if(Asum[i] * 2 >= A[i])
            res++;
        else
            break;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
	int n;
	while(1){
		int sum=0;
		cin >> n;
		if(n==0){
			break;
		}
		while(1){
			if(n==1){
				cout << sum << endl;
				break;
			}
			if(n%2==0){
				n=n/2;
				sum++;
			}else{
				n=n*3+1;
				sum++;
			}
			
		}
	}
	return 0;
}

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

int main() {
  int N,Y;
  cin >> N>>Y;
  for(int x=0; x<=N;x++){
    for(int y=0; y<=N-x;y++){
      int z=N-x-y;
      int sum = 10000*x+5000*y+1000*z;
      if (sum ==Y && z>=0){
        cout << x<<" "<<y<<" "<<z << endl;
        return 0;
      }
    }
  }
  cout << -1 <<" "<<-1<<" "<<-1 << endl;
  }


Measured memory_bytes: 256
import java.lang.Math;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            while (true) {
                int n = sc.nextInt();
                if (n == 0) break;
                double s[] = new double[n];
                double m = 0;
                for (int i = 0; i < n; i++) {
                    s[i] = sc.nextDouble();
                    m += s[i];
                }
                m /= n;
                double v = 0;
                for (int i = 0; i < n; i++) {
                    s[i] = Math.pow(s[i]-m, 2);
                    v += s[i];
                }
                v /= n;
                double d = Math.pow(v, 0.5);
                System.out.println(d);
            }
        }
    }
}


Measured memory_bytes: 39948
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll X;
  cin >> X;
  if(X==3 || X==5 || X==7){
    cout << "YES" << "\n";
  }else{
    cout << "NO" << "\n";
  }

  return 0;
}

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

class Node {
public :
    int location;
    int p, l, r;
    Node() {};
};

class Point {
public:
    int id, x, y;
    Point() {};
    Point(int id, int x, int y) :id(id), x(x), y(y) {};
    bool operator < (const Point &p) const {
        return id < p.id;
    }

    void print() {
        printf("%d\n", id);
    }

};

const int maxx = 1000010;
const int NIL = -1;

int n;
Point p[maxx];
Node T[maxx];
int np;

bool lessX(const Point &p1, const Point &p2) { return p1.x < p2.x; }
bool lessY(const Point &p1, const Point &p2) { return p1.y < p2.y; }

int makeKDTree(int l, int r, int depth) {
    if (l >= r)
        return NIL;
    int mid = (l + r) / 2;
    int t = np++;
    if (depth % 2 == 0)
        sort(p + l, p + r, lessX);
    else
        sort(p + l, p + r, lessY);

    T[t].location = mid;
    T[t].l = makeKDTree(l, mid, depth + 1);
    T[t].r = makeKDTree(mid + 1, r, depth + 1);

    return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point> &ans) {
    int x = p[T[v].location].x;
    int y = p[T[v].location].y;

    if (sx <= x && x <= tx && sy <= y && y <= ty)
        ans.push_back(p[T[v].location]);

    if (depth % 2 == 0) {
        if (T[v].l != NIL && sx <= x)
            find(T[v].l, sx, tx,sy, ty, depth + 1, ans);
        if (T[v].r != NIL && x <= tx)
            find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
    }else {
        if (T[v].l != NIL && sy <= y)
            find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
        if (T[v].r != NIL && y <= ty)
            find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
    }
}
int main()
{
    int x, y;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &x, &y);
        p[i] = Point(i, x, y);
        T[i].l = T[i].r = T[i].p = NIL;
    }

    np = 0;
    int root = makeKDTree(0, n, 0);

    int q;
    int sx, tx, sy, ty;
    vector<Point> ans;
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
        ans.clear();
        find(root, sx, tx, sy, ty, 0, ans);
        sort(ans.begin(), ans.end());
        for (int j = 0; j < ans.size(); j++)
            ans[j].print();
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 16464
#include <bits/stdc++.h>
#define len(x) (int) (x.size())
using namespace std;
typedef long long ll;

int main() {
    vector<int> numbers {1, 2, 3}, choices(2), ans(1);
    for(int &x: choices) cin >> x;

    sort(choices.begin(), choices.end());
    
    auto it = set_difference(numbers.begin(), numbers.end(), choices.begin(), choices.end(), ans.begin());
    ans.resize(it-ans.begin());

    cout << *ans.begin() << '\n';
    
    return 0;
}

Measured memory_bytes: 256
al=[chr(ord('A') + i) for i in range(26)]

H,W=map(int,input().split())
S= [list(input().split()) for _ in range(H)]

for i in range(H):
  for j in range(W):
    if S[i][j]=="snuke":
      ans=al[j]+str(i+1)
      print(ans)

Measured memory_bytes: 3060
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=sum([x for x in a if x>0])
np=sum([x for x in a[:k] if x>0])
nm=sum([-x for x in a[:k] if x<0])
ansb=nm
answ=np
# ansb:黒に塗った時、理想値からの差分
# answ:白に塗った時、理想値からの差分
for i in range(k,n):
  x=a[i]
  if x>0:
    np+=x
  else:
    nm-=x
  y=a[i-k]
  if y>0:
    np-=y
  else:
    nm+=y
  ansb=min(ansb,np)
  answ=min(answ,nm)
print(ans-min(ansb,answ))
  



Measured memory_bytes: 96332
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf ("%d",&n);

    int64_t l;
    vector<int64_t> ln(n+1);
    ln.at(0) = 2;
    ln.at(1) = 1;

    for (int i = 2; i <= n; i++) {
        ln.at(i) = ln.at(i-1) + ln.at(i-2); 
    }

    printf("%ld", ln.at(n));
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define ll long long
using namespace std;
int n,m;
ll a,ans;
priority_queue<ll> q;
int main()
{
  cin>>n>>m;
  for(int i=0;i<n;i++) cin>>a,q.push(a);
  while(m--)
  {
    ll t = q.top();
    q.pop();
    t/=2;
    q.push(t);
  }
  while(!q.empty())
  {
    ans+=q.top();
    q.pop();
  }
  cout<<ans;
}

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

int f[100];
int main(){
	int n,w,v;
	while(cin>>n>>w,n|w){
		memset(f,0,sizeof(f));
		int rm=0,maxh=0;
		double s=0;	
		while(n--){
			cin>>v;
			maxh=max(maxh,++f[v/w]);
			rm=max(rm,v/w);
		}
		for(int i=0;i<=rm;i++){
			s += f[i]*(1-(double)i/rm);
		}
		cout<<s/maxh+0.01<<endl;
	}
	return 0;
}

Measured memory_bytes: 1232
import itertools
s=list(input())
for x,y,z in list(itertools.product(["+","-"],repeat=3)):
    if int(s[0])+int(x+s[1])+int(y+s[2])+int(z+s[3])==7:
        print(s[0]+x+s[1]+y+s[2]+z+s[3]+"=7")
        break

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>

int main() {
  int N;
  std::cin >> N;
  int temp_min;
  int temp_max;
  for (int i=0; i<N; i++) {
    if (i == 0) {
      int n;
      std::cin >> n;
      temp_max = n;
      temp_min = n;
    }
    else {
      int n;
      std::cin >> n;
      temp_max = std::max(temp_max, n);
      temp_min = std::min(temp_min, n);
    }
  }
  std::cout << temp_max - temp_min << std::endl;
}


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

#define ll long long

ll dpa[100002];
ll dpb[100002];
ll dpc[100002];
int main()
{

      ios::sync_with_stdio(0);
      cin.tie(0);

      ll n;
      cin>>n;

      ll a[n+1],b[n+1],c[n+1];

      for(ll i=1;i<=n;i++)
      	cin>>a[i]>>b[i]>>c[i];

      dpa[1]=a[1];
      dpb[1]=b[1];
      dpc[1]=c[1];

      for(ll i=2;i<=n;i++)
      {

        dpa[i]=max(a[i]+dpb[i-1],a[i]+dpc[i-1]);
        dpb[i]=max(b[i]+dpa[i-1],b[i]+dpc[i-1]);
        dpc[i]=max(c[i]+dpa[i-1],c[i]+dpb[i-1]);

      }

   cout<<max(dpa[n],max(dpb[n],dpc[n]));

}


Measured memory_bytes: 4992
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstdio>
using namespace std;
#define pi acos(0.0)*2
#define sqr(x) ((x)*(x))

int main() {
  int a, b, h, m; cin >> a >> b >> h >> m;
  double a1 = h/6.0*pi + m/60.0 * pi/6, a2 = m/30.0*pi;
  double x1 = sin(a1) * a, y1 = cos(a1) * a;
  double x2 = sin(a2) * b, y2 = cos(a2) * b;
  printf("%.9f\n", sqrt(sqr(x1-x2) + sqr(y1-y2)));
  return 0;
}

Measured memory_bytes: 3616
import math

class Vector:
    def __init__(self,x,y):
        self.x = x
        self.y = y
        
    def __add__(self,other):
        return Vector(self.x+other.x,self.y+other.y)
    
    def __sub__(self,other):
        return Vector(self.x-other.x,self.y-other.y)
    
    def __mul__(self,scalar):
        return Vector(self.x*scalar,self.y*scalar)
    def __rmul__(self, scalar):
        return Vector(self.x*scalar,self.y*scalar)
    
   
    def __repr__(self):
        return str([self.x,self.y])
        
    def norm_2(self):
        return dot(self,self)
    
    def norm(self):
        return math.sqrt(self.norm_2())
    
def v_sum(v1,v2):
    return Vector(v1.x+v2.x,v1.y+v2.y) 
def scalar_multi(k,v):
    return Vector(k*v.x,k*v.y)
def v_diff(v1,v2):
    return v_sum(v1,scalar_multi(-1,v2))
    
def dot(vector1,vector2):
    return vector1.x*vector2.x+vector1.y*vector2.y

def cross(vector1,vector2):
    return vector1.x*vector2.y-vector1.y*vector2.x

def is_crossed(p,far_point,s,t):
    a = far_point-p
    b = t-s
    v = s-p
    w = t-p
    x = p-s
    y = far_point-s
    if cross(a,v)*cross(a,w)<0 and cross(b,x)*cross(b,y)<0:
        return 0#'crossed on the edge'
    if cross(b,x) == 0 and 0<=dot(b,x)<=b.norm_2():
        return 1#'p on segment'
    if (cross(a,v)== 0 and 0<=dot(a,v)<=a.norm_2()) or (cross(a,w)==0 and 0<=dot(a,w)<=a.norm_2()):
        return 2#'crossed on the corner'
    return 3#not crossed

def polygon_content(point):
    insec_count = 0
    
    
    far_point = Vector(21001,21011) + point
    
    for i in range(n):
        judge = is_crossed(point,far_point,p[i-1],p[i])
        if judge==0:
            insec_count+=1
        elif judge==1:
            return 1
        elif judge==2:
            insec_count+=0.5
        
    if insec_count==0:
        return 0
    elif insec_count%2==0:
            return 0
    else:
        return 2

n = int(input())
p = []
for i in range(n):
    x,y = map(int,input().split())
    p.append(Vector(x,y))

q = int(input())
for i in range(q):
    x,y = map(int,input().split())
    print(polygon_content(Vector(x,y)))


Measured memory_bytes: 5700
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int main()
{
    char b;
    cin >> b;
    if (b == 'A')
        cout << 'T' << endl;
    else if (b == 'T')
    {
        cout << 'A' << endl;
    }
    else if (b == 'C')
    {
        cout << 'G' << endl;
    }
    else
        cout << "C" << endl;

    return 0;
}


Measured memory_bytes: 256
def Warshall_Floyd(edges,N):
  for k in range(N):
    for i in range(N):
      for j in range(N):
        edges[i][j]=min(edges[i][j],edges[i][k]+edges[k][j])
  return edges

import itertools
N, M, R = map(int,input().split())
r = list(map(int,input().split()))
A=[[float("inf") for i in range(N)] for j in range(N)]
for m in range(M):
  a, b, c = map(int,input().split())
  A[a-1][b-1] = c
  A[b-1][a-1] = c
A = Warshall_Floyd(A,N)

ans = float("inf")
for road in list(itertools.permutations(r)):
  length = 0
  for i in range(R-1):
    length += A[road[i]-1][road[i+1]-1]
  ans = min(ans, length)
print(ans)

Measured memory_bytes: 66520
n, w = map(int, input().split())
lst = [[0 for i in range(w+1)] for j in range(n+1)]

for i in range(1, n+1):
    wi, vi = map(int, input().split())
    for j in range(w+1):
        if wi > j:
            lst[i][j] = lst[i-1][j]
        else:
            lst[i][j] = max(lst[i-1][j], lst[i-1][j-wi] + vi)
print(max(lst[n]))

Measured memory_bytes: 171400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int ans[110][110];

int main(){
    int h,w,n;
    cin>>h>>w>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];

    int id=0;
    rep(i,h){
        if(i%2==0){
            rep(j,w){
                ans[i][j]=id+1;
                a[id]--;
                if(a[id]==0) id++;
            }
        }
        else{
            for(int j=w-1;j>=0;j--){
                ans[i][j]=id+1;
                a[id]--;
                if(a[id]==0) id++;
            }
        }
    }


    

    rep(i,h){
        rep(j,w){
            cout<<ans[i][j]<<" ";
        }
        cout<<endl;
    }
}


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

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

    int x = 0;
    string s = to_string(n);
    rep(i, s.size()) x += s[i] - '0';

    if (n % x == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

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

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 6000;
char s[N];
int dp[N][N];

void add(int& x, int y) {
  x = ((int64)x + y) % MOD;
  if (x < 0) x += MOD;
}

int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%s", s);
  m = strlen(s);
  dp[0][0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= i; ++j) {
      add(dp[i + 1][max(0, j - 1)], dp[i][j] * (1 + (j > 0 && j <= m)));
      add(dp[i + 1][j + 1], dp[i][j] * (1 + (j >= m)));
    }
  }
  printf("%d\n", dp[n][m]);
  return 0;
}


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

typedef long long ll;
const int maxn = 100005;
const int INF = 1e9;
const ll INF_LL = 1e18, bound = 1e15+3;

int e_num = 1, S, T, maxf = 0;
ll mincost = 0;
int hed[maxn];
ll ct[maxn];
struct Edge {
  int from, to, nxt, c;
  ll cost;
} edge[maxn];
void addedge(int from, int to, int c, ll cost) {
  edge[++e_num] = (Edge){from, to, hed[from], c, cost};
  hed[from] = e_num;
}
void adde(int from, int to, int c, ll cost) {
  addedge(from, to, c, cost);
  addedge(to, from, 0, -cost);
}
queue<int> q;
#define prev prv
int inq[maxn], prev[maxn], pree[maxn];
bool SPFA() {
  for (int i = 0; i <= T; i++) ct[i] = INF_LL;
  inq[S] = 1;
  ct[S] = 0;
  q.push(S);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int i = hed[cur]; i; i = edge[i].nxt) {
      int to = edge[i].to;
      if (ct[to] > ct[cur] + edge[i].cost && edge[i].c) {
        if (!inq[to]) {
          inq[to] = 1;
          q.push(to);
        }
        ct[to] = ct[cur] + edge[i].cost;
        prev[to] = cur;
        pree[to] = i;
      }
    }
    inq[cur] = 0;
  }
  if (ct[T] == INF_LL) return 0;
  int flow = INF;
  for (int cur = T; prev[cur]; cur = prev[cur]) {
    int ed = pree[cur];
    flow = min(flow, edge[ed].c);
  }
  for (int cur = T; prev[cur]; cur = prev[cur]) {
    int ed = pree[cur];
    edge[ed].c -= flow;
    edge[ed ^ 1].c += flow;
  }
  maxf += flow;
  mincost += flow * ct[T];
  return 1;
}

const int N = 233;
int n, m, L[N], R[N], U[N], D[N], x[N], y[N];
int type[N], tt[N], vv[N];
ll v[N];

ll Main(int k) {
  memset(L, 0, sizeof L);
  memset(D, 0, sizeof D);
  memset(R, 0x3f, sizeof R);
  memset(U, 0x3f, sizeof U);
  for (int x = 1; x <= m; x++) {
    int t = tt[x], v = vv[x];
    if (type[x] == 'L') {
      for (int i = v + 1; i <= k; i++) {
        L[i] = max(L[i], t + 1);
      }
    } else if (type[x] == 'R') {
      for (int i = 1; i <= k - v; i++) {
        R[i] = min(R[i], t - 1);
      }
    } else if (type[x] == 'D') {
      for (int i = v + 1; i <= k; i++) {
        D[i] = max(D[i], t + 1);
      }
    } else {
      for (int i = 1; i <= k - v; i++) {
        U[i] = min(U[i], t - 1);
      }
    }
  }
  S = n * 4 + 1, T = n * 4 + 2;
  mincost = maxf = 0;
  e_num = 1;
  memset(hed, 0, sizeof hed);
  for (int i = 1; i <= k; i++) {
    adde(S, i, 1, 0);
    adde(i + k, T, 1, 0);
    for (int j = 1; j <= n; j++) {
      if (L[i] <= x[j] && x[j] <= R[i]) {
        adde(i, j + k + k, 1, 0);
      }
      if (D[i] <= y[j] && y[j] <= U[i]) {
        adde(j + k + k + n, i + k, 1, 0);
      }
    }
  }
  for (int j = 1; j <= n; j++) {
    adde(j + k + k, j + k + k + n, 1, bound - v[j]);
  }
  while (SPFA());
  if (maxf != k) return 0;
  return maxf * bound - mincost;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%lld", &x[i], &y[i], &v[i]);
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    char c[4];
    scanf("%s%d%d", c, &tt[i], &vv[i]);
    type[i] = c[0];
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = max(ans, Main(i));
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 3200
#include <iostream>

void mergeSort(int a[], int start, int end);
void merge(int a[], int start, int mid, int end);
int cnt = 0;

int main()
{
  using namespace std;
  int n;
  cin >> n;
  int *a = new int[n];
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  mergeSort(a, 0, n - 1);
  for (int i = 0; i < n - 1; i++)
  {
    cout << a[i] << ' ';
  }
  cout << a[n - 1] << endl << cnt << endl;
  return 0;
}

void mergeSort(int a[], int start, int end)
{
  if (start < end)
  {
    int mid = (start + end) / 2;
    mergeSort(a, start, mid);
    mergeSort(a, mid + 1, end);
    merge(a, start, mid, end);
  }
}

void merge(int a[], int start, int mid, int end)
{
  int len1 = mid - start + 1;
  int len2 = end - mid;
  int *L = new int[len1];
  int *R = new int[len2];
  for (int i = 0; i < len1; i++)
  {
    L[i] = a[start + i];
  }
  for (int i = 0; i < len2; i++)
  {
    R[i] = a[mid + 1 + i];
  }

  int m = 0, n = 0, k = start;
  while (m < len1 && n < len2)
  {
    cnt++;
    if (L[m] <= R[n])
    {
      a[k++] = L[m++];
    }
    else if (L[m] > R[n])
    {
      a[k++] = R[n++];
    }
  }
  while (m < len1)
  {
    cnt++;
    a[k++] = L[m++];
  }
  while (n < len2)
  {
    cnt++;
    a[k++] = R[n++];
  }
  delete[] L;
  delete[] R;
}



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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int k; cin >> k;

    int x = 7 % k;
    set<int> s;

    int count = 1;
    while (s.count(x) == 0) {
        if (x == 0) {
            cout << count << endl;
            return 0;
        }

        s.insert(x);
        x = (x * 10 + 7) % k;
        ++count;
    }

    cout << -1 << endl;
}

Measured memory_bytes: 50464
#include <functional>
#include <algorithm>
#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <cctype>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <queue>
#include <stdio.h>
#include <stack>
#include <ctime>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define TR(i,x) for(__typeof(x.begin()) i=x.begin();i!=x.end();i++)
#define ALL(x) x.begin(),x.end()
#define SORT(x) sort(ALL(x))
#define CLEAR(x) memset(x,0,sizeof(x))
#define FILL(x,c) memset(x,c,sizeof(x))
#define PB push_back
#define MP make_pair

using namespace std;

const double eps = 1e-8;

typedef map<int,int> MII;
typedef map<string,int> MSI;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<long double> VD;
typedef pair<int,int> PII;
typedef long long int64;
typedef long long LL;
typedef unsigned int UI;
typedef long double LD;

int main() {
    int n;
    cin >> n;
    vector<int> monsters{}, heros{};
    for (int i = 0, t = 0; i < n + 1; ++i) {
        cin >> t;
        monsters.push_back(t);
    }
    for (int i = 0, t = 0; i < n; ++i) {
        cin >> t;
        heros.push_back(t);
    }
    long carry = 0;
    long sum = 0;
    for (int i = n; i >= 1; --i) {
        long at_cnt = carry + heros[i - 1];
        sum += min(at_cnt, (long)monsters[i]);
        carry = at_cnt - monsters[i] > heros[i - 1] ? heros[i - 1] : at_cnt - monsters[i];
        carry = carry < 0 ? 0 : carry;
    }
    //cout << "cy:"<<carry<<endl;
    sum += min(carry, (long)monsters[0]);
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    string N; cin >> N;
    int b=0;
    for(int i=0;i<N.size();i++){
        b+=N[i]-48;
    }
    if(b%9==0){A2;}
    else A1;
    return 0;
}

Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std ;
const int MOD = 1e9+7 ;
void add_self(int& a , int b){
	a += b ;
	if(a >= MOD)
		a -= MOD ;
		
}

int main(){
	int n,k ;
	scanf("%d",&n) ;
	vector<vector<int> >can(n,vector<int>(n)) ;
	vector<int>dp(1<<n) ;
	dp[0] = 1 ; // choosing no pairs 
	for(int i=0;i<n;i++){
		for(int j = 0 ; j <n ;j++){
			scanf("%d",&can[i][j]) ;
		}
	}
	
	for(int mask = 0 ; mask < (1<< n) -1 ; mask++){
		int a = __builtin_popcount(mask) ; // men
		for(int b = 0 ; b < n ; b++){
			if(can[a][b] and !(mask & (1 << b)) ){ 
				int x = mask ^ (1 << b) ; // set women
				add_self(dp[x],dp[mask]) ;			
			}
		}
	}
	
	printf("%d\n" ,dp[(1<<n)-1]) ;
}




Measured memory_bytes: 8448
#include<stdio.h>
int main()
{
	int N,i,x,a[100];
    
    do{
	scanf("%d",&N);
    }while(N<0 || N>100);
  
  	x=0;
	for(i=0;i<N;i++)
	{
		scanf("%d",&a[i]);
		if((i+1)%2==1 && a[i]%2==1)
			x++;
	}
	
    printf("%d",x);
    return 0;
}

Measured memory_bytes: 1732
#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; i++)

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> v(N);
	rep(i, N) {
		cin >> v.at(i);
	}

	int a=0, b=0, c=0, x, y, z;
    rep(i, min(K,50)) {
        vector<int> vv(N+1);
        rep(j, N) {
            x = v.at(j);
            vv.at(max(j-x,  0)) += 1;
            vv.at(min(j+x+1,N)) -= 1;
        }
        v.at(0) = vv.at(0);
        rep1(j, N) {
            v.at(j) = v.at(j-1) + vv.at(j);
        }
    }

    rep(i, N) {
        cout << v.at(i) << " ";
    }
}


Measured memory_bytes: 4768
import java.util.*;
class Main{
    public static void main(String[] av){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	String S = sc.next();
	String Strarray[] = S.split("");
	int i = 0,cnt = 0;
	while(i < N-1){
	    if((Strarray[i].equals("X") && Strarray[i+1].equals("O"))||(Strarray[i].equals("O") && Strarray[i+1].equals("X"))){
		cnt++;
		i += 2;
	    }
	    else{
		i++;
	    }
	}
	System.out.println(cnt);
    }
}


Measured memory_bytes: 39972
n = int(input())
s = input()

ans = 0
# when 0-th person is the leader
for i in range(1, n):
    if s[i] == 'E':
        ans += 1

tmp = ans
# when i-th person is the leader
for i in range(1, n):
    if s[i-1] == 'W':
        tmp += 1
    if s[i] == 'E':
        tmp -= 1
    ans = min(ans, tmp)


print(ans)

Measured memory_bytes: 42968
//A
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int a[233] = {0};
	for(int i = 1;i <= 3;i++)cin >> a[i];
	swap(a[1],a[2]);
	swap(a[1],a[3]);
	for(int i = 1;i <= 3;i++)cout << a[i] << " ";
	return 0;
}


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

int main(){
	ll k,i,j,n,ai,aj,sum=0;
  cin>>n;
  ll arr[n];
  for(i=0;i<n;i++){
   cin>>arr[i];
    sum+=arr[i];
  }
   
  ll dp[n][n];
  
  for(k=0;k<n;k++){
  	for(i=0,j=k;j<n;j++,i++){
  		if(i==j)dp[i][j]=arr[i];
      else if(j==i+1)dp[i][j]=max(arr[i],arr[j]);
      else{
      	ai=arr[i]+min(dp[i+2][j],dp[i+1][j-1]);
      	aj=arr[j]+min(dp[i][j-2],dp[i+1][j-1]);
      	dp[i][j]=max(ai,aj);
      }
      
    }
  }
  cout<<(2*dp[0][n-1])-sum<<"\n";
  
  return 0;
}

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

int main()
{
  int A, B;
  int res=0;
  cin >> A >> B;

  res = A+B;
  if (A*B>res) res = A*B;
  if (A-B>res) res = A-B;
  
  cout << res << endl;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: AtCoder Beginner Contest 111
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  printf("%d\n", (n + 110) / 111 * 111);
  return 0;
}


Measured memory_bytes: 256
import heapq
N,M =map(int,input().split())
A=[-int(x) for x in input().split()]#大きい順で扱う為にマイナスを付ける

heapq.heapify(A)#Aを優先度付キューへ変換

for i in range(M):
  saitakane = heapq.heappop(A)#最高値を取り出す
  heapq.heappush(A,-(-saitakane//2))#切り捨ての為に正の数にしてから半分にして戻す（追加）
print(-sum(A))

Measured memory_bytes: 14184
#include <stdio.h>

int main(){
  int n,m;
  int mod = 1000000007;
  scanf("%d%d\n",&n,&m);
  int num[n+1],broken[m];
  for(int i = 0; i < m; ++i) scanf("%d\n",&broken[i]);
  int flag = 0;
  for(int i = 0; i < n+1; ++i) num[i] = 0;
  for(int i = 0; i < m-1; ++i){
    if(broken[i+1] - broken[i] < 2){
      flag = 1;
      num[n] = 0;
    }
    num[broken[i]] = -1;
  }
  if(m > 0) num[broken[m-1]] = -1;
  num[0] = 1;
  if(flag == 0){
    for(int i = 1; i < n+1; ++i){
      if(num[i] != -1){
        if(i == 1) num[i] = num[0];
        else{
          if(num[i-1] != -1) num[i] = (num[i] + num[i-1]) % mod;
          if(num[i-2] != -1) num[i] = (num[i] + num[i-2]) % mod;
        }
      }
    }
  }
  printf("%d",num[n]);
  return 0;
}

Measured memory_bytes: 896
import java.util.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long x = a*b/2;
        if(a==1 || b==1)x=1;
        else if(a%2==1 && b%2==1) x++;
        System.out.println(x);
    }
 
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    string s,t;
    cin>>s>>t;
    sort(ALL(s));
    sort(ALL(t),greater<char>());
    if (s<t) {
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,N,x,ans=0;
  cin>>N;
  vec v(N);
  rep(i,N)cin>>v[i];
  rep(i,N-1){
    v[i]=v[N-1]-v[i];
    ans+=moddevide(v[i],i+1);
  }
  rep(i,N-1){
    ans=ans*(i+1)%mod;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 1024
#import numpy as np
#import functools
#import operator
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with
#from itertools import permutations as perm
#import collections as C #most_common
#import math
#import sympy

N = int(input())
#N,K,d= map(int,input().split())
A = list(map(int,input().split()))
#S = str(input())
#T = str(input())
c=0

for i in range(1,N+1):
    if i%2!=0 and A[i-1]%2!=0:
        c+=1
print(c)


Measured memory_bytes: 9160
#include <bits/stdc++.h>
#define INF 1e18
#define MOD 1000000007
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    int a, b, c;
    cin >> a >> b >> c;

    print(a * b / 2);
}

int main()
{
    solve();

    return 0;
}

Measured memory_bytes: 256
using System;

namespace ABC127A
{
    class Program
    {
        static void Main(string[] args)
        {
            var AB = Console.ReadLine().Trim().Split(' ');
            var A = int.Parse(AB[0]);
            var B = int.Parse(AB[1]);

            Console.WriteLine(6 <= A && A <= 12 ? B / 2 : A <= 5 ? 0 : B);
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,w;
  cin>>n>>w;
  vector<Int> a(n),b(n);
  for(Int i=0;i<n;i++) cin>>a[i]>>b[i];
  
  vector<Int> dp(w+1,0);
  for(Int i=0;i<n;i++)
    for(Int j=w-a[i];j>=0;j--)
      chmax(dp[j+a[i]],dp[j]+b[i]);
  
  cout<<*max_element(dp.begin(),dp.end())<<endl;
  return 0;
}


Measured memory_bytes: 1024
d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) for _ in range(d)]

manzoku = 0
log = [-1] * 26
for i in range(d):
    q = t[i]-1
    manzoku += s[i][q]
    log[q] = i
    for j in range(26):
        manzoku -= c[j] * (i-log[j])
    print(manzoku)


Measured memory_bytes: 68604
#include<stdio.h>
typedef long long LL;
const int e[40]={0,1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,5,
                 5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8};
LL IN(void)
{
  LL x=0;short f=0,c=getchar();
  while(c<48||c>57)f^=c==45,c=getchar();
  while(c>47&&c<58)x=x*10+c-48,c=getchar();
  return f?-x:x;
}
int main(void)
{
  int x=0;LL a=0,i,p=1,q=-1,N=IN();
  while(N%2==0){x++;N/=2;}a+=e[x],x=0;
  while(N%3==0){x++;N/=3;}a+=e[x],x=0;
  while(N%5==0){x++;N/=5;}a+=e[x];
  while(q*q<=N)
  {
    p+=6,q+=6;
    x=0;while(!(N%p)){x++;N/=p;}a+=e[x];
    x=0;while(!(N%q)){x++;N/=q;}a+=e[x];
  }
  if(N>1)a++;
  return printf("%lld\n",a),0;
}

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)n; ++i)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<pair<int, int> > vii;


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

	vector<int> h(n), dp(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i]));
	}
	cout << dp[n - 1] << endl;	

}	

  // cout << "Case #" << c++ << ": " << ans << endl;  



Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val k: Int = sc.nextInt()
    val s: Int = sc.nextInt()
    var count = 0
    for (i in 0..k) {
        for (j in 0..k) {
            if (s - i - j in 0..k) {
                count++
            }
        }
    }
    println(count)
}

Measured memory_bytes: 31396
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;
const int mod = 998244353;

long long dp[N][2];
int go[N], sg[4*N];

void upd(int node, int l, int r, int pos, int val) {
	if(r<pos||l>pos) return;
	if(l==r) {
		sg[node] = max(sg[node], val);
		return;
	}
	int mid = (l + r) / 2;
	upd(2*node, l, mid, pos, val);
	upd(2*node+1, mid+1, r, pos, val);
	sg[node] = max(sg[2*node], sg[2*node+1]);
}

int que(int node, int l, int r, int ll, int rr) {
	if(l>rr||r<ll) return -1;
	if(l>=ll&&r<=rr) return sg[node];
	int mid = (l + r) / 2;
	int q1 = que(2*node, l, mid, ll, rr);
	int q2 = que(2*node+1, mid+1, r, ll, rr);
	return max(q1, q2);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;

	vector<pair<int,int>> v(n);
	vector<int> pos;

	for(int i = 0; i < n; i++) {
		cin >> v[i].first >> v[i].second;
	}

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

	for(int i = 0; i < n; i++) go[i] = v[i].first + v[i].second - 1;

	dp[n-1][0] = 1;
	dp[n-1][1] = 1;

	auto last_go = [&](int pos) {
		int val = v[pos].first + v[pos].second - 1;
		int l = pos, r = n-1;
		while(r-l>3) {
			int mid = (l+r)/2;
			if(val>=v[mid].first) l=mid;
			else r=mid-1;
		}
		for(int i = r; i >= 0; i--) {
			if(val>=v[i].first) return i;
		}
		return -1;
	};

	auto mx_go = [&](int l, int r) {
		if(l>r) return -1;
		return que(1, 0, n-1, l, r);
	};

	go[n - 1] = n - 1;
	upd(1, 0, n-1, n-1, n-1);

	for(int i = n - 2; i >= 0; i--) {
		go[i] = last_go(i);
		go[i] = max(go[i], mx_go(i+1, go[i]));
		upd(1, 0, n-1, i, go[i]);
	}


	for(int i = n - 2; i >= 0; i--) {
		dp[i][0] = (dp[i+1][0] + dp[i+1][1])%mod;
		if(v[n-1].first < v[i].first + v[i].second) {
			dp[i][1] = 1;
		}
		else {
			int p = go[i];
			if(p==n-1) dp[i][1]=1;
			else dp[i][1] = (dp[p+1][0] + dp[p+1][1])%mod;
		}
	}

	cout << (dp[0][0] + dp[0][1])%mod;

	return 0;
}


Measured memory_bytes: 8832
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
map<int, int> mp;
int res;
int main()
{
	cin >>n;
	for (int i=0;i<n;i++)
	{
		int x;
		cin >>x;
		mp[x]++;
	}
	for (map<int, int>::iterator it=mp.begin();it!=mp.end();it++)
	{
		int x=it->first,y=it->second;
		if (x==y) continue;
		if (x<y) res+=y-x;
		else res+=y;
	}
	cout <<res;
	return 0;
}

Measured memory_bytes: 4736
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U>
inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U>
inline void cmin(T& a, U b) { if (a > b) a = b; }

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;

constexpr char el = '\n';

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U>& p) {
  os << p.first << " " << p.second;
  return os;
}
template<typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template<typename T>
ostream &operator<<(ostream &os, const vector< T > &v) {
  rep(i, v.size())
    os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T>
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}
#line 2 "b.cpp"

int main() {
  ll n;
  cin >> n;

  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 3 and i%5) {
      ans += i;
    }
  }

  cout << ans << el;
}


Measured memory_bytes: 3652
from sys import stdin

N, D = map(int, input().split())
points = []
for i in range(N):
    X, Y = map(int, stdin.readline()[:-1].split())
    points.append((X, Y))

count = 0
for i in range(N):
    X, Y = points[i]
    d = (X**2 + Y**2) ** 0.5
    if d <= D:
        count += 1

print(count)


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

int main() {
    int N, M;
    cin >> N >> M;
    int left = 0, right = 100000;
    for (int i = 0; i < M; i++) {
        int l, r;
        cin >> l >> r;
        left = max(left, l);
        right = min(right, r);
    }
    if (right - left >= 0) {
        cout << right - left + 1 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from calendar import isleap

flag = False
while True:
    a, b = map(int, input().split())
    if a == 0:
        break
    if flag:
        print()
    flag = True
    ans = [i for i in range(a, b+1) if isleap(i)]
    print("\n".join(map(str, ans)) if len(ans) else "NA")

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

typedef long long ll;

ll ara[10000];
ll mod=1000000007;
void prime(ll n)
{
    while(n%2==0)
    {
        ara[2]++;
        n/=2;
    }
    for(ll i=3;i*i<=n;i+=2)
    {
        while(n%i==0)
        {
            ara[i]++;
            n/=i;
        }
    }
    if(n>2)
    {
        ara[n]++;
    }
    return;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    queue<ll>q,v;
    for(ll i=2;i<=n;i++)
    {
        prime(i);
    }
    ll prd=1;
    prd*=(ara[2]+1);
    for(ll i=3;i<=n;i+=2)
    {
        prd=(prd*(ara[i]+1))%mod;
    }
    cout<<prd<<endl;
    return 0;

}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (h, w, a, b) = readLine()!!.split(' ').map { it.toInt() }
    val s1 = "0".repeat(a) + "1".repeat(w - a)
    val s2 = "1".repeat(a) + "0".repeat(w - a)
    val ans = (0 until h).joinToString("\n") { if (it < b) s1 else s2 }
    println(ans)
}


Measured memory_bytes: 41600
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,n) for(int i=1; i<=(n); i++)

int main() {
    int k,n,ans=0,mx=0;
    string s;
    cin>>k>>n;
    vector<int>x(n);
    rep(i,n)cin>>x[i];
    //
    rep(i,n-1){
        mx=max(mx,x[i+1]-x[i]);
    }
    mx=max(mx,k+x[0]-x[n-1]);
    ans=k-mx;
    cout<<ans;
    return 0;
}



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

using namespace std;
string seats[1000005];

signed main()
{
    int n;
    cin>>n;
    cout<<0<<'\n';
    cout<<flush;
    cin>>seats[0];
    if(seats[0]=="Vacant")
        return 0;
    cout<<n-1<<'\n';
    cout<<flush;
    cin>>seats[n-1];
    if(seats[n-1]=="Vacant")
        return 0;
    
    int l=0,r=n-1;
    while(l+1<r)
    {
        int mid = (l+r)>>1;
        cout<<mid<<'\n';
        cout<<flush;
        cin>>seats[mid];
        if(seats[mid]=="Vacant")
            return 0;
        if(((mid-l+1)&1)==0)
        {
            if(seats[mid]==seats[l])
                r = mid;
            else
                l = mid;
        }
        else
        {
            if(seats[mid]==seats[l])
                l = mid;
            else
                r = mid;
        }
    }
}

Measured memory_bytes: 8660
#include <iostream>
#include <queue>

using namespace std;

static const int MAX=100;
static const int INF =(1<<21);

int n,BY[MAX][MAX];
int dist[MAX];//距離で訪問状態を管理する

void bfs(int);

int main(){
     int i,j,u,k,v;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=0;j<n;j++) BY[i][j]=0;
    }
    for(i=0;i<n;i++){
        scanf("%d%d",&u,&k);
        u--;
        for(j=0;j<k;j++){
            scanf("%d",&v);
            v--;
            BY[u][v]=1;
        }
    }
    bfs(0);

    return 0;
}
void bfs(int s){
    queue<int> q;
    q.push(s);
    for(int i=0;i<n;i++) dist[i]=INF;
    dist[s]=0;
    int u;
    while(!q.empty()){
        u=q.front();
        q.pop();
        for(int v=0;v<n;v++){
            if(BY[u][v]==0) continue;
            if(dist[v]!=INF) continue;
            dist[v]=dist[u]+1;
            q.push(v);
        }
    }
    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<((dist[i]==INF)?(-1):dist[i])<<endl;
    }
}







Measured memory_bytes: 3272
//Solution By SlavicG
#include "bits/stdc++.h"
using namespace std;
 
#define ll                          long long
 
#define forn(i,n)                   for(int i=0;i<n;i++)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
	
#define pb                          push_back
#define sz(a)                       (int)a.size()
 
#define   endl                       "\n"
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int  main()
{
	int k ,a ,b;
	cin >> k >> a >> b;
	for(int i =  a;i <= b;i++)
		if(i % k==0)
		{
			cout << "OK\n";
			return 0;
		}
	cout << "NG\n";
}

Measured memory_bytes: 3524
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
 
 int n,m,q ;
 ll ans=-INF;
vector<int> A ;
 int a[50],b[50],c[50],d[50] ;
void dfs(int i,int x){
  if(i==n){
   ll now=0 ; 
   rep(j,q){
   if(A[b[j]]-A[a[j]]==c[j]) 
     now+=d[j] ; 
   }
  chmax(ans,now) ;
  return  ;
  }
  rep2(j,x,m){
   A.pb(j) ;
   dfs(i+1,j) ;
   A.ppb() ;
  }
}

int main(){
cin>>n>>m>>q ;
rep(i,q){
    cin>>a[i]>>b[i]>>c[i]>>d[i] ;
   a[i]--;b[i] -- ;
   }
  dfs(0, 1) ;
  cout<<ans<<endl ;
  return 0;
  }

Measured memory_bytes: 3648