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

#define ll long long
#define ld long double
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

ll dp[(int)1e6][2];
ll a[(int)1e6];

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

    rep(i, n)
    {
        cin >> a[i + 1];
    }

    dp[2][0] = a[1];
    dp[2][1] = (-1) * a[1];
    a[0] = 0;
    //cout << dp[0][0] << dp[0][1] << endl;
    for (size_t i = 2; i < n; i++)
    {
        dp[i + 1][0] = max(dp[i][0] + a[i], dp[i][1] - a[i]);
        dp[i + 1][1] = max(dp[i][1] + a[i], dp[i][0] - a[i]);
        //cout << dp[i + 1][0] << dp[i + 1][1] << endl;
    }
    cout << max(dp[n][0] + a[n], dp[n][1] - a[n]) << endl;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#include <experimental/iterator>

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

/* debug */
auto debug = std::experimental::make_ostream_joiner(std::cout, " ");

/* snippet: modint library */
template<class T, int MOD>
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val % MOD + (val > 0 ? 0 : MOD)) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* snippet: using declarations */
using Int = long long;
using std::cout;
using std::cin;
using std::endl;
using Mint = Modint<long long, 1000000007>;

int main(){
	Int a, b, c, k;
	cin >> a >> b >> c >> k;
	if(k <= a){
		cout << k << endl;
	}else if(k <= a + b){
		cout << a << endl;
	}else{
		cout << a - (k - a - b) << endl;
	}

}


Measured memory_bytes: 3632
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
def jan(a):
    if a == 'r':
        return P
    elif a == 's':
        return R
    else:
        return S
ans = 0
for i in range(K):
    check = 'n' + T[i::K]
    h = 0
    for i in range(len(check)-1):
        if check[i] != check[i+1]:
            ans += jan(check[i+1])
            h = 0
        else:
            if h == 0:
                h = 1
            else:
                ans += jan(check[i+1])
                h = 0
print(ans)

Measured memory_bytes: 74056
/**akshaykumar99**/
 
#include<bits/stdc++.h>
using namespace std;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=2e5+1;
 
typedef long long ll;
typedef long double ld;

int main()
{
    IOS();
  
    ll n,x,y;
    vector<ll> v;
    cin>>n;
    cout<<n*n<<'\n';
    return 0;

}

Measured memory_bytes: 256
N = int(input())
X = list(map(int,input().split()))
ans = 1000**1000
for P in range(0,101):
    for i in range(1,N+1):
        if i == 1:
            c = (X[0]-P)**2
        else:
            c += (X[i-1] - P)**2
    if c < ans:
        ans = c
print(ans)

Measured memory_bytes: 3060
n = int(input())
a = []
b = []
for i in range(n):
  x,y = map(int,input().split())
  a.append(x)
  b.append(y)
a.sort()
b.sort()
if n % 2 == 1:
  print(b[n//2] - a[n//2] + 1)
else:
  print(b[n//2]+b[n//2-1]-a[n//2]-a[n//2-1]+1)

Measured memory_bytes: 99056
// 問題の URL を書いておく
// https://atcoder.jp/contests/abc074/tasks/arc083_b

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <numeric>
using namespace std;

//#define ENABLE_PRINT

template<typename T>
T Input()
{
    T v;
    cin >> v;
    return v;
}

template<typename T>
vector<T> InputVector(int n)
{
    vector<T> v(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    return v;
}

template<typename T>
void InputArray(T* begin, int n)
{
    for(int i = 0; i < n; ++i)
    {
        cin >> begin[i];
    }
}

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

int main(int, const char**)
{
    int n;
    cin >> n;
    vector<vector<int64_t>> g(n, vector<int64_t>(n, 0));
    rep(i, n)
    {
        rep(j, n)
        {
            cin >> g[i][j];
        }
    }

    rep(i, n)
    {
        rep(j, n)
        {
            rep(k, n)
            {
                if(!(i != j && j != k && i != k))
                {
                    continue;
                }
                auto a = g[i][j];
                auto b = g[j][k];
                auto c = g[k][i];
                if(a > b + c)
                {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }
    
    int64_t ans = 0;
    rep(i, n)
    {
        rep(j, n)
        {
            rep(k, n)
            {
                if(!(i != j && j != k && i != k))
                {
                    continue;
                }                
                auto a = g[i][j];
                auto b = g[j][k];
                auto c = g[k][i];
                if(a == b + c)
                {
                    ans -= g[i][j];
                    break;
                }
            }
        }
    }
    
    rep(i, n)
    {
        rep(j, n)
        {
            ans += g[i][j];
        }
    }

    cout << ans / 2 << endl;
    return 0;
}


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

int main()
{
    int a, b, c, result;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    result = c - a + b;
    if (result < 0)
        result = 0;
    printf("%d", result);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

// a^b mod m
int powmod(int a,int b,int m)
{
	if(b==0) return 1;
	int x=powmod(a,b/2,m); x=x*x%m;
	return b&1?x*a%m:x;
}
int inv(int n,int m)
{
	return powmod(n,m-2,m);
}

int expr(const string& s,int m,int& i);

int fact(const string& s,int m,int& i)
{
	int n=s.size();
	if(s[i]=='('){
		i++;
		int res=expr(s,m,i);
		i++;
		return res;
	}
	int res=0;
	while(i<n && isdigit(s[i]))
		res=res*10+s[i++]-'0';
	return res;
}

int term(const string& s,int m,int& i)
{
	int n=s.size();
	int res=fact(s,m,i);
	while(i<n){
		int op=s[i];
		if(op!='*' && op!='/') break;
		int tmp=fact(s,m,++i);
		if(op=='*') res=res*tmp%m;
		if(op=='/'){
			if(tmp==0) throw "NG";
			res=res*inv(tmp,m)%m;
		}
	}
	return res;
}

int expr(const string& s,int m,int& i)
{
	int n=s.size();
	int res=term(s,m,i);
	while(i<n){
		int op=s[i];
		if(op!='+' && op!='-') break;
		int tmp=term(s,m,++i);
		if(op=='+') res=(res+tmp)%m;
		if(op=='-') res=(res-tmp+m)%m;
	}
	return res;
}

int main()
{
	for(int p;scanf("%d%*c",&p),p;){
		static char line[100005]; 
		fgets(line,sizeof line,stdin);
		int n=strlen(line); 
		line[--n]=0;
		
		{
			int j=0;
			rep(i,n) if(line[i]!=' ') line[j++]=line[i];
			line[j]=0;
		}
		string s=line;
		//dump(line); dump(s);
		
		try{
			int i=0;
			int res=expr(s,p,i);
			printf("%s = %d (mod %d)\n",line,res,p);
		}
		catch(const char*){
			puts("NG");
		}
	}
	
	return 0;
}

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

int main() 
{ 
     
    long long int h;
    cin>>h;
    long long int cnt=0;
    long long int i=1;
    while(h>0){
        h=h/2;
        cnt+=i;
        i=i*2;
    }
    cout<<cnt;
	return 0; 
} 


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

using ll = long long;
using namespace std;

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    int cost[n + 1][n + 1];
    for (int i = 0; i <= n; i++)
        for (int k = 0; k <= n; k++)
            cost[i][k] = 0;
    for (int i = 1; i < x; i++) {
        for (int k = i + 1; k <= x; k++) {
            cost[i][k] = k - i;
            cost[k][i] = k - i;
        }
    }
    for (int i = y; i < n; i++) {
        for (int k = i + 1; k <= n; k++) {
            cost[i][k] = k - i;
            cost[k][i] = k - i;
        }
    }
    for (int i = x; i < y; i++) {
        for (int k = i + 1; k <= y; k++) {
            int c = min(k - i, 1 + y - k + i - x);
            cost[i][k] = c;
            cost[k][i] = c;
        }
    }
    for (int i = 1; i <= x; i++) {
        for (int k = x + 1; k <= y; k++) {
            cost[i][k] = cost[i][x] + cost[x][k];
            cost[k][i] = cost[i][x] + cost[x][k];
        }
    }
    for (int i = x; i < y; i++) {
        for (int k = y; k <= n; k++) {
            cost[i][k] = cost[i][y] + cost[y][k];
            cost[k][i] = cost[i][y] + cost[y][k];
        }
    }
    for (int i = 1; i <= x; i++) {
        for (int k = y; k <= n; k++) {
            cost[i][k] = cost[i][x] + cost[y][k] + 1;
            cost[k][i] = cost[i][x] + cost[y][k] + 1;
        }
    }
    map<int, int> ans;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k <= n; k++) {
            int c = cost[i][k];
            ans[c]++;
        }
    }
    for (int i = 1; i <= n - 1; i++) {
        cout << ans[i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  string a,x,y;
  ll l,ans,pl,i,z;
  cin >> a;
  x=a[0];
  y=a[1];
  l=1;
  pl=0;
  ans=0;
  for(i=2;i<=(ll)a.size()+1;i++){
    if(x==y){
      l+=1;
    }
    else if(x=="<"){
      pl=l;
      ans+=(l+1)*l/2;
      l=1;
      x=y;
    }
    else{
      ans+=(l+1)*l/2-min(l,pl);
      l=1;
      x=y;
    }
    y=a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 900
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
import java.io.*;
public class Main
{
	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String a = in.readLine();
		boolean playable = true;
		for(int i = 0; i < a.length(); i++) {
		    if(i%2==0) {
		        if(a.charAt(i)!='R' && a.charAt(i)!='U' && a.charAt(i)!='D'){
		            playable = false;
		            break;
		        }
		    } else {
		        if(a.charAt(i)!='L' && a.charAt(i)!='U' && a.charAt(i)!='D'){
		            playable = false;
		            break;
		        }
		    }
		}
		if(playable) {
		    System.out.println("Yes");
		} else {
		    System.out.println("No");
		}
	}
}


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

int main(void) {
	// N表示物品总数 W表示背包容量
	// w表示每件物品的重量 v表示每件物品的价值
	// K[i][j]表示背包容量为i时，前j件物品的最大价值
	int N, W, *w, *v, **K;
	cin >> N >> W;
	w = new int[N];
	v = new int[N];

	for (int i = 0; i < N; i++) {
		cin >> v[i] >> w[i];
	}

	K = new int*[W+1];
	for (int i = 0; i < W+1; i++) {
		K[i] = new int[N+1];
	}

	for (int i = 0; i <= N; i++) {
		K[0][i] = 0;
	}

	// 需要注意，第j件物品，他的价值与重量分别是v[j-1],w[j-1]
	for (int i = 1; i <= W; i++) {
		K[i][0] = 0;
		for (int j = 1; j <= N; j++) {
			if (w[j-1] > i) {
				K[i][j] = K[i][j-1];
			} else {
				K[i][j] = max(K[i][j-1], K[i-w[j-1]][j-1] + v[j-1]);
			}
		}
	}

	cout << K[W][N] << endl;
}


Measured memory_bytes: 7236
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n; cin >> n;
    for (int i = n; i >= 1; i--) {
        if (sqrt(i) == int(sqrt(i))) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    long long int a, d, c;
   double b;
    scanf("%lld %lf", &a, &b);
    c = round(b*100.0);
    d = (a*c)/100;
   printf("%lld\n",d);

    return 0;
}


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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

struct BIT{
	// 1-indexed BIT
private:
	int N; vector<int> bit;
public:
	BIT(int size){
		N = size;
		bit.assign(N+1, 0);
	}
	void add(int a, int w){
		for(int x = a; x <= N; x += x & -x)
			bit[x] += w;
	}
	int sum(int a){ // prefix sum
		int res = 0;
		for(int x = a; x > 0; x -= x & -x)
			res += bit[x];
		return res;
	}
};

struct query{
	int l, r, idx;
};

int main(){
	summon_tourist;

	int N, Q, C[500010];
	cin >> N >> Q;
	REP(i, N){
		cin >> C[i+1]; C[i+1]--;
	}
	vector<query> que(Q);
	REP(i, Q){
		cin >> que[i].l >> que[i].r;
		que[i].idx = i;
	}
	sort(ALL(que), [](auto const& a, auto const& b){
		return a.r < b.r;
	});
	vint ans(Q);
	vint appear(N, -1);
	BIT bit(N);
	int index = 1;
	REP(i, Q){
		while(index <= que[i].r){
			int color = C[index];
			if(appear[color] == -1){
				appear[color] = index;
				bit.add(index, 1);
			} else {
				bit.add(appear[color], -1);
				appear[color] = index;
				bit.add(index, 1);
			}
			index++;
		}
		ans[que[i].idx] = bit.sum(que[i].r) - bit.sum(que[i].l-1);
	}
	REP(i, Q){
		cout << ans[i] << ln;
	}
}

Measured memory_bytes: 17444
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int a,b,n;
const LL INF=1e16;
set <LL> s,t;
set <LL>::iterator it,it1,it2;
int main() 
{
	LL x;
	scanf("%d%d%d",&a,&b,&n);
	for (int i=1;i<=a;i++) scanf("%lld",&x),s.insert(x);
	for (int i=1;i<=b;i++) scanf("%lld",&x),t.insert(x);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld",&x);
		s.insert(x);
		it=s.find(x);
		it1=it,it2=it;
		LL bs=-INF,bt=-INF;
		LL ns=INF,nt=INF;
		if (it1!=s.begin()) it1--,bs=*it1;
		if (it2!=(--s.end())) it2++,ns=*it2;
		s.erase(it);
		t.insert(x);
		it=t.find(x);
		it1=it,it2=it;
		if (it1!=t.begin()) it1--,bt=*it1;
		if (it2!=(--t.end())) it2++,nt=*it2;
		t.erase(it);
		LL drr=max(nt,ns)-x,dll=x-min(bs,bt),dlr=2*(nt-x)+x-bs,drl=2*(ns-x)+x-bt,dlr1=nt-x+2*(x-bs),drl1=ns-x+2*(x-bt);
		LL ans=min(drr,min(min(dll,dlr),drl));
		ans=min(min(ans,dlr1),drl1);
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 10752
#include <iostream>

using namespace std;

int main(){
  int N, A, B, ans = 0;
  cin >> N >> A >> B;

  for (int i = 1; i <= N; i++){
    // 各桁を足した値
    int ss = 0, n = i;
    while(n != 0){
      int s = n%10;
      n /= 10;
      ss += s;
    }
    
    if(A <= ss && B >= ss){
      ans += i;
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 3748
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String str = s.next();
		int n = str.length();
		char[] arr = new char[n];
		for(int i = 0; i < n; i++) {
			if(str.charAt(i) == 'P') {
				arr[i] = 'P';
			} else {
				arr[i] = 'D';
			}
		}
		System.out.println(new String(arr));

	}
	
	

}


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

#define ll long long
#define ull unsigned long long

bool isPalindrome(string s) {
    string t(s.rbegin(), s.rend());
    return s == t;
}

ll P[] = { 0, 0, 0, 0, 0, 0, 1, 1, 1, 2 };
ll Q[] = { 1, 1, 1, 2, 2, 3, 2, 2, 3, 3 };
ll R[] = { 2, 3, 4, 3, 4, 4, 3, 4, 4, 4 };
ll D[5];
int main(void) {
    ll N;
    ll count = 0;
    ll res = 0;
    bool flags[5] = { true };
    cin >> N;
    for(ll i = 0;i < N;i++) {
        string name;
        cin >> name;
        if(name[0] == 'M') D[0]++;
        if(name[0] == 'A') D[1]++;
        if(name[0] == 'R') D[2]++;
        if(name[0] == 'C') D[3]++;
        if(name[0] == 'H') D[4]++;
    }
    for(ll i = 0;i < 10;i++) res += D[P[i]] * D[Q[i]] * D[R[i]];
    cout << res << endl;
    return 0;
}


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

int compare_char(char *a,char *b){
	return strcmp(a,b);
}

int intsort(const void *a, const void *b){
	return *(int*)b - *(int*)a;
	/*qsort(a,aの配列数,sizeof(int),intsort);*/
}

int longsort(const void *a, const void *b){
	long *A=(long *)a;
	long *B=(long *)b;
	if(*A>*B) return -1;
	if(*A<*B) return 1;
	return 0;
}

int main(){
  int i,N,M,l,r,ml=0,mr=1000000;
  scanf("%d",&N);
  scanf("%d",&M);
  for(i=0;i<M;i++){
    scanf("%d",&l);
    scanf("%d",&r);
    if(ml<l)ml=l;
    if(mr>r)mr=r;
  }
  if(mr<ml){
    printf("0\n");
  }else{
    printf("%d\n",mr-ml+1);
  }
  return 0;
}

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

int main(void)
{
	double a; //縦
	double b; //横
	double s; //面積
	double l; //周の長さ

	cin >> a >> b;

	if (a <= 0 || a > 100 || b <= 0 || b > 100)
	{
		return 0;
	}

	s = a * b;
	l = 2 * a + 2 * b;

	cout << s << ' ' << l << endl;

	return 0;
}


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

int calc(string &s,int &i){
  int res=0;
  while(1){
    if(isdigit(s[i]))res=s[i++]-'0';
    else if(s[i]=='('){res=calc(s,++i),i++;}
    else if(s[i]=='+')res+=calc(s,++i);
    else if(s[i]=='-')res-=calc(s,++i);
    else break;
  }
  return res;
}

map<string,int> mem[2];
int dfs(string s,int f){
  if(mem[f].count(s))return mem[f][s];

  int j=0,res=calc(s,j),n=s.size(),d=-1;
  for(int i=0;i<n;i++) d+=(s[i]=='+'||s[i]=='-');
  
  for(int i=0,c=0,cnt=0;i<n;i++,cnt++,d--){
    while(1){
      while(s[i]=='('||s[i]==')')c+=(s[i]=='(')-(s[i]==')'),i++;
      if(i>=n||s[i]=='+'||s[i]=='-') break;
      i++;
    }
    if(i>=n||(cnt&&s[i-2]=='(')||(d&&s[i+2]==')'))continue;
    string a=s.substr(0,i),b=s.substr(i+1,n-i-1);
    int t=c,ch=s[i];
    while(t--)a+=')',b='('+b;
    int mxa=dfs(a,0),mna=dfs(a,1);
    int mxb=dfs(b,0),mnb=dfs(b,1);
    if(f==0&&ch=='+') res=max(res, mxa+mxb);
    if(f==0&&ch=='-') res=max(res, mxa-mnb);
    if(f==1&&ch=='+') res=min(res, mna+mnb);
    if(f==1&&ch=='-') res=min(res, mna-mxb);
  }
  return mem[f][s]=res;
}

int main(){
  string S;
  cin>>S;
  cout <<dfs(S,0)<<endl;
  return 0;
}

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

lli h, w;

int main(void){
    cin >> h >> w;
    if(h == 1 || w == 1) cout << 1 << endl;
    else if(h*w%2 == 0){
        cout << h*w/2 << endl;
    }else{
        cout << (h*w+1)/2 << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin>>n;
	vector<int> v(n);
	for(int &x:v)cin>>x;
	vector<int> pre(n),suf(n);
	pre[0] = v[0];
	for(int i=1;i<n;i++)
		pre[i] = v[i] ^ pre[i-1];
	
	suf[n-1] = v[n-1];
	
	for(int i=n-2;i>=0;i--)
		suf[i] = v[i] ^ suf[i+1];
		
	for(int i=0;i<n;i++)
	{
		int p = -1;
		int s = -1;
		if(i>0)p = pre[i-1];
		if(i<n-1)s = suf[i+1];
		if(p==-1 and s==-1)cout<<v[i]<<' ';
		else if(p==-1)cout<<s<<' ';
		else if(s==-1)cout<<p<<' ';
		else cout<<(p^s)<<' ';
	}
	cout<<'\n';
}


Measured memory_bytes: 5568
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

int main() {
	int N;
	cin >> N;
	int ans = 0;
	for (size_t i = 1; i <= N; i++)
	{
		if (((int)log10(i)) % 2==0)ans++;
	}
	cout << ans;
}

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

long inv(int a, int m) {
    long i = 1, j = 0;
    for(int b = m; a > 1; swap(i, j), swap(a, b)) {
        j = (j + b / a * (m - i)) % m;
        b %= a;
    }
    return i;
}
int main() {
    int n, a, b, p = 1e9 + 7;
    cin >> n >> a >> b;
    long e = 1, x = 1, y = 1, A = 1, B = 1, d = 2;
    for(int m = n; m; m /= 2) {
        if(m % 2)
            (e *= d) %= p;
        (d *= d) %= p;
    }
    for(int i = 0; i < a; i++)
        (x *= n - i) %= p, (A *= a - i) %= p;
    for(int i = 0; i < b; i++)
        (y *= n - i) %= p, (B *= b - i) %= p;
    cout << (e + p + p - inv(A, p) * x % p - inv(B, p) * y % p - 1) % p << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=10050;
//↑templete
signed main(){

	string S;
	cin>>S;
    int N=S.length(), P=2019;

	ll ans=0;
	if(P==2 || P==5){
		for(int i=0;i<N;i++){
			int s=S[i]-'0';
			if(s%P==0)
				ans+=i+1;
		}
		cout<<ans<<endl;
		return 0;
	}

	reverse(S.begin(), S.end());
	vint A(1);
	int now=0, pot=1;
	for(int i=0;i<N;i++){
		int s=S[i]-'0';
		(pot*=10)%=P;
		now=(s*pot+now)%P;
		A.pb(now);
	}

	ll cnt[10001]={};
	for(int a:A)
		cnt[a]++;

	for(int i=0;i<P;i++)
		ans+=cnt[i]*(cnt[i]-1)/2;
	
	cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 4424
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
using namespace std;
#define PI 3.14159265358979
#define rep(i,n) for(int i=0;i<n;i++)


int main(void){

string s;

cin>>s;
int ans =0;
int size = s.size();

for(int i=0;i<ceil(size/2);i++)
{
if(s[i]!=s[size-i-1]) ans++;

}
  
  
  cout<<ans<<endl;
}




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

int main() {
  long long n,w,sum=0, mod=2019;
  cin>>n>>w;
  
  if(n<=w)
    cout<<"unsafe"<<endl;
  else
    cout<<"safe"<<endl;
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    int N, Q;
    cin >> N;
    long long sum = 0;
    vector<long long> num(110000, 0);
    for (int i = 0; i < N; ++i) {
        long long A;
        cin >> A;
        sum += A;
        num[A]++;
    }
        
    cin >> Q;
    for (int i = 0; i < Q; ++i) {
        long long B, C;
        cin >> B >> C;
        sum += (C - B) * num[B];
        num[C] += num[B];
        num[B] = 0;
        cout << sum << endl;
     }
}

















Measured memory_bytes: 4020
//AnkitCode99 (DP)....
//every ups and downs matter!

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr)
typedef long long int ll;

using namespace std;

const ll sz=1e5+5;
vector<ll> adj[sz];
ll cache[sz];

ll dfs(ll node)
{
    ll &ans=cache[node];
    if(ans!=-1)
        return ans;
    ans=0;
    for(auto &child:adj[node])
    {
        ans=max(ans,1LL+dfs(child));
    }
    return ans;


}

int main()
{
    fast;
    
    memset(cache,-1,sizeof cache);

    ll n,m;
    cin>>n>>m;
    
    for(ll i=1;i<=m;i++)
    {
        ll a,b;
        cin>>a>>b;
        adj[a].push_back(b);
    }

    
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        ans=max(ans,dfs(i));
    }
    cout<<ans<<endl;

    
}//Goodbye...

Measured memory_bytes: 7936
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 

const int MOD = 1000000007;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;

    LL ans = min(A+B+1, C) + B;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Rev(a) reverse(a.begin(), a.end())
typedef long long ll;
const ll MOD = 1e9+7;

/*ll gcd(ll a, ll b){
  if(b==0) return a;
  return gcd(b, a%b);
}*/
/*ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}*/

/*ll lcm(ll a, ll b){
  ll g = gcd(a, b);
  b /= g;
  a *= b;
  return a;
}*/

/*int dfs(vector<int> &T, vector<int> &C, int i, int sum, int g, int count){
   
}*/

int main(){
  /*double r;
  cin >> r;
  const double PI=3.14159265358979323846;
  printf("%lf\n", 2*r*PI);*/
  int n, m;
  cin >> n >> m;
  //vector<int> A(m);
  int sum = 0, a; 
  rep(i, m){
    cin >> a;
    sum+=a;
  }
  if(sum<=n) cout << n-sum << endl;
  else cout << -1 << endl;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main() {
    ll i, o, t, j, l, s, z;
    cin >> i >> o >> t >> j >> l >> s >> z;
    int cnt = 0;
    if (i % 2 == 1) cnt++;
    if (j % 2 == 1) cnt++;
    if (l % 2 == 1) cnt++;
    if (cnt <= 1) {
        cout << o + 2 * (i / 2) + 2 * (j / 2) + 2 * (l / 2) << endl;
    } else {
        ll mn = min({i, j, l});
        if (mn != 0 && mn % 2 == 0) {
            cout << o + i + j + l - 1 << endl;
            return 0;
        }
        i -= mn;
        j -= mn;
        l -= mn;
        cout << o + mn * 3 + 2 * (i / 2) + 2 * (j / 2) + 2 * (l / 2) << endl;
    }
    return 0;
}

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

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  int A,B;

  cin>>A>>B;

  if((B-1)%(A-1)==0){
    cout<<(B-1)/(A-1)<<endl;
  }else{
    cout<<(B-1)/(A-1)+1<<endl;
  }

  return 0;

}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}
	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}
	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;


signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	string s; cin >> s;
	ll n = s.size();
	unordered_map<ll, ll> cnt;
	cnt[0] = 1;

	mod = 2019;

	ll sm = 0;
	ll ten = 1;
	ll ans = 0;
	for (ll i = n - 1; i >= 0; i--) {
		sm += ten * (s[i] - '0');
		sm %= mod;
		ans += cnt[sm];

		cnt[sm]++;
		ten *= 10;
		ten %= mod;
	}

	cout << ans << endl;

	return 0;
}

/*

*/

Measured memory_bytes: 3748
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static int[] dp = new int[100];

    public static void main(String[] args) {
        int n = sc.nextInt();
        System.out.println(fib(n));
    }

    static int fib(int n) {
        if (n == 0 || n == 1) return 1;
        if (dp[n] > 0) return dp[n];
        dp[n] = fib(n - 1) + fib(n - 2);
        return dp[n];
    }
}

Measured memory_bytes: 26260
s = int(input())
MOD = 10 ** 9 + 7

s_list = [0] * (s + 1)

for i in range(3, s + 1):
    temp = 1
    for j in range(i - 3):
        temp += (s_list[j+1]) % MOD
    s_list[i] = temp % MOD

print(s_list[s])


Measured memory_bytes: 64524
from collections import defaultdict

n, t = map(int, input().split())
p_list = list(map(int, input().split()))

min_price = p_list[0]
max_rev = 0
max_dict = defaultdict(int)

for price in p_list[1:]:
  rev = price - min_price
  if rev >= max_rev:
    max_rev = rev
    max_dict[rev] += 1
  if price < min_price:
    min_price = price

max_rev_key = max(max_dict, key=max_dict.get)
min_cost = max_dict[max_rev_key]

print(min_cost)

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

void answer1() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  long long a, b, c;
  cin >> a >> b >> c;

  int amari = a % b;
  bool is_ok = false;
  for (int i = 0; i < b; i++) {
    if (i * amari % b == c) {
      is_ok = true;
      break;
    }
  }

  if (is_ok) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
}

int main() {
  answer1();
}


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

int main(int argc, char const *argv[])
{
    int A;
    int B;
    cin >> A >> B;

    int sum_length = B * 2;

    if (A <= sum_length)
    {
        cout << "0" << endl;
    }
    else
    {
        cout << A - sum_length << endl;
    }

    return 0;
}

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int ret=0,x;
	for (int i=0; i<2; i++) {
		cin>>x;
		if(x%2)
			ret++;
	}
	cout << (ret==2 ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#! /usr/bin/env python
# -*- coding: utf-8 -*-

x_list = []
while True:
    x = int(raw_input())
    if x == 0:
        break
    else:
        x_list.append(x)

for i, x in enumerate(x_list, 1):
    print("Case %d: %d") % (i, x)

Measured memory_bytes: 6592
#include<iostream>
using namespace std;
int main(){
    int n,count=0;
    cin>>n;
    int s[n];
    for(int i=0;i<n;i++)cin>>s[i];
    for(int i=0;i+1<n;i++){
        int index=i;
        for(int j=i+1;j<n;j++)if(s[j]>s[index])index=j;
        if(index-i)s[i]^=s[index]^=s[i]^=s[index];
    }
    for(int i=0;i+2<n;i++)for(int j=i+1;j+1<n;j++)for(int k=j+1;k<n;k++)if(s[i]<s[j]+s[k])count++;   
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

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


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll n;
cin>>n;
ll a;
cin>>a;
ll ans=a;
for(ll i=1;i<n;i++){
    cin>>a;
    ans=gcd(ans,a);
}
cout<<ans<<endl;
return 0;
}










Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,P; cin>>N>>P;
  vi dp(N+1);
  string S; cin>>S;
  reverse(ALL(S));
  int ans=0;
  if(P==2||P==5){
    rep(i,0,N){
      int X=S[i]-'0';
      if(X%P==0){
        ans+=N-i;
      }
    }
  }
  else{
    int Z=1;
    rep(i,0,N){
      int X=S[i]-'0';
      dp[i+1]=(dp[i]+X*Z)%P;
      Z*=10;
      Z%=P;
    }
    map<int,int> M;
    REP(i,0,N){
      ans+=M[dp[i]];
      M[dp[i]]++;
    }
  }
  cout<<ans<<endl;
  }







Measured memory_bytes: 2564
# coding: utf-8
# Your code here!

def BFS(K,edges,N):
  roots=[ [] for i in range(N)]
  for a,b,c in edges:
    roots[a-1]+=[(b-1,c)]
    roots[b-1]+=[(a-1,c)]
  dist=[-1]*N
  stack=[]
  stack.append(K)
  dist[K]=0
  while stack:
    label=stack.pop(-1)
    for i,c in roots[label]:
      if dist[i]==-1:
        dist[i]=dist[label]+c
        stack+=[i]
        
  return dist
        
n = int(input()) #n:頂点数　w:辺の数

# d = [[float("inf") for i in range(n)] for i in range(n)] 
d = []
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(n-1):
    # x,y,z = map(int,input().split())
    # x -= 1
    # y -= 1
    # d[x][y] = z
    # d[y][x] = z
    d.append(list(map(int,input().split())))
# for i in range(n):
#     d[i][i] = 0 #自身のところに行くコストは０
# print(warshall_floyd(d))

dist = BFS(0,d,n)
# print(dist)
for elm in dist:
    if elm % 2 == 0:
        print(0)
    else:
        print(1)

Measured memory_bytes: 61720
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    /////////////////////
    // Write code below /
    /////////////////////
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int weightOfLeft  = A + B;
    int weightOfRight = C + D;
    if (weightOfLeft < weightOfRight) {
        cout << "Right" << endl;
    } else if (weightOfLeft > weightOfRight) {
        cout << "Left" << endl;
    } else if (weightOfLeft == weightOfRight) {
        cout << "Balanced" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define se second
#define fi first
#define ss size()
#define pb push_back
#define mp make_pair
#define ins insert
#define ll long long
#define y1 y12313312312
#define endl '\n'
#define gcd gcd
#define tm tadsadaagsd
#define next nqweqweeqeqe
#define er erase
#define int ll

using namespace std;
//using namespace gnu_pbds;

//template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 1e5 + 40, T = 4 * N, logN = (int)log2(N) + 1, inf = 1e9 + 7, sx[4] = {1, -1, 0, 0}, sy[4] = {0, 0, 1, -1};
const ll INF = 1e18 + 9;

int n, m, r, l, e, o, z, ts, id, mx, mn = INF, w;
int a[N][4], d[N];
bool ch;
pair < int, int > col[N];
vector < int > g[N];
int f;

void freop()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

void boos()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int bp (int x, int y) {
    if (y == 0) return 1;
    if (y % 2 == 1) return bp(x, y - 1) * x;
    else
    {
        int asd = bp(x, y / 2);
        return asd * asd;
    }
}

int sum(int x)
{
    int summa = 0;
    while (x)
    {
        summa += x % 10;
        x /= 10;
    }
    return summa;
}

void dfs(int v, int p, int col1, int col2)
{
    f += a[v][col2];
    if (g[v].ss == 1 && p != -1)
    {
        if (f < mn)
        {
            mn = f;
            ch = 1;
        }
    }
    for (int i = 0; i < g[v].ss; i++)
    {
        int to = g[v][i];
        if (to == p) continue;
        dfs(to, v, col2, 6 - col1 - col2);
    }
    if (ch) d[v] = col2;
}

main()
{
    int x, y;
    setprecision(10);
    //freop();
    boos();
    cin >> n;
    f = n / 500 * 1000;
    n %= 500;
    f += n / 5 * 5;
    cout << f;
}


Measured memory_bytes: 4352
import math
x = int(input())
if x <= 11:
    count = 0
    point = 0
    while True:
        point += 6
        count += 1
        if point >= x:
            break
        point += 5
        count += 1
        if point >= x:
            break
    print(count)
else:
    count = math.ceil(x/11)*2
    if count%2 != 0:
        df = 6
    else:
        df = 5
    if count/2 * 11 - df >= x:
        count -= 1
    print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
ll modpow(ll a, ll n, ll mod = MOD) {
    ll res = 1;
    while(n > 0) {
        if(n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main() {
    ll n;
    cin >> n;
    cout << (modpow(10, n) - 2 * modpow(9, n) + modpow(8, n) + 2 * MOD) % MOD
         << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N, K, r, s, p;
    cin >> N >> K >> r >> s >> p;
    string T, U;
    cin >> T;
    U = T;
    map<char, ll> mp;
    mp['r'] = p, mp['s'] = r, mp['p'] = s;
    map<char, char> mc;
    mc['r'] = 'p', mc['s'] = 'r', mc['p'] = 's';

    ll ans = 0;
    rep(i, N) {
        if(i - K >= 0 && T[i] == T[i-K] && U[i-K] == mc[T[i]]) U[i] = T[i];
        else {
            ans += mp[T[i]];
            U[i] = mc[T[i]];
        }
    }
    cout << ans <<endl;
}


Measured memory_bytes: 512
import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        
        System.out.println(A*B/2);
        
    }
}

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

using namespace std;

typedef long long ll;

int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<char>> a(h+2,vector<char>(w+2,'.'));
    for (int i = 1; i < h+1; i++) {
        for (int j = 1; j < w+1; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 1; i < h+1; i++) {

        for (int j = 1; j < w+1; j++) {
            int cnt =0;
            if(a[i][j]=='#'){
                continue;
            }
            if (a[i][j] == '.'){
                if (a[i][j-1]=='#'){
                    cnt++;
                }
                if (a[i][j+1]=='#'){
                    cnt++;
                }
                if (a[i-1][j-1]=='#'){
                    cnt++;
                }
                if (a[i+1][j+1]=='#'){
                    cnt++;
                }
                if (a[i+1][j-1]=='#'){
                    cnt++;
                }
                if (a[i-1][j+1]=='#'){
                    cnt++;
                }
                if (a[i+1][j]=='#'){
                    cnt++;
                }
                if (a[i-1][j]=='#'){
                    cnt++;
                }
                a[i][j] = '0'+cnt;

            }
        }
    }
    for (int i = 1; i < h+1; i++) {
        for (int j = 1; j < w+1; j++) {
            cout << a[i][j];
        }
        cout << endl;
    }

    


    return 0;
}

Measured memory_bytes: 3576
N = int(input())

A = list(map(int, input().split()))


ans = int(1e9)
for i in range(N):
    cnt = 0
    while(A[i]%2 == 0):
        A[i] = A[i] // 2
        cnt = cnt + 1
        
    ans = min(ans,cnt)

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {
    ll N, ans=0, tmp;
    cin >> N;
    vector<ll> a(N), add(2e7, 0), sub(2e7, 0);
    for(ll i=0; i<N; i++){
	cin >> a[i];
	tmp = (i+1) + a[i];
	if(tmp<2e7)
	    add[tmp]++;
	tmp = (i+1) -a[i];
	if (tmp>=0 && tmp<2e7)
	    sub[tmp]++;
    }

    for(ll i=0; i<2e7; i++){
	ans += add[i] * sub[i];
    }

    cout << ans << endl;
} 




Measured memory_bytes: 317420