akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll A, B;
  cin >> A >> B;
  if ((A + B) % 2 == 0) {
    COUT((A + B) / 2);
  } else {
    COUT("IMPOSSIBLE");
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
bool visit(const Graph &g, int v, vector<int> &order, vector<int> &color) {
  color[v] = 1;
  fr(e, g[v]) {
    if (color[e->dst] == 2) continue;
    if (color[e->dst] == 1) return false;
    if (!visit(g, e->dst, order, color)) return false;
  }
  order.push_back(v); color[v] = 2;
  return true;
}
bool topologicalSort(const Graph &g, vector<int> &order) {
  int n = g.size();
  vector<int> color(n);
  rep(u, n) if (!color[u] && !visit(g, u, order, color))
    return false;
  reverse(all(order));
  return true;
}
int n,u,ans;
int c[20],k[20];
Graph g;
vi ord; bool v[20];

void dfs(int cur,int uni,int sbj)
{
	if(uni>=u)ans=min(ans,sbj);
	if(uni>=u||cur>=n)return;
	
	int a=ord[cur];
	fr(i,g[a])if(!v[i->dst])goto FAIL;
	v[a]=1; dfs(cur+1,uni+c[a],sbj+1); v[a]=0;
	FAIL:dfs(cur+1,uni,sbj);
}
int main()
{
	while(scanf("%d%d",&n,&u),n)
	{
		g.clear(); g.resize(n);
		rep(i,n)
		{
			scanf("%d%d",c+i,k+i);
			rep(j,k[i])
			{
				int t; scanf("%d",&t);
				g[i].pb(Edge(i,t,0));
			}
		}
		ord.clear();
		topologicalSort(g,ord); reverse(all(ord));
		
		ans=inf; dfs(0,0,0);
		rep(i,n)v[i]=0;;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 928
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
	int L, R,A,B,C,D;
	cin >> A>>B>>C>>D;
	L = A + B;
	R = C+D;
	if (L == R) {
		printf("Balanced\n");
	}
	else if (L > R) {
		printf("Left\n");
	}
	else {
		printf("Right\n");
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
int main(){
  long long int L,R;
  cin>>L>>R;
  int min=2019;
  
  if(R-L>=2019){
    cout<<0<<endl;
  }
  
  else{
    for(long long int i=L;i<=R;i++){
      for(long long int j=i+1;j<=R;j++){
        if(i*j%2019<min){
min=i*j%2019;
        }
      }
    }
    cout<<min<<endl;
  }
}


Measured memory_bytes: 256
import itertools

def main():
    n, m, q = list(map(int, input().split()))
    abcds = [list(map(int, input().split())) for _ in range(q)]

    combinations = list(itertools.combinations_with_replacement(range(1,m+1), n))

    maxScore = 0
    for combination in combinations:
        score = 0
        for a, b, c, d in abcds:
            if combination[b-1] - combination[a-1] == c:
                score += d
        if score >= maxScore:
            maxScore = score

    print(maxScore)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21436
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        const int Mod = 2019;
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long L = l[0], R = l[1];
            long min = long.MaxValue;
            for (var i = L; i < R && i < L + Mod; i++)
            {
                for (var j = i + 1; j <= R && j <= L + Mod; j++)
                {
                    min = Math.Min((i * j) % Mod, min);
                }
            }
            Console.WriteLine(min == long.MaxValue ? 0 : min);
        }
    }
}


Measured memory_bytes: 13268
n,m = map(int,input().split())
if min(n,m) == 1 and max(n,m) >= 3:
    print(max(n,m)-2)
elif min(n,m) == 1 and max(n,m) == 2:
    print(0)
elif min(n,m) == 2:
    print(0)
else:
    print((n-2)*(m-2))

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
def gcd(a, b):
    while b != 0:
        a, b = b, a%b
    return a

def lcm(a, b):
    return a*b // gcd(a, b)

def anti_division_iter(a, b, r):
    n = b // r
    m = (a-1) // r
    return n - m

a, b, c, d = map(int, input().split())

div_c = anti_division_iter(a, b, c)
div_d = anti_division_iter(a, b, d)
div_cd = anti_division_iter(a, b, lcm(c, d))

print((b-a+1) - (div_c + div_d - div_cd))


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#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)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int x,y;
    cin >> x >> y;
    rep(i,100){
        rep(j,100){
            if(i+j==x&&i*2+j*4==y){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3128
import java.util.Scanner;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int ans = 0;
    int n = sc.nextInt();
    int[] l = new int[n];
    for (int cnt = 0; cnt < n; cnt++) {
      l[cnt] = sc.nextInt();
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < i; j++) {
        for (int k = 0; k < j; k++) {
          if (l[i] == l[j])
            continue;
          if (l[j] == l[k])
            continue;
          if (l[k] == l[i])
            continue;
          int[] ls = { l[i], l[j], l[k] };
          Arrays.sort(ls);
          if (ls[0] + ls[1] > ls[2]) {
            ans++;
          }
        }
      }
    }
    System.out.println(ans);
    sc.close();
  }
}

Measured memory_bytes: 41496
n = int(input())
s = input()
L = [0 for j in range(n)] # L[j] => W
R = [0 for j in range(n)]
if s[0] == "W":
    L[0] = 1
if s[-1] == "W":
    R[-1] = 1
for i in range(1,n):
    L[i] = L[i - 1]
    R[-(i + 1)] = R[-i]
    if s[i] == "W":
        L[i] += 1
    if s[-(i + 1)] == "W":
        R[-(i + 1)] += + 1
m = min(n - 1 - R[1], L[-2])
for i in range(1,n - 1):
    k = L[i- 1] + (n - i - 1) - R[i + 1]
    if m > k:
        m = k
print(m)


Measured memory_bytes: 27332
/*
***************************************************************************
 name  : ITP1_01_D.cpp
 title : Watch
 make  : 2018/08/01 tanabe
***************************************************************************
*/

// Library
#include <iostream> // standard input output object

// Prototype
void Time(int *x,int *s,int n); // Calculate time

main(void){
  int h = 0; // hour
  int m = 0; // minits
  int s = 0; // second

  std::cin >> s; // input "s"

  Time(&h,&s,3600); // calculate h and s
  Time(&m,&s,60);   // calculate m and s

  std::cout << h << ":" << m << ":" << s << std::endl; // output "h:m:s"

}

// +----------------------------------+
// | name       : Tiem                |
// | obtain     : int h.m,int s,int n |
// | return     : none                |
// | processing : calculate time      |
// +----------------------------------+
void Time(int *x,int *s,int n){

  // continue s >= n
  // increment x at loop update
  for(;*s >= n;(*x)++){
    *s -= n; // subtract n from s
  }

}



Measured memory_bytes: 3136
#include <iostream>
using namespace std;
int main(){
    int i=0;
    char a[20],x;
    
    while(cin>>x){
        a[i]=x;
        i++;
        if(i>=20)break;
    }
    
    for(int f=i-1;f>=0;f--){
        cout<<a[f];
    }
    
    cout<<endl;
}

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

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> p(N);
    rep(i,N) cin >> p[i];

    sort(p.begin(),p.end());
    int sum = 0;
    rep(i,K) sum += p[i];
    cout << sum << endl;
} 

Measured memory_bytes: 3572
#!/usr/bin/env python3
import math

a, b, x = [int(s) for s in input().split()]

b_w = x / (a * a)

x1 = 2 * b_w - b

if x1 >= 0:
    print(math.atan((b - x1) / a) / (2*math.pi) * 360)
else:
    print(math.atan(b * a * b / x / 2) / (2*math.pi) * 360)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int n,a[100005],l,r,ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		cin>>l>>r;
		ans+=r-l+1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
char map[100][100];
int H, W;

void visit(int x, int y, char own){
  static int d[4][2] = {{1,0}, {0,1}, {-1,0}, {0,-1}};
  int i;
  int nx, ny;

  map[y][x] = '0';
  for(i = 0; i < 4; i++) {
    nx = x + d[i][0];
    ny = y + d[i][1];
    if(nx >= 0 && nx < W && ny >= 0 && ny < H && map[ny][nx] == own) {
      visit(nx, ny, own);
    }
  }
}

int main(){
  char x;
  int i,j;
  int count;
  while(1){
    scanf("%d %d", &H, &W);
    if(H==0 && W==0) break;
    for(i=0;i<H;i++){
      getchar();
      for(j=0;j<W;j++){
        scanf("%c", &x);
	map[i][j]=x;
      }
    }
    count = 0;
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
	if(map[i][j] != '0') {
	  visit(j, i, map[i][j]);
	  count++;
	}
      }
    }
    printf("%d\n", count);
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int seq[110];

int main() {
  int n, a, b, c, x;
  while (scanf("%d %d %d %d %d", &n, &a, &b, &c, &x), n|a|b|c|x) {
    REP(i, n) { scanf("%d", &seq[i]); }
    int cnt = 0;
    REP(i, n) {
      while (true) {
        if (x == seq[i]) { break; }
        x = (a * x + b) % c;
        cnt++;
        if (cnt > 10000) { break; }
      }
      if (i == n - 1) { break; }
      x = (a * x + b) % c;
      cnt++;
    }
    if (cnt > 10000) { puts("-1"); }
    else { printf("%d\n", cnt); }
  }
}

Measured memory_bytes: 0
(N, M) = gets.split.map(&:to_i)
ab = []
M.times.each { ab.push(gets.split.map(&:to_i)) }
ret = Array.new(N+1, 0)
ab.each { |t| ret[t[1]] = 1 if t[0] == 1 }
if ab.count { |t| t[1] == N and ret[t[0]] == 1 } > 0
    puts "POSSIBLE"
else
    puts "IMPOSSIBLE"
end

Measured memory_bytes: 17788
#include <stdio.h>
#include <iostream>
#include <vector>
#include <utility>
#include <math.h>

using namespace std;

typedef long long int ll;

const ll INF = ( -1 );
ll solve();

int main(void) {
	
	
	while(solve()){}

	return 0;
}


ll solve() {

	//dp[?¢¨????????????????????????][capture??????????????§???????¢¨???????????°] = ????°??????¢
	ll n;
	cin >> n;

	if( n == 0 ) return 0;

	vector<ll> p(n),t(n);
	vector< vector< ll > > dp( n, vector<ll>( 4, INF ) );
	vector< vector< ll > > tdp( n, vector<ll>( 4, 0 ) );

	for( ll i = 0; i < n; i++ )
		cin >> p[i] >> t[i];

	if( p[0] <= t[0] ) {
		dp[0][1] = p[0];
		tdp[0][1] = t[0];
	}

	for( ll i = 1; i< n; i++ ) {

		const ll dist = abs(p[i] - p[i-1]);

		for( ll j = 0; j < 4; j++ ) {

			//????????????capture??????
			if( j < 3 ) { 
				if( dp[i-1][j] != INF ) {
					//?????????
					ll cost = dist*(j+1);
					if( tdp[i-1][j]+cost <= t[i] ) {
						if( dp[i][j+1] == INF || dp[i][j+1] > dp[i-1][j]+dist ) {
							dp[i][j+1] = dp[i-1][j]+dist;
							tdp[i][j+1] = t[i];
						}
					}
				}
			}

			//?????????????????£????????£???capture
			if( j > 0 ) {
				if( dp[i-1][j] != INF ) {
					ll cost = p[i-1]*(j+1)+p[i];
					if(  tdp[i-1][j]+cost <= t[i] )
						
						if( dp[i][1] == INF || dp[i][1] > dp[i-1][j]+p[i-1]+p[i] ) {
							dp[i][1] = dp[i-1][j]+p[i-1]+p[i];
							tdp[i][1] = t[i];
						}
				}
			}
			
		}

	}

	for( int i = 0; i < 4; i++ ) {
		if( dp[n-1][i] != INF )
			dp[n-1][i] += p[n-1];
	}
	
	ll ans = INF;
	for( ll i = 0; i < 4; i++ ) {
		if( dp[n-1][i] != INF ) {
			if( ans == INF || ans > dp[n-1][i] )
				ans = dp[n-1][i];
		}
	}

	if( ans == INF ) {

		cout << "NG ";
		for( int i = 0; i < n; i++ ) {
			bool b = true;
			b = ( dp[i][0] == INF &&  dp[i][1] == INF &&
				  dp[i][2] == INF &&  dp[i][3] == INF);
			if( b ) {
				cout << i+1 << endl;
				break;
			}
		}

	} else {

		cout << "OK ";
		cout << ans << endl;

	}



	return 1;

}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = 1e9 + 1;

int main() {
  string s;
  cin >> s;
  if(s == "SUN") cout << 7 << endl;
  else if(s == "MON") cout << 6 << endl;
  else if(s == "TUE") cout << 5 << endl;
  else if(s == "WED") cout << 4 << endl;
  else if(s == "THU") cout << 3 << endl;
  else if(s == "FRI") cout << 2 << endl;
  else if(s == "SAT") cout << 1 << endl;
}


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

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

typedef struct Node { ll num; char c; } node;

vector<node> bubble_sort(vector<node> s, ll n) {
    for(ll i = 0; i < n; i++) {
        for(ll j = n-1; j > i; j--) { 
            if( s.at(j).num < s.at(j-1).num) {
                swap(s.at(j-1), s.at(j));
            }
        }
    }
    return s;
}

vector<node> selection_sort(vector<node> s, ll n) {
    for(ll i = 0; i < n; i++) {
        ll min = i;
        for(ll j = i; j < n; j++) { 
            if( s.at(min).num > s.at(j).num) {
                min = j;
            }
        }
        if( s.at(min).num < s.at(i).num) {
            swap(s.at(min), s.at(i));
        }
    }
    return s;
}

int main() {
    ll n; cin >> n;
    vector<node> s(n);
    for(ll i = 0; i < n; i++) {
        cin >> s.at(i).c >> s.at(i).num;
    }
    vector<node> sorted_buuble(n); sorted_buuble = bubble_sort(s,n);
    vector<node> sorted_selection(n); sorted_selection = selection_sort(s,n);
    for (ll j = 0; j < n-1; j++) { cout << sorted_buuble.at(j).c << sorted_buuble.at(j).num << ' '; }
    cout << sorted_buuble.at(n-1).c << sorted_buuble.at(n-1).num << endl << "Stable" << endl;
    for (ll j = 0; j < n-1; j++) { cout << sorted_selection.at(j).c << sorted_selection.at(j).num << ' '; }
    cout << sorted_selection.at(n-1).c << sorted_selection.at(n-1).num << endl;
    bool flg = true;
    for (ll i = 0; i < n; i++)
    {
        if( sorted_selection.at(i).c != sorted_buuble.at(i).c ) {
            flg = false; break;
        } 
    }
    if(flg) cout << "Stable" << endl;
    else cout << "Not stable" << endl;;
    
    return 0;
}




Measured memory_bytes: 3172
#include <iostream>
#include <string>

using namespace std;

int main(int argc, string *argv[]){
  char b;
  cin >> b;

  switch(b){
    case 'A':
    cout << 'T' << endl;
    break;
    case 'C':
    cout << 'G' << endl;
    break;
    case 'G':
    cout << 'C' << endl;
    break;
    case 'T':
    cout << 'A' << endl;
    break;
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), A = sc.nextInt();
		int[] x = new int[N];
		for(int i = 0; i < N; i++) x[i] = sc.nextInt();
		long[][][] dp = new long[N + 1][N + 1][2501];
		dp[0][0][0] = 1;
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N + 1; j++) {
				for(int k = 0; k < 2501; k++) {
					if(j + 1 < N + 1 && k + x[i] < 2501) dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
					dp[i + 1][j][k] += dp[i][j][k];
				}
			}
		}
		long ans = 0;
		for(int k = 1; k <= N; k++) {
			ans += dp[N][k][A * k];
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 83404
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
/**
 * @author penguin_410
 *         Date: 2014/03/06
 */
public class Main {
    public static void main(String... args) throws IOException {
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final StringBuilder sb = new StringBuilder();
        while (true) {
            final String line = br.readLine();
            final int index = line.indexOf(" ");
            final int x = Integer.parseInt(line.substring(0, index));
            final int y = Integer.parseInt(line.substring(index+1, line.length()));
            if (x == 0 && y == 0) break;
            sb.append(x < y ? x + " " + y : y + " " + x).append("\n");
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 22788
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n;
    cin>>n;
    ll cnt[5]={};
    string s,march="MARCH";
    rep(i,n){
        cin>>s;
        rep(j,5){
            if(s[0]==march[j]) cnt[j]++;
        }
    }
    ll ans=0;
    rep(i,5){
        for(ll j=i+1;j<5;j++){
            for(ll k=j+1;k<5;k++){
                ans+=cnt[i]*cnt[j]*cnt[k];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
int h,w,x,y,nx,ny,t,r,a[1010][1010],dx[]={0,1,0,-1},dy[]={1,0,-1,0};
char c;
main(){
  queue<tuple<int,int,int>>que;
  cin>>h>>w;
  rep(i,h)rep(j,w){
    cin>>c;
    a[i][j]=99999999;
    if(c=='#')que.emplace(i,j,0);
  }
  while(!que.empty()){
    tie(y,x,t)=que.front();que.pop();
    if(a[y][x]>t){
      a[y][x]=t;
      r=max(r,t);
      rep(i,4){
        ny=y+dy[i];nx=x+dx[i];
        if(nx<0||ny<0||nx>=w||ny>=h)continue;
        que.emplace(ny,nx,t+1);
      }
    }
  }
  cout<<r;
}

Measured memory_bytes: 52552
import sys


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    ans = [0] * n
    for i in range(n, 0, -1):
        s = 0
        for j in range(i, n + 1, i):
            s += ans[j - 1]
        if s % 2 == a[i - 1]:
            ans[i - 1] = 0
        else:
            ans[i - 1] = 1
    m = sum(ans)
    print(m)
    for i in range(1, n + 1):
        if ans[i - 1]:
            print(i)


if __name__ == "__main__":
    main()


Measured memory_bytes: 12224
#include<bits/stdc++.h>
using namespace std; 
int main(){
 ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int t;
   t=1;
   while(t--){
   	long long int ans=0;
   	int n;
   	cin>>n;
   	for(int i=1;i<=n;i++){
   	long long int x;
	   cin>>x;
	   if(i%2!=0&&x%2!=0)
	   ans++;	
	}
	cout<<ans<<"\n";
   }
   return 0;
}

Measured memory_bytes: 3608
def is_palindrom(s, start=0, end=None):
    if end is None:
        end = len(s) - 1
    n = len(s[start:end+1])
    for i in range(n//2):
        if s[start+i] != s[end - i]:
            return False
    return True

def is_strong_palindrom(s):
    n = len(s)
    if not is_palindrom(s):
        print("No")
    elif not is_palindrom(s, 0, (n-1)//2 - 1):
        print("No")
    elif not is_palindrom(s, (n+3)//2 -1, n-1):
        print("No")
    else:
        print("Yes")
        
line = input()
is_strong_palindrom(line)

Measured memory_bytes: 3064
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int n;
    cin >> n;
    cout << "ABC" << n << endl;

    return 0;
}


Measured memory_bytes: 256
/*
Author :: Shahadat Hossain Nirob
............SUST_MATH14..........
*/
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <vector>

#define Long long long
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define II() ( { int a ; read(a) ; a; } )
#define LL() ( { Long a ; read(a) ; a; } )
#define DD() ({double a; scanf("%lf", &a); a;})
#define DB if(0) 
#define D(x) cout << #x " is " << x << endl
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef vector<PII> VII;
typedef vector<string> VS;

const int INF = 2000000009;
const int MX = 200005;
const double EPS = 1e-9;
const int MOD = 1000000007;

template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

template<class T>inline bool read(T &x){
    int c=getchar();int sgn=1;
    while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}
    for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; 
    x*=sgn; return ~c;
}

#define nl puts ("")
#define sp printf ( " " )
#define phl printf ( "hello\n" )
#define ff first
#define ss second
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define MP make_pair
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define SQ(x) ((x)*(x))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define ALL(x) (x).begin(),(x).end()
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define SZ(x) ((vlong)(x).size())
#define NORM(x) if(x>=mod)x-=mod;
#define MOD(x,y) (((x)*(y))%mod)
#define ODD(x) (((x)&1)==0?(0):(1))

typedef string st;
typedef vector<st> vs;
#define rep(i, n) for(int i = 0; i < n; i++)
#define fogg(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i >= (b); i--)
#define test int t; cin >> t; while(t--)
#define endl '\n'
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main()
{
	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt","r",stdin);
 //    freopen("output.txt","w",stdout);
 //    #endif
    
    Long n=LL();
    Long arr[n+5],mn,mx;
    arr[0]=LL();
    mn=arr[0];
    mx=arr[0];
    fogg(i,1,n-1)
    {
    	arr[i]=LL();
    	mn=min(arr[i],mn);
    	mx=max(arr[i],mx);

    }
	cout << mx-mn << endl;
	return 0;
}



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

A = [ [0 for _ in range(10)] for _ in range(10)]

for n in range(1,N+1):
  y = str(n)
  A[int(y[0])][int(y[-1])] += 1
  #print(y[0], y[-1])

#print(A)
ans = 0
for i in range(10):
  for j in range(10):
    ans += A[i][j]*A[j][i]
    
print(ans)
  
  

Measured memory_bytes: 73528
import math
N, M = map(int, input().split())
ans_ki = 0
ans_gu = 0
# 奇数奇数
if M > 1:
    ans_ki = (math.factorial(M) / (2 * math.factorial(M - 2)))
else:
    pass
# 偶数偶数
if N > 1:
    ans_gu = (math.factorial(N) / (2 * math.factorial(N - 2)))
else:
    pass
ans = round(ans_ki + ans_gu)
print(ans)


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

using namespace std;

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

int main() {
    int H, W;
    cin >> H >> W;

    char g[51][51];
    int visited[51][51];
    int black = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> g[i][j];
            if (g[i][j] == '#') black++;
            visited[i][j] = -1;
        }
    }
    visited[0][0] = 0;

    queue<pair<int, int>> q;
    q.push(make_pair(0, 0));
    while (!q.empty()) {
        auto cur = q.front();
        q.pop();
        for (int i = 0; i < 4; ++i) {
            int ny = cur.first + dy[i], nx = cur.second + dx[i];
            if (0 <= ny && ny < H && 0 <= nx && nx < W &&
                g[ny][nx] == '.' && visited[ny][nx] == -1) {
                q.push(make_pair(ny, nx));
                visited[ny][nx] = visited[cur.first][cur.second] + 1;
            }
        }
    }

    if (visited[H - 1][W - 1] != -1) {
        cout << H * W - black - visited[H - 1][W - 1] - 1 << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
#from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [LI()for i in range(n)]
inf = 10**17
mod = 10**9 + 7

a,b=MI()
if (a*b)%2==1:
    print("Odd")
else:
    print("Even")

Measured memory_bytes: 38256
import sys 
N, K = map(int, input().split())
H = list(map(int, input().split()))

INF = sys.maxsize

DP = [INF] * N

for i in range(N):
    for k in range(1, K+1):
        DP[i] = min(abs(H[i] - H[max(i - k, 0)]) +  (DP[max(i - k, 0)] if DP[max(i - k, 0)] != INF else 0), DP[i])

print(DP[N-1])


Measured memory_bytes: 52448
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

long long  digsum(long long  n) {
    long long  res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//ミョ(-ω- ?)
int main() {
    ll n;
    cin >> n;
    ll res = INF;
    for(ll i = 1;i<n;i++){
        res = min(res,digsum(i) + digsum(n-i));
    }
    cout << res << endl;
    return 0;
}

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

  #define pb push_back
  #define mp make_pair
  #define ll long long int
  #define mod 1000000007
  #define w(t) int t;	cin>>t while(t--)
  #define vi vector<int>
  #define vll vector<ll>
  #define pi pair<int,int>
  #define pll pair<ll,ll>
  #define fastIO ios_base::sync_with_stdio(0);	cin.tie(0);	cout.tie(0);
  #define loop(i, k, n) for(ll i=k; i<n; i+=1)

  void take_fileIO(){
    #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif
    return;
  }

  void solve(){
    ll n; cin>>n;
    vll heights(n);

    loop(i, 0, n)
      cin>>heights[i];

    vll dp(n+1, 0);

    loop(i, 1, n){
      if(i==1){   //because for reaching i=1 there is only one option i.e. from 0 to 1.
        dp[1] = abs(heights[1]-heights[0]);
        continue;
      }
      ll option1 = dp[i-1] + abs(heights[i-1]-heights[i]);  //jump from i to i+1
      ll option2 = dp[i-2] + abs(heights[i]-heights[i-2]);  //jump from i to i+2

      dp[i] = min(option1, option2);
    }
    
    cout<<dp[n-1]<<endl;
    return;
  }

  int main(){

    fastIO;
    // take_fileIO();
    
    solve();

    return 0;
  }

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
signed main(void){
	ios::sync_with_stdio(false);
	int T,in[10],a,b,flag;
	cin>>T;
	while(T--){
		a=b=flag=0;
		for(int i=0;i<10;i++)
			cin>>in[i];
		for(int i=0;i<10;i++){
			int x=in[i];
			if(x>a&&x>b){
				if(a>b)	a=x;
				else	b=x;
			}
			else if(x<a&&x<b){
				flag=1;
				break;	
			}
			else if(x>a)
				a=x;
			else if(x>b)
				b=x;
		}
		if(flag)	cout<<"NO"<<endl;
		else 		cout<<"YES"<<endl;
	}
}

Measured memory_bytes: 1184
#define NOT_FOUND 20000
 
#include <stdio.h>
 

int linearSearch(int key, int *t, int n);
 
int main(void) {
    int s[10001] = {};
    int t[501] = {};
    int n = 0;
    int q = 0;
    int k = 0;
    int i = 0;
    int j = 0;
 
    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d", &s[i]);
 
    scanf("%d", &q);
    for (i = 0; i < q; i++)
        scanf("%d", &t[i]);
 
    for (i = 0; i < q; i++) {
        if (linearSearch(t[i], s, n) != NOT_FOUND)
            k++;
    }
 
    printf("%d\n", k);
 
    return 0;
}
 

int linearSearch(int key, int *s, int n) {
    int i = 0;
 
    s[n] = key;
 
    while (s[i] != key) {
        i++;
    }
 
    if (i == n)
        return NOT_FOUND;
 
    return i;
}

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    int n;
    cin >> n;
    queue<int> que;
    rep(i, n) {
        string s;
        cin >> s;
        if(s=="A") que.push(1);
        else {
            if(que.empty()) {
                P("NO");
                return 0;
            }
            else que.pop();
        }
    }
    if(que.empty()) P("YES");
    else P("NO");
    return 0;
}

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

struct point{
    double x, y;
    };
const double rot = M_PI / 3.0;
void koch(int n, point a, point b){
    if(n == 0) return;

    point s, t, u;
    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;//内分
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = s.x + cos(rot) * (t.x - s.x) - sin(rot) * (t.y - s.y);//回転行列
    u.y = s.y + sin(rot) * (t.x - s.x) + cos(rot) * (t.y - s.y);

    koch(n - 1, a, s);
    printf("%.10f %.10f\n", s.x, s.y);
    koch(n - 1, s, u);
    printf("%.10f %.10f\n", u.x, u.y);
    koch(n - 1, u, t);
    printf("%.10f %.10f\n", t.x, t.y);
    koch(n - 1, t, b);
    return;
}

int main(){
    point p1, p2;
    int n;
    scanf("%d", &n);
    p1.x = 0;
    p1.y = 0;
    p2.x = 100;
    p2.y = 0;
    printf("%.10f %.10f\n", p1.x, p1.y);
    koch(n, p1, p2);
    printf("%.10f %.10f\n", p2.x, p2.y);
    return 0;
}



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

#define pb push_back
#define mp make_pair

#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = (int)(1e6 + 5);
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e9 + 11);

int a[N];
int x[20][N], y[20][N];

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
       cin >> a[i];
       for (int j = 1; j <= a[i]; ++j)
            cin >> x[i][j] >> y[i][j];
    }
    int mx = 0;
    for (int mask = 0; mask < (1 << n); ++mask) {
        map <int, int> good;
        for (int i = 1; i <= n; ++i) {
           if ((mask >> (i - 1)) & 1)
                good[i] = 1;
            else
                good[i] = 0;
        }
        bool ch = 0;
        for (int i = 1; i <= n; ++i) {
            if ((mask >> (i - 1)) & 1) {
                for (int j = 1; j <= a[i]; ++j) {
                    if (good[x[i][j]] != y[i][j])
                        ch = 1;
                }
            }
        }
        if (!ch)
            mx = max(mx, __builtin_popcount(mask));
    }
    cout << mx;
    return 0;
}


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

int main()
{
    int ans=0,num_p=0,num_g=0,i;
    string s;cin>>s;
    for(i=0;i<s.length();i++)
    {
        if(s[i]=='g')
        {
            if(num_g>num_p)
            {
                ans++;
                num_p++;
            }
            else
                num_g++;
        }
        else
        {
            if(num_g>num_p)
            num_p++;
            else
            {
                ans--;
                num_g++;
            }
        }
    }
    cout<<ans;

}


Measured memory_bytes: 512
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T &a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i+1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for(T &i : v) is >> i; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "c.cpp"

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

  vl a(n+1), b(m+1);
  rep(i, n) {
    cin >> a[i+1];
  }
  rep(i, m) {
    cin >> b[i+1];
  }

  rep(i, n) {
    a[i+1] += a[i];
  }
  rep(i, m) {
    b[i+1] += b[i];
  }
  ll ans = 0;

  rep(i, n+1) {
    if (a[i] > k) break;
    ll cnt = i+(lower_bound(all(b), k-a[i]+1)-b.begin()-1);
    cmax(ans, cnt);
  }
  cout << ans << el;
}


Measured memory_bytes: 6364
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int p[210000];
int UF[210000];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;UF[a]+=UF[b];UF[b]=a;
}
pair<int,int> t[210000];
vector<pair<long long,pair<int,int> > >v;

pair<long long,int> segtree[2][524288];
pair<long long,int> query(int a,int b,int c,int d,int e,int f){
	if(d<a||b<c)return make_pair(inf,-1);
	if(c<=a&&b<=d)return segtree[f][e];
	return min(query(a,(a+b)/2,c,d,e*2,f),query((a+b)/2+1,b,c,d,e*2+1,f));
}
void update(int a,long long b,int c){
	int at=a;
	a+=262144;
	while(a){
		segtree[c][a]=min(segtree[c][a],make_pair(b,at));
		a/=2;
	}
}

int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	for(int i=0;i<a;i++){
		t[i]=make_pair(p[i],i);
	}
	for(int i=0;i<524288;i++)for(int j=0;j<2;j++)segtree[j][i]=make_pair(inf,-1);
	std::sort(t,t+a);

	for(int i=0;i<a;i++){
		int I=t[i].second;
		pair<long long,int> L=query(0,262143,0,I,1,1);
		pair<long long,int> R=query(0,262143,I,a-1,1,0);
		if(L.second!=-1){
			v.push_back(make_pair((long long)(I-L.second)*b+p[I]+p[L.second],make_pair(I,L.second)));
		}
		if(R.second!=-1){
			v.push_back(make_pair((long long)(R.second-I)*b+p[I]+p[R.second],make_pair(I,R.second)));
		}
		update(I,p[I]+(long long)b*I,0);
		update(I,p[I]+(long long)b*(a-I),1);
	}
	std::sort(v.begin(),v.end());
	long long ret=0;
	for(int i=0;i<a;i++)UF[i]=-1;
	for(int i=0;i<v.size();i++){
		if(FIND(v[i].second.first)!=FIND(v[i].second.second)){
			UNION(v[i].second.first,v[i].second.second);
			ret+=v[i].first;
		}
	}
	printf("%lld\n",ret);
}

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

int main()
{
    ll a,b,c,d[100005];
    cin>>a;
    for(int i=0; i<a; i++)
    {
        cin>>b;
        d[b-1]=i+1;
    }
    for(int i=0; i<a; i++)
    {
        cout<<d[i];
        if(i!=a-1)
        {
            cout<<" ";
        }
    }
    cout<<endl;
}


Measured memory_bytes: 1536
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	if (s == "AAA" || s == "BBB") {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(void){
	string s;
  	cin >> s;
    if(s=="SUN")
        cout<<"7";
    if(s=="MON")
      	cout<<"6";
    if(s=="TUE")
      	cout<<"5";
    if(s=="WED")
      	cout<<"4";
    if(s=="THU")
      	cout<<"3";
    if(s=="FRI")
      	cout<<"2";
  	if(s=="SAT")
      	cout<<"1";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,l,r) for(int i=(l),i##end=(r);i<=i##end;i++)
#define Fordown(i,r,l) for(int i=(r),i##end=(l);i>=i##end;i--)
using namespace std;
typedef long long ll;
const int INF=1e9;
const int mod=1e9+7;
const int N=1e6+10;
int fac[N],inv[N],val[N];
inline int read(){
	int x=0,flag=1;
	char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')flag=-1,ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x*flag;
}
inline int fpm(int a,int b){
	int res=1;
	while(b){
		if(b & 1)res=1ll*res*a%mod;
		a=1ll*a*a%mod,b/=2;
	}
	return res;
}
inline void init(int n){
	fac[0]=1;
	For(i,1,n)fac[i]=1ll*fac[i-1]*i%mod;
	inv[n]=fpm(fac[n],mod-2);
	Fordown(i,n-1,0)inv[i]=1ll*inv[i+1]*(i+1)%mod;
}
inline int C(int n,int m){
	return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
	int n=read();
	init(n+5);
	For(i,0,(n-2)/2)val[i]=1ll*C(n-2-i,i)*fac[n-1-i]%mod*fac[i]%mod;
	int ans=0;
	For(i,0,(n-2)/2)ans=(ans+1ll*(val[i]-val[i+1])*(n-1-i))%mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 11904
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long int 
    int main()
    {
        int n,i;
        cin>>n;
        double arr[n],sum=0,temp,last;
        for(i=0;i<n;i++)
        {
        cin>>arr[i];
        }
        sort(arr,arr+n);
        last=arr[0];
        for(i=1;i<n;i++)
        {
            temp=(arr[i]+last)/2;
            arr[i]=temp;
            last=arr[i];
        }
        printf("%0.6f",last);
    } 

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = 1234567;

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

ll calcS(ll n, ll b){
	return n/b  + n%b;
}

int main(void){
	ll n_memo,s;
	cin>>n_memo>>s;
	ll n = n_memo;
	if(n < s){
		cout<<-1<<endl;
		return 0;
	}
	if(n==s){
		cout<<s+1<<endl;
		return 0;
	}

	reps(b, (int)1e6){
		if(b<=1) continue;
		ll wa = 0;
		n = n_memo;
		while(n > 0){
			wa += n%b;
			n /= b;
		}
		if(wa == s){
			cout<<b<<endl;
			return 0;
		}
	}
	n = n_memo;
	if((int)1e6 > n){
		cout<<-1<<endl;
		return 0;
	}

	vector<ll> yakusu;
	reps(i, sqrt(n-s)+1){
		if((n-s)%i == 0){
			yakusu.push_back(i);
			yakusu.push_back((n-s)/i);
		}
	}
	ll ans = LINF;
	rep(i, yakusu.size()){
		ll b = yakusu[i] + 1;
		if(b <= (int)1e6) continue;
		if(n/b + n%b == s){
			ans = min(ans, b);
		}
	}
	if(ans != LINF){
		cout<<ans<<endl;
		return 0;
	}
	cout<<-1<<endl;
	/*
	ll begin = (ll)1e6 - 2;
	ll end = n+1;
	while(end - begin > 1){
		ll mid = (end + begin) / 2;
		if(calcS(n, mid) < s){
			begin = mid;
		}else{
			end = mid;
		}
	}
	if(calcS(n, begin) == s){
		cout<<begin<<endl;
	}else if(calcS(n,end) == s){
		cout<<end<<endl;
	}else{
		cout<<-1<<endl;
	}*/
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define SI size()
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PF push_front
#define PB push_back
#define VE vector<int>
#define VP vector<PA>
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int main(){
  int N;
  int A;
  cin>>N;
  int odd=0,even=0;
  FOR(i,0,N){
    cin>>A;
    if(A%2){
      odd++;
    }else{
      even++;
    }
  }
  if(odd%2==0&&even%2==0){
    YES(1);
  }else if(odd%2==0&&even%2==1){
    YES(1);
  }else if(odd%2==1&&even%2==0){
    YES(0);
  }else if(odd%2==1&&even%2==1){
    YES(0);
  }
  return 0;
}


Measured memory_bytes: 256