akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 200003
#define MOD 1000000007
using Graph=vector<vector<pair<int,double>>>;

int main(){
  int N;
  cin>>N;
  vector<ll> A(N),B(N);
  ll sum=0;
  int k;
  bool flag=false;
  for(int i=0;i<N;i++){
    cin>>A.at(i)>>B.at(i);
    sum+=A.at(i);
    if(A.at(i)>B.at(i)){
      if(flag){
        if(B.at(i)<B.at(k)){
          k=i;
        }
      }else{
        k=i;
        flag=true;
      }
    }
  }

  if(flag){
    cout<<sum-B.at(k)<<endl;
  }else{
    cout<<0<<endl;
  }
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<set>
#include<string>
#include<iterator>
#include<stdio.h>
#include<map>
#include<unordered_set>
#include<cmath>
#include<cstring>
#include<numeric>
#include<algorithm>
#define gap " "
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ll long long int
#define mod 1000000007
#define ISO ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
ll i, j;
ll gcd(ll a, ll b)
{
	return b ? gcd(b, a % b) : a;
}

ll binpow(ll a, ll b)
{
	ll res = 1;
	while (b > 0)
	{
		if (b & 1)
			res = (res * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return res % mod;
}
#define testcase ll t;cin>>t;while(t--)
int main()
{
	ISO;
	ll n;
	cin>>n;
	vector<ll>a(n+1,1);
	a[1]=1;
	for(i=2;i<=n;i++)
	{
			for(j=1;i*j<=n;j++)
			a[i*j]++;
	}
	ll cnt=0;
	for(i=1;i<=n;i++)
	cnt+=a[i]*i;
	cout<<cnt;
}

		

Measured memory_bytes: 81332
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define display(v) for (auto x : v) cout << x << ", "
#define dbg(x) cout << (#x) << " = " << (x) << "\n"
#define dbgp(x) cout << (#x) << " = {" << (x.first) << ", " << (x.second) << "}\n";
#define print(x) cout << (#x) << " = [ ";display(x); cout << "]\n"
#define pb push_back
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;


int main()
{
	fastio;

	ll n, a, b;
	cin >> n >> a >> b;
	cout << min(n * a, b);
	return 0;
}


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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define MAXN 11111

const int INF = 1 << 29 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int main() {
    int a ,b , c, d;
    cin >> a >> b >> c >> d ;
    if(a+b > c+d) cout << "Left" << endl ;
    else if(a+b < c+d) cout << "Right" << endl ;
    else cout <<"Balanced" << endl ;
    return 0 ;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int animal = sc.nextInt();
		int legs = sc.nextInt();
		boolean flag = true;
		if (legs > animal * 4) {
			System.out.println("No");
			return;
		} else if (legs % 2 > 0) {
			System.out.println("No");
			return;
		} else {

			for (int i = 0; i <= animal; i++) {
				if (i*4 + (animal - i) * 2 == legs ) {
					System.out.println("Yes");
					return;

				}else {
					flag = false;
				}
			}
			if(flag == false) {
				System.out.println("No");
			}
		}

	}
}


Measured memory_bytes: 35708
n=int(input())

x=[list(map(int,input().split()))for i in range(n-1)]
for i in range(n):
    time=0
    for j in range(i,n-1):
        c,s,f=x[j]
        if time==0:
            time=c+s
        else:
            if time<s:
                time=s+c
            else:
                time=(time//f+(time%f>0))*f+c
        #print(time)
    print(time)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;


int main(){
    double r;
    cin >> r;
    cout << 6.28318530717958623200*r << endl;
}


Measured memory_bytes: 3760
def gcd(a, b):
    if a%b == 0 :
        return b
    return gcd(b, a%b)
a,b,c,d=[int(_) for _ in input().split()]
nac=(a-1) - (a-1)//c
nbc=b - b//c
nad=(a-1) - (a-1)//d
nbd=b - b//d
lcm=c*d//gcd(c,d)

nacd=(a-1) - (a-1)//lcm
nbcd=b - b//lcm
print(nbc-nac + nbd-nad -nbcd+nacd)

Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <cstring>
#include <climits>
#define INF INT_MAX / 2
using namespace std;

typedef pair<double, double> P;
typedef long long ll;

int judge(vector<int> a,const int& n){
	for(int i=0;i<a.size();i++){
		if(a[i] == n)return i;
	}
	return -1;
}

int main(void) {
	int n,p;
	while(cin >> n >> p,n+p!=0){
	int i=0,ba = p;
	vector<int> a(n);
	int ret;
	while((ret=judge(a,p))== -1){
		if(ba > 0){
			a[i%n] += 1;
			ba -= 1;
		}else if(a[i%n] > 0){
			ba += a[i%n];
			a[i%n] = 0;
		}
		i++;
	}
	cout << ret << endl;
}
}

// command ctrl 上下
// command D
// command caps G → '' ""

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
int a[105][105];

int main(){
  int m,n;
  cin>>m>>n;
  char x;
  lp(i,m+1){
    if(i==0) continue;
    lp(j,n+1){
      if(j==0) continue;
      cin>>x;
      if(i==1)a[i][j]=1;
      if(x=='o'){
	a[i][j-1]=1;
	a[i][j]=1;
	a[i][j+1]=1;
      }
      if(x=='x'){
	a[i][j]=1;
	a[i-1][j-1]=1;
	a[i-1][j]=1;
	a[i-1][j+1]=1;
	a[i][j-1]=1;
	a[i][j+1]=1;
	a[i+1][j-1]=1;
	a[i+1][j]=1;
	a[i+1][j+1]=1;
      }
    }
  }
  int count=0;
  lp(i,m+1){
    if(i==0) continue;
    lp(j,n+1){
      if(j==0) continue;
      if(a[i][j]==0) count++;
    }
  }
  cout<<count<<endl;
  return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
 
int main() {
    string A; cin >> A;
   	ll n = A.size();
  	vector<ll> cnt(26);
    ll ans = 0;
 
    rep(i, A.size()) cnt.at(A.at(i)-'a')++;
 
    rep(i, 26) {
        ll x = cnt.at(i);
        ans += x*(x-1)/2;
    }
 
    cout << n*(n-1)/2 - ans + 1 << endl;
}

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

using namespace std;

int main()
{
    int n,m,f=0;
    cin>>n>>m;
    int a[n];
    fill(a,a+n,0);
    if(n==1){
            a[0]=0;
        }
        else{
            a[0]=1;
        }

    vector< pair<int,int> > v;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        v.push_back(make_pair(x,y));
        if(v[i].first==1&&v[i].second==0&&n!=1){
        f=1;
        }
    }
    sort(v.begin(),v.end());
    for(int i=0;i<m-1;i++){
        if((v[i].first==v[i+1].first&&v[i].second!=v[i+1].second)){
            f=1;
        }
    }
    for(int i=0;i<m;i++){
        a[v[i].first-1]=v[i].second;
    }

    if(f==1){
        cout<<"-1";
    }
    else{


            for(int i=0;i<n;i++){
        cout<<a[i];


    }
    }
    cout<<endl;
    return 0;

}


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

using namespace std;
typedef long long ll;
#define int ll

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

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

int N, X, Y;
vector<int> dist;

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

    cin >> N >> X >> Y;
    dist.assign(N + 10, 0);

    X--; Y--;
    for(int i = 0; i < N; ++i) {
        for(int j = i + 1; j < N; ++j) {
            int cand = j - i;
            chmin(cand, abs(X - i) + abs(Y - j) + 1);
            dist[cand]++;
        }
    }
    for(int i = 1; i < N; ++i) {
        printf("%lld\n", dist[i]);
    }

    return 0;
}



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

int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        int x = i;
        if(x % 3 == 0){
            printf(" %d", i);
            continue;
        }
        do{
            if(x % 10 == 3){
                printf(" %d", i);
                break;
            }
            x /= 10;
        }while(x);
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3208
import java.util.*;
class Main {
  static Scanner sc = new Scanner(System.in);
  
  public static void main(String[] args) {
    B();
    
    
  }
  
  private static void A(){
    int n = sc.nextInt();
    int val = sc.nextInt();
    System.out.print((n*500 >= val)?"Yes":"No");
  }
  
  private static void B(){
    int n = Integer.parseInt(sc.nextLine());
    String str = sc.nextLine();
    
    int ans = 0;
    
    for (int i = 0; i < str.length() - 2; i++){
      if (str.charAt(i) == 'A'){
        if (str.charAt(i + 1) == 'B' && str.charAt(i + 2) == 'C') ans++;
      }
      
    }
 System.out.print(ans);

  }
  
 
}



Measured memory_bytes: 23124
k=map(int,raw_input().split(" "))
vec=k[0]
col=k[1]

omatrix=[]
for i in range(vec+1):
	omatrix+=[[0]*(col+1)]

for i in range(vec):
	ipt=map(int,raw_input().split(" "))
	for j in range(col):
		omatrix[i][j]+=ipt[j]

for i in range(vec):
	omatrix[i][col]+=sum(omatrix[i])


for j in range(col+1):
	vsum=0
	for i in range(vec):
		vsum+=omatrix[i][j]
	omatrix[vec][j]+=vsum


for i in range(vec+1):
	for j in range(col+1):
		if j==col:
			print omatrix[i][j]
		else:
			print omatrix[i][j],

Measured memory_bytes: 6404
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int n,k;
string s;

int main(){
  cin>>n>>k;
  cin>>s;
  vector<P> v;

  int i=0;
  while(i<s.size()){
    int j=i;
    while(s[i]==s[j]&&j<s.size()) j++;
    v.PB(P(j-i,s[i]));
    i=j;
  }
  v.PB(P(0,0));
  rrep(i,v.size()){
    if(i)
    v[i].F=v[i-1].F;
  }
  v[0].F=0;
  rep(i,v.size()){
    if(i)
    v[i].F+=v[i-1].F;
  }
  rep(i,2*k+1){
    v.PB(P(v[v.size()-1].F,0));
  }

  int ans=0;
  rep(j,v.size()){
    if(v[j].S=='1'){
      if(j+2*k+1>v.size()) continue;
      ans=max(ans,v[j+2*k+1].F-v[j].F);
    }
    else{
      if(j+2*k>v.size()) continue;
      ans=max(ans,v[j+2*k].F-v[j].F);
    }
  }

  if(k+1>=v.size())
    ans=s.size();

  cout<<ans<<endl;
}


Measured memory_bytes: 2548
n=int(input().split()[0])
s=input().split()
l=[0 for i in range(n)]
m=[0 for i in range(n)]
M=[0 for i in range(n)]
for i in range(n):
  l[i]=int(s[i])
m[0]=l[0]
M[0]=l[-1]
for i in range(1,n):
  m[i]=min(m[i-1],l[i])
  M[i]=max(M[i-1],l[-i-1])
M.reverse()
d=[M[i]-m[i] for i in range(n)]
ma=max(d)
memo=-1
cnt=0
for i in range(n):
   if d[i]==ma and m[i]!=memo:
      cnt+=1
      memo=m[i]
print(cnt)

Measured memory_bytes: 19988
open Queue
let h, w = Scanf.scanf " %d %d" @@ fun a b -> a, b
let bc = ref 0
let sss = Array.init h @@ fun _ -> Array.init w @@ fun _ -> Scanf.scanf " %c" @@ fun c ->
  if c = '#' then incr bc; c
let q = create ()
let ds = Array.make_matrix h w @@ -1
let _ =
  push (0, 0) q; ds.(0).(0) <- 0;
  while not @@ is_empty q do
    let y0, x0 = pop q in
    let f (dy, dx) =
      let y, x = y0 + dy, x0 + dx in
      if 0 <= y && y < h && 0 <= x && x < w && ds.(y).(x) = -1 && sss.(y).(x) = '.' then
        (push (y, x) q; ds.(y).(x) <- ds.(y0).(x0) + 1) in
    List.iter f [-1, 0; 0, -1; 1, 0; 0, 1] done;
  Printf.printf "%d\n" @@ if ds.(h - 1).(w - 1) = -1 then -1 else h * w - ds.(h - 1).(w - 1) - 1 - !bc

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;i++)
const ll INF=1e15;
const ll MOD=1000000007;

int dp[81][81][13000];
int main(){
    int H,W;cin>>H>>W;
    int A[H][W],B[H][W];
    rep(i,H)rep(j,W)cin>>A[i][j];
    rep(i,H)rep(j,W)cin>>B[i][j];
    dp[0][0][6500+abs(A[0][0]-B[0][0])]=1;
    dp[0][0][6500-abs(A[0][0]-B[0][0])]=1;
    rep(i,H){
        rep(j,W){
            rep(k,13000){
                if(dp[i][j][k]==1){
                    if(i+1<H){
                        int p=abs(A[i+1][j]-B[i+1][j]);
                        dp[i+1][j][k+p]=1;
                        dp[i+1][j][k-p]=1;
                    }
                    if(j+1<W){
                        int p=abs(A[i][j+1]-B[i][j+1]);
                        dp[i][j+1][k+p]=1;
                        dp[i][j+1][k-p]=1;
                    }
                }
            }
        }
    }
    int ans=13000;
    rep(i,13000){
        int now=13000;
        if(dp[H-1][W-1][i]==1)now=abs(6500-i);
        ans=min(ans,now);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 328704
#include<bits/stdc++.h>
#define pb push_back
#define rep(a,b,c) for(int a=(int)b;a<(int)c;a++)
#define repk(a,b,c,k) for(int a=(int)b;a<(int)c;a+=(int)k)
#define comeback std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define int long long int
#define pii pair<int,int>
#define ful(a) a.begin(),a.end()
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
using namespace std;
int em(int x,int n)
{
    if(n==0)
    return 1;
    else if(n%2==0)
    return em((x%mod*x%mod)%mod,n/2);
    else
    return (x%mod*em((x%mod*x%mod)%mod,(n-1)/2))%mod;
}
signed main()
{
	comeback
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output1.txt","w",stdout);
	#endif*/
         int i,j;
         int t;
         cin>>t;
         int a[t+1];
         int dp[t+1];
         dp[1]=0;
         for(i=1;i<=t;i++)
         	cin>>a[i];
         for(i=2;i<=t;i++){
         	if(i-2>=1){
         		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
         	}
         	else
         		dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
         }
         cout<<dp[t];
     
}

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

int main()
{
	int n;
    cin >> n;
  	int cnt[n + 1];
    memset(cnt,0,sizeof(cnt));
    for(int i=1;i<=100;i++)
    {
        for(int j=1;j<=100;j++)
        {
            for(int k=1;k<=100;k++)
            {
                if(((i + j) * (i + j) + (j + k)*(j + k) + (i + k)*(i + k))/2 <= n && ((i + j) * (i + j) + (j + k)*(j + k) + (i + k)*(i + k))/2 >=1)
                cnt[((i + j) * (i + j) + (j + k)*(j + k) + (i + k)*(i + k))/2]++;
                //(i + j) * (i + j) + (j + k)*(j + k) + (i + k)*(i + k)
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        cout << cnt[i] << endl; 
    }
    
    
	return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    long L[]; L = new long[n];
    for (int i = 0; i < n; i++){
      long l = scan.nextLong();
      L[i] = l;
    }
    int ans = 0;
    for (int i = 0; i < n; i++){
      for (int j = i+1; j < n; j++){
        for (int k = j+1; k < n; k++){
          if (L[i] == L[j] || L[i] == L[k] || L[j] == L[k]){
            continue;
          }else{
            if (L[i]+L[j] > L[k] && L[i]+L[k] > L[j] && L[j]+L[k] > L[i]){
              ans++;
            }
          }
        }
      }
    }
    System.out.println(ans);
  }
}

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

int main(){
  int a,b,c,d;
  scanf("%d%d%d%d", &a, &b, &c, &d);
  if((a+b) > (c+d)){
    printf("Left\n");
  }
  else if((a+b) < (c+d)){
    printf("Right\n");
  }
  else{
    printf("Balanced\n");
  }
  return 0;
}


Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0 }, dy[] = { 0,1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑


long long a, b, k[200005], l[200005], mon;
queue<long long>ans;
set<long long>s;
int main() {
	cin >> a >> b;
	for (int i = 0; i < a; ++i) {
		cin >> k[i];
		s.insert(k[i]);
	}

	for (int i = 0; i < b; ++i) {
		cin >> l[i];
		s.insert(l[i]);
	}

	for (int i = 0; i < a; ++i) {
		while (mon < b&&l[mon] < k[i]) { ++mon; }
		if (mon == b) { break; }
		if (l[mon] == k[i]) {
			ans.push(k[i]);
			++mon;
		}
	}

	cout << ans.size() << " " << s.size() << endl;

	while (!ans.empty()) {
		cout << ans.front() << endl;
		ans.pop();
	}
	while (!s.empty()) {
		auto itr = s.begin();
		cout << *itr << endl;
		s.erase(s.begin());
	}
}



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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,m,l;
    cin >> n >> m >> l;
    vector<vector<int64>> g1(n, vector<int64>(n, LLINF));
    REP(i,m){
        int32 a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        g1[a][b] = c;
        g1[b][a] = c;
    }
    REP(k,n)REP(i,n)REP(j,n){
        g1[i][j] = min(g1[i][j], g1[i][k] + g1[k][j]);
    }
    vector<vector<int32>> g2(n, vector<int32>(n,INF));
    REP(i,n)REP(j,n){
        if(i == j)break;
        if(g1[i][j] <= l){
            g2[i][j] = 1;
            g2[j][i] = 1;
        }
    }
    REP(k,n)REP(i,n)REP(j,n){
        g2[i][j] = min(g2[i][j], g2[i][k] + g2[k][j]);
    }
    int32 q;
    cin >> q;
    REP(i,q){
        int32 s,t;
        cin >> s >> t;
        s--;t--;
        if(g2[s][t] == INF){
            cout << -1 << endl;
        }else{
            cout << g2[s][t] - 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1920
function Main(input) {
    input = input.split("\n");
    var n = parseInt(input[0], 10);
    var c = {};
    var f = {};
    var res = 0;
    for(var i = 1; i <= n; i++){
        var sortedStr = input[i].split("").sort().join("");
        c[sortedStr] = (c[sortedStr]) ? c[sortedStr] + 1 : 1;
        if(c[sortedStr] == 2){
            f[sortedStr] = 1;
        } else if(c[sortedStr] > 2) {
            f[sortedStr] += (c[sortedStr] - 1);
        }
    }
    for(key in f){
        res += f[key];
    }
	//出力
	console.log(res);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 46636
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  string s;
  cin>>s;
  cout << s.substr(0,s.size() - 8) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n";
long long M = 1e9+7;
long long power(long long a, long long p)
{
    if(p==0) return 1;
    long long ans= power(a,p/2);
    ans =(ans * ans) % M;
    if(p%2) ans = (ans*a) % M;
    return ans;
}

bool isPrime(long long n)
{
    if (n <= 1)
        return false;
    for (long long i = 2; i < n; i++)
        if (n % i == 0)
            return false;
    return true;
}
long long SieveOfEratosthenes(long long n, long long a)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (long long p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (long long i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (long long p=2; p<=n; p++)
       if (prime[p])
       {
           if(a%p==0)
           {
               return (a-p);
           }
       }
}
long long nCr(int n, int r)
{
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }
    return ans;
}
int vis[51][51];
int x[]={1,0,0,-1};
int y[]={0,1,-1,0};
void dfs_visit(long long n,long long a, long long b)
{
    vis[a][b]=1;
    for(int i=0; i<4; i++)
    {

        int p=a+x[i];
        int q=b+y[i];
        if(p>=0 && p<n && q>=0 && q<n && vis[p][q]==0)
        {
           // cout<<p<<" "<<q<<endl;
            vis[p][q]=1;
            dfs_visit(n,p,q);
        }
    }
}

int main()
{
    IOS;
    long long a,b,c,d,e,h,l,n,t,f,m,f1=0,flag=0,flag1=0,co=0,co1=0,co2=0,arr1[100001]={0},sum=0,sum1=0,ma=0,ma1=0,mi=1000000000000000001;
    long long g,co3=0,co4=0,co5=0,co6=0,co7=0,co8=0,mul=1,sum2=0,sum3=0,mu=1,mu1=1;
    long long a1,b1,a2,b2,a3,b3,a4,b4,a5,b5,b6;
    double pi=2 * acos (0.0);
    string str,str1,str2,str3,str4,str5,str6;
    char ch,ch1;
    //vector<long long>v; //vector<long long> v(n+1);
    //vector<long long>v1;
   // vector<string>vs;
   // vector<string>vs1;
    vector<char>vc;
    //map<long long,long long>mp;
    map<char,int>mp1;
    //set<long long>s;
    set<long long>s1;
    //list<char>li;
    queue<long long> q;
    //stack<long long> stk;
    //vector< pair<long long,long long> >v3;
    //map<long long,long long>::iterator it;
    //map<string,string>::iterator it;
   // vector<pair<char, pair<int,int> > > v3;
    //vector< pair<char,int > > v1;
    //int x[]={1,1,1,0,0,-1,-1,-1};
    //int y[]={0,1,-1,1,-1,1,-1,0};
    //int x[]={1,0,0,-1};
    //int y[]={0,1,-1,0};
    cin>>n;
    map<long long,long long>mp;
    for(int i=0; i<n-1; i++)
    {
        cin>>a;
        mp[a]++;
    }
    for(int i=1; i<=n; i++)
        cout<<mp[i]<<endl;
    return 0;
}


Measured memory_bytes: 16168
import os
import sys
from io import BytesIO, IOBase
# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------------------

def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
def toord(c): return ord(c)-ord('a')
def lcm(a, b): return a*b//lcm(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush


# ------------------------------
# f = open('./input.txt')
# sys.stdin = f

def main():
    n, d = RL()
    pt = [RLL() for _ in range(n)]
    res = 0
    for x, y in pt:
        if x**2+y**2<=d**2:
            res+=1
    print(res)



if __name__ == "__main__":
    main()



Measured memory_bytes: 102320
#include <sys/time.h>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
ll mod = 1000000007LL;



int main() {
	int n, k;

	cin >> n >> k;
	ll a[n];
	rep(i, n) {
		cin >> a[i];
	}
	ll imos[n + 1];
	imos[0] = 0;

	rep(i, n) {
		imos[i + 1] = imos[i] + a[i]; 
	}
	ll prev = imos[k] - imos[0];
	for (int i = k + 1; i <= n; i++) {
		//cout << "i: " << i << endl; 

		ll cur = imos[i] - imos[i - k];
		//cout << "cur: " << cur << endl; 

		if (prev < cur) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
		prev = cur;
	}

	return 0;
}


Measured memory_bytes: 6256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int   //used int to avoid mle
#define ulli unsigned long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define spl set<pll>
#define msl multiset <lli>
#define msp multiset <pll>
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define fbo find_by_order //returns iterator
#define fok order_of_key //return index
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
lli mod=1000000007;
//string s=bitset<32>(n).to_string();
typedef tree<lli,null_type,less<lli>,rb_tree_tag, // change both to lli if set is req insted of multiset
tree_order_statistics_node_update> indexed_set;
int main()
{
     ios::sync_with_stdio(0);
    cin.tie(0);
    
        lli n,r;
        cin>>n>>r;
        lli ani=0;
        while(n){
            n=n/r;
            ani++;
        }
        cout<<ani;


}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, d;
    cin >> n >> d;
    int cnt = 0;
    long long rez = 0;
    while(n--){
    	int a , b;
    	cin >> a >> b;
    	rez = pow(a,2) + pow(b,2);
    	if (sqrt(rez) <= d){
    		cnt++;
		}
	}
   cout << cnt ;
}  




Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll h,w,k;
	cin>>h>>w>>k;
	vvb vv(h,vb(w,false));
	vb vh(h,false);
	vvl ans(h,vl(w));
	ll cnt=1;
	rep(i,h)rep(j,w){
		char ch;
		cin>>ch;
		if(ch=='#'){
			vh[i]=true;
			ans[i][j]=cnt;cnt++;
			vv[i][j]=true;
		}
	}
	bool ok=false;
	rep(i,h){
		ok|=vh[i];
		if(!ok){
			continue;
		}
		else if(vh[i]){
			ll tab=0;
			rep(j,w){
				if(ans[i][j]!=0)tab=ans[i][j];
				ans[i][j]=tab;
			}
			rrep(j,w){
				if(ans[i][j]!=0)tab=ans[i][j];
				ans[i][j]=tab;
			}
		}
		else{
			rep(j,w){
				ans[i][j]=ans[i-1][j];
			}
		}
	}
	rrep(i,h){
		if(!vh[i]&&ans[i][0]==0){
			rep(j,w){
				ans[i][j]=ans[i+1][j];
			}
		}
	}
	rep(i,h){
		cout<<ans[i]<<endl;
	}
}


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

int main(void)
{
    int N;
    cin >> N;
    long long int Y;
    cin >> Y;
    
    int x = -1, y = -1, z = -1;
    
    for (int a = 0; a <= N; ++a)
    {
        for (int b = 0; b + a <= N; ++b)
        {
            int c = N - (a + b);
            int total = a*10000 + b*5000 + 1000*c;
            if ( total == Y )
            {
                x = a;
                y = b;
                z = c;
            }
        }
    }
    cout << x << " " << y << " " << z << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using ull = unsigned long long;
using ul = unsigned;
using ll = long long;
#define rep(i,a,b) for (int i =a;i<b;++i)
using namespace std;
void solve();
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin); 
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
#endif
	int t=1;
	//cin>>t;
	while(t--)
	{
	solve();
	 cout<<"\n";
	}
	
	cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	return 0;

}
int sq[1002][1002];
ll dp[1002][1002];
void solve()
{
	ll mod =1e+9+7;

	int h,w;
	cin>>h>>w;
	rep(i,1,h+1)
	{
		rep(j,1,w+1)
		{
			char ch;
			cin>>ch;
			if(ch=='.')
				sq[i][j]=0;
			else
				sq[i][j]=1;
		}
	}
	dp[1][1]=1;
	rep(i,1,h+1)
	{
		rep(j,1,w+1)
		{
			if(i==1&&j==1)
				continue;
			if(sq[i][j]==1)
			{
				dp[i][j]=0;
				continue;
			}
			int s1=0,s2=0;
			if(i>1)
			{	
				if(sq[i-1][j]==0)
					s1=dp[i-1][j];
			}
			if(j>1)
			{
				if(sq[i][j-1]==0)
					s2=dp[i][j-1];
			}
			
			dp[i][j]=(s1+s2)%mod;
		}
	}	
	cout<<dp[h][w];
/*rep(i,1,h+1)
	{
		rep(j,1,w+1)
		{
		//	cout<<dp[i][j]<<"\t";
		}
		cout<<"\n";
	}*/

}


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

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

    for(int i=n; i>=1; i--){
        if(i == 2 || i == 4 || i == 8 || i == 16 || i == 32 || i == 64){
            cout<<i<<endl;
            break;
        }

        else if(i == 1) cout<<i<<endl;
    }

    return 0;
}

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

int main(){
    int i,N,A,B,sum;
    cin >> N >> A >> B;
    int min=B;
    for(i=0;i<=N;i++){
        sum=i*A+(N-i)*B/N;
        if(min>sum){
            min=sum;
        }
    }
    cout << min <<endl;

}

Measured memory_bytes: 256
class RMaxQ:
    
    __slots__ = ["n", "data"]
    
    def __init__(self, li):
        self.n = len(li)
        self.data = li*2
        for i in range(self.n - 1, 0, -1):
            self.data[i] = max(self.data[2*i], self.data[2*i+1])
    
    def get(self, i):
        return self.data[i+self.n]
    
    def update(self, i, a):
        i += self.n
        self.data[i] = a
        while i > 1:
            i //= 2
            self.data[i] = max(self.data[2*i], self.data[2*i+1])
    
    def add(self, i, a):
        i += self.n
        self.data[i] += a
        while i > 1:
            i //= 2
            self.data[i] = max(self.data[2*i], self.data[2*i+1])
    
    def fold(self, l, r):
        l += self.n
        r += self.n
        res = 0
        while l < r:
            if l % 2:
                res = max(self.data[l], res)
                l += 1
            if r % 2:
                r -= 1
                res = max(res, self.data[r])
            l //= 2
            r //= 2
        return res
    
    def max_right(self, l, r, check):
        l += self.n
        r += self.n
        left_li = []
        right_li = []
        while l < r:
            if l % 2:
                left_li.append(l)
                l += 1
            if r % 2:
                r -= 1
                right_li.append(r)
            l //= 2
            r //= 2
        temp = 0
        for idx in (left_li + right_li[::-1]):
            if not check(max(temp, self.data[idx])):
                temp = max(temp, self.data[idx])
            else:
                break
        else:
            return -1
        while idx < self.n:
            if check(max(temp, self.data[2*idx])):
                idx = 2*idx
            else:
                temp = max(temp, self.data[2*idx])
                idx = 2*idx+1
        return idx - self.n

import sys
input = sys.stdin.readline
n, q = map(int, input().split())
A = list(map(int, input().split()))
seg = RMaxQ(A)
for _ in range(q):
    t, x, v = map(int, input().split())
    x -= 1
    if t == 1:
        seg.update(x, v)
    elif t == 2:
        print(seg.fold(x, v))
    else:
        ans = seg.max_right(x, n, lambda x: x>=v)
        if ans == -1:
            print(n+1)
        else:
            print(ans+1)

Measured memory_bytes: 94972
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }


int main(){
  char x,y;
  cin >> x >> y;
  char ans;
  if(x < y)ans = '<';
  else if(x == y)ans = '=';
  else ans = '>';
  cout << ans << endl;
}


Measured memory_bytes: 256
n,k,c=map(int, input().split())
s=list(input())
L=[]
R=[]

i=0
while i<n: # 前から貪欲に働く日を決定している。
    if s[i]=='o':
        L.append(i+1)
        i+=(c+1)
    else:
        i+=1

j=0
s2=s[::-1]
while j<n: # 後ろから貪欲に働く日を決定している。
    if s2[j]=='o':
        R.append(n-j)
        j+=(c+1)
    else:
        j+=1
R=R[::-1]        

if len(L)<=k:
    for p in range(min(len(L),len(R))):
        if L[p]==R[p]:
            print(L[p])

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

int main()
{
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;
	if (r <= x && x + r <= w) {
		cout << ((r <= y && y + r <= h)?"Yes":"No") << endl;
	} else {
		cout << "No" << endl;
	}
}

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

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() {
  int n;
  cin >> n;
  mint a = 1;
  mint b = 1;
  mint c = 1;
  if (n == 1) {
    cout << 0 << endl;
  } else if (n == 2) {
    cout << 2 << endl;
  } else {
    for (int i = 0; i < n; i++) {
      a *= 10;
      b *= 9;
      c *= 8;
    }
    b *= 2;
    cout << a - (b - c) << endl;
  }
}


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

using namespace std;

#define ll long long 
#define endl '\n'
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SIZE 100005

int main()
{
    int a;
    
    cin >> a;
    for(int i = 1; i <= 9; i++)
    {
		if(a%i==0 && a/i>=1 && a/i <= 9) {cout <<"Yes\n";return 0;}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N=200005;
int deep[N],dfn[N],ed[N],fa[N],dis[N],Time,ans;
struct Tree{
	int Head[N],Next[N<<1],Adj[N<<1],tot;
	inline void addedge(int u,int v){
		Next[++tot]=Head[u],Head[u]=tot,Adj[tot]=v;
		Next[++tot]=Head[v],Head[v]=tot,Adj[tot]=u;
	}
	inline void dfs(int x,int f){
		dfn[x]=++Time,fa[x]=f;
		for (int e=Head[x];e;e=Next[e])
			if (Adj[e]!=f){
				dis[Adj[e]]=dis[x]+1;
				dfs(Adj[e],x);
			}
		ed[x]=Time;
	}
	inline bool check(int x,int y){
		if (dfn[x]>dfn[y]) swap(x,y);
		if (dfn[y]>=dfn[x]&&dfn[y]<=ed[x]) return dis[y]-dis[x]>2;
		return fa[x]!=fa[y];
	}
	inline void dfs2(int x,int f){
		if (deep[x]>=dis[x]) return;
		ans=max(ans,dis[x]*2);
		for (int e=Head[x];e;e=Next[e])
			if (Adj[e]!=f){
				deep[Adj[e]]=deep[x]+1;
				dfs2(Adj[e],x);
				if (check(x,Adj[e])) {puts("-1");exit(0);}
			}
	}
}T1,T2;
int main(){
	int n,x,y;scanf ("%d%d%d",&n,&x,&y);
	if (x==y){puts("0");return 0;}
	for (int i=1;i<n;i++){
		int u,v;scanf ("%d%d",&u,&v);
		T1.addedge(u,v);
	}
	for (int i=1;i<n;i++){
		int u,v;scanf ("%d%d",&u,&v);
		T2.addedge(u,v);
	}
	T2.dfs(y,0);
	T1.dfs2(x,0);
	printf ("%d",ans);
	return 0;
}


Measured memory_bytes: 20480
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int L, R, X;
	cin >> L >> R >> X;
	cout << R / X - (L - 1) / X << endl;
}


Measured memory_bytes: 3544
from queue import deque
N = int(input())
A = list(map(int, input().split()))
ans = 0

A.sort(reverse=True)
q = deque()
q.append(A[0])

for i, a in enumerate(A):
    if i != 0:
        q.append(a)
        q.append(a)

for i in range(N-1):
    ans += q.popleft()

print(ans)

Measured memory_bytes: 32000
n=int(input())
ab=sorted([[int(i) for i in input().split()] for _ in range(n)],key=lambda x:x[1])
now=0
for a,b in ab:
    now+=a
    # print((a,b,now))
    if now>b:
        print("No")
        break
else:
    print("Yes" if now<=ab[-1][1] else "No")

Measured memory_bytes: 42716
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;
//26

int a[200000], sum[400000];
signed main(){
	int n, m, s = 0;
	scanf("%lld%lld", &n, &m);
	rep(i,n)scanf("%lld",&a[i]);
	rep(i,n-1){
		int l = a[i], r = a[i+1];
		if(l > r)r += m;
		if(l+2 <= r){
			sum[l+2]++;
			sum[r+1] -= (r-(l+1))+1;
			sum[r+2] += (r-(l+1));
		}
		s += r-l;
	}
	rrep(i,2*m)sum[i] += sum[i-1];
	rrep(i,2*m)sum[i] += sum[i-1];
	
	int ans = 0;
	rrep(i,m){
		chmax(ans, sum[i]+sum[i+m]);
	}
	printf("%lld\n", s-ans);
	return 0;
}





Measured memory_bytes: 3840
#include<stdio.h>
#include<stdlib.h>

int A[200001];


int cmp(const void* a, const void * b){
    return A[*(int *)b]-A[*(int *)a];
}

int main(void){
    int N = 0;
    int i = 0;
    int a[200001];

    scanf("%d", &N);
    for(i = 0; i < N; i++){
        scanf("%d", &A[i]);
        a[i] = i;
    }
    qsort(a, N, sizeof(int), cmp);

    for(i = 0; i < N-1; i++){
        if(i == a[0]){
            printf("%d\n", A[a[1]]);
        }else{
            printf("%d\n", A[a[0]]);
        }
    }
    if(N-1 == a[0]){
        printf("%d", A[a[1]]);
    }else{
        printf("%d", A[a[0]]);
    }

    return 0;    
}

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

#define fir first
#define sec second
// #define DEBUG

typedef long long LL;
typedef pair<int,int> pii;
pii g[3][3];
pii dir[9][9];
int ID[3][3];
int h, w, n;

inline bool judge(int x, int y) {
	return x<=0 || x>h || y<=0 || y>w;
}

inline bool judge(pii p) {
	return p.fir<=0 || p.fir>h || p.sec<=0 || p.sec>w;
}

void init() {
	int c = 0;

	for (int i=0; i<3; ++i) {
		for (int j=0; j<3; ++j) {
			g[i][j] = make_pair(i, j);
			ID[i][j] = c++;
		}
	}

	for (int id=0; id<9; ++id) {
		int x = id / 3;
		int y = id % 3;
		int z = 0;
		for (int i=0; i<3; ++i) {
			for (int j=0; j<3; ++j) {
				dir[id][z] = make_pair(g[i][j].fir-x, g[i][j].sec-y);
				++z;
			}
		}
	}

	// #ifdef DEBUG
	// for (int id=0; id<9; ++id) {
	// 	for (int i=0; i<9; ++i)
	// 		printf("(%d,%d) ", dir[id][i].fir, dir[id][i].sec);
	// 	putchar('\n');
	// }
	// #endif
}

int main() {
	LL c[10];
	pii p;
	init();

	scanf("%d %d %d", &h, &w, &n);
	set<pii> st;
	LL tot = 1LL * (h - 2) * (w - 2);
	for (int i=0; i<n; ++i) {
		scanf("%d %d", &p.fir, &p.sec);
		st.insert(p);
	}
	memset(c, 0, sizeof(c));

	int x, y, xx, yy, cnt;
	bool flag;

	for (auto iter=st.begin(); iter!=st.end(); ++iter) {
		x = iter->fir;
		y = iter->sec;
		for (int id=0; id<9; ++id) {
			flag = true;
			cnt = 0;
			for (int k=0; k<9; ++k) {
				p.fir = x + dir[id][k].fir;
				p.sec = y + dir[id][k].sec;
				if (judge(p.fir, p.sec)) {
					flag = false;
					break;
				}
				cnt += st.count(p)>0;

				// if (x==1 && y==1) {
				// 	printf("%d: %d %d\n", id, p.fir, p.sec);
				// }
			}
			if (flag)
				c[cnt]++;

			// #ifdef DEBUG
			// if (flag) 
			// 	printf("(%d, %d): %d = %d\n", x, y, id, cnt);
			// #endif
		}
	}

	c[0] = tot;
	for (int i=1; i<=9; ++i) {
		c[i] /= i;
		c[0] -= c[i];
	}

	for (int i=0; i<10; ++i) {
		cout << c[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<regex>
#include<string>

int main()
{
	int n;
	std::cin >> n;
	std::cin.ignore();

	while( n-- )
	{
		std::string s;
		std::getline( std::cin, s );

		std::smatch m;
		if( std::regex_match( s, m, std::regex( ">\'(=+)#(=+)~" ) ) && m[1].length() == m[2].length() )
			std::cout << 'A' << std::endl;
		else if( std::regex_match( s, std::regex( ">^(Q=)+~~" ) ) )
			std::cout << 'B' << std::endl;
		else
			std::cout << "NA" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1268
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;

#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()

ll n, k, m, M = 1e9 + 7;

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

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

    vl a(m);
    rep(i, m) cin >> a[i];

    int num = 0;
    rep(i, m) {
        if(a[i] < x) num++;
        else break;
    }

    num = min(num, m - num);
    
    cout << num << endl;
}

Measured memory_bytes: 3676