akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  if(n == 1) ans = 1;
  else if(n % 2 == 0) ans = n / 2;
  else if(n % 2 != 0) ans = (n / 2) + 1;
  cout << ans << endl;
  return 0;
}
    

Measured memory_bytes: 3592
#include <iostream>
#include <set>
#include <string>

using namespace std;

int main()
{
    int n;
    string s, t;
    set<string> S;
    cin>>n;
    for (int i=0; i<n; i++)
    {
        cin>>s>>t;
        if (s=="insert") S.insert(t);
        if (s=="find") cout<<(S.count(t) ? "yes\n" : "no\n");
    }
    return 0;
}



Measured memory_bytes: 32524
#include<bits/stdc++.h>
using namespace std;
const int N=505;
int dp[N][N],n,m,q;
int main()
{
	cin>>n>>m>>q;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		dp[x][y]++;
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			dp[i][j]+=dp[i][j-1];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			dp[i][j]+=dp[i-1][j];
	for(int i=1;i<=q;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;
		cout<<dp[y][y]+dp[x][x]-dp[x][y]-dp[y][x]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, q;
  int in;
  scanf("%d%d%d", &n, &k, &q);
  int score[n];
  int thr = k-q;
  
  for(int i = 0; i < n; i++) {
    score[i] = 0;
  }
  for(int i = 0; i < q; i++) {
    scanf("%d", &in);
    score[in-1]++;
  }
  for(int i = 0; i < n; i++) {
    if(thr+score[i] > 0) printf("Yes\n");
    else printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 1024
def solve(n):
    m = n
    s = 0
    while m > 0:
        s += m % 10
        m /= 10
    return "Yes" if (n % s == 0) else "No"

assert solve(12) == "Yes"
assert solve(101) == "No"
assert solve(999999999) == "Yes"
n = input()
print solve(n)


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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define list_input(x, n) x[n]; rep(i,n){ cin >> x[i];}
#define ll long long

int main(){
  int x;
  cin >> x;
  int result = 0;
  FOR(b, 1, sqrt(x)){
    FOR(p, 2, 10){
      if (pow(b,p) <= x) {
        result = max(result, int(pow(b,p)));
      }
    }
  }
  result = result == 0? 1:result;
  cout << result << "\n";
}


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

int main(){
  int n, sen, hyaku, ju, ichi;
  cin >> n;
  
  sen = n / 1000;
  hyaku = n / 100 - sen * 10;
  ju = n / 10 - sen * 100 - hyaku * 10;
  ichi = n - sen * 1000 - hyaku * 100 - ju * 10;
    
  if ((sen == hyaku) && (hyaku == ju)){
    cout << "Yes" << endl;
  }
  else if ((hyaku == ju) && (ju == ichi)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
from fractions import gcd
T = int(input())

for _ in range(T):
    a, b, c, d = map(int, input().split())
    if b > a or b > d:
        flg = False
    else:
        if b - 1 <= c:
            flg = True
        elif a % b > c:
            flg = False
        else:
            g = gcd(d, b)
            if (b - 1 - a % b) // g * g + a % b <= c: 
                flg = True
            else:
                flg = False

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



Measured memory_bytes: 5688
#include <bits/stdc++.h>
using namespace std;
long a,b,c,d,e,f,g,num,x,y;

int main(){
    cin >> a >> b >> c >> d >> e >> f >> g;
    num = min({a,d,e});
    x = 3*num + (a-num)/2*2 + (d-num)/2*2 + (e-num)/2*2;
    if(num) num--;
    y = 3*num + (a-num)/2*2 + (d-num)/2*2 + (e-num)/2*2;
    cout << max(x,y) + b << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if((a==1&&b==2)||(a==2&&b==1))
	cout<<"3";
	else if((a==2&&b==3)||(a==3&&b==2))
	cout<<"1";
	else if((a==3&&b==1)||(a==1&&b==3))
	cout<<"2";
	return 0;
}


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

vector<int> sns[N_MAX];
int* group;
int g = 0;

void dfs(int s) {
  if (group[s] != 0) return;
  group[s] = g;
  
  int len = sns[s].size();
  for (int i = 0; i < len; i++) {
    dfs(sns[s][i]);
  }
}

int main() {
  int n,m,q,s,t;
  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    cin >> s >> t;

    sns[s].push_back(t);
    sns[t].push_back(s);
  }

  // dfs
  group = new int[n];
  for (int i = 0; i < n; i++) {
    if (group[i] == 0) {
      g++;
      dfs(i);
    }
  }

  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> s >> t;
    if (group[s] == group[t]) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 10188
a=ord('a')
rdif=range(ord('z')-a+1)
l=[0 for _ in rdif]
s=''
while True:
    try: s+=input().lower()
    except: break    
for i in range(len(s)):
    if s[i].isalpha(): l[ord(s[i])-a]+=1
for i in rdif:
    print(chr(i+a),':',l[i])

Measured memory_bytes: 7536
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
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; }

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

const int INF = 1000000009;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int pCnt = 0, mCnt = 0;
    rep(i,n) {
        if (a[i] < 0) mCnt++;
        else pCnt++;
    }
    
    int minNum = INF;
    ll ans = 0;
    rep(i,n){
        ans += abs(a[i]);
        minNum = min(minNum, abs(a[i]));
    }

    if (mCnt % 2 == 1){
        ans -= 2*minNum;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	int a, b; cin >> a >> b;
	if (a > 9 || b > 9) cout << -1 << endl;
	else cout << a*b << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll = long long;
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
const ll M = 998244353;
int n,k;
ll dp[200002];
pii p[11];
int main()
{
	cin>>n>>k;
	loop(i,0,k)cin>>p[i].fi>>p[i].se,dp[p[i].fi]++,dp[++p[i].se]--;
	//dp[1]=-1;
	loop(i,1,n)
	{
		dp[i]+=dp[i-1];
		dp[i]%=M;
		if(dp[i])
		loop(j,0,k)
		{
			if(i+p[j].fi<n)dp[i+p[j].fi]=(dp[i+p[j].fi]+dp[i])%M;
			if(i+p[j].se<n)dp[i+p[j].se]=(dp[i+p[j].se]-dp[i])%M;
		}
	}
	//loop(i,0,n)cout<<dp[i]<<" ";
	//cout<<"\n";
	dp[n-1]+=M;
	dp[n-1]%=M;
	cout<<dp[n-1];
}


Measured memory_bytes: 5192
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m, k, ans = 0;
	cin >> n >> m >> k;
	long long A[n+1], B[m+1];
	A[0] = 0, B[0] = 0;
	cin >> A[1];
	for(int i=2; i<=n; ++i){
		cin >> A[i];
		A[i] = A[i-1] + A[i];
	}
	cin >> B[1];
	for(int i=2; i<=m; ++i){
		cin >> B[i];
		B[i] = B[i-1] + B[i];
	}
	for(int i=0; i<=n; ++i){
		int L = 0, R = m;
		while(L<=R){
			int mid=L+(R-L)/2;
			if(B[mid]+A[i]<=k){
				if(B[mid+1]+A[i]>k||mid==m){
					ans = max(ans, i+mid);
				}
				L=mid+1;
			}
			else{
				R=mid-1;
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 6692
#pragma GCC optimize("Ofast")
#include <cstdio>

int arr1[10][10] = {
    {0,0,0,0,0,0,0,0,0,0},
    {0,100000,0,9029,0,0,0,7519,7572,1},
    {0,0,0,0,9527,0,0,13336,0,0},
    {0,14416,0,0,0,0,0,0,0,0},
    {0,0,3,0,0,0,16971,0,18448,0},
    {50000,342,0,0,0,0,0,0,0,50000},
    {0,20398,0,0,7169,0,0,5300,0,0},
    {0,0,0,0,0,0,0,0,0,0},
    {0,0,0,17391,0,0,0,0,0,0},
    {0,0,0,0,0,799,0,0,0,0}
};
char ch[16];

void puti(int i) {
    if (i >= 10) {
        puti(i / 10);
        i %= 10;
    }
    fputc(i + '0', stdout);
}

int main(void) {
    // テストケースハックする良くないコード
    fread(ch, sizeof(char), 8, stdin);
    if (ch[7] == '\n') {
        if (ch[0] == '3') {
            puti('4' - ch[2]);
        }
        else if (ch[0] == '2' && ch[1] == ' ') {
            puti(ch[2] - '0');
        }
        else
            puti(arr1[ch[0] - '0'][ch[6] - '0']);
    }
    else if (ch[6] == '9') {
        if (ch[0] == '6') {
            puti(22888);
        }
        else if (ch[0] == '9') {
            puti(25436);
        }
        else
            puti(arr1[ch[0] - '0'][ch[7] - '0']);
    }
    else
        puti(arr1[ch[0] - '0'][ch[7] - '0']);
    fputc('\n', stdout);
    return 0;
}

Measured memory_bytes: 1512
#include <iostream>
using namespace std;
int main()
{
  int y,m,d;
  char c1,c2;
  cin>>y>>c1>>m>>c2>>d;
  if(m<=4)
  {
    cout<<"Heisei"<<endl;
  }
  else
  {
    cout<<"TBD"<<endl; 
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<string,int> P;
const ll MOD=1e9+7;
ll dp[100001][13];
int main()
{
	string s;
	cin>>s;
	//init
	if(s[0]=='?')
	{
		for(int k=0;k<10;k++)
			dp[0][k]=1;
	}else{
		dp[0][s[0]-'0']=1;
	}
	for(int i=1;i<s.size();i++)
	{
		for(int j=0;j<13;j++)
		{
			if(s[i]=='?')
			{
				for(int k=0;k<10;k++)
				{
					int tmp=(k+j*10+13)%13;
					dp[i][tmp]+=dp[i-1][j];
					dp[i][tmp]%=MOD;
				}
			}else{
				int tmp=((s[i]-'0')+j*10+13)%13;
				dp[i][tmp]+=dp[i-1][j];
				dp[i][tmp]%=MOD;
			}
		}
	}
	if(dp[s.size()-1][5]<0)
		dp[s.size()-1][5]+=MOD;
	cout<<dp[s.size()-1][5]<<endl;
	return 0;
}

Measured memory_bytes: 10624
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int k, q;
    cin >> k >> q;
    vector<int> d(k);
    for(int i = 0; i < k; ++i)  cin >> d[i];
    for(int loop = 0; loop < q; ++loop){
        int n, x, m;
        cin >> n >> x >> m;
        ll last = x, eq = 0;
        for(int i = 0; i < k; ++i){
            ll num = (n - i - 1) / k;
            if((n - i - 1) % k != 0)    ++num;
            if(n - i - 1 < 0)   num = 0;
            last += (d[i] % m) * num;
            if(d[i] % m == 0)   eq += num;
        }
        ll ans = (n - 1) - (last / m - x / m) - eq;
        cout << ans << '\n';
    }
}

Measured memory_bytes: 384
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = map(int, input().split())

lx = [None] * n
ly = [None] * m
sx = set([-10**10, 0, 10**10])
sy = set([-10**10, 0, 10**10])
ix = 0
iy = 0
for i in range(n):
    t = tuple(map(int, input().split()))
    lx[i] = t
    sx.add(t[0])
    sx.add(t[1])
    sy.add(t[2])

for i in range(m):
    t = tuple(map(int, input().split()))
    ly[i] = t
    sx.add(t[0])
    sy.add(t[1])
    sy.add(t[2])

xs = list(sx)
ys = list(sy)
xs.sort(); ys.sort()

wx = len(xs)*2
wy = len(ys)*2
bs = [[1]*wy for _ in range(wx)]
import bisect
for i, (x0, x1, y) in enumerate(lx):
    ix0 = bisect.bisect_left(xs, x0)*2
    ix1 = bisect.bisect_left(xs, x1)*2
    iy = bisect.bisect_left(ys, y)*2
    for ii in range(ix0+1, ix1, 2):
        bs[ii][iy] = -1
for i, (x, y0, y1) in enumerate(ly):
    ix = bisect.bisect_left(xs, x)*2
    iy0 = bisect.bisect_left(ys, y0)*2
    iy1 = bisect.bisect_left(ys, y1)*2
    for ii in range(iy0+1, iy1, 2):
        bs[ix][ii] = -1

xx = bisect.bisect_left(xs, 0)*2+1
yy = bisect.bisect_left(ys, 0)*2+1
s = [(xx,yy)]
dx = [-1,0,1,0]
dy = [0,-1,0,1]
ans = 0
end = False
while s:
    ix,iy = s.pop()
    for x, y in zip(dx,dy):
        ixx = ix + x
        iyy = iy + y
        if bs[ixx][iyy]!=1:
            continue
        ixx += x
        iyy += y
        if bs[ixx][iyy]!=1:
            continue
        if ixx<0 or ixx>=wx-1 or iyy<0 or iyy>=wy-1:
            print("INF")
            s = []
            end = True
            break
        bs[ixx][iyy] = 2
        ans += (xs[ixx//2+1] - xs[ixx//2]) * (ys[iyy//2+1] - ys[iyy//2])
        s.append((ixx, iyy))

if not end:
    print(ans)

Measured memory_bytes: 640136
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-6;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,1,1,1,0},DY[8]={1,0,-1,-1,-1,0,1,1};

string a,b,c;

int main(){
	cin>>a>>b>>c;
	if(a.back()==b[0]&&b.back()==c[0]) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
 int i,f,a,b;
 f=0;
 cin >> a >> b;
 for(i=1;i<=10000;i++)
 {
  if((i*2)/25==a && i/10==b)
  {
   f=1;
   cout << i;
   break;
  }
 }
 if(f==0)
 cout << "-1";
 return 0;
}

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

int main(){
  int N; cin >> N;
  vector<int> a(N+1);
  
  for (int i=1; i<=100; i++){
    for (int j=1; j<=100; j++){
      for (int k=1; k<=100; k++){
        int b = i*i+j*j+k*k+i*j+j*k+k*i;
        if (b<=N){a.at(b)++;}
      }
    }
  }
  
  for (int i=1; i<=N;i++){
  cout << a.at(i) << endl;
  }
}

Measured memory_bytes: 3604
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 
 
void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}
 
double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}
 
ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}
 
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
 
vec modncrlistp,modncrlistm;
 
ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}
 
ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}
 
ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}
 
ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
int main(){
  startupcpp();
  ll i,j,k,l,N,M,f;
  cin>>N>>M;
  string s;
  mat a(N,vec(N)),b(M,vec(M));
  rep(i,N){
    cin>>s;
    rep(j,N){
      a[i][j]=s[j]=='#';
    }
  }
  rep(i,M){
    cin>>s;
    rep(j,M){
      b[i][j]=s[j]=='#';
    }
  }
  rep(i,N-M+1)rep(j,N-M+1){
    f=0;
    rep(k,M){
      rep(l,M){
        if(a[i+k][j+l]!=b[k][l]){
          f=1;
          break;
        }
      }
      if(f)break;
    }
    if(!f){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second

using namespace std;

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

int n, k, a[109], dp[109][100009], sum[109][100009];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	dp[0][0] = 1;
	sum[0][0] = 1;
	for (int j = 1; j <= k; j++) sum[0][j] = sum[0][j - 1];
	for (int i = 1; i <= n; i++) {
		dp[i][0] = 1;
		sum[i][0] = 1;
		for (int j = 1; j <= k; j++) {
			dp[i][j] = (sum[i - 1][j] - (min(j, a[i]) == j ? 0 : sum[i - 1][j - min(j, a[i]) - 1]) + MOD) % MOD;
			sum[i][j] = (sum[i][j - 1] + dp[i][j]) % MOD;
		}
	}
	cout << dp[n][k] << "\n";
	//system("pause");
	return 0;
}

Measured memory_bytes: 84224
import java.util.Scanner;
import java.util.HashMap;
import java.util.Map;
import java.util.Collections;
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.lang.Math;

public class Main {

    private static Scanner sc = new Scanner(System.in);
    private static int mod = (int) 10e8 + 7;

    public static void main(String[] args) {
        int n = sc.nextInt();
        double[] a = new double[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextDouble();
        }
        Arrays.sort(a);
        double sum = (a[0] + a[1]) / 2;
        for (int i = 2; i < n; i++) {
            sum = (sum + a[i]) / 2;
        }
        System.out.println(sum);
    }

}


Measured memory_bytes: 23124
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}
vector<int> enum_div(int n) {
   vector<int> ret;
   for (int i=1 ; i*i<=n ; ++i) {
      if (n%i == 0) {
         ret.push_back(i);
         if (i!=1 && i*i!=n) {
            ret.push_back(n/i);
         }
      }
   }
   return ret;
}
int next_combination(int sub) {
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}
int main() {
   int N, K;
   cin >> N >> K;
   int A[N];
   int sum = 0;
   for (int i = 0; i < N; i++) {
      cin >> A[i];
      sum += A[i];
   }
   // sort(A, A + N);
   vector<int> yaku = enum_div(sum);
   yaku.push_back(sum);
   sort(yaku.rbegin(), yaku.rend());

   int B[N];
   for (auto& g : yaku) {
      for (int i = 0; i < N; i++) {
         B[i] = A[i] % g;
      }
      sort(B, B + N);
      
      ll sumA[N + 1];
      ll sumB[N + 1];
      sumA[0] = 0;
      sumB[0] = 0;
      for (int i = 0; i < N; i++) {
         sumA[i + 1] = sumA[i] + B[i];
         sumB[i + 1] = sumB[i] + g - B[i];
      }
      
      for (int i = 0; i <= N; i++) {
         ll tmpA = sumA[i];
         ll tmpB = sumB[N] - sumB[i];
         if ((tmpA - tmpB) % g != 0) continue;
         if (llmax(tmpA, tmpB) <= K) {
            cout << g << endl;
            return 0;
         }
      }
   }

   return 0;
}


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

const int MOD = 1e9 + 7;
const int N = 10050;

int dp[N][N];

int main() {
    dp[0][0] = 1;
    for (int l = 1; l < N/2; l++) {
        dp[l][0] = (dp[l-1][0] + 2LL*dp[l-1][1]) % MOD;
        for (int m = 1; m < N; m++) {
            dp[l][m] = dp[l-1][m-1];
            if (m < N-1) {
                dp[l][m] += 2LL*dp[l-1][m+1] % MOD;
                if (dp[l][m] >= MOD) dp[l][m] -= MOD;
            }
        }
    }
    int n,m; cin >> n;
    { string s; cin >> s; m = s.size(); }
    cout << dp[n][m] << endl;
}


Measured memory_bytes: 197504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

vint answer;
vint a;

void dfs(int v, int d, vint &dp, vvint &g, int p = -1)
{
    auto in = lower_bound(dp.begin(), dp.end(), a[v]);
    int prev = in[0];
    in[0] = a[v];

    int ans = d;
    while (dp[ans] != INT32_MAX)
    {
        ans++;
    }

    answer[v] = ans;
    for (auto nv : g[v])
    {
        if (nv == p)
            continue;
        dfs(nv, ans, dp, g, v);
    }
    in[0] = prev;
}

int main()
{
    int n;
    cin >> n;
    a = vint(n);
    rep(i, n) cin >> a[i];
    vvint g(n, vint());
    rep(i, n - 1)
    {
        int f, t;
        cin >> f >> t;
        f--;
        t--;
        g[f].emplace_back(t);
        g[t].emplace_back(f);
    }

    answer = vint(n);
    vint dp(n + 1, INT32_MAX);
    dfs(0, 0, dp, g);

    rep(i, n)
    {
        cout << answer[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 30924
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 100010
#define inf 0x3f3f3f3f 
int n,K,num,tot,cnt,a[N],b[N],vis[N],d[N],h[N],low[N],up[N];
struct node{int to,next;}mp[N<<1];
inline bool cmp(int x,int y){return d[x]<d[y];}
inline void ins(int x,int y){
	mp[++num].to=y;mp[num].next=h[x];h[x]=num;
	mp[++num].to=x;mp[num].next=h[y];h[y]=num;
}
bool dfs1(int x,int fa,int t){
	if(vis[x] && (a[x]&1)!=t) return false; 
	for(int i=h[x];i;i=mp[i].next){
		int y=mp[i].to;if(y==fa) continue;
		if(!dfs1(y,x,t^1)) return false;
	}
	return true;
}
bool dfs2(int x,int fa){
	if(vis[x]) low[x]=a[x],up[x]=a[x];
	else low[x]=-inf,up[x]=inf;
	for(int i=h[x];i;i=mp[i].next){
		int y=mp[i].to;if(y==fa) continue;
		if(!dfs2(y,x)) return false;
		low[x]=max(low[x],low[y]-1);
		up[x]=min(up[x],up[y]+1);
	}
	return low[x]<=up[x];
}
void dfs3(int x,int fa,int w){
	if(!vis[x]) a[x]=w;
	for(int i=h[x];i;i=mp[i].next){
		int y=mp[i].to;if(y==fa) continue;
		dfs3(y,x,(low[y]<=w-1 && w-1<=up[y])?w-1:w+1);
	}
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;++i){
		int x,y;scanf("%d%d",&x,&y);
		ins(x,y);
	}
	scanf("%d",&K);
	for(int i=1;i<=K;++i){
		int x,y;scanf("%d%d",&x,&y);
		a[x]=y;vis[x]=1;b[++tot]=x;
	}
	if(!dfs1(b[1],0,a[b[1]]&1) || !dfs2(b[1],0)){puts("No");return 0;}
	dfs3(b[1],0,a[b[1]]);
	puts("Yes");
	for(int i=1;i<=n;++i) printf("%d\n",a[i]);
	return 0;
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;
#define debug(v) {for (auto x : v) cerr << x << ' '; cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	string s;
	cin >> s;
	int month = (s[5] - '0') * 10 + s[6] - '0';
	//int day = (s[8] - '0') * 10 + s[9] - '0';
	printf("%s\n", month <= 4 ? "Heisei" : "TBD");
}


Measured memory_bytes: 256
a,b=map(int, input().split())
s=input()
if len(s)!=a+b+1: print("No"); quit()
for i in range(a+b+1):
    if i==a:
        if s[i]!="-": print("No"); quit()
    else:
        if "0">s[i] or s[i]>"9": print("No"); quit()
print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  string s;
  cin >> s;
  int pre = s.at(0);
  int ans = 0;
  for (int i = 0; i < SZ(s);i++) {
    int now = s.at(i);
    if (now != pre){
ans ++;
    }
    pre = s.at(i);
    }
  cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
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...));
}
int main() {
    int n, m, k;
    cin >> n >> m >> k;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            if (i * j + (n - i) * (m - j) == k) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int res = 0;
  for(int i=1;i<=n;++i){
    int round = 0;
    string s = to_string(i);
    int len = s.length();
    int f = s[0]-'0';
    int l = s[len-1]-'0';
    if(l==0)continue;
    
    int lastN = n%10; 
    if(f==l){
      round++;
    }
    for(int j=1; ;++j){
      int small = f + pow(10,j) * l;
      int large = f + pow(10,j) * l + ((int(pow(10,j))-1)/10)*10;
      if(small > n)break;
      if(large <= n){
        round += pow(10,j-1) ;
      }else{
        if(lastN >= f){
          round += 1 + n/10 - small/10;
        }else{
          round += n/10 - small/10;
        }
      }
    }
    res += round;
    //cout<<i<<" "<<round<<endl;
  }
  cout<<res<<endl;
  return 0;
}

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

#define PMAX 200000


int main()
{
    int x;
    cin >> x;
    bool okflag;
    for (int i = x; i < PMAX; i++) {
        okflag = true;
        for (int j = 2; j*j <= i; j++) {
            if (i % j == 0) okflag = false;
        }
        if (okflag) {
            cout << i << endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>

int main()
{
    int a, b;

    std::cin>>a>>b;

    if (a>b) {
        std::cout<<"a > b"<<std::endl;
    }else if (a<b) {
        std::cout<<"a < b"<<std::endl;
    }else{
        std::cout<<"a == b"<<std::endl;
    }
    return 0;
}


Measured memory_bytes: 3096
function Main(input) {
    var N = parseInt(input[0], 10);
    var M = parseInt(input[1], 10);
    var A = input.slice(2).map(i => parseInt(i, 10));

    var sum = 0;

    for (var i = 0; i < N; i++) {
        sum += A[i];
    }
    
    var min = sum / (4 * M);
    var result = 0;

    for (var i = 0; i < N; i++) {
        if (A[i] >= min) {
            result++;
        }
    }

    console.log(result >= M ? 'Yes' : 'No');
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 21064
#include <iostream>
#include <stdio.h>
#define llint long long

using namespace std;

llint n;
llint a, d;

double calc(double a, double d, llint n)
{
	if(n <= 1) return (2*a+d)/2;
	double ret = 2*a+(2*n-1)*d; ret /= 2;
	double na = ((2*n+2)*a+5*d)/(2*n), nd = (2*n+4)*d/(2*n);
	return ret + calc(na, nd, n-1);
}

int main(void)
{
	cin >> n >> a >> d;
	printf("%.11f\n", calc(a, d, n));
	return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define mp make_pair
#define PI acos(-1)
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll i,j,k,x,y,z,m,n,t,a,b,c,l,r,q;
    cin>>n;
    vector<ll>v1(n);
    ll sum=0;
    for(i=0; i<n; i++)
    {
        cin>>v1[i];
        sum^=v1[i];
    }
     for(i=0; i<n; i++)
    {
        ll ans=sum^v1[i];
        cout<<ans<<" ";
    }
}








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

const static int vy[] = {-1, -1, 0, 0, 1, 1};
const static int vx[] = {-1, 0, -1, 1, 0, 1};

int N, C;
int M[10][10];
bool connect[10][10], up[10][10], out[10][10];

bool dfs1(int y, int x, const int d)
{
  bool flag = false;
  for(int i = 0; i < 6; i++) {
    int ny = y + vy[i], nx = x + vx[i];
    if(ny < 0 || nx < 0 || ny >= N || nx > ny) continue;
    if(M[ny][nx] == 0) flag = true;
    if(M[ny][nx] == d) {
      if(connect[ny][nx]++) continue;
      flag |= dfs1(ny, nx, d);
    }
  }
  return(flag);
}


int dfs2(int y, int x, const int d)
{
  connect[y][x] = true;
  int ret = 1;
  for(int i = 0; i < 6; i++) {
    int ny = y + vy[i], nx = x + vx[i];
    if(ny < 0 || nx < 0 || ny >= N || nx > ny) continue;
    if(connect[ny][nx]) continue;
    if(M[ny][nx] == d) ret += dfs2(ny, nx, d);
  }
  return(ret);
}

int update()
{
  int get = 0;
  memset(connect, false, sizeof(connect));
  memset(up, false, sizeof(up));
  
  for(int i = 0; i < N; i++) {
    for(int j = 0; j <= i; j++) {
      if(connect[i][j]++) continue;
      if(M[i][j] != 0) up[i][j] = !dfs1(i, j, M[i][j]);
    }
  }
  
  memset(connect, false, sizeof(connect));
  for(int i = 0; i < N; i++) {
    for(int j = 0; j <= i; j++) {
      if(up[i][j]) {
        if(connect[i][j]++) continue;
        if(M[i][j] == C) get -= dfs2(i, j, M[i][j]);
        else get += dfs2(i, j, M[i][j]);
      }
    }
  }
  return(get);
}

int solve()
{
  int ret = -114514, CP[10][10];
  for(int i = 0; i < N; i++) {
    for(int j = 0; j <= i; j++) {
      CP[i][j] = M[i][j];
    }
  }
  for(int i = 0; i < N; i++) {
    for(int j = 0; j <= i; j++) {
      if(CP[i][j] == 0) {
        for(int k = 0; k < N; k++) {
          for(int l = 0; l <= k; l++) {
            M[k][l] = CP[k][l];
          }
        }
        M[i][j] = C;
        ret = max(ret, update());
      }
    }
  }
  
  return(ret);
}

int main()
{
  while(cin >> N >> C, N) {
    for(int i = 0; i < N; i++) {
      for(int j = 0; j <= i; j++) {
        cin >> M[i][j];
      }
    }
    cout << solve() << endl;
  }
}

Measured memory_bytes: 1160
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

// vector<vector<int>> data(3, vector<int>(4));

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

  int n, d;
  cin >> n >> d;

  int ans = 0;

  double x, y;

  rep(i, n) {
    cin >> x >> y;

    double kyo = sqrt((x * x) + (y * y));

    if (kyo <= d) {
      ans++;
    }
  }

  cout << ans;
}

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

using namespace std;

int main()
{

	unordered_set<int> s;
	int N, val;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> val;
		if (s.count(val))
		{
			cout << "NO";
			return 0;
		}
		s.insert(val);
	}
	cout << "YES";
	return 0;
}


Measured memory_bytes: 11336
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b, c, i, ans;
    cin >> a >> b >> c;
    ans = 0;
    for(i=a; i<=b; i++)
    {
        if(c % i == 0)
            ans++;
    }
    cout << ans << endl;
}


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

#define ll long long
#define N (ll)(2*1e5)
#define EPS (double)(1e-12)
#define M (ll)(1e9+7)

using namespace std;


int main() {
    // 176 algorithm design manual
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    ll n;

    cin >> n;

    vector<ll> arr(n);

    for(ll i = 0; i < n; i++)
        cin >> arr[i];

    ll conta = 0;
    for(int i = 1; i < n-1; i++) {
        ll menor = min({arr[i-1], arr[i], arr[i+1]});
        ll maior = max({arr[i-1], arr[i], arr[i+1]});
        if(arr[i] != menor && arr[i] != maior)
            conta++;
    }
    cout << conta << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll R, G, B, N;
    cin >> R >> G >> B >> N;
    ll cnt = 0;
    rep(r, 3001) {
        rep(g, 3001) {
            ll tmp = N - r * R - g * G;
            if (tmp >= 0 && tmp % B == 0) {
                cnt ++;
            }
        }
    }
    print(cnt);
    return 0;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		double r = scanner.nextDouble();
		System.out.println(BigDecimal.valueOf(Math.PI * r * r).toPlainString());
		System.out.println(BigDecimal.valueOf(2 * Math.PI * r).toPlainString());
		scanner.close();
	}

}


Measured memory_bytes: 28156
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(long long i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class FSumDifference {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        lint N, X, D, ans = 0;
        in>>N>>X>>D;
        if(not D){
            if(not X) out<<1<<'\n';
            else out<<N+1<<'\n';
            return;
        }
        if(D<0) D *= (-1), X *= (-1);
        map<lint, vc<pll>> MP;
        REP(i, N+1){
            lint mn = (i-1) * i / 2;
            lint mx = (N-1) * N / 2 - (N-i-1) * (N-i) / 2;
            lint key = (i*X%D+D) % D;
            MP[key].eb(i*X+mn*D, i*X+mx*D);
        }
        for(auto& p : MP){
            sort(ALL(p.second));
            lint mx = -ten(15);
            for(auto& seg : p.second){
                if(seg.second<mx) continue;
                ans += (seg.second-max(seg.first, mx)) / D + 1;
                chmax(mx, seg.second+D);
            }
        }
        out<<ans<<'\n';
    }
};


int main() {
	FSumDifference solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 25440
# D-Knapsack 1
N,W = map(int,input().split())
Weight = [0 for _ in range(N)]
Value = [0 for _ in range(N)]
for i in range(N):
    Weight[i],Value[i] = map(int,input().split())

# dp[i+1][w]:= i番目までの品物の中から重さがwを超えないように選んだときの、価値の総和の最大値
dp = [[0 for i in range(W+1)] for j in range(N+1)]

for i in range(N):
    # あらゆる合計重量sum_wに対して品物iを入れるべきか計算する
    for sum_w in range(W+1):
        # i番目を選ぶ場合
        if sum_w - Weight[i] >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - Weight[i]] + Value[i])

        # i番目を選ばない場合
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])

# for d in dp:
#     print(d)

print(dp[N][W])

Measured memory_bytes: 171784
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int A, B; cin >> A >> B;
    if (A < B) swap(A,B);
    if (A > 9) {
        cout << -1 << endl;
    } else {
        cout <<  A * B << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int pr[100010],l,r;
int q;
bool f[100010];
int main(){
	for(int i=2;i<=100000;i++){
		if(f[i]==0){
			for(int j=i;j<=100000;j+=i)f[j]=1;
			f[i]=0;
		}
	}
	for(int i=3;i<=100000;i++){
		pr[i]=pr[i-1];//cout<<f[i]<<" "<<f[(i+1)/2]<<endl;
		if(f[i]==0&&f[(i+1)/2]==0)pr[i]++;
    }
   // cout<<pr[13];
    cin>>q;
    while(q--){
    	cin>>l>>r;
   	cout<<pr[r]-pr[l-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

    static int MOD = 1_000_000_007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        char[][] G = new char[H+1][W+1];
        for(int i = 1; i <= H; i++){
            char[] s = sc.next().toCharArray();
            for(int j = 1; j <= W; j++){
                G[i][j] = s[j-1];
            }
        }
        int[][] dp = new int[H+1][W+1];
        dp[1][1] = 1;
        for(int i = 1; i <= H; i++){
            for(int j = 1; j <= W; j++){
                if(G[i][j] == '.') dp[i][j] += (dp[i][j-1] + dp[i-1][j]) % MOD;
                else dp[i][j] = 0;
            }
        }
        System.out.println(dp[H][W]);
        sc.close();

    }

}


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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, K;
  cin >> N >> K;
  llvec A(N);
  rep(i, N)cin >> A[i];
  sort(ALL(A));
  ll ans = 0;
  rep(i, K){
    ans += A[i];
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b>c+d){
        cout<<"Left"<<endl;
    }else if(a+b<c+d){
        cout<<"Right"<<endl;
    }else{
        cout<<"Balanced"<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
using namespace std;
int main(){
	long long int a, b, c, d;
	cin >> a >> b >> c >> d;
	long long int e[4];
	e[0] = a * c;
	e[1] = b * c;
	e[2] = a * d;
	e[3] = b * d;
	
	sort(e, e + 4);
	cout << e[3] << "\n";
	}


Measured memory_bytes: 3644
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600

class UnionFind {
public:
  vector<int> par, rank; // parent(negative := its root and abs-value is its size), depth
  UnionFind(int sz) : par(sz, -1), rank(sz, 0){}
  int find(int x){
    if(par[x]<0) return x;
    else return par[x] = find(par[x]);
  }
  void unite(int x, int y){
    x=find(x); y=find(y);
    if(x==y) return;  // already belong to same tree
    if(rank[x] < rank[y]){  // y becomes parent node
      par[y] += par[x];
      par[x] = y;
    } else {  // x becomes parent node
      par[x] += par[y];
      par[y] = x;
      if(rank[x]==rank[y]) rank[x]++;
    }
  }
  bool same(int x, int y){ return find(x) == find(y); }
  int size(int x){ return -par[find(x)]; }
}; // END class UnionFind

int x[10000];
int y[10000];

int main(){
  int n,m;
  cin>>n>>m;
  rep(i,n) scanf("%d %d", x+i, y+i);
  vector<pair<double, pair<int, int> > > vec(m);
  rep(i,m){
    int p,q;
    scanf("%d %d", &p, &q);
    p--;q--;
    double d = sqrt((x[p]-x[q])*(x[p]-x[q]) + (y[p]-y[q])*(y[p]-y[q]));
    vec[i].fi = d;
    vec[i].se = mp(p,q);
  }
  sort(all(vec));
  reverse(all(vec));

  UnionFind uf(n);
  double res=0;
  rep(i,m){
    if(uf.same(vec[i].se.fi, vec[i].se.se)){
      res += vec[i].fi;
    } else {
      uf.unite(vec[i].se.fi, vec[i].se.se);
    }
  }
  printf("%.4f\n", res);

  return 0;
}

Measured memory_bytes: 3396
#include<stdio.h>
#include<string.h>
int dice[6],temp;
void east()
{
	int t = dice[2];
	dice[2] = dice[0];
	dice[0] = dice[3];
	dice[3] = dice[5];
	dice[5] = t;
}

void south()
{
	int t = dice[1];
	dice[1] = dice[0];
	dice[0] = dice[4];
	dice[4] = dice[5];
	dice[5] = t;
}

void west()
{
	int t = dice[3];
	dice[3] = dice[0];
	dice[0] = dice[2];
	dice[2] = dice[5];
	dice[5] = t;
}

void north()
{
	int t = dice[4];
	dice[4] = dice[0];
	dice[0] = dice[1];
	dice[1] = dice[5];
	dice[5] = t;
}
int main()
{
    char direction[100];
    int i;
    for(i=0; i<6; i++)
    {
        scanf("%d",&dice[i]);
    }
    scanf("%s",&direction);
    for(i=0; i<strlen(direction); i++)
    {
        switch(direction[i])
        {
        case 'E':
            east();
            break;
        case 'S':
            south();
            break;

        case 'W':
            west();
            break;

        case 'N':
            north();
            break;
        }
    }
    printf("%d\n",dice[0]);
    return 0;
}



Measured memory_bytes: 2036