akhauriyash/Code-Regression huggingface dataset:
mod = 1000000007

S = input()
L = len(S)
i = L-1
A = [0 for _ in range(L+1)]
C = [0 for _ in range(L+1)]
Q = [0 for _ in range(L+1)]
while i >= 0:
    Q[i] = Q[i+1]
    A[i] = A[i+1]
    C[i] = C[i+1]

    if S[i] == '?':
        Q[i] = Q[i+1] + 1
    else:
        Q[i] = Q[i+1]

    if S[i] == 'A':
        A[i] = A[i+1] + 1
    else:
        A[i] = A[i+1]
    if S[i] == 'C':
        C[i] = C[i+1] + 1
    else:
        C[i] = C[i+1]
    i -= 1

ans = 0
for i in range(L):
    if S[i] in ('B','?'):
        a = A[0] - A[i]
        qleft = Q[0] - Q[i]
        c = C[i+1]
        qright = Q[i+1]
        if qleft > 0:
            LEFT = a*pow(3,qleft,mod) + qleft*pow(3,qleft-1,mod)
        else: 
            LEFT = a*pow(3,qleft,mod)
        if qright > 0:
            RIGHT = c*pow(3,qright,mod) + qright*pow(3,qright-1,mod)
        else:
            RIGHT = c*pow(3,qright,mod)
        number = (LEFT * RIGHT)%mod
        ans = (ans + number)%mod
print(ans)



Measured memory_bytes: 8724
n,m,c = map(int,input().split())
b_li = list(map(int, input().split()))
a_li = [list(map(int,input().split())) for _ in range(n)]
count = 0
for each in a_li:
    su = c
    for a,b in zip(each,b_li):
        su += a*b
    if su > 0:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

int n;
int digit(int x)
{
    int res = 0;
    while (x > 0)
    {
        res++;
        x /= 10;
    }
    return res;
}
int calc(int x)
{
    while (x >= 10)
        x /= 10;
    return x;
}

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

    cin >> n;
    int cnt[10][10] = {};
    for (int i = 1; i <= n; i++)
    {
        int tail = i % 10;
        int head = calc(i);
        cnt[head][tail]++;
    }
    int ans = 0;
    rep(i, 10) rep(j, 10) ans += cnt[i][j] * cnt[j][i];
    cout << ans << endl;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define ll long long int 
#define pb push_back
#define mp make_pair
#define ff first
#define se second
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,i,sum=0,k,mx=1000000000,x;
	cin>>n>>k;
	ll a[n];
	for(i=0;i<n;i++){
	    cin>>a[i];
	}
	sort(a,a+n);
	for(i=0;i<n-k+1;i++){
	    x=a[i+k-1]-a[i];
	 //   cout<<a[i+k-1]<<" "<<a[i]<<endl;
	    mx=min(mx,x);
	}
	cout<<mx;
}

Measured memory_bytes: 1024
<?php

fscanf(STDIN, "%d %d", $n, $m);
$A = [];
for ($i = 0; $i < $m; ++$i) {
    fscanf(STDIN, "%d", $a); 
    $A[] = $a;
}
const MOD = 1000000007;

$broken = array_fill(0, $n, false);
for ($i = 0; $i < $m; ++$i) {
    $broken[$A[$i]] = true;
}

$dp = array_fill(0, $n + 2, 0);
$dp[$n] = 1;
for ($i = $n - 1; $i >= 0; --$i) {
    if ($broken[$i]) continue;
    $dp[$i] = ($dp[$i + 1] + $dp[$i + 2]) % MOD;
}

echo $dp[0] % MOD;


Measured memory_bytes: 16884
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

	int i, j, n, m[11][11];

	while(cin >> n) {
		if(n==0)
			break;
		for(i=0; i<n+1; i++) {
			for(j=0; j<n+1; j++) {
				m[i][j]=0;
			}
		}
		for(i=0; i<n; i++) {
			for(j=0; j<n; j++) {
				cin >> m[i][j];
				m[i][n]+=m[i][j];
				m[n][j]+=m[i][j];
				m[n][n]+=m[i][j];
			}
		}
		for(i=0; i<n+1; i++) {
			for(j=0; j<n+1; j++) {
				printf("%5d", m[i][j]);
				if(j==n)
				 cout << endl;
			}
		}

	}

	return 0;

}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

//const ll INF=(ll)1e18;
const int INF=(1<<21);

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

  vector<pair<int, int>> e[n];

  int used[n][n];
  REP(i,n)REP(j,n)used[i][j]=0;

  REP(i,m){
    int a,b,c;
    cin >> a >> b >> c;
    a--; b--;
    e[a].push_back(make_pair(b,c));
    e[b].push_back(make_pair(a,c));
    used[a][b]=1;
    used[b][a]=1;
  }
    // REP(i,n){
    //   REP(j,n){
    //     cout << used[i][j] << " ";
    //   }
    //   cout << endl;
    // }


  REP(s,n){
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int,int>>> pq;
  
    int d[n];
    int p[n];
    bool visited[n];

    REP(i,n)d[i]=INF;
    REP(i,n)visited[i]=false;

    d[s]=0;
    p[s]=-1;
    visited[s]=true;


    pq.push(make_pair(0,s));

    int prev=s;
    while(!pq.empty()){
      int c=pq.top().first;
      int u=pq.top().second;
      pq.pop();

      visited[u] = true;
      if(d[u] < c)continue;

      REP(i,e[u].size()){
        int v = e[u][i].first;
        if(visited[v])continue;

        if(d[u] + e[u][i].second < d[v]){
          d[v] = d[u] + e[u][i].second;
          pq.push(make_pair(d[v], v));
          p[v] = u;
        }
      }
    }
    // cout << "d ";
    // REP(i,n){
    //   cout << d[i] << " ";
    // }
    // cout << endl;

    // REP(i,n){
    //   cout << p[i] << " - ";
    // }
    // cout << endl;

    REP(i,n){
      if(i==s)continue;
      used[p[i]][i]=0;
      used[i][p[i]]=0;
    }
  }

  int ans=0;
  REP(i,n){
    REP(j,n){
      ans += used[i][j];
    }
  }
  cout << ans / 2 << endl;
}



Measured memory_bytes: 384
n,m=map(int,input().split())
a=[str(input()) for _ in range(n)]
b=[str(input()) for _ in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        tmp=[]
        for k in range(m):
            tmp.append(a[j+k][i:i+m])
        if tmp==b:
            print("Yes")
            exit()
print("No")

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

int main(){
  string S;
  cin >> S;
  if(S=="AAA" or S=="BBB") cout << "No";
  else cout << "Yes";
}

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

int main()
{
    int i, N, K;
    int S = 1;

    cin >> N >> K;

    for (i = 0; i < N; i++)
    {
        if (2 * S - S < K)
        {
            S = 2 * S;
        }
        else
        {
            S = S + K;
        }
    }

    cout << S << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){ 
  ll N,K; cin >> N >> K; ll sum = 0;
  vector<ll> A(N); for(ll i = 0; i < N; i++){ cin >> A[i]; sum += A[i];}
  
  //考えられるのは、sumの約数しかありえない
  
  set<ll> s;
  ll ans = 1LL; //ans　は　答えとなりうるsの要素に過ぎない
  for(ll i = 1; i*i <= sum; i++){
    if( sum % i == 0){ s.insert(i); s.insert(sum/i);}
  }
  //sにsum の約数列挙
  
  for(auto ne : s){
    ll cnt = 1LL << 60;
    //caliculate cnt in this part
    vector<ll> r(N);
      for(ll i = 0; i < N; i++){ r[i] = A[i]%ne;}
    sort(r.begin(),r.end());
    ll rsum = 0;
    for(ll i = 0; i < N; i++){ rsum += ne-r[i];}
    ll lsum = 0;
    for(ll j = 0; j < N; j++){
      lsum += r[j]; rsum -= ne - r[j]; 
     
      if( lsum != rsum){ continue;}
     cnt = min(max(lsum,rsum), cnt); }
      
    
    if(cnt <= K){ ans = max(ans, ne);}
  }
  
  cout << ans << endl; return 0;}
    
  
  

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        
        if(a + b >= 10){
            System.out.println("error");
        }else{
            System.out.println(a + b);
        }
    }
}


Measured memory_bytes: 21712
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func strSprit(str string) []string {
	cols := strings.Split(str, " ")
	return cols
}

func parseInt(str string) int {
	n, _ := strconv.Atoi(str)
	return n
}

func intSprit(str string) []int {
	strs := strSprit(str)
	cols := make([]int, len(strs))
	for i, v := range strs {
		cols[i] = parseInt(v)
	}
	return cols
}

func bitCount(n uint) int {

	x := uint64(n)

	const m = 1<<64 - 1
	const m0 = 0x5555555555555555
	const m1 = 0x3333333333333333
	const m2 = 0x0f0f0f0f0f0f0f0f

	x = x>>1&(m0&m) + x&(m0&m)
	x = x>>2&(m1&m) + x&(m1&m)
	x = (x>>4 + x) & (m2 & m)
	x += x >> 8
	x += x >> 16
	x += x >> 32

	return int(x) & (1<<7 - 1)
}

func bitExist(n, i int) bool {
	return ((n >> uint(i)) & 1) == 1
}

func setBit(d, n int) int {
	t := 1 << uint(n)
	return d | t
}

func intAbs(n int) int {
	return int(math.Abs(float64(n)))
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
	line := readBigLine()
	N := parseInt(line)

	a := intSprit(readBigLine())

	d := make([]int, N)

	for i := 0; i < N; i++ {
		d[i] = a[i] - (i + 1)
	}

	sort.Ints(d)

	midi := len(d) / 2

	mid := 0

	if len(d)%2 == 0 {
		mid = (d[midi-1] + d[midi]) / 2
	} else {
		mid = d[midi]
	}

	res := 0
	for i := 0; i < N; i++ {
		res += intAbs(d[i] - mid)
	}
	fmt.Println(res)
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

int main() {
    int S, W;
    cin >> S >> W;
    
    if(W >= S) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

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

using namespace std;

int main(){
    unsigned long long n,atl=2,ans=0;
    
    cin >> n;

    for(unsigned long long i=0;i<n;i++){
        unsigned long long t;
        cin >> t;
        if(i==0){
            ans=t-1;
        }else if(atl==t){
            atl++;
        }else if(atl<t){
            ans+=(t/atl);
            if(t%atl==0){
                ans--;
            }
        }
    }
    cout << ans << endl;
}

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


def main():
    N, D = map(int, input().split())
    XY = [list(map(int, input().split())) for _ in range(N)]
    ans = 0

    for x, y in XY:
        d = (x**2 + y**2)**(1 / 2)
        if d <= D:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 45844
#include<bits/stdc++.h>
using namespace std;
const int maxn=1001000;
const long long md=1e9+7;
long long fac[maxn],inv[maxn];
long long powd(long long x,long long y){
	long long res=1;
	while(y){
		if(y&1) res=res*x%md;
		x=x*x%md;
		y>>=1;
	}
	return res;
}
long long f[maxn];
long long C(int x,int y){
	return fac[x]*inv[y]%md*inv[x-y]%md;
}
long long multiC(int x,int y){
	return C(x+y-1,y);
}
int main(){
	int n;
	scanf("%d",&n);
	n--;
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%md;
	inv[n]=powd(fac[n],md-2);
	for(int i=n;i>=1;i--)
		inv[i-1]=inv[i]*i%md;
	for(int i=1;i<=n;i++){
		if(n-i+1>i) continue;
		f[i]=multiC(n-i+1,i-(n-i+1));
	}
	long long ans=0;
	for(int i=0;i<=n;i++)
		ans=(ans+(C(n,i)-f[i]+md)*fac[i]%md*fac[n-i])%md;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 21632
#!/usr/bin/env python3
from itertools import accumulate

n, m, v, p = map(int, input().split())
a = sorted(map(int, input().split()))
cs = [0] + list(accumulate(a))
ans = p
rv = n - v
rp = n - p
for i in range(rp):
    if a[i] + m < a[rp]:
        continue
    l = rp - i
    if (cs[rp + 1] - cs[i + 1]) + (l - rv) * m <= (a[i] + m) * l:
        ans += 1
print(ans)


Measured memory_bytes: 14964
#include <iostream>
#include <queue>
using namespace std;
const int MAX_V=10000;
typedef pair<int,int> P;
vector<P> G[MAX_V];
bool f[MAX_V];
int v;
int prim(){
  int r=0;
  priority_queue<P,vector<P>,greater<P> > q;
  q.push(P(0,0));
  fill(f,f+v,0);
  for(;!q.empty();){
    P p=q.top();q.pop();
    int b=p.second,d=p.first;
    if(f[b]) continue;
    f[b]=1;
    r+=d;
    for(int i=0;i<(int)G[b].size();i++) q.push(G[b][i]);
  }
  return r;
}
int main(){
  int e;
  cin>>v>>e;
  for(int i=0,a,b,c;i<e&&cin>>a>>b>>c;i++) G[a].push_back(P(c,b)),G[b].push_back(P(c,a));
  cout<<prim()<<endl;
  return 0;
}

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

ans = [0]*N
for x in range(1,10**2+1):
    for y in range(1,10**2+1):
        for z in range(1,10**2+1):
            p = x**2+y**2+z**2+x*y+y*z+z*x-1
            if p < N:
                ans[p] += 1

[print(i) for i in ans]


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

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;

int main()
{
	int h, w;
	cin >> h >> w;

	vector<string> grid(h);

	for(auto &s: grid)
		cin >> s;

	vector<vector<ll>> dp(h, vector<ll>(w));

	dp[0][0] = 1;

	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
		{
			if(grid[i][j] == '#')
				continue;

			if(i > 0)
				dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
			if(j > 0)
				dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
		}
	}

	cout << dp[h - 1][w - 1] << endl;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double db;
typedef vector<ll> VI;
typedef vector<pair<ll,ll> > VII;
typedef map<ll,ll> mll;
typedef pair<ll,ll> pll;
//
#define M 1000000007
#define INF (ll)0x3f3f3f3f3f3f3f3f
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define itr iterator
#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
void fileioe(){
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout); 
	freopen("error.txt","w",stderr);
}

void error_out() { cerr << endl; }
template <typename Head, typename... Tail>
void error_out(Head H, Tail... T) {
  cerr << " " << H;
  error_out(T...);
}
void time_elapsed(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}
#ifndef ONLINE_JUDGE
#define error(...) cerr << "[" << #__VA_ARGS__ << "]:", error_out(__VA_ARGS__)
#define fioe() fileioe()
#define time() time_elapsed()
#else
#define error(...) 1
#define fioe() 1
#define time() 1
#endif


//
int main()
{
	GO
	//fioe();
	ll n;
	cin>>n;
	ll arr[n+2][3];
	for(ll i=0;i<n;i++){
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	}
	ll dp[n+2][3];
	memset(dp,0,sizeof(dp));
	dp[1][0]=arr[0][0];
	dp[1][1]=arr[0][1];
	dp[1][2]=arr[0][2];
	for(ll i=2;i<=n;i++){
		for(ll j=0;j<3;j++){
			for(ll k=0;k<3;k++){
				if(k==j){
					continue;
				}
				dp[i][j]=max(dp[i][j],dp[i-1][k]);
			}
			dp[i][j]+=arr[i-1][j];
		}
	}
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
	time();
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  set<int> Set[26];
  for (int i = 0; i < N; i++) {
    Set[S[i] - 'a'].insert(i);
  }

  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int mode;
    cin >> mode;
    if (mode == 1) {
      int k;
      char c;
      cin >> k >> c;
      k--;
      Set[S[k] - 'a'].erase(k);
      S[k] = c;
      Set[S[k] - 'a'].insert(k);
    } else {
      int l,r;
      cin >> l >> r;
      l--;
      r--;
      int res = 0;
      for (int i = 0; i < 26; i++) {
        auto itr1 = Set[i].lower_bound(l);
        auto itr2 = Set[i].lower_bound(r+1);
        if (itr1 != itr2) res++;
      }
      cout << res << endl;
    }
  }
  return 0;
}

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

int main(){
  int n,a[7]={64,32,16,8,4,2,1};
  cin>>n;
  for(int i=0;i<7;i++){
    for(int j=1;j<=n;j++){
      if(a[i]==j){ cout<<a[i]; return 0; }
    }
  }

}


Measured memory_bytes: 256
#include<stdio.h>


int main(void){ 


  long a,b;


  while(scanf("%ld %ld",&a,&b) != EOF)
  {


    printf("%ld\n",a/b);


    printf("%ld\n",a%b);


    printf("%.5lf\n",((double)a/(double)b));


  }


  return 0;


}


  

Measured memory_bytes: 636
#include <iostream>
#include<list>
#include <algorithm>
typedef long long int ll;

using namespace std;

int main()
{
    list <ll>p;
    list<ll>::iterator point=p.end();
     list<ll>::iterator point2=p.end();
    int N;
    cin >> N;
    while (N--)
    {
        int opr;
        cin >> opr;
        switch (opr)
        {
        case 0:
            int num;
            cin >> num;
            p.insert(point, num);
            point--;
            break;
        case 1:
            int step;
            cin >> step;
          if(step>=0)
            for(int i=0;i<step;i++)point++;
          else
            for(int i=0;i<-step;i++)point--;
            break;
        case 2:
            point2=point;
            point2++;
            p.erase(point);
            point=point2;
            break;
        default:break;
        }
    }
    for (point = p.begin();point != p.end();point++)
        cout << *point << endl;
}



Measured memory_bytes: 18556
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  int n, c = 0;
  cin >> n;

  string s[n], si, x;
  int t[n], ti;
  REP(i, n) cin >> s[i] >> t[i];
  cin >> x;

  bool f = false;
  REP(i, n) {
    if (s[i] == x) {
      f = true;
      continue;
    }
    if (!f) continue;
    c += t[i];
  }

  cout << c << endl;
  return 0;
}

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

int main(){
    int x[3];
    cin >> x[0] >> x[1] >> x[2];
    sort(x,x+3);
    if(x[0] == x[1] && x[1] != x[2]){
        cout << "Yes" << endl;
    }else if(x[0] != x[1] && x[1] == x[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (ll r = (aa)-1; r >= (bb); r--)
#define be(x) (x.begin(), x.end())
#define pb(t) push_back(t)
#define ll long long
#define mp(a, b) make_pair(a, b)
ll MOD=1000*1000*1000+7, n, m;
vector<ll>fib(100005, 1);
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, m;
	cin>>n>>m;
	if(m==n)cout<<"Yes\n";
	else cout<<"No\n";
}


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

int main(){
  int k,s;
  cin >> k >> s;
  int z=0;
  int count=0;
  for(int x=0;x<=k;x++){
  	for(int y=0;y<=k;y++){
      z=s-x-y;
      if(z<=k & z>=0)count++;
    }
  }
  cout << count;
  return 0;
}

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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    int n;
    cin >> n;
    ll ans = inf;
    vector <int> a(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for (ll i = 1; i <= 100; i++) {
        ll cnt = 0;
        for (int j = 0; j < n; j++) {
            cnt += abs(a[j]-i)*abs(a[j]-i);
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}



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

const int N = 3005, M = 6005;

int n, na, nb, a[N], b[N], wh[M];
char s[M];
std::string f[N];

int main()
{
	std::cin >> n;
	scanf("%s", s + 1);
	for (int i = 1; i <= n * 2; i++)
		if (s[i] == 'a') a[wh[i] = ++na] = i; else b[wh[i] = ++nb] = i;
	for (int i = n; i >= 1; i--)
	{
		if (a[i] < b[i])
		{
			int j = i;
			while (j <= n && (a[j] <= b[i] || b[j] <= b[i])) j++;
			f[i].push_back('a'); f[i].push_back('b'); f[i] = f[i] + f[j];
		}
		else
		{
			int mx = a[i], k = n + 1;
			for (int j = b[i]; j <= mx; j++)
				if (s[j] == 'b' && a[wh[j]] > mx) mx = a[wh[j]];
			for (int j = 1; j <= n; j++) if (a[j] > mx && b[j] > mx && j < k)
				k = j;
			for (int j = b[i]; j <= mx; j++) if (wh[j] >= i) f[i].push_back(s[j]);
			f[i] = f[i] + f[k];
		}
		if (f[i + 1] > f[i]) f[i] = f[i + 1];
	}
	return std::cout << f[1] << std::endl, 0;
}

Measured memory_bytes: 12924
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi; 

vector<int>dx={0,1,0,-1},dy={1,0,-1,0};
const int N=60,inf=1e18;
int a[N],B[N],S[N];
int G[N][N];

int32_t main()
{
	IOS
	int n,m;cin>>n>>m;
	int mn=1,mx=n;
	for(int i=1;i<=m;i++)
	{
		int l,r;cin>>l>>r;
		mn=max(mn,l);
		mx=min(mx,r);
	}
	cout<<max(mx-mn+1,0LL)<<endl;
	

}


Measured memory_bytes: 256
#include<stdio.h>

int f(int a){if(a<0)return -a;return a;}
	

int main(void){
	int i,n,x[100000],y[100000],t[100000];
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d %d %d",&t[i],&x[i],&y[i]);
	if((t[0]-x[0]-y[0])%2!=0||t[0]<x[0]+y[0]){printf("No\n");return 0;}
	for(i=1;i<n;i++)
		if((t[i]-t[i-1]-f(x[i]-x[i-1])-f(y[i]-y[i-1]))%2!=0||t[i]-t[i-1]<f(x[i]-x[i-1])+f(y[i]-y[i-1])){printf("No\n");return 0;}
	printf("Yes\n");
}

Measured memory_bytes: 1280
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main(){
  double x1,y1,x2,y2,d;
  cin >> x1 >> y1 >> x2 >> y2;
  d = sqrt(pow(x1-x2, 2) + pow(y1-y2, 2));
  cout << fixed;
  cout << std::setprecision(5) << d << endl;
  return 0;
}



Measured memory_bytes: 3244
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy

def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("GREATER")
    elif (x<y): print("LESS")
    else: print("EQUAL")

def ip():
    return int(input())


n = ip()                              #入力整数1つ
#n,m= (int(i) for i in input().split())      #入力整数横2つ
#a,b,c = (int(i) for i in input().split())    #入力整数横3つ
#n,a,b,c= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(h)]
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
m = ip()
ct(n,m)


Measured memory_bytes: 22164
#include<bits/stdc++.h>
#include<algorithm>
#include<iostream>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(ll)n;++i)
using P = pair<ll,ll>;

ll n,m,q;
vector<ll> a,b,c,d;
ll ans = -1;

void dfs( int s, int now, vector<int> v ){
	if( now == n+1 ){
		ll cnt = 0;
		rep(i,q){
			if( v.at(b.at(i)) - v.at(a.at(i)) == c.at(i) ){
				cnt += d.at(i);
			}
		}
		ans = max(ans,cnt);
		return;
	}
	for(int i=s;i<=m;++i){
		vector<int> tmp = v;
		tmp.emplace_back(i);
		dfs(i,now+1,tmp);
	}
}

int main(){
	cin >> n >> m >> q;
	a.resize(q,0);
	b.resize(q,0);
	c.resize(q,0);
	d.resize(q,0);
	rep(i,q){
		cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
		a.at(i)--;
		b.at(i)--;
	}
	vector<int> v = {};
	dfs(1,1,v);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define putchar putchar_unlocked
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
inline void putint(ll X) {
	int keta = 0;
	char C[20];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--) putchar(*(C + i));
	putchar('\n');
}

int N;
ll D[100001];
vector<pair<int, int>> E[100001];
void dfs(int A, ll B) {
	D[A] = B;
	for (auto p : E[A]) if (!(*(D + p.first))) dfs(p.first, B + p.second);
}

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


	int N = getint();
	rep(i, N - 1) {
		int a = getint();
		int b = getint();
		int c = getint();
		(*(E + a)).pb(mp(b, c));
		(*(E + b)).pb(mp(a, c));
	}
	int Q = getint();
	int K = getint();
	dfs(K, 1);
	rep(i, Q) {
		int x = getint();
		int y = getint();
		putint(*(D + x) + *(D + y) - 2);
	}

	Would you please return 0;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
using namespace std;

using ll = long long;
using boost::irange;

int main(){
    int N;

    cin >> N;

    vector<queue<int>> A(N);

    int tmp;
    queue<int> q;
    vector<int> nxt(N);
    vector<int> day(N, 0);

    for(int i : irange(0, N)){
        for(int j : irange(0,N-1)){
            cin >> tmp;
            A[i].push(tmp - 1);
        }
        A[i].push(-1);
        q.push(i);
        nxt[i] = A[i].front();
        A[i].pop();
    }

    int j;
    while(!q.empty()){
        int a = q.front(); q.pop();
        if(nxt[a] == -1) continue;
        int b = nxt[a];
        if(nxt[b] == -1) continue;

        if(nxt[b] == a){ 
            q.push(a);
            q.push(b);

            int d = max({day[a], day[b]}) + 1;
            day[a] = d;
            day[b] = d;

            nxt[a] = A[a].front(); A[a].pop();
            nxt[b] = A[b].front(); A[b].pop();
        }
    }

    for (auto &a : A){
        if(a.empty() == false){
            cout << "-1" << endl;
            return 0;
        }
    }

    cout << *max_element(day.begin(), day.end()) << endl;
    return 0;


}

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

int main(){
    int n;
    cin>>n;
    int A[3][101];
    for(int i = 1; i <= 2; ++i){
        for(int j = 1; j <= n; ++j){
            cin>>A[i][j];
        }
    }
    
    int dp[3][101] = {};
    for(int i = 1; i <= 2; ++i){
        for(int j = 1; j <= n; ++j){
            dp[i][j] = max(dp[i-1][j],dp[i][j-1]) + A[i][j];
        }
    }
    
    cout << dp[2][n]<< endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <typeinfo>
#include <math.h>
#include <iomanip>
#include <limits>

using namespace std;
using ll = long long;
const ll res = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
	int k, a, b, ans=0;
	cin >> k >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i%k == 0)
			ans = 1;
	}
	if (ans == 1)
		cout << "OK" << endl;
	else
		cout << "NG" << endl;

}

Measured memory_bytes: 3636
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scan.nextInt();
        }
        Arrays.sort(a);
        System.out.println(a[n - 1] - a[0]);
    }
}

Measured memory_bytes: 21204
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  ll N;
  while (cin >> N) {
    ll res = 1ll << 60;
    for (ll x = 1; x * x <= N; x++) {
      if (N % x != 0) continue;
      ll y = N / x;
      chmin(res, x + y - 2);
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String inputStr[] = scanner.nextLine().split(" ");
        int a = Integer.valueOf(inputStr[0]);
        int b = Integer.valueOf(inputStr[1]);
        int c = Integer.valueOf(inputStr[2]);
        int ans = c - (a - b);
        System.out.println(ans < 0? 0: ans);
    }
}

Measured memory_bytes: 23764
stack = []

for x in input().split():
    if x == '+':
        stack.append(stack.pop()+stack.pop())
    elif x == '-':
        stack.append(-stack.pop()+stack.pop())
    elif x == '*':
        stack.append(stack.pop()*stack.pop())
    else:
        stack.append(int(x))

print(stack[0])


Measured memory_bytes: 5600
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
using namespace std;

int main(){
    int x,a,b;
    cin >> x >> a >> b;
    x-=a;
    cout << x%b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define v(i) vector<i>
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORE(i,a,b) for(i=a;i<=b;i++)
#define FORV(i,a,b) for(i=a;i>b;i--)
#define FOREV(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define look(v) for(auto c:v) cout<<c<<" "; cout<<"\n";
#define dfdc int i,j,k,m,n,ct=0;string s;
#define ppl(a,st,end) for(i=st;i<=end;i++)cin>>a[i];
#define fz(a) memset(a,0,sizeof a);
#define dp_1(n) int dp[n];fz(dp);
#define dp_2(m,n) int dp[m][n];fz(dp);
#define arpt(a,s,e) for(i=s;i<=e;i++) cout<<a[i]<<" ";cout<<"\n";
#define tk int t;cin>>t;while(t--)
 
using namespace std;
 
typedef long long int ll;
 
 
int main(){
    fastio
    dfdc
    cin>>n;
    v(long long int) a(n);
    ppl(a,0,n-1);
    long long int ans = 0;
    for(int i=1;i<n;i++){
    	ans += max(a[i-1]-a[i],0ll);
    	a[i] = max(a[i],a[i-1]);
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 4764
import java.util.Scanner;
class Main{
    public static void main(String arg[]){
        Scanner scn=new Scanner(System.in);
        int n= scn.nextInt();
        String s = String.valueOf(n);
        int s_n=0;
        for(int i=0;i<s.length();i++){
            int num=Character.getNumericValue(s.charAt(i));
            s_n+=num;
        }
        if(n%s_n==0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23124
#include <stdio.h>

int main()
{
  char n[3];
  int i = 0;
  
  scanf("%s",n);
  
  if (n[0] == '7')
    i++;
  
  if (n[1] == '7')
    i++;
  
  if (n[2] == '7')
    i++;
  
  if (i > 0)
    printf("Yes");
  
  else
    printf("No");
  
  return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

long double n, q;
long double t[100000], a[100000], l[100000], r[100000];
map<long double, long double> mp;
vector<long double> vec;

signed main() {
	cin >> n;
	long double d = 1.0;
	for (int i = 0; i < n; i++) {
		cin >> t[i] >> a[i];
		vec.push_back(t[i]);
		mp[t[i]] = d;
		d = d * (10.0 - a[i]) / 10.0;
	}
	vec.push_back(1000000001.0);
	mp[1000000001.0] = d;
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> l[i] >> r[i];
		long double e = *upper_bound(all(vec), l[i]);
		long double f = *upper_bound(all(vec), r[i]);
		cout << printf("%.20Lf", 1000000000 * mp[f] / mp[e]);
	}
}


Measured memory_bytes: 18804
#include "bits/stdc++.h"
using namespace std;
#define fastcin {\
    cin.tie(0);\
    ios::sync_with_stdio(false);\
}
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = a; i >= b; i--)
#define fore(i, a) for(auto &i:a)
#define print(x) cout << x << "\n"
#define SORT(a, n) sort(a, a+n);
#define REVERSE(a,n) reverse(a,a+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VREVERSE(v) reverse(v.begin(), v.end());
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
const ll mod = 1000000007;
const int inf = 1e9+7;
const ll infl = 1e18+7;

int main() {
    fastcin;
    int n, m, a, b;
    cin >> n >> m;
    vector<pair<int, int> > req;
    rep(i, 0, m) {
        cin >> a >> b;
        req.push_back(make_pair(a, b));
    }
    VSORT(req);
    int ans = 1, c, d;
    a = req[0].first;
    b = req[0].second;
    rep(i, 1, m) {
        c = req[i].first;
        d = req[i].second;
        if(b<=c) {
            a = c;
            b = d;
            ans++;
        } else {
            if(a>c) a = c;
            if(d<b) b = d;
        }
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h> 
#define N 200005

using namespace std;

const int Mod=1e9+7; 
int n,w,a[N],dp[205][N];

int main(){
    scanf("%d%d",&n,&w);
    for (int i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);reverse(a+1,a+n+1);
    dp[0][w]=1;
    for (int i=0;i<n;i++){
        for (int j=0;j<=w;j++){
            dp[i+1][j%a[i+1]]=(dp[i+1][j%a[i+1]]+dp[i][j])%Mod;
            dp[i+1][j]=(dp[i+1][j]+1ll*dp[i][j]*(n-i-1)%Mod)%Mod;
        }
    }
    int ans=0;
    for (int i=0;i<a[n]&&i<=w;i++) ans=(ans+1ll*dp[n][i]*i%Mod)%Mod;
    printf("%d\n",ans);
    return 0;
}
//uoj

Measured memory_bytes: 156672
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        exec();
    }

    static void exec() {
        PrintWriter out = new PrintWriter(System.out);
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());

        out.println(c-(a-b) > 0 ? c-(a-b) : 0);

        out.flush();

    }

}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << endl
#define LINE cout << "line : " << __LINE__ << endl
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl
#define STOP assert(false)
#else
#define dump(x) ;
#define LINE 	;
#define dumpV(v);
#define STOP 	;
#endif
#define mp make_pair

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


const int MAX_N = 1e5+10;
int d[MAX_N][32];

int main(){
	int n;
	cin >> n;
	vi x(n);
	rep(i, n) cin >> x[i];

	ll l;
	cin >> l;

	rep(i, n) {
		auto it = upper_bound(all(x), x[i]+l);
		it--;
		d[i][0] = it-x.begin();
	}

	rep(k, 30) {
		rep(i, n) d[i][k+1] = d[d[i][k]][k];
	}

	#ifdef DEBUG_MODE
	//DEBUG_2D
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 30; j++) printf("%3d",d[i][j]);
		printf("\n");
	}
	#endif

	int q;
	cin >> q;
	rep(i, q) {
		int a, b;
		cin >> a >> b;
		if(a > b) swap(a, b);
		dump(mp(a, b));
		a--; b--;
		ll day = 0;
		int now = a;
		while(1) {
			int l = 0, r = 30;
			rep(_, 30) {
				int m = (l+r)/2;
				if(d[now][m] >= b) r = m;
				else l = m;
			}
			dump(now);
			dump(mp(l, r));
			day += (1LL << l);
			now = d[now][l];
			if(now >= b) break;
		}
		cout << day << endl;
	}
	return 0;
}

Measured memory_bytes: 13696
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x) \
  int x;     \
  cin >> x;  \
  while (x--)

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

  int a, b, c, k;
  cin >> a >> b >> c >> k;

  int ans = 0;
  ans += min(a, k);
  k -= min(a, k);
  k -= min(b, k);

  ans -= min(k, c);
  cout << ans;

  return 0;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}
#define ed "\n" 

using namespace std;
//----------------------------------------------------------------------------------------------
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);

    int n,k;
    cin >> n >> k;
    vector<int> h(n, 0);
    vector<int> dp(n, INF);
    
    REP(i, n){
        cin >> h[i];
    }
    dp[0]= 0; //足場１
    REP(i,n-1){
        FOR(j,1,k+1){
            if(i+j<n){
                dp[i+j]= min(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
            }
        }
    }
    // for(auto x:dp){
    //     cerr << x << " ";
    // }cerr << endl;
    cout << dp[n-1] << ed;
    

}

Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    vll s(n);
    vll t(m);
    REP(i,n){
        cin >> s[i];
    }
    REP(i,m){
        cin >> t[i];
    }
    vvll rui(n+1,vll(m+1,0));
    vvll sum(n+1,vll(m+1,0));
    ll ans=0;
    for(int i=n-1;i>=0;i--){
        ll tmp = 0;
        for(int j=m-1;j>=0;j--){
            if(s[i]==t[j]){
                sum[i][j]=rui[i+1][j+1]+1;
            }else{
                sum[i][j]=0;
            }
            tmp+=sum[i][j];
            rui[i][j]=rui[i+1][j]+tmp;
            rui[i][j]%=mod;
            sum[i][j]%=mod;
        }
    }
    cout << (rui[0][0]+1)%mod << endl;
    return 0;
}

Measured memory_bytes: 62976
N = gets.to_i
catch :done do
  N.times do
    t, x, y = gets.split(' ').map{|n| n.to_i}
    if (t.even? && (x + y).odd?) || (t.odd? && (x + y).even?) || x + y > t
      puts 'No'
      throw :done
    end
  end
  puts 'Yes'
end

Measured memory_bytes: 1788
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    int x;
    int train[101];
    int i = 0;

    while (scanf("%d", &x) != EOF){
        if (x == 0){
            train[i];
            i--;
            printf("%d\n", train[i]);
        }
        else {
            train[i] = x;
            i++;
        }
    }
    return (0);
}

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


int main(){
  int N, M;
  cin >> N >> M;
  vector<P>A(N);
  
  rep(i,N)cin >> A[i].first >> A[i].second;
  sort(A.begin(),A.end());
  
  ll ans = 0;
  
  rep(i,N){
    //安いのが残っていればそれを買う
    while(A[i].second){
      ans += A[i].first;
      A[i].second--;
      M--;
      //目的の個数Mに達したら終了
      if(M == 0){
        cout << ans << endl;
        return 0;
      }
    }
    
    
  }
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

vvi mat;
int k;

void pr1(){
    rep(i, k) cout << i + 1 << " ";
    cout << endl;
    
    rep(i, k-1){
        cout << 1 << " ";
        rep(j, k-1) cout << mat[i][j] << " ";
        cout << endl;
    }
}

void pr2(int x){
    rep(i, k-1){
        cout << x + 2 << " ";
        int now = i;
        rep(j, k-1){
            cout << mat[j][now] << " ";
            now += x;
            now %= k-1;
        }
        cout << endl;
    }
}

void Main(){
    k = 38;
    int n = k * (k-1) + 1;
    cout << n << " " << k << endl;
    
    mat = vvi(k-1, vi(k-1));
    rep(i, k-1) rep(j, k-1) mat[i][j] = (k+1) + i * (k-1) + j;
    
    pr1();
    rep(i, k-1) pr2(i);
    
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3620
n, m = map(int,input().split())

ab = []
for i in range(n):
    ab.append(list(map(int, input().split())))
    
cd = []
for i in range(m):
    cd.append(list(map(int, input().split())))

ans = [0] * m
for i in range(n):
    a, b = ab[i][0], ab[i][1]
    dist = [0] * m
    for j in range(m):
        dist[j] = abs(a - cd[j][0]) + abs(b - cd[j][1])
    dm = min(dist)
    for j in range(m):
        if dist[j] == dm:
            print(j+1)
            break

Measured memory_bytes: 8892
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
int main(){
  int N;
  scanf("%d", &N);
  std::vector<int > A(N);
  for (int i=0; i<N; i++){
    scanf("%d", &A[i]);
  }
  long long ans = 0;
  for (int i=0; i<N; i++){
    if (i>0){
      ans += std::min(A[i-1], A[i]);
      A[i] -= std::min(A[i-1], A[i]);
    }
    ans += A[i]/2;
    A[i] = A[i]%2;
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mk make_pair
const int N=200010;
int n, m;
vector<pair<int, pair<int, int>> > v[N], v1[N];
int main(){
	int t;
	cin>>t;
	while(t--){
		scanf("%d",&n);
		int k, l, r;
		ll ans=0;
		for(int i=0; i<=n+1; ++i){
			v[i].clear();
			v1[i].clear();
		}
		multiset<pair<int, pair<int, int>>>s;
		for(int i=0; i<n; ++i){
			scanf("%d%d%d",&k,&l,&r);
			if(r>=l){
				v1[k+1].push_back(mk(-(r-l), mk(-r, -l)));
			}
			else{
				v[k].push_back(mk(-(l-r), mk(-l, -r)));
			}
		}
		for(int i=n; i>=1; --i){
			for(auto it:v[i])s.insert(it);
				if(s.size()>0){
					ans-=s.begin()->second.first;
					s.erase(s.begin());
				}
		}
		while(s.size()>0){
				ans-=s.begin()->second.second;
				s.erase(s.begin());
		}
		for(int i=1; i<=n; ++i){
			for(auto it:v1[i])s.insert(it);
				if(s.size()>0){
					ans-=s.begin()->second.first;
					s.erase(s.begin());
				}
		}
		while(s.size()>0){
				ans-=s.begin()->second.second;
				s.erase(s.begin());
		}
		for(auto it:v1[n+1])ans-=it.second.second;
		printf("%lld\n",ans);
	}
}


Measured memory_bytes: 18852
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        if (a < b) {
            System.out.println("a < b");
        }
        if (a > b) {
            System.out.println("a > b");
        }
        if (a == b) {
            System.out.println("a == b");
        }
    }
}

Measured memory_bytes: 26308