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

const long long INF = 1LL << 60;

int main() {
    int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
    for (int i = 0; i < ty-sy; i++) {
        cout << 'U';
    }
    for (int i = 0; i < tx-sx; i++) {
        cout << 'R';
    }
    for (int i = 0; i < ty-sy; i++) {
        cout << 'D';
    }
    for (int i = 0; i < tx-sx; i++) {
        cout << 'L';
    }
    cout << 'L';
    for (int i = 0; i <= ty-sy; i++) {
        cout << 'U';
    }
    for (int i = 0; i <= tx-sx; i++) {
        cout << 'R';
    }
    cout << 'D';
    cout << 'R';
    for (int i = 0; i <= ty-sy; i++) {
        cout << 'D';
    }
    for (int i = 0; i <= tx-sx; i++) {
        cout << 'L';
    }
    cout << 'U' << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define ll long long int
#define NMAX 1000005

using namespace std;

ifstream fin("test.in");
ofstream fout("test.out");

ll n, val, i;

int main(){
    ios_base::sync_with_stdio(false);
    cin >> n;
    val = 2;
    for(i=2; i<=n+1; i++){
        val = 2 + 2*val;
    }
    cout << val << '\n';
    return 0;
}

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

cum = [[0]*(N) for i in range(N)]
for i in range(N):
  c = 0
  for j in range(i, N):
    c += A[j]
    cum[i][j] = c

dp = [[0]*N for i in range(N)]

def get_min_cost(i, j):
  global dp
  if dp[i][j] > 0:
    return dp[i][j]
  else:
    min_cost = 0
    for k in range(i, j):
      if min_cost == 0:
        min_cost = get_min_cost(i, k) + get_min_cost(k+1, j) + cum[i][j]
      else:
        cost = get_min_cost(i, k) + get_min_cost(k+1, j) + cum[i][j]
        min_cost = min(min_cost, cost)
    
    dp[i][j] = min_cost
    return dp[i][j]

print(get_min_cost(0, N-1))

Measured memory_bytes: 47708
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using Graph = std::vector<std::vector<int> >;
const int INF = 1e17;
/* libraries */

constexpr int MOD = 1e9+7;
struct mint
{
	int v;
	mint():v(0){}
	mint(int v):v((v+MOD)%MOD){}
	mint operator-()const{ return mint(0) - *this; }
	mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }
	mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }
	mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }
	mint& operator/=(const mint& a){ (*this) *= a.inv(); 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 operator/(const mint& a)const{ return mint(*this) /= a; }
	bool operator<(const mint& a)const{ return v < a.v; }
	bool operator==(const mint& a)const{ return v == a.v; }
	mint pow(int k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }
	mint inv()const{ return pow(MOD-2); }
	static mint comb(int n, int k) {
		if(n-k<k) k=n-k;
		mint num(1), dom(1);
		for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; }
		return num/dom;
	}
};
std::istream& operator>>(std::istream&i,mint&a){ int t; i>>t; a=mint(t); return i; }
std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }


signed main() {
	int n,k;
	std::cin >> n >> k;
	std::vector<mint> v(k+1);
	for(int x=k;x>0;x--) {
		v[x]=mint(k/x).pow(n);
		for(int y=2;y*x<=k;y++) {
			v[x]-=v[x*y];
		}
	}
	mint ans=0;
	for(int x=1;x<=k;x++) ans+=mint(x)*v[x];
	print(ans);
	return 0;
}


Measured memory_bytes: 4012
# -*- coding: utf-8 -*-

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    L, R, d = list(map(int, input().split()))

    return L, R, d


def main(L: int, R: int, d: int) -> None:
    """
    メイン処理.

    Args:\n
        L (int): 整数（1 <= L <= R <= 100）
        R (int): 整数（1 <= L <= R <= 100）
        d (int): 整数（1 <= d <= 100）
    """
    # 求解処理
    ans = R // d - (L - 1) // d

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    L, R, d = get_input()

    # メイン処理
    main(L, R, d)


Measured memory_bytes: 9068
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int N;
  cin >> N;
  
  vector<int>num(N,0);
  for(int i=0;i<N;i++){
    cin >> num[i];
  }
  
  int even = 0;
  int odd = 0;
  
  for(int i=0;i<N;i++){
    if(num[i] % 2 == 0)
      even++;
    else
      odd++;
  }
  
  int pow2 = 1;
  for(int i=0;i<even;i++){
    pow2 *= 2;
  }
  
  int pow3 = 1;
  for(int i=0;i<N;i++){
    pow3 *= 3;
  }

  cout << pow3 - pow2 << endl;
  
  return 0;
}



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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

// Mod int
const int mod = 1000000007;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  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;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
typedef vector<mint> vm;
typedef vector<vm> vvm;
//

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  VLL a(n);
  rep(i,n) cin >> a[i];
  ll cnt = 0;
  rep(i,n){
    FOR(j,i+1,n){
      if(a[i] > a[j]) cnt++;
    }
  }

  VLL b(a);
  sort(all(b));
  mint sum[n];
  memset(sum,0,sizeof(sum));
  rep(i,n){
    sum[i] = b.end() - upper_bound(all(b),a[i]) ;
  }

  mint ans = 0;
  if(k >=2){
    rep(i,n){
      mint tmp = ((k-1)*k)/2LL;
      tmp *= sum[i];
      ans += tmp;
    }
  }

  ans += k * cnt;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt(), H[] = new int[N], temp = 0, ans = 0;
		for (int i = 0; i < N; i++) {
			H[i] = sc.nextInt();
			if (i != 0) {
				if (H[i - 1] >= H[i]) {
					temp++;
                  	//System.out.println("time"+(i+1));
				} else {
					if (ans <= temp) {
						ans = temp;
						temp = 0;
					} else {
						temp = 0;
					}
				}
			}
		}
		if(temp>=ans)
			ans = temp;
		System.out.println(ans);
	}
}

Measured memory_bytes: 50940
#include"stdio.h"
int main(){
    int N,A,B,i,res=0;
    scanf("%d%d%d",&N,&A,&B);
    for(i=1;i<=N;i++){
        int sum=i%10+i/10%10+i/100%10+i/1000%10+i/10000;
        if(sum>=A&&sum<=B){
            res+=i;
        }
    }
    printf("%d",res);
    return 0;
}


Measured memory_bytes: 1720
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main()
{
   cin.tie(0);
   ios::sync_with_stdio(false);
   ll n;
   cin >> n;
   vector<ll> v(n);
   for (int i = 0; i < n; i++)
   {
      cin >> v[i];
   }
   ll bits = 0;
   for (int j = 0; j < n; j++)
   {
      bits = bits ^ v[j];
   }
   for (int i = 0; i < n; i++)
   {
      ll pin = v[i];
      bits = bits ^ v[i];
      cout << bits << " ";
      bits = bits ^ v[i];
   }
   cout << endl;
}

Measured memory_bytes: 4712
#include <bits/stdc++.h>
#define uint unsigned long long
#define ll long long
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9

using namespace std;
inline int read()
{
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}
inline int max(int a, int b)
{
	if(a < b) return b;
	return a;
}

struct circle
{
    db x, y, r;
}a[1015];
vector<db> cost(1015, 1e18);
db dist(db a1, db b1, db a2, db b2)
{
    return sqrt(((a1 - a2) * (a1 - a2)) + ((b1 - b2) * (b1 - b2)));
}
int main()
{
	a[0].x = (db)read();
	a[0].y = (db)read();
	a[1].x = (db)read();
	a[1].y = (db)read();
    a[0].r = a[1].r = 0;
    int n = read();
    vector<vector<pair<int, db> > > v(1010);
    v[0].pb(mp(1, dist(a[0].x, a[0].y, a[1].x, a[1].y)));
    v[1].pb(mp(0, dist(a[0].x, a[0].y, a[1].x, a[1].y)));
    cost[0] = 0;
    rep(i, 2, n + 1)
    {
        cin >> a[i].x >> a[i].y >> a[i].r;
        rep(j, 0, i - 1)
        {
            v[i].pb({j, max(0.0, dist(a[i].x, a[i].y, a[j].x, a[j].y) - a[i].r - a[j].r)});
            v[j].pb({i, max(0.0, dist(a[i].x, a[i].y, a[j].x, a[j].y) - a[i].r - a[j].r)});
        }
    }
    priority_queue<pair<db, int> > pq;
    pq.push({0, 0});
    while (pq.size())
    {
        int idx = pq.top().Y;
        pq.pop();
        int nn = v[idx].size() - 1;
        rep(i, 0, nn)
        {
            int cur = v[idx][i].X;
            if (cost[cur] > cost[idx] + v[idx][i].Y)
            {
                cost[cur] = cost[idx] + v[idx][i].Y;
                pq.push({-1 * cost[cur], cur});
            }
        }
    }
    printf("%.10lf", cost[1]);
    return 0;
}


Measured memory_bytes: 22384
#include <iostream>
#include <math.h>
#include <string>

#define MIN(x, y) (x < y ? x : y)
#define MAX(x, y) (x > y ? x : y)

using namespace std;

int main(){
	string s;
	cin >> s;

	int min = 0, max = 200001;
	for(int i = 0; i < s.length(); ++i){
		if(s[i] == 'A'){
			min = i;
			break;
		}
	}
	for(int i = s.length() - 1; i >= 0; --i){
		if(s[i] == 'Z'){
			max = i;
			break;
		}
	}
	
	cout << (max - min + 1) << endl;	
}



Measured memory_bytes: 640
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,ii ) for( typeof(gg.begin()) ii=gg.begin();ii!=gg.end();ii++)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define sz(a) int((a).size())
#define N 1000010
#define MAX 30
#define mod 1000000007
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define all(a) a.begin(),a.end()
const ll INF = 1e18+1;

int main()
{
	ll a,b,c;
	scanf("%lld%lld%lld",&a,&b,&c);
	if (a%2&&b%2&&c%2)
		printf("%lld\n",min(a*b,min(a*c,b*c)));
	else printf("0\n");
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    int n,m,x; cin >> n >> m >> x;
    int rel = 0, a[100] = {0};
    rep(i, m){
        int temp; cin >> temp;
        a[temp]++;
    }
    int zero = 0, maxi = 0;
    for(int i = x; i < n; i++) maxi += a[i];
    for(int i = x; i > 0; i--) zero += a[i];
    cout << min(maxi, zero) << endl;
}

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

int main(){
	long a,b,x;
	cin >> a >> b >> x;
	long cnt;
	if (a==0) {
		cnt=1+b/x;
	} else {
		cnt=(b/x)-((a-1)/x);
	}
	cout << cnt <<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
h = [int(i) for i in input().split()]

count = 0
provisional_max_count = 0
for i in range(n-1):
    if h[i] >= h[i+1]:
        count += 1
    else:
        provisional_max_count = max(count, provisional_max_count)
        count = 0
print(max(provisional_max_count, count))


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

int main() {
  int n,m,X,Y;
  cin >> n >> m >> X >> Y;
  vector<int> x(n),y(m);
  for(int i=0;i<n;i++){
    cin >> x.at(i);
  }
  for(int i=0;i<m;i++){
    cin >> y.at(i);
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  if(x.at(n-1)>=y.at(0)||y.at(0)<=X||Y<=x.at(n-1)){
    cout << "War" << endl;
  }else{
    cout << "No War" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int i = 0;i < (int)(n);i++)

int main() {
	int x,ans=1,b=2,p=2;
	cin >> x;
	while (true) {
		while (true) {
			if (x >= (int)pow((double)b, (double)(p + 1))) {
				p++;
			}
			else if (x == 1) {
				break;
			}
			else {
				ans = max(ans, (int)pow((double)b, (double)p));
				break;
			}
		}
		if (x >= (int)pow((double)(b+1), 2.0)) {
			b++;
			p = 2;
		}
      else if(x==1){break;}
		else {
			ans = max(ans, (int)pow((double)b, (double)p));
			break;
		}
	}
	cout << ans;
	return(0);
}
//(int)pow((double)b, (double)p)


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n = in();
  vi p(n);
  rep(i,n) cin >> p[i];
  vi q(n);
  rep(i,n) cin >> q[i];

  vector<int> v;
  rep(i,n) v.push_back(i+1);
  int a, b, cnt = 1;
  do {
    if (v == p) a = cnt;
    if (v == q) b = cnt;
    cnt++;
  } while (next_permutation(v.begin(), v.end()));

  cout << abs(a-b) << endl;
  return 0;
}

Measured memory_bytes: 256
#define DEBUG(...)
/*                        Strip me down and go to town                        */
/*                          Lick me over upside down                          */
/*                     Pound and pound and pound and pound                    */
/*                        Baby make me make that sound                        */
/*                Aaah, aaah, aaah, aaah, aaaaaaaaaaaaaaaaaah!                */
#include<stdio.h>
#include<algorithm>

using namespace std;

char str[5];

int main() {
  scanf("%s", str);
  sort(str, str + 4);
  if (str[0] == str[1] && str[2] == str[3] && str[1] != str[2]) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner s = new Scanner(System.in);
        int X = s.nextInt();
        int N = s.nextInt();
        Boolean check[] =  new Boolean[102];
        for(int i = 0; i < 102; i++){
            check[i] = true;
        } 
        for(int i = 0; i < N; i++ ) {
            check[s.nextInt()] = false;
        }
        int puraN = X;
        int maiN = X;
        int i = 0;
        int answer = X;
        while(!check[X]){
            if(i % 2 == 0){
                maiN -= 1;
                if(check[maiN]){
                    answer = maiN;
                    break;
                } 
            }
            if(i % 2 != 0){
                puraN += 1;
                if(check[puraN]){
                     answer = puraN;
                    break; 
                }
            }
            i += 1;
                
        }    
        
        System.out.println(answer); 
    }
}


Measured memory_bytes: 36084
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    print(Yes if '7' in input() else No)

main()



Measured memory_bytes: 10372
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  int n; cin >> n;
  vector<int> v(n);
  int sum = 0;
  for(int i = 0; i < n; i++){
    cin >> v[i];
    sum += v[i];
  }
  sort(v.begin(), v.end());
  if(sum % 10 != 0){
    cout << sum << endl;
    return;
  }
  for(int i = 0; i < n; i++){
    if(v[i] % 10 != 0){
      cout << sum - v[i] << endl;
      return;
    }
  }
  cout << 0 << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int a[101][101] = {};
int b[101][101] = {};
long ans[101][101] = {};

int main()
{
	int n, m, l;
	cin >> n >> m >> l;
	//A
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> a[i][j];
		}
	}
	//B
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < l; j++)
		{
			cin >> b[i][j];
		}
	}
	//
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < l; j++)
		{
			for (int k = 0; k < m; k++)
			{
				ans[i][j] = ans[i][j] + a[i][k] * b[k][j];
			}
		}
	}
	//
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < l; j++)
		{
			cout << ans[i][j];
			if (j != l-1)
			{
				cout << " ";
			}
			else
			{
				cout << endl;
			}
		}
	}


	return 0;
}

Measured memory_bytes: 3188
#include <stdio.h>

int main(void){
  int x[100005], A[100005]={0}, N, i;
  //N,Ai をinput
  scanf("%d", &N);
  for(i=1; i<=N; i++){
    scanf("%d", &A[i]);
    A[100000] += A[i];
  }
  //X1 から決める
  x[1] = A[100000] / 2;
  for(i=2; i<N; i += 2){
    x[1] -= A[i];
  }
  for(i=1; i<N; i++){
    x[i+1] = A[i] - x[i];
  }
  //output
  for(i=1; i<=N; i++){
    printf("%d\n", 2 * x[i]);
  }
  return 0;
}

Measured memory_bytes: 2048
n=int(input())
t,a=map(int,input().split())
h = list(map(int, input().split()))

best_point=0
best=float('inf')
i=0
for hi in h:
    tmp = t - (hi * 0.006)
    dif = abs(a - tmp)
    if abs(dif) < abs(best):
        best = dif
        best_point = i + 1
    i += 1
print(best_point)

Measured memory_bytes: 3064
#import sys
#input = sys.stdin.readline
def main():
    N = int( input())
    V = list( map( int, input().split()))
    V.sort()
    now = V[0]
    for i in range(1,N):
        now = (now+V[i])/2
    print(now)
if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
fn c2i(c: char) -> i32 {
    c as i32 - 48
}

fn s2i(s: String) -> i32 {
    s.parse().unwrap()
}

fn main() {
    let n = read::<usize>();
    let s = read::<String>().chars().collect::<Vec<char>>();
    let mut ans = vec![false; 1000];
    let mut d0 = vec![false; 10];
    let mut d1 = vec![false; 100];

    for i in 0..n-2 {
        //println!("i = {}, d0 = {:?}", i, d0);
        if d0[c2i(s[i]) as usize] {
            //println!("skip d0");
            continue;
        } else {
            d0[c2i(s[i]) as usize] = true;
        }

        for j in i + 1..n - 1 {
            //println!("j = {}, d1 = {:?}", j, d1);

            let keta2 = s2i(format!("{}{}", s[i], s[j])) as usize;
            if d1[keta2] {
                //println!("skip d1");
                continue;
            } else {
                d1[keta2] = true;
            }

            for k in j+1..n {
                let ansho = s2i(format!("{}{}{}", s[i], s[j], s[k])) as usize;
                //println!("- {}", ansho);
                ans[ansho] = true;
            }
        }
    }

    let count = ans.into_iter().filter(|&b| b == true).count();
    println!("{}", count);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

#define REP(i, s, n) for(int i = s; i < n; ++i)
#define rep(i, n)		 REP(i, 0, n)
#define SORT(c)			 sort((c).begin(), (c).end())
#define IINF	INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

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

/*
struct point{
	ll x;
	ll y;
	point(){x = 0;y = 0;}
	point(ll x, ll y):x(x), y(y){}
};
*/


int main() {

	int n, m;
	cin >> n >> m;
	
	vector<int> a(m), b(m), c(m);
	vector<vector<int>> g(n, vector<int>(n, IINF / 2));
	rep(i, n) g[i][i] = 0;
	
	rep(i, m){
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;b[i]--;
		g[a[i]][b[i]] =  c[i];
		g[b[i]][a[i]] = c[i];
	}
	
    rep(k, n) {
        rep(i, n) {
            rep(j, n) {
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
    
    int ans = 0;
    rep(i, m){
    	if(g[a[i]][b[i]] != c[i]) ans++;
    }
    
    
    cout << ans <<endl;

}


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

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

  long long a;
  string s;
  cin >> a >> s;
  if(a<3200){
    s="red";
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 508
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int K,A,B;

signed main(){
	cin>>K>>A>>B;
	for(int i=A;i<=B;i++){
		if(i%K==0){
			cout<<"OK"<<endl;
			return 0;
		}
	}
	cout<<"NG"<<endl;
	return 0;
}


Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N, Q;
	string S;
	cin >> N >> S >> Q;
	for (int i = 0; i < Q; i++) {
		long long K;
		cin >> K;
		long long CurX = 0, CurY = 0, COUNT = 0, ANS = 0;
		vector<long long> MCOUNT(N, 0);
		for (int j = 0; j < N; j++) {
			if (S[j] == 'D') CurX++;
			if (S[j] == 'M') CurY++;
			if (S[j] == 'M') COUNT += CurX;
			if (j - K >= 0) {
				if (S[j - K] == 'M') CurY--;
				if (S[j - K] == 'D') COUNT -= CurY, CurX--;
			}
			if (S[j] == 'C') ANS += COUNT;
		}
		cout << ANS << endl;
	}
}

Measured memory_bytes: 9220
n=int(input())
t,a=map(int, input().split())
h=list(map(int, input().split()))
ans=0
cnt=100000000
for i in range(n):
  if abs(a-t+(h[i]*0.006))<cnt:
    cnt=abs(a-t+(h[i]*0.006))
    ans=i
print(ans+1)

Measured memory_bytes: 9076
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
int n, k;
int a[200000];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>k;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a,a+n);
    int count[n];
    int tempcount=1;
    int j=0;
    for(int i=0;i<n-1;i++){
        if(a[i+1]==a[i]&&i==n-2){
            tempcount++;
            count[j]=tempcount;
        }
        else if(i==n-2){
            count[j]=tempcount;
            j++;
            count[j]=1;
        }
        else if(a[i+1]==a[i]){
            tempcount++;
        }
        else{
            count[j]=tempcount;
            tempcount=1;
            j++;
        }
    }
    if(j+1<=k){
        cout << 0 << "\n";
        return 0;
    }
    sort(count,count+j+1);
    int ans=0;
    for(int i=0;i<j+1-k;i++){
        ans+=count[i];
    }
    cout << ans << "\n";
}

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

#define  vt            vector
#define  db            long double
#define  int           long long
#define  pb            push_back
#define  inf           (int)1e18
#define  mxn           (int)2e5+5
#define  pii           pair<int,int>

#define  si(x)         (int)x.size()
#define  all(x)        x.begin(),x.end()
#define  mem(a,x)      memset(a,x,sizeof(a))
#define  forr(i,n)     for(int i=0;i<n;i++)

#define deb(x)   cout<<"> "<<#x<<" : "<<x<<endl
#define pnr(a)   for(auto x:a){cout<<x<<" ";}cout<<endl;
#define pnr2(a)  for(auto x:a){cout<<x.first<<" "<<x.second<<endl;}

int mainx()
{
    string s;
    cin >> s;
    int sum = 0;
    for (auto x : s)
    {
        sum += ( x - '0');
        if (sum % 9 == 0)
            sum = 0;
    }
    if (sum == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


inline void include() {
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    //freopen("out.txt","w",stdout);
#endif
}
int32_t main() {
    //include();
    ios::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    //cout << fixed << setprecision(20);

    int tt = 1;
    //cin>>tt;
    for (int t = 1 ; t <= tt ; t++ )
    {
        mainx();
    }
    return 0 ;
}


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

using ll = long long;
using ull = unsigned long long;

using namespace std;

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

    ll N,M,A,sum=0;
    ll count = 0;
    vector<ll> items;
    vector<ll> maxs;

    cin>>N>>M;

    for(ll i=0; i<N; ++i)
    {
        cin>>A;
        sum+=A;
        items.emplace_back(A);
    }

    double trigg = (1.0/(4*M))*sum;

    for(const auto& i:items)
    {
        if(i>=trigg)
        {
            count++;
            if(count >=M)
                break;
        }
    }



    if(count<M)
        cout<<"No\n";
    else
        cout<<"Yes\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
         
typedef long long ll;
using namespace std;
        
#define F first
#define S second
#define sqr(x) x*x
#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define repit(i, n) for(auto it = n.begin(); it != n.end(); ++it)
       
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
int lcm(int a,int b){return abs(a*b)/gcd(a,b);}
     
const long long MOD = 1e9 + 7;

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    ll res = 1;
    ll n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        res *= i;
        res %= MOD;  
    }
    cout << res;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    double R;cin >> R;
    const double PI=3.14159265358979323846;
    double ans = 2*R*PI;
    cout << std::fixed << std::setprecision(15) << ans << endl;
}

Measured memory_bytes: 3784
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
total = sum(a)
d = defaultdict(int)

for i in a:
    d[i] += 1

q = int(input())

for i in range(q):
    b, c = map(int, input().split())
    num = d[b]
    total += num * (c - b)
    print(total)
    d[b] = 0
    d[c] += num

Measured memory_bytes: 24108
ini=map(int, raw_input().split())
box=map(int, raw_input().split())

time=0

for i in range(ini[0]-1):
	pre_time=0
	if box[i]+box[i+1]>ini[1]:
		pre_time+=box[i]+box[i+1]-ini[1]
		box[i+1]-=pre_time
		if box[i+1]<0:
			box[i]+=box[i+1]
			box[i+1]=0
	time+=pre_time

print time

Measured memory_bytes: 11340
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string, copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7
ans = count = 0; pro = 1

d,g=map(int,input().split());g//=100
D=collections.defaultdict(lambda: inf )
D[0]=0
for i in range(1,d+1):
    p,c=map(int,input().split());c//=100
    # for key, value in tuple(D.items()):
    #     print(D[key],p)
    #     D[key+i*p+c//100] = min(D[key+i*p+c//100], D[key]+p)
    S=D.copy()
    for key,value in S.items():
        for k in range(1,p):    
        # print(D[key+i])
            D[key+i*k] = min(D[key+i*k],S[key]+k)
        D[key+i*p+c] = min(D[key+i*p+c],S[key]+p)
ans=inf
for key,value in D.items():
    # print(key,value)
    if key>=g:
        ans=min(ans,value)
print(ans)
        


Measured memory_bytes: 64476
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x, y;
  cin >> x >> y;
  int a = 1;
  while (x <= y) {
    x *= 2;
    if (x <= y) {
      a++;
    } else {
      break;
    }
  }
  cout << a << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

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

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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

ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

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

const ll mod = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//







int main()
{


        ll a,b,c,d;
        cin >> a >> b >> c >> d;

        ll tmp = lcm(c,d);

        ll val1 = b/c - a/c;
        if(a%c == 0) val1++;
        ll val2 = b/d - a/d;
        if(a%d == 0) val2++;

        ll val3 = b/tmp - a/tmp;
        if(a%tmp == 0) val3++;

        ll sum = b - a + 1;

        cout << sum - (val1 + val2 - val3) << endl;
        return 0;
}

















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

int main(){
  long long a,b;
  cin>>a>>b;
  if(a==1&&b==1){
    cout<<1<<endl;
  }else if(a==1){
    cout<<b-2<<endl;
  }else if(b==1){
    cout<<a-2<<endl;
  }else{
    cout<<(a-2)*(b-2)<<endl;
  }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.root(x)]

    def is_same(self, x, y):
        return self.root(x) == self.root(y)

    def members(self, x):
        root = self.root(x)
        return [i for i in range(self.n) if self.root(i) == root]

    def all_roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.all_roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.all_roots()}

    def __str__(self):
        return ''.join('{}: {}'.format(r, self.members(r)) for r in self.all_roots())

uf = UnionFind(n)
ab = [tuple(map(int,input().split())) for i in range(m)]
for a,b in ab:
    a,b = a-1,b-1
    if uf.is_same(a,b): continue
    uf.union(a,b)

ans = 0

loop = [set() for i in range(n)]
for i in range(n):
    r = uf.root(i)
    loop[r].add(i)

for i in range(n):
    for j in loop[i]:
        if p[j]-1 in loop[i]: ans += 1

print(ans)


Measured memory_bytes: 113120
import math
n,m=map(int,input().split())
count=0
if m==1 or n==1:
  count+=0
if n>1:
  count+= math.factorial(n)/(math.factorial(n-2)*2)
if m>1:
  count+= math.factorial(m)/(math.factorial(m-2)*2)
print(int(count))

Measured memory_bytes: 3060
from bisect import bisect
n = input()

data = [0]*(n+1)
def get(i):
    r = 0
    while i>0:
        r += data[i]
        i -= i & -i
    return r
def add(i, x):
    while i <= n:
        data[i] += x
        i += i & -i

H = []
V = []
s = set()
for i in xrange(n):
    x1, y1, x2, y2 = map(int, raw_input().split())
    if x1 == x2:
        if y1 > y2: y1, y2 = y2, y1
        V.append((x1, y1, y2))
    else:
        if x1 > x2: x1, x2 = x2, x1
        H.append((x1, y1, 1))
        H.append((x2+1, y1, -1))
        s.add(y1)
ys = [-10**18] + sorted(s)
ymap = {e: i for i, e in enumerate(ys)}.__getitem__
V.sort(); H.sort()

ans = 0
idx_h = 0; hn = len(H)
for x, y1, y2 in V:
    while idx_h < hn and H[idx_h][0] <= x:
        add(ymap(H[idx_h][1]), H[idx_h][2])
        idx_h += 1
    idx_l = bisect(ys, y1-1)-1
    idx_r = bisect(ys, y2)-1
    ans += get(idx_r) - get(idx_l)
print ans

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

int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n, x = 0;
  cin >> n;
  string s;
  cin >> s;
  
  int mx = 0;
  
  for(int i = 0; i < n; i++)
  {
    if(s[i] == 'I')
      x++;
    else
      x--;
    mx = max(mx, x);
  }
  
  cout << mx << endl;
  return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h, w, n;
  cin >> h >> w >> n;
  vector<ll> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  set<pair<int, int>> board;
  map<pair<int, int>, int> mp;
  for (int i = 0; i < n; i++) {
    for (int j = -1; j <= 1; j++) {
      for (int k = -1; k <= 1; k++) {
        int dy = a[i] + j, dx = b[i] + k;
        if (dy <= 1 || dy >= h || dx <= 1 || dx >= w) {
          continue;
        }
        mp[make_pair(dy, dx)]++;
      }
    }
  }
  vector<ll> answers(10, 0);
  answers[0] = (h - 2) * (w - 2);
  for (auto kv: mp) {
    answers[0]--;
    answers[kv.second]++;
  }
  for (int i = 0; i < 10; i++) {
    cout << answers[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 58112
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

constexpr int inf = 2147483647;
constexpr int64_t inf64 = 9223372036854775807;
constexpr int mod = 1e9+7;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};

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

  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  rep(i,h) cin >> grid[i];

  int cnt = 0;
  rep(i,h) rep(j,w) if(grid[i][j] == '#') cnt++;

  queue<pair<int, int>> que;
  vector<vector<int>> dist(h, vector<int> (w, -1));
  dist[0][0] = 0;
  que.push({0, 0});

  while(!que.empty()) {
    int vh = que.front().fi;
    int vw = que.front().se;
    que.pop();

    rep(dir, 4) {
      int nvh = vh + dy[dir];
      int nvw = vw + dx[dir];

      if(nvh < 0) continue;
      if(nvw < 0) continue;
      if(nvh >= h) continue;
      if(nvw >= w) continue;
      if(dist[nvh][nvw] != -1) continue;
      if(grid[nvh][nvw] == '#') continue;

      dist[nvh][nvw] = dist[vh][vw]+1;
      que.push({nvh, nvw});
    }
  }

  if(dist[h-1][w-1] == -1) cout << -1 << endl;
  else cout << h*w - cnt- dist[h-1][w-1] - 1 << endl;
  return 0;
}

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

using namespace std;

int main() {
	string str;
	cin >> str;
	int n = str.size();
	vector <string> a;
	a.push_back("dream");
	a.push_back("dreamer");
	a.push_back("erase");
	a.push_back("eraser");
	for (int i = 0; i < n;) {
		if (str[i] != 'd' && str[i] != 'e') {
			puts("NO");
			return 0;
		}
		if (str[i] == 'd') {
			bool found = true;
			if (i + 4 < n) {
				for (int j = 0; j < 5; j++) {
					if (str[i + j] != a[1][j]) found = false;	
				}
			} else {
				puts("NO");
				return 0;
			}
			if (!found) {
				puts("NO");
				return 0;
			} 
			if (i + 7 < n) {	
				if (str[i + 5] == 'e' && str[i + 6] == 'r' && (str[i + 7] == 'd' || str[i + 7] == 'e')) {
					i += 7;
					continue;
				}
			}
			if (i + 6 == n - 1) {
				if (str[i + 5] == 'e' && str[i + 6] == 'r') {
					i += 7; 
					break;
				}	
			}
			i += 5;
		} else {
			bool found = true;
			if (i + 4 < n) {
				for (int j = 0; j < 5; j++) {
					if (str[i + j] != a[2][j]) found = false;
				}
			} else {
				puts("NO");
				return 0;
			}
			if (!found) {
				puts("NO");
				return 0;
			}
			if (i + 5 < n) {
				if (str[i + 5] == 'r') {
					i += 6;
					continue;
				}
			}
			i += 5;
		}           	
	}
	puts("YES");
	return 0;
}

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n"
#define rep(i,n) for(int i=0; i<(n); ++i)

typedef pair<int, int> P;
typedef pair<string, int> Psi;



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

	string s; cin>>s;

	ll k; cin>>k;

	if( k-1<s.length()){
		if(s[k-1] =='1'){
		bool judge =true;
		rep(i, k){
			if(s[i] != '1'){
				judge =false;
				break;
			}
		}
		if(judge){writeln(1);
		return 0;
		}
		}
	}

	rep(i,s.length()){
		if(s[i] != '1'){
			writeln(s[i]);
			return 0;
		}
	}


}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int l,a,b,c,d,i,cnt=0;
	scanf("%d %d %d %d %d",&l,&a,&b,&c,&d);
	while(1){
		a-=c; b-=d;
		cnt++;
		if(a<=0&&b<=0)break;
	}
	printf("%d\n",l-cnt);
	return 0;
}

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

typedef long long ll;
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

int main(){

    int n,m;
    cin >> n >> m;

    ll XYZ[n],xYZ[n],XyZ[n],XYz[n],xyZ[n],Xyz[n],xYz[n],xyz[n];
    REP(i,n){
        ll x,y,z;
        cin >>x>>y>>z;
        XYZ[i] = x+y+z;
        XYz[i] = x+y-z;
        XyZ[i] = x-y+z;
        xYZ[i] = -x+y+z;
        xyZ[i] = -x-y+z;
        xYz[i] = -x+y-z;
        Xyz[i] = x-y-z;
        xyz[i] = -x-y-z;
    }
    sort(xyz,xyz+n,greater<ll>());
    sort(Xyz,Xyz+n,greater<ll>());
    sort(xYz,xYz+n,greater<ll>());
    sort(xyZ,xyZ+n,greater<ll>());
    sort(XYz,XYz+n,greater<ll>());
    sort(xYZ,xYZ+n,greater<ll>());
    sort(XyZ,XyZ+n,greater<ll>());
    sort(XYZ,XYZ+n,greater<ll>());

    ll a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0;
    REP(i,m){
        a += xyz[i];
        b+= Xyz[i];
       c += xYz[i];
       d += xyZ[i];
       e += XYz[i];
       f += xYZ[i];
     g   += XyZ[i];
       h += XYZ[i];
    }
    ll ans = max({a,b,c,d,e,f,g,h});
    cout << ans;
    
}


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

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

using namespace std;

int main(){
  ll n,result=0;cin>>n;
  int f=0;
  while(n>0){
    if(n>9){
      result+=9;

      if(n%10==9 && !f) f=0;
      else f=1;

    }else{
      result+=(n-f);
    }

//cout<<n<<' '<<result<<endl;

    n/=10;
  }

  cout<<result;

  return 0;
}

Measured memory_bytes: 256