akhauriyash/Code-Regression huggingface dataset:
////=====BIsmillahir Rahmanir Rahim =====////

/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
         Comilla University

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define fi 2*acos(0.0)
#define ll  long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define edl printf("\n")
#define infinity 1e16
#define mod 1000000007
#define cn continue
#define csprint1 printf("Case %lld: ", cs++)
#define csprint2 printf("Case %lld:\n", cs++)
#define sf(a) scanf("%lld", &a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define sffff(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define all(v) v.begin(),v.end()

using namespace __gnu_pbds;
using namespace std;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<pl> vpi;
typedef vector<pl> vpl;
typedef tree<pair<ll, int> , null_type, less<pair<ll, int> >, rb_tree_tag, tree_order_statistics_node_update> ost;
#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) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a <<","<< spc;
    err(++it, args...);
    cout<<edl;
}
///Bit manipulation

bool checkbit(int mask,int bit){return mask & (1<<bit);}
int setbit(int mask,int bit){ return mask | (1<<bit) ; }
int clearbit(int mask,int bit){return mask & ~(1<<bit);}
int togglebit(int mask,int bit){return mask ^ (1<<bit);}
int bitno(int mask) {return (int)__builtin_popcount(mask);}

/*----------------------Graph Moves----------------*/
const int fx[]={+1,-1,+0,+0};
const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

///=====================================///
const int maX=1e6+10;
ll Xor[maX];
ll ara[maX];
ll sum[maX];
int main()
{
    ll n;sf(n);
    for(ll i=1;i<=n;i++)cin>>ara[i];
    ll Xor=0,ans=0,r=0;
    for(ll l=1;l<=n;l++){
        while(r<=n && !(Xor & ara[r])){
            Xor^=ara[r];
            r++;
        }
        ans+=(r-l);
       //cout<<ans<<spc<<l<<spc<<r<<endl;
        if(r==l)r++;
        else Xor^=ara[l];
    }
    printf("%lld\n",ans);
return 0;
}


Measured memory_bytes: 5268
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   
int x[123456],y[123456],col[123456],jojo[12];
int vec[1234][1234][2],dp1[1234][1234],dp0[1234][1234];
int main(){
    std::ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    char ch;
    int i,j;
    int haha=0;
    rep(i,n){
    	cin>>x[i]>>y[i]>>ch;
    	if(ch=='B'){
    		col[i]=1;
    	}
    	else{
    		col[i]=0;
    	}
    	haha=x[i]/k;
    	haha%=2;
    	haha+=y[i]/k;
    	if(haha%2){
    		col[i]^=1;
    	}
    	jojo[col[i]]++;
    	x[i]=x[i]%k;
    	y[i]=y[i]%k;
    	vec[x[i]][y[i]][col[i]]++;
    }
    int val=0;
    dp1[0][0]=vec[0][0][1];
    dp0[0][0]=vec[0][0][0];
    f(i,1,k){
    	dp1[i][0]=dp1[i-1][0]+vec[i][0][1];	
    	dp0[i][0]=dp0[i-1][0]+vec[i][0][0];
    }
    f(j,1,k){
    	dp1[0][j]=dp1[0][j-1]+vec[0][j][1];
    	dp0[0][j]=dp0[0][j-1]+vec[0][j][0];
    }
    f(i,1,k){
    	f(j,1,k){
    		dp1[i][j]=dp1[i][j-1]+dp1[i-1][j]-dp1[i-1][j-1]+vec[i][j][1];
    		dp0[i][j]=dp0[i][j-1]+dp0[i-1][j]-dp0[i-1][j-1]+vec[i][j][0];
    	}
    }
    int maxi=max(jojo[0],jojo[1]);
	rep(i,k){
		maxi=max(maxi,dp1[i][k-1]+jojo[0]-dp0[i][k-1]);
		maxi=max(maxi,dp0[i][k-1]+jojo[1]-dp1[i][k-1]);
	}
	rep(j,k){
		maxi=max(maxi,dp1[k-1][j]+jojo[0]-dp0[k-1][j]);
		maxi=max(maxi,dp0[k-1][j]+jojo[1]-dp1[k-1][j]);
	}
	rep(i,k-2){
		rep(j,k-2){
			val=2*dp1[i][j]+jojo[1]-dp1[k-1][j]-dp1[i][k-1];
			val+=jojo[0]-(2*dp0[i][j]+jojo[0]-dp0[k-1][j]-dp0[i][k-1]);
			maxi=max(maxi,val);
			val=2*dp0[i][j]+jojo[0]-dp0[k-1][j]-dp0[i][k-1];
			val+=jojo[1]-(2*dp1[i][j]+jojo[1]-dp1[k-1][j]-dp1[i][k-1]);
			maxi=max(maxi,val);
		}
	}    
	cout<<maxi<<endl;



    return 0;  
    
}



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

using namespace std;

string s;

int main (){
	cin >> s;
	for (int i = 0; i < s.size(); i++){
		if ((i + 1) % 2 != 0 && (s[i] == 'U' || s[i] == 'R' || s[i] == 'D')){
		}
		else if ((i + 1) % 2 == 0 && (s[i] == 'L'|| s[i] == 'U' ||s[i] == 'D')){
		}
		else {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 998244353
using namespace std;
typedef long long ll;
ll kai[200001], inv[200001];
ll dp[200001];

ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n /= 2;
  }
  return res;
}
void init() {
  kai[0] = 1LL;
  for (ll i = 1LL; i <= 200000; i++) {
    kai[i] = kai[i - 1] * i;
    kai[i] %= MOD;
  }
  inv[200000] = mod_pow(kai[200000], MOD - 2LL, MOD);
  for (ll i = 199999; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1);
    inv[i] %= MOD;
  }
}

ll comb(ll r, ll c) {
  ll res;
  res = kai[r];
  res *= inv[c];
  res %= MOD;
  res *= inv[r - c];
  res %= MOD;
  return res;
}
int main() {
  ll n, m, k, ans = 0LL, cnt;
  cin >> n >> m >> k;
  init();
  for (int i = 0; i <= k; i++) {
    cnt = comb(n - 1LL, i);
    cnt *= m;
    cnt %= MOD;
    cnt *= mod_pow(m - 1LL, n - 1LL - i, MOD);
    cnt %= MOD;
    ans += cnt;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 6772
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define P pair<int, int>
#define dvec vector<vector<ll>>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
ll INF = 1e+18;
int iINF = 1e9;


int main()
{
  int H, W; cin >> H >> W;
  vector<vector<pair<int, int>>> grid(H, vector<pair<int, int>>(W, {0, 0}));
  rep(i, 0, H) rep(k, 0, W) cin >> grid[i][k].first;
  rep(i, 0, H) rep(k, 0, W) cin >> grid[i][k].second;
  vector<vector<vector<bool>>> dp(H + 1, vector<vector<bool>>(W + 1, vector<bool>(13000, false)));
  dp[0][1][0] = true;

  
  repe(i, 1, H){
    repe(k, 1, W){
      rep(l, 0, 13000){
        int pre = abs(grid[i - 1][k - 1].first - grid[i - 1][k - 1].second);
        if(dp[i - 1][k][l]){
          dp[i][k][l + pre] = true;
          if(l - pre >= 0) dp[i][k][l - pre] = true;
          if(pre - l >= 0) dp[i][k][pre - l] = true;
        }
        if(k == 1) continue;
        if(dp[i][k - 1][l]){
          dp[i][k][l + pre] = true;
          if(l - pre >= 0) dp[i][k][l - pre] = true;
          if(pre - l >= 0) dp[i][k][pre - l] = true;
        }
      }
    }
  }

  int ans = iINF;
  rep(i, 0, 13000){
    if(dp[H][W][i]){
      ans = i;
      break;
    }
  }
  cout << ans << endl;



}


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

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	std::string T, P;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif


#if INPUT_FROM_FILE
	std::getline(ifs, T);
	std::getline(ifs, P);
#else
	std::getline(std::cin, T);
	std::getline(std::cin, P);
#endif

	if(T.size() >= P.size()){
		for(int i = 0; i < T.size() - P.size() + 1; i++){
			std::string substr = T.substr(i, P.size());
			if(substr == P){
				std::cout << i << std::endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3212
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

from collections import deque
sys.setrecursionlimit(10**6)

N, M = mi()
x = li2(M)

adj = [[] for i in range(N)]
for i in range(M):
    x[i][0] -= 1
    x[i][1] -= 1
    adj[x[i][0]].append(x[i][1])

flag = [0]*N
ans = deque([])

def dfs(x, ans):
    if flag[x]:
        return None
    else:
        flag[x] = 1
        if adj[x]:
            for a in adj[x]:
                dfs(a, ans)
        #global ans
        ans.appendleft(x)

for i in range(N):
    dfs(i, ans)

dp = [0]*N
for a in ans:
    if adj[a]:
        for b in adj[a]:
            dp[b] = max(dp[b], dp[a] + 1)

print(max(dp))

Measured memory_bytes: 74648
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int x,y;
    cin>>x>>y;
    for(int i=0;i<=x;i++){
        int j = x-i;
        if((2*i+4*j)==y){
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
    return 0;
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const ll inf = 1e18;
const ll mod = 1e9+7;
const int N = 1e5+5;
//int a[N];

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int n, ans = 0, cnt = 0;

    cin >> n;

    int arr[n];

    for (int i = 0; i < n; i++) {

        cin >> arr[i];
    }

    for (int i = 0; i < n-1; i++) {

        if (arr[i+1] > arr[i]) {

            ans = max(cnt, ans);
            cnt = 0;
        } else cnt++;

        ans = max(cnt, ans);
    }

    cout << ans;

    return 0;
}


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

#define N 45

int main(void){
  int n, fib[N];
  
  fib[0]=fib[1]=1;
  
  for(int i=2; i<=N; i++) fib[i]=fib[i-1]+fib[i-2];
  
  scanf("%d", &n);
  printf("%d\n", fib[n]);
  
  return 0;
}



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

typedef long long ll;

ll f(ll x, ll m) {
    return (x * x) % m;
}

int main() {
    ll N, X, M;
    cin >> N >> X >> M;
    set<ll> s, c;
    s.insert(X);
    ll t = X;
    vector<ll> v, w;
    v.push_back(X);
    for (int i = 0; i < N; i++) {
        t = f(t, M);
        if (s.count(t) == 1) {
            if (c.count(t) == 1) {
                break;
            }
            w.push_back(t);
            c.insert(t);
        }
        if (c.size() == 0) {
            s.insert(t);
            v.push_back(t);
        }
    }
    
    ll ans = 0;
    if (v.size() >= N) {
        for (int i = 0; i < N; i++) {
            ans += v[i];
        }
        cout << ans << "\n";
        return 0;
    }
    
    for (ll i : v) {
        ans += i;
    }
    
    ll sum = 0;
    for (ll i : w) {
        sum += i;
    }
    
    N -= v.size();
    ll m = N / c.size();
    ans += m * sum;
    ll k = N - m * c.size();
    
    for (int i = 0; i < k; i++) {
        ans += w[i];
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 8568
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;
 
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair
 
static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;
 
template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
    v.assign(a,vector<T>(b,t));
}
 
//v.erase(unique(v.begin(),v.end()),v.end());

int main(){
	int n;
	while(cin>>n,n){
		vector<pair<double,double> > v(n);
		char t;
		rep(i,n){
			cin>>v[i].F>>t>>v[i].S;
		}
		int ans=0;
		rep(i,n){
			rep(j,10000){
				double x = v[i].F+sin(2*PI*j/10000),y = v[i].S+cos(2*PI*j/10000);
				int c=0;
				rep(k,n){
					if((v[k].F-x)*(v[k].F-x)+(v[k].S-y)*(v[k].S-y)<=1.0){
						c++;
					} 
				}
				ans=max(ans,c);
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1240
from collections import deque
k=int(input())
l=deque([i+1 for i in range(9)])
cnt=9
if k<=cnt:print(l[k-1])
else:
    while cnt<k:
        v=l.popleft()
        if v%10==0:l.append(v*10);l.append(v*10+1);cnt+=2
        elif v%10==9:l.append(v*10+8);l.append(v*10+9);cnt+=2
        else:
            rem=v%10
            l.append(v*10+rem-1)
            l.append(v*10+rem)
            l.append(v*10+rem+1)
            cnt+=3
    print(l[k-cnt-1])


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


using namespace std;


#define MAX 1000000
#define INITV (2147483647)


vector<int> S(4 * MAX, INITV);

int n, q, N;

void update(int i, int x)
{
    i += N - 1;
    S[i] = x;
    while (i > 0) {
        i = (i - 1) / 2;
        S[i] = min(S[i * 2 + 1], S[i * 2 + 2]);
    }
}


int find(int s, int t, int k, int l, int r)
{
    if (r <= s || t <= l)
        return INITV;

    if (s <= l && r <= t)
        return S[k];

    int u, v;
    u = find(s, t, k * 2 + 1, l, (l + r) / 2);
    v = find(s, t, k * 2 + 2, (l + r) / 2, r);
    return min(u, v);
}


int main()
{
    cin >> n >> q;
    N = 1;
    while (N < n)
        N *= 2;
    for (int i = 0; i < q; i++) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            update(x, y);
        } else {
            int r = find(x, y + 1, 0, 0, N);
            cout << r << endl;
        }
    }
}



Measured memory_bytes: 18236
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    vi vec(n);
    REP(i,n){
        cin>>vec[i];
    }
    vi dp(n,INF);
    dp[0]=0;
    REP(i,n-1){
        if(i+1<n)chmin(dp[i+1],dp[i]+abs(vec[i+1]-vec[i]));
        if(i+2<n)chmin(dp[i+2],dp[i]+abs(vec[i+2]-vec[i]));
    }
    cout<<dp.back()<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb; 
typedef long long ll;  
typedef double db;                         
 
 
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, N = 2e4 + 48, mod = 1e9 + 7;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


int n, x, d, ans;
map < int, vpii > g;

int get (int x) {
	return x * (x + 1) / 2;
}


main () {
	cin >> n >> x >> d;
	if (!d) {
		if (!x)
			cout << 1;
		else
			cout << n + 1;
		return 0;
	}

	if (d < 0) {
		d = -d;
		x = -x;
	}

	forn (k, 0, n) {
		int m = k*x % d, l = k*x / d + get(k - 1), r = k*x / d + get(n - 1) - get(n - 1 - k);
		g[m].pb({l, r});			
	}

	for (auto x : g) {
		auto v = x.s;
		sort(all(v));	
		
		forn (i, 0, sz(v) - 1) {
			int j = i + 1, mx = v[i].s;
			while (j < sz(v) && v[j].f <= mx) {
				mx = max(mx, v[j].s);
				++j;
			}
			ans += mx - v[i].f + 1; 
			i = j - 1;
		}		
	}

	cout << ans << endl;

} 

Measured memory_bytes: 22144
#include<iostream>
#include<string>

int main(){
    std::string O, E;
    std::cin >> O >> E;
    std::size_t n = O.size() + E.size();
    std::string S;
    for(int i = 0; i < n; i++){
        // originの都合逆になる
        if(i % 2 == 0) S += O[i / 2];
        else S += E[i / 2];
    }
    std::cout << S << std::endl;
    return 0;
}


Measured memory_bytes: 256
import sys

def LS2(): return list(sys.stdin.readline().rstrip())

s = LS2()
t = LS2()

from collections import defaultdict

dict_s = defaultdict(list)

for i in range(len(s)):
    dict_s[s[i]].append(i)

r = 0  # sの文字列を何回用いたか
u = -1  # 最後に用いた文字のindex
for a in t:
    if len(dict_s[a]) == 0:
        print(-1)
        exit()
    else:
        left = -1
        right = len(dict_s[a])
        while left + 1 < right:
            mid = (left + right)//2
            if dict_s[a][mid] > u:
                right = mid
            else:
                left = mid
        if right == len(dict_s[a]):
            r += 1
            u = dict_s[a][0]
        else:
            u = dict_s[a][right]

print(len(s)*r+u+1)

Measured memory_bytes: 87660
#include <iostream>
#include <bitset>
using namespace std;
int s[10] = {63,6,91,79,102,109,125,39,127,111};
int main() {
	int n, m;
	while (cin >> n, ~n) {
		bitset<7> b(0);
        while (n--) {
			cin >> m;
			cout << (b^=s[m]) << endl;
			b = s[m];
		}
	}
}

Measured memory_bytes: 1200
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    int M = sc.nextInt();
    
    Long[][] AB = new Long[N][2];

    for (int i = 0; i < N; i++) {
      AB[i][0] = sc.nextLong();
      AB[i][1] = sc.nextLong();
    }

    sc.close();

    Arrays.sort(AB, (a, b) -> Long.compare(a[0], b[0]));
    
    long sum = 0;

    int i = 0;

    while (0 < M) {
      if (AB[i][1] < M){
        sum += AB[i][0] * AB[i][1];
        M -= AB[i][1];
      } else {
        sum += AB[i][0] * M;
        M = 0;
      }
      i++;
    }

    System.out.println(sum);

  }

}

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

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    static int dx[]={-1,0,1,0};
    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}


        
//        long L=sc.nextLong();
//        int n=sc.nextInt();	
        int h=sc.nextInt(),w=sc.nextInt();
        char d[][] = new char[h][w];
        int dp[][]=new int[h][w];
        for (int i = 0; i < dp.length; i++) {
        	d[i]=sc.nextString().toCharArray();
        }
        dp[0][0]=1;
        for (int i = 0; i < h; i++) {
			for (int t = 0; t < w; t++) {
				if(d[i][t]=='.') {
					if(i>=1)dp[i][t]+=dp[i-1][t];
					if(dp[i][t]>=mod)dp[i][t]-=mod;
					if(t>=1)dp[i][t]+=dp[i][t-1];
					if(dp[i][t]>=mod)dp[i][t]-=mod;
				}
			}
		}
        
        out.println(dp[h-1][w-1]);
        out.flush();
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  
}

//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//    public int compareTo(P p){
//        return d-p.d; //des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 35380
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,c=0;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int b=1;
  while(c<=100001){
    c++;
    if(a[b-1]==2){
      cout<<c;
      return 0;
    }else{
      b=a[b-1];
    }
  }
  cout<<-1;
}


Measured memory_bytes: 640
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
countA = Counter(A)

#pairwiseかどうかを調べる
memo = [1]*(10**6+1)
memo[0] = 0
memo[1] = 0
for i in range(2,10**6+1):
    if memo[i] == 1:
        flag = False
        if i in countA:
            if countA[i] >= 2:
                break
            flag = True
        for j in range(i*2,10**6+1,i):
            if j in countA:
                if countA[j] >= 2:
                    break
                if flag:
                    break
                else:
                    flag = True
            memo[j] = 0
        else:
            continue
        break
else:
    print("pairwise coprime")
    exit()



#setwise coprimeを判断
def gcd(a,b):
    return a if b==0 else gcd(b,a%b)

g = A[0]
for i in range(1,N):
    g = gcd(g,A[i])
if g == 1:
    print("setwise coprime")
else:
    print("not coprime")


Measured memory_bytes: 241116
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>
#include <map>
#include <bitset>
#include <queue>

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

int main() {
    int n;
    cin >> n;
    string s;
    string r, g, b;
    vector<int>rn, gn, bn;
    cin >> s;
    rep(i, n) {
        if (s[i] == 'R')r.push_back('R'); rn.push_back(i);
        if (s[i] == 'G')g.push_back('G'); gn.push_back(i);
        if (s[i] == 'B')b.push_back('B'); bn.push_back(i);
    }
    ll rs = r.size(),gs = g.size(),bs = b.size();
    //cout << rs << endl;
    ll ans = rs * gs * bs;
    rep(i, n) {
        rep(j, n/2+1) {
            if (i + 2 * j >= n)break;
            if (s[i] != s[i + j] && s[i + j] != s[i + 2 * j] && s[i] != s[i + 2 * j]) {
                ans--;
            }
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3212
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
void solve() {
	while (true) {
		int n, w;
		cin >> n >> w;
		if (n == 0) return;
		int cnt[300] = {};
		REP(i, n) {
			int a;
			cin >> a;
			cnt[a / w]++;
		}
		int now_max = 0;
		int cnter = 0;
		REP(i, 300) {
			now_max = max(now_max, cnt[i]);
			if (cnt[i]) cnter = i;
		}
		long double ans = 0.01;
		REP(i, 300) {
			if (!cnt[i]) continue;
			ans += (long double)(cnter - i) / (long double)cnter * (long double)cnt[i] / (long double)now_max;
		}
		cout << ans << endl;
	}
}
#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3168
n = int(input())
s = [list(input()) for i in range(n)]
ABC = "abcdefghijklmnopqrstuvwxyz"
ans = ""

for moji in ABC:
    count = 50
    for i in s:
        if i.count(moji) < count:
            count = i.count(moji)
    ans += moji * count
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ull unsigned long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int main()
{	
	fast
	int a,b;
	string s,t,u;
	cin>>s>>t;
	cin>>a>>b;
	cin>>u;
	if(s==u)
		a--;
	if(t==u)
		b--;
	cout<<a<<" "<<b<<endl;
	
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(long long i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const double pi = acos(-1.0);
const ll mod = pow(10,9) + 7;
const ll INF = pow(2,31) - 1;

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()
{
    ll n;
    cin >> n;
    cout << (n+1) / 2 << endl;
    return 0;
}

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

const int INF = 0x7fffffff;

int N;

string solve(void){
    int v[1000];
    vector<int> xv;
    fill(v, v + N, INF);
    for(int x = 0; x < N; x++){
        string s;
        cin >> s;
        if(s == "x"){
            xv.push_back(x);
        }else{
            v[x] = stoi(s);
        }
    }
    for(int x = 0; x < N-1; x++){
        if(v[x] == INF || v[x+1] == INF) continue;
        if(x%2 == 0 && v[x] >= v[x+1]) return "none";
        if(x%2 &&      v[x] <= v[x+1]) return "none";
    }
    int min_v = -INF, max_v = INF;
    for(int i = 0; i < xv.size(); i++){
        if(xv[i] < N-1 && v[xv[i]+1] == INF) return "none";
        if(0 < xv[i]   && v[xv[i]-1] == INF) return "none";
        if(xv[i] % 2){
            min_v = max(min_v, v[xv[i]-1]+1);
            if(xv[i] < N-1) min_v = max(min_v, v[xv[i]+1]+1);
        }else{
            if(xv[i]) max_v = min(max_v, v[xv[i]-1]-1);
            if(xv[i] < N-1) max_v = min(max_v, v[xv[i]+1]-1);
        }
    }
    if(min_v > max_v) return "none";
    if(min_v == max_v){
        stringstream ss;
        ss << min_v;
        return ss.str();
    }
    return "ambiguous";
}

int main(){
    while(cin >> N && N){
        cout << solve() << endl;
    }
    return 0;
}

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

long long s[100001],t[100001] , p[100001];

long long x[100001];
long long y[100001];
long long X[100001];
long long Y[100001];
int main(){
	int n,m;
	while(cin >> n >> m){
		for(int i = 0 ; i < n ; i++){
			cin >> s[i] >> t[i];
		}
		for(int i = 0 ; i < m ; i++){
			cin >> p[i];
		}
		sort(p,p+m);
		
		x[0] = p[0];
		y[0] = 0;
		X[0] = 1;
		Y[0] = 0;
		for(int i = 1 ; i < m ; i++){
			x[i] = x[i-1] + ((i+1)%2) * (p[i]-p[i-1]);
			y[i] = y[i-1] + ((i+0)%2) * (p[i]-p[i-1]);
			X[i] = (i+1)%2;
			Y[i] = i%2;
		}
		long long ans = 0; 
		for(int i = 0 ; i < n ; i++){
			if(s[i] > t[i]){
				int a = (upper_bound(p,p+m,s[i])-p)-1;
				int b = (upper_bound(p,p+m,t[i]))-p; 
				if(a==-1 || b == m){
					ans += s[i]-t[i];
				}else{//1 2 3 5 
					ans += (s[i]-p[a]);
					if((b-a)%2){
						if( X[a] == 0) ans += x[a]-x[b];
						else		   ans += y[a]-y[b];
						ans += (p[b]-t[i]);
					}else{
						//1 2 3 4 5 
						//cout << a << " " << b << " " << (s[i]-p[a]) << endl;
						if( X[a] == 0) ans += x[a]-x[b];
						else		   ans += y[a]-y[b];
					}
				}
			}else{
				int a = (upper_bound(p,p+m,s[i])-p);
				int b = (upper_bound(p,p+m,t[i])-1)-p;
				if(b==-1 || a == m){
					ans += t[i]-s[i];
				}else{
					ans += (p[a]-s[i]);
					if((b-a)%2){
						if( X[a] == 1) ans += x[b]-x[a];
						else		   ans += y[b]-y[a];
						ans += (t[i]-p[b]);
					}else{
						if( X[a] == 1) ans += x[b]-x[a];
						else		   ans += y[b]-y[a];
					}
				}
				// 2 3
				
				// 2 2
				// 1 0
				// 0 3
				// 0 1
			}
		}
		cout << ans << endl;
		return 0;
	}
}

Measured memory_bytes: 6308
N=int(input())
A=list(map(int, input().split()))

from collections import defaultdict
ue=defaultdict(int)
st=defaultdict(int)

for i in range(N):
  ue[i+1+A[i]]+=1
  st[i+1-A[i]]+=1

ans=0

for i in ue.keys():
  ans+=ue[i]*st[i]
  
print(ans)

Measured memory_bytes: 73348
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    string::iterator itrA = s.begin();
    string::iterator itrZ = s.end() - 1;
    while (*itrA != 'A')
    {
        itrA++;
    }
    while (*itrZ != 'Z')
    {
        itrZ--;
    }
    
    cout << (int)(itrZ - itrA) + 1 << endl;
    
    return 0;
}

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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

string s;
int n;

string optimal(int left, int right) {
    string opt = "";
    vector<int> a, b;
    fori(i, left, right + 1) {
        if(s[i] == 'a') {
           a.push_back(i);
       }
       else {
           b.push_back(i);
       }
    }
    if(s[left] == 'a') {
        int limit = -1;
        fori(i, 0, a.size()) {
            if(limit < a[i]) {
                opt += "ab";
                limit = b[i];
            }
        }
    }
    else {
        ford(i, a.size() - 1, 0) {
            string cur = ""; 
            int a_ptr = i, b_ptr = i;
            while(a_ptr < (int) a.size() || b_ptr < (int) b.size()) {
                if(a_ptr == (int) a.size()) {
                    cur += "b";
                    b_ptr++;
                }
                else if(b_ptr == (int) b.size()) {
                    cur += "a";
                    a_ptr++;
                }
                else if(a[a_ptr] < b[b_ptr]) {
                    cur += "a";
                    a_ptr++;
                }
                else {
                    cur += "b";
                    b_ptr++;
                }
            }
            opt = max(opt, cur);
        }
    }
    return opt;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    cin >> s;
    vector<string> optimals;
    int sum = 0, start = 0;
    fori(i, 0, 2 * n) {
        sum += s[i] == 'a';
        sum -= s[i] == 'b';
        if(sum == 0) {
            optimals.push_back(optimal(start, i));
            start = i + 1;
        }
    }
    string best = "";
    ford(i, (int) optimals.size() - 1, 0) {
        best = max(best, optimals[i] + best); 
    }
    cout << best << '\n';
    return 0;
}


Measured memory_bytes: 512
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S> void arrErase(int k, int &sz, S a[]){
  int i;
  sz--;
  for(i=(k);i<(sz);i++){
    a[i] = a[i+1];
  }
}
template<class S, class T> void arrErase(int k, int &sz, S a[], T b[]){
  int i;
  sz--;
  for(i=(k);i<(sz);i++){
    a[i] = a[i+1];
  }
  for(i=(k);i<(sz);i++){
    b[i] = b[i+1];
  }
}
template<class S, class T, class U> void arrErase(int k, int &sz, S a[], T b[], U c[]){
  int i;
  sz--;
  for(i=(k);i<(sz);i++){
    a[i] = a[i+1];
  }
  for(i=(k);i<(sz);i++){
    b[i] = b[i+1];
  }
  for(i=(k);i<(sz);i++){
    c[i] = c[i+1];
  }
}
int N;
int A[100];
int ress;
int res[100];
int main(){
  int i;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  while(N){
    int i;
    for(i=(N)-1;i>=(0);i--){
      if(A[i]==i+1){
        res[ress++] = A[i];
        arrErase(i, N, A);
        goto e98WHCEY;
      }
    }
    wt_L(-1);
    wt_L('\n');
    return 0;
    e98WHCEY:;
  }
  for(i=(0);i<(ress);i++){
    wt_L(res[ress-1-i]);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20191125-1

// --- original code ---
// int N, A[100];
// int ress, res[100];
// 
// {
//   rd(N,A(N));
//   while(N){
//     rrep(i,N) if(A[i]==i+1){
//       res[ress++] = A[i];
//       arrErase(i, N, A);
//       break_continue;
//     }
//     wt(-1), return 0;
//   }
//   rep(i,ress) wt(res[ress-1-i]);
// }


Measured memory_bytes: 256
/*
title:

url:
*/

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

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 n, x;
    cin >> n >> x;
    int m[n];
    int min = INF;
    for (int i = 0; i < n; i++)
    {
        cin >> m[i];
        x -= m[i];
        min = min > m[i] ? m[i] : min;
    }
    int ans = n;
    ans += x / min;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;

using namespace std;
int main(){
    cs;
    int x,y,z,K,t=0;
    cin>>x>>y>>z>>K;
    vector<ll> a(x);
    vector<ll> b(y);
    vector<ll> c(z);
    rep(i,x) cin>>a[i];
    rep(i,y) cin>>b[i];
    rep(i,z) cin>>c[i];
    sort(a.rbegin(),a.rend());
    sort(b.rbegin(),b.rend());
    sort(c.rbegin(),c.rend());
    vector<ll> ans(1000000);
    rep(i,x){
        rep(j,y){
            rep(k,z){
                if((i+1)*(j+1)*(k+1)<=K) 
                {ans[t]=a[i]+b[j]+c[k];t++;}
            }
        }
    }
    sort(ans.begin(),ans.begin()+t,greater<>());
    rep(i,K) cout<<ans[i]<<'\n';
}

Measured memory_bytes: 8192
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

string s;
map<int, int> ma;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> s;
    int x = 0;
    ll res = 0;
    ma[0]++;
    int mu = 1;
    FORE(i,SZ(s)-1,0) {
        x = (x + mu * (s[i] - '0')) % 2019;
        mu = mu * 10 % 2019;
        res += ma[x];
        ma[x]++;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 3744
#include<iostream>
#include<cmath>
#include<iomanip>
#define PI 3.14159265359
using namespace std;

int main() {
	double a, b, c, s, l, h;
	cin >> a >> b >> c;
	c = c * PI / 180;
	h = b * sin(c);
	s = a * h / 2;
	l = a + b + sqrt(a * a + b * b - 2 * a * b * cos(c));
	cout << setprecision(10) << s << endl << l << endl << h << endl;
	return 0;
}

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

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define llint long long int


int main (void)
{
	//INPUT
	llint a,b,c;

	cin >> a >> b >> c;

	if (c-a-b<0) {
		cout << "No" << endl;
		return 0;
	}

	if ((c-a-b)*(c-a-b)-4*a*b > 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}



	return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
dp = [0]*(N+1)
dp[0] = 1
A=[int(input()) for _ in range(M)]
B=[1]*(N+1)
for i in range(M):
    B[A[i]] = 0
for i in range(N):
    if i-1 >= 0:
        dp[i+1] = dp[i]*B[i]+dp[i-1]*B[i-1]
    else:
        dp[i+1] = dp[i]*B[i]
    dp[i+1] %= 10**9+7
print(dp[N])

Measured memory_bytes: 15048
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;


int main() {
	string S;
	cin >> S;
	S[3] = '8';
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	vector<int>v1;
	int i1,u1=0;
	for(int i=0;i<3;i++)
	{
		cin>>i1;
		v1.push_back(i1);
	}
	sort(v1.begin(),v1.end());
	for(int i=1;i<3;i++)
	{
		u1+=(v1[i]-v1[i-1]);
	}
	cout<<u1;
	return 0;
 } 

Measured memory_bytes: 256
from numba import jit

@jit
def solve():
    n, k = map(int,input().split())
    p = list(map(int, input().split()))
    c = list(map(int, input().split()))
    max_score = -10**10

    for i in range(n):
        count = 1
        val = c[i]

        next_i = p[i] -1
        while next_i != i:
            count += 1
            val += c[next_i]
            next_i = p[next_i] - 1
        
        if val > 0:
            loop_num = (k//count -1)
            tmp_score = loop_num * val
            max_score = max(tmp_score, max_score)
            num = k%count+count

        else:
            tmp_score = 0
            num = min(k, count)

        next_i = i
        for _ in range(num):
            next_i = p[next_i] - 1
            tmp_score += c[next_i]
            max_score = max(tmp_score, max_score)
    
    print(max_score)

solve()

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

	int h, w; cin >> h >> w;
	vector<int> a(26, 0);
	for (int i = 0; i < h; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < w; j++) {
			int idx = s[j] - 'a';
			a[idx]++;
		}
	}
	sort(a.begin(), a.end());
	int one = 0, two = 0, four = 0;
	for (int i = 0; i < 26; i++) {
		int num = a[i],otmp,ttmp,ftmp;
		ftmp = (num / 4);
		num -= 4 * ftmp;
		ttmp = (num / 2);
		num -= 2 * ttmp;
		otmp = num;
		one += otmp;
		two += ttmp;
		four += ftmp;
	}
	bool flag = false;
	if (h % 2 == 0 && w % 2 == 0) {
		if (one == 0 && two == 0) flag = true;
	}
	else if (h % 2 != 0 && w % 2 != 0) {
		if (one == 1 && four*4>=h*w+1-(h+w)) flag = true;
	}
	else if (h % 2 == 0 && w % 2 != 0) {
		if (one == 0 && four*4>=h*w-h)flag = true;
	}
	else {
		if (one == 0 && four*4>=h*w-w)flag = true;
	}
	
	if (flag)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[10000],b[10000];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    for(int i=0;i<n;i++)scanf("%d",&b[i]);
    long long need=0;
    for(int i=0;i<n;i++){
        if(a[i]>b[i]){
            need=need+a[i]-b[i];
        }
    }
    for(int i=0;i<n;i++){
        if(a[i]<b[i]){
            long long diff=b[i]-a[i];
            need=need-diff/2;
        }
    }
    if(need<=0)puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int solve(int,int);

int n;
int A[2000],b[2000];

int main(){

  int i,j,k;
  int judge;

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&k);
  for(i=0; i<k; i++){
    scanf("%d",&b[i]);
  }

  for(i=0; i<k; i++){

    judge = solve(0,b[i]);
    if(judge == 1) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

int solve(int i, int m){

  int res;

  if(m==0) return 1;

  else if(i>=n) return 0;

  res = solve(i+1,m) || solve(i+1, m-A[i]);
  return res;
}

Measured memory_bytes: 584
<?php
fscanf(STDIN, '%d', $n);
$a = explode(' ', fgets(STDIN));

$flg = true;
foreach ($a as $value) {
//    var_dump((int)$value,(int)$value % 2 !==0,(int)$value %3 !== 0);
    if ((int)$value % 2 !==0) {
        continue;
    }

    if ((int)$value %3 === 0) {
        continue;
    } else if((int)$value %5 === 0) {
        continue;
    } else {
        $flg = false;
        break;
    }

}

if ($flg === true) {

    echo 'APPROVED'.PHP_EOL;
} else {
    echo "DENIED".PHP_EOL;
}


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

using namespace std;

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

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

int main(){
    vector<char> c(4);
    string num="1974";
    vector<ll> used(4);
    rep(i,4){
        cin >> c[i];
        rep(j,4){
            if(c[i]==num[j]) used[j]=1;
        }
    }
    bool ok=true;
    rep(i,4){
        if(used[i]==0){
            ok=false;
            break;
        }
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3516
#include<iostream>
using namespace std;
int main(){
	int n,m;

	cin >> n >> m;

	int A[n][m],b[m];
	int con[n];

	for(int i=0; i<n; i++){
		con[i] = 0;
	}

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

	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			con[i] += A[i][j]*b[j];
		}
	}

	for(int i=0; i<n; i++){
		cout << con[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1200