akhauriyash/Code-Regression huggingface dataset:
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from collections import deque

def main():
    h,w = map(int,input().split())
    grid = [input() for _ in range(h)]
    q = deque([])
    dist = [[-1] * w for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if grid[i][j] == '#':
                dist[i][j] = 0
                q.append((i,j))
    
    ans = 0
    while q:
        i,j = q.popleft()
        for k in range(4):
            y = i + dy[k]
            x = j + dx[k]
            if y < 0 or y >= h:
                continue
            if x < 0 or x >= w:
                continue
            if dist[y][x] < 0:
                dist[y][x] = dist[i][j] + 1
                ans = max(ans,dist[y][x])
                q.append((y,x))
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 86876
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;

int n;
int m,x,y;
int a[105];
int b[105];
int main()
{
	cin>>n>>m>>x>>y;
	rep(i,n)cin>>a[i];
	a[n]=x;
	rep(i,m)cin>>b[i];
	b[m]=y;
	rep(i,n+1)
	{
		rep(j,m+1)
		{
			if(a[i]>=b[j])
			{
				cout<<"War"<<endl;
				return 0;
			}
		}
	}
	cout<<"No War"<<endl;
	return 0;
}

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

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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n, t; cin >> n >> t;
    int cost = 1e9;
    REP(i, 0, n){
        int a, b; cin >> a >> b;
        if(b <= t){
            cost = min(cost, a);
        }
    }
    if(cost == 1e9){
        cout << "TLE" << endl;
        return 0;
    }
    cout << cost << endl;
}

Measured memory_bytes: 256
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

class Point {
 public:
  double x, y;

  Point(double x = 0, double y = 0): x(x), y(y) {}

  Point operator + (Point p) { return Point(x + p.x, y + p.y); }
  Point operator - (Point p) { return Point(x - p.x, y - p.y); }
  Point operator * (double a) { return Point(a * x, a * y); }
  Point operator / (double a) { return Point(x / a, y / a); }

  double abs() { return sqrt(norm()); }
  double norm() {return x * x + y * y; }

  bool operator < (const Point &p) const {
    return x != p.x ? x < p.x : y < p.y;
  }

  bool operator == (const Point &p) const {
    return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
  }

};

typedef Point Vector;

double dot(Vector a, Vector b) {
  return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
  return a.x * b.y - a.y * b.x;
}

struct Segment {
  Point p1, p2;
};

typedef Segment Line;

Point project(Segment s, Point p) {
  Vector base = s.p2 - s.p1;
  double r = dot(p - s.p1, base) / base.norm();
  return s.p1 + base * r;
}

int main() {
  Segment s;
  cin >> s.p1.x >> s.p1.y >> s.p2.x >> s.p2.y;
  int n;
  cin >> n;
  cout << fixed;
  for (int i = 0; i < n; i++) {
    Point p;
    cin >> p.x >> p.y;
    Point projected_p = project(s, p);
    cout << setprecision(10) << projected_p.x << " " << projected_p.y << endl;
  }
}



Measured memory_bytes: 3292
//一度提出してます
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

int main() {
  int64_t n,k,s;
  cin >> n >> k >> s;
  rep(i,k) cout << s << " ";
  if(s==1000000000) rep(i,n-k) cout << 3 << " ";
  else rep(i,n-k) cout << s+1 << " ";
  cout << endl;

}


Measured memory_bytes: 3608
#include<stdio.h>
#include<math.h>
int main(){
	int h,m,n;
	double f;
	scanf("%d",&n);
	while(n--){
		scanf("%d:%d",&h,&m);
		f=6.0*(double)m-0.5*((double)h*60.0+(double)m);
		if(f<0.0)f*=-1.0;
		if(f>180.0)f=360.0-f;
		//printf("%lf %lf %lf\n",(double)(6*m),(double)(0.5*(h*60.0+m)),f);
		if(f>=0.0 && f<30.0)printf("alert\n");
		else if(f>=30.0 && f<90.0)printf("warning\n");
		else printf("safe\n");
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

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


    ll ans = max(a,b)*2-1;
    if(a==b)ans++;
    
    cout << ans << endl;
    return 0;
}
 
 


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

int n;
string s, t, ans;

void in();
void solve();
void out();

int main(){
    in();
    solve();
    out();
}

void in(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> n;
    cin >> s >> t;
}

void solve(){
    for(int i = 0; i < n; i++){
        ans += s[i];
        ans += t[i];
    }
}

void out(){
    cout << ans;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * B - Golden Coins
 */
public class Main {
  @SuppressWarnings("resource")
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int val = 0;
    if (N != 0) {
      val = (N / 500) * 1000;
      val += (N % 500) / 5 * 5;
    }

    System.out.println(val);
  }
}

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

using namespace std;

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

ll sq2[100010];

long long factrial[10000000];
long long Repeat(long long a, long long cnt) {
    if(cnt == 0) return 1LL;
    if(cnt % 2 == 1) {
        long long x = Repeat(a, cnt / 2);
        return (((a * x) % MOD) * x) % MOD;
    } else {
        long long x = Repeat(a, cnt / 2);
        return (x * x) % MOD;
    }
}

long long fact(long long a) {
    if(a == 0)
        return 1LL;
    else if(factrial[a] != 0)
        return factrial[a];
    else
        return factrial[a] = (a * fact(a - 1)) % MOD;
}

long long conb(long long a, long long b) {
    long long fa, fb, fab;
    fa = fact(a);
    fb = fact(b);
    fab = fact(a - b);
    fb = Repeat(fb, MOD - 2);
    fab = Repeat(fab, MOD - 2);
    return (((fa * fb) % MOD) * fab) % MOD;
}

int main() {
    ll n, m, i, j, k;
    cin >> n;
    vector<ll> v(n + 1);
    ll p[n + 2] = {};
    ll l, r;
    for(i = 0; i <= n; i++) {
        cin >> v[i];
        if(p[v[i]] == 0) {
            p[v[i]] = i + 1;
        } else {
            l = p[v[i]];
            r = i + 1;
        }
    }
    ll ret = 0;
    /*ret = (Repeat(2,n+1) + MOD -1) % MOD;
    ret = (ret + MOD - (Repeat(2, l - 1) * Repeat(2, n + 1 - r))) % MOD;
    cout << ret << endl;
    */
    for(i=1;i<=n+1;i++){
        ret = conb(n+1,i);
        if(l+n-r>=i-1)ret = (ret + MOD - conb(l-1+n+1-r,i-1)) % MOD;
        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 5120
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

alias P = Tuple!(int, "x", int, "y");

long[10] R;
P[10^^5*10] PS;

void main()
{
    auto hwn = readln.split.to!(long[]);
    auto H = hwn[0];
    auto W = hwn[1];
    auto N = hwn[2];

    R[0] = (H-2) * (W-2);

    int i;
    foreach (_; 0..N) {
        auto ab = readln.split.to!(int[]);
        foreach (yd; [-1, 0, 1]) {
            foreach (xd; [-1, 0, 1]) {
                auto x = ab[1] + xd;
                auto y = ab[0] + yd;
                if (x <= 1 || x >= W || y <= 1 || y >= H) continue;
                PS[i++] = P(x, y);
            }
        }
    }
    sort!"a.y == b.y ? a.x < b.x : a.y < b.y"(PS[0..i]);
    if (i) {
        auto pre = PS[0];
        int cnt = 1;
        foreach (p; PS[1..i]) {
            if (pre == p) {
                ++cnt;
            } else {
                --R[0];
                ++R[cnt];
                cnt = 1;
                pre = p;
            }
        }
        --R[0];
        ++R[cnt];
    }

    foreach (r; R) {
        writeln(r);
    }
}

Measured memory_bytes: 9084
from __future__ import print_function

import sys
from math import gcd
from functools import reduce

input = sys.stdin.readline


def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x


def main():
    k = int(input().strip())
    ans=0
    for i in range(1,k+1):
        for j in range(1,k+1):
            for k in range(1,k+1):
                ans += find_gcd([i,j,k])
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 74816
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, now = 0, cnt = 0;
    cin >> n;
    vector<int> a(n), ok(n, false);
    rep(i, n)cin >> a[i];
    ok[0] = true;
    while(!ok[a[now]-1]){
        cnt++;
        now = a[now]-1;
        ok[now] = true;
        if(now == 1){
            cout << cnt << endl;
            return(0);
        }
    }
    cout << -1 << endl;
}  

Measured memory_bytes: 1024
//  s.at(0) = toupper(s.at(0));//小文字なら大文字へ//大文字の場合はそのまま
//  s.at(i) = tolower(s.at(i));//大文字なら小文字へ//小文字の場合はそのまま
//  string s;
//  cin >> s;
//  cout << s.at(0) <<endl;
//  cout << s.at(0)-'0' <<endl;
//  Aが16？
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll n,m;
  cin >> n >> m;
  vector<pair<ll,ll>>p(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i).first >> p.at(i).second;
  }
  sort(p.begin(),p.end());
  ll ans = 0;
  for(int i=0;i<n;i++){
    ll a = p.at(i).first;
    ll b = p.at(i).second;
    if(m>b){
      m -= b;
      ans +=a*b;
    }
    else{
      ans +=a*m;
      cout << ans << endl;
      return 0;
    }
  }
}


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

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

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

int main() {
  char c;
  cin >> c ;
  
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
    cout << "vowel" << endl;
  }
  
  else {
    cout << "consonant" << endl;  
  }
}

Measured memory_bytes: 256
#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(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll 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);
	string s;
	cin>>s;
	Yn(s[0]=='7'||s[1]=='7'||s[2]=='7');
}


Measured memory_bytes: 3636
N = int(input())
B = list(map(int, input().split()))


inv_output = list()
for i in range(N, 0, -1):
  for j in range(i, 0, -1):
    if B[j - 1] == j:
      inv_output.append(B.pop(j - 1))
      break
  else:
    print(-1)
    break
else:
  for i in inv_output[::-1]:
    print(i)

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

int main() {
	int n;
	cin >> n;
	for(int i=1; i<10; i++){
		for(int j=1; j<10; j++){
			if(n == i*j){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        s: String,
        t: String,
    }
    let mut res = 0;
    for (s_i, t_i) in s.chars().zip(t.chars()) {
        if s_i != t_i {
            res += 1;
        }
    }

    println!("{}", res);
}


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




int main() {
    int n;
    cin >> n;
    ull ans=1;
//    int cnt=0;
    ull ref = pow(10,18);

    ull realans=10;
    rep(i,n){
        ull tmp;
        ull oldans = ans;
        cin>>tmp;
        ans *=tmp;
        float logoldans = log10(oldans);
        float logans = log10(ans);
        if(ans>ref){
            realans = 2;
        }
        if(tmp==0){
            realans=0;
            break;
        }
        if (ans/tmp != oldans) {
            realans=2;
        }
//        if(logoldans+logans>18){
//            realans=2;
//            break;
//        }
    }

    switch(realans){
        case 2:
            cout<<-1<<endl;
            break;
        case 0:
            cout<<0<<endl;
            break;
        case 10:
            cout<<ans<<endl;
            break;

    }
    return 0;
}





/*
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef unsigned long long ll;
//typedef unsigned long long ull;



int main() {
    ll a;
    double b;
    cin>>a>>b;
//    cout << b<<endl;
    ll a0 =  b;
    ll a1 =  b*10;
    ll a2 =  b*100;
//    cout<<a1<<endl;
//    cout<<a2<<endl;
    ll b0 = a0%10;
    ll b1 = a1%10;
    ll b2 = a2%10;
    ll c0 = a*b0;
    ll c1 = a*b1/10;
    ll c2 = a*b2/100;
    ll ans= c0+c1+c2;
//    cout<<b1<<endl;
//    cout<<b2<<endl;
//    cout<<c1<<endl;
//    cout<<c2<<endl;
    cout<<ans<<endl;





    return 0;
}
*/


Measured memory_bytes: 3668
s = input()
t = input()

num = len(s) - len(t) + 1

ans = []
for i in range(num):
  counter = 0
  for j in range(len(t)):
    if t[j] == s[j+i]:
      counter += 1
  ans.append(counter)
  
print(len(t) - max(ans))

Measured memory_bytes: 9056
#include <stdio.h>

int main(void) {
	int a, b, c, x;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	if (a > b){
		x = a;
		a = b;
		b = x;
	}
	if (b > c){
		x = b;
		b = c;
		c = x;
	}
	if (a > b){
		x = a;
		a = b;
		b = x;
	}
	printf("%d %d %d\n", a, b, c);

	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1))
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N, A, B;
	cin >> N >> A >> B;
	string S;
	cin >> S;
	int all = 0, kaigai = 0;
	rep(i, N) {
		switch (S[i]) {
		case 'a':
			if (all < A + B) {
				cout << "Yes" << endl;
				all++;
			}
			else cout << "No" << endl;
			break;
		case 'b':
			if (all < A + B && kaigai < B) {
				cout << "Yes" << endl;
				all++;
				kaigai++;
			}
			else cout << "No" << endl;
			break;
		default:
			cout << "No" << endl;
		}
	}
}


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

int main(){
	int n; cin>>n;
	int cnt=0;
	rep(i,n){
		int a; cin>>a;
		if(a%2==1) cnt++;
	}
	if(cnt%2==0) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

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

typedef long long ll;
#define rep(i, n) for(ll i=0; i<n; i++)
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define sz(v) ll(v.size)
vector<int> L(10010);
vector<int> R(10010);
 

void solve(long long N, long long M, std::vector<long long> L, std::vector<long long> R){
    int maxL, minR;
    maxL = L[0]; minR = R[0];
    for(int i = 0;i<M;i++){
        if(L[i] > maxL) maxL = L[i];
        if(R[i] < minR) minR = R[i];
    }
    int ans = 0;
    if(maxL>minR){ ans = 0;}
    else {
        for(int i = maxL;i<=minR;i++) ans++;
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> L(M);
    std::vector<long long> R(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&L[i]);
        scanf("%lld",&R[i]);
    }
    solve(N, M, std::move(L), std::move(R));
    return 0;
}


Measured memory_bytes: 1920
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

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

signed main() {
	int Q, H, S, D, N;
	cin >> Q >> H >> S >> D >> N;
	
	int min1 = min(min(Q * 4, H * 2), S);
	int min2 = min(min1 * 2, D);

	ll ans = N / 2 * min2 + (N % 2)*min1;

	cout << ans << endl;
	return 0;
}

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long

LL h, w;
LL minmax()
{
	LL ret = LLONG_MAX;
	for(int i = 1; i < w; ++i)
	{
		LL a1 = i * h;
		LL a2 = max(((w - i) / 2) * h, (w - i) * (h / 2));
		LL a3 = (w - i) * h - a2;

		ret = min(ret, max({a1, a2, a3}) - min({a1, a2, a3}));
	}

	swap(h, w);

	for(int i = 1; i < w; ++i)
	{
		LL a1 = i * h;
		LL a2 = max(((w - i) / 2) * h, (w - i) * (h / 2));
		LL a3 = (w - i) * h - a2;

		ret = min(ret, max({a1, a2, a3}) - min({a1, a2, a3}));
	}

	return ret;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> h >> w;
	if(h % 3 == 0 || w % 3 == 0){
		cout << 0 << endl;
		return 0;
	}

	cout << minmax() << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = a; i < b; i++)
using namespace std;
typedef long long ll;

int main(){
    ll N, K; cin >> N >> K;
    vector<ll> A(N+1), sum(N+1);
    rep(i, 1, N+1){ cin >> A[i]; A[i] %= K; sum[i] = (sum[i-1] + A[i])%K;}

    rep(i, 1, N+1){
        sum[i] = sum[i] - i;
        if(sum[i] < 0) sum[i] = (K * ((-sum[i]) / K + 1) + sum[i]) % K;
    }
    unordered_map<int,int> mp;
    rep(i, 1, min(N + 1, K)) mp[sum[i]]++;
    //for(auto e: mp) cerr << e.first << " " << e.second << endl;

    ll norm = 0, ans = 0;
    rep(i, 1, N + 1){
        ans += mp[norm];
        mp[sum[i]]--;
        if(i + K - 1<= N) mp[sum[i+K-1]]++;
        norm = (norm - 1 + A[i] + K) % K;
        //cerr << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11592
#include<stdio.h>
 
int main(void)
{
    int H, W, i, j, f;
    for (;;) {
        scanf("%d %d", &H, &W);
        if ((H|W)==0) exit(0);
        for (i=1; i<=H; i++) {
            f = i % 2;
            for (j=1; j<=W; j++) {
                putchar(f==0 ? '.' : '#');
                f ^= 1;
            }
            putchar('\n');
        }
        putchar('\n');
    }
}




Measured memory_bytes: 2024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long x;scanf("%lld",&x);
    printf("%d %d ",0,0);
    long long k=sqrt(x);
    while(k*k<=x)k++;
    while(k*k>x)k--;
    if(k*k==x)printf("%lld %d %d %lld\n",k,0,0,k);
    else if(k*(k+1)>x)printf("%lld %d %lld %lld\n",k+1,1,(k+1)*k-x,k);
    else printf("%lld %d %lld %lld\n",k+1,1,(k+1)*(k+1)-x,k+1);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 3e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
int n;
ll a[maxx];
ll suml[maxx], sumr[maxx];
ll s1, s2;
priority_queue <ll, vector<ll>, less<ll> > qua; //降序, 队头大
priority_queue <ll, vector<ll>, greater<ll> > que; //升序, 队头小

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n * 3; i++) {
		scanf("%lld", &a[i]);
		if(i <= n) {
			s1 += a[i];
			que.push(a[i]);
		}
		else if(i >= 2 * n + 1) {
			s2 += a[i];
			qua.push(a[i]);
		}
	}
	suml[n] = s1; //前n项和
	sumr[n * 2 + 1] = s2; //后n项和
	int l = n + 1, r = 2 * n;
	//只能精确删除n项, 无论怎么删, 后n项都不可能进到前n项去
	//故让中间的n项去往两边置换
	//中间的n项必然是前x个置换到前n项内, 后n-x个置换到后n项内(或者不发生置换)
	//故分别维护前缀和、后缀和, 前缀和与后缀和的差维护一个最大值
	while(l <= r) {
		if(a[l] > que.top()) { //每次置换出最小的队头
			s1 += a[l];
			s1 -= que.top();
			que.pop();
			que.push(a[l]);
		}
		suml[l] = s1; //维护前缀和
		l++;
	}
	l = n + 1, r = 2 * n;
	while(l <= r) {
		if(a[r] < qua.top()) { //每次置换出最大的队头
			s2 += a[r];
			s2 -= qua.top();
			qua.pop();
			qua.push(a[r]);
		}
		sumr[r] = s2; //维护后缀和
		r--;
	}
	ll ans = -INF;
	for(int i = n; i <= n * 2; i++) ans = max(ans, suml[i] - sumr[i + 1]);
	printf("%lld\n", ans);
}

Measured memory_bytes: 7668
#include<iostream>
using namespace std;
int main(){
int h,w;
while(1){
cin >> h >> w;
if(h==0 && w==0)break;
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
if(i%2==0 && j%2==1 || i%2==1 && j%2==0)cout << ".";
else cout << "#";
}
cout <<endl;
}
cout <<endl;
}
return 0;
}


Measured memory_bytes: 3136
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#define ksjnf sfnlk
using namespace std;

int n,m,ans=0,tmp[200005];
struct Student{
    int l,r;
    bool operator<(const Student &b)const{
        return l!=b.l?l<b.l:r>b.r;
    }
}s[200005];
priority_queue<int,vector<int>,greater<int> > q;

int main(){
//  freopen("data.in","r",stdin);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&s[i].l,&s[i].r);
    sort(s+1,s+n+1);
    int h=1,t=m;
    for(int i=1;i<=n;i++){
        q.push(s[i].r);
        if(h<=t&&h<=s[i].l)h++;
        else{
            tmp[++tmp[0]]=q.top();
            q.pop();
        }
    }
    sort(tmp+1,tmp+tmp[0]+1);
    for(int i=tmp[0];i>=1;i--){
        if(h<=t&&tmp[i]<=t)t--;
        else ans++;
    }
    printf("%d",ans);
}

Measured memory_bytes: 3192
import sys
s = input()
q = int(input())
a = ['', '']
r = 0
for l in sys.stdin:
    if l[0] == '1':
        r += 1
    else:
        a[0 if l[2] == '21'[r % 2] else 1] += l[4]
if r % 2 == 0:
    print(''.join(reversed(a[1])) + s + ''.join(a[0]))
else:
    print(''.join(reversed(a[0])) + ''.join(reversed(s)) + ''.join(a[1]))

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

int count;
char say[10];
char str[3][10] = {"Fizz", "Buzz", "FizzBuzz"};
int ans;

int num(void)
{
	int i;
	int num;
	
	num = 0;
	i = 0;
	while (say[i] != '\0'){
		num *= 10;
		num += (say[i] - '0');
		i++;
	}
	
	return (num);
}

int judge(void)
{
	int flag;
	
	flag = 0;
	if (ans < 0){
		if (count != num()){
			flag = 1;
		}
	}
	else {
		if (strcmp(say, str[ans])){
			flag = 1;
		}
	}
	
	return (flag);
}

int main(void)
{
	int player[1000];
	int p_n;
	int m, n, m2;
	int i;
	int flag;
	
	while (scanf("%d%d", &m, &n), m){
		for (i = 0; i < m; i++){
			player[i] = 1;
		}
		
		m2 = m;
		count = 1;
		p_n = 0;
		while (n--){
			scanf("%s", say);
			if (m > 1){
				ans = -1;
				if (count % 3 == 0){
					ans = 0;
				}
				if (count % 5 == 0){
					ans = 1;
				}
				if (count % 3 == 0 && count % 5 == 0){
					ans = 2;
				}
				
				if (judge()){
					player[p_n] = 0;
					m--;
				}
				
				p_n = (p_n + 1) % m2;
				
				while (!player[p_n]){
					p_n = (p_n + 1) % m2;
				}
				count++;
			}
		}
		
		for (i = 0, flag = 0; i < m2; i++){
			if (player[i]){
				if (flag){
					printf(" ");
				}
				flag = 1;
				printf("%d", i + 1);
			}
		}
		printf("\n");
	}
	
	return (0);
}

Measured memory_bytes: 620
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    string s;
    cin >> s;
    string key = "keyence";
    int n = s.length();
    bool f = false;
    if (s == key)
        f = true;
    for (int i = 0; i < n; i++)
    {
        for (int j = 1; j <= n - i; j++)
        {
            // s[i, i+j-1] == key ?
            string t = s.substr(0, i) + s.substr(i + j, n - i - j);
            if (t == key)
                f = true;
        }
    }
    cout << (f ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    string s;
    cin >> s;
    rep(i, s.length()) {
        if (i % 2 == 0) {
            if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') {
                puts("No");
                return 0;
            }
        } else {
            if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') {
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 256
N,k=map(int,input().split())
L=[0 for i in range(2)]

K=[]
for i in range(k):
    l,r=map(int,input().split())
    K.append([l,r])
mod=998244353
L[1]=1
R=[0,1]
for i in range(2,N+1):
    cnt=0
    for l,r in K:
        cnt+=R[max(0,i-l)]
        cnt-=R[max(0,i-(r+1))]
    cnt%=mod
    L.append(cnt)
    R.append(R[-1]+cnt)
print(L[-1]%mod)
#print(R)

Measured memory_bytes: 96296
using System;

class Program {
    private static int Main() {
        var s = Console.ReadLine();
        var p = Console.ReadLine();

        // 判定用に2回繰り返す
        s += s;

        bool isYes = s.IndexOf( p ) >= 0;
        Console.WriteLine( isYes ? "Yes" : "No" );

        return 0;
    }
}

Measured memory_bytes: 16432
#!/usr/bin/python
# coding: utf-8

# AtCoder Beginner Contest 076
# D - AtCoder Express

from sys import stdin

# 移動距離を返す
def solve(ts, vs):
  if len(ts) == 0: return 0.0

  time  = sum(ts)  # 総時間
  limit = min(vs)  # 制限速度の下限
  if time / 2.0 <= limit:     # limitまで加速する時間がない
    return (time / 2.0) ** 2  # 半分の時間で加速，残りで減速

  # 制限速度まで達した区間がある
  if limit == 0:
    # その区間を除いて計算
    vzero = [i for i in range(len(vs)) if vs[i] == 0][0]
    return solve(ts[:vzero],     vs[:vzero]) + \
           solve(ts[vzero + 1:], vs[vzero + 1:])

  # 最初に1加速, 最後に1減速
  n = len(ts)
  ts[0]     -= 1
  ts[n - 1] -= 1
  # 長さ0の区間を削除
  if ts[n - 1] == 0:
    ts = ts[:n - 1]
    vs = vs[:n - 1]
  if ts[0] == 0:
    ts = ts[1:]
    vs = vs[1:]
  # 制限時間を1減らす (= 現在速度を1増やす)
  vs = [v - 1 for v in vs]
  # 1加速, 速度1でtime-2秒移動, 1減速, の移動距離
  dist = time - 2 + 1
  return dist + solve(ts, vs)

# 文字列をintのリストに分解する
def splitToInt(line):
  words = line.strip().split()
  return [int(w) for w in words]

N = int(stdin.readline())
ts = splitToInt(stdin.readline())
vs = splitToInt(stdin.readline())
if len(ts) != N or len(vs) != N: raise
print(solve(ts, vs))

Measured memory_bytes: 3316
from sys import stdin
from collections import Counter
import numpy as np

N, M = [int(x) for x in stdin.readline().split()]
A = np.array([int(a) for a in stdin.readline().split()], dtype=np.int64)

cum_remainders = (np.hstack([0, A]) % M).cumsum() % M

remainder_counts = Counter(cum_remainders)
combinations = 0
for count in remainder_counts.values():
    combinations += count * (count - 1) // 2
print(combinations)


Measured memory_bytes: 23120
#include <cmath>
#include <iostream>
#include <map>
using namespace std;
const int mod = 1e9 + 7;
int main() {
    int n, k;
    cin >> n >> k;

    int m = sqrt(n);
    map<int, long> num;
    for(int i = 1; i <= m; i++)
        num[n / i]++;
    for(int i = 1; i <= m; i++)
        num[i] = n / i - n / (i + 1);

    map<int, long> dp;
    for(auto x : num) {
        dp[n / x.first] = x.second;
    }

    for(int i = 1; i < k; i++) {
        long pre = 0;
        for(auto itr = dp.begin(); itr != dp.end(); itr++) {
            itr->second += pre;
            itr->second %= mod;
            pre = itr->second;
        }

        map<int, long> predp = dp;
        auto preitr = predp.rbegin();
        auto numitr = num.rbegin();
        for(auto itr = dp.begin(); itr != dp.end(); itr++) {
            itr->second = preitr->second * numitr->second % mod;
            preitr++, numitr++;
        }
    }
    long ans = 0;
    for(auto x : dp) {
        ans += x.second;
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 12160
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
struct point
{
    ll x;
    ll y;
}a,maxn;
int main()
{
     ll n;
     cin>>n;
     maxn.x=0;
     for (ll i=0;i<n;i++)
     {
         cin>>a.x>>a.y;
         if (a.x>maxn.x)
         {
             maxn.x=a.x;
             maxn.y=a.y;
         }
     }
     cout << maxn.x+maxn.y << endl;
}


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

int main() {
  ll n; cin>>n;
  vector<vector<ll>> v(n,vector<ll>(2));
  rep(i,n){cin>>v.at(i).at(0)>>v.at(i).at(1);}
  double sum=0;
  for(int i=1; i<n; i++){
    rep(j,i){
      double p=pow(pow(v.at(i).at(0)-v.at(j).at(0),2) 
             + pow(v.at(i).at(1)-v.at(j).at(1),2),0.5);
      sum+=p;
    }
  }
  cout << fixed << setprecision(10);
  cout<<sum*2/n;
}
      



Measured memory_bytes: 384
// LHIC code
#include <bits/stdc++.h>
 
#define mp make_pair
#define pb push_back
 
 
typedef long long ll;
typedef long long llong;
typedef long double ld;
 
using namespace std;
 
template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
        cerr << (*i) << " ";
    }
    cerr << "\n";
}
 
int n;
ld a, b;
ld h[120000];
 
int main() {
    cin >> n >> a >> b;
    a -= b;
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    ld l = 0;
    ld r = 1e9;
    while (r - l > 1) {
        ld mid = ceil((ld)(l + r)/(ld)2);
        ll cnt = 0;
        for (int i = 0; i < n; ++i) {
			if (h[i] > mid * b) {
                cnt += ceil(ld(h[i] - mid * b) / (ld)a);
            }
        }
        if (cnt <= mid)
            r = mid;
        else
            l = mid;
    }
    cout << (int)ceil(r) << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
    #include<cstdlib>
    using namespace std;
    int cmpfunc (const void * a, const void * b) {
       return ( *(int*)a - *(int*)b );
    }
    int main(){
      long int n,k;
      long int sum=0;
      cin>>n;
      cin>>k;
      if(n<=k)printf("0");
      
      else{
        long int arr[n];
        for(long int i=0;i<n;i++){
        	cin>>arr[i];
      	}
      	qsort(arr,n,sizeof(long int),cmpfunc);
      	for(long int j =0;j<n-k;j++){
        	sum+= arr[j];
      	}
      	cout<< sum ;
      }
      return 0;
    }

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

#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;


llong merge(int a[], int left, int mid, int right) {
    int L[MAX/2 + 2], R[MAX/2 + 2];
    llong cnt = 0;
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++) L[i] = a[left + i];
    for (int i = 0; i < n2; i++) R[i] = a[mid + i];
    L[n1] = R[n2] = SENTINEL;
    int i = 0, j = 0;
    for (int k = left; k < right; k++) {
        if (L[i] <= R[j]) {
            a[k] = L[i++];
        } else {
            a[k] = R[j++];
            cnt += n1 - i;
        }
    }
    return cnt;
}

llong mergeSort(int a[], int n, int left, int right) {
    llong v1, v2, v3;
    if (left+1 < right) {
        int mid = (left + right) / 2;
        v1 = mergeSort(a, n, left, mid);
        v2 = mergeSort(a, n, mid, right);
        v3 = merge(a, left, mid, right);
        return v1 + v2 + v3;
    } else {
        return 0;
    }
}

int main() {
    int a[MAX], n;

    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];

    llong ans = mergeSort(a, n, 0, n);
    cout << ans << endl;
}



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

int main() {
	int n,k;
	cin >> n >> k;
	std::vector<int> v(n);
	for(int i=0;i<n;i++)cin >> v[i];
	
	vector<int> dp(n+1,0);
	dp[0] = 0;
	dp[1] = abs(v[0]-v[1]);
	for(int i=2;i<=n;i++){
	  int ans=INT_MAX;
	  for(int j=1;j<=k&&i-j>=0;j++)
	     ans = min(ans,dp[i-j] + abs(v[i]-v[i-j]));
	     
	  dp[i] = ans;
	      
	  }
	
	cout << dp[n-1];
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main()
{
    int n,i,j,ans=0,tmp=0;;

    scanf("%d",&n);

    for (i=1;i<=n;i++){
        for(j=1;j<=i;j++){
            if(i%j==0&&i%2==1){
                tmp++;
            }
        }
        if(tmp==8){
            ans++;
        }
        tmp=0;
    }

    printf("%d\n",ans);

    return 0;
}

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

int main() {
    vector<int> d(5);
    for (int i = 0; i < 5; ++i) cin >> d[i];
    vector<pair<int, int>> r_and_d;
    for (int i = 0; i < 5; ++i) {
        r_and_d.push_back(make_pair(d[i] % 10, d[i]));
    }
    sort(r_and_d.begin(), r_and_d.end());
    int l = -1, minr = 10;
    for (int i = 4; i >= 0; --i) {
        if (r_and_d[i].first == 0) break;
        if (minr > r_and_d[i].first) l = i;
    }
    if (l != -1) swap(r_and_d[4], r_and_d[l]);
    int ans = 0;
    for (int i = 0; i < 5; ++i) {
        if (i == 4) ans += r_and_d[i].second;
        else if (r_and_d[i].first == 0) {
            ans += r_and_d[i].second;
        }
        else {
            ans += r_and_d[i].second - r_and_d[i].first + 10;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
use std::cmp::min;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let m:usize = read();
    let mut arr:Vec<i64> = (0..m).map(|_| read()).collect();
    arr.sort();

    let mut diffs = Vec::new();
    for i in 1..m {
        diffs.push(arr[i] - arr[i-1]);
    }
    diffs.sort_by(|a, b|b.cmp(a));

    let mut res = arr.get(m-1).unwrap() - arr[0];
    for i in 0..min(diffs.len(), n-1) {
        res -= diffs[i];
    }
    println!("{}", res);
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0;i < N;i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  int A = 0;
  int B = 0;
  for(int j = 0;j < N;j++) {
    if(j % 2 == 0) {
      A = A + vec.at(j);
    }
    else {
      B = B + vec.at(j);
    }
  }
  cout << A - B << endl;
}

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

void add(int a, int w, vector<int> &bit, int N) 
{
    for (int x = a; x <= N; x += x & -x) bit[x] += w;
}
int sum(int a, vector<int> &bit, int N) {
    int ret = 0;
    for (int x = a; x > 0; x -= x & -x) ret += bit[x];
    return ret;
}

int	main(void)
{
	int n, q;
	cin >> n >> q;
	vector<int> c(n);
	for (int i = 0; i < n; i++) cin >> c[i];
	vector<tuple<int, int, int>> query(q);
	for (int i = 0; i < q; i++)
	{
		int l, r, index;
		cin >> l >> r;
		index = i;
		query[i] = make_tuple(r, l, index);
	}
	sort(query.begin(), query.end());
	vector<pair<int, int>> ans(q);
	vector<int> BIT(n + 1, 0);
	vector<int> num_index(n + 1, -1);
	int end = 0;
	for (int i = 0; i < q; i++)
	{
		int l, r, index;
		tie(r, l, index) = query[i];
		while (end < r)
		{
			if (num_index[c[end]] != -1) add(num_index[c[end]] + 1, -1, BIT, n);
			add(end + 1, 1, BIT, n);
			num_index[c[end]] = end;
			end++;
		}
		int value = sum(r, BIT, n) - sum(l - 1, BIT, n);
		ans[i] = {index, value};
	}
	sort(ans.begin(), ans.end());
	for (int i = 0; i < q; i++) cout << ans[i].second << endl;
	return (0);
}

Measured memory_bytes: 19428
n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
MOD = 10**9 + 7

li_t = []
max_t = 0
for i in range(n):
    if t[i] > max_t:
        li_t.append((t[i], t[i] + 1))
        max_t = t[i]
    else:
        li_t.append((1, max_t + 1))

li_a = []
max_a = 0
for i in range(n)[::-1]:
    if a[i] > max_a:
        li_a.append((a[i], a[i] + 1))
        max_a = a[i]
    else:
        li_a.append((1, max_a + 1))
li_a = li_a[::-1]

ans = 1
for i in range(n):
    tmp = min(li_t[i][1], li_a[i][1]) - max(li_t[i][0], li_a[i][0])
    if tmp <= 0:
        ans *= 0
    ans *= tmp
    ans %= MOD
print(ans)

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

#define int long long

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
vint G[222222];

double P[222222];
void dfs(int v,int p){
    int cnt=0;
    for(auto u:G[v]){
        if(u==p)continue;
        cnt++;
        dfs(u,v);
        P[v]+=P[u]+1;
    }

    if(cnt==0)return;
    P[v]/=cnt;
}

double ans[222222];
void dfs2(int v,int p,double luz){
    if(v==0){
        ans[v]=P[v];
    }
    else{
        ans[v]=(P[v]*(G[v].size()-1)+luz)/G[v].size();
    }

    for(auto u:G[v]){
        if(u==p)continue;
        if(v==0){
            if(G[v].size()==1){
                dfs2(u,v,1);
            }
            else{
                double tmp=P[v]*G[v].size();
                tmp-=P[u]+1;
                tmp/=(G[v].size()-1);
                dfs2(u,v,tmp+1);
            }
        }
        else{
            int deg=G[v].size()-1;
            double tmp=P[v]*deg;
            tmp-=P[u]+1;
            tmp+=luz;
            tmp/=deg;
            dfs2(u,v,tmp+1);
        }
    }
}

signed main(){
    scanf("%lld",&N);
    rep(i,N-1){
        int a,b;
        scanf("%lld%lld",&a,&b);
        a--;b--;
        G[a].pb(b);G[b].pb(a);
    }

    dfs(0,-1);
    dfs2(0,-1,0.0);
    rep(i,N)printf("%.20f\n",ans[i]);
    return 0;
}


Measured memory_bytes: 22272
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 
#define debugP(vec) for(auto v : vec) cout << "(" << v.first << "," << v.second << ") "; cout << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << "(" << v.first << "," << v.second << ") "; cout << endl; } 

typedef long long ll;

const ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } else return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

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

	vector<int> a(n);
	rep(i, n) cin >> a[i];

	int mn = INF, mnIx = 0, mx = -INF, mxIx = 0;
	rep(i, n) {
		if(chmax(mx, a[i])) mxIx = i;
		if(chmin(mn, a[i])) mnIx = i;
	}

	int cnt = 0;
	vector<int> x,y;
	if (mx > -mn) {
	  rep(i,n) if(a[i] < 0) {cnt++; x.push_back(mxIx); y.push_back(i);}
	  rep(i,n-1) {x.push_back(i); y.push_back(i+1); cnt++;}
	}
	else {
		rep(i, n) if (a[i] > 0) { cnt++; x.push_back(mnIx); y.push_back(i); }
		rrep(i, n - 1) { x.push_back(i+1); y.push_back(i); cnt++;}
	}

	cout << cnt << endl;
	rep(i,x.size()) cout << x[i] + 1 << " " << y[i] + 1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int c[26]={};
  bool f=true;
  string w;cin>>w;
  int i;
  for(i=0;i<w.size();i++) c[w[i]-'a']++;
  for(i=0;i<26;i++) f&=(c[i]%2==0);
  cout << (f?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int d,n;
  scanf("%d%d",&d,&n);

  if(n!=100){
    if(d==0)
      printf("%d\n",n);
    if(d==1)
      printf("%d\n",100*n);
    if(d==2)
      printf("%d\n",10000*n);
  }

  if(n==100){
    if(d==0)
      printf("%d\n",n+1);
    if(d==1)
      printf("%d\n",101*n);
    if(d==2)
      printf("%d\n",10100*n);
  }

  return 0;
}

Measured memory_bytes: 1676