akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,c,d[30][30],a[500][500],cnt[3][30] = {},mi = INF;
	cin >> n >> c;
	for(int i = 0;i < c;i++){
		for(int j = 0;j < c;j++) cin >> d[i][j];
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			cin >> a[i][j]; a[i][j]--;
			cnt[(i + j) % 3][a[i][j]]++;
		}
	}
	for(int i = 0;i < c;i++){
		for(int j = 0;j < c;j++){
			for(int k = 0;k < c;k++){
				if(i != j && j != k && k != i){
					int sum = 0;
					for(int l = 0;l < c;l++) if(l != i) sum += cnt[0][l] * d[l][i];
					for(int l = 0;l < c;l++) if(l != j) sum += cnt[1][l] * d[l][j];
					for(int l = 0;l < c;l++) if(l != k) sum += cnt[2][l] * d[l][k];
					chmin(mi,sum);
				}
			}
		}
	}
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 2176
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
//istringstream iss(sentence);
long long mod = 998244353;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
  
const int biggg = 2000000000;
const long long bigggest = 1000000000000000000LL;
const double eps = .0000000001;

double torad(double deg){
    return pi*deg/180;
}
double dist(double a, double b, double c, double d){
    return sqrt(pow(a-c, 2)+pow(b-d, 2));
}
int main(){
    prep();
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double hourpercent = 360.0*(h*60+m)/720.0;
    double minpercent = 360.0*m/60.0;
    //cout << hourpercent << endl;
    double hx = cos(torad(hourpercent))*a;
    double hy = sin(torad(hourpercent))*a;
    double mx = cos(torad(minpercent))*b;
    double my = sin(torad(minpercent))*b;
    printf("%.12lf\n", dist(hx, hy, mx, my));
}

Measured memory_bytes: 4080
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  vector<int> N(4);
  int tmp[] = {1, 4, 7, 9};
  for(int i=0; i<4; i++) {
    cin >> N[i];
  }
  sort(N.begin(), N.end());
  bool ret = true;
  for(int i=0; i<4; i++) {
    if(N[i] != tmp[i])
      ret = false;
  }
  if(ret)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 10000
void linearSearch(int);
int count,n,A[N];
int main(){
  int i,j,q,r;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  count = 0;
  for(i=0;i<q;i++){
    scanf("%d",&r);
    linearSearch(r);
  }
  printf("%d\n",count);
  return 0;
}
void linearSearch(int r){
  int i;
  for(i=0;i<n;i++){
    if( A[i] == r ){
      count++;
      return;
    }
  }
}

Measured memory_bytes: 636
N, M = map(int, input().split())
MOD = 10**9+7
broken = [int(input()) for _ in range(M)]
l = ["empty"]*(N+1)
l[0], l[1] = 1, 1
for i in broken:
    l[i] = 0

for i in range(N+1):
    if l[i] == "empty":
        l[i] = (l[i-1] + l[i-2]) % MOD

print(l[N])

Measured memory_bytes: 7848
// Problem : A - Security
// Contest : AtCoder Beginner Contest 131
// URL : https://atcoder.jp/contests/abc131/tasks/abc131_a
// Memory Limit : 1024,000000 MB 
// Time Limit : 2000,000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <cmath>
#include <cstdio>

#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <map>
#include <set>
#include <vector>

using namespace std;

void preambule() {
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
}

string s;

void input() {
  cin >> s;
}

void solve1() {
  for (int i = 0; i < (int)s.size(); ++i) {
    if (isdigit(s[i]) && s[i] == s[i + 1]) {
      cout << "Bad";
      
      exit(0);
    }
  }
  
  cout << "Good";
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  preambule();
  input();
  solve1();
}


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


if K == 1:
  s = S[0].lower() + S[1:]
elif K == N:
  s = S[:-1] + S[-1].lower()
else:
  s = S[:K-1] + S[K-1].lower() + S[K:]

print(s)



Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
int main() {
    int n,m;cin>>n>>m;
    vector<P> ab(m);
    rep(i,m){
        cin>>ab.at(i).first;
        cin>>ab.at(i).second;
    }
    vector<int> count(n);
    rep(i,n) count[i]=0;
    rep(i,m){
        count[ab.at(i).first-1]++;
        count[ab.at(i).second-1]++;
    }
    rep(i,n){
        cout<<count.at(i)<<endl;
    }

}

Measured memory_bytes: 256
r, D, x = map(int, input().split())
x_list = []
x_list.append(x)
temp_x = 0
for i in range(1, 11):
    temp_x = x_list[i-1]*r - D
    x_list.append(temp_x)
x_list.pop(0)
for j in x_list:
    print(j)


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

	int H, W;
	cin >> H >> W;

	while (H != 0){

		int j, k;
		for (j = 0; j < H; j++){
			for (k = 0; k < W; k++){

				if (j == 0 || j == H - 1 || k == 0 || k == W - 1)
					cout << "#";
				else cout << ".";

			}
			cout << endl;
		}
		cout << endl;
		cin >> H >> W;
	}
	return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define t int t; cin>>t; while(t--)
    #define clear(a,x) memset(a,x,sizeof(a))
    #define boost ios_base::sync_with_stdio(false)
    #define show(a) for(int bm=0;bm<a.size();bm++)cout<<a[bm]<<" ";
    #define sc1(x) scanf("%d",&x)
    #define sc2(x,y) scanf("%d%d",&x,&y)
    #define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
    #define sc4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
    #define sc5(a,b,c,d,e) scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)
    #define pr1(x) printf("%d\n",x)
    #define pr2(x,y) printf("%d %d\n",x,y)
    #define pr3(x,y,z) printf("%d %d %d\n",x,y,z)
    #define pr4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
    #define pr5(a,b,c,d,e) printf("%d %d %d %d %d\n",a,b,c,d,e)
    #define scl(x) scanf("%lld",&x)
    #define prl(x) printf("%lld\n",x)
    #define u(i,a,b) for(i=a;i<b;i++)
    #define d(i,a,b) for(i=a;i>b;i--)
    #define all(x) x.begin(),x.end() 
    #define pb(x) push_back(x)
    #define eb(x) emplace_back(x)
    #define mp(x,y) make_pair(x,y) 
    #define ff first
    #define ss second
    #define mod 1000000007
    int func(int n)
    {
        int c=0;
        while((n%2)==0)
        {
            n/=2;
            c++;
        }
        return c;
    }
    int f[101][101];
    int main()
    {
        int h,w;
        cin>>h>>w;
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];
        int x,y;
        x=y=0;
        int flag;
        flag=0;
        for(int i=0;i<n;i++)
        {
            int p=a[i];
            while(p--)
            {
                f[x][y]=i+1;    
                if(!flag)
                    y++;
                else
                    y--;
                if(y>=w)
                {
                    flag=1;
                    y=w-1;
                    x++;
                }
                if(y<0)
                {
                    flag=0;
                    y=0;
                    x++;
                }
            }
        }
        for(int i=0;i<h;i++)
        {
            for(int j=0;j<w;j++)
                cout<<f[i][j]<<" ";
            cout<<endl;
        }
        return 0;
    }

Measured memory_bytes: 384
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[200007],b[200007];
bool cmp(int x,int y){
    return x>y;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    long long k;
    cin>>n>>k;
    for(int i=1;i<=n;++i)
        cin>>a[i];
    for(int i=1;i<=n;++i)
        cin>>b[i];
    sort(a+1,a+1+n,cmp);
    sort(b+1,b+1+n);
    long long l=0,r=1e12;
    long long ans=-1;
    while(l<=r){
        long long mid=(l+r)>>1;
        long long tamp=0;
        for(int i=1;i<=n&&tamp<=k;++i)
            if(1ll*a[i]*b[i]>mid)
                tamp+=a[i]-mid/b[i];
        if(tamp<=k){
            ans=mid;
            r=mid-1;
        }
        else
            l=mid+1;
    }//打发士大夫
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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 main() {
    ll n,k;
    cin >> n >> k;
    vector<ll>v(n);
    rep(i,n) {
        cin >> v[i];
    }
    
    ll ans = 0;
    for(ll a = 0;a<=n;a++) {
        for(ll b = 0;b<=n;b++) {
            vector<ll>val;
            ll tmp = 0;
            ll cnt = 0;
            if(a+b > n || a+b>k) continue;
            for(ll i = 0;i<a;i++) {
                val.push_back(v[i]);
                cnt++;
            }
            for(ll i = n-1;i>n-1-b;i--) {
                val.push_back(v[i]); 
                cnt++;
            }
            // cout << a << " " << b <<" ";
            cnt = k - cnt;
            // cout << a << " " << b <<" " << cnt << " ";
            sort(val.begin(),val.end());
            ll N = val.size();
            for(ll i = 0;i<N;i++) {
                if(cnt>0 && val[i]<0) {
                    cnt--;
                    continue;
                }
                tmp += val[i];
            }
            ans = max(ans,tmp);
            // cout << endl;
        }
        
    }
    cout << ans << endl;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> a(N);
    REP(i, N)
    {
        cin >> a[i];
    }

    vector<ll> sumA(N + 1), sumMaxA(N + 1);
    sumA[0] = 0;
    sumMaxA[0] = 0;
    REP(i, N)
    {
        sumA[i + 1] = sumA[i] + a[i];
        sumMaxA[i + 1] = sumMaxA[i] + max(0ll, a[i]);
    }

    ll ans = 0;
    REP(i, N - K + 1)
    {
        ll sumNowWhite = 0;
        ll sumNowBlack = 0;
        sumNowWhite += sumMaxA[i];
        sumNowBlack += sumMaxA[i];
        sumNowBlack += sumA[i + K] - sumA[i];
        sumNowWhite += sumMaxA[N] - sumMaxA[i + K];
        sumNowBlack += sumMaxA[N] - sumMaxA[i + K];
        ans = max(ans, sumNowWhite);
        ans = max(ans, sumNowBlack);
    }

    cout << ans << endl;
}


Measured memory_bytes: 5552
#[macro_use]
mod utils {
    macro_rules! input {
        ($($r:tt)*) => {
            let stdin = std::io::stdin();
            let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
            let mut next = move || -> String{
                bytes
                    .by_ref()
                    .map(|r|r.unwrap() as char)
                    .skip_while(|c|c.is_whitespace())
                    .take_while(|c|!c.is_whitespace())
                    .collect()
            };
            input_inner!{next, $($r)*}
        };
    }
    macro_rules! input_inner {
        ($next:expr) => {};
        ($iter:expr, ) => {};
 
        ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
            let $var = read_value!($next, $t);
            input_inner!{$next $($r)*}
        };
        ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
            let mut $var = read_value!($next, $t);
            input_inner!{$next $($r)*}
        };
    }
    macro_rules! read_value {
        ($next:expr, ( $($t:tt),* )) => {
            ( $(read_value!($next, $t)),* )
        };
        ($next:expr, [ $t:tt ; $len:expr ]) => {
            (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        };
        ($next:expr, chars) => {
            read_value!($next, String).chars().collect::<Vec<char>>()
        };
        ($next:expr, usize1) => {
            read_value!($next, usize) - 1
        };
        ($next:expr, $t:ty) => {
            $next().parse::<$t>().expect("Parse error")
        };
    }
}
 

fn main() {
    input!{
        n: u64,
        r: u64,
    }
    nsinsuu(n, r);

}
fn nsinsuu(mut num: u64, k: u64){
    let mut cnt = 0;
    while num != 0{
        cnt += 1;
        num = num / k;
    }
    println!("{}", cnt);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<int,vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;



int main()
{
    int N;
    cin >> N;
    vl A(N);
    in(N,A);
    map<ll,int> B;
    rep(i,N){
        B[A[i]]++;
    }
    ll aa = 0;
    ll bb = 0;
    for(auto p : B){
        if(p.se==1) continue;
        if(p.se>=4){
            aa = max(p.fi,aa);
            bb = max(p.fi,bb);
        }else{
            aa = max(p.fi,aa);
            if(bb < aa) swap(aa,bb);
        }
        
    }
    out(aa*bb);


    return 0;
}


Measured memory_bytes: 7296
import java.io.IOException;
import java.util.Scanner;

class Main {

	public static void main(String[] args) throws IOException {

		Scanner scane = new Scanner(System.in);

		double px1 = scane.nextDouble();

		double py1 = scane.nextDouble();

		double p2x1 = scane.nextDouble();

		double p2y1 = scane.nextDouble();


		System.out.println(Math.hypot((p2x1-px1),(p2y1-py1)));

	}

}

Measured memory_bytes: 27976
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    
    char s;
    cin>>n;
    vector<int> d(4,0);
    
    for(int i=0;i<n;i++)
    {
        cin>>s;
        if(s=='P')
            d[0]++;
        else if(s=='W')
            d[1]++;
        else if(s=='G')
            d[2]++;
        else if(s=='Y')
            d[3]++;
    }
    int sum=0;
    for(int i=0;i<4;i++)
    {
        if(d[i]!=0)
            sum++;
    }
    if(sum==4)
        printf("Four");
    else
        printf("Three");
    return 0;
}

Measured memory_bytes: 256
"""
int(input())
map(int, input().split())
list(map(int, input().split()))
input()
input().split()
"""


n=int(input())

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

ans=0
for i in range(1,n):
    if (a[i-1] > a[i]):
        ans+=a[i-1]-a[i]
        a[i]+= a[i-1]-a[i]

print(ans)

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

int main() {
  string a;
    cin>>a;
  
  for(int i=0;i<3;i++){
  if(a.at(i)=='1'){
    a.at(i)='9';
  }
  else{
    a.at(i)='1';
  }
  }
  
  cout<<a<<endl;
}

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

using namespace std;

int n, y;

int main(){
    cin >> n >> y;
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j <= n - i; ++j){
            int k = n - i - j;
            if(10000*i+5000*j+1000*k == y){
                printf("%d %d %d\n", i, j, k);
                return 0;
            }
        }
    }
    printf("-1 -1 -1\n");
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7
INF = 10 ** 18

N, M, P = map(int, input().split())
G = []
G_append = G.append

g = [[] for _ in range(N + 1)]
for _ in range(M):
    A, B, C = map(int, input().split())
    G_append((A, B, -C + P))
    g[A].append(B)

d = [INF] * (N + 1) #最短距離を記録しておくリスト
d[1] = 0
def find_negative_loop1(): #負の閉路が存在するかを確認
    for i in range(N):
        for j in range(M): #無向グラフのときは辺は実質的には2倍
            e = G[j]
            if d[e[0]] != INF and d[e[1]] > d[e[0]] + e[2]:
                d[e[1]] = d[e[0]] + e[2]
                #頂点の回数と同じだけループを回しても更新が起きる-->負の閉回路が存在
                if i == N-1:
                    return True #Trueの時, 負の閉路が存在
    return False #Falseの時, 負の閉路が存在しない

def find_negative_loop2(): #負の閉路が存在するかを確認
    check = [False] * (N + 1)
    for _ in range(N):
        for j in range(M): #無向グラフのときは辺は実質的には2倍
            e = G[j]
            if d[e[0]] != INF and d[e[1]] > d[e[0]] + e[2]:
                d[e[1]] = d[e[0]] + e[2]
                check[e[1]] = True
            if check[e[0]]:
                check[e[1]] = True
    return check[N]

#呼び出しスタート地点を入れる
if find_negative_loop1():
    if find_negative_loop2():
        print (-1)
    else:
        print (max(0, -d[N]))
else:
    print (max(0, -d[N]))





Measured memory_bytes: 42736
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define fi first
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)

int32_t main() 
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	fastIO;
	ll t,n,i,j,a,b,m,k,q,l,r,x,y;
	// cin>>t;
	// while(t--)
	// {
		cin>>n;
		if(n==0) cout<<"1";
		else cout<<"0";
	// }

	return 0;
}

Measured memory_bytes: 3684
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

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

signed main(void)
{
	int sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;

	string ans;
	REP(i, gy-sy) ans += 'U';
	REP(i, gx-sx) ans += 'R';
	ans += 'U';
	REP(i, gx-sx+1) ans += 'L';
	REP(i, gy-sy+1) ans += 'D';
	ans += 'R';
	//ans += 'a';
	REP(i, gx-sx) ans += 'R';
	REP(i, gy-sy) ans += 'U';
	ans += 'R';
	REP(i, gy-sy+1) ans += 'D';
	REP(i, gx-sx+1) ans += 'L';
	ans += 'U';

	cout << ans << endl;

	return 0;
}


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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 100500;

int n, a[N], b[N];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);

	//cout << setprecision(10) << fixed;
	
	cin >> n;

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

	ll add = 0;

	for (int i = n; i >= 1; i--)
		add += (b[i] - (a[i] + add) % b[i]) % b[i];

	cout << add;
	
	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0ll, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    ll n ,  a, b ;
    cin >> n >> a >> b;
    vl v;
    ll sum = 0 ;
    forn(i , 1 , n ) {
       ll x;
       cin >> x;
       v.pb(x) ;
    }
    forn(i , 1 , n - 1)  {
       ll diff = v[i] - v[i-1] ;
       ll x = diff * a ;
       ll y =  b;
       if(x <= y){
        sum = sum + x;
       }
       else {
        sum = sum + y;
       }
    }
    cout << sum << el ;
  ro ; 
}


Measured memory_bytes: 1400
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
using namespace std;
int main()
{

	//int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	long long a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, ans = 0;
	//cout << LONG_MAX << endl;
	//string s[1001];
	//long long n, A[1000000000];
	//string s;
	cin >> a;
	long long N[1000];

	for ( b = 0; b < a; b++)
	{
		cin >> N[b];
	}
	c = 9999999999;
	for ( b = 0; b < a; b++)
	{
		c = min(c, N[b]);
		d = max(d, N[b]);
	}
	cout << d - c << endl;
	return 0;
}

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

int n;
int a[114514];
int x, y;

int main(){
	scanf("%d", &n);
	for(int i=0; i<n; ++i) scanf("%d", &a[i]);

	for(int i=0; i<n; ++i)
		if(a[i] % 2 == 0){
			if(a[i] % 4 == 0) ++x;
			else ++y;
		}
	int f;
	if(y == 0) f = -1;
	else f = 0;

	if(x >= n-x-y+f) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 512
import java.util.*;
class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int n = scan.nextInt();
      	int q = scan.nextInt();
      	String word = scan.next();
      	int[] nums = new int[2*q];
      	for(int i=0;i<2*q;i++){
        	nums[i] = scan.nextInt();
        }
     	int[] ac = new int[word.length()];
      	ac[0] = 0;
      	for(int i=1;i<word.length();i++){
        	if(word.substring(i-1,i+1).equals("AC")){
            	ac[i] = ac[i-1]+1;
            } else {
            	ac[i] = ac[i-1];
            }
        }
      	int ans = 0;
      	for(int i=0;i<q;i++){
        	ans = -ac[nums[2*i]-1] + ac[nums[2*i+1]-1];
          	System.out.println(ans);
        }
    }
}

Measured memory_bytes: 85920
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            C();
        }

        static void C()
        {
            var S = Read();
            var count = 0;
            if (S[0] == '0')
            {
                for (int i = 0; i < S.Length; i += 2)
                {
                    if (S[i] == '1')
                    {
                        count++;
                    }

                    if ((i+1) < S.Length && S[i + 1] == '0')
                    {
                        count++;
                    }
                }
            }
            else
            {
                for (int i = 0; i < S.Length; i+=2)
                {
                    if (S[i] == '0')
                    {
                        count++;
                    }

                    if ((i + 1) < S.Length && S[i+1] == '1')
                    {
                        count++;
                    }
                }
            }
            Println(count);
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


Measured memory_bytes: 13116
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#define Mod 1000000007
#define INF 1e14
typedef long long int ll;

ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    if(n==1)
        return a;
    else
    {
        ll res=fast(n/2,a,m);
        if(n%2==0)
            return (((res%m)*(res%m))%m);
        else
        {
            return (((((res%m)*a)%m)*res)%m);
        }
    }
}
int main()
{
  ll n,k,q;
  cin>>n>>k>>q;
  ll b[n+1]={0};
  b[0]=k;
  ll r;
  while(q--)
  {
      cin>>r;
      b[0]-=1;
      b[n]+=1;
      b[r-1]+=1;
      b[r]-=1;
  }
  ll c[n],i;
  for(i=0;i<n;i++)
  {
      if(i==0)
        c[i]=b[i];
      else
        c[i]=b[i]+c[i-1];
  }
  for(i=0;i<n;i++)
  {
      if(c[i]<=0)
        cout<<"No\n";
      else
        cout<<"Yes\n";
  }


}


Measured memory_bytes: 2176
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int main(void)
{
  int K;
  cin >> K;
  int even = ceil((double)K / 2);
  int odd = (double)K / 2;

  cout << even * odd << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,m;
    cin >> n >> m;
    map<int,vector<pair<int,int>>> ms;
    VP ns(m);
    int p,y;
    REP(i,0,m) {
        cin >> p >> y;
        ms[p].emplace_back(y,i);
    }
    for (auto &m: ms) {
        sort(all(m.second));
        for (auto it = m.second.begin(); it != m.second.end(); ++it) {
            ns[it->second] = make_pair(m.first, it - m.second.begin() + 1);
        }
    }
    REP(i,0,m) {
        printf("%06d%06d\n", ns[i].first, ns[i].second);
    }
}

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

Measured memory_bytes: 13184
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    long total = 0;
    for (int i = 0; i < (1 << S.length() - 1); i++) {
      StringBuilder A = new StringBuilder();
      A.append(S.charAt(0));
      for (int j = 0; j < S.length() - 1; j++) {
        if ((1 & (i >> j)) == 1) {
          A.append("+");
        }
        A.append(S.charAt(j + 1));
      }
      String[] ss = A.toString().split("\\+");
      for (String s : ss) {
        total += Long.parseLong(s);
      }
    }
    System.out.println(total);
  }
}


Measured memory_bytes: 23892
from fractions import gcd
n,m=map(int,input().split())
s=input()
t=input()
if gcd(n,m)==1:
  if s[0]==t[0]:
    print(n*m)
  else:
    print(-1)
else:
  k=n//gcd(n,m)
  l=m//gcd(n,m)
  for i in range(gcd(n,m)):
    if s[i*k]!=t[i*l]:
      print(-1)
      exit()
  print(k*l*gcd(n,m))

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

using namespace std;

typedef long long ll;


class RollingHash {
    static const ll base1 = 1009;
    static const ll base2 = 2009;
    static const ll mod1 = 1000000007;
    static const ll mod2 = 1000000009;
    vector<ll> hash1, hash2, pow1, pow2;

public:
    RollingHash(const string &S) {
        int n = (int) S.size();
        hash1.assign(n + 1, 0);
        hash2.assign(n + 1, 0);
        pow1.assign(n + 1, 1);
        pow2.assign(n + 1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i + 1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i + 1] = (hash2[i] * base2 + S[i]) % mod2;
            pow1[i + 1] = (pow1[i] * base1) % mod1;
            pow2[i + 1] = (pow2[i] * base2) % mod2;
        }
    }

    /**
     * S の [l, r) のハッシュ値を返す
     * O(1)
     */
    inline pair<ll, ll> get(int l, int r) const {
        ll res1 = hash1[r] - hash1[l] * pow1[r - l] % mod1;
        if (res1 < 0) res1 += mod1;
        ll res2 = hash2[r] - hash2[l] * pow2[r - l] % mod2;
        if (res2 < 0) res2 += mod2;
        return make_pair(res1, res2);
    }

    /**
     * S のハッシュ値を返す
     * O(1)
     */
    inline pair<ll, ll> hash() const {
        return get(0, (int) hash1.size() - 1);
    }

    /**
     * LCP (Longest Common Prefix)
     * O( log N )
     */
    inline int getLCP(int a, int b) const {
        int len = min((int) hash1.size() - a, (int) hash1.size() - b);
        int low = 0, high = len;
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (get(a, a + mid) != get(b, b + mid)) high = mid;
            else low = mid;
        }
        return low;
    }

    /**
     * hash h1 と 長さ h2_len の文字列の hash h2 を結合
     */
    pair<ll, ll> concat(pair<ll, ll> h1, pair<ll, ll> h2, int h2_len) {
        return make_pair((h1.first * pow1[h2_len] + h2.first) % mod1, (h1.second * pow2[h2_len] + h2.second) % mod2);
    }
};

int main() {
    string T, P;
    cin >> T >> P;
    RollingHash rollingHash(T), rollingHash2(P);
    for (int i = 0; i < T.size(); ++i) {
        if (i + P.size() <= T.size() && rollingHash.get(i, i + P.size()) == rollingHash2.hash()) {
            cout << i << '\n';
        }
    }
    return 0;
}



Measured memory_bytes: 35672
#include<cstdio>
using namespace std;
int a,b;
int main(){
    scanf("%d%d",&a,&b);
    if(a>0)printf("Positive\n");            
    else if(b>=0)printf("Zero\n");           
    else if((a&1)^(b&1))printf("Positive\n"); 
    else printf("Negative\n");
    return 0;
}

Measured memory_bytes: 128
class Node:
    def __init__(self,key,left=None,right=None,parent=None):
        self.key = key
        self.left = left
        self.right = right
        self.parent = parent

root=None

#前序排序
def PreorderTreeWalk(u):
    if u == None:
        return
    print(" %d"%u.key,end='')
    PreorderTreeWalk(u.left)
    PreorderTreeWalk(u.right)

#中序排序
def InorderTreeWalk(u):
    if (u == None):
        return
    InorderTreeWalk(u.left)
    print(" %d"%u.key,end='')
    InorderTreeWalk(u.right)



def insert(value):
    global root
    
    y = None
    x = root
    z = Node(value)
 
    # 从根结点往下遍历
    while (x != None) :
        y = x
        # z 比 x 小， 则从x的左侧遍历
        # z 比 x 大， 则从x的右侧遍历
        if (z.key < x.key):
            x = x.left
        else:
            x = x.right
    

    z.parent = y

    #没有父结点的是root
    if (y == None): 
        root = z
    else: 
        # z 比 y 小， 则在y的左侧
        # z 比 y 大， 则在y的右侧
        if (z.key < y.key):
            y.left = z
        else:
            y.right = z
            
def find(u,value):
    while (u != None and u.key != value): 
        if (value < u.key):
            u = u.left;
        else:
            u = u.right;
    
    return u


# 树的最小值
def treeMinimum(x):
    while (x.left != None):
        x = x.left;
    return x


# case3如果同时具有左右子树。
#可以将结点x的左子树的最大值（也就是左子树一直往右孩子节点遍历即是最大值）
#或者右子树的最小值（也就是右子树一直往左孩子节点遍历即是最小值）替换x，然后拼接左子树或者右子树
#搜索后一个结点
def treeSuccessor(x) :
    if (x.right != None):
        return treeMinimum(x.right)

    y = x.parent;
    
    if x==y.left:
        return y
    else:
        while (y != None and x == y.right) :
            x = y
            x = y.parent
    
    return y


def treeDelete(z) :
        #x没有子结点，则将x结点删除即可 
        #如果x只有左子树或者只有右子树，则将子树拼接上父结点即可  
        # 确定要删除的结点
    if (z.left == None or z.right == None):
        y = z
    else:
        y = treeSuccessor(z)

    # 确定y的子结点x
    if (y.left != None):
        x = y.left
    else:
        x = y.right

    # 让子结点链接父结点
    if (x != None):
        x.parent = y.parent

    # 让父结点链接子结点
    if (y.parent == None):
        root = x
    else:
        if (y == y.parent.left):
            y.parent.left = x
        else:
            y.parent.right = x
    

    #case 3
    if (y != z):
        z.key = y.key;



n=int(input())
s=[]
for i in range(n):
    s=[x for x in input().split()]
    if s[0][0]=='i':
        insert(int(s[1]))    
    elif s[0][0]=='f':
        f = find(root,int(s[1]));
        if (f != None):
            print("yes")
        else:
            print("no")
    elif s[0][0]=='d':
            treeDelete(find(root, int(s[1])));
    else:
        InorderTreeWalk(root)
        print()
            
        PreorderTreeWalk(root)
        print()
       


Measured memory_bytes: 85280
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
int main() {
  string s;
  cin >> s;
  int N = s.size();
  int count = 0;
  if(N%2 == 0){
    for(int i = 0; i< N/2;i++){
      if(s[i] != s[N-i-1]){
        count += 1;
      }
    }
  }
  else{
    for(int i = 0; i< N/2;i++){
      if(s[i] != s[N-i-1]){
        count +=1;
      }
      
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
N = int(input())
a = [int(i) for i in input().split()]

odd_count = 0
four_times_count = 0
two_times_count = 0
for i in a:
  if i % 4 == 0:
    four_times_count += 1 
  elif i % 2 != 0:
    odd_count += 1
  elif i % 2 == 0 and i % 4 != 0:
    two_times_count += 1

if odd_count == 0 or odd_count == four_times_count or (two_times_count == 0 and odd_count - four_times_count == 1):
  print('Yes')
else: 
  print('No')


Measured memory_bytes: 14252
#include <stdio.h>
int main(void)
{
    float a,b,c,d,e,f,x1=0,x2=0,x3=0,x4=0,y1=0,y2=0,y3=0,x5=0,x6=0,x7=0;
    while(scanf("%f %f %f %f %f %f",&a,&b,&c,&d,&e,&f)!=EOF)
    {
        x1=-1*b/a;
        x2=c/a;
        x3=d*x1;
        x4=d*x2;
        y1=x3+e;
        y2=f-x4;
        y3=y2/y1;
        x5=b*y3;
        x6=c-x5;
        x7=x6/a;
        printf("%.3f %.3f\n",x7,y3);
    }
    return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <fstream>
#include <map>
#include <cassert>
#include <sstream>
#include <numeric>
#include <regex>
#include <cctype>
#include <utility>
#include <stdio.h>

typedef long long ll;

#define nums vector<int>
#define words vector<string>
#define letrs vector<char>
#define MOD 1000000007
#define pb push_back
#define llnums vector<ll>
#define FOR(i,n) for(int i{0}; i < n; ++i)

using namespace std;

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int arr[5], x;
  FOR(i, 5) {
      cin >>x;
      if(x==0){cout <<i+1 << '\n'; return 0;}
  }
  return 0;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#define PII pair<int,int>
#define MP make_pair
#define fir first
#define sec second
#define PB push_back
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=1e5+10;
const ll inf=1e18;
int n,m;
ll c[N];
void add(int i,ll t) { for(;i;i-=i&-i) c[i]=min(c[i],t); }
ll query(int i) { ll ans=inf; for(;i<=n;i+=i&-i) ans=min(ans,c[i]); return ans; }
vector<PII > G[N];
ll f[N];
int main() {
	rd(n),rd(m);
	for(int l,r,c,i=1;i<=m;++i) {
		rd(l),rd(r),rd(c);
		G[r].PB(MP(l,c));
	}
	memset(f,0x3f,sizeof(f));
	memset(c,0x3f,sizeof(c));
	f[1]=0,add(1,0);
	for(int i=2;i<=n;++i) {
		for(int j=0;j<G[i].size();++j)
			f[i]=min(f[i],query(G[i][j].fir)+G[i][j].sec);
		add(i,f[i]);
	}
	if(f[n]>1e16) printf("-1");
	else printf("%lld\n",f[n]);
	return 0;
}

Measured memory_bytes: 7168
#include<iostream>
#include<vector>
using namespace std;
 
int N, M;
int a[100000];
vector<bool> a_d(100001, false);
long long num[100001];
const long long dv = 1e9+7;
void solve()
{
	num[0]  = 1;
	if(!a_d[1])
		num[1] = 1;
	for(int i = 2; i <= N; i++){
		if(!a_d[i]){
				num[i] =(num[i-2] + num[i-1]) % dv;
		}
	}
	long long ans = num[N];
	cout << ans << endl;
}
int main()
{
	cin >> N >> M;
	for(int i = 0; i < M; i++){
		cin >> a[i];
		a_d[a[i]] = true;
	}
	solve();
	return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(0);

    string s;
    cin >> s;
    int idx=0;
    int n=s.length();
    for(;idx<n;){
        if(idx+5<=n && s.substr(idx,5)=="dream"){
            idx+=5;
            if(idx+2<=n && s.substr(idx,2)=="er"){
                if(idx+2>=n || s[idx+2]!='a')
                    idx+=2;
            }
        }
        else if(idx+5<=n && s.substr(idx,5)=="erase"){
            idx+=5;
            if(idx+1<=n && s.substr(idx,1)=="r"){
                if(idx+1>=n || s[idx+1]!='a')
                    idx+=1;
            }
        }
        else
            break;
    }

    if(idx==n) puts("YES");
    else puts("NO");

    return 0;
}

Measured memory_bytes: 640
$|=1;
$N = <STDIN>;chomp $N;
for($i=0;$i<$N-1;$i++){
	$line = <STDIN>;chomp $line;
	($c,$s,$f)=split " ",$line;
	push @C,$c;
	push @S,$s;
	push @F,$f;
}

for($i=0;$i<$N;$i++){
	$t=0;$j=$i;
	while($j<$N-1){
		if($t<$S[$j]) { $t=$S[$j]; }
		if($t%$F[$j]!=0) {$t+= $F[$j]-($t%$F[$j]);}
		$t+=$C[$j];
		$j+=1;
	}
	print "$t\n";
}


Measured memory_bytes: 640
from bisect import bisect_left, bisect_right

N, *X = map(int, open(0).read().split())

X.sort()
ans = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        k1 = bisect_right(X, X[j] - X[i])
        k2 = bisect_left(X, X[i] + X[j])
        k1 = max(k1, j + 1)
        ans += max(0, k2 - k1)

print(ans)


Measured memory_bytes: 74428
#include <string>
#include <cmath>
#include <limits>
#include <iostream>
typedef long long ll;
typedef unsigned long long ull;

using namespace std;
ull mod = 1000000007;


ull to_digit(char b) {
  if(b == '?')
    return -1;
  return b - '0';
}

ull dp[100001][13];


ull mod_pow(int a, int num_ten) {
  ull res = 1;
  for(int i =1;i<=num_ten; i++) {
    res *= 10;
    res %= mod;
  }
  res *= a;
  res %= mod;
  return res % 13;
}

ull digits_parade(string s) {

  ull digit = to_digit(s[0]);
  if(digit == -1) {
    for(int i=0;i<10; i++) {
      dp[1][i] = 1;
    }
  } else {
    dp[1][digit] = 1;
  }
  int length = (int) s.size();
  if(length == 1) {
    return dp[1][5];
  }
  for(int i=1; i< length; i++) {
    ull digit = to_digit(s[i]);
    if(digit != -1) {
      for(int j=0;j<13;j++) {
	dp[i+1][((j*10) + digit) % 13] = dp[i][j];
      }
    } else {
      for(int j=0; j<10; j++) {
	for(int k=0;k<13;k++) {
	  dp[i+1][((k*10) + j) % 13] += dp[i][k];
	  dp[i+1][((k*10) + j) % 13] %= mod;
	}
      }
    }
  }
  return dp[length][5];
}
int main() {
  string s;
  cin >> s;
  cout << digits_parade(s);
}

Measured memory_bytes: 13960
/* Akshat Sharma @akshat98 */
#include <iostream>
#include <bits/stdc++.h>
#define IOS  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp   make_pair
#define pb   push_back
#define F    first
#define S    second
#define ll   long long
#define MOD  1000000007
#define MAX  1000000001
#define vi   vector<int>
#define vl   vector<ll>
#define vpi  vector<pair<int,int> >
#define vpl  vector<pair<ll,ll> >
#define rep(i,a,b) for(i=a;i<b;i++)
#define reqp(i,a,b) for(i=a;i<=b;i++)
#define ren for(i=0;i<n;i++)
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef pair<int,int>pii;
typedef pair<ll,ll>pll;


int main()
{
	
	int i,j,k,l,n,test_case,m,r;
	test_case=1;
	//cin>>test_case;
	while(test_case--){
		cin>>k;
		ll ans=0;
		rep(i,1,k+1){
			rep(j,1,k+1){
				rep(l,1,k+1){
					ans+=__gcd(i,__gcd(j,l));
				}
			}
		}
		cout<<ans;


	}
	
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <vector>
#include <sstream>
#include <string>
#include <climits>
#include <set>
#include <array>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <map>
#include <utility>
using namespace std;

int main()
{
    char ch;
    cin >> ch;

    if (ch >= 'a' && ch <= 'z')
        cout << 'a';
    else cout << 'A';
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define endl "\n"
#define int long long
#pragma GCC optimize(3)
using namespace std;
int n,a[100005],ans;
signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++) 
		cin>>a[i];
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
	{
		a[i]+=a[i-1];
		ans=((a[i]*2<a[i+1])?0:(ans+1));
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        int n = ReadLineParseInt();
        int[] p = ReadLineParseIntArray();
        int count = 0;
        for(int i = 1; i < n - 1; i++)
        {
            int[] tmp = { p[i - 1], p[i], p[i + 1] };
            Array.Sort(tmp);
            if (p[i] == tmp[1])
                count++;
        }
        WriteLine(count);
    }

    static int ReadLineParseInt() => int.Parse(ReadLine());
    static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray();
}

Measured memory_bytes: 13396
import sys

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

A = ri()
B = ri()
print('GREATER' if A > B else 'LESS' if A < B else 'EQUAL')

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

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

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

	int n, m;
	cin >> n >> m;

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

	vector<vector<int>> dp(n + 1, vector<int>(m + 1));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= m; j++) {
			if (j >= w[i]) {
				dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
			} else {
				dp[i + 1][j] = dp[i][j];
			}
		}
	}

	cout << dp[n][m] << endl;
	return 0;
}



Measured memory_bytes: 6824