akhauriyash/Code-Regression huggingface dataset:
#include<set>  
#include<map>  
#include<cmath>  
#include<cstdio>  
#include<queue>
#include<vector>  
#include<cstring>  
#include<climits>  
#include<iostream>  
#include<algorithm>  
using namespace std; 
#define INF 0x3f3f3f3f
#define MAXN 100000
int read(){  
	int f=1,x=0;  
    char c=getchar();  
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}  
    while('0'<=c&&c<='9') x=x*10+c-'0',c=getchar();  
    return f*x;  
}
int ans=INF,d;
map<int,int> Map;
void DFS(int *a,int t)
{
	if(t>d)return ;
	int tmp=100*(a[2]-a[0])+10*(a[1]-a[0]),num[3];
	if(Map.count(tmp)){ans=min(ans,t+Map[tmp]);return ;} 
	num[0]=a[0]+2,num[1]=a[1],num[2]=a[2];
	sort(num,num+3);
	DFS(num,t+1);
	if(num[2]-num[0]<=2)
	{
		num[0]=a[0]+1,num[1]=a[1]+1,num[2]=a[2];
		sort(num,num+3);
		DFS(num,t+1);
	}
	return ;
}
int main(){
	Map[22]=1,Map[202]=1,Map[220]=1;
	Map[1]=1,Map[10]=1,Map[100]=1;
	Map[2]=2,Map[20]=2,Map[200]=2;
	Map[12]=3,Map[21]=3,Map[102]=3,Map[120]=3,Map[210]=3,Map[201]=3;
	Map[0]=0;
	int a[3];
	a[0]=read(),a[1]=read(),a[2]=read();
	if(a[0]==a[1]&&a[1]==a[2]) {printf("0\n"); return 0;}
	sort(a,a+3);
	d=(2*a[2]-a[0]-a[1])/2+2;
	DFS(a,0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
def main():
    mod = 10**9+7
    n = int(input())
    a, b, c, p = 1, 1, n, n-1
    for i in range(n-1):
        p = (p+a-1) % mod
        a, b, c = b, c, ((n-1)*(n-1)+p+c) % mod
    print(c)


main()


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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define INF 1e9
// const ll INF = 1LL << 60;

int main(){
  int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  cout << a[K-1] << endl;
  return 0;
}



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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

ll dp[MX][MX];
inline void chmax(ll& a, ll b) {
  a = max(a, b);
}

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back


int main(){
    ll x;
    cin >> x;
    
    vector<ll> v(1000);
    rep(i, 1000) v.at(i) = pow(i, 5);
    bool ans = false;
    
    rep(i, 1000){
        if (ans) break;
        ll a = abs(x - v.at(i));
        auto itr = find(v.begin(), v.end(), a);
        if (itr != v.end()) {
            int index = distance(v.begin(), itr);
            if (x - v.at(i) > 0) {
                index *= -1;
            }
            cout << i << " " << index << endl;
            ans = true;
        }
    }
}

Measured memory_bytes: 4120
#include<stdio.h>
int main()
{
  int N,a[110];
  scanf("%d",&N);
  for(int i=1;i<=N;i++){scanf("%d",&a[i]);}
  
  int ans=0;
  for(int i=1;i<=N;i+=2){
    if(a[i]%2==1) ans++;
  }
  printf("%d",ans);
}

Measured memory_bytes: 1680
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,m,i;
    cin>>n>>m;
    ll x[m];
    for (i=0;i<m;i++)
        cin>>x[i];
    sort(x,x+m);
    vector<ll> y;
    for (i=0;i<m-1;i++)
        y.pb(x[i+1]-x[i]);
    sort(y.rbegin(),y.rend());
    ll sum=0;
    for (i=0;i<n-1 && i<m-1;i++)
        sum+=y[i];
    cout<<x[m-1]-x[0]-sum<<endl;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 +5;
const int MOD=1e9+7;
int a[N]={0},ans[N]={0};

int main(){
	int n;
	string s;
	cin>>n>>s;
	for(int i=0;i<s.size();i++){
		s[i]=s[i]+n;
		if(s[i]>'Z') s[i]=s[i]-'Z'+'A'-1;
	}
	cout<<s;
}

Measured memory_bytes: 256
#include<iostream>
 #include<stdio.h>
 #include<cstdlib>
 #include<cstdio>
 #include<string>
 #include<math.h>
 #include<time.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<fstream> 
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 #include<list>
 #include<memory>
 
 using namespace std;


 int main()
 {
   int n,k;
   
   while(cin>>n>>k)
   {
     int arr[200000+5]={0};
     for(int i=0;i<n;i++)
     { 
       int temp;
       cin>>temp;
       arr[temp]++;
     }   
     int cnt=0;
     for(int i=1;i<=n;i++) if(arr[i]) cnt++;
     if(k>=cnt) cout<<"0"<<endl;
     else
     {
       sort(arr,arr+(n+1));
       int left=(cnt-k);
       //cout<<left<<endl;
       int result=0;
       bool flag=false;
       //for(int i=0;i<=n;i++) cout<<arr[i]<<" ";
       //cout<<endl;
       for(int i=1;i<=n;i++)
       {
         if(arr[i])
         {
           left--;
           result=result+arr[i];
           if(left==0) 
           {
             flag=true;            
           }          
         }        
         if(flag) break;
       }    
       cout<<result<<endl;
     }
   }
   return 0;
 }
 

       

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

int main(){
  int n, d, hoge;
  cin >> n >> d;
  d = 2*d + 1;
  for (int i = 1; i <= n; i++){
    if(d*i >= n){
      hoge = i;
      break;
    }
  }

  cout << hoge << endl;
  
}

Measured memory_bytes: 256
/*
.   Bismillahir Rahmanir Rahim
.   Author - Marajul islam
.   created- Sat Mar 28 17:56:18 2020

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


 
int sc1() {int x; scanf("%d", &x); return x;}
long long sc2() {long long x; scanf("%lld", &x); return x;}

const int mod= 1e9 + 7;
inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (long long)a * b % mod;}
 
#define F               first
#define S               second 
#define mp              make_pair
#define pb              push_back
#define pf              push_front
#define speed_up        ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x)           (int)x.size()
#define all(x)          x.begin(), x.end()
#define debug           cerr << "OK\n";
#define ub              upper_bound
#define lb              lower_bound
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a*b)/gcd(a,b)
#define Int             sc1()
#define LL              sc2()
#define For(n)          for(int i=0;i<n;i++)
#define Forj(n)         for(int j=0;j<n;j++)
#define Fork(n)         for(int k=0;k<n;k++)
#define For1(n)         for(int i=1;i<=n;i++)

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef set <int>       si;
typedef set <ll>        sll;
typedef multiset <int>  msi;
typedef multiset <ll>   msll;
typedef map <int, int>  mi;
typedef map <ll, ll>    mll;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ", ";
    err(++it, args...);
}
  
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 5e6 + 5;
 
 
 
int solve() {
 
	ll n=Int;

	ll x=n%500;
	ll x2=n/500;
	ll ans=x2*1000;
	ll x3=x/5;
	ll x4=x3*5;
	// cout<<x4<<endl;
	cout<<ans+x4<<endl;

 
	return 0;
}
 
 
 
 
int main()
{
	//speed_up;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
 
	int test = 1, tc = 0;
	//scanf("%d", &test);
	//cin >> test;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
 
	return 0;
 
 
 
 
}




Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;
typedef int keytype;

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

/* a[0], ..., a[n-1] の数の最大公約数 */
int ngcd(int n, int a[])
{
    int i, d;

    d = a[0];
    for (i = 1; i < n && d != 1; i++)
        d = gcd(a[i], d);
    return d;
}

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int is_prime(int x){
    if(x <= 1) return 0;
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0) return 0;
    }
    return 1;
}

int is_substr(char s[], char t[], int i){
    int flag = 1;

    if(s[i] == '\0') flag = 0;

    for(int j = 0; j < strlen(t); ++j, ++i){
        if(s[i] != t[j]){
            flag = 0;
            break;
        }
    }
    return flag;
}

// factor list, number of factors, natural number
void factorize(int ftr[], int *num, int n){
    int a = 2, cnt = 0;

    while(n >= a){
        if(n % a == 0){
            n = n / a;
            ftr[cnt++] = a;
        }else{
            a++;
        }
    }
    *num = cnt;
}

//#define N 5
//int p[N + 1];
int nextperm(int p[], int N)  /* 辞書式順序で次の順列 */
{
    int i, j, t;

    i = N - 1;
    p[0] = 0;  /* 番人 */
    while (p[i] >= p[i + 1]) i--;
    if (i == 0) return 0;  /* 完了 */
    j = N;
    while (p[i] >= p[j]) j--;
    t = p[i];  p[i] = p[j];  p[j] = t;
    i++;  j = N;
    while (i < j) {
        t = p[i];  p[i] = p[j];  p[j] = t;  i++;  j--;
    }
    return 1;  /* 未了 */
}

void comb(int size1, int size2, int v[size1][size2]){
  for(int i = 0; i < size1; i++){
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for(int k = 1; k < size1; k++){
    for(int j = 1; j < k; j++){
      v[k][j] = (v[k-1][j-1] + v[k-1][j]);
    }
  }
}

int abs_val(int a, int b){
    if(a > b) return a - b;
    else return b - a;
}

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

const int inf = 1012345678;
int main(){
    int a, b;

    scanf("%d %d", &a, &b);

    if((a % 2) == 1 && (b % 2) == 1) puts("Yes");
    else puts("No");

    return 0;
}


Measured memory_bytes: 1572
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, a;
  cin >> n;
  int ans = 0;
  for(int i = 0; i < n; i++){
    cin >> a;
    for(;a % 2 == 0;a /= 2)ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define   vpll   vector<pll >
#define   all(x) x.begin(),x.end()
#define   present(c,x)    ((c).find(x) != (c).end())
#define   dbg(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){
  std::cerr << name << " = " << arg1 << "\n";
}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    std::cerr.write(names, comma - names) << " = " << arg1;
    ZZ(comma, args...);
}
#define   sz(a)  a.size()
#define   vll vector<int>
#define   pll pair<int,int>
#define   ff  first
#define   ss  second
#define   br  cout<<"\n";
#define   ld  long double
#define   int  long long int
const int  INF = 1e18+7;
const int  MAX = 1234567;
const int  MOD = 1000000007;



void solve(){
    int a ;
    string s ;
    cin >> a >> s ;
    if ( a < 3200 )
    	cout << "red";
    else
    	cout << s ;
}
int32_t main(){
    int t;
    t=1;
    cin.sync_with_stdio(0), cin.tie(0);
    //cin>>t;
    while(t--){
        solve();
        br;
    }
    return 0;
}
 
 
 
 
 
 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main(void)
{
	int num, a, b;
	char student[100000]= {};
	int  totalcount= 0, bcount= 0;

	cin>>num>>a>>b>>student;
	for(int i= 0; i < num; i++)
	{
		switch(student[i])
		{
		case 'a':
			if(totalcount < a+b)
			{
				cout<<"Yes"<<endl;
				totalcount++;
			}
			else
				cout<<"No"<<endl;
			break;
		case 'b':
			if(totalcount < a+b && bcount < b)
			{
				cout<<"Yes"<<endl;
				totalcount++;
				bcount++;
			}
			else
				cout<<"No"<<endl;
			break;
		case 'c':
			cout<<"No"<<endl;
			break;
		}
	}
	return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define all(a) a.begin(), a.end()

typedef long long lint;

const int maxn = (int)1e5 + 9;

char a[maxn], b[maxn];
vector<int> pos[26];

int main() {
    scanf("%s%s", a, b);
    int an = strlen(a);
    int bn = strlen(b);
    rep(i, an) {
        pos[a[i] - 'a'].push_back(i);
    }
    rep(i, bn) {
        char ch = b[i];
        if (pos[ch - 'a'].size() == 0) {
            printf("-1\n");
            return 0;
        }
    }
    lint ans = 0LL;
    rep(i, bn) {
        char ch = b[i];
        auto p = lower_bound(all(pos[ch - 'a']), ans % an);
        if (p == pos[ch - 'a'].end()) {
            auto rp = lower_bound(all(pos[ch - 'a']), 0);
            ans = 1LL * ((ans / an) + 1LL) * an + *rp + 1;
        } else {
            ans = 1LL * (ans / an) *an + 1LL * (*p) + 1;
        }
    }
    printf("%lld\n", ans);
}


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


int main() {
  uint64_t x1,x2,y1,y2;
  uint64_t S;
  cin >> S;
  double rs = sqrt((double)S);
  uint64_t irs = rs;
  int64_t sub1;
  x1 = irs;
  y2 = irs;
  sub1 = x1 * y2 - S;
  if ( sub1 < 0 ) {
    y2 = irs+1;
    sub1 = x1 * y2 - S;
  }
  if ( sub1 < 0 ) {
    x1 = irs + 1;
    sub1 = x1 * y2 - S;
  }
  if ( sub1 == 0 ){
    x2 = 0;
  } else {
    x2 = 1;
  }
  y1 = sub1;

  cout << "0 0 " << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define mod 1000000007

int main() 
{
    ll n,m;
    cin>>n>>m;
    char a[n+1][m+1];
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        cin>>a[i][j];
    }
    ll dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            if(i==1 && j==1)
            dp[i][j]=1;
            else if(a[i][j]=='.')
            dp[i][j]=((dp[i-1][j])%mod+(dp[i][j-1])%mod)%mod;
        }
    }
    // for(ll i=1;i<=n;i++)
    // {
    //     for(ll j=1;j<=m;j++)
    //   cout<<dp[i][j]<<" ";
    //   cout<<endl;
    // }
    
    cout<<dp[n][m]%mod;
	return 0;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
#include<math.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define INF 2000000000
#define Min(a,b) (a<b?a:b)
#define Max(a,b) (a>b?a:b)
#define PI 3.1415926535897932
using namespace std;






int main()
{
int n;
    cin >> n;
    int h[n];
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }	
    int dp[n] = {};
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; i++)
    {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n - 1] << '\n';
	return 0;

return 0;
}



Measured memory_bytes: 1024
#C
n,m = map(int, input().split())
ab = [[int(i) for i in input().split()] for i in range(n)]

ab.sort(key=lambda x:x[0])
cost = 0
for i in range(n):
    value = ab[i][0]
    num = ab[i][1]
    if num> m:
        cost += value*m
        break
    else:
        cost += value*num
        m -= num
print(cost)

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

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

    long long int ans = 1001001001001;
    for(int bit = 0; bit < (1 << n); bit++){
        long long int coans = 0;
        int colornum = 0;
        int height = 0;
        for(int i = 0; i < n; i++){
            if(bit & (1 << i)){
                colornum++;
                if(a[i] > height){
                    height = a[i];
                }else{
                    coans += height-a[i]+1;
                    height++;
                }
            }else{
                if(height < a[i]) height = a[i];
            }
        }
        
        if(colornum >= k && coans < ans) ans = coans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "7 3", "3 2 2" ].parse.expand.solve == 0 );
	assert( [ "6 3", "1 4 1" ].parse.expand.solve == 1 );
	assert( [ "100 1", "100" ].parse.expand.solve == 99 );
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto kt = input.front.split.to!( long[] );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( kt[ 0 ], as );
}

auto solve( long k, long[] as )
{
	as.sort!( ( x, y ) => y < x );
	
	auto ans = 0L;
	auto a1 = as.front;
	as.popFront;
	foreach( a2; as )
	{
		a1 = ( a1 - a2 ).abs;
	}
	if( 0 < a1 ) ans += a1 - 1;
	return ans;
}


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

int b = 1'000'000'007;
int h1 = 1'100'023'409;
int h2 = 1'200'017'417;
int h3 = 1'500'026'741;

long long modpow(long long x, long long y, long long p){
    if (y == 0) return 1;
    if (y % 2) return x * modpow(x, y - 1, p) % p;
    return modpow(x, y / 2, p) * modpow(x, y / 2, p) % p;
}

void set_hash(string s, vector<vector<long long>> &hash){
    for (int i = 0; i < 3; i++) hash[i][0] = 0;
    for (int i = 0; i < s.size(); i++) hash[0][i + 1] = (hash[0][i] * b + s[i]) % h1;
    for (int i = 0; i < s.size(); i++) hash[1][i + 1] = (hash[1][i] * b + s[i]) % h2;
    for (int i = 0; i < s.size(); i++) hash[2][i + 1] = (hash[2][i] * b + s[i]) % h3;
}

bool check_equal(vector<vector<long long>> &hash_s, vector<vector<long long>> &hash_t, int &x, int &x_length){
    int cnt = 0;
    if (hash_s[0].back() == (hash_t[0][x + x_length] - hash_t[0][x] * modpow(b, x_length, h1) % h1 + h1) % h1) cnt++;
    if (hash_s[1].back() == (hash_t[1][x + x_length] - hash_t[1][x] * modpow(b, x_length, h2) % h2 + h2) % h2) cnt++;
    if (hash_s[2].back() == (hash_t[2][x + x_length] - hash_t[2][x] * modpow(b, x_length, h3) % h3 + h3) % h3) cnt++;
    if (cnt == 3) return true;
    return false;
}

vector<int> root;
vector<int> ranks;

int find(int x){
    if (root[x] == x) return x;
    root[x] = find(root[x]);
    return root[x];
}

bool check(int x, int y){
    return find(x) == find(y);
}

bool Union(int x, int y){
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (ranks[x] >= ranks[y]) root[y] = x;
    else root[x] = y;
    if (ranks[x] == ranks[y]) ranks[x]++;
    return true;
}

int main(){
    string s, t;
    cin >> s >> t;
    string new_s = s;
    while (new_s.size() < s.size() + t.size()) new_s += s;
    vector<vector<long long>> hash_s(3, vector<long long>(new_s.size() + 1));
    vector<vector<long long>> hash_t(3, vector<long long>(t.size() + 1));
    set_hash(new_s, hash_s);
    set_hash(t, hash_t);
    vector<int> roots(s.size());
    for (int i = 0; i < s.size(); i++) roots[i] = i;
    root = roots;
    vector<int> rankz(s.size(), 0);
    ranks = rankz;
    vector<bool> ok(s.size(), false);
    bool flag = false;
    int t_size = t.size();
    for (int i = 0; i < s.size(); i++){
        if (check_equal(hash_t, hash_s, i, t_size)) ok[i] = true, flag = true;
    }
    for (int i = 0; i < s.size(); i++){
        if (ok[i] && ok[(i + t.size()) % s.size()]){
            if (!Union(i, (i + t.size()) % s.size())){
                cout << - 1 << endl;
                exit(0);
            }
        }
    }
    for (int i = 0; i < s.size(); i++) find(i);
    sort(root.begin(), root.end());
    int ans = 0;
    int tmp = 0;
    int now = 0;
    for (int i = 0; i < s.size(); i++){
        if (root[i] != now){
            ans = max(ans, tmp);
            tmp = 0;
            now = root[i];
        }
        tmp++;
    }
    ans = max(ans, tmp);
    if (!flag) cout << 0 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 59500
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

ll n, m; 
vector<pair<ll, ll> > edg[1002];
ll d[1002];
bool neg[1002];

int main() {
	cin >> n >> m;
	for (ll i = 0; i < m; i++) {
		ll a, b, c; cin >> a >> b >> c;
		a--; b--;
		edg[a].push_back({b, -c});
	}
	

	for (int i = 0; i < n; i++) d[i] = 1e18;
	d[0] = 0;
	for (int i = 0; i < 2*n; i++) {
		for (int j = 0; j < n; j++) {
			for (auto p : edg[j]) {
				ll to = p.first, c = p.second;
				if (d[to] > d[j] + c) {
					d[to] = d[j] + c;
					if (i >= n - 1) neg[to] = true;
				}
			}
		}
	}	
	if (neg[n - 1]) cout << "inf" << endl;
	else cout << -d[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 384
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	K, X := getInt(), getInt()

	if 500*K >= X {
		out("Yes")
	} else {
		out("No")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}
// 1次元 vector
template <class T>
ostream &operator<<(ostream &s, vector<T> vec) {
    for (int i = 0; i < (int)vec.size(); ++i) {
        if (i > 0) {
            s << " ";
        }
        s << vec[i];
    }
    return s << endl;
}
template <class T>  // 2次元 vector
ostream &operator<<(ostream &s, vector<vector<T>> vec2) {
    for (int i = 0; i < (int)vec2.size(); ++i) {
        s << vec2[i];
    }
    return s;
}
using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

ll c(int i, int k, const vector<ll> &A) {
    if (k == 0 || k == 4) {
        return A[i];
    } else if (k == 1 || k == 3) {
        if (A[i] == 0) {
            return 2;
        } else {
            return A[i] % 2;
        }
    } else if (k == 2) {
        return (A[i] + 1) % 2;
    }
    return INF;
}
int main() {
    int L;
    cin >> L;
    vector<ll> A(L);
    for (int i = 0; i < L; i++) {
        cin >> A.at(i);
    }

    vector<vector<ll>> dp(L + 1, vector<ll>(5, 1e18));
    for (int i = 0; i < 5; i++) {
        dp[0][i] = 0;
    }

    for (int i = 0; i < L; i++) {
        for (int j = 0; j < 5; j++) {
            for (int k = j; k < 5; k++) {
                chmin(dp[i + 1][k], dp[i][j] + c(i, k, A));
            }
        }
    }
    cout << min(dp[L][0], min(dp[L][1], min(dp[L][2], min(dp[L][3], dp[L][4])))) << endl;
}


Measured memory_bytes: 15872
n, q = map(int, input().split())
s = input()
lr = []
for i in range(q):
    l, r = map(int, input().split())
    lr.append([l, r])

b = [0]
for j in range(n-1):
    if s[j] == 'A' and s[j+1] == 'C':
        b.append(b[j] + 1)
    else:
        b.append(b[j])
for i in range(q):
    l, r = lr[i]
    print(b[r-1] - b[l-1])

Measured memory_bytes: 22924
<?php 

$l = explode(" ", trim(fgets(STDIN)) );

$a = $l[0];
$b = $l[1];
$c = $l[2];
$d = $l[3];

$max = $a * $c;

if( $max < $a * $d ){
    $max =  $a * $d;
}
if( $max < $b * $c ){
    $max =  $b * $c;
}
if( $max < $b * $d ){
    $max =  $b * $d;
}

print $max;


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

int main() {
    int n;
    cin >> n;
    vector<pair<long double,string>> p(n);
    for(int i = 0; i < n; i++){
        double a;
        string b;
        cin >> a >> b;
        p.at(i) = make_pair(a,b);
    }
    double sum = 0;
    for(int i = 0; i < n; i++){
        if(p.at(i).second == "JPY"){
            sum = sum + p.at(i).first;
        } else {
            sum = sum + p.at(i).first * 380000;
        }
    }
    cout << fixed << setprecision(12) << sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i, j;
	cin >> num;
	vector<int> d(num), a(num), b(num);
	rep(i, num)
		cin >> d[i];
	rep(j, num){
		i = d[j] - 1;
		a[i] = 20001 * (i + 1);
		b[i] = 20001 * (num - i) + j;
	}
	rep(i, num - 1)
		cout << a[i] << " ";
	cout << a[i] << "\n";
	rep(i, num - 1)
		cout << b[i] << " ";
	cout << b[i] << "\n";
	return 0;
}

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

typedef long long ll;

int main()
{
	int n;	
	cin>>n;
	ll dp[n+1][3];
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		dp[i][0] = a + max(dp[i-1][2],dp[i-1][1]);
		dp[i][1] = b + max(dp[i-1][0],dp[i-1][2]);
		dp[i][2] = c + max(dp[i-1][0],dp[i-1][1]);
	}
	cout<<max(dp[n][0], max(dp[n][1],dp[n][2]));
}

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

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

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n;cin>>n&&n;){
		vl res(max(n+1,2));
		res[0]=2,res[1]=1;
		repi(i,2,n+1) res[i]=res[i-1]+res[i-2];
		cout<<res[n]<<endl;
	}
}


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

int n , a[200001] , b[200001] , k;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = n; i > 0; i--){
        int sum = 0;
        for (int j = i + i; j <= n; j += i) sum += b[j];
        sum %= 2;
        if (sum != a[i]) b[i] = 1, k++;
    }
    cout << k << "\n";
    for (int i = 1; i <= n; i++) if (b[i]) cout << i << " ";
}


Measured memory_bytes: 2432
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
vector<ll> tree[1010];
ll dp[1010] = {};
ll X[1010];
void dfs(ll cur, ll par){
    vector<ll> nxt(X[cur]+1, INF);
    nxt[0] = 0;
    for(auto &e: tree[cur]){
        if(e == par) continue;
        dfs(e, cur);
        vector<ll> prv(X[cur]+1);
        rep(i,0,X[cur]+1) prv[i] = nxt[i];
        nxt.assign(X[cur]+1, INF);
        rep(v,0,X[cur]+1){
            if(v + dp[e] <= X[cur] && prv[v] < INF){
               nxt[v + dp[e]] = min(nxt[v + dp[e]], prv[v] + X[e]); 
            }
            if(v + X[e] <= X[cur] && prv[v] < INF){
                nxt[v + X[e]] = min(nxt[v + X[e]], prv[v] + dp[e]);
            }
        }
    }
    ll res = INF;
    rep(i,0,X[cur]+1) res = min(res, nxt[i]);
    dp[cur] = res;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll P[1010];
    rep(i,0,N-1){
        cin >> P[i];
        P[i]--;
        tree[P[i]].push_back(i+1);
    }
    rep(i,0,N) cin >> X[i];
    rep(i,0,N) dp[i] = INF;
    dfs(0, -1);
    if(dp[0] != INF){
        print("POSSIBLE");
    }else{
        print("IMPOSSIBLE");
    }

}

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

int main(){
    int n,k;
    cin >> n >> k;
    int ans = 1;
    for(int i = 0;i<n;i++){
        if(ans < k){
            ans *= 2;
        }else{
            ans += k;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> v(n), c(n);
  int ans = 0;
  rep(i, n) cin >> v[i];
  rep(i, n) cin >> c[i];
  rep(i, n) ans += max(0, v[i] - c[i]);
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  int N,K;
  cin>>N>>K;

  int P[N];

  rep(i,N){
    cin>>P[i];
  }

  set<int> st;

  rep(i,K){
    st.insert(P[i]);
  }

  int allsho=0;
  bool nochan=false;
  ll ct=N-K+1;
  int itti=1;

  rep(i,K){
    if(i!=0){
      if(P[i-1]<P[i]) itti++;
      else itti=1;
    }
    if(itti>=K) nochan=true;
  }

  rep(i,N-K){
    bool ok=true;
    if(*st.begin()!=P[i]) ok=false;
    st.insert(P[i+K]);
    st.erase(P[i]);
    if(*--st.end()!=P[i+K]) ok=false;

    bool ok2=false;
    if(P[i+K-1]<P[i+K]) itti++;
    else itti=1;
    if(itti>=K){
      if(nochan) ok2=true;
      nochan=true;
    }

    ct-= (ok or ok2);
  }

  cout<< ct<<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 10368
#include "bits/stdc++.h"
using namespace std;

struct cust {
	int  m;
	int l;
	int k;
};
 
struct query {
	int type;
	int time;
	int id;
};
struct aa {
	int id;
	int time;
};
class Compare {
public:
	bool operator()(const query&l,const query&r) {
		return l.time==r.time?l.type==r.type?l.id>r.id:l.type>r.type:l.time > r.time;
	}
	bool operator()(const aa&l, aa&r) {
		return l.time > r.time;
	}
};

bool check(const int T, const vector<cust>&cus, const int n) {
	int waitnum = n;
	priority_queue<query,vector<query>,Compare>que;
	set<int>waits;
	for (int i = 0; i < cus.size(); ++i) {
		que.push(query{ 0,0,i });
	}
	while (!que.empty()) {
		query q(que.top());
		que.pop();
		 if (q.type == 0) {
			const int cid = q.id;
			if (waitnum) {
				waitnum--;
				const int nexttime = q.time + cus[cid].m;
				if (nexttime <= T) {
					que.push(query{ 1,nexttime,0 });
				}else {
					return false;
				}
			}
			else {
				waits.emplace(cid);
				const int nexttime = q.time + cus[cid].l;
				que.push(query{ 2,nexttime,cid });
			}
		}else if (q.type == 1) {
			auto it = waits.begin();
			if (it == waits.end()) {
				waitnum++;
			}
			else {
				const int cid = *it;
				const int nexttime = q.time + cus[cid].m;
				if (nexttime <= T) {
					waits.erase(it);
					que.push(query{ 1,nexttime,0 });
				}
				else {
					return false;
				}
			}
		}else if (q.type == 2) {
			const int cid = q.id;
			auto it = waits.find(cid);
			if (it!=waits.end()) {
				waits.erase(it);
				const int nexttime = q.time + cus[cid].k;
				if (nexttime <= T-cus[cid].m) {
					que.push(query{ 0,nexttime,cid });
				}
				else {
					return false;
				}
			}
		}
	}
	return true;
}

int main() {
	while (1) {
		int N, T; cin >> N >> T;
		if (!N)break;
		vector<cust>cus;
		int totalm = 0;
		for (int i = 0; i < N; ++i) {
			int m, l, k; cin >> m >> l >> k;
			totalm += m;
			cus.push_back(cust{ m,l,k });
		}
		int amin = (totalm-1) / T + 1;
		for (int n = amin; n <= N; ++n) {
			if (check(T, cus, n)) {
				cout << n << endl;
				break;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 3128
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    string s;cin>>s;
    int n = SIZE(s);
    REP(i,n){
        s[i] -= '0';
    }

    int result1 = 0;
    REP(i,n){
        if(s[i] != i%2){
            result1 ++;
        }
    }

    int result2 = 0;
    REP(i,n){
        if(s[i] != (i+1)%2){
            result2 ++;
        }
    }

    cout<<min(result1,result2)<<endl;
    
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 3748
#include <stdio.h>

int sum(int start, int end) {
  int rslt = 0;
  while (start < end) {
    rslt += start++;
  }
  return rslt;
}

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

  if (l < 0 && n+l > 0) {
    printf("%d\n", sum(l, l+n));
    return 0;
  }
  if (l < 0) {
    printf("%d\n", sum(l, l+n-1));
  } else {
    printf("%d\n", sum(l+1, l+n));
  }
  return 0;

}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = l[0], B = l[1], C = l[2];
            var K = int.Parse(Console.ReadLine());

            var max = Math.Max(A, Math.Max(B, C));

            var afVal = max;
            for (var i = 0; i < K; i++)
            {
                afVal *= 2;
            }

            var total = A + B + C;
            if (A == max)
                total -= A;
            else if (B == max)
                total -= B;
            else if (C == max)
                total -= C;

            total += afVal;

            Console.WriteLine(total);
        }
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef priority_queue<int> Pr; typedef vector<int> V; typedef vector<P> Vp; typedef map<int,int> MP;
const int mod = 1000000007; const Int INF = 1145141919810893931;
#define END {cout<<ans<<'\n'; return 0;}
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    Int n,m,ans=0; cin>>n>>m;
	if(n>0){
		if(m>0){
			if(n>m)ans=n-m+2;
			else ans=m-n;
		}else if(m==0){
			ans=n-m+1;
		}else{
			ans=abs(n+m)+1;
		}
	}else if(n==0){
		if(m>=0)ans=m-n;
		else ans=n-m+1;
	}else{
		if(m>0){
			ans=abs(n+m)+1;
		}else if(m==0){
			ans=m-n;
		}else{
			if(n>m)ans=n-m+2;
			else ans=m-n;
		}
	}
	END
}

Measured memory_bytes: 256
a,b = map(int,input().split())
s = input()
if len(s) == a + b + 1 and s[a] == "-":
    s = s.replace("-","")
    if s.isdecimal() and len(s) == a + b:
        print("Yes")
    else:
        print("No")
else:
    print("No")

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

#define infi            5e9
#define infl            5e18
#define MX              100005
#define pi              2*acos(0.0)
#define ll              long long int
#define rr              read()
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define ms(a,b)         memset(a, b, sizeof(a))
#define loop(i,n)       for(register int i=0;i<n;i++)
#define pool(i,n)       for(register int i=n-1;i>=0;i--)
#define loop1(i,n)      for(register int i=1;i<=n;i++)
#define pool1(i,n)      for(register int i=n;i>0;i--)

using namespace std;

inline ll read(){char c=getchar();ll num,sign=1;for(;c<'0'||c>'9';c=getchar())if(c=='-')sign=-1;for(num=0;c>='0'&&c<='9';){c-='0';num=num*10+c;c=getchar();}return num*sign;}
inline ll pw(ll b, ll p){ll ans=1;while(p>0){if(p&1)ans*=b;p>>=1;b*=b;}return ans;}
inline bool isPrime(ll n){if(n==1)return false;if(n==2)return true;if(!(n%2))return false;for(ll i=3;i<=sqrt(n);i+=2)if(!(n%i))return false;return true;}
inline ll gcd(ll a, ll b){if(a==0)return b;return gcd(b%a,a);}

// //*************************************  Bitmask Opereations  **********************************//
// int Set(int N,int pos){return N=N | (1<<pos);}
// int reset(int N,int pos){return N= N & ~(1<<pos);}
// bool check(int N,int pos){return (bool)(N & (1<<pos));}
// //********************************************************************************************//


int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    //#ifdef rid.dle//freopen("in.txt", "r", stdin);//#endif
    //freopen("in.txt", "r", stdin);

    int w=rr,h=rr,n=rr;
    
    int max_x=w,min_x=0,max_y=h,min_y=0;
    int x,y,a;
    loop(i,n){
        x=rr;y=rr;a=rr;
        if(a==1)min_x = max(min_x,x);
        else if(a==2)max_x = min(max_x,x);
        else if(a==3)min_y = max(min_y,y);
        else if(a==4)max_y = min(max_y,y);
    }
    if(max_x<=min_x || max_y<=min_y)cout << 0 << endl;

    else cout << abs(max_x-min_x) * abs(max_y-min_y) << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


int main(){
	int n,a[M],b[M];
	cin>>n;
	rep(i,0,n+1)cin>>a[i];
	rep(i,0,n)cin>>b[i];
	ll ans=0;
	rep(i,0,n){
		if(a[i]>=b[i])ans+=b[i];
		else{
			ans+=b[i];
			int div=b[i]-a[i];
			a[i+1]-=div;
			if(a[i+1]<0){
				ans+=a[i+1];
				a[i+1]=0;
			}
		}
	}
	print(ans);
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <set>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main(void){
    cin.tie(0);
   	ios::sync_with_stdio(false);
	string a, b;
	cin >> a >> b;
	int x = a.length(), y = b.length();
	if(x>y)
		cout << "GREATER" << endl;
		else if(x<y)
			cout << "LESS" << endl;
			else{
				int i;
				for (i = 0; i < x;i++){
					if(a[i]-'0'>b[i]-'0'){
						cout << "GREATER" << endl;
						break;
					}
					else if(a[i]-'0'<b[i]-'0'){
						cout << "LESS" << endl;
						break;
					}
				}
				if(i==x)
					cout << "EQUAL" << endl;
			}
			return 0;
}

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

int N;
int a[3][100010];
ll dp[3][100010];

int main() {
  cin >> N;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < N; j++) {
      cin >> a[i][j];
    }
    sort(a[i], a[i] + N);
  }
  for (int j = 0; j < N; j++) {
    dp[0][j] = 1;
  }
  for (int i = 1; i < 3; i++) {
    int k = 0;
    ll sum = 0;
    for (int j = 0; j < N; j++) {
      while (k < N && a[i-1][k] < a[i][j]) {
        sum += dp[i-1][k];
        ++k;
      }
      dp[i][j] = sum;
    }
  }
  ll res = 0;
  for (int j = 0; j < N; j++) {
    res += dp[2][j];
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3712
def main():
    k,n = map(int, input().split())
    A = list(map(int, input().split()))

    dis = 0
    for i in range(n-1):
        dis = max(dis, A[i+1]-A[i])
    dis = max(dis, A[0]+(k-A[-1]))
    print(k-dis)


if __name__ == '__main__':
    main()


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

int main() {
  int S,n,a,b,A,B;
  string str;
  cin >> S;
  A=0;
  B=0;
  b=(S%100);
  a=(S-b)/100;
  if(a<13 && a!=0){
    A=1;
  }
  if(b<13 && b!=0){
    B=1;
  }
  if(A==0&&B==0){
    str="NA";
  }else if(A==1&&B==0){
    str="MMYY";
  }else if(A==0&&B==1){
    str="YYMM";
  }else{
    str="AMBIGUOUS";
  }
    cout << str << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define lint long long
#define st first
#define nd second
#define INF 0x3f3f3f3f

using namespace std;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int i = 0;
	for(int i=1;i<=5;i++){
		lint x; cin>>x;
		if(x==0){
			cout<<i<<"\n";
			return 0;
		}
	}	

	return 0;	
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,st[5005],top;
int a[5005][205],l[5005],r[5005];
ll f[5005][5005],sum[5005];
void add(int l,int r,int l2,int r2,int x){
	f[l][r]+=x;f[l2+1][r2+1]+=x;
	f[l][r2+1]-=x,f[l2+1][r]-=x;
}
int main(){
	cin>>n>>m;
	int tmp;
	for(int i=2;i<=n;i++){
		scanf("%d",&tmp);
		sum[i]=sum[i-1]+tmp;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(int i=1;i<=m;i++){
		memset(l,0,sizeof(l));
		memset(r,0,sizeof(r));
		top=0;
		for(int j=1;j<=n;j++){
			while(top&&a[st[top]][i]<=a[j][i]) r[st[top--]]=j;
			st[++top]=j;
		}
		while(top) r[st[top--]]=n+1;
		for(int j=n;j>=1;j--){
			while(top&&a[st[top]][i]<a[j][i]) l[st[top--]]=j;
			st[++top]=j;
		} 
		for(int j=1;j<=n;j++){
			add(l[j]+1,j,j,r[j]-1,a[j][i]);
		}
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			f[i][j]+=-f[i-1][j-1]+f[i-1][j]+f[i][j-1];
			if(j>=i){
				ans=max(ans,f[i][j]-sum[j]+sum[i]);
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 200064
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    idx = 1
    cnt = 0
    for i in range(N):
        if A[i] == idx:
            idx += 1
            cnt += 1
    if cnt == 0:
        print(-1)
    else:
        print(N-cnt)
if __name__ == "__main__":
    main()

Measured memory_bytes: 24744
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  ll l,r;
  cin >> l >> r;
  if(r-l >= 2018) {
    cout << 0 << endl;;
    return 0;
  }
  while(l >= 2019){
    r -= 2019;
    l -= 2019;
  }
  if(r >= 2019){
    cout << 0 << endl;
    return 0;
  }
  ll a = 0;
  ll b = 100000000;
  for(int i = l; i < r; i++){
    for(int j = i+1; j < r+1; j++){
      a = i * j;
      a %= 2019;
      b = min(a,b);
    }
  }
  cout << b << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>

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

#define INF 1000 * 1000

typedef long long ll;

using namespace std;

int main() {
  ll c;

  ll n;
  cin >> n;

  vector<ll> a(n);
  vector<ll> b(n);

  rep(i, n)
    cin >> a[i] >> b[i];

  ll count = 0;

  for (int i = n - 1; i >= 0; --i) {
    ll x = (count + a[i]) % b[i];
    if (x > 0)
      count += b[i] - x;
  }

  cout << count << endl;

  return 0;

}



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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    for(int i = 0; i < H; i++){
        cin >> a.at(i);
    }

    vector<bool> row(H, false); /*falseの意味:該当行の全要素が白*/
    vector<bool> col(W, false); /*falseの意味:該当列の全要素が白*/
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(a.at(i).at(j) == '#'){ /*黒を見つけたとき*/
                row.at(i) = true; /*その黒がある行をtrue*/
                col.at(j) = true; /*その黒がある列をtrue*/
            }
        }
    }

    for(int i = 0; i < H; i++){
        if(row.at(i)){ //その行に黒があれば動作を行う
			for(int j = 0; j < W; j++){
				if(col.at(j)){ //その列に黒があれば動作を行う
					cout << a.at(i).at(j);
				}
			}
			cout << endl;
        }
    }
}

Measured memory_bytes: 3628