akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

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

const int inf = 999999999;
const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	cin.tie(0);
	ll N, x;
	vector<ll> a;
	cin >> N >> x;
	REP(i, N) {
		ll num;
		cin >> num;
		a.push_back(num);
	}
	sort(a.begin(), a.end());

	ll count = x;
	int ix = 0;
	while (ix+1 <= N) {
		count -= a[ix];
		if (count == 0) {
			ix++;
			break;
		}
		if (count < 0) {
			break;
		}
		if (count > 0 && (ix + 1) == N) {
			break;
		}
		ix++;
	}
	cout << ix;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include<iostream>
#include<vector>
using namespace std;
int main(void){
	int n,m;
	cin>>n>>m;
	vector<int> x(m),y(m),nu(n,1);
	vector<bool> red(n,false);
	red[0]=true;
	for(int i=0;i<m;i++){
cin>>x[i]>>y[i];
nu[x[i]-1]--;
if(red[x[i]-1])red[y[i]-1]=true;
if(nu[x[i]-1]==0)red[x[i]-1]=false;
nu[y[i]-1]++;
	}
	int t=0;
for(int i=0;i<n;i++){
	if(red[i])t++;
}
cout<<t<<endl;
return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int n, k, q;
    cin >> n >> k >> q;
    vector <int> a(n, 0);
    
    
    for(int i = 0; i < q; i++){
        int b;
        cin >> b;
        a[b-1] = a[b-1] + 1;
    }
    for(int i = 0; i < n; i++){
        a[i] = a[i] + k - q;
    }
    for(int i = 0; i < n; i++){
        if(a[i] > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}



Measured memory_bytes: 1024
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

# n = int(input())
# a, b = map(int, input().split())
# s = input()



s = input()

ans = 10000
for i in range(26):
	c = chr(ord('a') + i)
	if c in s:
		res = 0
		cnt = 0
		for now in s:
			if now == c:
				res = max(res, cnt)
				cnt = 0
			else:
				cnt += 1

		cnt = 0
		while s[-(cnt+1)] != c:
			cnt += 1
		res = max(res, cnt)

		ans = min(ans, res)
print(ans)


Measured memory_bytes: 38896
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

int main() {
	char n[3][3] = {};

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			std::cin >> n[i][j];
		}
	}
	std::cout << n[0][0] << n[1][1] << n[2][2] << std::endl;

}

Measured memory_bytes: 764
N, M = map(int, input().split())
kLst = [list(map(int, input().split())) for i in range(N)]

ansLst = [0] * M
for i in range(N):
    for j in range(1, len(kLst[i])):
        ansLst[kLst[i][j] - 1] += 1

ansCnt = 0
for i in ansLst:
    if i == N:
        ansCnt += 1

print(ansCnt)

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

using namespace std;

const int N = 3e5 + 7;

int main() {
	int a, b; cin >> a >> b;
	if(a <= 0 && b >= 0){
		cout << "Zero";
	} else if (a > 0 && b > 0){
		cout << "Positive";
	} else if(a < 0 && b < 0){
		if((b - a + 1) % 2 == 0){
			cout << "Positive";
		} else {
			cout << "Negative";
		}
	}
	return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
n, m = len(S), len(T)

def main(S, T, n, m):
    for i in range(n-m, -1, -1):
        flag = True
        for s, t in zip(S[i:i+m], T):
            if s == '?' or s == t:
                pass
            else:
                flag = False
                break
        if flag:
            S = S.replace('?', 'a')
            return S[:i] + T + S[i+m:]
    return 'UNRESTORABLE'

print(main(S, T, n, m))

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll a[99],b[99],n;
int main(){
	scanf("%lld",&n);
	rep(i,0,n)scanf("%lld",a+i);
	rep(i,0,n)scanf("%lld",b+i);
	ll ans=0;
	rep(i,0,n)ans+=max(0,a[i]-b[i]);
    printf("%lld",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;
long long n, m;
string s;
int main() {
	cin >> n;
    vector<int> v;
    for(int i=0; i<n; ++i){
        int a; cin >> a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    cout << v[v.size()-1] - v[0] << endl;
	return 0;
}


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

using namespace std;
const int maxN = 1e6 + 100;
const int INF = 1e9;
const int MOD = 1e9 + 7;

void rwFile() {
    freopen("OB.inp", "r", stdin);
    freopen("OB.out", "w", stdout);
}

int n, P[maxN], Q[maxN], d[maxN];
vector<int> a[maxN], c;
bool Kt[maxN];

void DFS(int u){
    if (a[u].size() >= 1) DFS(a[u][0]);
    if (a[u].size() >= 2) DFS(a[u][1]);
    c.push_back(u);
}

void solve() {
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> P[i];

    }
    for(int i = 0; i < n; i++){
        cin >> Q[i];
        d[Q[i]] = i;
    }
    memset(Kt, true, sizeof(Kt));

    for(int i = 0; i < n; i++){
        int last = d[P[i - 1]];
        int s = d[P[i]];
        if (s < last) {
            int k = s + 1;
            while (k < n && Kt[Q[k]]) k++;
            a[Q[k]].push_back(P[i]);
           // cout << P[i] << " " << Q[k] << '\n';
        }
        else{
            int k = s - 1;
            while (k >= 0 && Kt[Q[k]]) k--;
            a[Q[k]].push_back(P[i]);
           // cout << P[i] << " " << Q[k] << '\n';
        }
        Kt[P[i]] = false;
    }

    DFS(P[0]);
    cout << c[0];
    for(int i = 1; i < c.size(); i++)
        cout << " " << c[i];
    cout << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
   // rwFile();
    solve();
}



Measured memory_bytes: 27608
a, b, c, d, e, f = map(int, input().split())

maxn = .0
total, sato = 0, 0
for _a in range(0, f+1, 100*a):
  for _b in range(0, f-_a+1, 100*b):
    if _a == 0 and _b == 0:
      continue
    for _c in range(0, f-_a-_b+1, c):
      for _d in range(0, f-_a-_b-_c+1, d):
        if ((_a + _b) // 100) * e < _c + _d:
          break
        if 100 * (_c + _d) / (_a + _b + _c + _d) >= maxn:
          maxn = 100 * (_c + _d) / (_a + _b + _c + _d)
          total = _a + _b + _c + _d
          sato = _c + _d
print(total, sato)


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    int n, q; cin >> n >> q;
    vector<lint> a(n), s(n), t(n);
    rep(i, n) cin >> a[i];

    s[0]=a[0]; t[0]=0;
    rep(i, n-1){
        s[i+1] = s[i] + a[i+1];
        t[i+1] = t[i] + a[i+1]*((i+1)%2);
    }

    vector<lint> b;
    repn(k, (n+1)/2) b.push_back((a[n-k]+a[n-2*k+1])/2);
    reverse(all(b));

    rep(i, q){
        lint x; cin >> x;
        auto itr = lower_bound(all(b), x);
        int k = (n+1)/2 - (itr-b.begin());
        lint res = s[n-1] - s[n-k-1];
        if(n-2*k-1 >= 0){
            if(n%2) res += s[n-2*k-1] - t[n-2*k-1];
            else res += t[n-2*k-1];
        }
        out(res);
    }
}

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

int main(){
  int n;
  cin >> n;
  vector<int> an(n);
  for(int i=0; i<n; ++i) cin >> an[i];
  sort(an.begin(),an.end());
  ll ans = 0;
  if(n==2){
    cout << an[1]-an[0] << endl;
    return 0;
  }
  for(int i=0; i<n/2; ++i){
    if(i == 0) ans += an[n-1]+an[n-2] - an[0]*2;
    else ans += an[n-i]+an[n-i-2] - an[i]*2;
  }
  if(n%2==1){
    ans -= an[n/2] - an[n/2-1];
    ans += max(an[n/2] - an[n/2-1], an[n/2+1] - an[n/2]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3768
#include <stdio.h>
int main()
{
	int n=0;
	
	scanf("%d",&n);
	int a[n];	
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
		}
		if(n&1)
		{
			printf("%d",a[n]);
			for(int i=n-2;i>=1;i-=2)
			{
				printf(" %d",a[i]);
			}
			for(int i=2;i<=n-1;i+=2)
			{
				printf(" %d",a[i]);
			}
		}
		else
		{
			printf("%d",a[n]);
			for(int i=n-2;i>=2;i-=2)
			{
				printf(" %d",a[i]);
			}
			for(int i=1;i<=n-1;i+=2)
			{
				printf(" %d",a[i]);
			}
		}
	return 0;
	
}

Measured memory_bytes: 2816
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	bool a[35][15];
	for (int n; cin >> n&&n;) {
		fill(a[0], a[35], false);
		int m, g, d; cin >> m >> g >> d;
		rep(h, 0, d)rep(i, 1, n) { char c; cin >> c; a[h][i] = c - '0'; }
		//rep(h, 0, d)dumpc(a[h]);
		{
			int cur = m;
			rep(j, 0, d) {
				if (a[j][cur - 1])cur--;
				else if (a[j][cur])cur++;
			}
			if (cur == g) {
				cout << 0 << endl;
				continue;
			}
		}
		bool flag = true;
		rep(h, 0, d)rep(i, 1, n) {
			if (a[h][i - 1] || a[h][i] || a[h][i + 1])continue;
			a[h][i] = true;
			//cerr << h << " "; dumpc(a[h]);
			int cur = m;
			rep(j, 0, d) {
				if (a[j][cur - 1])cur--;
				else if (a[j][cur])cur++;
				//dump(cur);
			}
			if (cur == g) {
				cout << (h + 1) << " " << i << endl;
				i = n - 1; h = d; flag = false; break;
			}
			a[h][i] = false;
		}
		if (flag)cout << 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int n, k; cin >> n >> k;
    ll R, S, P; cin >> R >> S >> P;
    string t; cin >> t;
    vector<char> memo;

    ll ans = 0;
    for(int i=0; i<n; i++){
        if(t[i]=='r'){
            if(i < k){
                memo.push_back('p');
                ans += P;
            }
            else if((memo[i-k] != 'p')){
                memo.push_back('p');
                ans += P;
            }else if(memo[i-k] == 'p'){
                memo.push_back('j'); // j : != r s p
            }
        }else if(t[i]=='s'){
            if(i < k){
                memo.push_back('r');
                ans += R;
            }
            else if((memo[i-k] != 'r')){
                memo.push_back('r');
                ans += R;
            }else if(memo[i-k] == 'r'){
                memo.push_back('j'); // j : != r s p
            }
        }else if(t[i]=='p'){
            if(i < k){
                memo.push_back('s');
                ans += S;
            }
            else if((memo[i-k] != 's')){
                memo.push_back('s');
                ans += S;
            }else if(memo[i-k] == 's'){
                memo.push_back('j'); // j : != r s p
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3780
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC091A
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] n = Console.ReadLine().Split(' ');
			int a = int.Parse(n[0]);
			int b = int.Parse(n[1]);
			int c = int.Parse(n[2]);

			if ((a + b) >= c)
				Console.WriteLine("Yes");

			else
				Console.WriteLine("No");

			Console.ReadKey();
		}
	}
}


Measured memory_bytes: 11092
#include <cstdio>
#include <algorithm>  
#include <bitset>
#include <cassert>
#include <ctime>  
#include <cmath>  
#include <cstdlib>  
#include <cstring>  
#include <functional>  
#include <iostream>  
#include <deque>  
#include <stack>
#include <queue>  
#include <vector>  
#include <map>  
#include <set>  
#include <string>  
#include <unordered_map>  
#include <unordered_set>  
#pragma warning(disable:4996)

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define endl '\n'

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

const int INF = 1e9;
const int MAXN = 3e5 + 5;
const int SZ = 1 << 19;

char A[MAXN];
int dp[MAXN][3];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> A+1;
	int N = strlen(A+1);

	memset(dp, -1, sizeof(dp));

	dp[1][1] = 1, dp[2][2] = 1;
	if(A[1] != A[2]) dp[2][1] = 2;

	for(int i=3; i<=N; i++) {
		if(dp[i-1][1] != -1 && A[i-1] != A[i]) dp[i][1] = dp[i-1][1]+1;
		if(dp[i-1][2] != -1) dp[i][1] = max(dp[i][1], dp[i-1][2]+1);
		if(dp[i-2][1] != -1) dp[i][2] = dp[i-2][1]+1;
		if(dp[i-2][2] != -1 && !(A[i-3]==A[i-1] && A[i-2]==A[i])) dp[i][2] = max(dp[i][2], dp[i-2][2]+1);
	}
	cout << max(dp[N][1], dp[N][2]);
}


Measured memory_bytes: 3968
// Virtual

#include <bits/stdc++.h>
using namespace std;

// Utility
#define ALL(X) (X).begin(), (X).end()
#define RANGE(I, X, Y) for (int I = (X); I < (Y); I++)
using ll = int64_t;
using ull = uint64_t;
namespace std {
template<class ...Ts>        istream& operator>>(istream& i, tuple<Ts...>& x) { apply([&](auto&&... ys){ ((i >> ys), ...); }, x); return i; }
template<class T1, class T2> istream& operator>>(istream& i, pair<T1, T2>& x) { i >> x.first >> x.second; return i; }
template<class T>            istream& operator>>(istream& i, vector<T>& x)    { for (auto& y : x) { i >> y; } return i; }
}

// Debugging
#define DD(X) std::cout << #X ": " << (X) << std::endl << std::flush
namespace std {
template<class ...Ts>        ostream& operator<<(ostream& o, const tuple<Ts...>& x) { o << "("; apply([&](auto&& y, auto&&... ys){ o << y; ((o << ", " << ys), ...); }, x); o << ")"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const pair<T1, T2>& x) { o << tie(x.first, x.second); return o; }
template<class T>            ostream& operator<<(ostream& o, const vector<T>& x)    { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const set<T1, T2>& x)  { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& x)  { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
}

// Main
void mainCase() {
  int x, y;
  cin >> x >> y;
  cout << (x * y) << endl;
}

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

Measured memory_bytes: 3644
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int c[110],t[110];
    int min=10000000;
    for(int i=0;i<a;i++){
        cin>>c[i]>>t[i];
        if(t[i]<=b&&c[i]<=min){
            min=c[i];
        }
    }
    if(min==10000000){
        printf("TLE");
        return 0;
    }
    printf("%d",min);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

inline int topbit(unsigned long long x){
	return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
	return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){//popcount%2
	return __builtin_parity(x);
}



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

const ll INF=1e9+7;

int main(){
    string s,t;
    cin >> s >> t;
    ll n=s.length();
    ll m=t.length();
    vector<vector<ll>> dp(2*n+1,vector<ll>(26,INF));
    vector<vector<ll>> pos(26);
    string u=s+s;
    rep(i,2*n){
        ll v=u[i]-'a';
        pos[v].push_back(i+1);
    }
    rep(i,2*n){
        rep(j,26){
            auto it=upper_bound(pos[j].begin(),pos[j].end(),i)-pos[j].begin();
            if(it==pos[j].size()){
                continue;
            }
            dp[i][j]=pos[j][it];
        }
    }
    ll p=0;
    ll ans=0;
    rep(i,m){
        ll num=t[i]-'a';
        ll nxt=dp[p][num];
        if(nxt==INF){
            cout << -1 << endl;
            return 0;
        }
        ans+=nxt-p;
        p=(nxt-1)%n+1;
    }
    cout << ans << endl;
    return 0;
}

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

const int N=210,Mod=998244353;

struct Point{
	int x,y;
	Point(int x=0,int y=0):x(x),y(y) {}
	Point operator - ( const Point &A ) const { return Point(x-A.x,y-A.y); }
	Point operator / ( const int &p ) const { return Point(x/p,y/p); }
	bool operator == ( const Point &A ) const { return x==A.x && y==A.y; }
	bool operator < ( const Point &A ) const { return x<A.x || ( x==A.x && y<A.y); }
}p[N],q[N];
typedef Point Vector;

int n,qp2[N];

void Init() {
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d%d",&p[i].x,&p[i].y);
}

int gcd(int a,int b) { return (!b)?a:gcd(b,a%b); }

Vector C(const Vector &a) { return a/gcd(a.x,a.y); }

void Solve() {
	int ans=1; 
	qp2[0]=1; for (int i=1;i<=n;++i) qp2[i]=(qp2[i-1]<<1)%Mod,ans=(ans<<1)%Mod;
	ans--; ans-=n;
	std::sort(p+1,p+n+1);
	for (int i=1;i<=n;++i) {
		int t=0;
		for (int j=i+1;j<=n;++j) 
			q[++t]=C(p[j]-p[i]);
		std::sort(q+1,q+t+1);
		for (int h=1;h<=t;) {
			int p=h; while (q[p]==q[h] && h<=t) ++h;
			ans=(0ll+ans-(qp2[h-p]-1)+Mod)%Mod;
		}
	}
	printf("%d\n",ans);
}

int main() {
	Init();
	Solve();
	return 0;
}

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


int main(){
    string S;
    cin >>S;
    if (S== "SUN"){
        cout << 7 << endl;
    }else if (S=="MON") {
        cout << 6 << endl;
    }
    else if (S=="TUE") {
        cout << 5 << endl;
    }
    else if (S=="WED") {
        cout << 4 << endl;
    }
    else if (S=="THU") {
        cout << 3 << endl;
    }
    else if (S=="FRI") {
        cout << 2 << endl;
    }
    else if (S=="SAT") {
        cout << 1 << endl;
    }
}

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

using namespace std;
using ll = long long;

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

  int n;
  cin >> n;

  map<pair<int, int>, ll> m;
  for (int i = 1; i <= n; i++) {
    int x = int(i / pow(10, int(log10(i))));
    int y = i % 10;
    m[{x, y}]++;
  }

  ll ans = 0;
  // i〇〇〇j
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      ans += m[{i, j}] * m[{j, i}];
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4048
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
        public static void main(String[] args) throws Exception {
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                StringTokenizer st;
                PrintWriter pw = new PrintWriter(System.out);

                st = new StringTokenizer(br.readLine());
                long a = Long.parseLong(st.nextToken());
                long b = Long.parseLong(st.nextToken());
                pw.println(lcm(a,b));



                pw.flush();
                pw.close();
        }

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

        static long gcd(long a, long b) {
                return b==0?a:gcd(b,a%b);
        }
}


Measured memory_bytes: 21204
main :: IO ()
main = do
  nm <- getLine
  if nm == "0 0"
    then return ()
    else do
      ls <- getLine
      let ls' = map read . words $ ls
          [n,m] = map read .words $ nm
      print $ solve ls' m
      main

solve :: [Int] -> Int -> Int
solve ls m = package (sort ls) m
  where
    sort :: [Int] -> [Int]
    sort [] = []
    sort (x:xs) = (sort higher) ++ [x] ++ (sort lower)
      where
        higher = [p | p <- xs, p >= x]
        lower = [p | p <- xs, p < x]

    package :: [Int] -> Int -> Int
    package [] _ = 0
    package ls m = (takeSum ls m) + (package (rest m ls) m)
      where
        takeSum :: [Int] -> Int -> Int
        takeSum [] _ = 0
        takeSum _ 0 = 0
        takeSum _ 1 = 0
        takeSum (x:xs) n = x + (takeSum xs (n - 1))

        rest :: Int -> [Int] -> [Int]
        rest _ [] = []
        rest 0 xs = xs
        rest n (x:xs) = rest (n-1) xs

Measured memory_bytes: 5452
N = int(input())
A = []
for i in range(N):
  temp = int(input())
  A.append(temp)
A.sort()

if N%2 == 0:
  c = N//2
  small = A[:c]
  large = A[c:]
  ans = 2*sum(large)-min(large)-(2*sum(small)-max(small))
else:
  c = N//2
  small = A[:c+1]
  small.sort()
  large = A[c+1:] #largeの数のほうが少ない
  ans = 2*sum(large)-(2*sum(small)-small[-1]-small[-2])
  #print(large,small)
  small = A[:c]
  large = A[c:]
  large.sort()
  anst = 2*sum(large)-large[0]-large[1]-2*sum(small)
  ans = max(ans,anst)
print(ans)

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


int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1;i<=n;i++){
    int cnt  = 0;
    for(int j = 1;j<=i;j++){
      if(i%2!=0&&i%j==0) cnt++;
    }
    if(cnt==8)ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")
#define pb(s) push_back(s)
#define SZ(x) ((int)(x).size())

void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}

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

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

    // input
    ll N; 
    cin >> N;

    p(N*N*N);
    
    return 0;
}

Measured memory_bytes: 256
//Decision's template
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<numeric>
using namespace std;

#define maxn 100007
#define DP_maxn 16
#define INF 1000000007
#define mod 1000000007
#define mst(s,k) memset(s,k,sizeof(s))
#define eps 1e-12
#define f_read freopen("std.in","r",stdin);
#define f_witten freopen("std.out","w",stdout);

typedef long long ll;

struct Edge{
    int from,to,dist;
    Edge(int u,int v,int d):from(u),to(v),dist(d){}
};

/*-------------------------------template End--------------------------------*/

int n;
int tmp;
int ans = 0;
int main(){
	cin>>n;
	for(int i = 1;i <= n;i++) {
		cin>>tmp;
		ans^=tmp;
	}
	if(ans == 0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
} 

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

int main(){
	long long int a,b,c,ans=0;
	cin>>a>>b>>c;
	ans=b/a;
	if(ans>c){
		cout<<c<<endl;
	}
	else{
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
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; }
const int INF = 1e9;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int s, w;
    cin >> s >> w;
    if(w >= s) cout << "unsafe" << endl;
    else cout << "safe" << endl;

}

Measured memory_bytes: 3608
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>

int main()
{
    int x, a;
    scanf("%d %d", &x, &a);
    if (x < a)
        printf("0");
    else
        printf("10");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
int n;
vector<int> a;
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
	  fac[i] = fac[i-1] * i % MOD;
	  inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
	  finv[i] = finv[i-1] * inv[i] % MOD;
	}
}
//組み合わせ
long long COM (int n, int k) {
	if(n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
void solve() {
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	int sum = 0;
	for (int i = 0; i <= n + 1; ++i) {
		sum += abs(a[i] - a[i + 1]);
	}
	for (int i = 1; i <= n; ++i) {
		int ans = sum;
		ans = sum - abs(abs(a[i - 1] - a[i + 1]) - (abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1])));
		cout << ans << endl;
	}
	return;
}
int main() {
	cin >> n;
	a.resize(n + 2, 0);
	solve();
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

constexpr int MAX = 4000;

using B = bitset<MAX>;

int n;
B x, a, b;

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

    cin >> n >> x;
    rep(i, n) for(cin >> b; b.any(); swap(a, b)) {
        int p = MAX;
        while(p--)
            if(b[p]) break;
        for(int j = MAX; j-- > p;)
            if(a[j]) a ^= b << j - p;
    }

    int p = MAX;
    while(p--)
        if(a[p]) break;

    int ans = 0;
    for(int i = MAX; i-- > p;)
        ans = (ans << 1 | x[i]) % Mod;

    b = x;
    for(int i = MAX - 1; i >= p; b ^= a << (i - p)) {
        while(i >= p && !b[i])
            i--;
    }
    for(int i = p - 1; ~i; i--)
        if(b[i]) {
            ans -= !x[i];
            break;
        }

    cout << (ans + 1) % Mod << endl;

    return 0;
}

Measured memory_bytes: 256
use whiteread::parse_line;

fn main() {
    let s: String = parse_line().unwrap();
    let mut black = String::new();
    //let mut _white = String::new();

    for i in 0..s.len() {
        if i % 2 == 0 {
            black.push('0');
        //white.push('1');
        } else {
            black.push('1');
            //white.push('0');
        }
    }

    let s = s.as_str().chars();
    let mut black = black.as_str().chars();
    //let _white = _white.as_str().chars();
    let mut b_diff = 0;
    let mut w_diff = 0;
    for c in s {
        if Some(c) != black.next() {
            b_diff += 1;
        } else {
            w_diff += 1;
        }
    }
    println!("{}", b_diff.min(w_diff));
}


Measured memory_bytes: 2332
import java.io.*;
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String str = scan.nextLine();
    ArrayList<String> array = new ArrayList<String>();

    char characters[] = str.toCharArray();
    int remainlength = characters.length;
    for(int  i = 0 ; i < characters.length; i++){
      array.add(String.valueOf(characters[i]));
    }

    array.remove(array.size() - 1);
    array.remove(array.size() - 1);
    remainlength -= 2;
    while(remainlength != 0){
      boolean unmatchflag = false;
      for(int i = 0; i < array.size()/2;i++){
        if(!array.get(i).equals(array.get(i + array.size()/2))){
          unmatchflag = true;
          break;
        }
      }
      if(unmatchflag){
      array.remove(array.size() - 1);
      array.remove(array.size() - 1);
      remainlength -= 2;
    } else{
      break;
    }
    }

    System.out.println(remainlength);
  }
}


Measured memory_bytes: 21844
N = int(input())
l = []
s = set()
for i in range(N):
	a,b,c = map(int,input().split(' '))
	l.append(a)
	l.append(b)
	l.append(c)
	l.sort()
	d = str(l[0])
	e = str(l[1])
	f = str(l[2])
	g = d + e + f
	s.add(g)
	l = []
print(N - len(s))

Measured memory_bytes: 7684
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B){
  priority_queue<ll> que;
  vector<pll> AB;
  REP(A.size()){
    AB.push_back(pll(A[i],B[i]));
  }
  sort(AB.begin(),AB.end());
  ll index=0;
  ll ans=0;
  REP(M){
    while(index<AB.size()&&(AB[index].first<i+2)){
      ll tmp=AB[index].second;
      que.push(tmp);
      ++index;
    }
    if(!que.empty()){
      ans+=que.top();
      que.pop();
    }
  }
  cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}

Measured memory_bytes: 5232
# python3 (3.4.3)
import sys
input = sys.stdin.readline

# main
from math import ceil
from decimal import *
N = int(input())
TA = [list(map(int,input().split())) for _ in range(N)]


t,a = 1,1
for i in range(N):
    n = Decimal(max(ceil(t/TA[i][0]), ceil(a/TA[i][1])))
    t = n*TA[i][0]
    a = n*TA[i][1]

print(t+a)

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    while(true){
        int N, R; cin >> N >> R;
        if(N == 0 && R == 0) break;
        vector<int> A(N);
        rep(i, N) A[i] = N-i;
        rep(i, R){
            int start, num;
            cin >> start >> num; start--;

            vector<int> B(num);
            rep(j, num) B[j] = A[start+j];

            for(int j = start+num-1; j >= num; j--) A[j] = A[j-num];

            for(int j = 0; j < num; j++) A[j] = B[j];
        }
        cout << A[0] << endl;
    }
    return 0;
}


Measured memory_bytes: 3012
n = int(input())
w0 = input()
word_set = set([w0])
ans = True

for i in range(1, n):
    w = input()
    if ans and w not in word_set and w[0] == w0[-1]:
        word_set.add(w)
        w0 = w
    else:
        ans = False

if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct node {
	int key;
	struct node *r,*l,*p;
};
struct node *NIL,*root;
int a=0,b=0;
void insert(int k) {
	struct node *x=root,*y=NIL,*z;
	z=(struct node*)malloc(sizeof(struct node));
	z->key=k;
	z->l=NIL;
	z->r=NIL;
	while(x!=NIL) {
		y=x;
		if(k<x->key)
			x=x->l;
		else
			x=x->r;
	}
	z->p=y;
	if(y==NIL) {
		root=z;
	} else if(z->key<y->key)
		y->l=z;
	else
		y->r=z;
}
void inOrder(struct node *p) {
	if(p==NIL)
	return;
	inOrder(p->l);
    printf(" %d",p->key);
	inOrder(p->r);
}
void preOrder(struct node *p) {
	if(p==NIL)
	return;
	printf(" %d",p->key);
	preOrder(p->l);
	preOrder(p->r);
}
int print(struct node *p) {
	a=0;
	b=0;
	inOrder(p);
	printf("\n");
	preOrder(p);
	printf("\n");
	return a;
}
struct node *find(struct node *x,int k){
	while(x!=NIL&&x->key!=k){
		if(k>x->key)
		x=x->r;
		else
		x=x->l;
	}
	return x;
}
struct node *getMin(struct node *x){
	while(x->l!=NIL){
		x=x->l;
	}
	return x;
}
struct node *getSuccessor(struct node *z){
	if(z->r!=NIL)
	return getMin(z->r);
	
	struct node *y=z->p;
	while(y!=NIL&&z==y->r){
		z=y;
		z=y->p;
	}
	return y;
}
void deleteNode(struct node *z){
	struct node *x,*y;
	if(z->l==NIL||z->r==NIL)
	y=z;
	else
	y=getSuccessor(z);
	
	if(y->l==NIL)
	x=y->r;
	else
	x=y->l;
	
	if(x!=NIL)
	x->p=y->p;
	
	if(y->p==NIL)
	root=x;
	else if(y==y->p->l)
	y->p->l=x;
	else
	y->p->r=x;
	
	if(y!=z)
	z->key=y->key;
}
int main() {
	int m,i,j,o=0,k;
	char str[10];
	int len[11];
	struct node *x;
	scanf("%d",&m);
	for(i=0; i<m; i++) {
		scanf("%s",str);
		if(str[0]=='i') {
			scanf("%d",&k);
			insert(k);
		} else if(str[0]=='p'){
			print(root);
		}
		else if(str[0]=='d'){
			scanf("%d",&k);
			deleteNode(find(root,k));
		}
		else{
			scanf("%d",&k);
			x=find(root,k);
			if(x!=NIL)
			printf("yes\n");
			else
			printf("no\n");
		}
	}//输入
	return 0;
}


Measured memory_bytes: 20488
# coding: utf-8
import copy
D = int(input())
C = list(map(int,input().split()))
S = []
for i in range(D):
    s = list(map(int,input().split()))
    S.append(s)
    
day_of_problems = [0] * 27

tmp = 0

for i in range(D):#i+1日目
    A = []
    for t in range(26):
        A.append(S[i][t] + day_of_problems[t])
    tmp = max(A)
    idx = A.index(tmp)
    day_of_problems[idx] = i+1
    print(idx+1)
        
    

Measured memory_bytes: 74960
#include<cstdio>
#define swap(x,y) (x^=y,y^=x,x^=y)
using namespace std;
const int maxn=105;
int n,a[maxn],ans[maxn];
inline int read(){
	int ret=0;bool f=0;char ch=getchar();
	while(ch>'9'||ch<'0') f^=ch=='-',ch=getchar();
	while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=getchar();
	return f?-ret:ret;
}
int main(){
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=n;i;i--){
		int k=0;
		for (int j=i;j;j--)
		if(a[j]==j){k=j;break;}
		if(!k) return puts("-1")&0;
		ans[i]=k;
		for (int j=k;j<i;j++) swap(a[j],a[j+1]);
	}
	for (int i=1;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#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 <complex>
#include <stack>
#include <queue>

using namespace std;
static const double EPS = 1e-10;

int main(){
	vector<int> p;
	vector<int> a(1000000);
	bool b;
	int n = 1000000;

	a[0] = a[1] = 0;
	a[2] = 1;
	p.push_back(2);
	for(int i = 3; i < n; i++){
		b = true;
		for(int j = 0; j < p.size(); j++){
			if(p[j]*p[j] > i){
				break;
			}
			if(i % p[j] == 0){
				b = false;
				break;
			}
		}
		if(b){
			p.push_back(i);
		}
		a[i] = p.size();
	}

	while(cin >> n){

		cout << a[n] << endl;
	}

	return 0;
}

Measured memory_bytes: 5496
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef struct {
  int type;
  int x;
} S;

int64_t MOD = 1000000007;

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

  vector<S> v;

  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    v.push_back({ 0, a });
  }

  for (int i = 0; i < N; i++) {
    int b;
    cin >> b;
    v.push_back({ 1, b });
  }

  sort(v.begin(), v.end(), [](S a, S b) { return a.x < b.x; });

  int cnt0 = 0;
  int cnt1 = 0;
  int64_t ans = 1;
  for (auto i: v) {
    if (i.type == 0) {
      if (cnt1 == 0) {
        cnt0 += 1;
      } else {
        ans = ans * cnt1 % MOD;
        cnt1 -= 1;
      }
    } else {
      if (cnt0 == 0) {
        cnt1 += 1;
      } else {
        ans = ans * cnt0 % MOD;
        cnt0 -= 1;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 2420
#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(){
	int n;
	cin >> n;
	vector<int> t(n);
	vector<int> x(n);
	vector<int> y(n);
	for(int i = 0;i < n;i++){
		cin >> t[i] >> x[i] >> y[i];
	}

	int nowx = 0;
	int nowy = 0;
	int nowt = 0;
	for(int i = 0;i < n;i++){
		if(abs(nowt - t[i]) < abs(nowy - y[i]) + abs(nowx - x[i])){
			cout << "No" << endl;
			return 0;
		}
		else if(abs(nowt - t[i]) % 2 != (abs(nowy - y[i]) + abs(nowx - x[i])) % 2){
			cout << "No" << endl;
			return 0;
		}
		nowt = t[i];
		nowx = x[i];
		nowy = y[i];
	}

	cout << "Yes" << endl;
}


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

using namespace std;

const int N=1e6+3;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

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

const int inf=1e9;

int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans[N],sz[N];

char s[N];

pair<int,int> p[N];

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&p[i].first),p[i].second=i;
	sort(p,p+n);
	for(int i=0;i<n;i++){
		int x=n-1;
		if (i==n-1)
			x--;
		ans[p[i].second]=p[x].first;
	}
	for(int i=0;i<n;i++)
		printf("%d\n",ans[i]);
}


Measured memory_bytes: 5248
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N, C = map(int, input().split())
sushis = [list(map(int, input().split())) for _ in range(N)]

# Aを時計回り,Bを反時計回りとする
# O->Aと0->A->Oのコストを計算
# O->Aについてval(O->A[i]) > val(O->A[i+1])の時、i+1に行くよりiで止めた方が得.
# それをtmpMaxでごにょごにょしてる
valA = []
valArev = []
sumV = 0
tmpMax = -float('inf')

for d, v in sushis:
    sumV += v
    valArev.append(sumV-2*d)
    tmpMax = max(tmpMax, sumV-d)
    valA.append(tmpMax)

valB = []
valBrev = []
sumV = 0
tmpMax = -float('inf')
for d, v in reversed(sushis):
    sumV += v
    revD = C-d
    valBrev.append(sumV-2*revD)
    tmpMax = max(tmpMax, sumV-revD)
    valB.append(tmpMax)


# 折り返しなしの場合の値
ans = max(valA+valB+[0])
# O->A->O->B
# i=N-1の時は折り返しなしの場合と同じだから、省く
for i in range(N-1):
    ans = max(ans, valArev[i]+valB[N-i-2])  # 被った寿司を取らないようにvalB[N-i-2])

# O->B->O->A
for i in range(N-1):
    ans = max(ans, valBrev[i]+valA[N-i-2])
print(ans)


Measured memory_bytes: 46752
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#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 all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    string N; cin >> N;
    for (auto c : N) {
        if (c == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3560
import java.io.*;
import java.util.*;

public class Main {

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }

    public static void main(String[] args) {
        FastReader scanner = new FastReader();
        int N = scanner.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = scanner.nextInt();
        }

        int[] DP = new int[N];
        DP[1] = Math.abs(A[1] - A[0]);

        for (int i = 2; i < N; i++) {
            DP[i] = Math.min(DP[i - 1] + Math.abs(A[i] - A[i - 1]), DP[i - 2] + Math.abs(A[i] - A[i - 2]));
        }
        System.out.println(DP[N - 1]);
    }
}

Measured memory_bytes: 30356
#!/usr/bin/env python3
import sys


def solve(N: int, S: str):
    Right_w, Right_e = S.count("W"), S.count("E")
    Left_w, Left_e = 0, 0

    ans = N

    for si in S:
        # update stack
        if si == "W":
            Right_w -= 1
        else:
            Right_e -= 1
        # update ans
        ans = min(ans, Left_w + Right_e)
        # update stack
        if si == "W":
            Left_w += 1
        else:
            Left_e += 1
    print(ans)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N = int(input())
    S = str(input())
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

template <class T = int>
class CuSum {
private:
	vector<T> cusum;

public:
	CuSum(vector<T> const &vec) : cusum(vec.size() + 1) { for (int i = 0; i < (int)(vec.size()); i++) cusum[i + 1] = cusum[i] + vec[i]; }

	CuSum(int N) : cusum(N + 1) {}
	void add(int i, T x) { cusum[i + 1] += cusum[i] + x; }

	T query(int l, int r) { return cusum[r] - cusum[l]; }  // partial sum of [l, r)
};

int main() {

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

	int N, Q;
	string S;
	cin >> N >> Q >> S;

	CuSum<int> ACsum(N);
	for (int i = 1; i < N; i++) ACsum.add(i, (int)(S[i - 1] == 'A' && S[i] == 'C'));

	pair<int, int> range;
	for (int i = 0; i < Q; i++) {
		cin >> range.first >> range.second;
		cout << ACsum.query(range.first, range.second) << "\n";
	}

	return 0;
}

Measured memory_bytes: 1488
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<vector<ll> > dp(n + 1, vector<ll>(13));
  dp[0][0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= 12; ++j) {
      if (s[i] == '?') {
        for (int k = 0; k <= 9; ++k) {
          dp[i + 1][((10 * j) + k) % 13] += dp[i][j];
          dp[i + 1][((10 * j) + k) % 13] %= MOD;
        }
      } else {
        int num = s[i] - '0';
        dp[i + 1][((10 * j) + num) % 13] += dp[i][j];
        dp[i + 1][((10 * j) + num) % 13] %= MOD;
      }
    }
  }
  cout << dp[n][5] << endl;
  return 0;
}

Measured memory_bytes: 13696