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

typedef long long LL;
LL n, a, b;
LL m[100003];

bool judge(LL x)
{
    LL sum = 0;
    for(int i=0; i<n; ++i)
    {
        LL t = (LL)m[i]-x*b;
        if(t>0)
        {
            sum += (int)ceil(t*1.0/(a-b));
            if(sum > x || sum < 0)
                return false;
        }
    }
    return true;
}


int main()
{
    while(scanf("%d%d%d",&n,&a,&b)!=EOF)
    {
        LL max1=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&m[i]);
            max1=max(max1,m[i]);
        }
        LL l=0,r=max1;
        while(l<r)
        {
            LL mid=(r+l)/2;
            if(judge(mid))
                r=mid;
            else
                l=mid+1;
        }
        printf("%lld",r);
    }
    return 0;
}


Measured memory_bytes: 1024
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD (LL)(1e9+7)

int N;
ll P[100000];
int place[100001];
multiset<int> st;
ll ans = 0;
int main(){
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> P[i];
		place[P[i]] = i;
	}
	st.insert(-1);
	st.insert(-1);
	st.insert(place[N]);
	st.insert(N);
	st.insert(N);
	for(ll i=N-1; i>=1; i--){
		int p = place[i];
		st.insert(p);
		auto itr = st.lower_bound(p);
		itr++;
		int c = *itr;
		itr++;
		int d = *itr;
		itr = st.lower_bound(p);
		itr--;
		int b = *itr;
		itr--;
		int a = *itr;

		ans += (b-a)*(c-p)*i + (p-b)*(d-c)*i;
	}
	cout << ans << endl;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    for(int i=0;i<10000;i++){
        C -= B;
        if(C<=0){
            cout << "Yes\n";
            return 0;
        }
        A -= D;
        if(A<=0){
            cout << "No\n";
            return 0;
        }
    }
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll a;
    ll b;
    ll c;
    ll d;
}frequent;

int cmp( const void *p, const void *q ) {
    if( ((frequent*)p)->a == ((frequent*)q)->a ) return ((frequent*)p)->b - ((frequent*)q)->b;
    return ((frequent*)p)->a - ((frequent*)q)->a;
}
int cmp1( const void *p, const void *q ) {
    // if( ((frequent*)p)->a == ((frequent*)q)->a ) return ((frequent*)p)->b - ((frequent*)q)->b;
    return ((frequent*)p)->c - ((frequent*)q)->c;
}

int main(void){
    // char ;
    ll n,m;
    scanf("%lld%lld",&n,&m);
    frequent x[m];
    rep(i,0,m){
        scanf("%lld%lld",&x[i].a,&x[i].b);
        x[i].c=i;
    }
    qsort(x,m,sizeof(frequent),cmp);
    ll y=1;
    x[0].d=1;
    rep(i,1,m){
        if(x[i].a==x[i-1].a){
            y++;
        }else{
            y=1;
        }
        x[i].d=y;
    }
    qsort(x,m,sizeof(frequent),cmp1);
    rep(i,0,m){
        printf("%06lld%06lld\n",x[i].a,x[i].d);
    }
    // printf("\n");
    return 0;
}


Measured memory_bytes: 7756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;

#define INX(x) (cin >> x)
#define OUTX(x) (cout << x << endl)

#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>


//ビット列からインデックスの数字列に変換
vll f(ll x, ll len)
{
    vll result;
    for(ll ind = 0; ind < len; ind++)
    {
        ll y = x & 1;
        if(y)
        //if(x & 1 == 0) //これダメ
        {
            result.ADD(ind);
        }
        x >>= 1;
    }
    return result;
}

int main()
{
    //bit全探索
    ll H, W, K;
    cin >> H >> W >> K;

    bool c[6][6];
    for (ll i = 0; i <  H; i++)
    {
        for (ll j = 0; j < W; j++)
        {
            char tmp;
            cin >> tmp;
            c[i][j] = tmp == '#'; //黒がtrueとする
        }
    }
    
    //ビット全探索
    ll result = 0;
    for(ll i = 0, endi = 1 << H; i < endi; i++)
    {
        vll vlli = f(i, H);
        for(ll j = 0, endj = 1 << W; j < endj; j++)
        {
            vll vllj = f(j, W);

            //このパターンでの黒の数を数え上げ
            ll cnt = 0;
            for(ll ti : vlli)
            {
                for(ll tj : vllj)
                {
                    if(c[ti][tj])
                    {
                        cnt++;
                    }
                }
            }

            if(cnt == K)
            {
                result++;
            }
        }
    }
    OUTX(result);


    return 0;
}


Measured memory_bytes: 3612
N = int(input())
AryA = list(map(int, input().split()))
AryB = list(map(int, input().split()))
AryC = list(map(int, input().split()))

sum = 0
tmpBox = N+1

for item in AryA:
	sum += AryB[item-1]
	if (item == tmpBox + 1):
		sum += AryC[tmpBox-1]
	tmpBox = item
print(sum)

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


int main()
{
 
	//freopen("output.in","r",stdin);
    //freopen("output2.txt","w",stdout);

	long long int n,f[105][15],p[105][15],i,a,x,j,mx=-10000000000000000,tmp;
	bool is[15];
	
	cin>>n;
	
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=10;j++)
			cin>>f[i][j];
	}
	
	for(i=1;i<=n;i++)
	{
		for(j=0;j<=10;j++)
		{
			cin>>p[i][j];
		}
	}
	a=1;
	
	while(a<=1023)
	{
		x=a;
		
		for(i=0;i<15;i++)
			is[i]=0;
		i=1;
		while(x!=0)
		{
			if(x&1)
				is[i]=1;
			x/=2;
			i++;
		}
		
		
		{
			tmp=0;
			for(i=1;i<=n;i++)
			{
				long long int cnt=0;
				for(j=1;j<=10;j++)
				{
					if(is[j]==1&&f[i][j]==1)
						cnt++;
				}
			//	cout<<i<<" .. "<<cnt<<" += "<<p[i][cnt]<<endl;
				tmp+=p[i][cnt];
			}
			mx=max(mx,tmp);
			
			//cout<<a<<" "<<tmp<<endl;
		}
		a++;
	}
	cout<<mx;
	return 0;
}

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

public class Hello
{
    public static void Main()
    {
        // Your code here!
        int N = int.Parse(Console.ReadLine());
        List<int> A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        
        while(A.Count >= 2)
        {
            A.Sort();
            for(int i = 1; i < A.Count; i++)
            {
                A[i] %= A[0];
                if(A[i] == 0)
                {
                    A.RemoveAt(i);
                }
            }
            
        }
        Console.WriteLine(A[0]);
        /*
        for (int i = 0; i < A.Count; i++)
        {
            Console.Write(A[i] + " ");
        }
        */
        
    }
}

Measured memory_bytes: 19296
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

//const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 1'000'000'000'000'000'000ll + 7;
//const i64 inf = 1'000'000'007;

const long double eps = 1e-8;

const i64 MAXN = 10;
const i64 MAXM = 10;
const i64 MAXQ = 50 + 5;

i64 cnt[MAXN + 2][MAXN + 2];

i64 n, m, q;
i64 a[MAXQ];
i64 b[MAXQ];
i64 c[MAXQ];
i64 d[MAXQ];

i64 count() {
    for (i64 j = 1; j <= MAXM; j++) {
        cnt[1][j] = 1;
    }

    for (i64 i = 2; i <= MAXN; i++) {
        for (i64 j = 1; j <= MAXM; j++) {
            for (i64 k = 1; k <= j; k++) {
                cnt[i][j] += cnt[i - 1][k];
            }
        }
    }

    i64 R = 0;
    for (i64 j = 1; j <= MAXM; j++) {
        R += cnt[MAXN][j];
    }

    return R;
}

i64 R = 0;
i64 qcnt = 0;

i64 check(vector<i64>& z) {
    qcnt += 1;
    i64 R = 0;
    for (i64 i = 0; i < q; i++) {
        if (z[b[i]] - z[a[i]] == c[i]) {
            R += d[i];
        }
    }
    return R;
}

void gen(vector<i64>& z) {
    if (z.size() == n) {
        i64 r = check(z);
        R = max(R, r);
        return;
    }

    for (i64 i = z.empty() ? 1 : z.back(); i <= m; i++) {
        z.push_back(i);
        gen(z);
        z.pop_back();
    }
}


int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n >> m >> q;
    for (i64 i = 0; i < q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i] -= 1;
        b[i] -= 1;
    }

    vector<i64> z;
    gen(z);
    cout << R << endl;

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  bool answer = false;
  for (int i = 0; i * 4 <= N; i++) {
    for (int j = 0; i * 4 + j * 7 <= N; j++) {
      if (i * 4 + j * 7 == N) answer = true;
    }
  }
  cout << (answer ? "Yes" : "No") << endl;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[200005];
ll B[200005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    REP(i, N) {
        cin >> A[i];
    }

    REP(_, K) {
        memset(B, 0, sizeof(B));
        REP(i, N) {
            ll l = std::max(i - A[i], 0LL);
            ll r = std::min(i + A[i], N - 1);
            B[l]++;
            B[r + 1]--;
        }
        REP(i, N) {
            B[i + 1] += B[i];
            A[i] = B[i];
        }
        swap(A, B);

        bool e = true;
        REP(i, N) {
            if (A[i] < N)
                e = false;
        }
        if (e)
            break;
    }

    REP(i, N) {
        cout << A[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 6740
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm> // sort
#include <utility> // pair
#include <cfloat> // DBL_MAX

typedef long long ll;
using namespace std;

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

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

  sort(As.begin(), As.end());
  ll ans = N;
  for(int i=1; i<N; i++){
    if(As[i-1] == As[i]){
      ans--;
    }
  }
  if(ans%2 == 0){
    ans--;
  }

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


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

int main(){
    string s, s_f;
    int q;
    cin >> s;
    cin >> q;
    int count = 0;

    for(int i = 0; i < q; i++){
        int q_1, q_2;
        cin >> q_1;
        if(q_1 == 1){
            count += 1;
        }
        else{
            string q_3;
            cin >> q_2 >> q_3;
            int x = count;
            x += q_2;
            if(x % 2 == 0){
                s += q_3;
            }
            else{
                s_f += q_3;
            }
        }
    }

    string ans = "";
    if(count % 2 == 1){
        for(int i = 0; i < s.size(); i++){
            ans += s[s.size() - i -1];
        }
        ans += s_f;
    }
    else{
        string s_f_ = "";
        for(int i = 0; i < s_f.size(); i++){
            s_f_ += s_f[s_f.size() - i -1];
        }
        ans = s_f_ + s;
    }
    cout << ans;
}

Measured memory_bytes: 1344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main() {
	int n; cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	int ans = 0;
	for(int i=0; i<n;i+=2){
		if(a[i]%2) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define last Last
#define int long long
const int N=1e6+5;
int n,m,ans,cnt,sum,a[N],gs[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read()
{
	int ret=0,f=0;char c=gc();
	while(!isdigit(c)){if(c=='-')f=1;c=gc();}
	while(isdigit(c)){ret=ret*10+c-48;c=gc();}
	if(f)return -ret;return ret;
}
signed main()
{
	n=read();m=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=2;i<=n;i++)
	{
		int l=a[i-1],r=a[i];
		if(l>r)r+=m;
		sum+=r-l;
		if(r-l>1)
		{
			gs[l+2]++;
			gs[r+1]-=r-(l+2)+2;
			gs[r+2]+=r-(l+2)+1;
		}
	}
	for(int i=1;i<=m*2;i++)gs[i]+=gs[i-1];
	for(int i=1;i<=m*2;i++)gs[i]+=gs[i-1];
	ans=sum;
	for(int i=1;i<=m;i++)ans=min(ans,sum-gs[i]-gs[i+m]);
	cout<<ans;
}

Measured memory_bytes: 5888
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;

using Graph = vector<vector<int> >;

vector<int> seen;

int main()
{
	int N,M,X;

	cin >> N >> M >> X;

	int cnt_l = 0;
	int cnt_r = 0;
	int m;
	for (int mi = 0; mi < M; mi++) {
		cin >> m;
		if (m < X) {
			cnt_l++;
		}
		else {
			cnt_r++;
		}
	}
		
	cout << min(cnt_l, cnt_r);


	//printf("%.9f", ans);
	//std::cout << "Yes";

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a[55];
  double m;
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n);
  m=(a[1]+a[0])/2.0;
  if(n==2) printf("%.7lf",m);
  else {
         for(int i=2;i<n;i++)
            m=m/2.0+a[i]/2.0;
             printf("%.7lf",m);
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stack>
#include<queue>
#include<vector>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define F(i,L,R) for(int i=L;i<R;i++)
#define FE(i,L,R) for(int i=L;i<=R;i++)
#define RF(i,l,r) for(int i=r;i>l;i--)
#define RFE(i,l,r) for(int i=r;i>=l;i--)
#define getI(i) scanf("%d",&i)
#define getII(i,j) scanf("%d%d",&i,&j)
#define getIII(i,j,k) scanf("%d%d%d",&i,&j,&k)
#define VgetI(i) int (i);scanf("%d",&(i));
#define VgetII(i,j) int (i),(j);scanf("%d%d",&(i),&(j));
#define VgetIII(i,j,k) int (i),(j),(k);scanf("%d",&(i),&(j),&(k));
#define EoF(n) int(n);while(~getI(n))
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define abs(n) (n>0?n:(-n))
#define INF 2147483647
#define nINF -2147483648
int main(){
	VgetII(n,k);
	int stick[n],ans=0;
	F(i,0,n) getI(stick[i]);
	sort(stick,stick+n);
	for(int i=n-1,j=0;i>=0&&j<k;i--,j++) ans+=stick[i];
	printf("%d\n",ans);
}


Measured memory_bytes: 256
using System;

namespace abc167_a
{
  class Program
  {
    static void Main(string[] args)
    {
      var S = Console.ReadLine().ToCharArray();
      var T = Console.ReadLine().ToCharArray();

      if (S.Length != T.Length - 1)
      {
        Console.WriteLine("No");
        return;
      }

      for (int i = 0; i < S.Length; i++)
      {
        if (S[i] != T[i])
        {
          Console.WriteLine("No");
          return;
        }
      }

      Console.WriteLine("Yes");
    }
  }
}

Measured memory_bytes: 25788
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;	
	
}





Measured memory_bytes: 3652
//List of Top 3 Hills
#include<bits/stdc++.h>
using namespace std;
vector<int> v;

int main(){
  for(int i=0; i<10; i++){
    int tmp;
    scanf("%d", &tmp);
    v.push_back(tmp);
  }
  sort(v.begin(), v.end(), greater<int>());
  for(int i=0; i<3; i++)
    printf("%d\n", v[i]);
  return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <string>
#include <cstdlib>

int main() {
    int n;
    std::cin >> n;
    int t[n+1],x[n+1],y[n+1];
    for(int i = 1; i <= n; i++) std::cin >> t[i] >> x[i] >> y[i];
    t[0] = 0; x[0] = 0; y[0] = 0;
    int dift,difx,dify;
    for(int i = 1; i <= n; i++){
        dift = t[i]-t[i-1];
        difx = std::abs(x[i]-x[i-1]);
        dify = std::abs(y[i]-y[i-1]);
        if(difx + dify > dift){
            std::cout << "No" << std::endl;
            return 0;
        }else{
            if((difx+dify)%2 == 0 && dift%2 != 0){
                std::cout << "No" << std::endl;
                return 0;
            }
            else if((difx+dify)%2 != 0 && dift%2 == 0){
                std::cout << "No" << std::endl;
                return 0;
            }
        }
    }
    std::cout << "Yes" << std::endl;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

char S[12];

void solve(){
	scanf("%s", S);
	if(S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I') puts("Yes");
	else puts("No");
}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		// printf("Case #%d: ", tc);
		solve();
	}
	return 0;
}

Measured memory_bytes: 764
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import unittest
from io import StringIO
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    s = str(input())
    ls = len(s)
    dp = [[0]*13 for _ in range(ls+1)]
    dp[0][0] = 1
    MOD = 10**9+7

    for i in range(ls):
        for j in range(13):
            if s[i] == '?':
                for k in range(10):
                    dp[i+1][(j*10+k) % 13] += dp[i][j]
                    dp[i+1][(j*10+k) % 13] %= MOD
            else:
                dp[i+1][(j*10+int(s[i])) % 13] += dp[i][j]
                dp[i+1][(j*10+int(s[i])) % 13] %= MOD

    print(dp[ls][5])


resolve()

Measured memory_bytes: 76940
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=15,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int p[MAXn],c[MAXn];
int dp[MAXn][1005];
int main(){
  IOS();
  int d,g;
  cin>>d>>g;
  int tot=0;
  RST(dp,-1);
  REP(i,d){
    cin>>p[i]>>c[i];
    tot+=p[i];
  }
  int ans=INF;
  REP(i,p[0]+1){
    if( i!=p[0] ) dp[0][i]=i*100;
    else dp[0][i]=i*100+c[0];
  }
  for(int i=1;i<d;i++){
    REP(j,tot+1){
      REP(k,p[i]+1){
        if( j-k<0 ) continue;
        if( k!=p[i] ) chkmax(dp[i][j],dp[i-1][j-k]+k*100*(i+1));
        else chkmax(dp[i][j],dp[i-1][j-k]+k*100*(i+1)+c[i]);
        debug(dp[i][j],i,j);
      }
    }
  }
  REP(i,d) pary(dp[i],dp[i]+tot);
  REP(i,tot+1)if(dp[d-1][i]>=g) chkmin(ans,i);
  cout<<ans<<endl;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main(){

    int n;
    cin >> n;
    int a;
    
    rep(i,n){
        cin >> a;
        if(a%2==1){
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
    return 0;
}

Measured memory_bytes: 3580
n,m = map(int,input().split())
ab = []
for i in range(0,m):
    ab.append(list(map(int,input().split())))

ab.sort(key=lambda x:x[0])

i = 0
count = 1
b1=ab[0][1]
a1=ab[0][0]
while i < m:
    if ab[i][0]>=b1:
        count += 1
        b1 = ab[i][1]
    else:
        b1 = min(b1,ab[i][1])
    i += 1
print(count)

Measured memory_bytes: 29144
#include<stdio.h>
#include<iso646.h>
 
int main(){
  int A,B;
 
  scanf("%d %d",&A,&B);
 
  if((A + B) < 10){
    printf("%d\n",A + B);
  }else{
    printf("error\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int i,j;
	int q;
	int b,e,t;
	int a[1001];
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	cin>>q;
	for(i=0;i<q;i++){
		cin>>b>>e>>t;
		int x=e-b;
		for(j=0;j<n;j++){
			if(j>=0&&j<x){
				swap(a[j+b],a[j+t]);
			}
		}
	}
	cout<<a[0];
	for(i=1;i<n;i++){
		cout<<" "<<a[i];
	}
	cout<<endl;
	return 0;
}
	


Measured memory_bytes: 3124
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

K = int(input())

print(A[K-1])


Measured memory_bytes: 2940
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { -1,0,1,0 }, dy[4] = { 0,-1,0,1 };
const char dir[4] = { 'u','l','d','r' };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        (wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

int n;
int s[1010], p[1010], q[1010], r[1010];
int P, Q, R, C;

int main() {
	while (cin >> n&&n) {
		REP(i, n)cin >> s[i] >> p[i] >> q[i] >> r[i];
		cin >> P >> Q >> R >> C;
		int cnt = 0;
		REP(i, n) {
			if (P < p[i])continue;
			if (Q < q[i])continue;
			if (R < r[i])continue;
			if (C < 4 * p[i] + 9 * q[i] + 4 * r[i])continue;
			cout << s[i] << endl;
			cnt++;
		}
		if (!cnt)cout << "NA" << endl;
	}
}


Measured memory_bytes: 3108
use std::io::*;
use std::str::FromStr;
use std::f64;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a:f64 = read();
    let b:f64 = read();
    let mut n: f64 = read(); //時
    let m: f64 = read(); //分

    if n > 12.0 {
        n -= 12.0;
    }

    let n_angle = n * 30.0 + m * 0.5;
    let m_angle = m * 6.0;

    let mut angle = 0.0;
    if n_angle < m_angle {
        if (m_angle - n_angle) < 360.0 - (m_angle - n_angle){
            angle = m_angle - n_angle;
        }else{
            angle = 360.0 - (m_angle - n_angle);
        }
    }else{
        if (n_angle - m_angle) < 360.0 - (n_angle - m_angle){
            angle = n_angle - m_angle;
        }else{
            angle = 360.0 - (n_angle - m_angle);
        }
    }

    let ans = a*a + b*b - 2.0*a*b*((angle.to_radians()).cos());
    println!("{:.012}",ans.sqrt());
}


Measured memory_bytes: 3036
L, R = map(int, input().split())

if R - L >= 2019:
    print(0)
else:
    a = L % 2019
    b = R % 2019
    if a >= b:
        print(0)
    else:
        ans = 2019
        for i in range(a, b):
            for j in range(i+1, b+1):
                ans = min(ans, (i*j)%2019)
        print(ans)

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    vector<ll> h(n);
    vector<int> ok(n - 1);
    rep (i, n) {
        cin >> h[i];
    }
    FOR (i, 1, n) {
        if (h[i - 1] - h[i] >= 0) {
            ok[i - 1] = 1;
        }
    }
    rep (i, n - 1) {
        int cnt = 0;
        FOR (j, i, n - 1) {
            if (ok[j] == 0) break;
            cnt++;
        }
        ans = max(ans, cnt);
        i += cnt;
    }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 1408
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
l = []

for i in range(n, 0, -1):
    s = 0
    c = n // i
    if c == 1:
        b[i-1] = a[i-1]
    else:
        for j in range(1, c+1):
            s += b[i*j-1]
        if (s+a[i-1])%2 == 1:
            b[i-1] = 1
    #print("n:" + str(i) + " c:" + str(c) + " s:" + str(s))

for k in range(0, n):
    if b[k] == 1:
        l.append(k+1)

print(len(l))
for m in l:
    print(m)


Measured memory_bytes: 12472
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
using namespace std;

#define LL long long

const int MAXN = 500000 + 5;



int main()
{
    LL K, D, X, n, m;
    bool ne = false;
    cin >> X >> K >> D;
    if (X < 0){
        ne = true;
        X = -X;
    }
    n = X / D;

    if (n <= K){
        X = X - n * D;
        n -= K;
        n = -n;
        if (n & 1){
            X -= D;
        }
    }
    else{
        X = X - K * D;
    }
    cout << abs(X);
    system("pause");
    return 0;
}

Measured memory_bytes: 3696
#include<stdio.h>
int n,a,b,i,j,m;
int main(void){
scanf("%d%d%d",&n,&a,&b);
if(a <= b){
i = a;
m = b;
}else{
i = b;
m = a;
}
 // printf("%d,%d",i,m);

if(a+b < n){

   j = 0;
}else{
  j = a+b-n;
 

}
  
printf("%d %d\n",i,j);
return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007

int main(){
    string S;
    int K;
    cin >> S >> K;
    for(int i=0;i<S.size();i++){
        if(S[i]!='1'){
            cout << S[i] << endl;
            return 0;
        }
        if(i+1==K){
            cout << 1 << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(void)
{
	using namespace std;
	char c;
	int count[26] = {0};
	while(cin >> c)
	{
		if(c >= 'a' && c <= 'z')
			count[int(c - 'a')] ++;
		else if(c >= 'A' && c <= 'Z')
			count[int(c - 'A')] ++;
		else
			continue;
	}
	for(int i = 0; i < 26; i++)
		cout << char(i + 'a') << " : " << count[i] << endl;
	return 0;
}


Measured memory_bytes: 3100
#include <iostream>
using namespace std;
bool kansu(string,string);

int main(void){
    string s,t;
    cin>>s>>t;
    if(kansu(s,t)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

bool kansu(string s,string t){
    for(int i=0;i<s.length();++i){
        if (s[i]!=t[i]) return false; 
    }
    return true;
}


Measured memory_bytes: 3592
/*
Look at the star
Look at the shine for U
*/ 

#include<bits/stdc++.h>
#define sl(x) scanf("%lld",&x)
using namespace std;
typedef long long ll;
const int N = 1e6+5;
const ll mod = 1e9+7;
const ll INF = 0x3f3f3f3f;
ll s[N];

int main()
{
	ll i,j,k,n;
	sl(n);
	for(i = 0;i < n;i++)
	sl(s[i]);
	
	ll sum = 0;
	for(i = 0;i < n;i++)
	sum += s[i]-1;
	
	cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll n;
  cin >> n;
  ll a[90];
  a[0] = 2; a[1] = 1;
  for(int i=2; i<n+1; ++i) a[i] = a[i-1]+a[i-2];
  cout << a[n] << endl;
}

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

using namespace std;
typedef long long ll;

ll n,a[100100],temp,flag,mod=1e9+7,ans=1;

int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>temp;
        a[temp]++;
    }
    if((n+1) % 2 == 0){
        if(a[0] != 1)flag=1;
        for(int i=1;i<n/2+1;i++){
            if(a[i*2] != 2)flag=1;
            if(a[i*2-1] != 0)flag=1;
            (ans*=2) %= mod;
        }
        if(flag)cout<<0<<endl;
        else cout<<ans<<endl;
    }
    else{
        for(int i=1;i<n/2+1;i++){
            if(a[i*2-1] != 2)flag=1;
            if(a[i*2] != 0)flag=1;
            (ans*=2) %= mod;
        }
        if(flag)cout<<0<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


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

const long long MOD = 1000000007;
const int MAX = 1000010;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(void) {
    long long S;
    cin >> S;
    long long div = S / 3;
    long long ans = 0;
    COMinit();
    for (long long i = 1; i <= div; i++) {
        long long e = S - i * 3;
        ans = (ans + COM(e + i - 1, i - 1) % MOD) % MOD;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 27140
#include <iostream>
using namespace std;
int main(){
    int a,b,t;
    while(1){
        cin>>a>>b;
        if(a==0){
            if(b==0){
                break;
            }
        }
        if(a>b){
         t=a;
         a=b;
         b=t;
    }
    cout<<a<<" "<<b<<endl;
    }
    return 0;
}



Measured memory_bytes: 3084
n,x=(int(x) for x in input().split())
list = input().split()
list = [int(s) for s in list]
list.append(0)
d = 0
count = 0

for i in range(n+1):
    if d > x:
        break
    else:
        count = count + 1
        d = d + list[i]

print(count)

Measured memory_bytes: 3060
n,k = map(int, input().split())
ans=0
if k==0:
    print(n*n)
    exit()
for i in range(1, n+1):
    p = n//i

    ans+=(p*max(0, i-k))
    ans+=(max(0, n%i-k+1))
print(int(ans))


Measured memory_bytes: 2940
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
    
def do():
    n=INT()
    A=LIST()
    ct=1000
    st=0
    flg=0 #0=stock0
    for i in range(n-1):
        if flg==0:
            if A[i]<A[i+1]:
                st=ct//A[i]
                ct=ct%A[i]
                flg=1
            else:
                pass
        else:
            if A[i]>A[i+1]:
                ct=ct+st*A[i]
                st=0
                flg=0
            else:
                pass
    ct=ct+st*A[n-1]
    print(ct)

if __name__ == '__main__':
    do()

Measured memory_bytes: 9160
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String s=sc.next();
		int limit=s.length();
		Character[] a=new Character[limit];
		
		for(int i=0;i<limit;i++){
	
	a[i]= s.charAt(i);
	
		}
		// スペース区切りの整数の入力
		//int b = sc.nextInt();
		//int c = sc.nextInt();
		// 文字列の入力
		//String s = sc.next();
		// 出力
	if(limit>=4){
	if(a[0]=='Y'&&a[1]=='A'&&a[2]=='K'&&a[3]=='I')
		System.out.println("Yes");
		else
		System.out.println("No");
	}
		else
		System.out.println("No");
	
	   // System.out.println(a[2]);
	}
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

int main(int argc, char *argv[]) {
    ll n;
    cin >> n;

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

    cout << ans << endl;
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<iomanip>
using namespace std;

int main(){

	while (true) {
		int cnt = 0;
		cin >> cnt;
		if (cnt == 0) break;

		typedef std::pair<long, long> elemType;
		typedef std::vector<elemType> dataType;
		dataType data;
		for (int i = 0; i < cnt; ++i) {
			long id, price, amount;
			cin >> id >> price >> amount;
			long g = price * amount;

			bool found = false;
			for (unsigned int i = 0; i < data.size(); ++i) {
				if (data[i].first == id) {
					data[i].second += g;
					found = true;
				}
			}
			if (!found) data.push_back(elemType(id, g));
		}
		bool bHitted = false;
		for (dataType::iterator it = data.begin(); it != data.end(); ++it) {
			if (it->second >= 1000000) {
				cout << it->first << "\n";
				bHitted = true;
			}
		}
		if (!bHitted) {
			cout << "NA\n";
		}
	}
	return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
unordered_map < int, int > P;
int main()
{   
    int n, m;
    scanf("%d %d", &n, &m);
    LL result = 0LL;
    int sum = 0;
    P[0] = 1;   
    for (int i = 0; i < n; ++i) {
        int a;
        scanf("%d", &a);
        sum = (sum + a) % m;
        result += 1LL * P[sum]++;
    }    
    printf("%lld", result);
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
const long long INF = 1LL << 60;

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;}

int main()
{   
    int n; cin >> n;
    vector<ll> a(n),b(n),c(n);
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++) cin >> b[i];
    for(int i=0;i<n;i++) cin >> c[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    ll res = 0;
    for(int i=0;i<n;i++){
        auto posa = lower_bound(a.begin(),a.end(),b[i]) - a.begin();
        auto posc = upper_bound(c.begin(),c.end(),b[i]) - c.begin();
        res += posa*(n-posc);
    }

    cout << res << endl;
}

Measured memory_bytes: 2560
N = int(input())
h_list = list(map(int, input().split()))

minn = 1
maxn = 10**9

lmax_list = [minn for i in range(N)]
rmin_list = [maxn for i in range(N)]

lmax_list[0] = h_list[0]
rmin_list[N-1] = h_list[N-1]
for i in range(1, N):
    h = h_list[i]
    if h > lmax_list[i-1]:
        lmax_list[i] = h
    else:
        lmax_list[i] = lmax_list[i-1]

for i in range(N-2)[::-1]:
    h = h_list[i]
    if h < rmin_list[i]:
        rmin_list[i] = h
    else:
        rmin_list[i] = rmin_list[i+1]

diff_list = [ lmax_list[i] - rmin_list[i+1] for i in range(N-1)]

if len(diff_list) > 0 and max(diff_list) > 1:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 14480
#include <vector>
#include <iostream>
#include <map>
const int INF = 1e9;
using namespace std;

pair<string, string> get_name(string S){
  string s, t;
  for(int i = 0; i < S.length(); ++i){
    if(S[i] == '-'){
      t = S.substr(i+1);
      break;
    }
    s += S[i];
  }
  return pair<string, string>(s, t);
}

void dfs(vector< vector<int> > &G, vector<int> &C, int v){
  int n = G.size();
  for(int i = 0; i < n; ++i){
    if(G[v][i] >= INF && G[i][v] >= INF) continue;
    if(C[i] == 0){
      C[i] = -C[v];
      dfs(G, C, i);
    }
  }
}

int main(){
  int N;
  while(cin >> N, N){
  map<string, int> m;
  vector<string> from(N), to(N);
  for(int i = 0; i < N; ++i){
    string s;
    cin >> s;
    pair<string, string> E = get_name(s);
    m[E.first] = 1;
    m[E.second] = 1;
    from[i] = E.first;
    to[i] = E.second;
  }
  int t = 1;
  for(auto itr = m.begin(); itr != m.end(); ++itr){
    itr->second = t;
    ++t;
  }
  int n = m.size();
  cout << n << endl;
  vector< vector<int> > G(n, vector<int>(n, INF));
  for(int i = 0; i < N; ++i){
    int u = m[from[i]] - 1, v = m[to[i]] - 1;
    G[u][v] = 1;
  }
  vector<int> C(n, 0);
  for(int i = 0; i < n; ++i){
    if(!C[i]){
      C[i] = 1;
      dfs(G, C, i);
    }
  }

  vector< vector<int> > G_ = G;
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      if(G[i][j] < INF || G[j][i] < INF) continue;
      bool f = false;
      for(int k = 0; k < n; ++k){
        if((G[i][k] < INF && G[j][k] < INF) || (G[k][i] < INF && G[k][j] < INF)){
          f = true;
          break;
        }
      }
      for(int k = 0; k < n; ++k){
        if((G[i][k] < INF && G[k][j] < INF) || (G[k][i] < INF && G[j][k] < INF)){
          f = false;
          break;
        }
      }
      if(f){
        G_[i][j] = 1;
        G_[j][i] = 1;
      }
    }
  }

  for(int k = 0; k < n; ++k){
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < n; ++j){
        G_[i][j] = min(G_[i][j], G_[i][k] + G_[k][j]);
      }
    }
  }

  int M;
  cin >> M;
  for(int i = 0; i < M; ++i){
    string S;
    cin >> S;
    pair<string, string> Q = get_name(S);
    int u = m[Q.first] - 1, v = m[Q.second] - 1;
    if(u < 0 || v < 0){
      cout << "NO" << endl;
      continue;
    }
    if(C[u] != C[v] && G_[u][v] < INF) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  }
  return 0;
}



Measured memory_bytes: 3424
N = int(input())
a_ls = list(map(int, input().split()))
abs_ls = [0] * N
minus = 0
for i in range(N):
    if a_ls[i] < 0:
        minus += 1
    abs_ls[i] = abs(a_ls[i])

if minus % 2 == 1:
    ans = sum(abs_ls) - 2 * min(abs_ls)
else:
    ans = sum(abs_ls)
print(ans)

Measured memory_bytes: 20064
import numpy as np

def input_numbers():
    temp = list(map(int, input().split()))
    return temp

def GCD(a, b):
    if(a < b):
        temp = a
        a = b
        b = temp
    a = a % b
    if(a == 0):
        return b
    else:
        return GCD(a, b)

n = int(input())
a = input_numbers()

g = a[0]
for i in range(1, n):
    g = GCD(g, a[i])

print(g)

Measured memory_bytes: 23132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N,vector<int>(M));
    for (int i = 0; i < N; i++) {
        cin >> C[i];
        for (int j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }
    int ans = INT32_MAX;
    for (int i = 1; i < (1<<N); i++) {
        vector<int> sum(M);
        int total = 0;
        for (int j = 0; j < N; j++) {
            if (i & (1<<j)) { // If you read j-th book.
                total += C[j];
                for (int k = 0; k < M; k++) {
                    sum[k] += A[j][k];
                }
            }
        }
        for (int j = 0; j < M; j++) {
           if (sum[j] < X) break; 
           if (j == M - 1) { // If all algorithm archivement is over X.
               ans = min(ans, total);
           }
        }
    }
    if (ans != INT32_MAX) {
        cout << ans ;
    } else {
        cout << "-1";
    }
    return 0;
}

Measured memory_bytes: 3640
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);
struct table
{
	pii v[20][200111];
	int lg2[200111],n;
	void construct(int n,int *a)
	{
		for(int i=2;i<200111;i++)lg2[i]=lg2[i>>1]+1;
		this->n=n;
		for(int i=1;i<=n;i++)v[0][i]=mp(a[i],i);
		for(int i=1;i<20;i++)
		{
			for(int j=1;j<=n;j++)
			{
				int nxt=j+(1<<i-1);
				if(nxt>n)v[i][j]=v[i-1][j];
				else v[i][j]=min(v[i-1][j],v[i-1][nxt]);
			}
		}
	}
	pii query(int l,int r)
	{
		int len=lg2[r-l+1];
		return min(v[len][l],v[len][r-(1<<len)+1]);
	}
}m[2];
int n,a[200111],b[200111],pos[200111],dgr[100111];
vector<pii> all;
vector<int> g[100111];
void dfs(int l,int r,int f=-1)
{
	if(l>r)return;
	int par=l&1,fa=(int)all.size();
	pii mn=m[par].query(l,r),mn2=m[par^1].query(mn.ss+1,r),aa=mp(mn.ff,mn2.ff);
	mn=m[par^1].query(l,r);mn2=m[par].query(l,mn.ss-1);aa=min(aa,mp(mn2.ff,mn.ff));
//	printf("dfs %d %d mnpair= %d %d\n",l,r,aa.ff,aa.ss);
	all.pb(aa);
	dfs(l,pos[aa.ff]-1,fa);
	dfs(pos[aa.ff]+1,pos[aa.ss]-1,fa);
	dfs(pos[aa.ss]+1,r,fa);
	if(f>-1)
	{
		g[f].pb(fa);
		dgr[fa]++;
	}
}
set<pair<pii,int> > st;
int main()
{
	get1(n);
	for(int i=1;i<=n;i++){get1(a[i]);pos[a[i]]=i;}
//	memcpy(t,a,sizeof(a));
	for(int i=1;i<=n;i++)
	{
		if(i%2)
		{
			b[i]=a[i];
			a[i]=n+1;
		}
		else b[i]=n+1;
	}
	m[0].construct(n,a);m[1].construct(n,b);
	dfs(1,n);
//	sort(all.begin(),all.end());
	for(int i=0;i<(int)all.size();i++)if(dgr[i]==0)st.insert(mp(all[i],i));
	while(!st.empty())
	{
		int x=st.begin()->ss;
		st.erase(mp(all[x],x));
		printf("%d %d ",all[x].ff,all[x].ss);
		for(int i=0;i<(int)g[x].size();i++)
		{
			dgr[g[x][i]]--;
			if(dgr[g[x][i]]==0)
				st.insert(mp(all[g[x][i]],g[x][i]));
		}
	}
	return 0;
}

Measured memory_bytes: 85492
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++);

using namespace std;

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

	int total = 0;
	for(int i=0;i<n;i++){
		total += a[i];
		if(total >= h){ 
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 640
import sys

read = sys.stdin.read
readline = sys.stdin.readline

N, M, *sc = map(int, read().split())
answer = [-1] * N

for s, c in zip(*[iter(sc)] * 2):
    s -= 1
    if answer[s] == -1:
        answer[s] = c
    else:
        if answer[s] != c:
            print(-1)
            exit()

if N != 1:
    if answer[0] == -1:
        answer[0] = 1
    elif answer[0] == 0:
        print(-1)
        exit()

answer = [i if i != -1 else 0 for i in answer]
print(''.join(map(str, answer)))


Measured memory_bytes: 3064