akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, d: "List[int]"):
    d.sort()
    s = d[N//2-1]
    e = d[N//2]
    print(e-s)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    d = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, d)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14452
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];

    ll sum = accumulate(all(a), 0LL);
    if (N % 2) {
        write(sum % 2 ? "First" : "Second");
    }
    else {
        int minimum = *min_element(all(a));
        if (minimum % 2) {
            write("First");
        }
        else {
            write(sum % 2 ? "First" : "Second");
        }
    }
}


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

public class Main{
    static public void main(String[] args) throws Exception{
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String[] buf = reader.readLine().split(" ")
        Main main = new Main();
        main.solve();
    }
    void solve(){
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        char c = s[0];
        char a = (char)(c+1);
        System.out.println(a);
    }
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pl;
typedef pair<ll,pl> tl;
const int MN = 200200;
//Range Updates
//Maximum queries
class ST {
	private:
		int n,h;
		vl st,lz;
		const ll STV = -1LL<<62;
		//minimum start
		//const ll STV = 1LL<<62;
		int log2(int v) {
			if(v <= 1) return 1;
			return log2(v/2)+1;
		}
		void ap(int p, ll val) {
			st[p] += val;
			if(p < n) {lz[p] += val;}
		}
		void build(int p) {
			while(p > 1) {
				p >>= 1;
				if(p >= n) continue;
				st[p] = max(st[p<<1],st[p<<1|1])+lz[p];
			}
		}
		void psh(int p) {
			for(int s=h;s>0;s--) {
				int i = p>>s;
				if(lz[i] != 0) {
					ap(i<<1,lz[i]);
					ap(i<<1|1,lz[i]);
					lz[i] = 0;
				}
			}
		}
	public:
		ST(int _n) {
			n = _n;
			h = log2(n);
			st.assign(2*n,0);
			lz.assign(n,0);
		}
		void up(int l, int r, ll val) {
			if(l >= r) return;
			l += n;r += n;
			int li = l,ri = r;
			for(;l<r;l>>=1,r>>=1) {
				if(l&1) {ap(l++,val);
				}
				if(r&1) {ap(--r,val);
				}
			}
			build(li);build(ri-1);
		}
		ll qu(int l, int r) {
			l += n;r += n;
			psh(l);psh(r-1);
			ll res = STV;
			for(;l<r;l>>=1,r>>=1) {
				if(l&1) {res = max(res,st[l++]);}
				if(r&1) {res = max(res,st[--r]);}
			}
			return res;
		}
};
pl ro[MN];
ll lo[MN];
ll va[MN];

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n,m;
	cin >> n >> m;
	ST st(n+2);
	for(int i=0;i<m;i++) {
		ll l,r,v;
		cin >> l >> r >> v;
		va[i] = v;
		lo[i] = l;
		ro[i] = {r,i};
	}
	sort(ro,ro+m);
	int id = 0;
	for(int i=1;i<=n+1;i++) {
		while(id < m && ro[id].first < i) {
			int idx = ro[id].second;
			int lf = lo[idx];
			int rt = ro[id].first;
			st.up(lf,rt+1,va[idx]);
			id++;
		}
		ll nx = st.qu(0,i);
		st.up(i,i+1,nx);
	}
	ll res = st.qu(0,n+2);
	cout << res << '\n';
}


Measured memory_bytes: 11264
#include<stdio.h>
int main(void)
{
	int h,w;
	char str[101];
	scanf("%d %d",&h,&w);
	for(int i=0;i<h;i++){
		scanf("%s",str);
		printf("%s\n%s\n",str,str);
	}
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
/*{{{*/
#include <bits/stdc++.h>
#ifdef LOCAL
int c_ = 0;
#define cout (c_?cerr:cout)
#define debug(...) \
{if(!c_++)cerr<<"\033[96;1m"; \
__VA_ARGS__; \
if(!--c_)cerr<<"\033[0m";}
#else
#define debug(...) {}
#endif
#define assrt(...) debug(\
if (not (__VA_ARGS__)) \
    exit((cerr << __LINE__ << ": " << #__VA_ARGS__ << '\n', 0));\
)
#define st first
#define nd second
#define all(...) (__VA_ARGS__).begin(), (__VA_ARGS__).end()
using namespace std; using ll = long long;
template < typename t > using V = vector< t >;
template < typename t, size_t s > using A = array< t, s >;
void print() {cout << '\n';}
template< typename t, typename... v >
void print(const t& a, const v&... b)
{cout << a << (sizeof...(b)?" ":""); print(b...);}
template< typename t > void print_range(t a, const t& b)
{ while (a != b) cout << (*a++) << ' '; cout << '\n';}
#define dump(...) debug(print(#__VA_ARGS__,'=',__VA_ARGS__))
#define dump_range(...) debug(cerr<<#__VA_ARGS__ << ": "; print_range(__VA_ARGS__))
/*}}}*/

constexpr int nax = 3e5;

int n;
vector< int > gr[nax + 1];

pair< int, int > dfs(const int v, const int oj)
{
    pair< int, int > res = {0, v};
    for (int s : gr[v])
        if (s != oj)
        {
            auto q = dfs(s, v);
            ++q.st;
            res = max(res, q);
        }
    return res;
}

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

    cin >> n;

    for (int i = 0; i < n - 1; ++i)
    {
        int p, q; cin >> p >> q;
        gr[p].push_back(q);
        gr[q].push_back(p);
    }

    auto p = dfs(1, 1);
    p = dfs(p.nd, p.nd);

    cout << ((p.st % 3 == 1)? "Second" : "First") << '\n';
}

Measured memory_bytes: 22528
#include<bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < (n); i++)
#define mp make_pair
#define puts(x) cout << x << endl
using namespace std;
int h, w, n;
pair<int, int>p[234567];
int k[234567], d = 1, ans;
int main() {
	cin >> h >> w >> n;
	for0(i, n)cin >> p[i].second >> p[i].first;
	sort(p, p + n);
	k[1] = 1; ans = h;
	for0(i, n) {
		int x = p[i].second, y = p[i].first;
		while (d < y) k[d + 1] = k[d++] + 1;
		if (k[y] == x)k[y]++;
		else if (k[y] < x)ans = min(ans, x - 1);
	}
	puts(ans);
}

Measured memory_bytes: 2560
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

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

signed main() {
    int n, q;
    string s;
    cin >> n >> s >> q;

    set<int> pos[26];
    rep(i, s.size()) {
        pos[s[i] - 'a'].insert(i + 1);
    }

    rep(i, q) {
        int t;
        cin >> t;

        if (t == 1) {
            int in; char c;
            cin >> in >> c;
            pos[s[in - 1] - 'a'].erase(in);
            pos[c - 'a'].insert(in);
            s[in - 1] = c;
        } else {
            int l, r;
            cin >> l >> r;
            int ans = 0;
            rep(j, 26) {
                if (auto it = pos[j].lower_bound(l); it != pos[j].end() && *it <= r) ++ans;
            }

            cout << ans << endl;
        }
    } 

    return 0;
}

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

int main()
{
  int L,R;
  cin>>L>>R;

  int imax;
  if(R-L>2019){
    imax = 2019+L;
  }else{
    imax = R;
  }

  int ans = 2019;
  for(long long i=L;i<imax;i++){
    for(long long j=i+1;j<=imax;j++){
      if((i*j)%2019 < ans){
        ans = (i*j)%2019;
      }
      if(ans == 0){
        break;
      }
    }
  }

  cout<<ans<<endl;
}


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

using namespace std;
int a[55];

int main() {
  int n; cin >> n;
  priority_queue<double, vector<double>, greater<double>> pq;
  for(int i=1; i<=n; ++i) {
    int x; cin >> x;
    pq.push(x);
  }
  while(pq.size() > 1) {
     double o = pq.top();
     pq.pop();
     double p = pq.top();
     pq.pop();
     pq.push((p+o)/2.0);
  }
  cout << pq.top() << "\n";
  //cout << 1/sm << "\n";
  return 0;
}


Measured memory_bytes: 256
s, t = input(), input()

d = {}
d2 = {}
for i, j in zip(s, t):
    if i in d:
        if d[i] != j:
            print("No")
            exit()

    else:
        d[i] = j

    if j in d2:
        if d2[j] != i:
            print("No")
            exit()

    else:
        d2[j] = i

print("Yes")

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

template<typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}

const int maxn = 1e5 + 11;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  
  int n; cin >> n;
  cout << n*n << endl;


  return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : b.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
int main() {
	int n;cin>>n;
	vector<ll> x(n),y(n);
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
	}
	map<ll,map<ll,ll>> m;
	ll ans=n;
	ll dif=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i!=j){
				ll dx=x[i]-x[j];
				ll dy=y[i]-y[j];
				m[dx][dy]++;
				if(dif<m[dx][dy]){
					dif=m[dx][dy];
				}
			}
		}
	}
	cout<<ans-dif<<endl;
	return 0;
}

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

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

    long long n, p;
    cin >> n >> p;
    
    map<long long, long long> mp;

    // 素因数分解
    long long tmp = p;
    for(long long i = 2; i * i <= p; i++){
        if(tmp == 1) break;
        while(tmp % i == 0){
            mp[i]++;
            tmp /= i;
        }
    }

    mp[tmp]++;

    long long ans = 1;
    for(auto x : mp){
        for(int i = 0; i < x.second / n; i++){
            ans *= x.first;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
      
        int k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
       
      
      int largest = (b / k) * k;
		
		if (a <= largest) {
			System.out.println("OK");
		} else {
			System.out.println("NG");
		}     
    }
}

Measured memory_bytes: 35588
s=input()
lens=len(s)


def combi(x):
    return (x*(x-1))//2

L=[0]
for i in range(lens):
    L.append((L[-1]+int(s[lens-1-i])*pow(10,i,2019))%2019)

D={i:0 for i in range(2019)}
for ele in L:
    D[ele]+=1

ans=0
for key in D:
    if D[key]>1:
        ans+=combi(D[key])
    
print(ans)

Measured memory_bytes: 16288
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(n)]
ans = 0
for j in range(n):
    check = c
    for i in range(m):
        check += b[i] * a[j][i]
    if check > 0:ans += 1
print(ans)

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

using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  long mover = count(s.begin(), s.end(), 'E');
  long min_mover = mover;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'W') {
      ++mover;
    } else if (s[i] == 'E') {
      --mover;
    }
    min_mover = min(min_mover, mover);
  }
  cout << min_mover << endl;
}


Measured memory_bytes: 888
#include<stdio.h>
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
int a[105];
int sum1[105];
int sum2[105];
int sum[105];
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    memset(sum1,0,sizeof(sum1));
    memset(sum2,0,sizeof(sum2));
    memset(sum,0,sizeof(sum));
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
    }
    for(int t=1; t<=n; t++)
    {
        for(int i=1; i<=n; i++)
        {
            if(i<=t)
                sum1[t]+=a[i];
            else
                sum2[t]+=a[i];
        }
        sum[t]=abs(sum1[t]-sum2[t]);
    }
    sort(sum+1,sum+n+1);
    printf("%d\n",sum[1]);

    return 0;
}

Measured memory_bytes: 256
import sys

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

s = LS2()
t = LS2()

from collections import defaultdict

dict_s = defaultdict(list)

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

d = {}
for a in dict_s.keys():
    d[a] = 0

r = 0
u = -1
for a in t:
    if len(dict_s[a]) == 0:
        print(-1)
        exit()
    else:
        left = -1
        right = len(dict_s[a])
        while left + 1 < right:
            mid = (left + right)//2
            if dict_s[a][mid] > u:
                right = mid
            else:
                left = mid
        if right == len(dict_s[a]):
            r += 1
            u = dict_s[a][0]
        else:
            u = dict_s[a][right]

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




Measured memory_bytes: 88048
import scala.io.StdIn
import scala.annotation.tailrec

object Main extends App {
  val n = StdIn.readInt
  val a = StdIn.readLine.split(" ").map(_.toLong)

  // 1項目が 0 の時は 1 か -1 に変える
  val init1 = if(a.head <= 0) 1 - a.head else 0
  val ans1 = a.tail./:(a.head + init1, init1.abs)((acc,i) => {
    val (bsum, bcnt) = acc
    val sum = bsum + i
    val cnt = if(bsum < 0 && sum < 0) 1 - sum
    else if(bsum > 0 && sum > 0) -1 - sum
    else if(sum == 0) if(bsum < 0) 1 else -1
    else 0
    (sum+cnt, bcnt+cnt.abs)
  })._2

  val init2 = if(a.head < 0) 0 else -1 - a.head
  val ans2 = a.tail./:(a.head + init2, init2.abs)((acc,i) => {
    val (bsum, bcnt) = acc
    val sum = bsum + i
    val cnt = if(bsum < 0 && sum < 0) 1 - sum
    else if(bsum > 0 && sum > 0) -1 - sum
    else if(sum == 0) if(bsum < 0) 1 else -1
    else 0
    (sum+cnt, bcnt+cnt.abs)
  })._2

  println(math.min(ans1, ans2))
}

Measured memory_bytes: 51024
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<pair<string, int>, int> P;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<P> V(N);
    rep(i,0,N){
        string s;
        int num;
        cin >> s >> num;
        V[i] = make_pair(make_pair(s,-num), i);
    }
    sort(V.begin(), V.end());
    rep(i,0,N){
        cout << V[i].second + 1 << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
P = list(map(int, input(). split()))
Q = sorted(P)
cnt = 0
i = 0

while cnt <= 2 and i < len(P):
  if Q[i] != P[i]:
    cnt += 1
  i += 1

if cnt <= 2:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>
#include<math.h>


using namespace std;

void koch(double x1, double y1, double x2, double y2, int n){
  double th = M_PI * 60 / 180;

  if(n == 0) {
    printf("%.8f %.8f\n", x2, y2);
  } else {
    double s_x = (2*x1 + x2) / 3;
    double s_y = (2*y1 + y2) / 3;
    double t_x = (x1 + 2*x2) / 3;
    double t_y = (y1 + 2*y2) / 3;
    double u_x = (t_x - s_x) * cos(th) - (t_y - s_y) * sin(th) + s_x;
    double u_y = (t_x - s_x) * sin(th) + (t_y - s_y) * cos(th) + s_y;
 
    koch(x1, y1, s_x, s_y, n-1);
    koch(s_x, s_y, u_x, u_y, n-1);
    koch(u_x, u_y, t_x, t_y, n-1);
    koch(t_x, t_y, x2, y2, n-1);
  }
}

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

  printf("%.8f %.8f\n", 0.0, 0.0);
  koch(0.0, 0.0, 100.0, 0.0, n);
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
const ll inf = 1e16;
const ll md = 1000000007;
int m, n;

int main() {
  vi a;
  int k;
  rep(_,5){
    int x;
    cin>>x;
    a.push_back(x);
  }
  cin>>k;
  if(a[4]-a[0]>k) puts(":(");
  else puts("Yay!");
  return 0;
}


Measured memory_bytes: 256
n, a, b = map(int, input().split())
mod = 10**9+7

ans = pow(2, n, mod)-1

def choose(n, r):
    res = 1
    fac = 1
    for i in range(r):
        res *= n-i
        res %= mod
        fac *= i+1
        fac %= mod
    return res*pow(fac, mod-2, mod)%mod

ans -= choose(n, a)
ans -= choose(n, b)

print(ans%mod)

Measured memory_bytes: 3064
#include<iostream>
#include<map>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdlib>
#include<math.h>
#include<set>
#include<array>
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 rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef pair<int, int> pii;

typedef long long ll;
typedef pair<ll, ll>pll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
const int MOD = 1000000007;
const int INF = 1 << 29;
const long long LINF = 1LL << 60;



int main() {

	int n;
	cin >> n;
	int sho = n / 100;
	int ama = n % 100;
	int cnt = 0;
	while (5 <= ama) {
		cnt++;
		ama -= 5;
	}
	if (ama > 0)cnt++;

	if(cnt<=sho)cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}


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

int main() {
  int n; scanf("%d", &n);
  bool flag = false;
  for (int i = 0; i <= 25; i++) {
    if (n < i * 4) break;
    if ((n - i * 4) % 7 == 0) {
      flag = true;
      break;
    }
  }
  if (flag) puts("Yes");
  else puts("No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define N             (int)(1e6+5)
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;
int prime[1005]; vi v;
void seive(){
    for(int i=1;i<=n;i++){
        prime[i]=1;
    }
    prime[1]=0;
    for(int i=2;i<=n;i++){
        if(prime[i]){
            v.pb(i);
            for(int j=i*i;j<=n;j+=i){
                prime[j]=0;
            }
        }
    }
}
int solve(){
    cin>>n;
    seive();
    ans=1;
    rep(i,0,sz(v)-1){
        int t=n,x=v[i],s=0;
        while(t){
            t/=v[i];
            s=(s+t)%M;
        }
        ans=(ans*(s+1))%M;
    }
    cout<<ans;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

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

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;

    int cnt = 0;
    for (int i = a; i <= b; i++) {
        string s;
        for (int t = i; t; s += t % 10 - '0', t /= 10);
        reverse(s.begin(), s.end());
        bool f = true;
        for (int j = 0; j < s.size() / 2; j++) {
            if (s[j] != s[s.size() - j - 1]) f = false;
        }
        if (f) cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;


int main(){
    string s;
    cin >>s;
    int a,z;
    a=0;
    while(1){
        if(s[a] =='A') break;
        a+=1;
    }
    z=s.length()-1;
    while(1){
        if(s[z]=='Z') break;
        z-=1;
    }

    cout << z - a +1 << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(j, m) for (int j = 0; i < (int)(n); j++)
using ll = long long;
using namespace std;

int main() {
  int a;
  ll s;
  cin >>a;
  s =a*a;
  cout <<s<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int64_t n, m; cin >> n >> m;
    
    vector<vector<int>> edge(n, vector<int>());
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b; a--; b--;
        edge.at(a).push_back(b);
        edge.at(b).push_back(a);
    }
    
    vector<int> color(n, -1);
    color.at(0) = 0;
    
    queue<int> q;
    q.push(0);
    
    bool is_bipartite = true;
    while (!q.empty() && is_bipartite) {
        int v = q.front();
        q.pop();
        
        int c = color.at(v);
        for (int i : edge.at(v)) {
            if (color.at(i) == c) {
                is_bipartite = false;
                break;
            } else if (color.at(i) == 1 - c) continue;
            else {
                color.at(i) = 1 - c;
                q.push(i);
            }
        }
    }
    
    if (is_bipartite) {
        int64_t a = 0;
        for (int i = 0; i < n; i++) a += color.at(i);
        cout << n * (n - 1) / 2 - a * (a - 1) / 2 - (n - a) * (n - a - 1) / 2 - m << endl;
    } else {
        cout << n * (n - 1) / 2 - m << endl;
    }
    
    return 0;
}


Measured memory_bytes: 6272
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        int[] h = new int[n];
        int offset = 1000000000;
        for(int i=0; i<n; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            h[i] = sc.nextInt();
            offset = Math.min(offset, h[i]);
        }
        for(int i=0; i<n; i++) {
            h[i] -= offset;
        }
        for(int cx = 0; cx <= 100; cx++) {
            for(int cy = 0; cy <= 100; cy++) {
                A: for(int ch = 0; ch <= 200; ch++) {
                    for(int i=0; i<n; i++) {
                        int hh = ch - Math.abs(cx - x[i]) - Math.abs(cy - y[i]);
                        hh = Math.max(hh, -offset);
                        if(hh != h[i]) continue A;
                    }
                    System.out.println(String.format("%d %d %d", cx, cy, ch + offset));
                    return;
                }
            }
        }

    }

}


Measured memory_bytes: 23116
import fractions as fr

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

a, b, k = map(int, input().split())
c = fr.gcd(a, b)
d = make_divisors(c)
print(d[-k])


Measured memory_bytes: 5048
//#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

//ifstream cin("x.in"); ofstream cout("x.out");

string s;

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

    cin >> s;

    int i = 0, j = (int)s.size() - 1;

    int ans = 0;
    bool ok = 1;

    while (i < j) {
        if (s[ i ] == s[ j ]) {
            ++ i, -- j;
        } else if (s[ i ] == 'x') {
            ++ i;
            ++ ans;
        } else if (s[ j ] == 'x') {
            -- j;
            ++ ans;
        } else {
            ok = 0;
            break;
        }
    }

    if (ok == 0)
        ans = -1;
    cout << ans;
    return 0;
}


Measured memory_bytes: 512
n = int(input())
s = input()
R = s.count('R')
G = s.count('G')
B = s.count('B')
ans = 0
if n <= 2:
    print(0)
    exit()
for i in range(1,(len(s)-1)//2+1):
    for j in range(n-2*i):
        if s[j] != s[j+i] and s[j+i] != s[j+2*i] and s[j+2*i] != s[j]:
            ans -=1
print(R*G*B + ans)

Measured memory_bytes: 68120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define TEST cout << "PASS" << endl
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 1e6 + 1e3 + 1;
const ll INFL = 1e15 + 1e12 + 1e9 + 1e6 + 1e3 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main(){
    int n;
    ll a, b;
    ll h[100000];
    cin >> n >> a >> b;
    rep(i, n) cin >> h[i];
    int lb = 0, ub = INF;    //(lb, ub]
    ll mid;
    while(ub - lb > 1){
        mid = (lb + ub) / 2;
        ll cnt = 0;
        rep(i, n){
            if(h[i]/ b <mid) continue;
            cnt += (h[i] - b * mid + a - b - 1) / (a - b);
            if(cnt > mid) break;
        }
        //printf("lower_bound : %d, upper_bound : %d\n", lb, ub);
        if(cnt > mid) lb = mid;
        else ub = mid;
    }
    cout << ub << endl;
}

Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
 
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; }



int main(){

	lli n,d;
	cin>>n>>d;

	d = 2*d+1;

	cout<<(n-1)/d + 1<<endl;


    return 0;
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int l,r;
  l=r=0;
  string ans="";
  for(int i=0;i<n;i++){
    if(s[i]=='(') l++;
    else r++;
    ans.push_back(s[i]);
    if(r>l){
      ans.insert(ans.begin(),'(');
      l++;
    }
  }
  for(int i=0;i<l-r;i++){
    ans.push_back(')');
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
	int a,b,c,i;
	while(scanf("%d %d",&a,&b)!=EOF){
	i=1;
	c=a+b;
	while(c=c/10){
		i++;
	}
		
	printf("%d\n",i);
	}
	return 0;
}

Measured memory_bytes: 1028
package main

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

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = nextInt()
	}
	return ints
}

const (
	yes = "YES"
	no  = "NO"
)

func canSortAsc(in []int) string {
	forSort := append([]int{}, in...)
	sort.Ints(forSort)

	unmatchCount := 0
	for i := 0; i < len(in); i++ {
		if in[i] != forSort[i] {
			unmatchCount++
		}
		if unmatchCount > 2 {
			return no
		}
	}
	return yes
}
func main() {
	n := nextInt()
	ints := nextInts(n)
	r := canSortAsc(ints)
	fmt.Println(r)
}


Measured memory_bytes: 640
//In the name of GOD
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll maxn = 5e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define pb push_back
#define Mp make_pair
#define pll pair<ll, ll>
#define F first
#define S second

ll n, k, a[2][maxn], t;

int main(){
	fast_io;
	
	cin >> n >> k;
	for(ll i = 0; i < n; i++){
		cin >> a[0][i];
	}
	for(ll j = 0; j < k; j++){
		bool f = 1;
		for(ll i = 0; i < n; i++){
			if(a[j & 1][i] != n) f = 0;
			a[j + 1 & 1][i] = 0;
		}
		if(f){
			for(ll i = 0; i < n; i++){
				cout << n << " ";
			}
			return 0;
		}
		for(ll i = 0; i < n; i++){
			a[j + 1 & 1][max(0ll, i - a[j & 1][i])]++;
			a[j + 1 & 1][min(n, i + a[j & 1][i] + 1)]--;
		}
		for(ll i = 1; i < n; i++){
			a[j + 1 & 1][i] += a[j + 1 & 1][i - 1];
		}
	}
	for(ll i = 0; i < n; i++){
		cout << a[k & 1][i] << " ";
	}
	
	return 0;
}

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

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int n,m,l;
    cin >>n>>m>>l;
    int A[n][m];
    int B[m][l];
    long long C[n][l];
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++)cin >> A[i][j];
    }
    for (int i = 0; i < m; i++){
        for (int j = 0; j < l; j++)cin >> B[i][j];
    }
    for (int j = 0; j < n; j++){
        for (int k = 0; k < l; k++)C[j][k]=0;
    }
    for (int i = 0; i < m; i++){
        for (int j = 0; j < n; j++){
            for (int k = 0; k < l; k++){
                C[j][k]+=A[j][i]*B[i][k];
            }
        }
    }
    for (int j = 0; j < n; j++){
        for (int k = 0; k < l; k++){
            cout<<C[j][k];
            if(k!=l-1)cout<<' ';
        }
        cout<<'\n';
    }
}


Measured memory_bytes: 3260
import java.awt.*;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
        int k=sc.nextInt(),n=sc.nextInt();
        int a[]=new int[n];
        for (int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        int min=-1;
        for (int i=0;i<n;i++){
           if (i==0){
               min=Math.min(k-(a[i+1]-a[i]),a[n-1]);
               continue;
           }
           if (i==n-1){
               min=Math.min(min,Math.min(a[n-1]-a[0],k-(a[i]-a[i-1])));
               continue;
           }
           min=Math.min(min,Math.min(k-(a[i]-a[i-1]),k-(a[i+1]-a[i])));
        }
        System.out.println(min);


    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 47216
#include<stdio.h>
#define H 500000

int parent(int i){
  return i/2;
}
int left(int i){
  return i*2;
}
int right(int i){
  return 2*i+1;
}

void maxHeapify(int);

int A[H];
int n;
int main(){

  int i,x;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  for(i=n/2;i>=1;i--){
    maxHeapify(i);
  }
 
  for(i=1;i<=n;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
  
}



void maxHeapify(int i){
  int l,r,largest,tmp;

  l=left(i);
  r=right(i);

   if(l<=n && A[l]>A[i]){
    largest=l;
  }
  else {
    largest=i;
  }
  if(r<=n && A[r]>A[largest]){
    largest=r;
  }
 
  if(largest!=i){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(largest);
  }
}

Measured memory_bytes: 2552
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
using namespace std;
 
int main() {
  int N, L;
  cin >> N >> L;
  
  int temp=abs(L);
  int min=L;
  for(int i=1;i<=N;i++){
    if(abs(L+i-1)<temp){
      temp = abs(L+i-1);
      min = L+i-1;
    }
  }

  cout << (N-1+2*L)*N/2 - min << endl;
}

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

using namespace std;
int main(){
	long long K,A,B;
	cin>>K>>A>>B;
	if(A-1>=K||(B-A)<=2){
		cout<<K+1;
		return 0;
	}
	else{
		long long ans=A+(K-A+1)/2*(B-A)+(K-A+1)%2;
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    println(problem057a(a, b))
}

fun problem057a(a: Int, b: Int): Int {
    val ans = a + b
    return if (ans < 24) ans else ans - 24
}

Measured memory_bytes: 29484
# by the authority of GOD     author: manhar singh sachdev #

import os,sys
from io import BytesIO, IOBase

def main():
    s = int(input())
    mod = 10**9+7
    dp = [1]+[0]*s
    for i in range(1,s+1):
        for j in range(i-2):
            dp[i] += dp[j]
            dp[i] %= mod
    print(dp[-1])

#Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == '__main__':
    main()

Measured memory_bytes: 65404
var
  a, h, f, w, id, hs, sum: array [0..200000] of longint;
  u, v: array [0..400000] of longint;
  s, t: array [1..800000] of longint;
  n, q, i, x, y, num: longint;
procedure swap(var x, y: longint); inline;
var
  t: longint;
begin
  t := x;
  x := y;
  y := t;
end;
procedure add(x, y: longint); inline;
begin
  inc(num);
  u[num] := h[x];
  v[num] := y;
  h[x] := num;
end;
procedure pushup(x: longint); inline;
begin
  s[x] := s[x shl 1] + s[x shl 1 or 1];
end;
procedure pushdown(x, l, r: longint); inline;
var
  m: longint;
begin
  m := (l + r) shr 1;
  inc(s[x shl 1], t[x] * (m - l + 1));
  inc(s[x shl 1 or 1], t[x] * (r - m));
  inc(t[x shl 1], t[x]);
  inc(t[x shl 1 or 1], t[x]);
  t[x] := 0;
end;
procedure build(x, l, r: longint);
var
  m: longint;
begin
  if l = r then
  begin
    s[x] := w[l];
    exit;
  end;
  m := (l + r) shr 1;
  build(x shl 1, l, m);
  build(x shl 1 or 1, m + 1, r);
  pushup(x);
end;
procedure update(x, l, r, tl, tr, k: longint);
var
  m: longint;
begin
  if (l >= tl) and (r <= tr) then
  begin
    inc(s[x], k * (r - l + 1));
    inc(t[x], k);
    exit;
  end;
  pushdown(x, l, r);
  m := (l + r) shr 1;
  if tl <= m then
    update(x shl 1, l, m, tl, tr, k);
  if tr > m then
    update(x shl 1 or 1, m + 1, r, tl, tr, k);
  pushup(x);
end;
function query(x, l, r, t: longint): longint;
var
  m: longint;
begin
  if l = r then  
    exit(s[x]);
  pushdown(x, l, r);
  m := (l + r) shr 1;
  if t <= m then
    exit(query(x shl 1, l, m, t))
  else
    exit(query(x shl 1 or 1, m + 1, r, t));
end;
procedure dfs1(x, y, z: longint);
var
  i, max: longint;
begin
  f[x] := y;
  sum[x] := 1;
  hs[x] := 0;
  max := 0;
  i := h[x];
  while i > 0 do
  begin
    if v[i] <> y then
    begin
      dfs1(v[i], x, z + 1);
      if sum[v[i]] > max then
      begin
        max := sum[v[i]];
        hs[x] := v[i];
      end;
      inc(sum[x], sum[v[i]]);
    end;
    i := u[i];
  end;
end;
procedure dfs2(x, y: longint);
var
  i: longint;
begin
  inc(num);
  id[x] := num;
  w[id[x]] := a[x];
  if hs[x] = 0 then
    exit;
  dfs2(hs[x], y);
  i := h[x];
  while i > 0 do
  begin
    if (v[i] <> f[x]) and (v[i] <> hs[x]) then
      dfs2(v[i], v[i]);
    i := u[i];
  end;
end;
procedure updatesubtree(x, k: longint); inline;
begin
  update(1, 1, n, id[x], id[x] + sum[x] - 1, k);
end;
begin
  read(n, q);
  num := 0;
  for i := 1 to n - 1 do
  begin
    read(x, y);
    add(x, y);
    add(y, x);
  end;
  num := 0;
  dfs1(1, 0, 0);
  dfs2(1, 1);
  build(1, 1, n);
  for i := 1 to q do
  begin
    read(x, y);
    updatesubtree(x, y);
  end;
  for i := 1 to n do
    write(query(1, 1, n, id[i]), ' ');
end.


Measured memory_bytes: 24960
#include<bits/stdc++.h>
using namespace std;
int main(){
   long long n;
    long long k;
    vector<pair<int,int> >a;
    cin>>n>>k;
    
    for(int i=1;i<=n;i++ ){
        pair<int,int>x;
        cin>>x.first>>x.second;
        a.push_back(x);
    }
    sort(a.begin(),a.end());
    long long count=0;
    for(int i=0;i<a.size();i++){
        count+=a[i].second;
        if(count>=k){
            cout<<a[i].first<<endl;
            return 0;
        }
    }
    //cout<<a[n-1].first<<endl;
}

Measured memory_bytes: 1400
program ccc

integer :: n, i
integer,allocatable,dimension(:) :: a, b, c
integer,allocatable,dimension(:,:) :: dp

read*, n
allocate(a(n))
allocate(b(n))
allocate(c(n))
allocate(dp(3,n))
do i=1,n
read*, a(i),b(i),c(i)
end do
dp=-1
dp(1,1)=a(1)
dp(2,1)=b(1)
dp(3,1)=c(1)

do i=2, n
dp(1,i)=max(a(i)+dp(2,i-1),a(i)+dp(3,i-1))
dp(2,i)=max(b(i)+dp(3,i-1),b(i)+dp(1,i-1))
dp(3,i)=max(c(i)+dp(1,i-1),c(i)+dp(2,i-1))
end do

write(*,'(i0)') max(dp(1,n),dp(2,n),dp(3,n))

end program

Measured memory_bytes: 2560
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
const ll mod = 1e9 + 7 ;
const ll inf =
 1e9 + 5 ;
 //1e18L + 5;
const ll nax = 2e5 + 5;
void min_self(ll&a , ll b){a=min(a,b);}
void max_self(ll&a , ll b){a=max(a,b);}
void add_self(ll&a , ll b){a=(a+b)%mod;}
//#define (x)  get<0>(x) 
//#define (x)  get<1>(x)
//#define (x)  get<2>(x)
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

ll n , d, a;  
cin >> n>> d >> a; 
vector<pair<ll,ll>> v(n) ;
for(ll i = 0 ; i<n ; i++){
	ll k , l ; 
	cin >> k >> l ; 
	l = (a - 1 + l)/a ;
	v[i] = {k , l };
}
sort(all(v)) ;
// for(auto it:v)cout<<it.first << " j " << it.second << endl;
vector<ll> arr(n+1) ; 
ll ans = 0 ;
for(ll i = 0 ; i<n ; i++){
// for(auto it: arr)cout<<it<<" " ;cout << endl;

v[i].second += arr[i]  ;
if(v[i].second <= 0 ){
	arr[i+1] += arr[i] ; 
	continue ;
}
// cout <<i << " " << v[i].second << endl;
ll low = i , high  = n-1 ; 
ll ok  ;
while(low <= high ){
	ll mid = low + (high - low) /2; 
	if(v[mid].first <= v[i].first + 2*d){
		ok = mid; 
		 low = mid + 1 ; 
	}
	else high = mid -1 ; 
}
// cout << "ok "  << i << " " << ok << endl;

arr[i] -= v[i].second ;
// if(i!=0)arr[i] += arr[i-1];
arr[ok+1] += v[i].second ;
arr[i+1] += arr[i];
ans += v[i].second ;

}

cout << ans ; 

	
}

Measured memory_bytes: 4992
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	int r; cin>>r;
	cout<<r*r;

	return 0;
}

Measured memory_bytes: 3572
/*Shivam Bhalla */
/* f2016941@pilani.bits-pilani.ac.in */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iostream>
#include <string>
#include <cmath>
#include <cassert>
#include <bits/stdc++.h>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
long long maxv = 1e9;

bool cmp(pair<long long,long long>a, pair<long long,long long>b){
	if(b.second>a.second)
		return 1;
	else
		return 0;
}

int N,M;
vector< pair<long long,long long> >arr;
int main(){
	cin>>N>>M;
	arr.resize(N);
	for(int i=0;i<N;i++)
		cin>>arr[i].second>>arr[i].first;
	sort(arr.begin(),arr.end(),cmp);
	long long total=0;
	for(int i=0;i<N;i++){
		if(arr[i].first<=M){
			M-=arr[i].first;
			total+=(arr[i].first)*(arr[i].second);
		}
		else{
			total+=(long long)M*(arr[i].second);
			break;
		}
	}
	cout<<total;
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int shu[50][4];
int A[11]={0,1,1,1,1,1,1,1,1,1,1};
bool genA_next(int n,int m)
{
	if (A[1]==A[n]&&A[1]==m) return false;
	
	if(A[n]==m)
	{
		int i=n;
		while(A[i]+1>m)
		{
			if(A[i-1]<m)
			{
				int tmp=A[i-1]+1;
				for(int j=i;j<=n;j++)
					A[j]=tmp;
				break;
			}
			else i--;
		}
		A[i-1]++;
	}
	else
		A[n]++;
		//if(A[n]+1>m){A[n-1]=A[n-2]+1,A[n]=A[n-1]};
	return true;
}
int main()
{
	int n,m,q,maxs=0;
	cin>>n>>m>>q;
	A[0]=m;
	for(int i=0;i<q;i++)
		for(int j=0;j<4;j++)
			cin>>shu[i][j];
	bool con=1;
	
	while(con)
	{
	
		int score=0;
		for(int i=0;i<q;i++)
		{
			if(A[shu[i][1]]-A[shu[i][0]]==shu[i][2])
				score+=shu[i][3];
		}
		maxs=max(maxs,score);
		con= genA_next(n, m);
	}
	cout<<maxs;
	return 0;
}

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

bool simulate(LL n, LL k) {
    while (n >= k) {
        if (n%k == 0)
            n = n/k;
        else
            n = n%k;
    }

    return (n == 1);
}

int main() {
    // for (int n = 2; n <= 50; n++) {
    //     cout << n << ":";
    //     for (int k = 2; k <= n; k++) {
    //         if (simulate(n, k))
    //             cout << " " << k;
    //     }
    //     cout << endl;
    // }

    LL N;
    set<LL> candidate;

    cin >> N;

    if (N == 2) {
        cout << 1 << endl;
        return 0;
    }

    for (LL div = 2; div * div <= N; div++) {
        if (N % div != 0) continue;

        if (simulate(N, div)) candidate.insert(div);
        if (simulate(N, N/div)) candidate.insert(N/div);
    }

    for (LL div = 2; div * div <= N - 1; div++) {
        if ((N - 1) % div != 0) continue;

        if (simulate(N, div)) candidate.insert(div);
        if (simulate(N, (N - 1)/div)) candidate.insert((N - 1)/div);
    }

    candidate.insert(N);
    candidate.insert(N - 1);

    cout << candidate.size() << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define pb push_back
#define F first
#define S second

#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define int long long
#define ll long long
const int M=1e9+7;

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

int expo(int x, int y) {int res=1;x=x%M;while(y>0){if(y&1)res=(1ll*res*x)%M;
	y=y>>1;x=(1ll*x*x)%M;} return res;}
	

signed main(){
	gearup;
	int t = 1;
	//cin >> t;
	while(t--){
		int n, m;
		cin >> n >> m;
		int ans = n * (n - 1) + m * (m - 1);
		ans /= 2;
		cout << ans ;
	}
	return 0;
}

Measured memory_bytes: 256