akhauriyash/Code-Regression huggingface dataset:
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    

#乗法のmod逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

# nCr mod m
# modinvが必要
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


#べき乗
def Raise(x, y):
    # xをy乗する。
    n = 0
    while True:
        if (1<<n) > y:
            break
        n+=1
    D = [0]*(n+1)
    D[0] = x
    index = 0
    for index in range(1,n):
        D[index] = (D[index-1]**2)
    res = 1
    index = 0
    for index in range(0, n):
        if (y>>index)&1 == 1:
            res *= D[index]
    return res


def main():
    #答えは 10^2 - 2*9^2 + 8^2
    n = I()
    mod=10**9+7
    res = pow(10, n, mod)- 2 * pow(9, n, mod) + pow(8, n, mod)
    print(res % (10**9+7))

if __name__ == "__main__":
    main()

Measured memory_bytes: 68056
#include<stdio.h>

int main(){
	
	int N,M,D;
	int i,j,k;
	char F[101][101];
	
	scanf("%d%d%d",&N,&M,&D);
	for(i=0;i<N;i++) scanf("%s",F[i]);
	
	int cnt=0;
	
	for(i=0;i<N;i++){
		for(j=0;j<M-D+1;j++){
			int flg=0;
			for(k=j;k<D+j;k++){
				if(F[i][k]=='#'){
					flg=1;
					break;
				}
			}
			if(flg==0) cnt++;
		}
	}
	
	for(i=0;i<M;i++){
		for(j=0;j<N-D+1;j++){
			int flg=0;
			for(k=j;k<D+j;k++){
				if(F[k][i]=='#'){
					flg=1;
					break;
				}
			}
			if(flg==0) cnt++;
		}
	}
	
	printf("%d\n",cnt);
	
	return 0;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define lp3(i,a,b) for(int i=a;i<b;i++)
#define lp2(i,n) for(int i=0;i<n;i++)
#define ll long long
using namespace std;
int main(){
	int a=0,b=0;
	string r,j="WA";
	cin>>r;
	if(r[0]=='A'){
		lp3(i,1,r.size()){
			if(isupper(r[i])==0)b++;
			if(r[i]=='C'){
				if(i>1&&i<r.size()-1){
					if(a==0){
						j="AC";
						a++;
					}
					else j="WA";
				}
			}
		}
	}
	if(b!=r.size()-2)j="WA";
	cout<<j<<endl;
	return 0;
}


Measured memory_bytes: 256
// Ashish Agarwal @ashuag007
// references: geeksforgeeks

#include<bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
typedef long long ll;

int main(void)
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll t,h,w;
    cin>>t>>h>>w;
    ll cnt=0;
    while(t--)
    {
        ll a,b;
        cin>>a>>b;
        cnt+=min(a/h,b/w);
        //cout<<cnt<<endl;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,a[10000];
	long long sum=0;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
		sum+=a[i];
	}
	sort(a,a+n);
	cout << a[0] << " " << a[n-1] << " " << sum << endl;
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=1000000;
const ll inf=1e18;
const ll mod=1e9+7;

int main()
{
    FasterIO;
    ll n, m, a, b;
    cin>>n>>a>>b;
    ll d=n/(a+b);
    ll r=d*a;
    r+=min(n%(a+b), a);
    cout<<r<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Arrays;

public class Main {

	public static void main(String[] args) {
		int[] v = {1,2,3,4,5,6,7,8,9};
		Arrays.stream(v).forEach(x -> {
			Arrays.stream(v).forEach(y -> {
				System.out.println(x+"x"+y+"="+x*y);
			});
		});
	}

}



Measured memory_bytes: 30700
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#define llint long long

using namespace std;

llint n, Q;
llint a[100005], sum[100005];
llint osum[100005], esum[100005];

bool check(llint mid, llint x)
{
	if(x >= a[n-mid+1]) return false;
	int d = abs(a[n-mid+1] - x);
	int num = lower_bound(a+1, a+n+1, x+d) - lower_bound(a+1, a+n+1, x-d);
	return num >= mid-1;
}

int main(void)
{
	cin >> n >> Q;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) sum[i] = sum[i-1] + a[i];
	for(int i = 1; i <= n; i++){
		osum[i] = osum[i-1];
		esum[i] = esum[i-1];
		if(i%2) osum[i] += a[i];
		else esum[i] += a[i];
	}
	
	for(int q = 0; q < Q; q++){
		llint x;
		cin >> x;
		
		llint ub = n+1, lb = 0, mid;
		while(ub-lb>1){
			mid=(ub+lb)/2;
			if(check(mid, x)) lb = mid;
			else ub = mid;
		}
		
		llint ans = sum[n] - sum[n-lb];
		if(n%2) ans += osum[n-2*lb];
		else ans += esum[n-2*lb];
		cout << ans << endl;
	}
}

Measured memory_bytes: 4864
//Catchharsh
#include<bits/stdc++.h>
#define ll long long int 
#define ld long double
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define F first
#define S second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define see(x) cout<<#x<<" = "<<x<<endl
const ll MOD = 1e9+7;
const ll INF = 1011111111;
const ll LLINF = 1000111000111000111LL;
const ld EPS = 1e-10;
const ld PI = 3.14159265358979323;
using namespace std;
ll power (ll base,ll exponent)
{
    ll ans=1;
    //base%=MOD;
    //exponent%=(MOD-1);
    while(exponent!=0)
    {
      if(exponent&1) ans=(1LL*ans*base);
      base=(1LL*base*base);
      exponent>>=1;
    }
    return ans;
}

int32_t main()
{   
     IOS;
     
     ll n,m,i,j,k;
     cin>>n;
     string s;
     cin>>s;
     ll r[n]={0},g[n]={0},b[n]={0};
     for(i=n-1;i>=0;i--)
     {
       if(i==n-1)
       {
         if(s[i]=='R') r[i]++;
         else if(s[i]=='G') g[i]++;
         else b[i]++;
       }
       else
       {
        r[i]=r[i+1];
        g[i]=g[i+1];
        b[i]=b[i+1];
        if(s[i]=='R') r[i]++;
         else if(s[i]=='G') g[i]++;
         else b[i]++;
       }
     }
     ll sum=0;
     for(i=0;i<n-2;i++)
     {
      for(j=i+1;j<n-1;j++)
      {
        if(s[i]==s[j]) continue;
        else
        {
          k=2*j-i;
          pair<char,char> p={s[i],s[j]};
          pair<char,char> f1={'R','G'},f2=f1,f3={'R','B'},f4=f3;
          swap(f2.F,f2.S);
          swap(f4.F,f4.S);
          if(p==f1||p==f2) {sum+=b[j+1];if(k<n&&s[k]=='B') sum--;}
          else if(p==f3||p==f4){sum+=g[j+1];if(k<n&&s[k]=='G') sum--;}
          else {sum+=r[j+1];if(k<n&&s[k]=='R') sum--;}
        }
      }
     }
     cout<<sum;
     
     cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';             
}

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

#define ll long double
int N;
vector<vector<vector<ll>>> dp(310, vector<vector<ll>>(310, vector<ll>(310, -1)));

ll getTimes(ll a, ll b, ll c) {
	if (a + b + c == 0) {
		return 0.00;
	}
	if (dp[a][b][c] != -1) return dp[a][b][c];
	ll k = a + b + c;
	ll sum = N / k;
	if (a) {
		sum += (a / k) * getTimes(a - 1, b, c);
	}
	if (b) {
		sum += (b / k) * getTimes(a + 1, b - 1, c);
	}
	if (c) {
		sum += (c / k) * getTimes(a, b + 1, c - 1);
	}
	return dp[a][b][c] = sum;
}

int main() {
	cin >> N;
	int x;
	int a = 0, b = 0, c = 0;
	for (int i = 0; i < N; i++) {
		cin >> x;
		if (x == 1) a++;
		if (x == 2) b++;
		if (x == 3) c++;
	}
	ll res = getTimes(a, b, c);
	cout << fixed << setprecision(12) << res << endl;
	return 0;
}

Measured memory_bytes: 474188
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
 
int main() {
	string s; cin >> s;
	string ans;
	for (int i = 0; i < s.size(); i += 2) {
		ans += s[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
fun main(args : Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val ss = IntArray(n) {0}

    repeat(k) {
        val d = readLine()!!.toInt()
        readLine()!!.split(" ").map { it.toInt()-1 }.forEach {
            ss[it]++
        }
    }

    println(ss.count { it == 0 })
}

Measured memory_bytes: 38896
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll h, cnt = 1;
    cin >> h;
    ll ans = 0;
    while (h > 0) {
        ans += cnt;
        cnt += cnt;
        h /= 2;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3584
#include <stdio.h>

int abs(int x)
{
	if (x > 0){
		return (x);
	}
	return (-x);
}

int main()
{
	int N, T, E;
	int x;
	int i, j;
	
	scanf("%d %d %d", &N, &T, &E);
	
	for (i = 0; i < N; i++){
		scanf("%d", &x);
		for (j = 1; x * j - T <= E; j++){
			if (abs(x * j - T) <= E){
				printf("%d\n", i + 1);
				return (0);
			}
		}
	}
	
	printf("-1\n");
	return (0);
}

Measured memory_bytes: 596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		
		int cake4 = n / 4;
		int price = n % 4;
		
		if(price == 0){
			System.out.println("Yes");
			return;
		}
		
		while(cake4 > 0){
			price += 4;
			cake4--;
			if(price % 7 == 0){
				System.out.println("Yes");
				return;
			}
		}
		
		System.out.println("No");
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


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

int main()
{
    int N, K, C;
    cin >> N >> K >> C;
    string S;
    cin >> S;

    vector<int> L(K);
    int idx = 0, c = 0;
    for (int i = 0; i < N; i++)
    {
        if (c > 0)
            c--;
        else
        {
            if (S.at(i) == 'o')
            {
                L.at(idx) = i;
                idx++;
                if (idx >= K)
                {
                    break;
                }
                c = C;
            }
        }
    }

    vector<int> R(K);
    idx = K - 1;
    c = 0;
    for (int i = N - 1; i >= 0; i--)
    {
        if (c > 0)
            c--;
        else
        {
            if (S.at(i) == 'o')
            {
                R.at(idx) = i;
                idx--;
                if (idx < 0)
                {
                    break;
                }
                c = C;
            }
        }
    }

    for (int i = 0; i < K; i++)
    {
        if (L.at(i) == R.at(i))
        {
            cout << L.at(i) + 1 << endl;
        }
    }
}

Measured memory_bytes: 3332
def distance(sX, sY, pX, pY):
	return abs(sX-pX) + abs(sY-pY)

def getIndex(stuX, stuY, points):
	minDist = -1
	index = 0
	for i in range(len(points)):
		pX = points[i][0]
		pY = points[i][1]
		if (minDist == -1 or distance(stuX, stuY, pX, pY) < minDist):
			minDist = distance(stuX, stuY, pX, pY)
			index = i + 1
	return index

[N, M] = input().split()
N = int(N)
M = int(M)
stus = []
points = []
for n in range(N):
	[x,y] = input().split()
	x = int(x)
	y = int(y)
	stus.append([x, y])
for m in range(M):
	[x,y] = input().split()
	x = int(x)
	y = int(y)
	points.append([x,y])
for s in stus:
	print(getIndex(s[0], s[1], points))

Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <vector>
#define pb push_back
#define row(x) (!x || x == r)
#define col(x) (!x || x == c)
int r, c, n, st[100005], tp; 
struct data
{
	int x, y, idx, tp; 
	data(int _x, int _y, int _idx)
	{
		x = _x; 
		y = _y; 
		idx = _idx; 
		if (!x)
			tp = 1; 
		else if (y == c)
			tp = 2; 
		else if (x == r)
			tp = 3; 
		else
			tp = 4; 
	}
	inline bool operator <(const data &a) const
	{
		if (tp != a.tp)
			return tp < a.tp; 
		switch (tp)
		{
		case 1:
			return y < a.y; 
		case 2:
			return x < a.x; 
		case 3:
			return y > a.y; 
		case 4:
			return x > a.x; 
		}
		return false; 
	}
}; 
std::vector<data> vec; 
int main()
{
	// freopen("ARC076-E.in", "r", stdin); 
	scanf("%d%d%d", &r, &c, &n); 
	for (int i = 0; i < n; i++)
	{
		int x1, y1, x2, y2; 
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2); 
		if ((row(x1) || col(y1)) && (row(x2) || col(y2)))
		{
			vec.pb(data(x1, y1, i)); 
			vec.pb(data(x2, y2, i)); 
		}
	}
	std::sort(vec.begin(), vec.end());
	for (data x : vec)
	{
		if (tp && st[tp - 1] == x.idx)
			tp--; 
		else
			st[tp++] = x.idx; 
	}
	puts(tp ? "NO" : "YES"); 
	return 0; 
}


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

using namespace std;

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

int main(void){
  //infinity //様々な流儀
  const long long INF = 1LL << 62; //long long 1を62bit左にシフト
  //dp table
  long long dp[100010]; //10^5などに合わせて
  //initialize
  for(int i=0;i<100010;i++) dp[i] = INF;
  //initial condition
  dp[0] = 0;

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

  for(int i=1;i<N;i++){
    chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
    if(i > 1) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
  }

  cout << dp[N-1] << endl;

  return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <functional>
#include <iostream>
#include <set>
#include<iomanip>
using namespace std;
int comp(const void* a,const void *b){
	if(*((int *)a)>*(int *)b){
		return 1;
	}else if(*((int *)a)==*(int *)b){
		return 0;
	}else{
		return -1;
	}
}
int main() {
	int n;
	cin>>n;
	int *l = new int[n];
	for(int i=0;i<n;i++){
		cin>>l[i];
	}
	qsort(l,n,sizeof(int),comp);
	long sum=0;
	for(int i=0;i<n-1;i++){
		sum+=l[i];
	}
	if(sum>l[n-1]){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
const char nl = '\n';
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  (B) <= (A) && (A) <= (C)
#define AIN(A, B, C) assert(IN(A, B, C))
ll power(ll x, unsigned int y) {ll res = 1;	while (y > 0) { if (y & 1) res = res*x%mod; y = y>>1; x = x*x;} return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ar[200005];

void solve(){
    ll n;
    cin>>n;
    ll k;cin>>k;
    ll l=0,h=0;
    ll sum=0;
    f(i,0,n)cin>>ar[i],h=max(h,ar[i]),sum+=ar[i];
    
    ll m; ll ans=h;
    while(l<h){
       m=(l+h)/2;ll c=0;
             if(m==0)l++,m=1;
      for(int i=0;i<n;i++){
      	 ll p=ar[i]/m;
      	 if(ar[i]%m==0)p--;
      	 c+=p;
      }
             
       
      if(c<=k)h=m,ans=min(ans,m);
      else if(c>k)l=m;
      if(m==(l+h)/2)l++;
    }
    
    cout<<ans;
    
}
int main() {
    ios;
	int t=1;
	//cin>>t;
	while(t--)solve();
 
    
}


Measured memory_bytes: 5192
#include<cstdio>
int main(){
    int n;
    char s[101];
    scanf("%d%s",&n,s);
    int i=0,k=0,min=0;
    while(s[i]!='\0'){
        if(s[i]=='(')k++;
        else{
            k--;
            if(min>k)min=k;
        }
        i++;
    }
    for(int j=min;j<0;j++)printf("(");
    printf("%s",s);
    for(int j=min;j<k;j++)printf(")");
    return 0;
}

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

using namespace std;
bool is_pal(string s) {
  int sz = s.size();
  for (int i = 0; i < sz / 2; ++i) {
    if (s[i] != s[sz - i - 1])
      return false;
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  int sz = s.size();
  string s1 = s.substr(0, (sz - 1) / 2);
  string s2 = s.substr((sz + 1)/ 2, sz);
  //cout << s1 << " --- " << s2 << '\n';
  if (is_pal(s) && is_pal(s1) && is_pal(s2)) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 256
/*
 * author :Sadik Hassan
 *  
 * created : 21.01.2020 17:28:06
 * 
 * 
 * 
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)      for(int i=0;i<n;i++)
#define repn(i,n)     for(int i=1;i<=n;i++)
#define rrep(i,n)     for(int i=n-1;i>=0;i--)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
const int N = 1e9+10;

int main()
{
    _SAD()
    string s;
    cin>>s;
    for(int i=0;i<SZ(s);i++)
    {
		if(s[i]=='C')
		{
			for(int j=i+1;j<SZ(s);j++)
			{
				if(s[j]=='F')
				{
					cout<<"Yes"<<nl;
					return 0;
				}
			}
		}
	}
	cout<<"No"<<nl;
    return 0;
}


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

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;++i){
        cin >> a[i];
    }

    ll ans = 1LL;
    int j = 0;
    for(int i=0;i<n;++i) {
        while(j < n-1 && a[j] >= 2*(j-i)+1) ++j;
        ans *= ll(j-i+1);
        ans %= MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
from sys import stdin, setrecursionlimit
setrecursionlimit(10000000)

input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()


a, b = mi()
for i in range(max(b-a+1, -1000000), min(b+a, 1000000)):
    print(i, end=" ")

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys



def solve(N: int):
    from itertools import product, count, takewhile
    ans = 0
    for i in range(10):
        for s in product('357', repeat=i):
            if not('3' in s and '5' in s and '7' in s):
                continue
            if int(''.join(s)) <= N:
                ans += 1
    return ans


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
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
    print(solve(N))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=2e5+10;
const int mod=1e9+7;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        if(x>=k)
            cnt++;
    }
    cout<<cnt<<'\n';




}


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

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int main(){
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  cout << H*W - h*W - w*H + h*w <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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 ll = long long;
using vi = vector<int>; using vvi = vector<vi>;
const ll MOD = 1e9+7; ll INF = 1LL << 60;
const vi d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vi d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vi d4x = {1, 0, -1, 0}; vi d4y = {0, 1, 0, -1};
//---------------------------------------

int main(){
    int n,m; cin>>n>>m;
    vector<pair<int,int>> lr(m);
    rep(i,m){
        cin>>lr[i].first>>lr[i].second;
    }
    vector<int> a(n+1,0);
    rep(i,m){
        a[lr[i].first-1]++;
        a[lr[i].second]--;
    }
    int cnt=0;
    if(a[0]==m) cnt++;
    for(int i=1; i<n+1; i++){
        a[i]=a[i-1]+a[i];
        if(a[i]==m) cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 1408
n=int(input())
a =[int(i) for i in input().split()]
b =[int(i) for i in input().split()]
a0=a.copy()

for i in range(n):
    if a[i]>=b[i]:
        a[i]-=b[i]
        b[i]=0
    else:
        b[i]-=a[i]
        a[i]=0
        if a[i+1]>b[i]:
            a[i+1]-=b[i]
            b[i]=0
        else:
            b[i]-=a[i+1]
            a[i+1]=0
print(sum([a0[i]-a[i] for i in range(n+1)]))

Measured memory_bytes: 18624
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const int INF = 2e9;
int N;
ll k, A[100005];

int main() {
  INCANT;
  cin >> N >> k;
  rep(i, N) cin >> A[i];

  ll ans=0ll;
  ll Cnt[40];
  rep(i, 40) {
    ll mask = 1ll << i;
    ll cnt = 0;
    rep(j, N) if (mask & A[j]) cnt++;
    Cnt[i] = cnt;
  }
  for (int i = 39; i>=-1; i--) { // XとKが初めて違うbitのところ。-1はX=K用
    if (i>=0 && !(k & (1ll<<i))) continue;
    ll tmp = 0ll;
    for (int bit=39; bit>=0; bit--) {
      ll mask = 1ll << bit;
      ll keisu = 0ll;
      if (i<bit) {
        if (k & mask) keisu = N-Cnt[bit];
        else keisu = Cnt[bit];
      }
      else if (i==bit) keisu=Cnt[bit];
      else keisu = max(Cnt[bit], N-Cnt[bit]);
      
      tmp+=keisu*mask; 
    }
    ans  = max(ans,tmp);
  }
  
  cout << ans <<  endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
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;}


int n,m;
vector<vector<int>> e;

bool all(vector<int> v){
	REP(i,v.size()){
		if(v[i]==-1){
			return false;
		} 
	}
	return true;
}

int dfs(int parent, vector<int> visited){
	visited[parent] = 1;
	if(all(visited)){
		return 1;
	}
	
	int ret=0;
	for(auto child: e[parent]){
		if(visited[child]==1) continue;
		
		ret += dfs(child, visited);
	}
	return ret;
}

int main(){
	
	cin >> n >> m;
	e.resize(n);
	REP(i,m){
		int a,b;
		cin >> a >> b;
		a--; b--;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	
	vector<int> visited(n, -1);
	int ans = dfs(0, visited);
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3640
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> as(n), bs(n);
    vector<ll> ps;
    for(int i = 0; i < n; i++){
        cin >> as[i] >> bs[i];
        ps.push_back(as[i] + bs[i]);
    }
    vector<int> is(n);
    iota(is.begin(), is.end(), 0);
    sort(is.begin(), is.end(), [&](int i, int j){ return ps[i] > ps[j]; });
    printde(ps, is);

    ll ans = 0;
    for(int i = 0; i < n; i += 2){
        int idx = is[i];
        ans += as[idx];
        printde(ans);
        if(i == n - 1){ break; }
        idx = is[i + 1];
        ans -= bs[idx];
        printde(ans);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main()
{
    int w,h,n;
    cin >> w >> h >> n;
    int mins[4]={0,w,0,h};
    vector<int> x(n), y(n), a(n);
    rep(i,n){
        cin >> x[i] >> y[i] >> a[i];
        a[i]--;
    }
    rep(i,n){
        if(a[i]==0){
            mins[0] = max(mins[0], x[i]);

        }else if(a[i]==1){
            mins[1] = min(mins[1], x[i]);
        }
        else if(a[i]==2){
            mins[2] = max(mins[2], y[i]);
        }
        else if(a[i]==3){
            mins[3] = min(mins[3], y[i]);
       }
    }
    cout << max(0, (mins[1] - mins[0])) * max(0,(mins[3] - mins[2])) << endl;
}

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

int main(){
    string S;
    cin >> S;
    int cnt = 0;
    if(S[0] == 'o'){
        cnt++;
    }
    if(S[1] == 'o'){
        cnt++;
    }
    if(S[2] == 'o'){
        cnt++;
    }
    cout << 700+cnt*100 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

int main() {
    std::string S;
    std::cin >> S;
    
    std::vector<int> red(S.size(), 0), blue(S.size(), 0);
    if (S[0] == '0') red[0] = 1;
    else blue[0] = 1;
    for (int i = 1; i < S.size(); ++i) {
        if (S[i] == '0') {
            red[i] = red[i - 1] + 1;
            blue[i] = blue[i - 1];
        } else {
            red[i] = red[i - 1];
            blue[i] = blue[i - 1] + 1;
        }
    }
    
    int ans = 0;
    for (int i = 0; i < S.size(); ++i) {
        if (S[i] == '1' && blue[i] <= red[i]) ans += 2;
        if (S[i] == '0' && blue[i] >= red[i]) ans += 2;
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int N, ans;
    cin >> N;
    vector<int> h(N);
    REP(int,i,0,N) cin >> h.at(i);
    vector<int> dp(N,0);
    dp.at(0) = 0;
    dp.at(1) = abs(h.at(1) - h.at(0));
    if ( N > 2 ) dp.at(2) = min(abs(h.at(2) - h.at(0))+dp.at(0), 
                                abs(h.at(2) - h.at(1))+dp.at(1));
    REP(int,i,3,N){
        dp.at(i) = min(abs(h.at(i)-h.at(i-1))+dp.at(i-1),
                       abs(h.at(i)-h.at(i-2))+dp.at(i-2) );
    }
    cout << dp.at(N-1) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)




























int main(){
    ll h, w, k;
    cin >> h >> w >> k;
    ll sy, sx, gy, gx;
    cin >> sy >> sx >> gy >> gx;
    sy--; sx--; gy--; gx--;
    vector<string> s(h);
    REP(i, h){
        cin >> s[i];
    }
    using T = tuple<ll, ll, ll, ll, ll>;
    const ll dy[4] = {-1, 0, 1, 0};
    const ll dx[4] = {0, 1, 0, -1};
    vector dist(4, vector(h, vector(w, INF)));
    priority_queue<T, vector<T>, greater<T>> que;
    REP(i, 4){
        que.push({0, k + 1, sy, sx, i});
        dist[i][sy][sx] = 0;
    }
    while(!que.empty()){
        auto [d, L, y, x, dir] = que.top(); que.pop();
        if(dist[dir][y][x] < d) continue;
        REP(i, 4){
            ll yy = y + dy[i], xx = x + dx[i], dd = d + ((L < k && i == dir)? 0 : 1);
            if(yy < 0 || yy >= h || xx < 0 || xx >= w || s[yy][xx] == '@' || dist[i][yy][xx] <= dd) continue;
            dist[i][yy][xx] = dd;
            que.push({dd, ((L < k && i == dir)? L + 1 : 1), yy, xx, i});
        }
    }
    ll ans = INF;
    REP(i, 4){
        ans = min(ans, dist[i][gy][gx]);
    }
    cout << ((ans != INF)? ans : -1) << endl;
}


Measured memory_bytes: 54088
#include<iostream>
using namespace std;
char a[128],b[128],c[128];
int d,e,f=0;
int main(){
    cin >>d;
cin >> a>>b>>c;
for(int i=0;i<d;i++){
    e=0;
    if(a[i]!=b[i])e++;
    if(a[i]!=c[i])e++;
    if(b[i]!=c[i])e++;
    if(e==3)f+=2;
    if(e==2)f++;
}
cout << f;
}


Measured memory_bytes: 256
#include<cstdio>

int main(){
    unsigned A, B, C;
    int K;
    scanf("%u %u %u\n%d", &A, &B, &C, &K);
    while(K > 0 && B <= A){
        B <<= 1;
        K--;
    }
    while(K > 0 && C <= B){
        C <<= 1;
        K--;
    }
    if(A < B && B < C) printf("Yes\n");
    else printf("No\n");
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
 string s;
  cin>>s;
  for(int i=0;i<s.length();i++)
  {	
    if(s[i]=='7')	{cout<<"Yes"<<endl;return 0;}
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3600
n,k=map(int,input().split())
P=list(map(int,input().split()))

dp=[0]*n
ans,total=0,0
for i in range(n):
  dp[i]=((1/2)*P[i]*(P[i]+1)) / P[i]
  if i>=k:
    ans=max(ans,total)
    total-=dp[i-k]
  total+=dp[i]
ans=max(ans,total)
print(ans)

Measured memory_bytes: 25604
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int mod = 998244353;
typedef long long ll;
ll dp[2][6005]={0};
int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    dp[a%2][b]=1;
    int j;
    for(int i=a;i<=c;i++){
        int row=i%2;
        j=b;
        if(i==a)
            j++;
        for(;j<=d;j++)
        if(i!=a&&j!=b){
            dp[row][j]=(dp[(row+1)%2][j]*j%mod+dp[row][j-1]*i%mod-(i-1)*(j-1)*dp[(row+1)%2][j-1]%mod+mod)%mod;
        }
        else
            dp[row][j]=(dp[(row+1)%2][j]*j%mod+dp[row][j-1]*i%mod)%mod;
//        for(int j=b;j<=d;j++){
//            cout << dp[row][j] << " \n"[j==d];
//        }
    }
    cout << dp[c%2][d] << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Library

//
int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int n;
    cin >> n;
    double ans = 0;
    for(int i = 0; i < n; ++i){
        double x; string u;
        cin >> x >> u;
        if(u == "JPY"){
            ans += x;
        }
        else{
            ans += 380000.0 * x;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
        

fast();
//ll t;cin>>t;while(t--)
{
    ll s,d,t;
    cin>>d>>t>>s;
    if(s*t>=d)
      Yes
    else
      No
}
return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  string S; cin >> S;
  string result;
  if (S=="Sunny") result = "Cloudy";
  else if (S=="Cloudy") result = "Rainy";
  else if (S=="Rainy") result = "Sunny";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;
typedef long long LL;

const int MOD = 1e9+7;

int dfs(vector<int> &dp,int h,vector<vector<int>>&table){
    if(h<=0) return 0;
    if(dp[h]!=-1) return dp[h];
    int cnt  = MOD;
    for(auto item:table){
        cnt = min(cnt,dfs(dp,h-item[0],table)+item[1]);
    }
    dp[h] = cnt;
    return dp[h];
}
void solve(){
    int h,n;
    cin>>h>>n;
    vector<vector<int>> table(n,vector<int>(2,0));
    for(int i=0;i<n;i++) cin>>table[i][0]>>table[i][1];
    vector<int> dp(h+1,MOD);
    dp[0] = 0;
    // dp[0]= 0;
    // cout<<dfs(dp,h,table)<<endl;
    for(int i=0;i<h;i++){
        for(auto &item:table){
            int mm = min(h,item[0]+i);
            dp[mm] = min(dp[mm],dp[i]+item[1]);
        }
    }
    cout<<dp[h]<<endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    // cin>>T;
    while(T--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 384
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n;
pi ps[100005];
int main(){
  cin>>n;
  REP(i,n) scanf("%d%d",&ps[i].fr,&ps[i].sc);

  multiset<lint> L,R;
  lint offL=0,offR=0;
  L.insert(ps[0].fr);R.insert(ps[0].fr);
  lint base=0;
  for(int i=1;i<n;++i){
    offR+=ps[i-1].sc-ps[i-1].fr;
    offL+=ps[i].sc-ps[i].fr;

    lint r=*R.begin()+offR,l=*(--L.end())-offL;
    if(ps[i].fr<=r && l<=ps[i].fr){
      L.insert(ps[i].fr+offL);
      R.insert(ps[i].fr-offR);
    }else if(ps[i].fr<l){
      base+=abs(l-ps[i].fr);
      L.erase(--L.end());
      R.insert(l-offR);
      L.insert(ps[i].fr+offL);
      L.insert(ps[i].fr+offL);
    }else{
      base+=abs(r-ps[i].fr);
      R.erase(R.begin());
      L.insert(r+offL);
      R.insert(ps[i].fr-offR);
      R.insert(ps[i].fr-offR);
    }
  }
  cout<<base<<endl;
  return 0;
}





Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin >> P[i];
  }
  sort(P.begin(),P.end());
  int a = P[N-1];
  int sum=0;
  for(int i=0;i<N-1;i++){
    sum+=P[i];
  }
  cout << sum + a/2 << endl;
}

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

void solve()
{
  int n,sum=0;
  cin>>n;
  int a[n],b[n],c[n-1];
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i];
  for(int i=0;i<n-1;i++)cin>>c[i];
  sum+=b[a[0]-1];
  for(int i=1;i<n;i++)
  {
      sum+=b[a[i]-1];
      if(a[i-1]==a[i]-1)
      {
          sum+=(c[a[i-1]-1]);
      }
  }cout<<sum;
}
signed main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int T=1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,C;
    cin >> N >> C;
    vvec<int> D(C,vec<int>(C));
    for(int i=0;i<C;i++) for(int j=0;j<C;j++) cin >> D[i][j];
    vvec<int> A(N,vec<int>(N));
    vvec<int> sum(3,vec<int>(C));
    for(int i=0;i<N;i++) for(int j=0;j<N;j++){
        cin >> A[i][j];
        A[i][j]--;
        for(int k=0;k<C;k++) sum[(i+j)%3][k] += D[A[i][j]][k];
    }
    int ans = 2e9;
    for(int i=0;i<C;i++) for(int j=0;j<C;j++) for(int k=0;k<C;k++){
        if(i==j || j==k || k==i) continue;
        ans = min(ans,sum[0][i]+sum[1][j]+sum[2][k]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1280
// A - Changing a Character
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	int n, k;
	cin >> n >> k;
	static char s[1024];
	cin >> s;
	s[k - 1] = s[k - 1] - 'A' + 'a';
	cout << s << endl;

	return 0;
}


Measured memory_bytes: 256
N,K = list(map(int, input().split()))
mod = 10**9+7
ans = 0

for i in range(K,N+2):
    M = N*(N+1)/2 - (N-i)*(N-i+1)/2+1
    m = i*(i-1)/2
    ans += (M-m)%mod

print(int(ans)%mod)

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

int main(){
	// your code goes here
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	cout.tie(NULL);
	
	char ch;
	cin>>ch;
	ch=ch+1;
	cout<<ch;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;


int main(){
	long a,b,n;
	cin >>n >> a >> b;
  	cout << n /(a+b)*a+min(n%(a+b),a) << endl;
	
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)

{

int x,y,W,H,r ;

scanf("%d %d %d %d %d",&W,&H,&x,&y,&r) ;

if(x>=r&&y>=r&&W>=x+r&&H>=y+r){

printf("Yes\n") ;

}

else{

printf("No\n") ;

}

return 0 ;

}

 

Measured memory_bytes: 584
N,M=map(int,input().split())
A=[[0 for i in range(2)] for j in range(N+1)]
for i in range(M):
    p,s=input().split()
    p=int(p)
    if s=="AC": A[p][0]=1
    if s=="WA" and A[p][0]==0: A[p][1]+=1
AC=0
Pen=0
for row in A:
    AC+=row[0]
    Pen+=row[0]*row[1]
print(AC, Pen)

Measured memory_bytes: 14836
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define mod 1000000007
using namespace std;
const int N=123456;

vector<int>adj[N];
int color[N];


int find(int u,int par,int n,vi&path)
{

    for(auto v:adj[u])
    {
        if(v==par)continue;
        if(v==n)return 1;

        if(find(v,u,n,path))
            {path.pb(v);
             return 1;
            }
    }
    return 0;
}

void dfs(int u,int par,int n)
{
    for(int v : adj[u])
    {
       if(v==par)continue;

       if( color[v]==0 && color[u]==1)
            color[v]=1;
       else if( color[v]==0 )
        color[v]=2;

        dfs(v,u,n);
    }

}


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

int n;
cin>>n;

for(int i=0;i<n-1;i++)
{
    int a,b;
    cin>>a>>b;

    adj[a].pb(b);
    adj[b].pb(a);
}

color[1]=2;
color[n]=1;


vector<int>path;
find(1,0,n,path);

int k = path.size();
for(int i=0;i<k/2;i++)
{
    color[path[i]]=1;

}

for(int i=k/2;i<k;i++)
    color[path[i]]=2;



dfs(1,0,n);
int  w=0,b=0;

for(int i=1;i<=n;i++)
{
    //cout<<color[i]<<" ";
    if(color[i]==1)
        w++;
    else
        b++;
}
//cout<<w<<" "<<b<<endl;

if(w>=b)
    cout<<"Snuke";
else
    cout<<"Fennec";



return 0;
}


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

ll gcd(ll x, ll y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

int main() {
    ll x;
    cin >> x;
    
    ll ans = 0;
    int i;
    for (i = 1; ans < x; i++) {
        ans += i;
    }
    i--;
    cout << i << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
ll gcd(ll x, ll y) {
    ll num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

Measured memory_bytes: 3628
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val list = readLine()!!.split(" ").map(String::toInt)

    var count = 1
    var current = list[0]
    for (i in 1..(n - 1)) {
        if (list[0] <= list[i] && current <= list[i]) {
            current = list[i]
            count++
        }
    }
    println(count)
}

Measured memory_bytes: 37872