akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;

typedef long long ll;
const ll mod=1e9+7;
const ll MAXN=20000+10;
const ll INF=0x7fffffff;

ll gra[210][210];
int n,m,r;
ll mn=INF;

int rtown[10];
bool vis[10];

void clean(){
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			if(i==j)//增加 
				continue;
			gra[i][j]=INF;
		}
	}
}

ll ans=INF;

void Floyd(){
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				gra[i][j]=min(gra[i][j],gra[i][k]+gra[k][j]);
			}
		}
	}
}

void dfs(int loc,int visit,ll pay){
	if(visit>=r){
		ans=min(ans,pay);
	}
	for(int i=1;i<=r;i++){
		if(vis[i]==true)	
			continue;
		int go=rtown[i];
		int now=rtown[loc];
//		if(gra[now][go]==INF||gra[now][go]==0)
//			continue;
		vis[i]=true;
		dfs(i,visit+1,pay+gra[now][go]);
		vis[i]=false;
	}
}

void print(){
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cout<<gra[i][j]<<" ";
		}
		cout<<endl;
	}
}
int main()
{
	scanf("%d %d %d",&n,&m,&r);
	clean();
	for(int i=1;i<=r;i++){
		scanf("%d",&rtown[i]);
	}
	for(int i=1;i<=m;i++){
		int x,y,cost;
		scanf("%d %d %d",&x,&y,&cost);
		if(gra[x][y]>cost){//增加 
			gra[x][y]=gra[y][x]=cost;
		} 
		
	}
	Floyd();
//	cout<<"图："<<endl;
//	print();
	for(int i=1;i<=r;i++){
		vis[i]=true;
		dfs(i,1,0);
		vis[i]=false;
	}
	
	cout<<ans<<endl;
	return 0;
}	 


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

int main() {
  int N;
  cin >> N;
  vector<long long> A = {2,1};

  for(int i=1;i<=N;i++){
    if(i!=1){
      A.push_back(i);
      A.at(i) = A.at(i-2)+A.at(i-1);
    }
  }
  cout << A.at(N) << endl;
}


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

int main(void) {
	int low, max;
	int current;
	int current_before;
	int current_after;
	int current_center;
	int current_before_reverse;
	int temp;
	int count = 0;

	scanf("%d%d", &low, &max);

	for(int i=low; i <= max; i++){
		current = i;
		current_after = current % 100;
		current = current / 100;
		current_center = current % 10;
		current = current / 10;
		current_before = current;
		temp = current_before % 10;
		current = current / 10;
		current_before_reverse = current + temp * 10;
		if(current_before_reverse == current_after){
			count++;
		}
	}

	printf("%d", count);


	/*
	printf("%d\n", current_before);
	printf("%d\n", current_center);
	printf("%d\n", current_after);
	printf("%d\n", current_before_reverse);
	*/

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

vector<vector<ll>> e;
template <class T>
void printArray(const vector<T>& a) {
  int n = a.size();
  for (int i = 0; i < n; i++) {
    cout << a[i] << " \n"[i == n - 1];
  }
}

void pr(ll u, ll v, ll w) { e.push_back({u, v, w}); }

int main() {
  ll l;
  cin >> l;
  ll k = -1, c = 1;
  while (c <= l) {
    c *= 2;
    k++;
  }

  FOR(i, 1, k + 1) {
    pr(i, i + 1, 0);
    pr(i, i + 1, 1LL << (i - 1));
  }

  IFOR(i, 1, k + 1) {
    if (l - (1LL << (i - 1)) >= (1LL << k)) {
      pr(i, k + 1, l - (1LL << (i - 1)));
      l -= 1LL << (i - 1);
    }
  }

  cout << k + 1 << " " << SZ(e) << "\n";
  REP(i, SZ(e)) { printArray(e[i]); }
}

Measured memory_bytes: 3620
N, M, X, Y = map(int, input().split())
xLst = list(map(int, input().split()))
yLst = list(map(int, input().split()))

ans = 'War'
Z = []
for i in range(X + 1, Y + 1):
    Z.append(i)

delxLst = []
for i in range(len(Z)):
    for j in range(len(xLst)):
        if Z[i] <= xLst[j]:
            delxLst.append(i)
            break

delxLst.sort(reverse=True)
for i in range(len(delxLst)):
    del Z[delxLst[i]]

delyLst = []
for i in range(len(Z)):
    for j in range(len(yLst)):
        if Z[i] > yLst[j]:
            delyLst.append(i)
            break
delyLst.sort(reverse=True)
for i in range(len(delyLst)):
    del Z[delyLst[i]]

if len(Z) > 0:
    print('No War')
else:
    print('War')

Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
int n;
cin>>n;
while(n--){
    string t;
    cin>>t;
    set<string> s;
    int m=t.size();
    string tmp={};
    s.insert(t);
    for(int i=0;i<m-1;i++){
        tmp.push_back(t[i]);
        string tmp2=t.substr(i+1,m-i-1);
        string a=tmp,b=tmp2,arev=tmp,brev=tmp2;
        reverse(all(arev));reverse(all(brev));
        string a1,b1;
        a1=a;
        a1+=brev;
        b1=brev;
        b1+=a;
        s.insert(a1);
        s.insert(b1);
        a1=arev;
        b1=b;
        a1+=b;
        b1+=arev;
        s.insert(a1);
        s.insert(b1);
        a1=arev;
        b1=brev;
        a1+=brev;
        b1+=arev;
        s.insert(a1);
        s.insert(b1);
        b1=b;
        b1+=a;
        s.insert(b1);
    }
    cout<<s.size()<<"\n";
}
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

void panic() {
	puts("Impossible");
	exit(0);
}

int main(){

	int n = nxt();
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		a[i] = nxt();
	}
	sort(all(a));

	int d = a.back();
	int r = a[0];
	if (r != (d + 1) / 2) {
		panic();
	}

	vector<int> cnt(n);
	for (int x : a) {
		cnt[x]++;
	}

	for (int i = 0; i < n - 1; i++) {
		if (a[i + 1] - a[i] > 1) {
			panic();
		}
	}

	if (d % 2 == 0) {
		if (cnt[r] > 1) {
			panic();
		}
	} else {
		if (cnt[r] > 2) {
			panic();
		}
	}

	for (int i = r + 1; i <= d; i++) {
		if (cnt[i] < 2) {
			panic();
		}
	}

	puts("Possible");

	return 0;
}

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

int a, b, c;

int main(){
    scanf("%d%d", &a, &b);
    for(c = 1; c <= 100000; c++){
        if((int)(c*0.08) == a && (int)(c*0.1) == b){
            printf("%d\n", c);
            return 0;
        }
    }
    puts("-1");
    return 0;
}

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

struct state
{
  int f;
  int i, j;
  unsigned s;
  state() : f(0), i(-1), j(-1), s(0) {}
  state(int a, int b, int c, unsigned d) : f(a), i(b), j(c), s(d) {}
};

struct dungeon
{
  vector<string> grid;
  vector<vector<string> > moves;

  inline static int initial_floor(char c)
  {
    return c == '^' || isupper(c);
  }

  char get(const state& s) const
  {
    const char c = grid[s.i][s.j];
    if (c == '#' || c == '|') {
      return c;
    }
    int f = initial_floor(c);
    const int S = moves.size();
    for (int i = 0; i < S; i++) {
      const vector<string>& g = moves[i];
      if ((s.s & (1<<i)) && g[s.i][s.j] == '*') {
        f ^= 1;
      }
    }
    if (f == s.f) {
      return tolower(c);
    } else {
      return '#';
    }
  }
};

int main()
{
  int H, W;
  dungeon d;
  cin >> W >> H;
  d.grid.resize(H);
  state start;
  for (int i = 0; i < H; i++) {
    cin >> d.grid[i];
    for (int j = 0; j < W; j++) {
      if (d.grid[i][j] == '%') {
        start.i = i;
        start.j = j;
      }
    }
  }
  int S;
  cin >> S;
  for (int k = 0; k < S; k++) {
    vector<string> v(H);
    for (int i = 0; i < H; i++) {
      cin >> v[i];
    }
    d.moves.push_back(v);
  }

  static const int INF = 10000000;
  static int dist[2][50][50][1<<10];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < H; j++) {
      for (int k = 0; k < W; k++) {
        fill_n(dist[i][j][k], 1<<S, INF);
      }
    }
  }
  dist[start.f][start.i][start.j][start.s] = 0;
  queue<state> q;
  q.push(start);
  int ans = INF;
  while (!q.empty()) {
    const state s = q.front();
    q.pop();
    const int dd = dist[s.f][s.i][s.j][s.s] + 1;
    const char here = d.get(s);
    if (here == '&') {
      ans = min(ans, dd-1);
    }

    for (int i = 0; i < 4; i++) {
      static const int di[] = {-1, 1, 0, 0}, dj[] = {0, 0, -1, 1};
      const state t(s.f, s.i + di[i], s.j + dj[i], s.s);
      int& next = dist[t.f][t.i][t.j][t.s];
      if (d.get(t) != '#' && dd < next) {
        next = dd;
        q.push(t);
      }
    }

    if (here == '|') {
      const state t(s.f ^ 1, s.i, s.j, s.s);
      int& next = dist[t.f][t.i][t.j][t.s];
      if (dd < next) {
        next = dd;
        q.push(t);
      }
    } else if (isalpha(here)) {
      const int sw = here - 'a';
      int f = s.f;
      if (d.moves[sw][s.i][s.j] == '*') {
        f ^= 1;
      }
      const state t(f, s.i, s.j, s.s ^ (1<<sw));
      int& next = dist[t.f][t.i][t.j][t.s];
      if (dd < next) {
        next = dd;
        q.push(t);
      }
    }
  }
  if (ans == INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

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

string chmin (string& S, string T) {
  if (S > T) S = T;
  
  return S;
}

int main() {
  string S, T;
  
  cin >> S >> T;
  int M = S.size(), N = T.size();
  
  int Tstart = -1;
  string ans = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
  for (int i = 0; i + N - 1< M; i++) {
    bool cond = true;
    for (int j = 0; j < N; j++) {
      if (S[i+j] != T[j] && S[i+j] != '?') {
        cond = false;
        break;
      }
    }
    
    if (cond) {
      Tstart = i;
      string s;
      int k = 0;
      for (int j = 0; j < M; j++) {
        if (j >= i && j < i + N) {
          s += T[k];
          k++;
        } else if (S[j] == '?'){
          s += 'a';
        } else {
          s += S[j]; 
        }
      }
      ans = chmin(ans, s);
    }
    
  }
  if (Tstart == -1) {
    cout << "UNRESTORABLE" << endl;
  } else {
    cout << ans << endl;
  }
}

Measured memory_bytes: 3636
H,W=map(int,input().split())
if H%2==0:
    ans=(H//2)*W
else:
    if W%2==0:
        ans=((H//2)+1)*(W//2)+((H//2)+0)*(W//2)
    else:
        ans=((H//2)+1)*((W//2)+1)+((H//2)+0)*(W//2)

if H==1:
    ans=1
elif W==1:
    ans=1
elif H==2 and W==2:
    ans=2
print(ans)

Measured memory_bytes: 3064
function main(input) {
	const args = input.split('\n');
	const s = args[0];
	const K = parseInt(args[1], 10);
	var t = [];
	for(i=0;i<=s.length-1;i++){
		for(j=i+1;j<=i+5;j++){
			var x = s.slice(i,j);
			var d = 0;
			for(k=0;k<t.length;k++){
				if(t[k] === x){
					d = 1;
					break;
				}
			}
			if(d === 0){
				t.push(x);
				t.sort(function(a,b){
					if( a < b ) return -1;
					if( a > b ) return 1;
					return 0;
				});
				if(t.length >= 6){
					t = t.slice(0,5);
				}
			}
		}
	}
	var b = 0;
	var c = '';
	//console.log(t);
	for(i=0;i<t.length;i++){
		if(t[i] != c){
			b += 1;
			c = t[i];
		}
		if(K == b){
			console.log(c);
			break;
		}
	}
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 10264
#include <cstdio>
#include <algorithm>
#include <utility>
#include <set>

#define st first
#define nd second

using namespace std;

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

const int MAXN = 5E3 + 10, MAXM = 2E2 + 10;

int n, m;
int a[MAXN];
int b[MAXN][MAXM];
ll c[MAXN][MAXN];

PII lst[MAXN];

int main(){
	scanf("%d%d", &n, &m);
	for (int i = 1; i < n; ++i)
		scanf("%d", a + i);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			scanf("%d", b[i] + j);
	for (int i = 1; i <= m; ++i){
		set<int> st;
		st.insert(0), st.insert(n + 1);
		for (int j = 1; j <= n; ++j){
			lst[j] = PII(b[j][i], j);
			st.insert(j);
		}
		sort(lst + 1, lst + n + 1);
		for (int j = 1; j <= n; ++j){
			int u = lst[j].nd;
			auto p = st.find(u);
			int l = *prev(p) + 1, r = *next(p) - 1;
			st.erase(p);
			c[l][u] += lst[j].st, c[u + 1][r + 1] += lst[j].st;
			c[l][r + 1] -= lst[j].st, c[u + 1][u] -= lst[j].st;
		}
	}
	ll ans = 0;
	for (int i = 1; i <= n; ++i){
		for (int j = 1; j <= n; ++j)
			c[i][j] += c[i][j - 1];
		ll dist = 0;
		for (int j = i; j <= n; ++j){
			c[i][j] += c[i - 1][j];
			ans = max(ans, c[i][j] - dist);
			dist += a[j];
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 200320
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::ops::Bound::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

const M: usize = 1_000_000_007;

#[fastout]
fn main() {
    input! {
        n: usize,
    }

    let mut memo = HashMap::new();
    let ans = rec("TTT", n, &mut memo);
    println!("{}", ans);
}

fn rec(s: &str, count: usize, memo: &mut HashMap<(usize, String), usize>) -> usize {
    if let Some(&res) = memo.get(&(count, s.to_string())) {
        return res;
    }
    if count == 0 {
        return 1;
    }

    let mut res = 0usize;
    for c in "AGCT".chars() {
        let mut s = s.to_string();
        s.push(c);
        if is_valid(&s) {
            res += rec(&s[1..], count-1, memo);
            res %= M;
        }
    }
    memo.insert((count, s.to_string()), res);
    res
}

fn is_valid(s: &str) -> bool {
    if s.contains("GAC") || s.contains("ACG") || s.contains("AGC") {
        return false;
    }
    let s2 = "".to_string() + &s[0..1] + &s[2..];
    if s2 == "AGC" {
        return false;
    }
    let s2 = "".to_string() + &s[0..2] + &s[3..];
    if s2 == "AGC" {
        return false;
    }
    true
}

Measured memory_bytes: 2732
#include <iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a>b)
        cout<<"a > b"<<endl;
    else if(b>a)
        cout<<"a < b"<<endl;
    else
        cout<<"a == b"<<endl;
    return 0;
}


Measured memory_bytes: 3076
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
a=get_i
puts a.join(" ")
1.upto(N-1) do|i|
    min=a[i]
    j=i-1
    while j>=0 and a[j]>min
        a[j+1]=a[j]
        j-=1
    end
    a[j+1]=min
    puts a.join(" ")
end


Measured memory_bytes: 8904
import java.io.*;
import java.util.*;
public class Main{
  public static void main(String args[]) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String in = br.readLine();
    in = in.trim();
    String f[] = in.split(" ");
    int d = Integer.parseInt(f[0]);
    int t = Integer.parseInt(f[1]);
    int s = Integer.parseInt(f[2]);
    double calcT = (double)d/(double)s;
    double targetT = Double.valueOf(t);
    if(calcT <= targetT)
      System.out.println("Yes");
    else
      System.out.println("No");
  }
}


Measured memory_bytes: 32536
# Python3 code to find number of
# distinct numbers in a subarray
from sys import stdin,stdout
import sys
sys.setrecursionlimit(10**5)
MAX = 500001

def input():
    return stdin.readline().strip()
# structure to store queries
class Query:
    def __init__(self, l, r, idx):
        self.l = l
        self.r = r
        self.idx = idx


# updating the bit array
def update(idx, val, bit, n):
    while idx <= n:
        bit[idx] += val
        idx += idx & -idx


# querying the bit array
def query(idx, bit, n):
    summ = 0
    while idx:
        summ += bit[idx]
        idx -= idx & -idx
    return summ


def answeringQueries(arr, n, queries, q):
    # initialising bit array
    bit = [0] * (n + 1)

    # holds the rightmost index of
    # any number as numbers of a[i]
    # are less than or equal to 10^6
    last_visit = [-1] * MAX

    # answer for each query
    ans = [0] * q

    query_counter = 0
    for i in range(n):

        # If last visit is not -1 update -1 at the
        # idx equal to last_visit[arr[i]]
        if last_visit[arr[i]] != -1:
            update(last_visit[arr[i]] + 1, -1, bit, n)

        # Setting last_visit[arr[i]] as i and
        # updating the bit array accordingly
        last_visit[arr[i]] = i
        update(i + 1, 1, bit, n)

        # If i is equal to r of any query store answer
        # for that query in ans[]
        while query_counter < q and queries[query_counter].r == i:
            ans[queries[query_counter].idx] = \
                query(queries[query_counter].r + 1, bit, n) - \
                query(queries[query_counter].l, bit, n)
            query_counter += 1

    # print answer for each query
    for i in range(q):
        print(ans[i])


# Driver Code
if __name__ == "__main__":
    n, q = map(int, input().split())
    a = [int(k) for k in input().split()]
    queries = []
    for i in range(q):
        l, r = map(int, input().split())
        queries.append(Query(l-1, r-1, i))
    queries.sort(key=lambda x: x.r)
    answeringQueries(a, n, queries, q)

# This code is contributed by
# sanjeev2552


Measured memory_bytes: 180244
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
void slove(int question_num)
{
    int a[102]={0};
    for(int i=1;i<10;i++)
    {
        for(int j=1;j<10;j++)
            a[i*j]=1;
    }
    while(question_num--)
    {
        int n;cin>>n;
        if(a[n]) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}
int main()
{
//    int t;cin>>t;
    slove(1);
    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 main(){
  int n,h,ans=0;cin>>n>>h;
  vector<int> a(n,0),b(n,0);
  REP(i,n) cin>>a.at(i)>>b.at(i);
  sort(a.begin(),a.end(),greater<int>());
  sort(b.begin(),b.end(),greater<int>());

  REP(i,n) if(a.at(0)<b.at(i)){
    h-=b.at(i);
    ans++;
    if(h<=0) break;
  }
  if(h>0) ans+=(h+a.at(0)-1)/a.at(0);

  cout<<ans;
}

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

int main(){
  int N;
  cin >> N;
  for(int i=0;i<=N;i++){
    if(i==N){
    cout << "Three" << endl;
    continue;
    }
    string S;
    cin >> S;
    if(S=="Y"){
      cout << "Four"<< endl;
      break;
    }
  }
}


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

using namespace std;

#define fcout(d) cout << fixed << setprecision(d)
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rep1(i,n) for(int (i) = 1; (i) <= (n); ++(i))
#define repU(i,bottom,ceiling) for(int (i) = (bottom); (i) <= (ceiling); ++(i))
#define repD(i,ceiling,bottom) for(int (i) = (ceiling); (i) >= (bottom); --(i))
#define pub push_back
#define pob pop_back
#define prf printf
#define scf scanf
#define mkp make_pair
#define fir first
#define sec second
#define clr(a) memset((a),0,sizeof(a))
#define all(a)  begin((a)),end((a))

typedef long long ll;
typedef unsigned long long ull;
typedef double db;

const vector<pair<int,int>> DIR = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int INF = -1 + (1<<30);
const int MOD = (int)1e9 + 7;

template<typename T> inline T gcd(T a,T b){ if(a % b){ return gcd(b,a % b); }else{ return b; } }

template<typename T> inline T lcm(T a,T b){ return a / gcd(a,b) * b; }

inline long long Pow(const long long n,long long m,const int mod = MOD){
	long long res = 1,pow = n;
	while(m) {
		if(m & 1) res = (res * pow) % mod;
		pow = (pow * pow) % mod;
		m >>= 1;
	}
	return res;
}

inline vector<long long> Frac(const int range,const int mod = MOD){
	vector<long long> frac;
	frac.push_back(1);
	for(int i = 1; i <= range; ++i) frac.push_back((long long)frac.back() * i % mod);
	return frac;
}

inline long long Comb(const int n,const int m,const int mod = MOD){
	if(n < m || m < 0) return 0;
	vector<long long> frac(Frac(n,mod));
	long long rev = Pow((long long)frac[m] * frac[n-m] % mod,mod-2,mod);
	return rev * frac[n] % mod;
}

template<typename T> inline bool v_find(const vector<T> v,const T obj){
	auto itr = find(v.begin(), v.end(), obj);
	size_t index = distance(v.begin(),itr);
	if (index != v.size()) { return true; }
	return false; 
}

template<typename T> inline bool v_erase(vector<T> &v,const T obj){
	auto itr = find(v.begin(), v.end(), obj);
	size_t index = distance(v.begin(),itr);
	if (index != v.size()) {
		v.erase(itr);
		return true;
	}
	return false;	
}

template<class T,class U> inline auto LB(const T v,const U in){ return lower_bound(v.begin(),v.end(),in); }

template<class T,class U> inline auto UB(const T v,const U in){ return upper_bound(v.begin(),v.end(),in); }

inline unsigned long long next_subset(unsigned long long subset){
	unsigned long long tem = subset + (subset & -subset);
	unsigned long long btm = (~tem & subset) / (subset & -subset) >> 1;
	return btm | tem;
}
ll n,a[100001];
inline void solve(){
	cin>>n;
	rep(i,n) cin>>a[i];
	sort(a,a+n);
	cout<<a[n-1]-a[0];

	return;
}

inline void input(){
	

	return;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	input();
	solve();
	return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
//n以下の素数列挙(O(nloglogn))
vector<long> primes(long n){
    bool judge[n+1];
    for(int i = 0;i<=n;i++){
        judge[i] = true;
    }
    vector<long> prime;
    for(int i = 2;i<=n;i++){
        if(judge[i]){
            for(int j = 2*i;j<=n;j+=i){
                judge[j] = false;
            }
            prime.push_back(i);//ここでprimeに入れられる素数の条件を指定できる
        }
    } 
    return prime;
}
int main(){
    long long n,p;
    cin >> n >> p;
    vector<long> prs = primes(long(sqrt(p))+2);
    map<long,int> mp;
    for(int i = 0;i<prs.size();i++){
        mp[prs[i]] = 0;
        while(p%prs[i]==0){
            mp[prs[i]]++;
            p/=prs[i];
        }
    }
    long long ans = 1;
    if(n==1) ans*=p;
    for(int i = 0;i<prs.size();i++){
        if(mp[prs[i]]>=n){
            for(int j = 0;j<mp[prs[i]]/n;j++){
                ans*=prs[i];
            }
        }
    }
    cout << ans << endl;     
}

Measured memory_bytes: 6772
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>
#include <bitset>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

int main(int argc, char const* argv[])
{
  int n, k;
  cin >> n >> k;
  vector<ll> a;
  vector<ll> sum, psum;
  for(int i = 0; i < n; i++){
    ll x;
    cin >> x;
    a.pb(x);
    if(i == 0){
      sum.pb(x);
      psum.pb(max((ll)0, x));
    }else{
      sum.pb(sum[i - 1] + x);
      psum.pb(psum[i - 1] + max((ll)0, x));
    }
  }
  ll res = -linf;
  for(int i = 0; i + k <= n; i++){
    ll tmp = 0;
    if(i > 0)tmp += psum[i - 1];
    tmp += psum[n - 1] - psum[i + k - 1];
    res = max(res, tmp);
    tmp += sum[i + k - 1];
    if(i > 0)tmp -= sum[i - 1];
    res = max(res, tmp);
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 2912
#include <iostream>

int main() {
  int M = 0;
  int D = 0;
  std::cin >> M >> D;

  int d2 = D/10;
  int d1 = D - d2 * 10;
  int count = 0;

  // std::cout << "d2 : " << d2 << std::endl;
  // std::cout << "d1 : " << d1 << std::endl;
  // std::cout << "________________"  << std::endl;


  for(int i = 1; i <= M; i++ )
  {
    for(int j = 2; j <= d2; j++)
    {
      for(int k = 2; k <= 9; k++)
      {
        if( (j >= d2) && (k > d1) )
        {
          break;
        }
        if( i == j*k )
        {
          // std::cout << "**************"  << std::endl;
          // std::cout << "i : " << i << std::endl;
          // std::cout << "j : " << j << std::endl;
          // std::cout << "k : " << k << std::endl;
          // std::cout << "**************"  << std::endl;
          count++;
        }


      }
    }
  }
  // std::cout << "________________"  << std::endl;
  // std::cout << "count : " <<count << std::endl;
  std::cout  <<count << std::endl;

}


Measured memory_bytes: 256
n = int(input())
x = list(map(int,input().split()))
y = list(x)
y.sort()
z = n // 2 - 1
a = y[z]
b = y[z + 1]
for i in x:
    if i <= a :
        ans = b
    else:
        ans = a
    print(ans)


Measured memory_bytes: 26016
#include <iostream>
#include <map>
#include <string>
using namespace std;

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

    for(int i=0; i<s.size(); i++){
        int d = int(s[i] - 'A' + n)%26 + 'A';
        printf("%c", d);
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
char s[10];
bool check()
{
    for (int i = 0; i < 3; ++ i)
        if (s[i] == s[i + 1])return false;
    return true;
}
void slove()
{
    scanf("%s" ,s);
    if (check()) puts("Good");
    else puts("Bad");
    return ;
}
signed main()
{
    slove();
    return 0;
}


Measured memory_bytes: 256
import sys
n = int(input())
a = list(map(int, input().split()))

nl = sum(a)

tmp = 1
l = 0
ans = 0
for ai in a:
    ans += tmp
    if tmp < ai:
        print(-1)
        sys.exit()
    tmp -= ai
    l += ai
    if l + 2 * tmp <= nl:
        tmp *= 2
    else:
        tmp = nl - l

print(ans)


Measured memory_bytes: 19996
n=int(input())
arr=[input() for _ in range(n)]
dic={}

for i in range(n): #各単語の出現回数を数える
    if arr[i] not in dic:
        dic[arr[i]]=1
    else:
        dic[arr[i]]+=1

largest=max(dic.values()) #最大の出現回数を求める
ans=[]

for keys in dic.keys():
    if dic[keys]==largest: #出現回数が最も多い単語を集計する
        ans.append(keys)

ans=sorted(ans) #単語を辞書順に並べ替えて出力する
for words in ans:
    print(words)

Measured memory_bytes: 35216
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T>
struct Kruskal{
  
  struct edge{
    Int from,to;
    T cost;
    Int used;
    edge(){}
    edge(Int from,Int to,T cost):
      from(from),to(to),cost(cost),used(0){}
    bool operator<(const edge& e) const{
      return cost<e.cost;
    }
  };

  Int n;
  vector<Int> p,r;
  vector<edge> edges;

  Kruskal(){}
  Kruskal(Int n):n(n){}

  void init(Int n){
    r.assign(n,1);
    p.resize(n);
    iota(p.begin(),p.end(),0);
  }
  
  Int find(Int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }

  bool same(Int x,Int y){
    return find(x)==find(y);
  }

  void unite(Int x,Int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }

  void add_edge(Int u,Int v,T c){
    edges.emplace_back(u,v,c);
  }
  
  T build(){
    sort(edges.begin(),edges.end());
    init(n);
    T res=0;
    for(auto &e:edges){
      if(!same(e.from,e.to)){
        res+=e.cost;
        unite(e.from,e.to);
        e.used=1;
      }
    }
    return res;
  }
};


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  Int n,d;
  cin>>n>>d;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  Kruskal<Int> ks(n);
  using P = pair<Int, Int>;

  const Int INF = 1e18;
  vector<P> ls(n,P(INF,-1)),rs(n,P(INF,-1)),dp(n);
  function<void(Int, Int)> dfs=
    [&](Int l,Int r)->void{
      if(l+1==r){
        dp[l]=P(a[l],l);
        return;
      }
      Int m=(l+r)>>1;      
      dfs(l,m);
      dfs(m,r);
      P x(INF,-1),y(INF,-1);
      for(Int i=l,j=m;i<m||j<r;){
        if(i<m&&(j==r||dp[i].first<=dp[j].first)){
          Int k=dp[i++].second;
          chmin(rs[k],y);
          chmin(x,P(a[k]-k*d,k));
        }else{
          Int k=dp[j++].second;
          chmin(ls[k],x);
          chmin(y,P(a[k]+k*d,k));
        }
      }
      
      inplace_merge(dp.begin()+l,dp.begin()+m,dp.begin()+r);
    };  
  dfs(0,n);
  
  auto add_edge=
    [&](Int x,Int y){
      if(x<0||y<0) return;
      Int c=abs(x-y)*d+a[x]+a[y];
      ks.add_edge(x,y,c);
    };
  for(Int i=0;i<n;i++) add_edge(ls[i].second,i);
  for(Int i=0;i<n;i++) add_edge(i,rs[i].second);

  cout<<ks.build()<<endl;
  return 0;
}


Measured memory_bytes: 33616
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

def main():
    n = int(input())
    p = list(map(int, input().split()))
    ans = 1
    minimum = p[0]
    for i in range(1, n):
        if minimum >= p[i]:
            ans += 1
            minimum = p[i]
    print(ans)

main()

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

int main () {
  int N, A, X;
  cin >> N >> A;
  X = N / 500;
  
  if (N - 500*X <= A) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#include <list> 
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll getDigit(ll n) {
	ll cnt = 0;
	while (n != 0) {
		n /= 10;
		cnt++;
	}
	return cnt;
}
int main() {
	ll r, g, b, n,cnt = 0;
	cin >> r >> g >> b >> n;
	for (ll i = 0; i <= n; i++){
		for (ll k = 0; k <= n-r*i; k++) {
			if (n - (r * i + g * k) < 0)break;
			if ((n - (r * i + g * k)) % b == 0)cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{	int X, N;
	int num[102] = {0};
	int i, tmp, sub, ans;

	scanf("%d %d", &X, &N);

	if (N == 0)
	{
		printf("%d\n", X);
		return (0);
	}

	for (i = 0; i < N; i++)
	{
		scanf("%d", &tmp);
		num[tmp]++;
	}

	i = 101;
	sub = 102;
	while (0 <= i)
	{
		if (0 < num[i])
		{
			i--;
			continue;
		}
		tmp = X - i;
		if (tmp < 0)
			tmp *= -1;
		if (tmp <= sub)
			ans = i;
		else
			break;
		sub = X - i;
		if (sub < 0)
			sub *= -1;
		i--;
	}
	printf("%d\n", ans);

	return (0);
}


Measured memory_bytes: 1716
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl

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

    for(int i=n; i<1000; i++){
        int tmp = i%10;
        int tmp2 = i/10%10;
        int tmp3 = i/100;
        if(tmp==tmp2 && tmp2 == tmp3){
            cout << i << endl;
            return 0;
        }
    }
}

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

void chmax(ll& a, ll b) { if (a < b) a = b; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> p(n);
  rep(i, n) {
    int a;
    cin >> a;
    p[i] = make_pair(a, i);
  }
  sort(p.rbegin(), p.rend());
  
  vector<vector<ll>> dp(2005, vector<ll>(2005, 0ll));
  rep(i, n) {
    for (int j = 0; j+i < n; ++j) {
      int k = i+j;
      chmax(dp[i+1][j], dp[i][j] + 1ll*p[k].first*abs(p[k].second-i));
      chmax(dp[i][j+1], dp[i][j] + 1ll*p[k].first*abs(n-1-j-p[k].second));
    }
  }
  ll ans = 0;
  rep(i, n) chmax(ans, dp[i][n-i]);
  cout << ans << endl;
}

Measured memory_bytes: 34600
import heapq

N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]

ans = 0
for i in range(N):
    for j in range(N):
        via_k = float('inf')
        for k in range(N):
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                exit()
            if k == i or k == j:
                continue
            via_k = min(via_k, A[i][k] + A[k][j])
        if i <= j:
            continue
        if A[i][j] < via_k:
            ans += A[i][j]
print(ans)


Measured memory_bytes: 75412
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
string s,a;
getline(cin,s);
a+=s[0];
for(int i=1;i<s.length();i++)
{
    if(s[i]==' ')
    {
        a+=s[i+1];
    }
}
cout<<a;
return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;




int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

	ll n,x=1;
	cin>>n;
	while(x<=n)
		x=x<<1LL;
	cout<<x-1<<"\n";
		

}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
pl=1
visit=[-1]*n
visit[0]=0
loop=0
cnt=0

while 1:
    cnt+=1
    pl=a[pl-1]
    if visit[pl-1]!=-1:
        loop=visit[pl-1]
        break
    visit[pl-1]=cnt
    if cnt==k:
        print(pl)
        exit()

loop_len=cnt-loop
k=(k-loop)%loop_len+loop
print(visit.index(k)+1)

Measured memory_bytes: 32380
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

int n;
const int V_MAX = 305;
ll d[V_MAX][V_MAX];

void warshall_floyd(){
    for(int k = 0; k < n; k++){
        for(int i = 0; i < n; i++){
            if(d[i][k] == INF) continue;
            for(int j = 0; j < n; j++){
                if(d[k][j] == INF) continue;
                d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
            }
        }
    }
}

int main()
{
    int h,w;
    n = 10;
    cin >> h >> w;
    int a[h][w];
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            cin >> d[i][j];
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
        }
    }
    warshall_floyd();
    ll ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(a[i][j] == -1) continue;
            else ans += d[a[i][j]][1];
        }
    }
    cout << ans << endl;
}   

Measured memory_bytes: 384
import math
K=int(input())
c = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      if i == j == k:
        c += i
      elif i == j:
        c += math.gcd(i,k)
      elif i == k:
        c += math.gcd(i,j)
      elif j == k:
        c += math.gcd(i,k)
      else:
        c += math.gcd(math.gcd(i, j), k)
print(c)

Measured memory_bytes: 73180
if __name__ == '__main__':
	while True:
		try:
			x1,y1,x2,y2,x3,y3,xp,yp = map(float,raw_input().split())
			r = 0
			vec = (x2 - x1) * (yp - y1) - (y2 - y1) * (xp - x1)
			if vec > 0:
				r += 1
			elif vec < 0:
				r -= 1
			vec = (x3 - x2) * (yp - y2) - (y3 - y2) * (xp - x2)
			if vec > 0:
				r += 1
			elif vec < 0:
				r -= 1
			vec = (x1 - x3) * (yp - y3) - (y1 - y3) * (xp - x3)
			if vec > 0:
				r += 1
			elif vec < 0:
				r -= 1
			if r == 3 or r == -3:
				print("YES")
			else:
				print("NO")
		except EOFError:
			break

Measured memory_bytes: 4272
from collections import Counter

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    n = ii()
    v = list(mi())
    ve = [v[i] for i in range(n) if i%2==0]
    vo = [v[i] for i in range(n) if i%2==1]

    ce = Counter(ve)
    co = Counter(vo)

    if ce.most_common()[0][0] == co.most_common()[0][0]:
        if len(ce.most_common()) > 1 and len(co.most_common()) > 1:
            if ce.most_common()[1][1] > co.most_common()[1][1]:
                ne = ce.most_common()[1][1]
                no = ce.most_common()[0][1]
            else:
                ne = ce.most_common()[0][1]
                no = co.most_common()[1][1]
        else:
            ne = ce.most_common()[0][1]
            no = 0
    else:
        ne = ce.most_common()[0][1]
        no = co.most_common()[0][1]

    print(n-ne-no)

if __name__ == '__main__':
    main()

Measured memory_bytes: 113812
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

int n;
int sum[100010];

signed main(){
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n){
        cin >> a[i];
    }
    vector<P> m;
    vector<int> ans(n, 0);
    int MAX = 0;
    rep(i, 0, n){
        if(a[i] > MAX){
            MAX = a[i];
            m. push_back(P(a[i], i));
        }
    }
    sort(all(a));
    sort(all(m));
    repb(i, n - 1, 0){
        sum[i] += sum[i + 1] + a[i];
    }
    int now = 0;
    repb(i, m.size() - 1, 0){
        int limit = (i == 0 ? 0 : m[i - 1].first);
        int idx = upper_bound(all(a), limit) - a.begin();
        int tmp = sum[idx] - now - limit * (n - idx);
        now += tmp;
        ans[m[i].second] = tmp;
    }
    rep(i, 0, n){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 5104
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

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

using namespace std;
ll GCD(ll x, ll y){
  ll r;
  if(x<y){
    r=x;
    x=y;
    y=r;
  }
  r = x % y;
  while(r!=0){
    x = y;
    y = r;
    r = x%y;
  }
  return y;
}

int main(int argc, const char * argv[]) {
  ll A,B,C,D;
  ll i,j;
  cin >> A >> B >> C >> D;
  ll L,G;
  G = GCD(C,D);
  L = C*D/G;
  ll ans = B - A + 1;
  ans += B/L;
  ans -= (A-1)/L;
  ans -= (B/C+B/D);
  ans += ((A-1)/C+(A-1)/D);
  
  
  cout << ans;
  return 0;
}

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

int H,W;

vector<pair<int,int> > G[1000000];
int d[1000000];

void bfs(int Ch, int Cw){
    fill(d,d+1000000,-1);
    int v=Ch*W+Cw;
    deque<pair<int,int> > deq;
    deq.push_back(make_pair(v,0));
    pair<int,int> pa;
    int from,to,cost,zeroone;
    int i;
    while(!deq.empty()){
        pa= deq.front();
        deq.pop_front();
        from=pa.first;
        cost=pa.second;
        if(d[from]>=0) continue;
        d[from]=cost;
        for(i=0; i<G[from].size(); i++){
            pa=G[from][i];
            to=pa.first;
            zeroone=pa.second;
            if(d[to]<0){
                if(zeroone==0){
                    deq.push_front(make_pair(to,cost));
                }else{
                    deq.push_back(make_pair(to,cost+1));
                }
            }
        }
    }
}

int main(){
    cin >> H >> W;
    int Ch, Cw, Dh, Dw;
    cin >> Ch >> Cw >> Dh >> Dw;
    Ch--;
    Cw--;
    Dh--;
    Dw--;
    string S[H];
    int i,j,k,l;
    for(i=0; i<H; i++){
        cin >> S[i];
    }
    for(i=0; i<H; i++){
        for(j=0; j<W; j++){
            if(i>=1){
                if(S[i][j]=='.'&&S[i-1][j]=='.'){
                    G[i*W+j].push_back(make_pair((i-1)*W+j,0));
                }
            }
            if(i<=H-2){
                if(S[i][j]=='.'&&S[i+1][j]=='.'){
                    G[i*W+j].push_back(make_pair((i+1)*W+j,0));
                }
            }
            if(j>=1){
                if(S[i][j]=='.'&&S[i][j-1]=='.'){
                    G[i*W+j].push_back(make_pair(i*W+j-1,0));
                }
            }
            if(j<=W-2){
                if(S[i][j]=='.'&&S[i][j+1]=='.'){
                    G[i*W+j].push_back(make_pair(i*W+j+1,0));
                }
            }
            for(k=max(i-2,0); k<=min(i+2,H-1); k++){
                for(l=max(j-2,0); l<=min(j+2,W-1); l++){
                    if(S[i][j]=='.'&&S[k][l]=='.'){
                        G[i*W+j].push_back(make_pair(k*W+l,1));
                    }
                }
            }
        }
    }
    bfs(Ch,Cw);
    cout << d[Dh*W+Dw] << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 122276
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;
map<ll, int> m;

int main() {
    cin >> n;
    rep(i, n) {
        ll a; cin >> a;
        m[a]++;
    }
    ll ans = 0;
    for (auto kv: m) {
        ll k = kv.first;
        int v = kv.second;
        if (k > v) ans += v;
        else if (k < v) ans += (v - k);
    }
    cout << ans << endl;
}


Measured memory_bytes: 6272
#include<iostream>
#include<algorithm>

int N;

int count(int a) {
  int lsd = a%10;
  if(lsd == 0) return 0;
  int msd = a; while(msd >= 10) msd/=10;
  int res = 0;
  if(lsd == msd) ++res; //1-digit
  int k = lsd*10;
  if(k + msd <= N) ++res; //2-digit
  int d=10;
  k *= 10;
  while(k + msd <= N) {
    res += std::min(d, (N-(k+msd))/10 + 1);
    d *= 10;
    k *= 10;
  }
  return res;
}

int main() {
  std::cin >> N;
  int ans = 0;
  for(int i = 1; i <= N; ++i) ans += count(i);
  std::cout << ans << std::endl;
  return 0;
}


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


void solve(long long N, std::vector<long long> d){
    sort(d.begin(), d.end());
    if(N % 2 != 0){
        cout<<0<<endl;
    }else{
        cout<<d.at(N/2) - d.at(N/2-1)<<endl;
    }
}

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


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int fIndex = S.indexOf("A");
		int lIndex = S.lastIndexOf("Z");
		System.out.println(S.substring(fIndex, lIndex + 1).length());

	}
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}


const int MAX_N = 500000 + 10;
int dp[MAX_N];
int len[MAX_N];

int main2() {
  int N; cin >> N;
  string s; cin >> s;

  memset(dp, 0, sizeof(dp));
  
  {
    int c = 0;
    for (int i = 0; i < N; i++) {
      if (s[i] == '1') {
        c++;
      } else {
        c = 0;
      }
      len[i] = c;
    }
    // pv(len, len + N);
  }

  for (int i = 2; i < N; i++) {
    chmax(dp[i], dp[i-1]);
    if (s[i-2] == '1' && s[i-1] == '0' && s[i] == '1') {
      for (int j = i - 2; j >= 0 && s[j] == '1'; j--) {
        chmax(dp[i], (i-1-j) + (j-1 >= 0 ? dp[j-1] : 0));
      }
    }
    if (s[i] == '1') {
      if (i - len[i] >= 0 && s[i - len[i]] == '0' && 
          i - len[i] - 1 >= 0 && s[i-len[i] - 1] == '1') 
        {
          chmax(dp[i], len[i] + (i-len[i]-2 >= 0 ? dp[ i - len[i] - 2 ] : 0) );
        }
      }
  }
  // pv(dp, dp + N);
  cout << dp[N-1] << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



Measured memory_bytes: 4740
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf_char=vector<vector<char>>;
using Graf_int=vector<vector<int>>;
#define MAX 100000

int main()
{
    int n;
    cin >> n;
    vector<ll> h(n);
    rep(i,n){
        cin >> h[i];
    }
    int max_=0;
    int tmp=0;
    rep(i,n-1){
        if(h[i]>=h[i+1]){
            tmp++;
        }else{
            max_=max(max_,tmp);
            tmp=0;
        }
    }
    max_=max(max_,tmp);
    cout << max_ << endl;
}

Measured memory_bytes: 4048
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>     // pow
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

// long long gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a;
// }

// int binary_search(int key) {
//     int ng = -1;
//     int ok = (int)a.size();
//     while(abs(ok - ng) > 1) {
//         int mid = (ok + ng) / 2;
//         if(isOK(mid, key))
//             ok = mid;
//         else
//             ng = mid;
//     }
//     return ok;
// }

// cout << fixed << setprecision(10);
// vector<vector<int>> vec(H, vector<int>(W))    // int H*W
// int MOD = 1000000007;

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

    vector<char> C;
    for(int i=0; i<N; i++){
        C.push_back('a'+i);
    }
    
    vector<string> ans = {"a"};
    for(int i=1; i<N; i++){
        vector<string> tmp;
        for(string x: ans){
            map<char, int> M;
            char last = 'a' - 1;
            for(char c: x){
                M[c] = 1;
                last = max(last, c);
            }
            for(auto m:M){
                tmp.push_back(x+m.first);
            }
            char extra = last + 1;
            tmp.push_back(x+extra);
        }
        ans = tmp;
    }

    for(auto a:ans){
        cout<<a<<endl;
    }

}

Measured memory_bytes: 5876