akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <list>
using namespace std;

int main() {
    int n; scanf("%d",&n);
    list<int> v;
    for(int i=0;i<n;i++){
        char com[15]; int x; scanf("%s",com);
        if(com[0]=='i'){
            scanf("%d",&x); v.push_front(x);
        }
        else if(com[6]=='F'){
            v.pop_front();
        }
        else if(com[6]=='L'){
            v.pop_back();
        }
        else if(com[0]=='d'){
            scanf("%d",&x);
            for(list<int>::iterator itr=v.begin();itr!=v.end();++itr){
                if(*itr==x){v.erase(itr); break;}
            }
        }
    }
    int i=0;
    for(list<int>::iterator itr=v.begin();itr!=v.end();++itr){
        if(i++) cout << " ";
        cout << *itr;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 34372
use std::io::*;
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let mut sc = Scanner::new(cin.lock());

    loop {
        let h: usize = sc.next();
        let w: usize = sc.next();

        if h == 0 && w == 0 {
            break;
        }

        for _ in 0..h {
            println!("{}", "#".repeat(w));
        }
        println!();
    }
}

/* ========== Scanner ========== */

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.next::<String>().chars().collect()
    }
}



Measured memory_bytes: 5028
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

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

    cout << (double)3.141592 * 2 * r << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	vector<string> s(3);
	rep(i,3) cin>>s[i];
	int now=0;
	while(true){
		if(s[now].empty()){
			char ans='A'+now;
			cout<<ans<<endl;
			return 0;
		}
		int ne=s[now][0]-'a';
		s[now].erase(begin(s[now]));
		now=ne;
	}
}

Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

S = P[:X] + Q[:Y]
S.sort(reverse=True)

S_wa = []
wa = 0
for s in S[::-1]:
    wa += s
    S_wa.append(wa)
# print(S_wa)
big = S_wa[-1]
ans = S_wa[-1]

R_wa = []
wa = 0
for r in R:
    wa += r
    R_wa.append(wa)
# print(R_wa)

kazu = min(len(R_wa), len(S_wa))

for i in range(kazu):
    ans = max(ans, big + R_wa[i] - S_wa[i])
print(ans)


Measured memory_bytes: 115784
import itertools
import math

N=int(input())
pos=[list(map(int,input().split())) for _ in range(N)]
Cases=itertools.permutations([x for x in range(N)])

ans=0
for case in Cases:
    for i in range(N-1):
        x,y=map(int,pos[case[i]])
        nx,ny=map(int,pos[case[i+1]])
        tmp=math.sqrt((nx-x)**2+(ny-y)**2)
        ans+=tmp
ans/=math.factorial(N)
print(ans)


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

int main(){
    int N, L;
    cin >> N >> L;
    int res = 1000;
    int r;
    int ans = 0;
    for(int i = 1; i <= N; ++i){
        ans += L + i - 1;
        if(res > abs(L + i - 1)){
            res = abs(L + i - 1);
            r = i;
        }
    }
    cout << ans - (L + r - 1) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int digit=0,count=0,num,jud;

  scanf("%d",&num);
  while(num != 0){
    jud = num;
    while(jud!=0){
      jud /= 10;
      ++digit;
    }
    if(digit%2 != 0) count++;
    num--;
    digit = 0;
  }

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

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n + 1);
  int x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a[x]++;
  }
  sort(a.begin(), a.end(), greater<int>());
  int ans = n;
  for (int i = 0; i < k; i++) {
    ans -= a[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

def main():
    n=I()
    w=L()
    right=0
    heavy=0
    mini=1e+7
    for i in range(1,n+1):
        right=0
        heavy=0
        for j in range(len(w)):
            if j+1<=i:
                right+=w[j]
            else:
                heavy+=w[j]
        mini=min(mini,abs(heavy-right))
    print(mini)

if __name__=='__main__':
    main()

Measured memory_bytes: 3064
def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        x, y = y, x % y
    return x

a,b,c,d = map(int,input().split())
lcm = (c*d) // gcd(c, d)
ans = b - a + 1
cdiv = b // c - (a-1) // c
ddiv = b // d - (a-1) // d
cddiv = b // lcm - (a-1) // lcm
#print(ans, cdiv, ddiv, cddiv, lcm)
ans -= cdiv + ddiv - cddiv
print(ans)


Measured memory_bytes: 3060
N = int(input())
char_cnt = {}
check = {}

for c in input():
    if c in char_cnt:
        char_cnt[c] += 1
    else:
        char_cnt[c] = 1
        check[c] = 1

for i in range(N - 1):
    s = input()
    cnt = {}
    for c in s:
        if c in cnt:
            cnt[c] += 1
        else:
            cnt[c] = 1
    for c, n in cnt.items():
        if c in char_cnt:
            char_cnt[c] = min(char_cnt[c], cnt[c])
            check[c] += 1

ans = ""
for c, n in sorted(char_cnt.items(), key=lambda x:x[0]):
    if check[c] == N:
        for i in range(n):
            ans += c
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int D, G;
    cin >> D >> G;
    G /= 100;
    vector<int> p(D), c(D);
    REP(i, D) {
        cin >> p.at(i) >> c.at(i);
        c[i] /= 100;
    }

    int ans = INF;
    REP(bit, 1 << D) {
        int g = G;
        int tmp = 0;
        REP(i, D) {
            int mask = 1 << i;
            if (mask & bit) {
                g -= (p[i] * (i + 1) + c[i]);
                tmp += p[i];
            }
        }
        // cout << bit << " " << g << " " << tmp << endl;
        for (int i = (D - 1); i >= 0; i--) {
            if (g <= 0) break;
            int mask = 1 << i;
            if ((mask & bit) == 0) {
                if (g > p[i] * (i + 1)) {
                    g -= p[i] * (i + 1);
                    tmp += p[i];
                } else {
                    tmp += (g + i) / (i + 1);
                    g = 0;
                    break;
                }
            }
        }
        // cout << bit << " " << g << " " << tmp << endl;
        if (g <= 0) {
            chmin(ans, tmp);
        }
    }

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


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

class Program
{
    static void Main(string[] args)
    {
        //入力
        var arr = arrInt();
        if (arr[0] + arr[1] + arr[2] >= 22) Console.WriteLine("bust");
        else Console.WriteLine("win");

    }

   

    //入力受け取り用
    static string crS() { return Console.ReadLine(); }
    static int crI() { return int.Parse(Console.ReadLine()); }
    static int[] arrInt(){return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();}
    static long[] arrLong(){ return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray(); }
    static string[] arrStr(){return Console.ReadLine().Split(' ').ToArray();}

}

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

//#define int long long
const int MOD = 2019;
using ll = long long;
using intpair = pair<int, int>;
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

int modpow(int a, int n){
    ll ret = 1;
    while(n>0){
        if(n&1) ret = (ret*a) % MOD;
        a = (a*a) % MOD;
        n >>= 1;
    }
    return ret % MOD;
}

signed main(){
    string s;
    cin >> s;
    
    int n = (int)s.length();
    
    vector<ll> t(n+1);
    t[n] = 0;
    
    for(int i = n-1; i >= 0; --i){
        t[i] = mod((ll)(s[i]-'0') * modpow(10,n-1-i) + t[i+1]);
    }
    
    map<int, ll> m;
    for(ll i : t) m[i]++;
    
    ll ans = 0;
    for(auto [mod, p] : m){
        ans += p*(p-1)/2;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 5164
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list -- START --
def summarizeList(l):
  sl=sorted(l)

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res
# Summarize count of factor within list --- END ---

def main():
  n=I()
  A=LI()

  A=[0]+A
  for i in range(n):
    A[i+1]+=A[i]

  ans=A.count(0)-1

  sl=summarizeList(A)
  # print(sl)
  for x,c in sl:
    if x==0:
      ans+=(c-1)*(c-2)//2
      continue

    ans+=c*(c-1)//2

  return ans

# main()
print(main())


Measured memory_bytes: 44096
import scala.collection.mutable
import scala.io.StdIn._

case class Edge(from: Int, to: Int, cost: Int)

object Main extends App {
  val n = readInt()
  val d = mutable.Seq.fill(n, n)(Int.MaxValue)
  var edges = mutable.Seq.fill(n)(Seq.empty[Edge])

  for (i <- 0 until n) {
    val costs = readLine().tail.split(" ")
    for (j <- costs.indices) {
      if (costs(j) != "-1") {
        d(i)(j) = costs(j).toInt
        edges(i) :+= Edge(i, j, costs(j).toInt)
      }
    }
  }

  val searched = mutable.Seq.fill(n)(false)
  val parents = mutable.Seq.fill(n)(-1)
  val distances = mutable.Seq.fill(n)(Int.MaxValue)
  distances(0) = 0
  val que = mutable.PriorityQueue(0)(Ordering.by((x: Int) => distances(x)).reverse)

  while (que.nonEmpty) {
    val from = que.dequeue()
    if (!searched(from)) {
      searched(from) = true
      edges(from).foreach(e => {
        val to = e.to
        if (!searched(to) && distances(to) > d(from)(to)) {
          distances(to) = d(from)(to)
          parents(to) = from
        }
        que.enqueue(to)
      })
    }
  }

  val s = parents.zipWithIndex
    .foldLeft(0)((acc, z) =>
      z match {
        case (p, i) if p != -1 => acc + d(i)(p)
        case _ => acc
      })

  println(s)
}

Measured memory_bytes: 67060
from operator import itemgetter
n =int(input())
x =[]
l =[]

for i in range(n):
    x1,l1 = [int(i) for i in input().split()]
    x.append(x1)
    l.append(l1)

min = []
max = []
for i in range(n):
    min1, max1 = (x[i]-l[i],x[i]+l[i])
    min.append(min1)
    max.append(max1)

minmax= sorted([(min[i],max[i])for i in range(n)], key=itemgetter(1))
ans = 0
T = -1000000000
for i in range(n):
    if T<=minmax[i][0]:
        ans +=1
        T = minmax[i][1]
print(ans)
    

Measured memory_bytes: 28484
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int main() {
    int n ,m , x, y; cin >> n >> m >> x >> y;
    vector<int> a(n+1), b(m+1);
    a[n] = x;
    b[m] = y;
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];

    if (*min_element(all(b)) <= *max_element(all(a))){
        print("War");
    }else{
        print("No War");
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

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


		try{
long  x=sc.nextLong();
 long k=sc.nextLong();
long d=sc.nextLong();
long steps=Math.abs(x)/d;
long remaining=k-steps;

long ans=0;
if(x>=0) {

if(k>=steps) {
	ans=x%d;
	if(remaining%2==0) {
		ans=ans;
	}else {
		ans-=d;
	}
	System.out.println(Math.abs(ans));
}else {
	x-=k*d;
	System.out.println(Math.abs(x));

}
}else {
	if(k>=steps) {
		ans=x+steps*d;
		if(remaining%2==0) {
		ans=ans;
		}else {
			ans+=d;
		}
		System.out.println(Math.abs(ans));
	}else {
		x+=k*d;
		System.out.println(Math.abs(x));
	}
}
		}catch(Exception e){
		    return;
		}
	}

}


Measured memory_bytes: 35752
#include <iostream>
#include <vector>
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;


int solve(vector<int> a, int n) {
    int ptr = 0;
    int cnt = 0;
    rep (i, n) {
        ptr = a[ptr]; cnt++;
        if (ptr == 1) return cnt;
    }
    return -1;
}


int main() {
    int n; cin >> n;
    vector<int> a(n); rep(i, n) cin >> a[i];
    rep (i, n) --a[i];
    cout << solve(a, n) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){

    long long int testcase;
    long long int total = 1;
    long long int A[100005]; //A untuk angka
    bool lanjut = true;
    bool printtotal = true;
    scanf("%lld", &testcase);
   
    
    for (long long int i = 1; i <= testcase; i++){ //kalau ada 0 auto
        scanf("%lld", &A[i]);
        if(A[i]==0){
            printf("0\n");
            lanjut = false;
            break;
        }
    }
    
      if(lanjut){
          for(int i = 1; i<=testcase;i++){
              if(1000000000000000000/total >= A[i]){
                  total *= A[i];
            }
            else{
                printf("-1\n"); //kelebihan dari 10^18
                printtotal = false;
                break;
            }    
        }    
        if(printtotal){   //kalau tidak print
            printf("%lld\n",total);
        }
    }
    return 0;
}

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

bool match(vector<string> nv, vector<string> mv, int x, int y){
	for(int i=0; i<mv.size(); i++){
		for(int j=0; j<mv.size(); j++){
			if(mv[i][j] != nv[x+i][y+j]) return false;
		}
	}
	return true;
}

int main(){
	int n, m;
	cin >> n >> m;
	vector<string> nv(n);
	vector<string> mv(m);
	string s;
	for(int i=0; i<n; i++){
		cin >> s;
		nv[i] = s;
	}
	for(int i=0; i<m; i++){
		cin >> s;
		mv[i] = s;
	}
	for(int i=0; i<n-(m-1); i++){
		for(int j=0; j<n-(m-1); j++){
			if(match(nv, mv, i, j)) {
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int N;
  scanf("%d", &N);
  double A[N];
  for(int i = 0; i < N; i++){
    scanf("%lf", &A[i]);
  }
  
  double reA[N];
  for(int i = 0; i < N; i++){
    reA[i] = 1 / A[i];
  }
  
  double sum = 0;
  for(int i = 0; i < N; i++){
    sum += reA[i];
  }
  
  printf("%lf", 1 / sum);
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int max3(int x,int y,int z){
  int max=0;
  if(x>y){
    max=x;
  }else{
    max=y;
  }
  if(max<z){
    max=z;
  }
  return max;
}
int main(void){
  int a,b;
  scanf("%d %d",&a,&b);
  int add=a+b;
  int sub=a-b;
  int mul=a*b;
  int ans=max3(add,sub,mul);
  printf("%d\n",ans);
  return 0;
}

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

    

int main(){
  ll N,ans=0;
  cin >> N;
  if(N%2==1){
    cout << 0 << endl;
  }else{
    N/=2;
    for(ll i=1;i<=25;i++){
      ans+=N/(ll)pow(5,i);
    }
    cout << ans << endl;
  }
  
    
  
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define present(i, c) ((c).find(i) != (c).end())

#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define fora(i, a, b) for(int i = (a); i < (b); i++)
#define ford(i, n) for(int i = (n)-1; i >= 0; i--)

#define TRACE(x...) x
#define watch(x) TRACE(cerr << #x" = " << x << endl)
#define watch_all(x) TRACE(cerr << #x" = "; for(auto __i : x) cerr << __i << " "; cerr << endl)
	
#define INF 0x3F3F3F3F

//=========================

/*
// ===============
// Codigo Original
// ===============

string S, T;
int n, m;
string dp[3001][3001];

void run_test() {
	cin >> S >> T;
    n = sz(S); m = sz(T);
    for0(i, n+1) dp[i][0] = "";
    for0(i, m+1) dp[0][i] = "";
    for1(i, n) for1(j, m) {
        if(sz(dp[i-1][j]) > sz(dp[i][j])) dp[i][j] = dp[i-1][j];
        if(sz(dp[i][j-1]) > sz(dp[i][j])) dp[i][j] = dp[i][j-1];
        if(S[i-1] == T[j-1]) if(sz(dp[i-1][j-1]) + 1 > sz(dp[i][j])) dp[i][j] = dp[i-1][j-1] + S[i-1];
    }
    string ans = "";
    for0(i, n+1) for0(j, m+1) if(sz(dp[i][j]) > sz(ans)) ans = dp[i][j];
    cout << ans << endl;
}
*/

// ============================
// Otimizando Memoria
// Removendo uma dimensao da DP
// ============================
string S, T;
int n, m;
string dp[2][3001];

void run_test() {
	cin >> S >> T;
    n = sz(S); m = sz(T);
    for0(i, m+1) dp[0][i] = dp[1][i] = "";
    int curr = 1, prev = 0;
    for1(i, n) {
        for1(j, m) {
            if(sz(dp[prev][j]) > sz(dp[curr][j])) dp[curr][j] = dp[prev][j];
            if(sz(dp[curr][j-1]) > sz(dp[curr][j])) dp[curr][j] = dp[curr][j-1];
            if(S[i-1] == T[j-1]) if(sz(dp[prev][j-1]) + 1 > sz(dp[curr][j])) dp[curr][j] = dp[prev][j-1] + S[i-1];
        }
        prev = curr;
        curr = 1-curr;
    }
    string ans = "";
    for0(j, m+1) if(sz(dp[prev][j]) > sz(ans)) ans = dp[prev][j];
    cout << ans << endl;
}

//=========================

ifstream infile;
clock_t start__;
void open_func();
void close_func();

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	open_func();
	//int t; cin >> t; while(t--) run_test();
	run_test();
	close_func();
	return 0;	
}

void open_func() {
	//infile = ifstream("input.in"); if(infile.good()) cin.rdbuf(infile.rdbuf());
	start__ = clock();
	cerr << "---" << endl;
}

void close_func() {
	clock_t elapsed = clock()-start__;
	cerr << "---" << endl << "(time " << fixed << setprecision(2) << elapsed * (1.0/CLOCKS_PER_SEC) << "s)" << endl;	
	//if(infile.good()) infile.close();
}


Measured memory_bytes: 8336
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
using namespace std;
using ll = long long;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;
const ll mod=1e9+7;

map<map<char,ll>,ll> mp;

int main(){
      int a,b,c;
      cin>>a>>b>>c;
      cout<<(b+c)-min(a,b+c)<<endl;
      return 0;
}

Measured memory_bytes: 256
n, u, v = (int(i) for i in input().split())
ablist=[]
onilist=[-1]*n
whelist=[]
sudelist=[0]*n
for i in range(n):
    whelist.append([])

for i in range(n-1):
    a, b = (int(i) for i in input().split())
    ablist.append([a, b])
    whelist[a-1].append(b-1)
    whelist[b-1].append(a-1)

#print(ablist)

onilist[v-1]=0

mark=1
now=[v-1]
turn=1
while mark<n:
    nextis=[]
    for nw in now:
        nextis+=whelist[nw]
    now=[]
    for nx in nextis:
        if onilist[nx]==-1:
            onilist[nx]=turn
            now.append(nx)
            mark+=1
    turn+=1

#print(onilist)

swit=0
nowmax=onilist[u-1]
limit=nowmax//2

now=[u-1]
sudelist[u-1]=1
#print(sudelist, nowmax, limit)
while swit==0:
    nextis=[]
    for nw in now:
        nextis+=whelist[nw]
    now=[]
    #print(nextis)
    for nx in nextis:
        if sudelist[nx]==0 and onilist[nx]>limit:
            now.append(nx)
            sudelist[nx]=1
            if onilist[nx]>nowmax:
                nowmax=onilist[nx]
    #print(now)
    if now==[]:
        swit=1

#print(sudelist)
print(nowmax-1)

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


int main() {
    int n, k, s;
    cin >> n >> k >> s;

    vint ans(n, s);
    if (s < 1000000000){
        rep(i, n-k) ans[i]++;
    }
    else {
        rep(i, n-k) ans[i]--;
    }

    rep(i, n) printf("%d%s", ans[i], i != n-1 ? " " : "\n");
    return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;
#define inf 1000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
//#define mp make_pair

int a[4];

int main(){

cin >> a[0] >> a[1] >> a[2];
sort(a, a+3);
reverse(a, a+3);

if(a[2]%2==a[1]%2){
    cout << a[0]-a[1] + (a[1]-a[2])/2;
}
else {
    cout << (a[0]-a[1]+1)/2 + (a[0]-a[2]+1)/2  + 1;

}

return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int n;
	pair< int,double > b;
	b= pair<int,double>(0,10000000.0);
	cin >> n;
	if(n == 0) break;
	REP(i,n){
	    double j,h,w;
	    cin >> j >> h >> w;
	    h /= 100;
	    double bmi = w / (h*h);
	    bmi = abs(bmi - 22.0);
	    if(b.second > bmi){
		b.first = (int)j;
		b.second = bmi;
	    }
	}
	cout << b.first << endl;
    }
    return 0;
}

Measured memory_bytes: 1228
n = gets.to_i

for i in 1 .. 3500 do
	for j in i .. 3500 do
		numera = 4 * i * j - n * (i + j)
		delim = n * i * j
		if numera > 0 && delim % numera == 0 then			
			puts "#{i} #{j} #{delim/numera}"
			exit
		end
	end
end

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

const double eps = 1e-7;

int main()
{
	double D,d,px,py,vx,vy;
	while(cin >> D, D)
	{
		cin >> px >> py >> vx >> vy;

		if(abs(px*vy-py*vx) > eps)
		{
			cout << "impossible" << endl;
			continue;
		}

		d=sqrt(px*px+py*py);	
		if(px*vx+py*vy>0)
		{
			d=2.0-d;
		}

		if(D>=d)
		{
			printf("%.8lf\n", d);
		}
		else
		{
			cout << "impossible" << endl;
		}
	}
}

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

using namespace std;

const int maxn=2e5+5;

typedef long long ll;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a,b;
	cin>>a>>b;
	if(b*2>=a) cout<<0<<endl;
	else cout<<a-b*2<<endl;
	return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; }



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int h,w;
    cin>>h>>w;
    int cnt=0;
    rep(i,h){
        rep(j,w){
            char x;
            cin>>x;
            if(x=='#') cnt++;
        }
    }
    if(cnt==h+w-1){
        cout<<"Possible"<<endl;
    }
    else{
        cout<<"Impossible"<<endl;
    }
    
}

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

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


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pii pair<int,int>
#define pll pair<long long, long long>
#define rep(i,l,r) for(int i = l;i<r;i++)

#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
using namespace __gnu_pbds;

typedef tree<pll,null_type,less<pll>,rb_tree_tag,tree_order_statistics_node_update> order_set;

const int INF = (int)1e9 + 7;
const long long LLINF = (long long)1e18 + 7;

int r_n = 100100;


int main() {
    vector<bool> prime(r_n +1, true);
    prime[0] = prime[1] = false;
    for (int i = 2; i <= r_n; i++) {
        if(prime[i]) {
            if (i * 1LL * i <= r_n) {
                for (int j = i * i; j <= r_n; j += i) {
                    prime[j] = false;
                }
            }
        }
    }
    vector<int> pref_ans(100100);
    for (int i = 1; i <= 100100; i++) {
        pref_ans[i] = pref_ans[i - 1];
        if (i % 2 == 1)
            if (prime[i] && prime[(i + 1) / 2]) {
                pref_ans[i]++;
            }
    }
    int q;
    cin >> q;
    while (q--) {
        int l, r;
        cin >> l >> r;
        cout << pref_ans[r] - pref_ans[l - 1] << endl;
    }
}

Measured memory_bytes: 1024
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

x,y,a,b,c = map(int,readline().split())
p = list(map(int,readline().split()))
q = list(map(int,readline().split()))
r = list(map(int,readline().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
p = p[:x]
a = len(p)
c = len(r)
q = q[:y]
q = r+q
q.sort(reverse=True)

def cumsum(lst): #元のリストを保持
    res = lst[:]
    for i in range(1,len(res)):
        res[i] += res[i-1]
    return res
cum_p = cumsum(p)
cum_q = cumsum(q)
ans = 0
for i in range(max(0,a-c),a+1): #赤色りんごの個数制限
    if i == 0:
        ans = max(ans,cum_q[x+y-i-1])
    else:
        ans = max(ans,cum_p[i-1] + cum_q[x+y-i-1])

print(ans)



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

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


const int LOG = 35;
const long long LL_INF = (long long) 2e18 + 5;

int N;
long long T;
vector<pair<long long, long long>> stores;

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

    cin >> N >> T;

    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        stores.emplace_back(a, b);
    }

    auto &&compare_stores = [&](const pair<long long, long long> &x, const pair<long long, long long> &y) {
        long long a = x.first + 1, b = x.second;
        long long c = y.first + 1, d = y.second;
        return c * b + c + d < a * d + a + b;
    };

    sort(stores.begin(), stores.end(), compare_stores);
    assert(is_sorted(stores.begin(), stores.end(), compare_stores));
    dbg(stores);

    vector<long long> dp(LOG + 1, LL_INF);
    dp[0] = 0;

    auto &&evaluate = [&](const pair<long long, long long> &store, long long time) {
        return time + store.first * time + store.second;
    };

    for (auto &store : stores) {
        if (store.first == 0)
            continue;

        for (int s = LOG - 1; s >= 0; s--)
            if (dp[s] <= T)
                dp[s + 1] = min(dp[s + 1], evaluate(store, dp[s] + 1));
    }

    sort(stores.begin(), stores.end());
    int zeros = 0;

    while (zeros < N && stores[zeros].first == 0)
        zeros++;

    int best = 0;

    for (int s = 0; s <= LOG; s++) {
        int count = s;
        long long time = dp[s];

        for (int i = 0; i < zeros; i++)
            if (time <= T && evaluate(stores[i], time + 1) <= T) {
                time = evaluate(stores[i], time + 1);
                count++;
            }

        if (time <= T)
            best = max(best, count);
    }

    cout << best << '\n';
}


Measured memory_bytes: 6512
#include <cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int a[105];
    int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n;i++)
    {
        if(a[i]&1)
            continue;
        else
        {
            if((a[i]%3!=0)&&(a[i]%5!=0))
                break;
        }
    }
    if(i<n)
        printf("DENIED\n");
    else
        printf("APPROVED\n");
    return 0;
}



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


int main() {
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    rep(i,a+1){
        rep(j,b+1){
            rep(k,c+1){
                if(500*i + 100*j + 50*k == x)ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
// template {{{

#include <bits/stdc++.h>
using namespace std;

#define loop(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) loop(i, 0, n)
#define rloop(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define rrep(i, n) rloop(i, 0, n)
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ef emplace_front
#define mp std::make_pair
#define mt std::make_tuple
#define fi first
#define se second

using ll = long long;
using ull = unsigned long long;

template<typename T, size_t H, size_t W>
using matrix = std::array<std::array<T, W>, H>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 10;
const ll LLINF = 1e18 + 10;

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

template<typename T>
inline T sq(T x){ return x * x; }

template<typename T, typename U>
inline void chmax(T &x, U y){ x = std::max<T>(x, y); }

template<typename T, typename U>
inline void chmin(T &x, U y){ x = std::min<T>(x, y); }

template<typename T>
inline void sort(T &c){ std::sort(std::begin(c), std::end(c)); }

template<typename T>
inline void reverse(T &c){ std::reverse(std::begin(c), std::end(c)); }

template<typename T>
inline void unique(T &c){ std::sort(c); c.erase(std::unique(std::begin(c), std::end(c))); }

// }}}

using pr = pair<int, int>;

int n;
int p[800], d[800];
vector<pr> g[800];
bool leaf[800];
int dist[800];

int dfs(int v, int par)
{
	leaf[v] = true;
	for (auto &e : g[v]){
		int to, cost;
		tie(to, cost) = e;
		if (to == par) continue;
		dist[to] = dist[v] + cost;
		dfs(to, v);
		leaf[v] = false;
	}
}

int calc(int rt)
{
	memset(leaf, 0, sizeof(leaf));
	dist[rt] = 0;
	dfs(rt, -1);
	
	int res = 0;
	rep(i, n - 1) res += d[i];
	
	rep(s, n){
		for (auto &e : g[s]){
			int t, cost;
			tie(t, cost) = e;
			if (!leaf[s] && !leaf[t]){
				res += cost;
			}
		}
	}

	int mx = 0;
	rep(i, n){
		if (!leaf[i]) chmax(mx, dist[i]);
	}
	res -= mx;
	
	return res;
}

int main()
{
	while (cin >> n, n){
		rep(i, n) g[i].clear();
		rep(i, n - 1) cin >> p[i];
		rep(i, n - 1) cin >> d[i];
		rep(i, n - 1){
			int x = i + 1, y = p[i] - 1;
			g[x].emplace_back(y, d[i]);
			g[y].emplace_back(x, d[i]);
		}
		int res = INF;
		rep(i, n) chmin(res, calc(i));
		cout << res << endl;
	}
}

Measured memory_bytes: 3212
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  deque<ll> A;
  deque<ll> B;
  REP(i, N) {
    ll a;
    cin >> a;
    A.push_back(a);
  }
  sort(ALL(A));
  bool rev = false;
  REP(i, N / 2) {
    if (rev) {
      B.push_front(A.front());
      B.push_back(A.back());
    } else {
      B.push_front(A.back());
      B.push_back(A.front());
    }
    A.pop_front();
    A.pop_back();
    rev = !rev;
  }
  ll ans = 0;
  REP(i, B.size() - 1) { ans += abs(B[i + 1] - B[i]); }

  if (A.size() > 0) {
    ans += max(abs(B.front() - A[0]), abs(B.back() - A[0]));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1152
/**
 *   author: sahushivam
 *   created: 12 January 2020 (Sunday)  16:50:15
**/
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1e18
#define F first
#define S second
#define PB push_back	
#define MP make_pair
#define int long long

void solve(){
	char c;
	cin>>c;
	cout<<(char)(c+1);
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int t=1; while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
"use strict";

process.stdin.resume();
process.stdin.setEncoding('utf8');

let input_stdin = '';
let chunks = '';

process.stdin.on('data', function (data) {
    input_stdin += data;
});

process.stdin.on('end', function () {
    chunks = input_stdin.split('\n');
    start();    
});

function start() {
	const n = parseInt(chunks.shift());
	let array = chunks[0].split(' ').map(Number);

	const dp = Array(n).fill(Infinity);
  
  	dp[0] = 0;

	for (let i = 0; i < n; i++) {
		for (let j = i + 1; j < i + 3 && j < n; j++) {
			dp[j] = Math.min(dp[j], dp[i] + Math.abs(array[i] - array[j]));
          	
		}
	}

	console.log(dp[n - 1]);
}


Measured memory_bytes: 28876
#include <iostream>
using namespace std; 
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define rep(i,a,b) for(int i=a;i<=b;i++)
int fg[200005],fg2[200005];
int main(int argc, char** argv) {
	int n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	
	string s;
	cin>>s;
	if(c==d){
	printf("No");return 0;}
	fg[b-1]=1,fg2[a-1]=1;
	rep(i,b,d-1)
	{
		if((fg[i-1]||fg[i-2])&&s[i]=='.')
		{
			fg[i]=1;
		}
	}
	
	rep(i,a,c-1)
	{
		if((fg2[i-1]||fg2[i-2])&&s[i]=='.')
		{
			fg2[i]=1;
		}
	}
	
	if(!fg[d-1]||!fg2[c-1])
	{
		printf("No");
		return 0;
	}
	
	if(d<c)
	{
		rep(i,b-2,d-1)
		{
			int j=i;
			if(s[i]!='.')continue;
			while(s[j]==s[i]&&j<=d)j++;
			if(j-i>=3)
			{
				printf("Yes");
				return 0;
			}
			i=j-1;
		}
		printf("No");
	}
	else printf("Yes"); 
	
	
	return 0;
}

Measured memory_bytes: 1600
import java.util.*;
public class Main {
	public static void main(String[] args){
		// 整数の入力
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		// 絶対値の差分を取る10
		int c = Math.abs(a - b);

		// 偶数の場合はNG
		if(c % 2 != 0) {
			System.out.println("IMPOSSIBLE");
		}else {
			int k = (a + b) / 2;
			System.out.println(k);
		}
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll p=1e9+7;
ll n,tot,e[500010],hd[500010],nt[500010],sz[500010],ans,a[500010];
void build(int x,int y){
	tot++;
	e[tot]=y;
	nt[tot]=hd[x];hd[x]=tot;
}
void dfs(int x,int fa){
	int i;
	sz[x]=1;
	for(i=hd[x];i;i=nt[i]){
		if(e[i]==fa)continue;
		dfs(e[i],x);
		sz[x]+=sz[e[i]];
	}
	ans=ans*sz[x]%p;
}
ll ksm(ll x,ll y){
	ll xlh=1;
	while(y){
		if(y&1)xlh=xlh*x%p;
		x=x*x%p;
		y/=2;
	}
	return xlh;
}
void get(int x,int fa,int la){
	a[x]=ans*la%p*ksm(sz[x],p-2)%p*n%p;
	int i;
	for(i=hd[x];i;i=nt[i]){
		if(e[i]==fa)continue;
		get(e[i],x,la*ksm(sz[x],p-2)%p*(n-sz[e[i]])%p);
	}
}
int main(){
	ll i,x,y,jc;
	scanf("%lld",&n);
	ans=1;jc=n;
	for(i=1;i<n;i++){
		scanf("%lld%lld",&x,&y);
		build(x,y);build(y,x);
		jc=jc*i%p;
	}
	dfs(1,0);
	get(1,0,1);
	for(i=1;i<=n;i++)printf("%lld\n",jc*ksm(a[i],p-2)%p);
}

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

//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 SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//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();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
const double PI  = acos(-1.0);
//-------------------------------------------


int main() {
    LL N;
    cin >> N;
    bool flag = true;
    int K = 0;
    LL c;
    int keta = 0;

    while ( N ){
        c = N;
        keta = N % 10;
        if( c > 9 &&keta != 9){
            flag = false;
        }

        N /= 10;
        K++;
    }

    if(flag){
        cout << c + (K -1) *9 << endl;
    }
    else{
        cout << c + (K - 1)*9 -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 1e5 + 5;
const int Mod = 1e9 + 7;

int n;
int pos[N];

int main()
{
  cin >> n;
  for(int i = 0 ; i < n ; i++)
    cin >> pos[i];
  long long ans = 1;
  int cnt = 0;
  for(int i = 0 ; i < n ; i++) {
    ans = (ans * (cnt + 1)) % Mod;
    int last = 2 * cnt - 1;
    if(pos[i] == last + 1) {
      cnt--;
    }
    cnt++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
using ll = long long;

int main(){
	int N;
	ll answer=1;
	int count=0;
	char judge;
	
	string S_1,S_2;
	cin >> N >> S_1 >> S_2;
	
	if(S_1[count]==S_2[count]){
		judge='X';
		count++;
		answer*=3;
	}else{
		judge='Y';
		count=count+2;
		answer*=6;
	}
	
	while(count<N){
		if(S_1[count]==S_2[count]){//X
			if(judge=='X'){
				answer=answer*2%1000000007;
			}
			
			judge='X';
			count++;
		}else{//Y
			if(judge=='X'){
				answer=answer*2%1000000007;
			}else{//Y-Y
				answer=answer*3%1000000007;
			}
			judge='Y';
			count = count + 2;
		}
	}
	cout << answer << endl;
	

	return 0;
}

Measured memory_bytes: 256