akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define MAX 105
#define int long long int
int power(int a,int  n,int m)
{
    int res=1;
    while(n)
    {
        if(n&1)
        {
            res = ((res%m)*(a%m))%m;
            n--;
        }
        else
        {
            n/=2;
            a = ((a%m)*(a%m))%m;
        }
    }
    return res;
}
const int m = 1000000007;
int modInverse(int a, int m)
{
    int m0 = m;
    int y = 0, x = 1;
  
    if (m == 1)
      return 0;
  
    while (a > 1)
    {
        // q is quotient
        int q = a / m;
        int t = m;
  
        // m is remainder now, process same as
        // Euclid's algo
        m = a % m, a = t;
        t = y;
  
        // Update y and x
        y = x - q * y;
        x = t;
    }
  
    // Make x positive
    if (x < 0)
       x += m0;
  
    return x;
}

void solve()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0 ; i < n ; i++)
        cin >> a[i];
    int temp1 = 0;
    for(auto it: a)
    {
        temp1  = ((temp1%m)+(it%m))%m;
    }
    temp1 = power(temp1,2,m)%m;
    int temp2=0;
    for(int i = 0 ; i < n ; i++)
    {
        a[i] = power(a[i],2,m)%m;
    }
    for(int i = 0 ; i < n ; i++)
    {
        temp2  = ((temp2%m)+(a[i]%m))%m;
    }
    if(temp1<temp2)
    {
        temp1+=m;
    }
    int ans = (temp1-temp2)%m;
    
    int ans2 = modInverse(2,m);
    
    ans =((ans%m)*(ans2%m))% m;
    cout << ans;
    
    return;
}

int32_t main()
{
    int T = 1;
    //cin >> T;
    for(int i = 1 ; i <= T ; i++)
        solve();
    
    return 0;
}
/*
 AtCoder after Google Online Challenge Fail:(
 */


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

int main() {
  vector<int> a(5);
  int k;
  for (int i=0;i<5;i++){
    cin>>a.at(i);
  }
  cin>>k;
  string ret="Yay!";
  for (int i=0;i<5;i++){
    for (int j=0;j<5;j++){
    if(abs(a.at(j)-a.at(i))>k){
      ret=":(";
      break;}
  }
  }
  cout<<ret<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;


/*
           1) long long vs int overflow
           2) read question carefully
*/

#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define umapii unordered_map < int , int >
#define umapll unordered_map<ll,ll>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vs vector<string>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define all(v) (v).begin(),(v).end()
#define FOR(i,a,b) for(int i = a;i <= b; i++)

#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

const ll mod = 1000000007;
/*STL:
       (1) PRIORITY_QUEUE pq:
       -> priority_queue < int > pq; // max_heap
       -> priority_queue < int , vector < int > , greater < int > > pq; // max_heap 
       -> pq.top()   --> returns the maximum or maximum element
       -> pq.push()  --> push element into the queue
       -> pq.pop()   --> remove top most element
       -> pq.empty() --> checks whether queue is empty or not



*/
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
}

const int inf = 1e9 + 7;
const  int N= 1e5+7;
int dp[N][3];
int main(){
    ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n +1),b(n+1),c(n+1);
    for(int i=1;i<=n;i++) cin>>a[i]>>b[i]>>c[i];
    dp[1][0]=a[1];dp[1][1]=b[1];dp[1][2]=c[1];
    for(int i=1;i<=n;i++){
        if(i+1>n) break;
        dp[i+1][0]=max(dp[i][1],dp[i][2])+a[i+1];
        dp[i+1][1]=max(dp[i][0],dp[i][2])+b[i+1];
        dp[i+1][2]=max(dp[i][0],dp[i][1])+c[i+1];
    }
    cout<<max({dp[n][0],dp[n][1],dp[n][2]})<<'\n';
}

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

int main(){
    int n;
    cin >> n;
    vector<int> R(n);
    for(int i=0;i<n;i++){
        cin >> R[i];
    }
    int minv = R[0];
    int maxv = -2000000000;
    for(int i=1;i<n;i++){
        maxv =max(maxv, R[i]-minv);
        minv = min(R[i], minv);
    }
    cout << maxv << endl;
}


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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll H,W;
    string s[26][26];
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> s[i][j];
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if(s[i][j] == "snuke"){
                cout << (char)(j+'A') << i+1 << endl;
            }
        }
    }
}

Measured memory_bytes: 3572
// Nguyen Anh Tu
#include <bits/stdc++.h>
#define FOR(x,a,b) for(int x=a;x<=b;x++)
#define FORD(x,a,b) for(int x=a;x>=b;x--)
#define maxn 100005
#define maxc 1000000007
#define MOD 1000000007
#define reset(x,y) memset(x,y,sizeof(x))
#define task ""
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define pii pair<int,int>
#define ll long long
#define bit(p,x) ((x>>p) & 1)
#define remain(a,b) (a+b >= MOD) ? (a+b - MOD) : (a+b)

using namespace std;
string s;
bool ok1,ok2;
int main()
{
   ios_base::sync_with_stdio(NULL);
   cin.tie(NULL);
   cout.tie(NULL);
    cin >> s;
    for(int i=0; i<=2; ++i) if(s[i] == 'A') ok1 = 1;
    else ok2 = 1;  
    if(ok1 && ok2) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

char s[100010];
int cnt[2];
int main() {
	scanf("%s", s);
	for (int i = 0; s[i] != 0; i++) {
		cnt[s[i] - '0']++;
		swap(cnt[0], cnt[1]);
	}
	printf("%d\n", min(cnt[0], cnt[1]));
}

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, 0);

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    ans[a]++;
    ans[b]++;
  }

  for (int x : ans) {
    cout << x << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
const int mod = 1000000007;
struct mint {
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
mint inv() const {
return pow(mod-2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res/=a;
}
};
mint dp[11000][110][2];
int main(){
    string s;cin >> s;
    int d;cin >> d;
    dp[0][0][1]=1;
    int n=(int)s.size();
    rep(i,n){
        int now=s[i]-'0';
        rep(j,d){
            rep(k,10){
                dp[i+1][(j+k)%d][0]+=dp[i][j][0];
                if(k<now) dp[i+1][(j+k)%d][0]+=dp[i][j][1];
            }
            dp[i+1][(j+now)%d][1]+=dp[i][j][1];
        }
    }
    mint ans=dp[n][0][1]+dp[n][0][0];
    ans-=1;
    cout << ans.x << endl;
    return 0;
}

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

int main(){
    int a,b,c=0,d=-1;
    cin >> a >> b;

    bool g[100][100];
    REP(i,100) REP(j,100) g[i][j] = i<50;
    while(--a>0) d<49 ? g[2*c][2*++d]=0 : g[2*++c][d=0]=0;
    c=26;
    while(--b>0) d<49 ? g[2*c][2*++d]=1 : g[2*++c][d=0]=1;

    cout << "100 100\n";
    REP(i,100){
        REP(j,100) cout << (g[i][j] ? "#" : ".");
        cout << "\n";
    }
}


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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> dp(n+1);
  dp[0] = 1;
  for(int i=0;i<n;i++){
    dp[i+1] = min(dp[i]*2,dp[i]+k);
  }
  cout << dp[n] << endl;
  return 0;
}


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

#ifdef DEBUG
#define debug(...) __VA_ARGS__
#else
#define endl '\n'
#define debug(...)
#endif
#define debugf(...) debug(printf(__VA_ARGS__))

const int N = 1e5 + 5;



int (((((main)))))() <%
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c > 21) cout << "bust" << endl;
    else cout << "win" << endl;

    return 0;
%>

Measured memory_bytes: 3588
s = gets.chomp.split("").sort!
t = gets.chomp.split("").sort.reverse!
s1=""; t1=""
(s.length).times do |i|
  s1 += s[i]
end
(t.length).times do |i|
  t1 += t[i]
end
if s1 < t1 then
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 3836
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <vector>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n;
    cin >>n;
    vector<ll> a(n,0);
    rep(i,0,n) cin >> a[i];

    sort(a.begin(), a.end(), greater<ll>());

    ll al(0), b(0);
    rep(i,0,n) if (i%2 == 0)al+=a[i]; 
    rep(i,0,n) if (i%2 != 0)b+=a[i]; 

    cout << abs(al - b) << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

    static final int[] NS = {1, 4, 8, 9, 16, 25, 27, 32, 36, 49, 64, 81, 100, 121, 125, 128, 144, 169, 196, 216, 225, 243, 256, 289, 324, 343, 361, 400, 441, 484, 512, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1000,};

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int x = sc.nextInt();
        for (int i = NS.length - 1; i >= 0; i--) {
            if (NS[i] <= x) {
                System.out.println(NS[i]);
                return;
            }
        }
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
    }

}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  long long n,A[200000],ans=0,j=0,k=0,x=0,y,z=0;
  cin>>n;
  rep(i,n) cin>>A[i];
  rep(i,n){
    if(i>=1) x=x^A[i-1];
    y=x^A[j];
    while(y==x+A[j]&&j!=n) x+=A[j],j++,y=x^A[j];
    ans+=(j-i)*(j-i+1)/2;
    ans-=(k-i)*(k-i+1)/2;
    k=j;
  }
  cout<<ans;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>

using namespace std;
using ll = long long;

int main() {
  ll N;
  cin >> N;
  string rname;
  while(N) {
    char c = (N-1)%26+'a';
    rname.push_back(c);
    if (c == 'z') N -= 26;
    N/= 26;
  }
  reverse(begin(rname), end(rname));
  cout << rname << endl;
}


Measured memory_bytes: 3572
n=int(input())
e=[0]*(n+1)
for i in range(2,n+1):
    cur=i
    for j in range(2,i+1):
        while cur%j==0:
            e[j]+=1
            cur//=j

def num(m):
    return len(list(filter(lambda x:x>=m-1,e)))

print(num(75)+num(25)*(num(3)-1)+num(15)*(num(5)-1)+num(5)*(num(5)-1)*(num(3)-2)//2)


Measured memory_bytes: 38512
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
 



int main()
{
    fastio
    ll i,j;
    
    ll n,k;
    cin>>n>>k;
    ll a[n];
    
    for(i=0;i<n;i++)
    cin>>a[i];
    
    sort(a,a+n);
    ll res=0;
    
    for(i=0;i<k;i++)
    res+=a[i];
    cout<<res;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int pre[100005];
int main()
{
   	int n , m , c;
  	cin >> n >> m >> c;
  	int b[m];
  	for(int i = 0 ; i < m ; i++)
      cin >> b[i];
  	int a[n][m];
  	int ans = 0;
  	for(int i = 0 ; i < n ; i++)
    {
      	int sm = 0;
		for(int j = 0 ; j < m ; j++){
          	cin >> a[i][j];
      		sm += a[i][j]*b[j];
        }
      	if(sm + c> 0 )
          ans++;
    }
  	cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////


int main() {

	ll M;
	cin >> M;
	cout << 48 - M;

	system("PAUSE");

	

}


Measured memory_bytes: 504
#include <stdio.h>

long long  absu(long long  a){
  if(a > 0){
    return a;
  }
  return -a;
}

int main(void){
  long N,K;
  scanf("%ld%ld",&N,&K);
  long long x[N];
  long number = -1;

  for(int i = 0;i < N;i++){
    scanf("%lld",&x[i]);
  }

  long long min = 9223372036854775807;

  for(int i = 0;i+K-1 < N;i++){
    if(min > absu(x[i])+absu(x[i]-x[i+K-1])){
      min = absu(x[i])+absu(x[i]-x[i+K-1]);
    }
    if(min > absu(x[i+K-1])+absu(x[i]-x[i+K-1])){
      min = absu(x[i+K-1])+absu(x[i]-x[i+K-1]);
    }
  }

  printf("%lld\n",min);

  return 0;
}

Measured memory_bytes: 896
def solve(X, Y, Z, V, E, A):
    dp = [[0.0] * 6001 for _ in range(Y + max(V) + 1)]
    dp[0][0] = 1.0
    for i in range(Y):
        for j in range(5001):
            if dp[i][j] <= 0.0:
                continue
            for k in V:
                t = i + k
                if t > Y:
                    dp[Y][j] += dp[i][j]/X
                elif E[t] == 1:
                    dp[min(Y, t+A[t])][j] += dp[i][j]/X
                else:
                    dp[t][max(0, j+A[t])] += dp[i][j]/X

    s = 0
    for i in range(5001):
        if dp[Y][i] <= 0.0:
            continue
        s += i * dp[Y][i]
    print(int(s))

if __name__ == "__main__":
    import sys

    while True:
        X, Y, Z = map(int, raw_input().split())
        if X | Y | Z == 0:
            sys.exit()
        V = map(int, raw_input().split())
        E = [0] * 100
        A = [0] * 100
        for _ in range(Z):
            n, e, a = map(int, raw_input().split())
            E[n] = e
            if e == 3:
                A[n] = -a
            else:
                A[n] = a
        solve(X, Y, Z, V, E, A)

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

int main()
{
    string s;
    cin >> s;
    bool kaibun = true;
    int N = s.size();
    int c = 0;
    int d = 0;

    for (int i = 0; i < N;i++)
    {
        if(s[i] != s[N-i-1]){
            kaibun = false;
 
        }
    }
    for (int i = 0; i <  (N-1)/2;i++)
    {
        if(s[i] != s[(N-1)/2-i-1]){
            kaibun = false;
 
        }
    }
    for (int i = N;i > (N+1)/2;i--)
    {
        if(s[i-1] != s[(N+1)/2+N-i]){
            kaibun = false;
 
        }
    }
    if(kaibun){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
def f(k):
    import itertools

    N = [[str(i) for i in range(10)]]
    n = 0
    while n < k:
        T = []
        U = [n[0] for n in N[-1]]
        anchor = 0
        for i in range(len(U) - 1):
            if U[i] != U[i + 1]:
                T.append((anchor, i + 1))
                anchor = i + 1
        else:
            T.append((anchor, len(U)))
        M = []
        for i in range(10):
            for d in (-1, 0, 1):
                if 0 <= i + d < len(T):
                    for j in range(*T[i + d]):
                        M.append("{}{}".format(i, N[-1][j]))
        N[-1] = [n for n in N[-1] if not n.startswith("0")]
        n += len(N[-1])
        N.append(M)
    N = list(itertools.chain.from_iterable(N))
    return N[k - 1]


K = int(input())
print(f(K))


Measured memory_bytes: 59660
# coding:utf-8

import sys
from collections import deque, Counter

INF = float('inf')
MOD = 10 ** 9 + 7
dy, dx = (0, -1, 0, 1), (1, 0, -1, 0)

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    S = [SI() for _ in range(n)]

    cnt = {"B_": 0, "_A": 0, "B_A": 0}
    res = 0
    for s in S:
        for i in range(len(s) - 1):
            if s[i: i + 2] == 'AB':
                res += 1

        if s[0] == 'B' and s[-1] == 'A':
            cnt["B_A"] += 1
        elif s[0] == 'B':
            cnt["B_"] += 1
        elif s[-1] == 'A':
            cnt["_A"] += 1

    # print(res, cnt)
    res += min(cnt["B_"], cnt["_A"])
    if max(cnt["B_"], cnt["_A"]) > 0:
        res += cnt["B_A"]
    else:
        res += max(0, cnt["B_A"] - 1)

    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
int main(){
  #define int long long
  int N,count=0;;
  cin>>N;
  vector<int> d(N);
  for(int i=0;i<N;i++){
    cin>>d.at(i);
  }
  sort(d.begin(),d.end());
  for(int i=0;i<N-2;i++){
    for(int j=i+1;j<N-1;j++){
      for(int k=j+1;k<N;k++){
        if(d.at(i)+d.at(j)>d.at(k) && d.at(i)!=d.at(j) && d.at(j)!=d.at(k)){
          count++;
        }
      }
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 3628
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    ll ar[21][21];
    ll n,m,x;
    ll ar2[21],ar3[21];
    ll ans;
    void func(int i,ll sum)
    {
        if(i==n+1)
        {
            int j;
            for(j=1;j<=m;++j)
            {
                if(ar2[j]<x)
                    return;
            }
            ans=min(ans,sum);
            return;
        }
        func(i+1,sum);
        int j;
        for(j=1;j<=m;++j)
        {
            ar2[j]=ar2[j]+ar[i][j];
        }
        func(i+1,sum+ar3[i]);
        for(j=1;j<=m;++j)
        {
            ar2[j]=ar2[j]-ar[i][j];
        }
    }

    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            cin>>n>>m>>x;
            int i,j;
            ans=1e15;
            for(i=1;i<=n;++i)
            {
                cin>>ar3[i];
                for(j=1;j<=m;++j)
                {
                    cin>>ar[i][j];
                }
            }
            func(1,0);
            if(ans==1e15)
                ans=-1;
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ri register int
const long double PI=3.141592653589793238462643383279;
const int N=500005,M=998244353;
int n,i,ans,p,e[N],vis[N];
struct str{
	int a,x;
}a[N],b[N];
bool cmp(str a,str b)
{
	return a.a<b.a;
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)
	{
		scanf("%d",&a[i].a);
		a[i].x=i;
	}
	for(i=1;i<=n;++i)
	{
		scanf("%d",&b[i].a);
		b[i].x=i;
	}
	sort(a+1,a+1+n,cmp);
	sort(b+1,b+1+n,cmp);
	for(i=2;i<=n;++i)
		if(a[i].a<=b[i-1].a)
			ans=-1;
	for(i=1;i<=n;++i)
		if(a[i].a>b[i].a)
			ans=n;
	for(i=1;i<=n;++i)
		e[a[i].x]=b[i].x;
	for(p=1;!vis[p];p=e[p])
	{
		vis[p]=1;
		++ans;
	}
	if(ans<n)
		puts("Yes");
	else
		puts("No");
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main(){
    int n;
    cin>>n;
    vector<ll> a(n),b(n),c(n);
    rep(i,n){
        cin>>a[i];
        a[i]*=-1;
    }
    rep(i,n) cin>>b[i];
    rep(i,n) cin>>c[i];

    sort(all(a));
    sort(all(c));

    ll ans=0;
    rep(i,n){
        ll tmp=c.end()-upper_bound(all(c),b[i]);
        tmp*=a.end()-upper_bound(all(a),-b[i]);
        ans+=tmp;
    }

    cout<<ans<<endl;
}
    




Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
string alp="abcdefghijklmnopqrstuvwxyz";

int main(){
    int Q;
    cin >> Q;
    rep(i,Q){
        ll A,B;
        cin >> A >> B;
        ll C=sqrt(A*B);
        if (C*C==A*B){
            if (A==B){
                cout << C*2-2 << endl;
            }
            else {
                cout << C*2-3 << endl;
            }
        }
        else {
            if(C*(C+1)<A*B){
                cout << C*2-1 << endl;
            }
            else {
                cout << C*2-2 << endl;
            }
        }
    }
}

Measured memory_bytes: 256
n = int(input())
ac,wa,tle,re = 0,0,0,0
for i in range(n):
  s = str(input())
  if s == "AC":
    ac += 1
  elif s == "WA":
    wa += 1
  elif s == "TLE":
    tle += 1
  else:
    re += 1
print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)


Measured memory_bytes: 9140
import java.util.*;
import java.io.*;
public class Main
{
    static int[] ar;
    static int[][] dp;
    public static void main(String[] args) throws Exception{
        BufferedReader bff=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter wff=new PrintWriter(System.out);
        bff.readLine();
        String[] st=bff.readLine().split(" ");
        ar=new int[st.length];
        for(int i=0;i<st.length;i++){
            int k=Integer.parseInt(st[i]);
            ar[i]=k;
        }
        dp=new int[ar.length][2];
        for(int[] aux:dp){
            Arrays.fill(aux,-1);
        }
        int res=Math.min(calcular(ar[0],1,0),calcular(ar[0],1,1));
        wff.println(res);
        wff.flush();
    }

    public static int calcular(int k,int i,int way){
        int res=1;
        if(i<ar.length){
            if(way==-1){
                int aux=ar[i];
                if(aux!=k){
                    if(k-aux>0){
                        res=calcular(aux,i+1,0);
                    }
                    else{
                        res=calcular(aux,i+1,1);
                    }
                }
                else{
                    res=calcular(k,i+1,way);
                }
            }
            else{
                if(dp[i][way]==-1){
                    int aux=ar[i];
                    if(way==0){
                        if(k-aux>=0){
                            res=Math.min(1+calcular(aux,i+1,-1),calcular(aux,i+1,way));
                        }
                        else{
                            res=1+calcular(aux,i+1,-1);
                        }
                    }
                    else{
                        if(k-aux<=0){
                            res=Math.min(1+calcular(aux,i+1,-1),calcular(aux,i+1,way));
                        }
                        else{
                            res=1+calcular(aux,i+1,-1);
                        }
                    }
                    dp[i][way]=res;
                }
                else{
                    res=dp[i][way];
                }
            }
        }
        return res;
    }
}


Measured memory_bytes: 51804
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  for (int i = 0; i < 5; ++i) {
    cin >> n;
    if (n != 0) continue;
    cout << (i + 1) << '\n';
    break;
  }
}


Measured memory_bytes: 3640
#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 n,a[44],b[44],c[44];
int ma,mb;

int dp[44][444][444];

int main(){
	cin.sync_with_stdio(false);
	cin>>n>>ma>>mb;
	rep(i,n)cin>>a[i]>>b[i]>>c[i];
	rep(i,44)rep(j,444)rep(k,444)dp[i][j][k]=INF;
	dp[0][0][0]=0;
	rep(i,n)rep(j,430)rep(k,430){
		minch(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
		minch(dp[i+1][j][k],dp[i][j][k]);
	}
	int res=INF;
	repl(j,1,444)repl(k,1,444){
		if(ma*k==mb*j){
			minch(res,dp[n][j][k]);
		}
	}
	if(res==INF)cout<<-1<<endl;
	else cout<<res<<endl;
	return 0;
}


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

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

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> left(n);
    vector<ll> right(n);
    rp(i,n) cin >> a.at(i);
    left.at(0)=0; right.at(n-1)=0;
    rp(i,n-1){
        left.at(i+1)=gcd(a.at(i),left.at(i));
        right.at(n-2-i)=gcd(a.at(n-1-i),right.at(n-1-i));
    }
    ll ans=0;
    rp(i,n) ans=max(ans,gcd(left.at(i),right.at(i)));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
while True :
    try :
        x1, y1, x2, y2, x3, y3, xp, yp = map(float, input().split())
        
        # 三角形の回転方向で判定する
        # 三角形PAB, PBC, PCAの回転が全て同じならば、
        # 点Pは三角形ABC内に存在する
        # 三角形ABCの回転の方向は、
        # x1(y2 - y3) + x2(y3 - y1) + x3(y1 - y2)
        # の符号で判断できる
        # 正なら左周り、負なら右回り
        
        a = xp * (y1 - y2) + x1 * (y2 - yp) + x2 * (yp - y1)
        b = xp * (y2 - y3) + x2 * (y3 - yp) + x3 * (yp - y2)
        c = xp * (y3 - y1) + x3 * (y1 - yp) + x1 * (yp - y3)
            
        if((a < 0 and b < 0 and c < 0) or (a > 0 and b > 0 and c > 0)) :
            print("YES")
        else :
            print("NO")
            
    except :
        break


Measured memory_bytes: 5592
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
const int MOD = 1000000007;

int main()
{
  int X,A,B;
  cin >> X >> A >> B;
  cout << ((A-B >= 0) ? "delicious" : (X+A-B >= 0 ? "safe" : "dangerous"))<< endl;
  
  return 0;
}



Measured memory_bytes: 256
n = int(input())
an = list(map(int, input().split()))

maxi = 0
humi = 0
maxi = an[0]
for i in range(1, n):
    if an[i] < maxi:
        hu = maxi -an[i]
        humi += hu
    maxi = max(maxi, an[i])

print(humi)

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

#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;

int L[MAX / 2 + 2], R[MAX / 2 + 2];

llong merge(int A[], int n, int left, int mid, int right) {
	int i, j, k;
	llong cnt = 0;
	int n1 = mid - left;
	int n2 = right - mid;
	for (i = 0; i < n1; i++) L[i] = A[left + i];
	for (i = 0; i < n2; i++) R[i] = A[mid + i];
	L[n1] = R[n2] = SENTINEL;
	i = j = 0;
	for (k = left; k < right; k++) {
		if (L[i] <= R[j]) {
			A[k] = L[i++];
		}
		else {
			A[k] = R[j++];
			cnt += n1 - i;
		}
	}
	return cnt;
}

llong mergeSort(int A[], int n, int left, int right) {
	int mid;
	llong v1, v2, v3;
	if (left + 1 < right) {
		mid = (left + right) / 2;
		v1 = mergeSort(A, n, left, mid);
		v2 = mergeSort(A, n, mid, right);
		v3 = merge(A, n, left, mid, right);
		return v1 + v2 + v3;
	}
	else return 0;
}

int main() {
	int A[MAX], n, i;

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

	llong ans = mergeSort(A, n, 0, n);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4640
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int N;
int count(int nokori, string s){
	if(nokori == 0){
		if(atoi(s.c_str()) <= N){
			int c[8] = {};
			for(int i=0; i<s.size(); i++){
				c[s[i]-'0']++;
			}
			if(c[3]>0 && c[5]>0 && c[7]>0) return 1;
			//cout << atoi(s.c_str()) << endl;
		}
		return 0;
	}
	return count(nokori-1,s+'7') + count(nokori-1,s+'5') + count(nokori-1,s+'3');
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	cin >> N;
	int ans = 0;
	for(int i=3; i<=9; i++){
		ans += count(i,"");
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import sys


def gcd(n, m):
    while m:
        n, m = m, n % m
    return n


def lcm(x, y):
    return int((x * y) / gcd(x, y))

for line in sys.stdin:
    l = line.replace('\n', '')
    a, b = l.split()
    a = int(a)
    b = int(b)
    print(gcd(a, b), lcm(a, b))

Measured memory_bytes: 6732
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	string s;
	int abc[26];
	fill(abc,abc+26,0);
	int ans=0;
	
	cin>>s;
	for(int i=0;i<3;i++)
	{
		abc[s[i]-'a']++;
	}
	for(int i=0;i<3;i++)
	{
		if(abc[i]!=1)
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 1234567890

const int maxn = 2e5 + 10;


//initialization here
//

int v[110], w[110];
int dp[110][10005];

//
//initialization finish


// your function is here
//




//
// your function finished



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

	// your code is here
	//
	int n; cin >> n;

	int t[104];
	ll ans = 0;
	rep(i, n)
	{
		cin >> t[i];
		ans += t[i];
	}

	int m; cin >> m;

	int d1,d2;
	rep(i, m)
	{
		cin >> d1 >> d2;
		Print(ans - t[d1-1] + d2);
	}

	//
	// your code finished

	return 0;
}

Measured memory_bytes: 256
a = int(input())
b = list(map(int, input().split()))
b = sorted(b)

def cal(x,y):
  return (x+y)/2

ans = cal(b[0],b[1])

if a >= 3:
  for i in range(a):
    i = i+2
    if i > a-1:
      break
    ans = cal(ans,b[i])
    
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define vint vector<int>
signed main(){
  int N,M,O,P=0,count=0,count2=0;
  str S,W,T;
  cin>>N>>M>>O;
  rep(0,200)if(N*i%M==O)P+=1;
  if(P>1)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    int total = sc.nextInt();
    int x = -1;
    int y = -1;
    int z = -1;
    for(int i = 0; i <= number; i++) {
      for(int j = 0; (i + j) <= number; j++) {
          int k = number - i - j;
          if((1000 * i + 5000 * j + 10000 * k) == total) {
            x = i;
            y = j;
            z = k;
          } 
      }
    }
    System.out.println(z + " " + y + " " + x);
    
  }
}

Measured memory_bytes: 23764
import math
n = int(input())
total = 0
towns = []
for _ in range(n):
    x, y = map(int, input().split())
    for t in towns:
        total += math.sqrt( (t[0]-x)**2 + (t[1]-y)**2 )
    towns.append([x,y])

print(total*2/n)


Measured memory_bytes: 3060
#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 n;
	cin >> n;
	vi cnt(n + 1);
	for(int i = 0; i < n - 1; i++) {
		int t;
		cin >> t;
		cnt[t]++;
	}
	for(int i = 1; i <= n; i++) cout << cnt[i] << endl;
	
}





Measured memory_bytes: 3988
import sys
readline = sys.stdin.readline
import math

def main():
    A, B, H, M = map(int, readline().rstrip().split())
    rad_b = M / 60 * 360
    rad_a = H / 12 * 360 + 30 * (M / 60)
    rad_diff = min(rad_a - rad_b, 360 - (rad_a - rad_b))
    res = A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(rad_diff))
    print(math.sqrt(res))


if __name__ == '__main__':
    main()

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

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

#define LL long long
#define Ldouble long double
#define PI 3.14159265358979323846264338327950288419

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int n, ans, s[500005], dp[500005][4], p;
char str[500005];

void eval(){
//	FI(i, 1, p) printf("%d%c", s[i], i == p ? '\n':' ');
	FI(i, 0, p) FI(j, 0, 3) dp[i][j] = 0;
	FI(i, 1, p){
		//0: unscathed
		//1: one gone, used by front
		//2: all gone, use front
		//3: all gone, use back
		dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2]));
		dp[i][1] = dp[i - 1][3];
		if(i > 1){
			if(s[i - 1] > 1){
				dp[i][2] = dp[i - 1][1] + s[i];
				dp[i][2] = max(dp[i][2], dp[i - 1][2] + s[i] - 1);
			}
			dp[i][2] = max(dp[i][2], dp[i - 1][0] + s[i]);
		}
		if(i < p){
			dp[i][3] = s[i] + max(max(dp[i - 1][0], dp[i - 1][1]), max(dp[i - 1][2], dp[i - 1][3] - 1));
		}
	//	printf("%d: %d %d %d %d\n", i, dp[i][0], dp[i][1], dp[i][2], dp[i][3]);
	}
	int best = 0;
	FI(i, 0, 3) best = max(best, dp[p][i]);
	ans += best;
	//printf("best = %d\n", best);
	p = 0;
	return;
}

void solve(){
	ans = 0;
	int mode = 0, cur = 0;
	FI(i, 1, n){
		if(str[i] == '0'){
			if(mode == 0) continue;
			else if(mode == 1){
				//already one zero
				eval();
				mode = 0;
			}
			else if(mode == 2){
				//no zeroes yet
				s[++p] = cur;
				cur = 0;
				mode = 1;
			}
		}
		else{
			if(mode <= 1){
				cur = 1;
				mode = 2;
			}
			else cur++;
		}
	}
	if(cur) s[++p] = cur;
	eval();
	printf("%d\n", ans);
}

int main(){
	scanf("%d %s", &n, str + 1);
	solve();
	return 0;
}


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

typedef struct{
  int k;
  int lh;
  int rh;
}Node;

void buildMaxHeap(Node *);
void maxHeapify(Node *,int);

int heap;

int main(){
  int i,n;
  Node *node;

  scanf("%d",&n);

  heap = n;
  
  node = (Node *)malloc(sizeof(Node) * n+1);

  
  for(i = 1 ; i < n+1 ; i++){
    scanf("%d",&node[i].k);
  }


  for(i = 1 ; i < n+1 ; i++){
     
    node[i].lh = 2 * i;
    node[i].rh = 2 * i + 1;     
  }


  buildMaxHeap(node);
  
  for(i = 1 ; i < n+1 ; i++) printf(" %d",node[i].k);

  printf("\n");


  return 0;
}


void buildMaxHeap(Node *node){
  int i;
  for(i = heap/2 ; i >= 1 ; i--){
 
    maxHeapify(node,i);
  }
}

void maxHeapify(Node *node,int i){
  int l,r,largest,s;

  l = node[i].lh;
  r = node[i].rh;

  if(l <= heap  && node[l].k > node[i].k)
    largest = l;

  else
    largest = i;

  if(r <= heap  && node[r].k > node[largest].k)
    largest = r;


  if(largest != i){
    s = node[i].k;
    node[i].k = node[largest].k;
    node[largest].k = s;
    maxHeapify(node,largest);
  }
}
    

Measured memory_bytes: 6460
from collections import Counter

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

dic = dict(Counter(A))
ls = list(dic.items())
ls.sort(key=lambda x: x[1])

i=0
ans=0
res=len(ls)
while 1:
  if res <= K or i >= N:
    break
  ans += ls[i][1]
  i+=1
  res-=1
print(ans)

Measured memory_bytes: 160228
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        mut x: [i64; m],
    }

    x.sort();

    let mut ds = vec![];
    for i in 0..m - 1 {
        ds.push(x[i + 1] - x[i]);
    }
    ds.sort();

    let ans = if n >= m {
        0
    } else {
        ds[0..(m - n)].iter().sum::<i64>()
    };

    println!("{}", ans);
}


Measured memory_bytes: 6396
n = gets.to_i
as = gets.split.map(&:to_i)

ls = Array.new(n+2, 0)
rs = Array.new(n+2, 0)

1.upto(n) do |i|
  ls[i] = ls[i-1].gcd(as[i-1])
end
n.downto(1) do |i|
  rs[i] = rs[i+1].gcd(as[i-1])
end

result = rs.map.with_index do |r, i|
  case i
  when 0, 1 then 1
  when 2 then r
  when rs.size-1 then ls[i-2]
  else
    r.gcd(ls[i-2])
  end
end.max
puts result


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

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

const int MOD = 1e9+7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vi c(1);
    cin >> c[0];
    int j=0;
    for (int i=1; i<n; ++i) {
        int cnew;
        cin >> cnew;
        if (cnew != c[j]) {
            c.push_back(cnew);
            ++j;
        }
    }
    n = c.size();
    map<int,int> ps;
    int soli = 1;
    for (int i=0; i<n; ++i) {
        ps[c[i]] += soli;
        ps[c[i]] %= MOD;
        soli = ps[c[i]];
    }
    cout << soli << "\n";
}


Measured memory_bytes: 10356
#include<stdio.h>

int main(void){
int a,b,c,d,i,count = 0;
scanf("%d %d %d",&a,&b,&c);
for(i = a; i < b+1; i++){
if(c%i == 0){
count++;
}
}
printf("%d\n",count);
return 0;
}


Measured memory_bytes: 2140
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        List<Integer> ss = Stream.of(sc.nextLine().split(" "))
                .map(Integer::parseInt)
                .collect(Collectors.toList());
        if (n != ss.size()) {
            return;
        }
        int q = Integer.parseInt(sc.nextLine());
        List<Integer> ts = Stream.of(sc.nextLine().split(" "))
                .map(Integer::parseInt)
                .collect(Collectors.toList());
        if (q != ts.size()) {
            return;
        }
        int c = (int)ts.stream()
                .filter(t -> Main.binarySearch(ss, t))
                .count();
        System.out.println(c);
    }

    public static boolean binarySearch(List<Integer> ss, Integer target) {
        int left = 0;
        int right = ss.size();
        while(left < right)  {
            int mid = (left + right) / 2;
            int s = ss.get(mid);
            if (s == target) {
                return true;
            } else if (s > target) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return false;
    }
}




Measured memory_bytes: 70952