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

#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 1e9+7;
typedef pair<int,int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int H,W,r=0;
    cin >> H >> W;
    vector<string> f(H);

    rep(i,H)
        cin >> f.at(i);
    
    rep(i,H)
        rep(j,W) {
            if(f.at(i).at(j) == '#')
                continue;
            int tr=0;
            vector<vector<int>> d(H, vector<int>(W, INF));
            queue<P> q;
            q.push(P(i,j));
            d.at(i).at(j) = 0;

            while(!q.empty()) {
                P p = q.front();
                q.pop();
                rep(k,4) {
                    int nh=p.first+dx[k], nw=p.second+dy[k];
                    if(nh<0 || nh>=H || nw<0 || nw>=W)
                        continue;
                    if(f.at(nh).at(nw)!='#' && d.at(nh).at(nw)==INF) {
                        q.push(P(nh,nw));
                        d.at(nh).at(nw) = d.at(p.first).at(p.second) + 1;
                    }
                }
            }

            rep(k,H)
                rep(l,W)
                    if(d.at(k).at(l) != INF)
                        tr = max(tr,d.at(k).at(l));
            r = max(r,tr);
        }

    cout << r << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int cnt[100002] = {};
    int a;
    while (cin >> a) {
        cnt[a-1]++;
        cnt[a]++;
        cnt[a+1]++;
    }
    int maxCnt = 0;
    for (int i=1; i<100001; i++) {
        maxCnt = max(maxCnt, cnt[i]);
    }
    cout << maxCnt << endl;
}

Measured memory_bytes: 3952
import itertools

n, m, q = map(int, input().split())
abcd = [tuple(map(int, input().split())) for _ in range(q)]
ans = 0
for com in itertools.combinations_with_replacement(range(1, m + 1), n):
    score = sum([d for a, b, c, d in abcd if com[b-1] - com[a-1] == c])
    if ans < score:
        ans = score
print(ans)


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

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


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

  vector<ll> a(n);
  vector<ll> b(m);
  rep(j,n) cin >> a[j];
  rep(i,m) cin >> b[i];
   

  ll ans = 0;

  ll sum = 0;
  ll id_a = 0;
  ll id_b = 0;

  while(sum+a[id_a] <= k && id_a < n){
    sum += a[id_a];
    ans ++;
    id_a ++;
  }
  while(sum+b[id_b] <= k && id_b < m){
    sum += b[id_b];
    ans ++;
    id_b ++;
  }

  ll tmp = ans;
  id_a--;
  for(ll i = id_a; i >= 0; i--){
    tmp--;
    sum-=a[i];

    while(sum+b[id_b] <= k && id_b < m){
      sum+=b[id_b];
      tmp++;
      id_b++;
    }

    ans = max(ans, tmp);
  }

  cout << ans << endl;

  return 0;
} 



Measured memory_bytes: 6368
#include <stdio.h>

int kazoeru(char[]);

int main(void)
{
  char A[10],B[10],C[10];
  scanf("%s",A);
  scanf("%s",B);
  scanf("%s",C);
  
  int a = kazoeru(A);
  int b = kazoeru(B);
  
  if((A[a] == B[0]) && (B[b] == C[0]))
    printf("YES");
  else
    printf("NO");
  
  return 0;
}

int kazoeru(char hairetu[])
{
  int i = 0;
  while(hairetu[i] != '\0'){
    i++;
  }
  return i-1;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N, A[101010];
ll cl[101010];
ll i,j,ans;

bool solve(ll a){
    ll i, j;
    fornum(i,0,a+1){
        cl[i] = -1;
    }
    
    fornum(i,0,N){
        ll l = 0, r = a;
        while(l<r){
            ll c = (l + r) / 2;
            if(cl[c]<A[i]){
                r = c;
            }else{
                l = c+1;
            }
        }
        if(l==a){
            return false;
        }
        cl[l] = A[i];
    }
    return true;
}

int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
    }
    ll l = 1, r = N;
    while(l<r){
        ll c = (l + r) / 2;
        if(solve(c)){
            r = c;
        }else{
            l = c + 1;
        }
    }
    printf("%lld", l);

    return 0;
}

Measured memory_bytes: 1792
import sys
import math
import collections
#n = int(input())
a, b = map(int, input().split())
#s = input()
#x = list(map(int, input().split()))

cnt = 1
while (cnt < 2000):
    if math.floor(cnt * 0.08) == a and math.floor(cnt * 0.1) == b:
        print(cnt)
        sys.exit()
    cnt += 1

print(-1)
    


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

int main(){
	bool a[52];
	for (int i = 0; i < 52; i++){
		a[i] = false;
	}
	int n;
	cin >> n;
	char cards[2];
	int cardn;
	for (int i = 0; i < n; i++){
		cin >> cards >> cardn;
		a[(cards[0] == 'S' ? 0 
			: cards[0] == 'H' ? 1 
			: cards[0] == 'C' ? 2 
			: cards[0] == 'D' ? 3 
			: 0) * 13 + cardn - 1] = true;
	}
	for (int i = 0; i < 52; i++){
		if (a[i] == false){
			cout << (i / 13 == 0 ? "S" :
				i / 13 == 1 ? "H" :
				i / 13 == 2 ? "C" :
				i / 13 == 3 ? "D" :
				"S") << " " << i % 13 + 1 << endl;
		}
	}
}

Measured memory_bytes: 3092
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cerr << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ll MOD=1e9+7;
ll dp[605][605],g[605],match[605],dp2[605][605];

int main()
{jizz
	ll n,m,ans=0,a,b,flag;
	cin >> n >> m;
	while(m--)
		cin >> a >> b,match[a]=b,match[b]=a;
	g[0]=1,n*=2;
	for(int i=2;i<=n;i+=2)
		g[i]=g[i-2]*(i-1)%MOD;
	for(int i=1;i<n;i+=2)
		for(int j=1;j+i<=n;++j)
		{
			a=0,b=0,flag=0;
			for(int k=j;k<=j+i&&!flag;++k)
				if(match[k]&&(match[k]<j||match[k]>i+j))
				{
					flag=1;
					break;
				}
			if(flag) continue;
			for(int k=1;k<j;++k)
				if(!match[k]) ++b;
			for(int k=j+i+1;k<=n;++k)
				if(!match[k]) ++b;
			for(int k=j+i-1;k>=j;--k)
			{
				if(!match[k+1]) ++a;
				dp[j][j+i]=(dp[j][j+i]-dp2[j][k]*g[a]%MOD*g[b])%MOD;
				dp2[j][j+i]=(dp2[j][j+i]-dp2[j][k]*g[a])%MOD;
			}
			if(!match[j]) ++a;
			dp[j][j+i]=((dp[j][j+i]+g[a]*g[b])%MOD+MOD)%MOD,dp2[j][j+i]=(dp2[j][j+i]+g[a])%MOD;
			ans=(ans+dp[j][j+i])%MOD;
		}
	cout << ans << "\n";
}

Measured memory_bytes: 5888
#!/usr/bin/env python3
import sys
import math
from fractions import gcd

def my_lcm(a: int, b: int):
    return  abs(a*b) // gcd(a, b)

def nr_divide(a: int, b: int, x: int):
    count = b//x - a//x + 1
    if a % x != 0:
        count -= 1
    return count

def solve(A: int, B: int, C: int, D: int):
    E = my_lcm(C, D)
    N = B - A + 1
    nrC = nr_divide(A, B, C)
    nrD = nr_divide(A, B, D)
    nrE = nr_divide(A, B, E)
    count = N - nrC - nrD + nrE
    print(count)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)
    return

if __name__ == '__main__':
    main()


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

  
// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};
 
int n;
vi c, in, out;
vvi to, vs;
int k = 0;

void dfs(int v = 0, int p = -1){
    in[v] = k; k++;
    for(auto u : to[v]){
        if(u == p) continue;
        dfs(u, v);
    }
    out[v] = k;
}

ll c2(ll x) { return x*(x+1)/2; }

void Main() {
    // ABC163 - F - pass path i //
    
    cin >> n;
    c.resize(n); rep(i, n) {cin >> c[i]; c[i]--;}
    to.resize(n); 
    in.resize(n); out.resize(n);
    vs.resize(n);
    
    rep(i, n-1){
        int a, b; cin >> a >> b; a--; b--;
        to[a].pb(b); to[b].pb(a);
    }
    
    dfs();
    
    /*
    for(auto x : in) cout << x << " ";
    cout << endl;
    for(auto x : out) cout << x << " ";
    cout << endl;
    //*/
    
    rep(i, n) vs[c[i]].pb(i); 
    ll tot = c2(n);
    
    // BIT は 1-indexed であることに注意
    BIT<int> tree(n);
    rep(i, n) tree.add(i, 1);
    
    rep(i, n){
        ll ans = tot;
        vi & nvs = vs[i];
        sort(all(nvs), [&](int a, int b){
            return in[a] > in[b];
        });
        // どこを変えたか
        vector<P> history;
        for(int v : nvs){
            int cnt = 1;
            for(int u : to[v]){
                if(in[u] < in[v]) continue;
                int num = tree.sum(in[u], out[u]);
                ans -= c2(num);
                cnt += num;
            }
            tree.add(in[v], -cnt);
            history.eb(in[v], cnt);
        }
        ans -= c2(tree.sum(0,n));
        for(auto [x, y] : history){
            tree.add(x, y);
        }
        cout << ans << endl;
    }
	return;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 35380
#include<iostream>
using namespace std;
int main(){
    long long n,m,l,num;
    cin>>n>>m>>l;
    int A[n][m],B[m][l];
    for (int a=0;a<n;a++){
        for (int b=0;b<m;b++){
            cin>>num;
            A[a][b]=num;
        }
    }for (int a=0;a<m;a++){
        for (int b=0;b<l;b++){
            cin>>num;
            B[a][b]=num;
        }
    }long long sum=0;
    for (int a=0;a<n;a++){
        for (int c=0;c<l;c++){
            for(int b=0;b<m;b++){
                sum=sum+A[a][b]*B[b][c];
            }cout<<sum;
            sum=0;
            if(c!=l-1) cout<<" ";
        }cout<<endl;
    }return 0;
}


Measured memory_bytes: 3148
#include <stdio.h>

int A[100001], n;
int binary_search(int key)
{
	int left = 0;
	int right = n;
	int mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (A[mid] == key)
			return 1;
		else if (A[mid] > key)
			right = mid;
		else
			left = mid + 1;
	}

	return 0;
}

int main()
{
	int i, n1, key;
	int sum = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &A[i]);
	}

	scanf("%d", &n1);
	for (i = 0; i < n1; i++) {
		scanf("%d", &key);
		sum += binary_search(key);
	}
	printf("%d\n", sum);
	return 0;
}



Measured memory_bytes: 2200
import math

a,b,x = map(int,input().split())
result = 0

if x > (a*a*b/2):
	result = 180/math.pi*math.atan(2*b/a-2*x/(a**3))
else:
	result = 90 - 180/math.pi*math.atan(2*x/(a*b*b))

print(result)

Measured memory_bytes: 3060
/*
[m-solutions2019] F - Random Tournament
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 2000;

int N;
bitset<MAX_N> A[MAX_N];

bitset<MAX_N> dpl[MAX_N], dpr[MAX_N];

ll solve() {
    for (int i = 0; i < N; i++) {
        dpl[i][i] = dpr[i][i] = true;
    }
    for (int l = 1; l < N; l++) {
        for (int i = 0; i + l < N; i++) {
            int j = i + l;
            dpl[j][i] = (A[i] & dpl[j] & dpr[i + 1]).any();
        }
        for (int j = l; j < N; j++) {
            int i = j - l;
            dpr[i][j] = (A[j] & dpr[i] & dpl[j - 1]).any();
        }
    }

    int ans = (dpr[0] & dpl[N - 1]).count();
    return ans;
}

int main() {
    cin >> N;
    for (int i = 1; i < N; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < i; j++) {
            A[i][j] = s[j] == '1';
            A[j][i] = !A[i][j];
        }
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <map>
#include <math.h>
#include <algorithm>
#include <set>
#include <unordered_map>
#define pb          push_back 
#define endl        "\n"
#define mostrar(x,y) cout<<x<<" "<<y<<endl;
#define f           first
#define s           second
#define mod         1000000007
using namespace std;
typedef pair<int,int> ii;
typedef pair<pair<int,int>,int> iii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;

int main(){
    ofstream out("output.txt");

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


    long long   r,D,x2000;
    cin>>r>>D>>x2000;

    int a[11];

    a[0] = x2000;
    long long res;
    for(int i = 1; i<=10; i++){
        res = a[i-1]*r-D;
        a[i] = res; 
        cout<<res<<endl;
    }

    


    return 0;
}







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


  
int main(){
    string s;
    cin >>s;
    ll n=s.length();
    ll r=0;
    ll l=0;
    rep(i,n){
        if(s[i]=='R'){
            r++;
        }else{
            l++;
        }
        if(i==n-1){
            rep(j,r-1){
                cout<<0<<" ";
            }
            if((r+l)%2==0){
                cout<<(r+l)/2<<" "<<(r+l)/2<<" ";
            }
            else if(r%2==0){
                cout<<(r+l)/2<<" "<<(r+l+1)/2<<" ";
            }else{
                cout<<(r+l+1)/2<<" "<<(r+l)/2<<" ";
            }
            rep(j,l-1){
                cout<<0<<" ";
            }
            r=0;
            l=0;

        }else if(s[i]=='L' &&s[i+1]=='R'){
            rep(j,r-1){
                cout<<0<<" ";
            }
            if((r+l)%2==0){
                cout<<(r+l)/2<<" "<<(r+l)/2<<" ";
            }
            else if(r%2==0){
                cout<<(r+l)/2<<" "<<(r+l+1)/2<<" ";
            }else{
                cout<<(r+l+1)/2<<" "<<(r+l)/2<<" ";
            }
            rep(j,l-1){
                cout<<0<<" ";
            }
            r=0;
            l=0;
        }
    }
    cout<<endl;
        
    return 0;
}

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

int main(){
	string s, t, n;

	cin >> s;
	cin >> t;

	n = s + s;
	if(n.find(t) < s.size() ){
		cout << "Yes";
	}
	else{
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
	long long int dp[101][21]={};
	int n,num[101];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>num[i];
	}
	dp[1][num[0]]=1;
	for(int i=1;i<n-1;i++){
		for(int j=0;j<=20;j++){
			if(0<=j+num[i] && j+num[i]<=20)
				dp[i+1][j+num[i]]+=dp[i][j];
			if(0<=j-num[i] && j-num[i]<=20)
				dp[i+1][j-num[i]]+=dp[i][j];
		}
	}
	cout<<dp[n-1][num[n-1]]<<endl;
return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n, a, b, c; scanf("%d%d%d%d", &n, &a, &b, &c);
	std::vector<int> l(n);
	for(int i = 0; i < n; i++) scanf("%d", &l[i]);
	
	int ans = 1 << 30;
	for(int latte = 0; latte < (1 << (2 * n)); latte++) {
		int cost = 0;
		int A = 0, B = 0, C = 0;
		for(int i = 0; i < n; i++) {
			if(((latte >> (2 * i)) & 3) == 0) continue;
			if(((latte >> (2 * i)) & 3) == 1) {
				if(A) cost += 10;
				A += l[i];
			}
			if(((latte >> (2 * i)) & 3) == 2) {
				if(B) cost += 10;
				B += l[i];
			}
			if(((latte >> (2 * i)) & 3) == 3) {
				if(C) cost += 10;
				C += l[i];
			}
		}
		if(!A or !B or !C) continue;
		cost += std::abs(A - a) + std::abs(B - b) + std::abs(C - c);
		ans = std::min(ans, cost);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
import sys
from heapq import heappush, heappop, heapify
import math
from math import gcd
import itertools as it
from collections import deque 

input = sys.stdin.readline

def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
def dbg(o):
    print(o, file=sys.stderr)

# ---------------------------------------

a, b, c, d = inpl()
INF = 10**20

ls = []
ls.append(a*c)
ls.append(b*c)
ls.append(a*d)
ls.append(b*d)
mx = -INF
for i in ls:
    mx = max(mx, i)
print(mx)



Measured memory_bytes: 9464
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(){
  int r,d,i;
  int x[15];

  scanf("%d %d %d", &r, &d, &x[0]);

  for(i = 1;i <= 10;i++){
    x[i] = r*x[i - 1] - d;
    printf("%d\n", x[i]);
  }
  
  return 0;
}

Measured memory_bytes: 128
def main():
    from collections import deque
    import sys;input=sys.stdin.readline

    h,w=map(int,input().split())
    grid=[["#"]*(w+2)]+[list("#"+input()+"#")for x in range(h)]+[["#"]*(w+2)]

    stack=deque()
    for y in range(1,h+1):
        for x in range(1,w+1):
            if grid[y][x]=="#":
                #grid[y][x]=0
                stack.append((y,x))

    for i in range(h*w):
        tmp=deque()
        while stack:
            my,mx=stack.pop()
            for y,x in ([0,1],[1,0],[-1,0],[0,-1]):
                if grid[my+y][mx+x]==".":
                    #grid[my+y][mx+x]=i+1
                    grid[my+y][mx+x]="#"
                    tmp.append([my+y,mx+x])
        stack=tmp
        if not tmp:
            print(i)
            break
if __name__ == '__main__':
    main()

Measured memory_bytes: 130908
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

s = input()

m = {}
m[0] = 0
index = 0
for i in range(20):
    minx = 10 ** i
    maxx = 10 ** (i + 1) - 1
    F_num = maxx // 3 - minx // 3
    B_num = maxx // 5 - (minx - 1) // 5
    FB_num = maxx // 15 - minx // 15
    P_num = maxx - minx - F_num - B_num + FB_num + 1
    m[i + 1] = m[i] + P_num * (i + 1) + F_num * 4 + B_num * 4
    if s <= m[i + 1]:
        s -= m[i]
        index = i + 1
        break

#print index
ans = []
rem = 0

for i in range(index - 1, -1, -1):
    rem *= 10
    lst = range(10)
    if rem == 0:
        lst = range(1, 11)
    for j in lst:
        minx = rem + j * (10 ** i)
        maxx = rem + (j + 1) * (10 ** i) - 1
        F_num = maxx // 3 - (minx - 1) // 3
        B_num = maxx // 5 - (minx - 1) // 5
        FB_num = maxx // 15 - (minx - 1) // 15
        P_num = maxx - minx - F_num - B_num + FB_num + 1
        S_num = P_num * (index) + F_num * 4 + B_num * 4
        #print minx, maxx
        #print S_num
        if s > S_num:
            s -= S_num
        else:
            rem += j
            break
S = ""
for num in range(rem, rem + 100):
    if num % 3 == 0:
        S += "Fizz"
    if num % 5 == 0:
        S += "Buzz"
    if num % 3 != 0 and num % 5 != 0:
        S += str(num)
print S[s - 1:s + 19]


Measured memory_bytes: 5008
n = int(input())
h = list(map(int,input().split()))
pre = 0
cont = 0
g = 0
for i in range(n):
    if i==0:
        pre = h[i]
    else:
        if pre >= h[i]:
            cont += 1
        else:
            g = max(g,cont)
            cont = 0
    if (i==n-1):
        g = max(g,cont)
    pre = h[i]
print(g)

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

/* Faulty First Draft (Took Hours to debug this)
 * You were doing mod with dp but not prefix sum
 * That was a grave mistake
 */

/* Faulty First Draft (2 Penalties)
 * The mod can become negative, even if the original
 * difference was positive. Why?
 */
const int mod = 1e9 + 7;

inline int add(int a, int b)
{
	long long int x = a;
	long long int y = b;
	
	int res = (x + y)%mod;	

	if(res < 0)
		res += mod;

	return res;
}

void Candies_DP(vector<int> &a, int totalCandies)
{
	int n = a.size();

	vector<vector<int>> dp(n, vector<int>(totalCandies + 1, 0));
	vector<vector<int>> prefix(n, vector<int>(totalCandies + 1, 0));

	/* dp[i][j] represents the total number of ways to distribute j candies
	 * to the children [0...i]
	 */

	/* prefix[i][j] is the sum of dp[i][k] where k ranges from 0 to j */

	/* Base case : One children. The candies should be less than or equal to what he can take */
	
	int i = 0;
	for(int j = 0; j <= totalCandies; j++)
	{
		if( a[0] >= j)
			dp[i][j] = 1;
		
		prefix[i][j] = dp[i][j];

		if( j != 0)
			prefix[i][j] = add(prefix[i][j], prefix[i][j-1]);
	}

	for(int i = 1; i < n; i++)
	{
		for(int j = 0; j <= totalCandies; j++)
		{
			/* dp[i][j] is the sum of all dp[i-1][k]
			 * where k belongs to [j-a[i], j - 0]
			 */
			int left = j - a[i];

			if(left < 0)
				left = 0;

			int right = j;
			
			// Faulty First Draft : Took prefix[i] instead of prefix[i-1]
			dp[i][j] = add(dp[i][j], prefix[i-1][right]);

			if(left != 0)
				dp[i][j] = add(dp[i][j], -1*prefix[i-1][left-1]);
			
			prefix[i][j] = dp[i][j];

			if(j != 0)
				prefix[i][j] = add(prefix[i][j], prefix[i][j-1]);
		}
	}
	
	cout << dp[n-1][totalCandies] << endl;
}

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

	vector<int> a(n);
	for(auto &ele : a)
		cin >> ele;

	Candies_DP(a, totalCandies);
	return 0;
}

					


Measured memory_bytes: 78968
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
    int x;
    int y;

}a[105],b[105];

int cmp(struct node p,struct node q)
{
    if(p.x==q.x)
    {
        return p.y<q.y;

    }
    else
        return p.x<q.x;
}

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {

        cin>>a[i].x>>a[i].y;
    }

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

        cin>>b[i].x>>b[i].y;

    }
    
    sort(b,b+n,cmp);

    int c[105];
    memset(c,0,sizeof(c));
    int ans=0;
    for(int i=0;i<n;i++)
    {
    	int max=-1;int z=-1;
        for(int j=0;j<n;j++)
        {
            if(!c[j]&&a[j].x<b[i].x&&a[j].y<b[i].y&&a[j].y>max)
            {
                max=a[j].y;
                z=j;
            }

        }
        if(max!=-1)
        {
        	c[z]=1;
        	ans++;
		}

    }


    cout<<ans<<endl;


    return 0;

}


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

int main() {
  int p, q;
  while(cin >> p >> q) {
    bool num[1000000] = {}; num[p] = 1;
    int pos[1000000] = {}; pos[p] = -1;
    bool loop = 0;
    int cnt = 0;
    string t;
    while(1) {
      p *= 10;
      t += (char)(p/q + '0');
      p %= q;
      if(num[p] == 1) {
	loop = 1;
	break;
      }
      num[p] = 1;
      if(p == 0) break;
      pos[p] = cnt++;
    }
    
    cout << t << endl;
    
    if(loop) {
      int I;
      for(I=0; I<=pos[p]; I++) {
	cout << ' ';
      }
      for(I; I<t.size(); I++) {
	cout << '^';
      }
      cout << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 6088
n,m = map(int,input().split())
a = list(map(int,input().split()))

fm = 0
for i in range(40,0,-1):
    x = 2**(i-1)
    p = 0
    q = 0
    for j in a:
        b = x & j
        p += x ^ b
        q += b
    if q >= p:
        fm += q
    else:
        if m >= x:
            fm += p
            m -= x
        else:
            fm += q
print(fm) 

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

using namespace std;

#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define fd(i,b,a) for(int i=(b);i>=(a);--i)

typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x;cin>>x;
    if(x==0)cout<<1;
    if(x==1)cout<<0;
    return 0;
}

Measured memory_bytes: 3652
N = int(input())
V = list(map(int, input().split()))
Vs = sorted(V)
x=0
for i in range(N-1):
  if i == 0:
    x += (Vs[i] + Vs[i+1]) / 2 ** (N-i-1)
  else:
    x += (Vs[i+1]) / 2 ** (N-i-1)

print(x)
  

Measured memory_bytes: 2940
#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, m;
  cin >> n >> m;

  vector<int> rem(m, 0);
  vector<int> c(m, 0);
  vector<queue<int>> q(n, queue<int>());
  int x;
  rep(i,n)rep(j,m) {
    cin >> x;
    q[i].push(x-1);
  }

  int ans = n;

  rep(k,m-1) {
    fill(c.begin(), c.end(), 0);
    rep(j,n) c[q[j].front()] += 1;
    int mi = 0;
    rep(i,m) if(c[i] > c[mi]) mi = i;
    ans = min(ans, c[mi]);
    rem[mi] = 1;
    rep(j,n) while(rem[q[j].front()]) q[j].pop();
  }

  cout << ans << endl;

  return 0;
}


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

bool isPrime(int n) {
    switch(n) {
        case 0:
        case 1: return false;
        case 2:
        case 3: return true;
    }

    if(n%2 == 0) return false;
    if(n%3 == 0) return false;
    if(n%6 != 1 && n%6 != 5) return false;

    for(int i=5; i*i<=n; i+=6) {
        if(n%i==0) return false;
        if(n%(i+2)==0) return false;
    }

    return true;
}

int main() {
    int q,l,r;
    int count[100001]={};
    for(int i=0; i<100001; i++) {
        if(isPrime(i) && isPrime((i+1)/2)) {
            count[i] = count[i-1]+1;
        } else{
            count[i] = count[i-1];
        }
    }

    cin >> q;
    while(q--) {
        cin >> l >> r;
        cout << count[r]-count[l-1] << endl;
    }
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int N = int.Parse(input[0]);
    int Q = int.Parse(input[1]);
    
    Dictionary<int, List<int>> Tree = new Dictionary<int, List<int>>();
    for (int i = 0; i < N - 1; i++)
    {
      string[] ab = Console.ReadLine().Split(' ');
      int a = int.Parse(ab[0]) - 1;
      int b = int.Parse(ab[1]) - 1;
      
      if (Tree.ContainsKey(a)){
        Tree[a].Add(b);
      }
      else{
        List<int> val = new List<int>(){b};
        Tree.Add(a, val);
      }
      
      if (Tree.ContainsKey(b)){
        Tree[b].Add(a);
      }
      else{
        List<int> val = new List<int>(){a};
        Tree.Add(b, val);
      }
      
    }
    
    // 各点に加算される値
    int[] c = new int[N];
    for (int i = 0; i < Q; i++)
    {
      string[] p = Console.ReadLine().Split(' ');
      c[int.Parse(p[0]) - 1] += int.Parse(p[1]);
    }
    
    // 出力の初期化
    int[] buf = new int[c.Length];
    for (int i = 0; i < buf.Length; i++)
    {
      buf[i] = -1;
    }
    buf[0] = c[0];
    
    // 再起関数
    c = CountRec(c, buf, 0, Tree);
    
    Console.WriteLine(string.Join(" ", c));
  }
  
  static int[] CountRec(int[] c, int[] ans, int x, Dictionary<int, List<int>> Tree)
  {
    if (Tree.ContainsKey(x))
    {
      List<int> ys = Tree[x];
      foreach (int y in ys)
   	  {
        if (ans[y] == -1){
          ans[y] = c[y] + ans[x];
          ans = CountRec(c, ans, y, Tree);
        }
   	  }
    }
    return ans;
  }
}

Measured memory_bytes: 83600
import re
s = 0

while True :
    try :
        text = input()
    except EOFError :
        break

    regex = re.compile('\d+')

    for line in text.splitlines():
        match = regex.findall(line)
    
    
    for i in range(len(match)) :
        s += int(match[i])
print(s)


Measured memory_bytes: 6556
/* 十 聖イシドールスよ、迷えるプログラマを導き給え！ 十 */
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <deque>
 
#define rep(i, n) for(int i = 0; i < n; i++)
 
//const long long INF = 1LL << 60;
const int INF = 1e9;
using ll = long long;

int main()
{
    int N;
    std::cin >>  N;
    std::vector<std::pair<int, int>> D(N);
    for(int i = 0; i < N; i++)
    {
        int buf1, buf2;
        std::cin >> buf1 >> buf2;
        D[i].first = buf1;
        D[i].second = buf2;

    }

    int ans = 0;
    rep(i, N-2)
    {
        if(D[i].first == D[i].second)
        {
            if(D[i+1].first == D[i+1].second)
            {
                if(D[i+2].first == D[i+2].second)
                {
                    ans++;
                }
            }            
        }
    }

    if(ans != 0)
    {
        std::cout << "Yes";
    }
    else
    {
        std::cout << "No";
    }
    
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
#define showm(m) for(auto i: m){cout << m.x << " ";}
#define ENTER cout<<endl
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;

ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

#define NODE 100050
int visited[NODE] = {0};
vector<int> mid(NODE);
vector<vector<P>> line(NODE);
vector<int> ans;

int dfs(int n){
    visited[n] = 1;
    
    for(P next: line[n]){
        if(visited[next.first]) continue;
        int l = dfs(next.first);
        if(l) ans.push_back(next.second);
        mid[n] = mid[n]^l;
    }

    return mid[n];
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<Pl> ab(n);
    vector<Pll> lr(m);
    rep(i,n) cin >> ab[i].first >> ab[i].second;
    rep(i,m) cin >> lr[i].first >> lr[i].second;
    // rep(i, n){ ll tmpa; int tmpb; cin >> tmpa >> tmpb; ab[i]={tmpa, tmpb};}
    // rep(i, m){ ll tmpa; ll tmpb; cin >> tmpa >> tmpb; lr[i]={tmpa, tmpb};}

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

    vector<int> bom(n+2);
    bom[0] = 0; bom[n+1] = 0;
    rep(i, n) bom[i+1] = ab[i].second;
    rep(i, n+1) mid[i] = bom[i] == bom[i+1] ? 0 : 1;

    vector<tuple<int, int, int>> range;
    rep(i, m) {
        int from = lower_bound(ab.begin(), ab.end(), Pl(lr[i].first, 0)) - ab.begin();
        int to = upper_bound(ab.begin(), ab.end(), Pl(lr[i].second, 1)) - ab.begin();
        int id = i+1; 
        range.emplace_back(from,to,id);
    }

    // show(bom);ENTER;
    // show(mid);ENTER;
    // rep(i, m) cout << get<0>(range[i]) << get<1>(range[i]) << endl;


    rep(i, m){
        int from, to, id;
        tie(from,to,id) = range[i];
        line[from].emplace_back(to, id);
        line[to].emplace_back(from, id);
    }

    rep(i, n+1){
        if(visited[i]==1) continue;
        if(dfs(i)) {puts("-1"); return 0;}
    }

    sort(ans.begin(), ans.end());
    cout << ans.size() << endl;
    rep(i, ans.size()){
        cout << ans[i] <<" ";
    }
    return 0;
}


Measured memory_bytes: 22384
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n, MOD = map(int,input().split())
    E = [[] for _ in range(n)]
    nv_to_idx = [{} for _ in range(n)]
    for _ in range(n - 1):
        u, v = map(int,input().split())
        u -= 1; v -= 1
        nv_to_idx[u][v] = len(E[u])
        nv_to_idx[v][u] = len(E[v])
        E[u].append(v)
        E[v].append(u)

    # tree DP
    dp = [1] * n
    deg = [len(E[v]) - 1 for v in range(n)]
    deg[0] += 1
    stack = [(0, -1)]
    while stack:
        v, p = stack.pop()
        if v >= 0:
            for nv in E[v]:
                if nv == p:
                    continue
                stack.append((~nv, v))
                stack.append((nv, v))
        else:
            if deg[~v] == 0:
                dp[p] = dp[p] * (dp[~v] + 1) % MOD
            deg[p] -= 1

    # rerooting
    def rerooting(v, p):
        # p-rooted -> dp[p] を v-rooted に modify
        if p != -1:
            idx = nv_to_idx[p][v]
            dp[p] = cum_left[p][idx] * cum_right[p][idx + 1] % MOD

        # monoid に対する cumulative sum を計算
        if cum_left[v] is None:
            k = len(E[v])
            left = [1] * (k + 1)
            right = [1] * (k + 1)
            for i in range(k):
                left[i + 1] = left[i] * (dp[E[v][i]] + 1) % MOD
            for i in range(k - 1, -1, -1):
                right[i] = right[i + 1] * (dp[E[v][i]] + 1) % MOD
            cum_left[v] = left
            cum_right[v] = right

        # dp[v] を v-rooted に modify
        dp[v] = cum_left[v][-1]

    ans = [None] * n
    stack = [(0, -1)]
    cum_left = [None] * n
    cum_right = [None] * n
    while stack:
        v, p = stack.pop()
        if v >= 0:
            rerooting(v, p)
            ans[v] = dp[v]
            for nv in E[v]:
                if nv == p:
                    continue
                stack.append((~nv, v))
                stack.append((nv, v))
        else:
            rerooting(p, ~v)

    print(*ans, sep = '\n')
resolve()

Measured memory_bytes: 129840
import java.util.*;
public class Main{
 public static void main(String[] args) {
   Scanner kbd = new Scanner(System.in);
   int n=kbd.nextInt();
   String[] A= new String[n];
   for(int i=0;i<n;i++){
     A[i]=kbd.next();
}
int x=1;
Arrays.sort(A);
for(int i=0;i<n-1;i++){
if(!(A[i].equals(A[i+1]))){
  x=x+1;
}
}
System.out.println(x);
}
}


Measured memory_bytes: 69988
#include<queue>
#include<string>
#include<iostream>
using namespace std;
int main()
{
    string cmd;
    priority_queue<int>Q;
    int a;
    while(cin>>cmd&&cmd!="end")
    {
        if(cmd=="insert")
        {
            cin>>a;
            Q.push(a);
        }
        else if(cmd=="extract")
        {
            cout<<Q.top()<<endl;
            Q.pop();
        }
    }
    if(cin>>cmd&&cmd=="end")
        return 0;
    return 0;
}


Measured memory_bytes: 6960
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 998244353;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	int a, b, c, d; cin >> a >> b >> c >> d;
	VVI dp(d+1,VI(c+1,0)); dp[b][1]=1;
	for(int i=b+1;i<=d;i++){
		ll sum=0;
		for(int j=1;j<=c;j++){
			if(j>a)
				sum*=i-1;
			sum%=MOD;
			dp[i][j]=sum+(dp[i-1][j]*j)%MOD;
			sum+=dp[i-1][j];
			sum%=MOD;
		}
	}
	ll ans=0, p=1;
	for(int i=c;i>=1;i--){
		ans+=(dp[d][i]*p)%MOD;
		ans%=MOD;
		if(i>a)
			p=(p*d)%MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 73652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N, M, K;
string S, T;
vector<vector<int>> A;
vector<int> B;
//=============================
void input()
{
    cin >> N >> M;
    A.resize(N);
    rep(i, M)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        A[a].push_back(b);
        A[b].push_back(a);
    }
}
//=============================
void dfs(int now, int visited, int &ans)
{
    visited += (1 << now);
    if (visited == (1 << N) - 1)
    {
        ans++;
        return;
    }
    for (auto x : A[now])
    {
        if (visited >> x & 1)
            continue;
        dfs(x, visited, ans);
    }
}
//=============================
void solve()
{
    int ans = 0;
    dfs(0, 0, ans);
    cout << ans << endl;
}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll K, A, B;
  cin >> K >> A >> B;
  ll i = 0;
  ll ans = 1;
  while(i < K) {
    if(B - A > 2 && ans >= A && K - i >= 2) {
      ans += B - A;
      i += 2;
    } else {
      ans++;
      i++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(){
  long long A, B, V, W, T;
  cin >> A >> V >> B >> W >> T;
  
  if(V - W > 0 && abs(B - A) <= T * (V - W)) puts("YES");
  else puts("NO");
  
  return 0;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {
	static int goal;

	static ArrayList<Integer> list = new ArrayList<>();
	static int[] cache;

	// static int[] result;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		goal = sc.nextInt();
		// result = new int[goal + 1];
		// Arrays.fill(result, -1);
		int c = sc.nextInt();
		for (int i = 0; i < c; i++) {
			list.add(sc.nextInt());
		}
		cache = new int[goal + 1];
		Collections.sort(list, Collections.reverseOrder());
		System.out.println(compute(goal));

	}

	public static int compute(int value) {
		if (cache[value] != 0) {
			return cache[value];
		}
		HashSet<Integer> set = new HashSet<Integer>();
		for (int e : list) {
			if (e == value) {
				cache[value] = 1;
				return 1;
			}
			if (e < value) {
				int coins = 1;
				coins += compute(value - e);
				set.add(coins);

			}
		}
		int result = Integer.MAX_VALUE;
		for (int e : set) {
			if (e < result) {
				result = e;
			}
		}
		cache[value] = result;
		return result;

	}

}

Measured memory_bytes: 62732
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

vector<int> A;

int main() {
   int a;
   for (int i = 0; i < 3; i++) {
       cin >> a;
       A.push_back(a);
   }

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

   int ans = 0;
   for (int i = 2; i > 0; i--) {
       ans += A[i] - A[i - 1];
   }

   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = list(map(int,readline().split()))
a.sort()

if a[0] == a[-1]:
  if n > 1:
    print(0)
  else:
    print(1)
  exit()

def gcd(a, b):
    while b: a, b = b, a % b
    return a
def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2, 7, 61] if n < 1<<32 else [2, 3, 5, 7, 11, 13, 17] if n < 1<<48 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1: continue
        while y != n - 1:
            y = y * y % n
            if y == 1 or t == n - 1: return 0
            t <<= 1
    return 1
def findFactorRho(n):
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g): return g
            elif isPrimeMR(n // g): return n // g
            return findFactorRho(g)
def primeFactor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i * i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k: ret[i] = k
        i += i % 2 + (3 if i % 3 == 1 else 1)
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k
 
    if n > 1: ret[n] = 1
    if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
    return ret

def divisors(N):
    pf = primeFactor(N)
    ret = [1]
    for p in pf:
        ret_prev = ret
        ret = []
        for i in range(pf[p]+1):
            for r in ret_prev:
                ret.append(r * (p ** i))
    return ret
    
s = set()
ans = 0
for nm,i in enumerate(a):
  c = set(divisors(i))
  if c&s == set() and ((nm < n-1 and a[nm+1] != i) or nm == n-1): 
    ans += 1
  s.add(i)

print(ans)

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

int main() {
  string S;
  cin >> S;
  
  int year = atoi(S.substr(0, 4).c_str());
  int month = atoi(S.substr(5, 2).c_str());
  int day = atoi(S.substr(8, 2).c_str());
  
  string result = "Heisei";
  if (year > 2019 || year == 2019 && month > 4) {
    result = "TBD";
  }
  
  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int N,H,W;
	cin>>N>>H>>W;
	int ans=0;
	fx(N){
		int a,b;
		cin>>a>>b;
		if(a>=H&&b>=W){
			ans++;
		}
	}
	ce(ans)
}

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

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;
int x[100010] = {0};

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

    int zis = 0;
    vector<int> m,p;
    REP(i,n){
        int a;
        cin >> a;
        if(a > 0) p.push_back(a);
        if(a < 0) m.push_back(-a);
        if(a == 0)k--;
    }
    if(k == 0){
        cout << 0;
        return 0;
    }
    SORT(m);
    SORT(p);
    int ans = 10000000000;

    if(m.size() >= k) ans = min(ans,m[k-1]);
    if(p.size() >= k) ans = min(ans,p[k-1]);

    for(int i = 1;i <= k-1;i++){
        if(i <= m.size() && k-i <= p.size()){
            ans = min(ans, 2*m[i-1] + p[k-i-1]);
            ans = min(ans, m[i-1] + 2*p[k-i-1]);
        } 
    }
    cout << ans;


    
    return 0;
}
//g++ -std=c++14 code1.cpp


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

using ll = long long;

const int mod = 1000000007;
const int INF = 1000000000;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    map<string, int> mp;
    int ma = 0;
    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        mp[s]++;
        ma = max(ma, mp[s]);
    }
    vector<string> ans;
    for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
        if (itr->second == ma) ans.push_back(itr->first);
    }
    for (string s : ans) cout << s << endl;
}


Measured memory_bytes: 25584
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
typedef long long ll;

int h[100010];
int main(){
    int n;
    cin>>n;
    REP(i,n) cin>>h[i];
    bool flag=true;
    int max_h=h[0];
    for (int i = 0; i < n; i++)
    {
        
      
        if(h[i]>=max_h){
            max_h=h[i];
        }
          if(h[i]-max_h<-1){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    

    return 0;
}

Measured memory_bytes: 640
s = input()
boundary = [-1]
child = [0]*len(s)
lasti = 0
for i in range(len(s)-1):
    if s[i] == "L" and s[i+1] == "R":
        boundary.append(i)
        
boundary.append(len(s)-1)
n = len(boundary) if len(boundary) else 0
for i in range(n-1):
    start = boundary[i]+1
    end = boundary[i+1]
    for j in range(start,end+1):
        if s[j] == "R" and s[j+1] == "L":
            child[j] += (j-start)//2
            child[j] += (end - j)//2
            child[j] += 1
            j+=1
            child[j] += (j-start)//2
            child[j] += (end - j)//2
            child[j] += 1
            
print(*child)

    

        

Measured memory_bytes: 8304
#include <iostream>
#include <cstdio>
#include <string>
#include <cctype>
#include <algorithm>
using namespace std;


int main(){
  string s;
  getline(cin,s);
  
  for(int i=0;i<s.size();i++){
    s[i] = toupper(s[i]);
    printf("%c",s[i]);
  }
  cout << endl;
  
}

Measured memory_bytes: 1168
#include "bits/stdc++.h"
using namespace std;
#ifdef LOCAL
#define debug(x)   cerr<<#x<<" = "<<x<<endl
#else
#define debug(x) 
#endif
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define pii pair<int,int>
#define endl '\n'
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
const int inf = 1e18 + 5;
signed main()
{
    #ifdef LOCAL
        input_from_file;
        output_to_file;
    #endif 
    IOS
    int n; cin>>n;
    string str; cin>>str;
    if(n%2){
        cout<<"No";
        return 0;
    }
    for(int i=0;i<n/2;i++)
    {
        if(str[i] != str[n/2 + i]){
            cout<<"No";
        return 0;
        }
    }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <iomanip>
#include <cmath>

#define vi vector<int>
#define tests int t; cin>>t; while(t--)
#define ll long long
#define vll vector<long long>
#define sort(v) sort(v.begin(), v.end())
#define sortg(v) sort(v.begin(), v.end(), greater<int> ())

using namespace std;

char nums[10] = { '0','1','2','3','4','5','6','7','8','9' };
char alphsl[26] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
const ll MOD = 1000000007;

using namespace std;

double res(int h, int c, int a) {
	int pp = 0;
	if (a % 2 == 0) {
		pp= (h + c) * (a / 2);
		
	}
	else pp= ((h + c) * ((a - 1) / 2)) + h;
	return pp / a;
}



void solve() {

	int n;
	cin >> n;
	vll v(n);
	
	for (auto& x : v) cin >> x;

	ll currsum = 0;

	for (int i = 0; i < n; i++) 
		currsum += v[i];
	
	ll ans = 0, currdif=0;
	for (int i = 0; i < n; i++) {
		currdif += v[i];
		ans += v[i] * ((currsum - currdif)%MOD);
		ans %= MOD;
	}
	cout << ans << endl;
}

int main() {


	
	solve();

	return 0;
}

Measured memory_bytes: 4828