akhauriyash/Code-Regression huggingface dataset:
program main
implicit None
	integer(8)::n,m,i,j,q,r
	integer(8),allocatable::p(:),y(:),a(:),b(:),c(:)
	
	read*,n,m
	allocate(p(m),y(m),a(m))
	
	do i = 1,m
		read*,p(i),y(i)
		a(i) = i
	enddo
	
	call h3(p,a,y,m)
	
	q = 1
	r = 1
	
	do
		do
			if(r+1 > m)exit
			if(p(r+1)/=p(r))exit
			r = r+1
		enddo
		j = r-q+1
		allocate(b(j),c(j))
		b(1:j) = y(q:r)
		c(1:j) = a(q:r)
		call h2(b,c,j)
		do i = 1,j
			b(i) = i
		enddo
		y(q:r) = b(1:j)
		a(q:r) = c(1:j)
		q = r+1
		r = r+1
		deallocate(b,c)
		if(r>m)exit
	enddo
	
	call h3(a,p,y,m)
	
	do i = 1,m
		y(i) = p(i)*1000000+y(i)
	enddo
	
	do i = 1,m
	print"(i12.12)",y(i)
	enddo
	
end program main


subroutine h3(a,b,c,n)
implicit None
	integer(8)::a(n),b(n),c(n),x,y,z
	integer(8)::n,i,ie,i0,i1,i2
	
	do i = n/2,1,-1
		x = a(i);y = b(i);z = c(i);ie = n + 1; i0 = i; i1 = i0 * 2
		do while(i1 < ie)
			i2 = i1 + 1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				b(i0) = b(i1);b(i1) = y
				c(i0) = c(i1);c(i1) = z
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
	do ie = n,2,-1
		x = a(ie);y = b(ie);z = c(ie)
		a(ie) = a(1);b(ie) = b(1);c(ie) = c(1)
		a(1) = x;b(1) = y;c(1) = z
		i0 =1;i1 =2
		do while(i1 <ie)
			i2 = i1 +1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				b(i0) = b(i1);b(i1) = y
				c(i0) = c(i1);c(i1) = z
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
end subroutine h3

subroutine h2(a,b,n)
implicit None
	integer(8)::a(n),b(n),x,y
	integer(8)::n,i,ie,i0,i1,i2
	
	do i = n/2,1,-1
		x = a(i);y = b(i);ie = n + 1; i0 = i; i1 = i0 * 2
		do while(i1 < ie)
			i2 = i1 + 1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				b(i0) = b(i1);b(i1) = y
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
	do ie = n,2,-1
		x = a(ie);y = b(ie)
		a(ie) = a(1);b(ie) = b(1)
		a(1) = x;b(1) = y
		i0 =1;i1 =2
		do while(i1 <ie)
			i2 = i1 +1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				b(i0) = b(i1);b(i1) = y
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
end subroutine h2

Measured memory_bytes: 4224
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

ll dp[SIZE][3];

int main() {
  int N, K, R, S, P;
  string T;

  cin >> N >> K >> R >> S >> P >> T;

  int point[3] = {R, S, P};

  for (int i=0; i<N; i++) {
    for (int j=0; j<3; j++) {
      if (i < K) {
        if (T[i] == "spr"[j]) {
          dp[i][j] = point[j];
        }
      } else {
        if (T[i] == "spr"[j]) {
          if (j != 0) dp[i][j] = max(dp[i][j], dp[i-K][0] + point[j]);
          if (j != 1) dp[i][j] = max(dp[i][j], dp[i-K][1] + point[j]);
          if (j != 2) dp[i][j] = max(dp[i][j], dp[i-K][2] + point[j]);
        } else {
          if (j != 0) dp[i][j] = max(dp[i][j], dp[i-K][0]);
          if (j != 1) dp[i][j] = max(dp[i][j], dp[i-K][1]);
          if (j != 2) dp[i][j] = max(dp[i][j], dp[i-K][2]);
        }
      }
    }
  }

  ll ans = 0;

  for (int i=N-K; i<N; i++) {
    ans += max({dp[i][0], dp[i][1], dp[i][2]});
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
  
int main()
{
  ll R, G, B, N;
  cin >> R >> G >> B >> N;

  if(R==1&&G==1&&B==1){
    cout << (N+2)*(N+1)/2 << endl;
  }else{ 
    ll cnt = 0;
    REP(i,N/R+2){
      REP(j,(N-i*R)/G+2){
        REP(k,(N-i*R-j*G)/B+2){
          if(i*R+j*G+k*B==N){
            cnt++;
          }
        }
      }
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
template < class R > inline void Readin( R &K ) {
	K = 0 ; bool F = false ; char C = getchar() ; while( C < '0' or C > '9' ) { if( C == '-' ) F = true ; C = getchar() ; }
	while( C <= '9' and C >= '0' ) K = ( K << 1 ) + ( K << 3 ) + C - '0' , C = getchar() ; if( F ) K = -K ;
}
template < class R > inline void Checkmax( R &A , R B ) {
	if( A < B ) A = B ;
}
template < class R > inline void Checkmin( R &A , R B ) {
	if( A > B ) A = B ;
}
const int Mod = 1e9 + 7 ;
inline void Moding( int &A ) {
	if( A >= Mod ) A -= Mod ;
	if( A < 0 ) A += Mod ;
}
inline int Pow( int A , int B ) {
	register int Ans = 1 ;
	while( B ) {
		if( B & 1 ) Ans = 1ll * Ans * A % Mod ;
		A = 1ll * A * A % Mod ;
		B >>= 1 ;
	}
	return Ans ;
}
const int MaxN = 400000 + 10 ;
const int MaxM = 4000 + 10 ;
int N ;
int A[MaxN] , B[MaxN] ;
int Fac[MaxN] , Inv[MaxN] ;
inline int C( int N , int M ) {
	return 1ll * Fac[M] * Inv[N] % Mod * Inv[M-N] % Mod ;
}
inline int F( int N , int M ) {
	return C( N , N + M ) ;
}
int Dp[MaxM][MaxM] ;
inline int DP() {
	register int Ans = 0 ;
	for(register int i = 0 ; ++i <= N ; ) {
		++Dp[2001-A[i]][2001-B[i]] ;
		--Dp[2001+A[i]][2001+B[i]] ;
	}
	for(register int i = 0 ; ++i <= 4001 ; )
		for(register int j = 0 ; ++j <= 4001 ; ) {
			register int Vot = 0 ;
			if( Dp[i][j] < 0 ) {
				Vot = -Dp[i][j] ;
				Dp[i][j] = 0 ;
			}
			Moding( Dp[i][j] += Dp[i-1][j] + Dp[i][j-1] - Mod ) ;
			Moding( Ans += 1ll * Vot * Dp[i][j] % Mod ) ;
		}
	return Ans ;
}
inline int MORE() {
	register int Ans = 0 ;
	for(register int i = 0 ; ++i <= N ; )
		Moding( Ans += F( A[i] << 1 , B[i] << 1 ) ) ;
	return Ans ;
}
int main() {
	N = 400000 ;
	Fac[0] = Inv[0] = 1 ;
	for(register int i = 0 ; ++i <= N ; )
		Fac[i] = 1ll * Fac[i-1] * i % Mod ;
	Inv[N] = Pow( Fac[N] , Mod - 2 ) ;
	for(register int i = N ; --i ; )
		Inv[i] = 1ll * Inv[i+1] * (i+1) % Mod ;
	Readin( N ) ;
	for(register int i = 0 ; ++i <= N ; ) {
		Readin( A[i] ) ;
		Readin( B[i] ) ;
	}
	return not printf( "%lld\n" , 1ll * ( DP() - MORE() + Mod ) % Mod * ( Mod + 1 >> 1 ) % Mod ) ;
}

Measured memory_bytes: 68480
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#define MAXV 111
#define F(a,b) for(int a = 0; a < b; ++ a)
#define FF(a,b) for(int a = 1; a <= b; ++ a)
using namespace std;
long long dp[100010];
int w[MAXV], v[MAXV];
int main(){
	int N, C;
	scanf("%d%d", &N, &C);
	F(i,N){
		scanf("%d%d", &w[i], &v[i]);
	}
	memset(dp, -1, sizeof(dp));
	for(int j = 0; j <= C; ++ j){
		dp[j] = (j >= w[0] ? v[0] : 0);
	}
	for(int i = 1; i < N; ++ i){
		for(int j = C; j >= w[i]; -- j){
			dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
		}
	}
	printf("%lld\n", dp[C]);
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<int>> c(10,vector<int>(10));
  vector<vector<int>> a(h,vector<int>(w));
  vector<vector<int>> m(10,vector<int>(10));
  for(int i=0;i<=9;i++){
    for(int j=0;j<=9;j++){
      cin >> c[i][j];
    }
  }
  for(int i=0;i<=9;i++){
    for(int j=0;j<=9;j++){
      for(int k=0;k<=9;k++){
        c[j][k]=min(c[j][k],c[j][i]+c[i][k]);
      }
    }
  }
  int ans=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> a[i][j];
      if(a[i][j]>=0){
        ans+=c[a[i][j]][1];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,l,r) for (int i=l; i<=r; i++)
typedef long long ll;
using namespace std;

const int N=210;
int n,u,v,mn,p,cnt,tot,h[N],a[N],d[N],to[N],nxt[N],b[N],dep[N][N];

void add(int u,int v){ to[++cnt]=v; nxt[cnt]=h[u]; h[u]=cnt; }

void dfs(int x,int fa,int k){
	dep[k][x]=dep[k][fa]+1;
	for (int i=h[x],v; i; i=nxt[i])
		if ((v=to[i])!=fa) dfs(v,x,k);
}

ll work(int x,int y){
	ll res=1;
	memset(b,0,sizeof(b));
	rep(i,1,n){
			int p=min(dep[x][i],dep[y][i]);
			b[p]=max(b[p],d[i]-1);
	}
	rep(i,1,n) if (b[i]) res*=b[i]; else break;
	return res<<1;
}

int work1(int x){
	ll res=1;
	memset(b,0,sizeof(b));
	rep(i,1,n) b[dep[x][i]]=max(b[dep[x][i]],d[i]-1);
	rep(i,2,n) if (b[i]) res*=b[i]; else break;
	return res*d[x];
}

int main(){
	scanf("%d",&n); mn=n+1;
	rep(i,2,n) scanf("%d%d",&u,&v),add(u,v),add(v,u),d[u]++,d[v]++;
	rep(i,1,n) dfs(i,0,i);
	rep(i,1,n) rep(j,1,n) dep[i][0]=max(dep[i][0],dep[i][j]);
	rep(i,1,n) mn=min(mn,dep[i][0]);
	rep(i,1,n) if (dep[i][0]==mn) a[++tot]=i;
	if (tot==2) printf("%d %lld\n",mn-1,work(a[1],a[2]));
	else{
		ll ans=work1(a[1]);
		for (int i=h[a[1]]; i; i=nxt[i]) a[++tot]=to[i];
		rep(i,2,tot) ans=min(ans,work(a[1],a[i]));
		printf("%d %lld\n",mn,ans);
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = str(input())
 
if N + 2 // 2 == 1:
    print('No')
 
else:
    f = int(N/2)
    b = int(N/2)
    front = S[:f]
    back = S[b:]
    if front == back:
        print('Yes')
    else:
        print('No')
    
#print(front)
#print(back)

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

int main(){
  int i,kantei=0,mum_a[26],mum_b[26];
  string a,b;
  bool flag=false;

  cin>>a;
  cin>>b;

  a=a+a;
  for(i=0;i<(int)a.size()-(int)b.size()+1;i++){
    string t=a.substr(i,(int)b.size());

    if(t==b){
      flag=true;
      break;
    }
  }

  if(flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}



Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fi first
#define se second 
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define pp pair<ll,ll> 
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t = 1;
void solve() 
{
	ll n, x;
	cin>>n;
	rep(i,0,n){
		cin>>x;
		if(x%2==0){
			if(x%3!=0 and x%5!=0){
				cout<<"DENIED\n";
				return;
			} 
		}
	}
	cout<<"APPROVED\n";
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cin >> t ;
    while(t--){
        solve();
    }
    return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end() 
#define MOD 1000000007
#define N 100005
#define pll pair<ll,ll>
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));


void solve()
{ 
     ll n;
     cin >> n;
     while(n>0)
     {
          ll temp = n%10;
          if(temp==7)
          {
               cout<<"Yes\n";
               return;
          }
          n/=10;
     }
     cout<<"No\n";
}

int main()
{
     FAST;
     ll t = 1;
  ///   cin >> t;
     while(t--)
     {     
          solve();
     }
}

Measured memory_bytes: 3648
# Longest Increasing Subsequence
import bisect

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))


# def dfs(i, j):
#     if i == n:
#         return 0
#     if j < a[i]:
#         return 1 + dfs(i+1, a[i])
#     else:
#         return max(dfs(i+1, j), dfs(i+1, a[i]))
#
# print(dfs(i, -1))


L = [a[0]]
for x in a[1:]:
    if L[-1] < x:
        L.append(x)
    else:
        j = bisect.bisect_left(L, x)
        L[j] = x

print(len(L))

Measured memory_bytes: 11136
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

int dp[10005];
int need[10]{0,2,5,5,4,5,6,3,7,6};

void solve() {
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++) {
    dp[i] = -1;
  }
  vector<int> can;
  {
    int m;
    cin >> m;
    can.resize(m);
    for(int i = 0; i < m; i++) cin >> can[i];
    sort(can.begin(), can.end());
    reverse(can.begin(), can.end());
  }
  for(int i = 0; i <= n; i++) {
    if(dp[i] < 0) continue;
    for(int out: can) {
      if(i + need[out] <= n) {
        dp[i+need[out]] = max(dp[i+need[out]], 1 + dp[i]);
      }
    }
  }
  int curr = n;
  while(curr) {
    for(int out: can) {
      if(need[out] > curr) continue;
      if(dp[curr-need[out]]+1 == dp[curr]) {
        cout << out;
        curr -= need[out];
        break;
      }
    }
  }
  cout << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
cnt = 0

for j in range(1, n-1):
  if p[j-1] < p[j] and p[j] < p[j+1]:
    cnt += 1
  elif p[j-1] > p[j] and p[j] > p[j+1]:
    cnt += 1

print(cnt)

Measured memory_bytes: 3060
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n, i;
  scanf("%d", &n);
  vector<int> vec(n);
  for (i=0; i<n; i++) {
    scanf("%d", &vec[i]);
  }
  reverse(vec.begin(), vec.end());
  for (i=0; i<n-1; i++) printf("%d ", vec[i]);
  printf("%d\n", vec[i]);
}


Measured memory_bytes: 2760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int R;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> R;
  if (R < 1200) {
    cout << "ABC" << endl;
  } else if (R < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }

  return 0;
}

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

const int M=1e5+5;
char s[M];

int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	scanf("%s",s);
	int i=0,j;
	int cntl=0,cntr=0;
	while(i<n)
	{
		j=i;
		while(j<n&&s[i]==s[j])
			j++;
		if(s[i]=='L') cntl++;
		else cntr++;
		i=j;
	}
	int cnt=min(k,min(cntl,cntr));
	int ans=(cntl-cnt)+(cntr-cnt);
	if(!ans) ans++;
	printf("%d\n",n-ans);
	return 0;
}

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

int main(void) {
  string s;
  int count;
  int flag;
  count = 0;
  while(cin >> s) {
    flag = 0;
    for(int i = 0; i < s.length()/2; i++) {
      if(s[i] != s[s.length()-1-i]) {
	flag = 1;
	break;
      }
    }
    if(flag == 0) count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














ll N, A, B;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> A >> B;

	ll len = A + B;
	ll ans = (N / len) * A + min(A, N % len);

	cout << ans << endl;
}







Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

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

    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) { cin >> A[i]; }

    ll sum = 0;
    vector<bool> B(N, false);
    if (A[0] != 0) {
        cout << -1 << endl;
        return 0;
    }

    rep(i, N - 1) {
        if (A[i + 1] > A[i] + 1) {
            cout << -1 << endl;
            return 0;
        }
        if (A[i + 1] - A[i] == 1)
            B[i + 1] = true, sum++;
    }

    rep(i, N) {
        if (!B[i])
            sum += A[i];
    }

    cout << sum << endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	string s;
	cin >> s;

	int n = s.size();
	vector<vector<ll>> dp(n+1,vector<ll>(4,0));
	dp[0][0] = 1;

	for(int i = 0;i < n;i++){
		for(int j = 0;j < 4;j++){
			dp[i+1][j] += dp[i][j] * (s[i] == '?' ? 3LL : 1LL);
			dp[i+1][j] %= MOD;
		}
		if(s[i] == 'A' || s[i] == '?'){
			dp[i+1][1] += dp[i][0];
			dp[i+1][1] %= MOD;
		}
		if(s[i] == 'B' || s[i] == '?'){
			dp[i+1][2] += dp[i][1];
			dp[i+1][2] %= MOD;
		}
		if(s[i] == 'C' || s[i] == '?'){
			dp[i+1][3] += dp[i][2];
			dp[i+1][3] %= MOD;
		}
	}

	cout << dp[n][3] << endl;
}


Measured memory_bytes: 7424
import sys
def input(): return sys.stdin.readline().strip()


def main():
    n, m = map(int, input().split())
    if n == 1 and m == 1: ans = 1
    elif m == 1: ans = n - 2
    elif n == 1: ans = m - 2
    else: ans = (m - 2) * (n - 2)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61724
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>


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

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353LL;

using namespace std;
typedef long long ll;


using Tp = tuple<int, int, int>;
vector<Tp> update;
vector<vector<int>> dp;
vector<int> mx;
int allmax;
void st(int i, int j, int k) {
	update.emplace_back(i, j, k);
	update.emplace_back(j, i, k);
}

void upd() {
	for (auto [a, b, c] : update) {
		chmax(dp[a][b], c);
		chmax(mx[a], c);
		chmax(allmax, c);
	}
	update.clear();
}
int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n; cin >> n;
	vector<int> a(n * 3); for (int i = 0; i < n * 3; i++) cin >> a[i], a[i]--;
	dp.assign(n, vector<int>(n, -1));
	mx.assign(n, -1);
	dp[a[0]][a[1]] = dp[a[1]][a[0]] = mx[a[0]] = mx[a[1]] = 0;
	int pl = 0;
	for (int i = 2; i + 2 < 3 * n; i += 3) {
		if (a[i] == a[i + 1] and a[i + 1] == a[i + 2]) {
			pl++;
			continue;
		}
		for (int kkt = 0; kkt < 3; kkt++) {
			vector<int> v;
			int r = a[i + kkt];
			for (int j = 0; j < 3; j++) if (j != kkt) v.emplace_back(a[i + j]); 
			st(v[0], v[1], max(allmax, dp[r][r] + 1));
			if (v[0] == v[1]) {
				for (int j = 0; j < n; j++) if (dp[v[0]][j] != -1) st(r, j, dp[v[0]][j] + 1);
			}
			for (int j = 0; j < n; j++) st(r, j, mx[j]);
		}
		upd();
	}
	int res = 0; 
	for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {
		if (i == j and i == a.back()) {
			chmax(res, dp[i][j] + 1);
		}
		else {
			chmax(res, dp[i][j]);
		}
	}
	res += pl;
	cout << res << endl;
}


Measured memory_bytes: 19520
#include<iostream>

using namespace std;

int main() {
  string s;
  int ans(0);
  cin >> s;
  s += '.';
  for (int i = 1; i < s.length(); ++i) {
    if (s[i] != s[i-1]) ans++;
  }
  cout << ans - 1 << endl;
  return 0;
}

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

#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int N = 200001;


void solve() {
    int n , m , sum = 0;
    cin >> n >> m;
    int arr[m];
    for(ll i = 0 ; i < m ; i ++) cin >> arr[i] , sum += arr[i];
    if(sum <= n) cout << n - sum;
    else cout << -1;
    
}

/*
 */

int main()
{
    fastio
    int testcase = 1;
    //cin >> testcase ;
    
    while(testcase --) {
        solve();
        cout << '\n';
    }
    
    return 0;
}
 



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

vector<vector<int>> G;
int n,m;
vector<int> h;

int main(){
    cin>>n>>m;
    h.resize(n);
    G.resize(n);
    rep(i,n) cin>>h[i];
    for (int i=0;i<m;i++){
        int a,b;cin>>a>>b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    int ans = 0;
    rep(i,n){
        bool f = true;
        for (int x:G[i]){
            if (h[i]<=h[x]) f=false;
        }
        if (f) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 11884
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
	while(true){
	int to=1,so=2,ea=3,no=5,we=4,be=6;
	int n;string s;int ans=1;
	scanf("%d",&n);
	if(n==0)return 0;
	for(int i=0;i<n;i++){
		cin >> s;
		if(s=="North"){
			int to1=so;int so1=be;int be1=no;int no1=to;
			to=to1,so=so1,be=be1,no=no1;
		}
		if(s=="East"){
			int to1=we;int we1=be;int be1=ea;int ea1=to;
			to=to1,we=we1,be=be1,ea=ea1;
		}
		if(s=="West"){
			int to1=ea;int ea1=be;int be1=we;int we1=to;
			to=to1,ea=ea1,be=be1,we=we1;
		}
		if(s=="South"){
			int to1=no;int no1=be;int be1=so;int so1=to;
			to=to1,no=no1,be=be1,so=so1;
		}
		if(s=="Right"){
			int so1=ea;int ea1=no;int no1=we;int we1=so;
			so=so1,ea=ea1,no=no1,we=we1;
		}
		if(s=="Left"){
			int so1=we;int ea1=so;int no1=ea;int we1=no;
			so=so1,ea=ea1,no=no1,we=we1;
		}
		ans+=to;
	}
	printf("%d\n",ans);
	}
}

Measured memory_bytes: 1248
import heapq

def main():
    _, k, q = map(int, input().split())
    a = list(map(int, input().split()))
    idx = make_index(a)
    groups = [(0, len(a))]

    m = float('inf')
    for y in sorted(set(a)):
        xs = []
        for start, stop in groups:
            xs.extend(nsmallest(stop - start - k + 1, a, start, stop))

        if len(xs) < q:
            break

        xxs = heapq.nsmallest(q, xs)
        x = xxs[-1]
        m = min(m, x - y)

        groups = split_groups(idx[y], groups, k)

    print(m)

MEMO = dict()
def nsmallest(n, a, start, stop):
    global MEMO
    key = (n, id(a), start, stop)
    if key in MEMO:
        return MEMO[key]

    val = heapq.nsmallest(n, a[start:stop])
    MEMO[key] = val
    return val

def split_groups(pivots, groups, k):
    gs = []

    i = 0
    for start, stop in groups:
        while i < len(pivots) and pivots[i] < start:
            i += 1
        while i < len(pivots) and pivots[i] <= stop:
            if pivots[i] - start >= k:
                gs.append((start, pivots[i]))
            start = pivots[i] + 1
            i += 1

        if stop - start >= k:
            gs.append((start, stop))

    return gs


def make_index(a):
    idx = dict()

    for i, x in enumerate(a):
        if x in idx:
            idx[x].append(i)
        else:
            idx[x] = [i]

    return idx

main()


Measured memory_bytes: 12404
#include<stdio.h>
int main()
{
	int a,b,m;
	int a1,b1;
	scanf("%d%d",&a,&b);
	int i;
	m=(a+b);
	for(i=m;i<=1250;i++)
	{
		a1=i*0.08;
		b1=i*0.1;
		if(a1==a&&b1==b)
		{
			printf("%d\n",i);
			break;
		}
	}
	if(i==1251)
	{
		printf("-1\n");
	}
	return 0;
}

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

bool agree(vector<int>p ,vector<int> q){
  int p_size=p.size();
  int q_size=q.size();
  if(p_size!=q.size()) return 0;
  else{
    for(int i=0; i<p_size; i++){
      if(p[i]!=q[i]) return 0;
    }
  }
  return 1;
}

int main(){
  int n;
  cin >> n;
  vector<int> m(n);
  vector<int> m2(n);
  for(int i=1; i<=n; i++){
    m[i-1]=i;
    m2[i-1]=i;
  }
  
  int p=0;
  int q=0;
  vector<int> pin(n);
  vector<int> qin(n);
  for(int i=0; i<n; i++) cin >>pin[i];
  for(int i=0; i<n; i++) cin >>qin[i];
  do{
    p++;
    if(agree(m,pin)) break;
  }while(next_permutation(m.begin(),m.end()));
  do{
    q++;
    if(agree(m2,qin)) break;
  }while(next_permutation(m2.begin(),m2.end()));   
  cout << abs(p-q) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N, K;
	cin >> N >> K;
	int H[100200];
	rep(i, N) cin >> H[i];

	int dp[100200];
	rep1(i, N) dp[i] = 1e9;
	dp[0] = 0;
	rep(i, N) {
		rep1(j, K) dp[i + j] = min(dp[i + j], dp[i] + abs(H[i] - H[i + j]));
	}
	co(dp[N - 1]);

	Would you please return 0;
}

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

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	vector<int> b(n - 1);
	rep(i, n - 1) cin >> b[i];

	int ans = b.front() + b.back();
	for (int i = 1; i < n - 1; ++i) {
		ans += min(b[i - 1], b[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 1003;
const int MAX_M = 1003;

int a[MAX_N][MAX_N];
int dp[MAX_M][MAX_N][3];
int m,n,K;

int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d",&K);
	rep(i,n){
		string s;
		cin >> s;
		rep(j,m){
			if(s[j] == 'J'){
				a[i][j] = 0;
			}else if(s[j] == 'O'){
				a[i][j] = 1;
			}else{
				a[i][j] = 2;
			}
		}
	}
	rep(i,n+1){
		rep(k,3){
			dp[i][0][k] = 0;
		}
	}
	rep(j,m+1){
		rep(k,3){
			dp[0][j][k] = 0;
		}
	}
	rep(i,n){
		rep(j,m){
			rep(k,3){
				dp[i+1][j+1][k] = dp[i][j+1][k] + dp[i+1][j][k] - dp[i][j][k];
				if(a[i][j] == k){
					dp[i+1][j+1][k]++;
				}
			}
		}
	}
	rep(i,K){
		int p,q,r,s;
		scanf("%d%d%d%d",&p,&q,&r,&s);
		int res[3];
		rep(j,3){
			res[j] = dp[r][s][j] - dp[p-1][s][j] - dp[r][q-1][j] + dp[p-1][q-1][j];
		}
		printf("%d %d %d\n",res[0],res[1],res[2]);
	}
	return 0;
}

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

//#define DEBUG

using namespace std;

template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}


void solve(){
    uint32_t N ;
    cin >> N;
    std::vector<uint32_t> A;
    std::unordered_set<uint32_t> S;
    for(uint32_t i = 0 ; i < N ; i++){
        uint32_t a;
        cin >> a;
        A.push_back(a);
    }
    std::sort(A.begin(), A.end());
    if( N == 1){
        cout << 1 << endl;
        return;
    }
    uint32_t count = 0;
    if( A[0] == 1){
        if( A[1] > 1){
            cout << 1 << endl;
            return;
        }else{
            cout << 0 << endl;
            return;
        }
    }else{
        for(uint32_t i = 0 ; i < N ; i++){
            if( S.find(A[i]) != S.end() ){
                continue;
            }else{
                for(uint32_t k = 1 ; k <= 1000000 / A[i]; k++){
                    S.insert(k * A[i]);
                }
                if( i == N - 1 || A[i] != A[i+1]){
                    count++;
                }
            }
        }

    }
    //cout << "last found " << found_last << endl;
    cout << count << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 3;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


Measured memory_bytes: 42868
from collections import deque
n,m = map(int, input().split())

g = [[] for i in range(n)]
for i in range(m):
  a, b = map(int, input().split())
  g[a-1].append(b-1)
  g[b-1].append(a-1)
v = [-1 for i in range(n)]
ans = []
for i in range(n):
  if v[i]!=-1:
    continue
  v[i]=0
  an=1
  d = deque([i])
  while len(d):
    x = d.popleft()
    for i in g[x]:
      if v[i] == -1:
        d.append(i)
        v[i]=0
        an+=1
  ans.append(an)
print(len(ans)-1)

Measured memory_bytes: 86944
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <stack>
using namespace std;
#define ll int64_t
const long mod = 1e9 + 7;


const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


std::vector<long > l(10);
long n;
long A, B, C;
long maxv = 100000;


long dfs(long a, long b, long c, long v, long ad) {
  long val = 0;

  long ret1, ret2, ret3, ret4;
  // cerr << " a :" <<a << "  b :"<<b << "  c:"<<endl;

  if (v < n) {
    long ad_ = ad;
    ret1 = dfs(a, b, c, v + 1, ad_);

    ad_ = (a > 0) ? ad + 10 : ad + 0;
    ret2 = dfs(a + l[v], b, c, v + 1, ad_);

    ad_ = (b > 0) ? ad + 10 : ad + 0;
    if (b>0)ad_ = ad + 10;
    ret3 = dfs(a, b + l[v], c, v + 1, ad_);

    ad_ = (c > 0) ? ad + 10 : ad + 0;
    ret4 = dfs(a, b, c + l[v], v + 1, ad_);


    // ret1 = dfs(a, b, c, v + 1, 0);
    // ret2 = dfs(a + l[v], b, c, v + 1, ad_) + 10;
    // ret3 = dfs(a, b + l[v], c, v + 1, ad_) + 10;
    // ret4 = dfs(a, b, c + l[v], v + 1, ad_) + 10;

    val = min(min(ret1, ret2), min(ret3, ret4));
  } else {
    if (a == 0 || b == 0 || c == 0) {
      return LINF;
    }
    // val = abs(A - a) + abs(B - b) + abs(C - c) + ad - 30;
    val = abs(A - a) + abs(B - b) + abs(C - c) + ad;


  }


  return val;
}



int main() {

  cin >> n >> A >> B >> C;

  for (int i = 0; i < n; ++i) {
    cin >> l[i];
  }

  double ans = 0;

  ans =  dfs(0, 0, 0, 0, 0);


  cout << ans;

}




















Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class ATransfer {
public:
    static constexpr int kStressIterations = 0;
    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int A, B, C;
        cin >> A >> B >> C;
        int r = A - B;
        cout << max(C - r, 0LL) << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ATransfer solver;
    solver.solve(in, out);
    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int a,b,c;

int main(){
	cin.sync_with_stdio(false);
	cin>>a>>b>>c;
	if(a<b&&b<c)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int a[110][110];

int main() {
    int H, W, N;
    cin >> H >> W >> N;
    int r = 0, c = 0;

    rep(i, N) {
        int x;
        cin >> x;
        while (x) {
            a[r][c] = i;
            if (r % 2 == 0) {
                ++c;
            } else {
                --c;
            }
            if (c == W) {
                r++;
                c = W - 1;
            }
            if (c == -1) {
                r++;
                c = 0;
            }
            --x;
        }
    }

    rep(i, H) {
        rep(j, W) { cout << a[i][j] + 1 << ' '; }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.rbegin(),a.rend());
    int now = 0;
    int ans1 = -1,ans2 = -1;
    rep(i,n-1){
        if(a[i] == a[i+1] && now == 0){
            ans1 = a[i];
            i++;
            now++;
        }
        else if(a[i] == a[i+1] && now == 1){
            ans2 = a[i];
            break;
        }
    }
    if(ans1 == -1 || ans2 == -1) cout << 0 << endl;
    else cout << (ll)ans1*ans2 << endl;
}



Measured memory_bytes: 640
/* nothing is impossible */
#pragma comment(linker, "/stack:227420978")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h> 
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef double ld;
typedef string st;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
const ll MOD = 1e9 + 7 ;
const ll INF=1e14;                                                                                                 
ll mpow(ll a,ll b,ll p=MOD){a=a%p;ll res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}             

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 // freopen("input.txt", "r", stdin);
  ll n;
  cin>>n;
  ll i,j;
  bool f=false;
  for(i=0;i<104;i++)
  {
    for(j=0;j<104;j++)
    {
      if(i*4+7*j==n)
      {
        f=true;
        break;
      }
    }
    if(f) break;
  }
  if(f)
  {
    //if(i==0||j==0||i>2&&j>2) cout<<"YES";
    //else 
      cout<<"Yes";
  }
  else cout<<"No";
return 0;
}         

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    ll D;
    cin >> D;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    int Q;
    cin >> Q;
    vector<int> B(Q);
    rep(i, Q) cin >> B[i], B[i]--;
    
    vector<ll> P(N + 1);
    P[0] = D;
    rep(i, N){
        P[i + 1] = min(P[i], abs(P[i] - A[i]));
    }
    
    vector<ll> pos(N + 1, 0);
    pos[N] = 0;
    
    ll p = 0;
    for(int i = N - 1; i >= 0; i--){
        if(p * 2 + 1 >= A[i]){
            p += A[i];
            pos[i] = p;
        }
        else{
            pos[i] = p;
        }
    }
    
    
    rep(i, Q){
        if(pos[B[i] + 1] >= P[B[i]]){
            output("NO");
        }
        else{
            output("YES");
        }
    }

    return 0;
}


Measured memory_bytes: 15616
"use strict";

const receive = () => require("fs").readFileSync("/dev/stdin", "utf8").split(/\s/);

const main = input => {
  const [A, B, X] = input.map(x => Number(x));
  const ans = (X - A <= B) && (A <= X) ? "YES" : "NO";
  console.log(ans);
};

main(receive());


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

int main(){
    int N,alice=0,bob=0;
    cin >> N;
    vector<int> card(N);
    for (int i=0;i<N;i++) cin >> card.at(i);
    sort(card.begin(),card.end());
    reverse(card.begin(),card.end());
    for (int i=0;i<N;i++) {
        if((i==0 )|| (i% 2==0)){
            alice += card.at(i);
        }else{
            bob += card.at(i);
        }
    }
    cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lg long long int
#define loop(i,s,e) for(lg i=s;i<=e;i++)
#define iloop(i,s,e) for(lg i=e;i>=s;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007


using namespace std;

lg min(lg a,lg b)
{return a<b?a:b;}
lg max(lg a,lg b)
{return a>b?a:b;}
lg lcm(lg a ,lg b)
{
    return (a*b)/__gcd(a,b);
}
lg n,m,k,ans;
int main()
{
    char ap;
    cin>>ap;
    if(ap<96) cout<<"A"<<endl;
    else cout<<"a"<<endl;

}


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

using namespace std;

int main(){

	int a, b;
	int sum=0;

	cin>> a >> b;

	for(int i=a;i<=b;i++){
		if(i/10000==i%10 && (i/1000)%10==(i%100)/10) sum++;
	}

	cout<< sum << endl;


}
/*
struct xxxx{
	int x;
	int y;
	int num;

	bool operator<(const xxxx &in) const{
		return num<in.num;
	};
};
*/

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

using namespace std;

int main()
{
   
   int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  
  if((a+b)==(c+d))
      printf("Balanced");
  
  else if((a+b)>(c+d))
       printf("Left");
  
  else
    printf("Right");
  
  
}

Measured memory_bytes: 256
Public Class Program
  Shared Sub Main()
    Dim xa As Integer() = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
    Dim x As Integer = xa(0)
    Dim a As Integer = xa(1)
    If x < a Then
      Console.WriteLine("0")
    Else
      Console.WriteLine("10")
    End If
  End Sub
End Class

Measured memory_bytes: 11092
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(1)
	s = sys.stdin.readline().rstrip()
	t = sys.stdin.readline().rstrip()
	ans = 0
	for i in range(len(s)):
		ans += s[i] != t[i]
	print(ans)

	


main()

Measured memory_bytes: 69932
//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define    MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define    for0(i,n) for(int i=0;i<n;i++)
#define    forn(i,n) for(int i=1;i<=n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    Sort(s) sort(s.begin(),s.end())
#define    gcd(a, b) __gcd(a , b)
#define    lcm(a,b) (a*(b/__gcd(a,b)))
#define    nl     "\n"
#define    End    return 0 
#define    gt     greater<int>()
#define    ll     long long 
#define    mp     make_pair
#define    pb     push_back
#define    vi     vector<int>
#define    vl     vector<ll>
#define    mod    1000000007
#define    sp(n)  fixed<<setprecision(n)
#define    pi     acos(-1)

int main()
{
MP;
    
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(1)
    {
        c-=b;
        if(c<=0){
            cout<<"Yes";End;
        }
        a-=d;
        if(a<=0){
            cout<<"No";End;
        }
    }

End;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define S set<int>
#define pb(v) push_back(v)
int calu(int N){
    int ans = 0;
    while(N%2==0){
        N/=2;
        ans++;
   }
    return ans;
}
int main(){
    CIN(N);
    int ans = 0;
    int f = 0;
    FOR(a,1,N+1){
        int b = calu(a);
        if(b >= ans){
            ans = b;
            f = a;
        }
    }
    COUT(f);
    return 0;
}


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

int main(){

    int a[5];
    int b[5];
    int sum = 0;
    int c[5];

    for (int i = 0; i < 5; i++){
        cin >> a[i];

        b[i] = a[i] % 10;
        c[i] = a[i] / 10;
    }    

    for (int j = 0; j < 5; j++){
        
        if (b[j] == 0){

            sum += c[j] * 10;
        }else {

            sum += c[j] * 10 + 10;
        }

    }

    int min = b[0];
    
    for (int k = 1; k < 5; k++) {

        if (b[k] < min && b[k] != 0) {
            min = b[k];
        }
    }

    if (min != 0) {
        sum -= (10 - min);
    }

    cout << sum << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define M 1000000007
#define f(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define primeDEN 727999983
 
using namespace std;

bool check(string s,string p)
{
    for(int i=0;i<s.size()-p.size();i++)
    {
        if(s.substr(i,p.size())==p)return true;   
    }
    return false;
}


int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;cin>>s;
    string p;cin>>p;
  int cnt=0;
	f(i,0,s.size())
    {
      if(s[i]!=p[i])cnt++;
    }
  cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3796
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;

int main() {
	int n;
	int sum = 0;
	int ans = 0;
	cin >> n;
	vector<int> a(n + 1),b(n+1),c(n+1);
	for (int i = 1; i < n + 1; i++) {
		cin >> a.at(i);
	}
	for (int i = n; i > 0; i--) {
		
		for (int j = 1; j * i < n + 1; j++) {
			sum += b.at(j * i);
		}
		if (sum % 2 == a.at(i)) b.at(i)=0;
		else {
			b.at(i)=1;
			ans++;
			c.at(ans-1) = i;
		}
		sum = 0;
	}
	
	cout << ans << endl;
	for (int i = 0; i < ans-1; i++) {
		cout << c.at(i) << " ";
	//	f = 1;
	}
	if (ans>=1)cout << c.at(ans - 1) << endl;
	return 0;

	
}

Measured memory_bytes: 5616