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

#define ll long long 
#define ff(i, a, b) for(int i = a; i <= b; i++)
#define fo(i, a, b) for(int i = a; i < b; i++)
#define fod(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const int INF = 1e9, N = 1000010;
const ll INFL = 1e18;

typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <ii> vii;

int n; string s;
int J[N], I[N];
int ans;

int main() {
	ios_base::sync_with_stdio(false);
	cin >> s; n = s.size();
	J[0] = (s[0] == 'J');
	fo(i, 1, s.size()) if (s[i] == 'J') J[i] = J[i - 1] + 1;
	I[n - 1] = (s[n - 1] == 'I');
	fod(i, n - 2, 0) if (s[i] == 'I') I[i] = I[i + 1] + 1;
	int i = 0;
	while(i < s.size()) {
		if (s[i] != 'O') { i++; continue; }
		int j = i; 
		while(s[j] == 'O' && j < n) j++;
		j--;
		int len = j - i + 1;
		//cout << i << ' ' << j << ' ' << len << "\n";
		if (J[i-1] >= len && I[j+1] >= len) ans = max(ans, len);
		i = j + 1;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 10040
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 998244353
#define INF 93193111451418101
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

ll H, n, vis[40009][5], dp[40009][5]; // null,left,right,middle,both
bool check(ll h, ll x) {
  if (vis[h][x] == false && vis[h][x + 1] == false && vis[h + 1][x] == false && vis[h + 1][x + 1] == false) {
    return true;
  }
  return false;
}
// null,left,right,middle,both
ll DP(ll h, ll pre) {
  if (dp[h][pre]) {
    return dp[h][pre];
  }
  if (h == H - 1) {
    return 0;
  }
  ll cnt = 0;
  if (pre == 0) {
    if (check(h, 2)) {
      cnt = max(cnt, DP(h + 1, 2) + 1);
    }
    if (check(h, 1)) {
      cnt = max(cnt, DP(h + 1, 3) + 1);
    }
    if (check(h, 0)) {
      cnt = max(cnt, DP(h + 1, 1) + 1);
    }
    if (check(h, 0) && check(h, 2)) {
      cnt = max(cnt, DP(h + 1, 4) + 2);
    }
  }
  if (pre == 1) {
    if (check(h, 2)) {
      cnt = max(cnt, DP(h + 1, 2) + 1);
    }
  }
  if (pre == 2) {
    if (check(h, 0)) {
      cnt = max(cnt, DP(h + 1, 1) + 1);
    }
  }
  cnt = max(cnt, DP(h + 1, 0));
  dp[h][pre] = cnt;
  // cout << h << " " << pre << " " << cnt << endl;
  return cnt;
}

int main() {
  cin >> H >> n;
  REP(i, n) {
    ll x, y;
    cin >> x >> y;
    vis[y][x] = 1;
  }
  cout << DP(0, 0) << endl;
}



Measured memory_bytes: 4508
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;

 main()

{
    fast
    string s;
    cin>>s;
    cout<<s.substr(0,3);
    return 0;

}





































Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,a;
	cin>>n;
	bool f=1;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a%2==0){
			if(!(a%3==0||a%5==0))f=0;
		}
	}
	cout<<(f?"APPROVED":"DENIED");
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n), b(n);
	std::vector<std::pair<int, int>> vec;
	for(int i = 0; i < n; i++) {
		scanf("%d%d", &a[i], &b[i]);
		
		vec.push_back({b[i], i});
	}
	sort(begin(vec), end(vec));
	
	i64 now = 0;
	bool ans = true;
	for(auto v: vec) {
		ans &= (now + a[v.second] <= v.first);
		now += a[v.second];
	}
	
	if(ans) printf("Yes\n");
	else printf("No\n");
	return 0;
}


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

int n, m;

int main() {
    scanf("%d%d", &n, &m);
    double p = pow(0.5, m);
    double q = 1 - p, tt = 1;
    double s = (n - m) * 100 + m * 1900;
    double ans = 0;
    for (int i = 1; i < 10000; i++) {
        ans += p * tt * s * i;
       // printf("%.2f\n", p * tt * s * i);
        tt *= q;
    }
    printf("%.0f\n", ans);
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8

n = int(input())
l = list(map(int, input().split()))
prev = 0
ans = "Yes"

if n > 1:
  prev = l[0]
  for i in range(1, n):
    
    if prev != l[i] and prev > (l[i] - 1):
      ans = "No"
      break
    
    if prev == l[i]:
      prev = l[i]
    else:
      prev = l[i] - 1

print(ans)

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

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  string r = "";
  r += s1.at(0);
  r += s2.at(0);
  r += s3.at(0);
  transform(r.begin(), r.end(), r.begin(), ::toupper);
  cout << r << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main() {

    int n;
    cin >> n;

    string s;
    int tot = 0, a = 0, b = 0, ab = 0;

    for(int i = 0;i < n;i++){
        cin >> s;
        for(int j = 0;j<s.size()-1;j++){
            if(s[j] == 'A' && s[j+1] == 'B'){
                tot++;
            }
        }
        if(s[0] == 'B' && s[s.size()-1] == 'A'){
            ab++;
        }
        if(s[0] == 'B' && s[s.size()-1] != 'A'){
            b++;
        }
        if(s[0] != 'B' && s[s.size()-1] == 'A'){
            a++;
        }
    }
    if(ab == 0){
        tot += min(a,b);
    }
    if(ab != 0 && a == 0 && b == 0){
        tot += ab-1;
    }
    if(ab != 0 && a != 0 && b == 0){
        tot += ab;
    }
    if(ab != 0 && a == 0 && b != 0){
        tot += ab;
    }
    if(ab && a && b){
        tot += ab+1;
        tot += min(a-1,b-1);
    }

    cout << tot << endl;

    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define all(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
#define MOD 1000000007
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
inline bool BETWEEN(int x, int min,int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}

using namespace std;
#pragma endregion
signed main() {
		int n,k;
		int a = 0;
		cin >> n >> k;
		cout << max(a,n-k);
}

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

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

  string S;
  cin >> S;

  if (S.size()%2 == 0){

    bool incorrect = false;

    for (int i = 0; i < N/2; i++){

      if (S.at(i) != S.at(i+N/2)){

      incorrect = true;
      break;

      }
    }

    if (incorrect){

      cout << "No" << endl;

    }
    else{

      cout << "Yes" << endl;

    }
  }
  else{

    cout << "No" << endl;

  }
}


Measured memory_bytes: 764
//tt89 ;)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
void testcase(int t) { cout<<"Case #"<<t<<": "; }
void online() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif //ONLINE_JUDGE
}
const int mod= 1e9+7;

unordered_set<int> s;

int getAns(int n) {
    int c=0;
    int num=7;

    while(num!=0) {
        num%=n;
        if( num==0 ) return c+1;
        else if(s.find(num)!=s.end()) return -1;
        else s.insert(num);

        num= num*10+7;
        c++;
    }
    return -1;
}

int main() {
    fastIO;
    int n; cin>>n;
    int ans=getAns(n);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 42544
#include <bits/stdc++.h>
using namespace std;
 
int r, s, t, k, maks, n;
int main()
{
    cin >> r >> s >> t >> k;
    for (int i = 1; i <= k; i++)
    {
        if (r > s && r > t)
        {
            r *= 2;
            maks = r + s + t;
        }
        else if (s > r && s > t)
        {
            s *= 2;
            maks = r + s + t;
        }
        else
        {
            t *= 2;
            maks = r + s + t;
        }
        
    }
    cout << maks << endl;
}

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

int main(){
    
    long long int N,A,B;
    cin>>N>>A>>B;
    if(A>B) cout<<0<<endl;
    else if(N==1&&A!=B) cout<<0<<endl;
    else if(N==1) cout<<1<<endl;
    else cout<<(N-2)*(B-A)+1<<endl;
}


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

def solve1():
    no_rem = 0
    rem_half = 0

    for i in range(1,n+1):
        no_rem += 1 if i % k == 0 else 0

        rem_half += 1 if k%2 == 0 and i%k == k//2 else 0

    print(no_rem ** 3 + rem_half**3)
    

def solve2():
    no_rem = n//k

    rem_half = 0 if k%2==1 else (n + k//2)//k
    print(no_rem**3 + rem_half**3)

solve2()

Measured memory_bytes: 3060
n, x = map(int, input().split())
L = list(map(int, input().split()))
D = []
D.append(0)
for i in range(n):
  D.append(D[i] + L[i])
ans = 0
for i in range(n + 1):
  if(D[i] <= x):
    ans += 1
print(ans)


Measured memory_bytes: 3060
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<iomanip>
#include<unordered_map>
#define deg(x) cerr<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;typedef long long LL;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,int> pss;
typedef unsigned long long ull;
const ll mod=998244353;
const int inf=1e9+7;
const double eps=1e-6;
ll qpow(ll a,ll b,ll m){ ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return (r+m)%m;}
const double pi=acos(-1);

ll a[203040];

int main(){
    TB
    int n;
    cin>>n;
    fd(n) cin>>a[i];
    ll sum=0,g=a[0];
    fdd(1,n){
        if(a[i]>=g){
            g=a[i];
        }else{
            sum+=g-a[i];
        }
    }
    cout<<sum<<'\n';
    return 0;
}

Measured memory_bytes: 5164
#include<iostream>
using namespace std;
int main()
{
    long long N,M;
    while(cin>>N>>M)
    {
        if(2*N<=M)
    {
        cout<<N+(M-2*N)/4<<endl;
    }
    else
    {
        cout<<M/2<<endl;
    }
    }

}

Measured memory_bytes: 256
import itertools

N, M = map(int, input().split())
t = []
ans = 0
for i in range(N):
    t.append(list(map(int, input().split()))[1::])

t = list(itertools.chain.from_iterable(t))
for i in set(t):
    if t.count(i) == N:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
#define speed ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ub(a,x) upper_bound(a.begin(),a.end(),x)-a.begin()
#define lb(a,x) lower_bound(a.begin(),a.end(),x)-a.begin()
#define ll long long int
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define PI 3.1415926535897932384626
#define keep_unique(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());

 
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long 

void solveFunction()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<int> v[3];
    for(int i=0;i<n;i++)
    {
    	if(s[i]=='R') v[0].pb(i);
    	else if(s[i]=='G') v[1].pb(i);
    	else v[2].pb(i);
    }

    int ans = 0;

    for(int i:v[0])
    {
    	for(int j:v[1])
    	{
    		if(j>i)
    		{
    			int id = ub(v[2],j);
	    		ans += (v[2].size()-id);
	    		if(binary_search(all(v[2]),j+(j-i))) ans--;
    		}
    	}
    }

    for(int i:v[0])
    {
    	for(int j:v[2])
    	{
    		if(j>i)
    		{
    			int id = ub(v[1],j);
	    		ans += (v[1].size()-id);
	    		if(binary_search(all(v[1]),j+(j-i))) ans--;
    		}
    	}
    }

    for(int i:v[1])
    {
    	for(int j:v[2])
    	{
    		if(j>i)
    		{
    			int id = ub(v[0],j);
	    		ans += (v[0].size()-id);
	    		if(binary_search(all(v[0]),j+(j-i))) ans--;
    		}
    	}
    }

    for(int i:v[1])
    {
    	for(int j:v[0])
    	{
    		if(j>i)
    		{
    			int id = ub(v[2],j);
	    		ans += (v[2].size()-id);
	    		if(binary_search(all(v[2]),j+(j-i))) ans--;
    		}
    	}
    }

    for(int i:v[2])
    {
    	for(int j:v[0])
    	{
    		if(j>i)
    		{
    			int id = ub(v[1],j);
	    		ans += (v[1].size()-id);
	    		if(binary_search(all(v[1]),j+(j-i))) ans--;
    		}
    	}
    }

    for(int i:v[2])
    {
    	for(int j:v[1])
    	{
    		if(j>i)
    		{
    			int id = ub(v[0],j);
	    		ans += (v[0].size()-id);
	    		if(binary_search(all(v[0]),j+(j-i))) ans--;
    		}
    	}
    }

    cout<<ans;

}

main()  
{
    speed;
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solveFunction();
    }
}



Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

const ll mod = 1e9 + 7;
const ll INF = 1e18 + 5;
const int inf = -1 * ((1 << 31) + 1);

int n;ll k;
vector<ll> a;
bool f(ll x){
    ll tot = 0;
    rep(i,n){
        if(a[i] < 0){
            int l = -1, r = n;
            while(abs(l-r)>1){
                int c = (l+r)/2;
                if(a[c]*a[i] < x)r = c;else l = c;
            }
            tot += n - r;
        }else{
            int l = -1,r = n;
            while(abs(l-r)>1){
                int c = (r+l)/2;
                if(a[c]*a[i] < x)l=c;else r = c;
            }
            tot += r;
        }
        if(a[i]*a[i] < x)tot--;
    }
    tot /= 2;
    return tot < k;
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin >> n >> k;
    a.resize(n);
    rep(i,n)cin >> a[i];
    sort(ALL(a));
    ll ok = -INF, ng = INF;
    while(abs(ok-ng)>1){
        ll mid = (ok+ng)/2;
        bool can = 1;
        can = f(mid);
        if(can)ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

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

const int INF = 1001001001;

int a[12][12];

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    rep(i,n){
        cin >> c[i];
        rep(j, m) cin >> a[i][j];
    }

    int ans = INF;
    rep(s, 1 << n){
        int cost = 0;
        vector<int> d(m);
        rep(i, n){
            if(s >> i & 1){
                cost += c[i];
                rep(j, m) d[j] += a[i][j];
            }
        }
        bool ok = true;
        rep(j, m) if(d[j] < x) ok = false;
        if(ok) ans = min(ans, cost);
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
import std.stdio;

struct Deque(T) {
	T[] array;
	size_t first, last, length_;

	this(size_t maxLength) {
		array = new T[maxLength];
		first = last = maxLength / 2;
	}

	bool empty() {
		return length_ == 0;
	}

	size_t length() {
		return length_;
	}

	T back() {
		if (last == 0) {
			return array[$ - 1];
		} else {
			return array[last - 1];
		}
	}

	void popBack() {
		if (last == 0) {
			last = array.length - 1;
		} else {
			--last;
		}
		--length_;
	}
	
	void pushBack(T x) {
		if (length_ >= array.length) {
			throw new Exception("Deque is full.");
		}
		array[last] = x;
		++last;
		++length_;
		if (last >= array.length) {
			last = 0;
		}
	}



	T front() {
		return array[first];
	}

	void popFront() {
		++first;
		if (first >= array.length) {
			first = 0;
		}
		--length_;
	}

	void pushFront(T x) {
		if (length_ >= array.length) {
			throw new Exception("Deque is full.");
		}
		if (first == 0) {
			first = array.length - 1;
		} else {
			--first;
		}
		array[first] = x;
		++length_;
	}
}

void main() {
	int n, x, y;
	readf(" %s %s %s", &n, &x, &y);
	// x, yをデクリメントしてゼロオリジンにします。
	--x;
	--y;
	
	auto queue = Deque!(int)(2048);
	auto a = new int[n];
	auto answer = new int[n];

	void push(int v, int d) {
		if (a[v] != int.max) {
			return;
		}
		a[v] = d;
		queue.pushBack(v);
	}

	foreach (base;0..n) {
		a[] = int.max;

		push(base, 0);

		while (!queue.empty) {
			auto vertex = queue.front;
			queue.popFront();

			auto distance = a[vertex];
			
			if (vertex == x) {
				push(y, distance + 1);
			}
			if (vertex == y) {
				push(x, distance + 1);
			}
			if (vertex + 1 < n) {
				push(vertex + 1, distance + 1);
			}
			if (vertex - 1 >= 0) {
				push(vertex - 1, distance + 1);
			}
		}

		foreach (e;a) {
			++answer[e];
		}
	}

	foreach (e;answer[1..$]) {
		writeln(e / 2);
	}
}


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

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	int N;
	cin >> N;
	string S=to_string(N);
	int siz=S.size(), ans=0;
	int M=S[0]-'0', m=S[S.size()-1]-'0';
	for(int i=1; i<=N; i++){
		string a=to_string(i);
		int as=a[0]-'0', ae=a[a.size()-1]-'0';
		if(ae==0) continue;
		if(as==ae) ans++;
		if(ae==M){
			rep(j,siz-2) ans+=pow(10,j);
			int res=N-M*pow(10,siz-1);
			res/=10;
			ans+=res;
			if(as<=m) ans++;
		}
		else if(ae<M){
			rep(j,siz-1) ans+=pow(10,j);
		}
		else{
			rep(j,siz-2) ans+=pow(10,j);
		}
	}
	if(siz==1) ans--;
	cout << ans << endl;

	return 0;
}

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

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back
#define DEBUG(x) cout << #x << " = " << x << endl;

using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> inline T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

inline void proc_status ()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) << endl;
}

const int Maxn = 3e7 + 100;
const int Mod = 1e9 + 7;

int N = 1e7, M = 3e7;
int S, Len[Maxn], ans;

inline void Add (int &a, int b) { if ((a += b) >= Mod) a -= Mod; }

inline int Pow (int a, int b)
{
	int ans = 1;
	for (int i = b; i; i >>= 1, a = (LL) a * a % Mod) if (i & 1) ans = (LL) ans * a % Mod;
	return ans;
}

inline void Calc1 ()
{
	int r = 0, sum = 0;
	for (int l = 1; l < N; ++l)
	{
		while (sum < S) sum += Len[++r];
		if (sum == S) ++ans;
		sum -= Len[l];
	}
}

inline void Calc2 ()
{
	for (int i = 1; i <= S / 8; ++i)
		if (!(S % i)) Add (ans, ((LL) Pow (10, S / i - 1) * 9 % Mod - i + 1 + Mod) % Mod);
		else Add (ans, 1);
}

inline void Solve ()
{
	for (int i = 1; i <= M; ++i) Len[i] = Len[i / 10] + 1;

	Calc1 ();
	Calc2 ();
	cout << ans << endl;
}

inline void Input ()
{
	S = read<int>();
}

int main()
{

#ifdef hk_cnyali
	freopen("F.in", "r", stdin);
	freopen("F.out", "w", stdout);
#endif

	Input ();
	Solve ();

	return 0;
}


Measured memory_bytes: 117376
from bisect import bisect_left, bisect_right
from itertools import accumulate

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

ans=A_sum[N-1]
for m in range(2,N-1):
  sum_left=A_sum[m-1]
  i=bisect_left(A_sum,sum_left/2)
  sum1=A_sum[i]
  if i!=0:
    if A_sum[i]+A_sum[i-1]>sum_left:
      sum1=A_sum[i-1]
  sum2=sum_left-sum1

  sum_right=A_sum[N-1]-sum_left
  i=bisect_left(A_sum,sum_left+sum_right/2)
  sum3=A_sum[i]-sum_left
  if i!=m:
    if A_sum[i]+A_sum[i-1]-2*sum_left>sum_right:
      sum3=A_sum[i-1]-sum_left
  sum4=sum_right-sum3
  max_sum=max(sum1,sum2,sum3,sum4)
  min_sum=min(sum1,sum2,sum3,sum4)
  dif=max_sum-min_sum
  if dif<ans:
    ans=dif

print(ans)

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

#define int long long
//typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif



signed main() {
    string S;
    cin >> S;

    set<char> s;
    rep(i,S.size()) s.insert(S[i]);

    if(S.size()!=26){
        char add=0;
        for(char c = 'a'; c<='z'; c++){
            if(s.find(c)==s.end()){ add = c; break;}
        }
        S += add;
        cout << S << endl;
    }else{
        string T = S;
        if(!next_permutation(T.begin(), T.end())){
            cout << -1 << endl; return 0;
        }else{
            rep(i,T.size()){
                if(T.substr(0,i)>S){
                    cout << T.substr(0,i) << endl;
                    return 0;
                }
            }
        }
        
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main (){
  int h, w, i, hi, wi;
  int flag = 0;

  for ( i = 1; 1; i++){
    scanf("%d %d",&h, &w);
    if ( h ==0 && w == 0)
      break;

    for ( hi = 0; hi < h; hi++){
      if ( hi % 2 == 1){
        flag = 1;
      } else {
        flag = 0;
      }
      for ( wi = 0; wi < w; wi++){
        if (flag == 0){
          printf("#");
          flag = 1;
        } else {
          printf(".");
          flag = 0;
        }
      }
      printf("\n");
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 572
import collections

N = int(input())
D = list(map(int,input().split()))
D_counter = collections.Counter(D)
D_max = max(D)
ans = 1
if D[0] > 0:
    ans = 0
else:
    if D_counter[0] > 1:
        ans = 0
    for n in range(1,D_max+1):
        if D_counter[n] > 0:
            for d in range(D_counter[n]):
                ans = ans * D_counter[n-1]
                ans = ans % 998244353
        else:
            ans = 0
            break
print(ans)


Measured memory_bytes: 19936
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int[] b = new int[a];
		int c = Integer.MAX_VALUE;
		int d = Integer.MIN_VALUE;
		long e = 0;
		for (int i = 0; i < a; i++) {
			int f = scanner.nextInt();
			c = Math.min(c, f);
			d = Math.max(d, f);
			e += f;
		}
		System.out.println(String.format("%d %d %d", c, d, e));

	}
}



Measured memory_bytes: 41540
#include<cstdio>
using namespace std;
int tot,m,n,TT;
int wz[234234],rdt[234234],rd[234234],pd[234234],b[234234],sz[234234],dfn[234234];

void cnct(int x,int y)
{
	rd[++tot]=x,rdt[tot]=wz[y],wz[y]=tot;
	rd[++tot]=y,rdt[tot]=wz[x],wz[x]=tot;
}

void dfs(int x,int from)
{
  int t=wz[x];
  b[x]=1,dfn[x]=++TT;
  while(t)
    {
    	if(rd[t]!=from)
    	{
      if(b[rd[t]])
      {
      	if(dfn[rd[t]]<dfn[x])
	    sz[x]++,pd[t]=1;
	  }
	else
	{
		dfs(rd[t],x);
	  if(sz[rd[t]]%2!=0) 
	   {
	   	if(t%2==0) pd[t-1]=1;
	    else pd[t+1]=1;
	   }
	  else sz[x]++,pd[t]=1;
	  }
	}
	  t=rdt[t];
	}
}

int main()
{
int i,x,y;
  scanf("%d%d",&n,&m);
  for(i=1;i<=m;i++) 
    {
	  scanf("%d%d",&x,&y);
	  cnct(x,y);
	}
  dfs(1,0); 
  if(sz[1]%2!=0) {printf("-1\n");return 0;}
  for(i=1;i<=m*2;i+=2)
    {
	  if(pd[i]) printf("%d %d\n",rd[i+1],rd[i]);
	  else printf("%d %d\n",rd[i],rd[i+1]);
	}
}

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


int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int num = a*100 + b*10 + c;
  string ans = "NO";
  if(num%4 == 0) ans = "YES";
  cout << ans << endl;
  return 0;
  
}

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

#define ll long long

int main() {
  int N;
  cin >> N;
  
  map<string, ll> Map;
  
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    sort(S.begin(), S.end());
    Map[S]++;
  }
  
  ll ans = 0;
  auto Begin = Map.begin(), End = Map.end(); 
  for (auto s = Begin; s !=End; s++) {
    ans += s->second * (s->second - 1) / 2 ;
  }
  
  cout << ans << endl;
  
    

}

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

typedef long long ll;
const ll mod = 1e9 + 7;
using namespace std;

ll n, k;
ll f[100010];
ll power(ll a, ll b)
{
  return b?power(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1;
}
long long ans;
int main()
{
  cin >> n >> k;
  for(int i = k; i >= 1; i--)
  {
		f[i] = power(k/i, n);
    for(int j = 2*i; j <= k; j+=i)
    {
		f[i] -= f[j];
    }
    ans = (ans + i * f[i] % mod) % mod;
  }
  cout << (ans + mod) % mod << endl;
	return 0;
}

Measured memory_bytes: 4420
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll a[100050];
int main() {
    int n;
    scanf("%d",&n);
    int cnt  = 0;
    for (int i = 0; i <  n; i++) {
        scanf("%lld",&a[i]);
        if (a[i]&1) {
            cnt++;
        }
    }
    if (cnt&1) {
        printf("NO\n");
    }else {
        printf("YES\n");
    }
    return 0;;
}


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

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

void Bubble_Sort(int N, vector<int> &A, int &c){
  bool flag = true;

  while(flag){
    flag = false;
    for(int j = N-1; j > 0; j--){
      if(A.at(j) < A.at(j -1)){
        swap(A.at(j), A.at(j-1));
        flag = true;
        c++;
      }
    }
  }
}

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

  vector<int> A(N);
  rep(i, N){
    cin >> A.at(i);
  }

  int counter = 0;
  Bubble_Sort(N, A, counter);

  rep(i, N){
    cout << A.at(i);
    if(i != N-1) cout << " ";
    else cout << endl;
  }

  cout << counter <<endl;
}



Measured memory_bytes: 3112
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second


namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

vector<int>devisor(int n) {
	vector<int>value;
	FOR(i, 1, pow(n, 0.5) + 1) {
		if (n % i == 0) {
			value.push_back(i);
			if (i * i != n) {
				value.push_back(n / i);
			}
		}
	}
	return value;
}
int ans(int &gcd, vector<int>&devisor,vector<int>&a) {
	bool flag = true;
	int i = 0;
	while (flag) {
		int count = 0;
		rep(j, a.size()) {
			if (a[j] % devisor[i] != 0) {
				count++;
			}
			if (count >= 2) {
				break;
			}
		}
		if (count <= 1) {
			gcd = max(gcd, devisor[i]);
			flag = false;
		}
		else {
			i++;
		}
	}
	return gcd;
}

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(all(a));

	int b = a[0];
	int c = a[1];
	vector<int>div_b,div_c;
	div_b = devisor(b);
	div_c = devisor(c);
	sort(all(div_b));
	reverse(all(div_b));
	sort(all(div_c));
	reverse(all(div_c));
	int gcd = 1;
	int answer = max(ans(gcd, div_c, a), 
		ans(gcd, div_b, a));
	cout << answer << endl;

}


Measured memory_bytes: 640
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	s = chomp(readline())
	l = length(s)
	x = zeros(Int,26)
	x.+= l
	for i in 1:l
		x[Int(s[i])-96] = 0
	end
	for i in 97:122
		k = 0
		for j in 1:l
			if s[j] == Char(i)
				k = 0
			else
				k += 1
			end
			x[i-96] = max(k, x[i-96])
		end
	end
	println(minimum(x))
end
main()

Measured memory_bytes: 168272
#include <iostream>
#include <vector>

int calc(std::vector<int> a, const int count, const int i) {
  if (i >= (int)a.size()) {
    for (auto &v : a) {
      if (v % 2 == 0) {
        return count + 1;
      }
    }
    return count;
  }
  int c = count;
  --a.at(i);
  c += calc(a, count, i + 1);
  ++a.at(i);
  c += calc(a, count, i + 1);
  ++a.at(i);
  c += calc(a, count, i + 1);
  return c;
}

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  for (int i = 0; i < n; ++i)
    std::cin >> a.at(i);
  std::cout << calc(a, 0, 0) << std::endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define max 101

int main(){
  int n,u,k,i,j,num;
  int Adj[max][max]={0};
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&num);
      Adj[u][num]=1;
    }
  }
  for(i=1;i<=n;i++){
    for(j=1;j<=n-1;j++){
      printf("%d ",Adj[i][j]);
    }
    printf("%d\n",Adj[i][n]);
  }
  return 0;
}



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

using namespace std;

#define FOE(i, s, t) for (int i = s; i <= t; i++)
#define FOR(i, s, t) for (int i = s; i < t; i++)
#define FOD(i, s, t) for (int i = s; i >= t; i--)

#define LL long long
#define mp make_pair
#define pb push_back

#define M 998244353
#define K 300001

int n, _m, k;

LL fact[K], pw2[K], rev[K];

LL bigmod(LL a, LL p) {
	if (!p) return 1;
	
	LL t = bigmod(a, p >> 1);
	
	t = t * t % M;
	if (p & 1) t = t * a % M;
	
	return t;
}

LL c(LL n, LL k) {
	return fact[n] * rev[k] % M * rev[n - k] % M;	
}

int main() {
	scanf("%d%d%d", &n, &_m, &k);

	fact[0] = pw2[0] = 1;
	
	FOE(i, 1, n) {
		fact[i] = fact[i - 1] * i % M;
		pw2[i] = pw2[i - 1] * (_m - 1) % M;	
	}
	
	FOE(i, 0, n) rev[i] = bigmod(fact[i], M - 2);
	
	LL ret = 0;
	
	FOE(i, 0, k) {
		LL pu = n - i - 1;
		
		ret = (ret + (_m * pw2[pu] % M * c(n - 1, pu) % M)) % M;
	}
	
	cout << ret << endl;
}

Measured memory_bytes: 8336
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
 
public class Main {
    static List<Integer> list = new ArrayList<Integer>();
    static int x = 0;
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        x = sc.nextInt();
        int n = sc.nextInt();
 
        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }
        
        System.out.println(dfs(0));
    }
 
    private static int dfs(int n) {
        if (!(list.contains(x - n))) {
            return x - n;
        } else if (!(list.contains(x + n))) {
            return x + n;
        }
        return dfs(++n);
    }
}

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

using namespace std;

long long n,k,a,b,c,q[200005],nr,rs;
string s,x;

int main() 
{
    cin>>s;
    for (int i=0; i<s.size(); i++)
        rs = rs + (s[i]-48)%3;
    rs%=3;
    cout<< (rs==0 ? "Yes" : "No");
}

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

using namespace std;
typedef long long ll;
#define debug(x) cerr << x << "\n"
#define all(x) (x).begin(),(x).end()
#define exist(s, e)((s).find(e) != (s).end())

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    string s;
    int maxx = 0;
    int x = 0;
    cin >> n >> s;
    for(int i=0;i<n;i++) {
        if (s[i] == 'I') x++;
        else x--;
        if (x > maxx) maxx = x;
    }
    cout << maxx << '\n';

    return 0;
}

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

int main() {
	int Ah,Am,As, Bh,Bm,Bs;
	for (int i = 0; i < 3; i++) {
		cin >> Ah >> Am >> As >> Bh >> Bm >> Bs;
		int ans1, ans2, ans3;
		if (As > Bs) {
			ans3 = (Bs + 60) - As;
			Bm--;
		}
		else ans3 = Bs - As;
		if (Am > Bm) {
			ans2 = (Bm + 60) - Am;
			Bh--;
		}
		else ans2 = Bm - Am;
		ans1 = Bh - Ah;
		cout << ans1 << ' ' << ans2 << ' ' << ans3 << endl;
	}
}


Measured memory_bytes: 3096
from math import floor

def binary_search(A, key):
    left = 0
    right = len(A)

    while left < right:
        mid = (left + right) // 2
        # print("left, right, mid, key, A[mid]:", left, right, mid, key, A[mid])
        if A[mid] == key:
            return mid
        elif A[mid] > key:
            right = mid
        else:
            left = mid + 1
    return None



def main():
    n = int(input())
    S = list(map(int, input().split((' '))))
    q = int(input())
    T = list(map(int, input().split((' '))))

    ans = 0

    for key in T:
        # print("key:", key)
        if binary_search(S, key) is not None:
            ans += 1

    print(ans)

            

main()


Measured memory_bytes: 16772
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	int a = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1') {
			a++;
		}
	}
	cout << a << endl;
}


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

template<class E>
using nega_queue=priority_queue<E,vector<E>,greater<E>>;

UL N;
UL UF[100];
void unite(UL a,UL b){
 a=UF[a]; b=UF[b];
 rep(i,N) if(UF[i]==b) UF[i]=a;
}

int main() {
 scanf("%u",&N);
 nega_queue<pair<int,pair<UL,UL>>> G;
 rep(i,N) rep(j,N){
  int d; scanf("%d",&d);
  if(d!=-1) G.push({d,{i,j}});
 }
 int ans=0;
 rep(i,N) UF[i]=i;
 while(G.size()){
  int d=G.top().first;
  UL u=G.top().second.first;
  UL v=G.top().second.second;
  G.pop();
  if(UF[u]==UF[v]) continue;
  unite(u,v);
  ans+=d;
 }
 printf("%d\n",ans);
 return 0;
}



Measured memory_bytes: 3324
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;



int main(){
    int A,B; cin >> A >> B;
    cout << A*B << endl;
}

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

int main(){
    string str;
    cin >> str;
    sort(str.begin(),str.end());
    bool abc=true;
    for(int i=1;i<str.length();i++){
        if(str[i]==str[i-1]) abc=false;
    }
    if(abc) puts("yes");
    else puts("no");
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var N int
	fmt.Scan(&N)
	sc.Split(bufio.ScanWords)
	retMap := map[string]int{}
	for i := 0; i < N; i++ {
		str := nextLine()
		retMap[str]++
	}
	fmt.Println("AC x", retMap["AC"])
	fmt.Println("WA x", retMap["WA"])
	fmt.Println("TLE x", retMap["TLE"])
	fmt.Println("RE x", retMap["RE"])

}
func nextLine() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int64 {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return int64(i)
}
func MySort(a []int) {
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })

}
func SortedBinaryAppend(sortedArr []int, targetValue int) []int {
	return []int{}
}
func SortedBinaryDelete(sortedArr []int, targetValue int) []int {
	return []int{}
}
func SortedBinarySearch(sortedArr []int, targetValue int) int {
	post := len(sortedArr) - 1
	pre := 0
	for {
		div := (post + pre) / 2
		tim := sortedArr[div]
		if tim == targetValue {
			return pre + div
		} else if tim > targetValue {
			post = tim
		} else {
			pre = tim
		}
		if pre == post {
			return -1
		}
	}
}
func Abs(i int) int {
	if i < 0 {
		return -1 * i
	}
	return i
}
func Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func CalcNum(tate int, yoko int, A int, B int, dp *map[[2]int]int) int {
	if (*dp)[[2]int{tate, yoko}] != 0 {
		return (*dp)[[2]int{tate, yoko}]
	}
	return yoko*CalcNum(tate-1, yoko, A, B, dp) + tate*CalcNum(tate, yoko-1, A, B, dp)
}
func arrSum(arr []int) int {
	sum := 0
	for _, a := range arr {
		sum += a
	}
	return sum
}
func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}
func scanStrings(len int) (strings []string) {
	var str string
	for i := 0; i < len; i++ {
		fmt.Scanf("%s", &str)
		strings = append(strings, str)
	}
	return
}


Measured memory_bytes: 2140
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long int ll;

int main(){
	int n;
	cin >> n;
	vector<int> w(n + 1, 0);
	for(int i = 1; i <= n; i++){
		cin >> w[i];
		w[i] += w[i - 1];
	}
	int res = 1 << 30;
	for(int i = 0; i <= n; i++){
		res = min(res, abs(w[i] - (w[n] - w[i])));
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
	}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	int n,a,b,sum=0,tmp,ans=0;
    cin >> n >> a >> b;
    for(int i=1;i<=n;i++){
        tmp=i;
        while(tmp!=0){
            sum+=tmp%10;
            tmp/=10;
        }
        if(a<=sum && sum<=b) ans+=i;
        sum=0;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll n;cin>>n;
    ll a;cin>>a;
    ll b;cin>>b;
    vector<ll> x(n);
    For(i,0,n) cin>>x[i];
    For(i,0,n-1) ans+=min((x[i+1]-x[i])*a,b);
    cout<<ans<<endl;
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    int ans=0;
    int a,b,c,x;
    cin>>a>>b>>c>>x;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            if(500*i+100*j<=x&&(x-500*i-100*j)%50==0&&(x-500*i-100*j)/50<=c){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
H,W,K = map(int, input().split())

S = [input() for _ in range(H)]
ans = [[0 for _ in range(W)] for _ in range(H)]

# 左上から見ていった時に見つかったイチゴの個数
cnt_sb = 0
for i in range(H):
    # その行で見つかったイチゴの数
    cnt_sb_row = 0
    for j in range(W):
        # あるマスでいちごが　見つかった時
        if S[i][j] == "#":
            cnt_sb += 1
            cnt_sb_row += 1
        # ピースの番号。その行でイチゴが見つかっていない場合は今までに見つかったイチゴの数+1。（直前の行と被らないようにするため）
        # その行でイチゴが見つかっていれば、現時点で見つかったイチゴの数
        if cnt_sb_row == 0:
            ans[i][j] = cnt_sb + 1
        else:
            ans[i][j] = cnt_sb


    # ある行にイチゴがなかった場合は、上にあるピースに所属するよう修正する
    if cnt_sb_row == 0:
        # イチゴが一つでも見つかっている状態なら、丸っと一行同じにできる
        if cnt_sb != 0:
            ans[i] = ans[i-1]
        
    # 上から調べたときに、i行目で初めてイチゴが見つかった場合、
    # その時点では、iより上は全部同じピース扱いになっているので、i行目と同じように切り分ける
    if cnt_sb != 0 and cnt_sb == cnt_sb_row:
        for j in range(i):
            ans[j] = ans[i]

for i in range(H):
    print(*ans[i])

Measured memory_bytes: 7568
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

ll a[100001];
int d[100001];
vector<ll> v;
int main(){
    ll n,t,q;
    cin>>n>>t>>q;
    int pre=2;
    v.pb(LLONG_MIN);
    rep(i,n){
        cin>>a[i]>>d[i];
        if(pre==1&&d[i]==2){
            v.pb((a[i-1]+a[i])/2);
        }
        pre=d[i];
    }
    v.pb(LLONG_MAX);
    int x;
    rep(i,q){
        cin>>x;--x;
        if(d[x]==2){
            int cur=lower_bound(v.begin(),v.end(),a[x])-v.begin();
            if(a[x]-t>v[cur-1]) cout<<a[x]-t<<endl;
            else cout<<v[cur-1]<<endl;
        }
        else{
            int cur=upper_bound(v.begin(),v.end(),a[x])-v.begin();
            if(a[x]+t<v[cur]) cout<<a[x]+t<<endl;
            else cout<<v[cur]<<endl;
        }
    }
    return 0;
}


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

using namespace std;

int n, x;
vector<int> city;

int ans;

int main()
{
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);

    cin>>n>>x;
    city.push_back(x);

    int i;
    for(i=0; i<n; i++)
    {
        int t;
        cin>>t;
        city.push_back(t);
    }

    sort(city.begin(), city.end());

    for(i=1; i<=n; i++)
    {
        if(ans==0) ans=city[i]-city[i-1];
        else ans=__gcd(ans, city[i]-city[i-1]);
    }

    cout<<ans;
}


Measured memory_bytes: 892
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

int main()
{
    int a, b;
    cin >> a >> b;
    int dif = a - b;
    int ltall = dif * (dif - 1) / 2;
    cout << ltall - b << endl;
}

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

int main(void){
  long n, h, w;
  cin >> n >> h >> w;
  long a[n], b[n];
  for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
  int num = 0;
  for(int i = 0; i < n; i++){
    if(a[i] >= h && b[i] >= w) num++;
  }
  cout << num << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
#define llx(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
using namespace std;
long long n,m,i,ii,j,k,ans=1ll<<61,ans2,dep[105],x,y,ss,mx[105];
vector<long long> bi[105];
void dfs(int x,int fa)
{
	mx[dep[x]]=max(mx[dep[x]],(long long)bi[x].size()-(fa!=0));
	llx(bi[x],it)
	{
		if (*it==fa) continue;
		dep[*it]=dep[x]+1;
		dfs(*it,x);
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<n;i++)
	{
		 cin>>x>>y;
		 bi[x].push_back(y);
		 bi[y].push_back(x);
	}
	for (i=1;i<=n;i++)
	{
		dep[i]=1;
		memset(mx,0,sizeof(mx));
		dfs(i,0);
		for (j=1;mx[j];j++);
		if (j<ans)
		{
			ans=j;
			ans2=1ll<<61;
		}
		if (j==ans)
		{
			ss=1;
			for (k=1;k<j;k++) ss*=mx[k];
			if (ss<ans2) ans2=ss;
		}
	}
	for (i=1;i<=n;i++)
	{
		llx(bi[i],it)
		{
			ii=*it;
			dep[i]=dep[ii]=1;
			memset(mx,0,sizeof(mx));
			dfs(i,ii);
			dfs(ii,i);
			for (j=1;mx[j];j++);
			if (j<ans)
			{
				ans=j;
				ans2=1ll<<61;
			}
			if (j==ans)
			{
				ss=2;
				for (k=1;k<j;k++) ss*=mx[k];
				if (ss<ans2) ans2=ss;
			}
		}
	}
	cout<<ans<<' '<<ans2<<endl;
	return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

const int MAX_k = 200010;
const int mod = 998244353;
ll com[MAX_k];
ll fac[MAX_k], inv[MAX_k], finv[MAX_k];

void cominit(int n){
  com[0] = 1;
  com[1] = n;
  fac[0] = 1;
  fac[1] = n;
  inv[1] = 1;
  finv[0] = finv[1] = 1;
  rep(i, 2, MAX_k){
    fac[i] = fac[i-1]*(n-i+1) %mod;
    inv[i] = mod - inv[mod%i]*(mod/i) %mod;
    finv[i] = finv[i-1]*inv[i] %mod;
    com[i] = fac[i]*finv[i] %mod;
  }
}

ll modPow(int a, int n, int mod){
  if(n == 0)
    return 1;
  if(n%2 == 0){
    ll t = modPow(a, n/2, mod);
    return t*t%mod;
  }
  ll t = modPow(a, n-1, mod);
  return a*t%mod;
}

int main(){
  int n, m, k;
  cin >> n >> m >> k;
  
  ll ans = 0;
  
  cominit(n-1);
  
  rep(i, 0, k+1){
    ll t = m;
    t = t*com[i]%mod;
    t = t*modPow(m-1, n-i-1, mod)%mod;
    ans = (ans + t)%mod;
  }
  
  cout << ans << endl;
  
  return 0;
  
}

Measured memory_bytes: 9892