akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int max=100001;
  vector<int> a(max,1);
  a[0]=0;
  a[1]=0;
  for(int i=2;i<max;i++){
    for(int j=i*2;j<max;j+=i) a[j]=0;
  }
  vector<int> b(max,0);
  for(int i=0;i<max;i++){
    if(a[i]==1&&a[(i+1)/2]) b[i]=1;
  }
  
  vector<int> s(max+1,0);
  for(int i=0;i<max;i++) s[i+1]=s[i]+b[i];
  
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int l,r;
    cin>>l>>r;
    r++;
    cout<<s[r]-s[l]<<endl;
    }
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}

int main(){
    ld a,b,h,m;
    cin >> a >> b >> h >> m;
    ld x1,y1,x2,y2,s1,s2;
    s1=m/30*M_PI;
    s2=(60*h+m)/360*M_PI;
    y2=cos(s2)*a;
    x2=sin(s2)*a;
    y1=cos(s1)*b;
    x1=sin(s1)*b;
    cout  << setprecision(100) << sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) << endl;
    return 0;
}
 
 


Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
    long long int a, b, c, k;
    
    cin >> a >> b >> c >> k;
    
//    if ((a + b + c) * pow(2,k) > pow(10, 18)){
//        cout << "Unfair" << endl;
//        return 0;
//    }
        
    
    if (k % 2 == 0)
        cout << a - b << endl;
    else
        cout << b - a << endl;
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String c = sc.next();

        if( Character.isUpperCase( c.charAt( 0 ) ) ) {
            System.out.println( "A" );
        }
        else {
            System.out.println( "a" );
        }
    }
}


Measured memory_bytes: 35660
N,Ma,Mb = map(int,input().split())
first_half = []
last_half = []
for i in range(N):
	a,b,c = map(int,input().split())
	if i < N // 2:
		first_half.append((a,b,c))
	else:
		last_half.append((a,b,c))

first_half_combination = {}
last_half_combination = {}
def make_all_combination(i,a,b,c,d_list,flag):
	if i == len(d_list):
		if c == 0:
			return

		w = Ma * b - Mb * a
		if flag:
			if w not in first_half_combination or c < first_half_combination[w]:
				first_half_combination[w] = c
		else:
			if -w not in last_half_combination or c < last_half_combination[-w]:
				last_half_combination[-w] = c
		return
	make_all_combination(i+1,a,b,c,d_list,flag)
	make_all_combination(i+1,a+d_list[i][0],b+d_list[i][1],c+d_list[i][2],d_list,flag)

make_all_combination(0,0,0,0,first_half,True)
make_all_combination(0,0,0,0,last_half,False)

INF = 10**8
f_0 = first_half_combination[0] if 0 in first_half_combination else INF
l_0 = last_half_combination[0] if 0 in last_half_combination else INF
ans = min(f_0,l_0) if min(f_0,l_0) < INF else -1
for w in first_half_combination.keys():
	if w == 0:
		continue
	if w in last_half_combination:
		cost = first_half_combination[w] + last_half_combination[w]
		if w == 0:
			cost = min(first_half_combination[w], last_half_combination[w])
		if ans == -1 or cost < ans:
			ans = cost
print(ans)

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

int main(void) {

  int n;
  cin >> n;

  vector<int> A(n);

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

  for (int i = 0; i < n; i++) {
    cout << A[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3976
import math
a, b, c = map(int, input().split())

sinc = math.sin(math.radians(c))
cosc = math.cos(math.radians(c))

S = a * b * sinc / 2

L = a + b + math.sqrt(a**2 + b**2 - (2 * a * b * cosc))

H = b * sinc

print(S, L, H)


Measured memory_bytes: 5708
//2分探索したよ!!
#include<iostream>
#include<algorithm>
using namespace std;
#define INF ( 1 << 30 )
int n, m, book[100];
bool basic(double x){
  int index = 0, dan = 0, c = 0;
  while(index < n && dan < m){
    if(c + book[index] <= x) c += book[index++];
    else c = 0, dan++;
  }
  return index == n && dan < m;
}
int main(){
  while(cin >> m >> n , m){
    for(int i = 0 ; i < n ; i++ ) cin >> book[i];
    int light = 0, left = INF;
    for(int i=0 ; i < 100 ; i++){
      int java = (light + left ) / 2;
      basic(java) ? left = java : light = java;
    }
    cout << max(light,left) << endl;
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
void solve(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a.at(i);
    int count=0;

    rep(i,n){
        int minj=i;
        for(int j=i;j<n;j++){
            if(a.at(j)<a.at(minj)) minj=j;
        }
        if(a.at(minj)!=a.at(i)) count++;
        int tmp=a[i];
        a[i]=a[minj];
        a[minj]=tmp;
    }

    rep(i,n){
        cout<<a.at(i);
        if(i==n-1) cout<<endl;
        else cout<<" ";
    }
    cout<<count<<endl;

    
}
int main(){
    solve();
    return 0;
}


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

int n;
long long sum;
int cnt[100005];

int main(){

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

    cin>>n;
    for(int i=1;i<=n;i++){
        int t;
        cin>>t;
        sum+=t;
        cnt[t]++;
    }
    int q;
    cin>>q;
    while(q--){
        int b,c;
        cin>>b>>c;
        sum-=(long long)cnt[b]*b;
        sum+=(long long)cnt[b]*c;
        cnt[c]+=cnt[b];
        cnt[b]=0;
        cout<<sum<<endl;
    }

    return 0;
}

Measured memory_bytes: 3988
#include <stdio.h>


int main(void){
	int n,r,p,c,i,j,k;
	
	while(1){
		scanf("%d %d",&n,&r);
		if(n == 0) break;
		int huda[51],pre[51];
		for(i = 0;i < n;i++){
			huda[i] = i;
			pre[i] = i;
		}
		for(j = 0;j < r;j++){
			scanf("%d %d",&p,&c);
			for(k = n - p - c + 1;k < n - c;k++) huda[k] = pre[k + c];
			for(k = n - c;k < n;k++) huda[k] = pre[k - p + 1];
			for(i = 0;i < n;i++) pre[i] = huda[i];
		}
		printf("%d\n",huda[n - 1] + 1);
	}
	return 0;
}


Measured memory_bytes: 2016
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure abc170a is
	x : Integer;
begin
	for i in 1 .. 5 loop
		get(x);
		if x /= i then
			put(Integer'Image(i));
			exit;
		end if;
	end loop;
end abc170a;

Measured memory_bytes: 3520
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;

#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD = 1000000007;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };


int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(0, (min(b, d) - max(a, c))) << endl;
	return 0;
}

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

signed main() {
	bool kata = false;
	int n;
	cin >> n;
	vector<string> v(n);
	for (int i = 0; i < n; ++i)cin >> v[i];
	int ab = 0;
	int aend = 0;
	int bstart = 0;
	for (string s : v) {
		for (int i = 1; i < s.size(); ++i) {
			if (s[i - 1] == 'A' && s[i] == 'B')++ab;
		}
		if (s[0] == 'B') ++bstart;
		if (s.back() == 'A')++aend;
		if ((s[0] == 'B') ^ (s.back() == 'A'))kata = true;
	}
	if (kata)cout << ab + min(aend, bstart) << endl;
	else cout << ab + max(0ll, aend - 1) << endl;
}


Measured memory_bytes: 768
import itertools
n, x = map(int, input().split())

while n != 0 or x != 0:
    ans = 0
    for c in itertools.combinations(list(range(1, n+1)), 3):
        if sum(c) == x:
            ans += 1

    print(ans)

    n, x = map(int, input().split())


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

typedef pair<int,int> hashv;
const ll mod1=1000000007;
const ll mod2=1000000009;

hashv operator + (hashv a,hashv b) {
	int c1=a.fi+b.fi,c2=a.se+b.se;
	if (c1>=mod1) c1-=mod1;
	if (c2>=mod2) c2-=mod2;
	return mp(c1,c2);
}

hashv operator - (hashv a,hashv b) {
	int c1=a.fi-b.fi,c2=a.se-b.se;
	if (c1<0) c1+=mod1;
	if (c2<0) c2+=mod2;
	return mp(c1,c2);
}

hashv operator * (hashv a,hashv b) {
	return mp(1ll*a.fi*b.fi%mod1,1ll*a.se*b.se%mod2);
}
const int N=210000;
map<hashv,int> st,stt;
int n,cnt[40];
char s[1010000];
hashv val[N];

struct Hash_table {
	static const int V=50010003;
	int fst[V],nxt[V];
	int ctm,ptm[V],T;
	int val[V];
	hashv key[V];
	void init() { T=0; ctm++;}
	void add(hashv s) {
		int S=(s.fi*mod2+s.se)%V;
		if (ptm[S]!=ctm) ptm[S]=ctm,fst[S]=-1;
		for (int j=fst[S];j!=-1;j=nxt[j]) if (key[j]==s) {
			val[j]++;
			return;
		}
		nxt[T]=fst[S],fst[S]=T,key[T]=s,val[T]=1;
		T++;
	}
	int query(hashv s) {
		int S=(s.fi*mod2+s.se)%V;
		if (ptm[S]!=ctm) return 0;
		for (int j=fst[S];j!=-1;j=nxt[j]) if (key[j]==s) 
			return val[j];
		return 0;
	}
}Hash;


int main() {
	scanf("%d",&n);
	hashv base(13331,23333);
	Hash.init();
	rep(i,0,n) {
		scanf("%s",s);
		int m=strlen(s);
		reverse(s,s+m);
		hashv p(0,0);
		rep(i,0,26) cnt[i]=0;
		rep(i,0,m) cnt[s[i]-'a']++;
		rep(i,0,m) {
			rep(j,0,26) if (cnt[j]>0) {
				auto q=p;
				q=q*base+hashv(j+'a',j+'a');
				Hash.add(q);
			}
			cnt[s[i]-'a']--;
			p=p*base+hashv(s[i],s[i]);
		}
		stt[p]++;
		val[i]=p;
	}
	ll ans=0;
	rep(i,0,n) ans+=Hash.query(val[i]);
	for (auto p:stt) {
		ans=ans-(ll)p.se*(p.se+1)/2;
		//printf("zz %d\n",p.se);
	}
	printf("%lld\n",ans);
}


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

int main() {
  int N,K;
  cin>>N>>K;
  vector<int>X(N);
  for(int i=0;i<N;i++){
    cin>>X.at(i);
  }
  int a=0;
  for(int i=0;i<N;i++){
    a=a+min(X.at(i),max(K-X.at(i),X.at(i)-K));
  }
  cout<<a*2<< endl;
  
}


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

using namespace std;
typedef long long ll;
typedef long double ld;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define pcnt __builtin_popcount
#define pcntll(x) __builtin_popcountll(x)
#define DMAX DBL_MAX;
#define IMIN INT_MIN;
#define IMAX INT_MAX;

//const ll MOD = 1e9+7;
//const ll MOD = 998244353;
//const ll MAX = 3e5+1;
const ll INF = (ll) 4e18;
//const ld PI = acos(-1L);
//
ll a, b, c, d;
unordered_map<ll, ll> cache;

ll calc(ll x) {
    if (cache.find(x) != cache.end()) return cache[x];
    ll ans = INF;
    if ((ld) x * (ld) d < INF) ans = x * d;

    if (x % 2 == 0) {
        ll ca = calc(x / 2) + a;
        ans = min(ans, ca);
    }
    else {
        ll ca = calc(x / 2 + 1) + a + d;
        ans = min(ans, ca);
    }

    if (x % 3 == 0) {
        ll ca = calc(x / 3) + b;
        ans = min(ans, ca);
    }
    else {
        ll D = x % 3;
        ll U = 3 - D;
        ll ca = min(
                calc(x / 3) + b + D*d,
                calc(x / 3 + 1) + b + U*d
                );
        ans = min(ans, ca);
    }

    if (x % 5 == 0) {
        ll ca = calc(x / 5) + c;
        ans = min(ans, ca);
    }
    else {
        ll D = x % 5;
        ll U = 5 - D;
        ll ca = min(
                calc(x / 5) + c + D*d,
                calc(x / 5 + 1) + c + U*d
                );
        ans = min(ans, ca);
    }

    //out(x << ' ' << ans);
    return cache[x] = ans;
}

signed main(){
    //cin.tie(nullptr);
    //ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);

    ll T;
    cin >> T;
    while(T--) {
        ll N;
        cin >> N >> a >> b >> c >> d;
        cache.clear();
        cache[0] = 0;
        cache[1] = d;
        ll ans = calc(N);
        out(ans);
    }

    return 0;
}


Measured memory_bytes: 4184
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MOD 1000000007LL
#define MAX 10000
#define NIL -1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
typedef pair<double, double> doup;


int main(void) {
    ll N;
    cin >> N;
    ll i, j;
    ll s, t;
    for(i=1; i<=3500; i++) {
        for(j=1; j<=3500; j++) {
            s=N*i*j;
            t=4*i*j-N*(i+j);
            if(t>0 && s%t==0) {
                cout << (N*i*j)/(4*i*j-N*(i+j)) << " " << i << " " << j << endl;
                return 0;
            }
        }
    }
    
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b;
 while(1){
     scanf("%d%d",&a,&b);
     if(a==0&&b==0)
     break;
     
     if(a>b)
     printf("%d %d\n",b,a);
     else
     printf("%d %d\n",a,b);
     
 }
return 0;
}

Measured memory_bytes: 2572
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()

	var ans int64
	if n+m <= 3 {
		ans = 1
	} else if n == 1 || m == 1 {
		ans = int64(max(n, m) - 2)
	} else {
		ans = (int64(n - 2)) * (int64(m - 2))
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();
		int m = H-h;
		int n = W-w;
		System.out.println(m*n);
	}
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll l, r; cin >> l >> r;
  if(r-l+1 >= 2019) cout << 0 << endk;
  else {
    ll ans = 2020;
    REP(i, l, r+1) REP(j, i+1, r+1) {
      chmin(ans, 1LL*i*j%2019);
    }
    cout << ans << endk;
  }
  return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    unordered_set<int> all;
    for(int k = 1; k * k <= n; k++) {
        if((n - 1) % k == 0) {
            all.insert(k);
            all.insert((n - 1) / k);
        }
    }
    for(int k = 2; k * k <= n; k++) {
        int km = k, kmm = k * k;
        while(km < n) {
            if(kmm == n) {
                all.insert(k);
                break;
            }
            if((n - km) % kmm == 0) {
                all.insert(k);
                break;
            }
            km *= k, kmm *= k;
        }
    }
    if(all.find(1) != all.end()) {
        all.erase(all.find(1));
    }
    all.insert(n);
    cout << sz(all) << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
nums = list(map(int, input().split()))
count = -1
flag = 0
while flag == 0:
    for i in range(N):
        if nums[i]%2 == 0:
            nums[i] = nums[i]/2
        else:
            flag = 1
            break
    count = count+1
print(count)

Measured memory_bytes: 3060
S = input()
'''
dp[i]はSのi文字目（1~Sの長さ)までを表せるかどうか
'''
dp = [0] * (len(S) + 1)
dp[0] = 1
check = "NO"

words = ["dream", "dreamer", "erase", "eraser"]

for i in range(len(S)):
    if dp[i] == 0:
        continue
    for w in words:
        if S[i:i+len(w)] == w:
            dp[i+len(w)] = 1
    if dp[len(S)] == 1:
        check = "YES"
        break

print(check)


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

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

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

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

template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

int main() {
  int N,f;
  ll p;
  cin >> N;
  vector<vector<int>> F(N),P(N);
  rep(i,N)rep(j,10){
    cin >> f;
    F[i].push_back(f);
  }
  rep(i,N)rep(j,11){
    cin >> p;
    P[i].push_back(p);
  }

  ll ans = LONG_LONG_MIN,tans;
  for (int i=1;i<(1<<10);i++) {
    vector<int> memo(N,0);
    rep(j,10) if (i>>j&1) {
      rep(k,N) if (F[k][j]) memo[k]++;
    } 
    tans=0;
    rep(j,N){
      tans += P[j][memo[j]];
    }
    
    chmax(ans,tans);
  }
  cout << ans << endl;  
}

Measured memory_bytes: 256
N = int(input())
A_list = list(map(int, input().split()))

height_list = [0] * N

for i in range(1, N):
    if height_list[i - 1] + A_list[i - 1] > A_list[i]:
        height_list[i] = height_list[i - 1] + A_list[i - 1] - A_list[i]

print(sum(height_list))

Measured memory_bytes: 32024
#include <stdio.h>
int main()
{
    int W,H,i,j,k;
    while(1){
    scanf("%d %d",&W,&H);
    k=1;
    if(W==0 && H==0)
    {
        return 0;
    }
    else
    {
    for(i=1; i<=W; i++)
    {
        for(j=1; j<=H; j++)
        {
            if(k == 1)
            {
                printf("#");
            }
            else
            {
                printf(".");
            }
            k *= -1;
        }

        if(H % 2 == 0)
        {
            k *= -1;
        }

        printf("\n");
    }
    printf("\n");
    }
    }
    return 0;
}




Measured memory_bytes: 2100
N,M = map(int,input().split(" "))

L =[0 for i in range(N)]

for i in range(M):
  a,b = map(int,input().split(" "))
  L[a-1] +=1
  L[b-1] +=1

for i in range(N):
  print(L[i])
  

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

int main() {
	int i,j,N;
	int count=0;
	
	cin>>N;
	if(N==2){
		cout<<2<<endl;
	}
	
else{
       for(j=N;j<100100;j++){
       	count=0;
			for(i=2;i<j;i++){
				if (j%i==0){
					count=count+1;
					break;
				}
			}
			if(count==0){
				break;
			}
			
			
                }
                cout<<j<<endl;
}

	

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    long double a;
    long double b;
    
    cin >> a >> b;
    
    long long k = (long long) b;
    long double l = (long double) b - (long double) k;
    
    long long ansa = k*a;
    long double ld = l*100;
    long double ansb = ld*a;
    long double ansbb = ansb/100;
    cout << (long long)(ansa + ansbb) << endl;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    string s;
    cin>>s;
    ll ans = 0;
    rep(i, 4){
        if(s[i]=='2')ans++;
    }
    print(ans);
}

Measured memory_bytes: 256
# 整数の入力
N = int(input())
# スペース区切りの整数の入力 -> list
A = list(map(int, input().split()))

ret = 0
while all([a % 2 == 0 for a in A]):
  ret += 1
  A = list(map(lambda x: x / 2, A))

print(ret)

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

int main()
{
	int n,x;
	cin>>n;
	for(int i=1; i<=n; i++)
	{
		cin>>x;
		if(x%2==0)
		{
			if(x%3!=0 && x%5!=0)
			{
				cout<<"DENIED";
				return 0;
			}
		}
	}
	cout<<"APPROVED";
	return 0;
}

Measured memory_bytes: 256
from math import sqrt
inpl = lambda: list(map(int,input().split()))
N, D = inpl()
X = [ inpl() for _ in range(N) ]
ans = 0
for i in range(N):
    for j in range(i+1,N):
        dist = sqrt(sum( (X[i][d]-X[j][d])**2 for d in range(D)))
        if dist == int(dist):
            ans += 1
print(ans)

Measured memory_bytes: 3064
#!/usr/bin/env python3
import itertools

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

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])

ans = sum([c[a][1] for a in itertools.chain.from_iterable(A) if a >= 0])
print(ans)


Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5, mod = 1e9 + 7;
int tr[8][2], f[maxn + 10][8], n;
char s[maxn + 10];
int main() {
	tr[0][0] = 1; tr[0][1] = 2;
	tr[1][0] = 3; tr[1][1] = 4;
	tr[2][0] = 5; tr[2][1] = 6;
	tr[3][0] = 1; tr[3][1] = 1;
	tr[4][0] = 1; tr[4][1] = 2;
	tr[5][0] = 7; tr[5][1] = 2;
	tr[6][0] = 6; tr[6][1] = 6;
	tr[7][0] = 5; tr[7][1] = 5;
	scanf("%s", s + 1);
	n = strlen(s + 1); f[0][0] = 1;
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j < 8; ++j)
			for (int k = 0; k < 2; ++k)
				if (s[i] == '?' || (k + '0' == s[i]))
					(f[i][tr[j][k]] += f[i - 1][j]) %= mod;
	printf("%d", (f[n][2] + f[n][6]) % mod);
}


Measured memory_bytes: 9856
#include<bits/stdc++.h>
using namespace std;
const int t=1e7;
long long a[t],b[t];
int n;
long long sum,spfa;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) 
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++) 
    {
        cin>>b[i];
    }
    for(int i=1;i<=n;i++) 
    {
        if(a[i]>b[i]) 
        {
            sum+=(a[i]-b[i]);
        }
        if(a[i]<b[i]) 
        {
            spfa+=(b[i]-a[i])/2;
        }
    }
    if(sum<=spfa) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
int main()
{
    string S;
    cin >> S;
    
    int N = S.size();
    int ans = 0;
    for (int i = 1; i < N;i++)
    {
        if(S[i-1] == S[i]){
            ans++;
            if(S[i-1] == '0'){
                S[i] = '1';
            }
            else{
                S[i] = '0';
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

long sumT=0;

int main(){
  int N,T;
  cin>>N>>T;
  if(N==1){
    cout<<T<<endl;
    return 0;
  }
  int pre=0;
  //int last_press=0;
  cin>>pre;
  for(int i=1;i<N;i++){
    int cur;
    cin>>cur;
    int sub=cur-pre;
    if(sub>=T)
      sumT+=T;
    else
      sumT+=cur-pre;
    pre=cur;
  }
  sumT+=T;
  cout<<sumT<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,k;
int dp[100001];
int solve(int arr[],int idx)
{
    if(idx>=n) return INT_MAX;
    if(idx==n-1) return 0;
    if(dp[idx]!= -1) return dp[idx];
    int mi=INT_MAX;
    for(int i=1;i<=k;i++)
    {
        int left=INT_MAX;
        if(idx+i <= n-1)
        {
            left=abs(arr[idx+i]-arr[idx])+solve(arr,idx+i);
        }
        mi=min(mi,left);
    }
    return dp[idx]=mi;
    
}

int main() {
    memset(dp,-1,sizeof(dp));
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++)
	{
	    cin>>arr[i];
	}
	cout<<solve(arr,0)<<endl;
}


Measured memory_bytes: 8832
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e14;
const int ZERO = 0;
const int MOD = 1000000007;
const double PI = 3.1415926535897;

struct edge{
	int to,cost;
};
typedef pair<int,int> P; //firstは最短距離、secondは頂点の番号

int V; //頂点数
vector<edge> G[100010];
int d[100010]; //頂点sからの最短距離

void dijkstra(int s) {
	//greater<P>を指定することでfirstが小さい順に取り出せる
	priority_queue<P,vector<P>,greater<P>> que;
	fill(d,d + V,INF);
	d[s] = 0;
	que.push(P(0,s));

	while(!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) {
			continue;
		}
		for(int i = 0;i < G[v].size();i++) {
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

signed main() {
    int u, v;
    cin >> V >> u >> v;
    u--;
    v--;
    for(int i = 0;i < V - 1;i++) {
        int A,B;
        cin >> A >> B;
        A--;
        B--;
        G[A].push_back(edge{B,1});
        G[B].push_back(edge{A,1});
    }
    dijkstra(u);
    vector<int> U(V);
    for(int i = 0;i < V;i++) {
        U.at(i) = d[i];
    }
    dijkstra(v);
    vector<int> vv(V);
    for(int i = 0;i < V;i++) {
        vv.at(i) = d[i];
    }
    int ret = 0;
    for(int i = 0;i < V;i++) {
        if(vv.at(i) > U.at(i)) {
            if(vv.at(i) + U.at(i) == vv.at(u)) {
                ret = max(ret,vv.at(u) / 2);
            }
            ret = max(ret,vv.at(i) - 1);
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 11080
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	line := nextLine()
	input := strings.Split(line, " ")
	n, _ := strconv.Atoi(input[0])
	m, _ := strconv.Atoi(input[1])
	x, _ := strconv.Atoi(input[2])

	line = nextLine()
	a := make(map[int]int, m)
	for _, s := range strings.Split(line, " ") {
		t, _ := strconv.Atoi(s)
		a[t] = 1
	}

	cost1 := 0
	for i := x + 1; i <= n; i++ {
		c, ok := a[i]
		if ok {
			cost1 += c
		}
	}

	cost2 := 0
	for i := x - 1; i >= 0; i-- {
		c, ok := a[i]
		if ok {
			cost2 += c
		}
	}
	if cost1 <= cost2 {
		fmt.Println(cost1)
	} else {
		fmt.Println(cost2)
	}
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <unordered_set>
#include <cctype>
#include <cassert>


using namespace std;

typedef long long ll;
typedef long double ld;

const int nax = 3005;

ld dp[nax];
ld new_dp[nax];

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("angle2.in", "r", stdin);
	//freopen("angle2.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;

	dp[0] = 1.0;
	for (int i = 0; i < n; i++) {
		ld p;
		cin >> p;

		fill(begin(new_dp), end(new_dp), 0.0);

		for (int j = 0; j <= n; j++) {
			new_dp[j + 1] += dp[j] * p;
			new_dp[j] += dp[j] * (1.0 - p);
		}

		memcpy(dp, new_dp, sizeof(new_dp));
	}

	cout << setprecision(10) << fixed << accumulate(begin(dp) + (n + 1) / 2, end(dp), 0.0);
	return 0;
}

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

int main() {
  int N; cin >> N;
  vector<int> v(N);
  rep(i,N) cin >> v[i];
  sort(v.begin(), v.end());
  double ans = v[0];
  repi(i,1,N) ans = (ans + v[i])/2;
  printf("%.10f\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char x[3001],y[3001];
int b[3001][3001];
int c[3001][3001];
void lcs(int m,int n)
{
    int i;
    int j;
    for(i=1; i<=m; i++)
        c[i][0]=0;
    for(i=1; i<=n; i++)
        c[0][i]=0;
    c[0][0]=0;
    for(i=1; i<=m; i++)
        for(j=1; j<=n; j++)
        {
            if(x[i-1]==y[j-1])
            {
                c[i][j]=c[i-1][j-1]+1;
                b[i][j]=1;
            }
            else if(c[i-1][j]>c[i][j-1])
            {
                c[i][j]=c[i-1][j];
                b[i][j]=2;
            }
            else
            {
                c[i][j]=c[i][j-1];
                b[i][j]=3;
            }
        }
}
 
void show(int i,int j,char*x)
{
    if(i==0||j==0)
        return;
    if(b[i][j]==1)
    {
        show(i-1,j-1,x);
        printf("%c",x[i-1]);
    }
    else if(b[i][j]==2)
        show(i-1,j,x);
    else
        show(i,j-1,x);
}
int main()
{ 
	scanf("%s",x);
	scanf("%s",y);
    int m=strlen(x);
    int n=strlen(y);
    lcs(m,n);
    show(m,n,x);
}

Measured memory_bytes: 70656
#include<stdio.h>

int main() {
   int x, y, i, r;

   scanf("%d%d", &x, &y);

   if (x>=y) {
      while (y!=0) {
         r=y;
         y=x%y;
         x=r;
      }
      printf("%d\n",x);
     
   } else {
      while (x!=0) {
         r=x;
         x=y%x;
         y=r;
         
      }
      printf("%d\n",y);
    }
  
   return 0;
   
}

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

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
	int n;
	cin >> n;
	vector<int> s(n), l(n), p(n);
	rep(i, n) cin >> s[i] >> l[i] >> p[i];
	int m; cin >> m;
	vector<int> w(m);
	rep(i, m) cin >> w[i];

	int dp[400];
	fill(dp, dp+400, -1);
	dp[0] = 0;

	rep(i, 400){
		rep(j, n){
			for(int k = s[j]; k <= l[j]; k++){
				if(i-k >= 0) dp[i] = max(dp[i], dp[i-k]+p[j]);
			}
		}
	}
	vector<int> ret(m);
	rep(i, m){
		if(dp[w[i]] == -1){cout << -1 << endl; return 0;}
		ret[i] = dp[w[i]];
	}
	rep(i, m) cout << ret[i] << endl;
}

Measured memory_bytes: 1204
#include <iostream>
using namespace std;
int main(){
    int a,b,sum=0,count;
    while(cin>>a>>b){
        count++;
        sum=a+b;
        if(sum<10)cout<<"1"<<endl;
        else if(sum<100)cout<<"2"<<endl;
        else if(sum<1000)cout<<"3"<<endl;
        else if(sum<10000)cout<<"4"<<endl;
        else if(sum<100000)cout<<"5"<<endl;
        else if(sum<1000000)cout<<"6"<<endl;
        else if(sum<10000000)cout<<"7"<<endl;
        else if(sum<100000000)cout<<"8"<<endl;
        
        if(count==200)break;
        
    }
    return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <string>

int main() {
  std::string s1;
  std::string s2;
  std::cin >> s1 >> s2;
  
  std::sort(s1.begin(), s1.end()); // ascending order
  std::sort(s2.begin(), s2.end(), std::greater<char>()); // descending order
 
  int l1 = s1.length();
  int l2 = s2.length();
  
  for (int i = 0; i < (l1 < l2 ? l1 : l2); i++) {
    if (s1[i] < s2[i]) {
      std::cout << "Yes" << '\n';
      return 0;
    } else if (s1[i] == s2[i]) {
      continue;
    } else {
      std::cout << "No" << '\n';
      return 0;
    }
  }
  if (l1 >= l2) std::cout << "No" << '\n';
  else std::cout << "Yes" << '\n';
  
  return 0;
}


Measured memory_bytes: 256
N, x = map(int, input().split())

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

ans = 0

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

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

int di[4] = {1, 0, -1, 0};
int dj[4] = {0, 1, 0, -1};

void dfs(int &black, int &white, vector<vector<int> > &G, int i, int j){
    int now_color = G[i][j];
    if(G[i][j] == 1) black++;
    else white++;
    G[i][j] = 0;

    for(int h = 0; h < 4; h++){
        int ni = i + di[h];
        int nj = j + dj[h];
        if(G[ni][nj] == 0) continue;
        if(G[ni][nj] != now_color) dfs(black, white, G, ni, nj);
    }

}

signed main(){

    int h, w; cin >> h >> w;
    vector<vector<int> >  G(h + 2, vector<int> (w + 2, 0));
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            char input; cin >> input;
            if(input == '.') G[i][j] = 1;
            else G[i][j] = 2;
        }
    }

    int ans = 0;

    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(G[i][j] == 1){
                int black = 0;
                int white = 0;
                dfs(black, white, G, i, j);
                ans += black * white;
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13952
while True:
    N = int(input())
    if N == 0:
        break
    
    first_group_menbers = set(input()[:-1].split(":")[1].split(","))
    
    d = {}
    for i in range(N-1):
        group, members = input()[:-1].split(":")
        d[group] = set(members.split(","))
        
    for i in range(N):
        for group, members in d.items():
            if group in first_group_menbers:
                first_group_menbers.remove(group)
                for m in members:
                    first_group_menbers.add(m)
    
    print(len(first_group_menbers))

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

class Dice {
 public:
  vector<int> numbers;
  explicit Dice(vector<int> nums) : numbers{nums} {};
  auto roll(int i, int j, int k, int l) {
    auto tmp = numbers.at(i);
    numbers.at(i) = numbers.at(j);
    numbers.at(j) = numbers.at(k);
    numbers.at(k) = numbers.at(l);
    numbers.at(l) = tmp;
  };

  auto roll_S() { roll(0, 4, 5, 1); };
  auto roll_E() { roll(0, 3, 5, 2); };
  auto roll_C() { roll(1, 3, 4, 2); };  // clock wise
};
int main() {
  vector<int> d1n(6), d2n(6);

  for (size_t i = 0; i < 6; i++) {
    cin >> d1n.at(i);
  }

  for (size_t i = 0; i < 6; i++) {
    cin >> d2n.at(i);
  }

  Dice d1{d1n};

  int cnt = 0;

  for (size_t i = 0; i < 6; i++) {
    for (size_t j = 0; j < 4; j++) {
      if (d1.numbers == d2n) {
        cout << "Yes" << endl;
        return 0;
      }
      d1.roll_C();
    }

    if (cnt % 2 == 0) {
      d1.roll_S();
    } else {
      d1.roll_E();
    }
    cnt += 1;
  }

  cout << "No" << endl;

  return 0;
}



Measured memory_bytes: 3160
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <numeric>
#include <bitset>
#include <stack>
#include <cstring>
using namespace std;

const int INF = 1 << 30;
const double EPS = 1e-10;

int main()
{
  int n, m;
  while (cin >> n >> m) {
    vector<int> x(n), y(n);
    set<int> sx, sy;
    for (int i = 0; i < n; ++i) {
      cin >> x[i] >> y[i];
      sx.insert(x[i]);
      sy.insert(y[i]);
    }

    vector<int> ix(1, -INF), iy(1, -INF);
    for (set<int>::iterator it = sx.begin(); it != sx.end(); ++it)
      ix.push_back(*it);
    for (set<int>::iterator it = sy.begin(); it != sy.end(); ++it)
      iy.push_back(*it);

    vector<vector<int> > dp(iy.size(), vector<int>(ix.size(), 0));
    for (int i = 0; i < n; ++i)
      ++dp[lower_bound(iy.begin(), iy.end(), y[i])-iy.begin()][lower_bound(ix.begin(), ix.end(), x[i])-ix.begin()];

    for (unsigned int i = 0; i < dp.size(); ++i) {
      for (unsigned int j = 1; j < dp[i].size(); ++j)
        dp[i][j] += dp[i][j-1];
    }

    for (unsigned int i = 0; i < dp[0].size(); ++i) {
      for (unsigned int j = 1; j < dp.size(); ++j)
        dp[j][i] += dp[j-1][i];
    }

    while (m--) {
      int x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;

      int ix1 = upper_bound(ix.begin(), ix.end(), x2)-1-ix.begin();
      int iy1 = upper_bound(iy.begin(), iy.end(), y2)-1-iy.begin();

      int ix2 = upper_bound(ix.begin(), ix.end(), x1-1)-1-ix.begin();
      int iy2 = upper_bound(iy.begin(), iy.end(), y1-1)-1-iy.begin();

      int ix3 = upper_bound(ix.begin(), ix.end(), x1-1)-1-ix.begin();
      int iy3 = upper_bound(iy.begin(), iy.end(), y2)-1-iy.begin();

      int ix4 = upper_bound(ix.begin(), ix.end(), x2)-1-ix.begin();
      int iy4 = upper_bound(iy.begin(), iy.end(), y1-1)-1-iy.begin();

      cout << dp[max(0, iy1)][max(0, ix1)] + dp[max(0, iy2)][max(0, ix2)] - dp[max(0, iy3)][max(0, ix3)] - dp[max(0, iy4)][max(0, ix4)] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 99476
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int mod=1e9+7;
const int maxn=410;
int n,c;
LL p1[maxn][maxn],p2[maxn][maxn],dp[maxn][maxn];
LL a[maxn],b[maxn];

void _init() {
    for (int i=1;i<=400;i++) {
        p1[i][0]=p2[i][0]=1;
        for (int j=1;j<=400;j++)
            p1[i][j]=(p1[i][j-1]*i)%mod;
    }
    for (int i=1;i<=400;i++)
        for (int j=0;j<=400;j++)
            p2[i][j]=(p2[i-1][j]+p1[i][j])%mod;
}

int main() {
    _init();
    while (scanf("%d%d",&n,&c)!=EOF) {
        for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
        for (int i=1;i<=n;i++) scanf("%lld",&b[i]);
        dp[0][0]=1;
        for (int i=1;i<=n;i++)
            for (int j=0;j<=c;j++)
                for (int k=0;k<=j;k++) {
                    LL t=(p2[b[i]][k]-p2[a[i]-1][k]+mod)%mod;
                    dp[i][j]=(dp[i][j]+dp[i-1][j-k]*t)%mod;
                }

        printf("%lld\n", dp[n][c]);
    }
    return 0;
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
#define int long long
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
#define loop(n) for(int i=0;i<n;i++)
#define double long double
#define mod 998244353
#define F first
#define S second
#define pb push_back

using namespace std;

signed main()
{
	fast;
	int test=1;
	// cin>>test;
	for(int index=0;index<test;index++)
	{
        int n;
        cin>>n;
        vector<string> v(n);
        set<string> s;
        int ans=0;
        loop(n)
        {
            cin>>v[i];
            if(s.find(v[i])==s.end()) 
            {
                ans++;
                s.insert(v[i]);
            }

        }
        
        cout<<ans<<endl;

        
        
        
    }
}

Measured memory_bytes: 25048
N, M = map(int, input().split())
drink = []
for _ in range(N):
    drink.append(list(map(int, input().split())))
drink = sorted(drink)
money = 0
honsuu = 0
for i in range(N):
    if honsuu + drink[i][1] <= M:
        money += drink[i][0] * drink[i][1]
        honsuu += drink[i][1]
    else:
        money += drink[i][0] * (M-honsuu)
        break
print(money)


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    cout << 2 * N / __gcd(2LL, N) << endl;
    return 0;
}


Measured memory_bytes: 3584
N = int(input())
A = {}
for i in range(N):
  s = str(input())
  if s in A:
    A[s] += 1
  else:
    A[s] = 1

max_val = max(A.values())
keys = [key for key in A if A[key] == max_val]
keys.sort()
for s in keys:
  print(s)

Measured memory_bytes: 32096
#include <iostream>
#define MIN(a,b) ((a>b)?(b):(a))

using namespace std;

int main(void){
	int a=0,b=0;
	int n;
	while(cin>>n,n){
		a=b=0;
		for(int i=2;i<=n;i++){
			int j=i;
			while(j%2==0){
				a++;
				j/=2;
			}
			while(j%5==0){
				b++;
				j/=5;
			}
		}
		cout<<MIN(a,b)<<endl;
	}
	return 0;
}

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

int main(){

    int a,b,k;

    cin >> a >> b >> k;

    int cnt=0;

    for(int i=100;i>=1;i--){
        if(a%i==0&&b%i==0){
            cnt++;
        }
        if(cnt==k){
            cout << i << endl;
            return 0;;
        }
    }

    return 0;
}

Measured memory_bytes: 256
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):
        # assert i > 0
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)

n = int(input())
s = list(input())
q = int(input())
ord_a = ord("a")
queries = [tuple(input().split()) for i in range(q)]
bits = [BIT(n) for i in range(26)]
for k,v in enumerate(s,1):
  bits[ord(v)-ord_a].add(k,1)
for query,i,c in queries:
  if query == "1":
    i = int(i)
    prev = s[i-1]
    if prev != c:
      bits[ord(prev)-ord_a].add(i,-1)
      bits[ord(c)-ord_a].add(i,1)
      s[i-1] = c
  elif query == "2":
    l,r = int(i),int(c)
    res = 0
    for bit in bits:
      if bit.get(r,l-1):
        res += 1
    print(res)

Measured memory_bytes: 275228