akhauriyash/Code-Regression huggingface dataset:
import java.io._
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.ArrayBuffer
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val A = map(3)(_ => sc.nextInt())
    var ms = 1000
    rep(3) { i =>
      rep(3) { j =>
        rep(3) { k =>
          if (i != j && j != k && i != k) ms = min(ms, abs(A(i) - A(j)) + abs(A(j) - A(k)))
        }
      }
    }

    out.println(ms)
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int)(f: Int => Unit): Unit = {
    var i = 0
    while(i < n) { f(i); i += 1 }
  }
  def rep_r(n: Int)(f: Int => Unit): Unit = {
    var i = n - 1
    while(i >= 0) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}


Measured memory_bytes: 27332
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compl(const void *a, const void *b){return (*(long*)a<*(long*)b)-(*(long*)a>*(long*)b);}

int main(void){
	char s[101];
	scanf("%s", s);
	char l=strlen(s), i;
	char max=0;
	for(char c='a'; c<='z'; c++){
		char t[101];
		strcpy(t, s);
		char f=0;
		for(i=0; i<l; i++){
			if(t[i]!=c){f=1; break;}
		}
		if(f==0){max=l; break;}
		char k=l;
		while(1){
			f=0;
			k--;
			for(i=0; i<k; i++){
				if(t[i]==c || t[i+1]==c){
					t[i]=c;
				}else{
					f=1;
				}
			}
			if(f==0) break;
		}
		if(k>max) max=k;
	}
	printf("%d\n", l-max);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count etc.
#include <cstdlib>	// require abs
#include <cstdio>	// require printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen

using namespace std;

typedef pair<long long, long long > P;

int main()
{
//	cut here before submit 
//	freopen ("testcase.oldbridge", "r", stdin );
	int n;

	while (cin >> n && n ){
		vector <P> t(n);
		int i;

		for (i = 0; i < n; ++i ){
			long long a, b;
			cin >> a >> b;
			t[i].first = b;
			t[i].second = a;
		} // end for

		sort (t.begin(), t.end() );
/*
		for (i = 0; i < n; ++i ){
			cout << '(' << t[i].first << ',' << t[i].second << ')' << endl;
		} // end for
*/	
		long long sum = 0;	
		for (i = 0; i < n; ++i ){
			sum += t[i].second;
			if (sum > t[i].first ){
				break;
			} // end if
		} // end for
		if (i == n ){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		} // end if
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
///"Bismillahir Rahmanir Raheem"///
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vii;
typedef vector<pil> vil;
typedef vector<pli> vli;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};

const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;
const int LOGN = 20;
const int xx  =  1e5+5;

int dp[xx];
int visited[xx];
int in_degree[xx];
vi edges[xx];

void dfs(int s){
        visited[s] = true;
        for(int i : edges[s]){
            in_degree[i]--;
            dp[i] = max(dp[i],dp[s]+1);

        if(in_degree[i]==0)
            dfs(i);
    }
}
int main(){
    ios::sync_with_stdio(0);
	cin.tie(0);

    int n,m;
    cin>>n>>m;
    f0(i,m){
        int x,y;
        cin>>x>>y;
        edges[x].pb(y);
        in_degree[y]++;
    }

    f1(i,n){
       if(in_degree[i]==0 && !visited[i])
            dfs(i);
    }
    int ans = 0;
    f1(i,n){
        ans = max(ans,dp[i]);
    }
    cout<<ans<<endl;
return 0;
}


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

#define N_MAX 100

int64_t A; // ~10^15
int Bx100;
string str_B; //文字列でとって、小数点を取り除いて、int型にぶちこむ。

void input(){
    cin >> A >> str_B;
    str_B.erase(1,1);
    Bx100 = stoi(str_B);
}

void solve(){
    // pに含まれない整数のうち、最もXに近いものを答えよ。
    // 複数存在する場合は小さい方を答えよ。
    int64_t ans;
    ans = A*Bx100/100;
    cout << ans << endl;
}

int main(){
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3160
#include <iostream>
const int MAX = 1e6 + 9 ;
int cnt[MAX] , mark[MAX] ;
int main(){
    int n , x ;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&x);
        cnt[x]++;
    }

    int ans = 0;
    if(cnt[1]>1){
        puts("0");
        return 0 ;
    }else if(cnt[1]){
        puts("1");
        return 0;
    }else{
        for(int i=2;i<MAX;i++){
            if(!cnt[i])continue;
            for(int j=i+i;j<MAX;j+=i) mark[j] = 1;
            ans += (cnt[i]==1 && !mark[i]);
        }
        printf("%d\n",ans);
    }

    return 0 ;
}

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

using namespace std;

bool flat;

void f7(int a)

{

	flat=0;	for(int i=0;i<3;i++)

	{

		if(a%10==7)

		{

			flat=1;

			break;

		}

		else

			a=a/10;

	}

}

int main(void)

{

	int a;

	scanf("%d",&a);

	f7(a);

	if(flat==1)

		printf("Yes\n");

	else

		printf("No\n");

	return 0;

}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
using ll = long long;

int main(){
    int n; cin >> n;
    vector<int> p(n), q(n), tmp(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> q[i];
    }
    iota(tmp.begin(), tmp.end(), 1);
    int count = 1, cnta = -1, cntb = -1;
    do{
        if(tmp == p) cnta = count;
        if(tmp == q) cntb = count;
        if(cnta != -1 && cntb != -1)break;
        count++;
    }while(next_permutation(tmp.begin(), tmp.end()));
    if(cnta < cntb) swap(cnta, cntb);
    cout << cnta - cntb << endl;

    return 0;
}



Measured memory_bytes: 256
import sys
import math
N = int(input())
A = [0]+list(map(int, input().split()))
ans = 0

for i in range(1, N+1):
    if A[i] < A[i-1]:
        ans += A[i-1]-A[i]
        A[i] = A[i-1]


print(ans)


Measured memory_bytes: 33016
h, w = gets.split.map(&:to_i)
map = []
h.times do
  map << gets.chomp.chars
end

h.times do |i|
  w.times do |j|
    if map[i][j] == '#'
      if i > 0 && map[i-1][j] =~ /[#x]/
          map[i][j] = 'x'
      elsif  i < h-1 && map[i+1][j] =~ /[#x]/
          map[i][j] = 'x'
      elsif  j > 0 && map[i][j-1] =~ /[#x]/
          map[i][j] = 'x'
      elsif  j < w-1 && map[i][j+1] =~ /[#x]/
          map[i][j] = 'x'
      else
        puts 'No'
        exit
      end
    else
      next
    end
  end
end
puts 'Yes'

Measured memory_bytes: 2172
import sys
input=sys.stdin.readline
N,t,a=map(int,input().split())
L=[[]for i in range(N+1)]
for i in range(N-1):
    A,B=map(int,input().split())
    L[A].append(B)
    L[B].append(A)
    
#print(L)

Q=[[t,0]]
C1=[-1 for i in range(N+1)]
for i in range(10**6):
    if i==len(Q):
        break
    if C1[Q[i][0]]==-1:
        C1[Q[i][0]]=Q[i][1]
        if Q[i][0]!=a:
            for j in L[Q[i][0]]:
                if C1[j]==-1:
                    Q.append([j,Q[i][1]+1])
#print(C1)

Q=[[a,0]]
C2=[-1 for i in range(N+1)]
for i in range(N+1):
    if C1[i]==-1:
        C2[i]=-2
#print(C2)
for i in range(10**6):
    if i==len(Q):
        break
    if C2[Q[i][0]]==-1:
        C2[Q[i][0]]=Q[i][1]
        for j in L[Q[i][0]]:
            if C2[j]==-1:
                Q.append([j,Q[i][1]+1])
#print(C1)
#print(C2)
ANS=0
for i in range(N+1):
    if C1[i]<C2[i] and C2[i]>ANS:
        ANS=C2[i]
print(ANS-1)

Measured memory_bytes: 78880
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=200005;
int q[N],f[N],h[N],n,c;
inline double slope(int j,int k)
{
	return double((f[j]+h[j]*h[j])-(f[k]+h[k]*h[k]))/(2*h[j]-2*h[k]);
}
main()
{
	ios::sync_with_stdio(false);
	cin>>n>>c;
	for(int i=1;i<=n;i++)
		cin>>h[i];
	int b=1,e=1;
	q[1]=1;
	for(int i=2;i<=n;i++)
	{
		while(b!=e&&slope(q[b],q[b+1])<=h[i])
			b++;
		int k=q[b];
		f[i]=f[k]+c+(h[i]-h[k])*(h[i]-h[k]);
		while(b!=e&&slope(q[e-1],q[e])>=slope(q[e],i))
			e--;
		q[++e]=i;
	}
	cout<<f[n]<<endl;
	return 0;
}

Measured memory_bytes: 4992
import kotlin.math.abs

fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun main(args: Array<String>) {
    val (x, n) = intList()
    if (n == 0) {
        println(x.toString())
    } else {
        val p = intList()
        (0.until(102).toList() - p).map { Pair(it, abs(x - it)) }
            .groupBy { it.second }
            .minBy { it.key }
            ?.value?.minBy { it.first }
            ?.let {
                println(it.first.toString())
                return
            }
        println("0")
    }
}

Measured memory_bytes: 37160
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val ss = mutableListOf<Map<Char, List<Char>>>()

    repeat(n) {
        val s = readLine()!!.groupBy { it }
        ss.add(s)
    }

    var ans = ""

    for (i in 'a'..'z') {
        val repeat = ss.minBy { it[i]?.size ?: 0 }?.get(i)?.size ?: 0
        ans += "$i".repeat(repeat)
    }

    println(ans)
}

Measured memory_bytes: 31936
require 'prime'
N = gets.to_i

hash = Hash.new(0)
(2..N).each do |i|
    Prime.prime_division(i).each do |pr, n|
        hash[pr] += n
    end
end
nums = hash.values.select{|n| n>=2 }
len = nums.length

divs = [1,3,5,15,25,75]

dp = Array.new(len+1){Array.new(76, 0)}
dp[0][1] = 1
len.times do |i|
    divs.each do |d1|
        divs.each do |d2|
            next if d1*d2 > 75
            if nums[i]+1 >= d2
                dp[i+1][d1*d2] += dp[i][d1]
            end
        end
    end
end

puts dp[len][75]

Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B,i;
  cin >> A >> B;
  i = 0;
  for (int x = A; x < B+1; x++){
    int z = 0;
    for (int a = x; a > 0; a/=10){
     z = 10*z + a%10;
    }
    if( x==z )
     i++;
    
  }
  cout << i << endl;
}
       

Measured memory_bytes: 256
n,m,x_p,y_p = gets.split.map &:to_i

x = gets.split.map &:to_i
y = gets.split.map &:to_i

x_max = x.max
y_min = y.min

if x_max < y_min && y_min > x_p && x_max < y_p then
	puts "No War"
else
	puts "War"
end



Measured memory_bytes: 1788
#include<iostream>
#include<cstring>

using namespace std;

// http://d.hatena.ne.jp/Nekonyan/20110508 
// Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。

int table[10+1][9699];
int memo[10];

void numnum (int size, int depth, int sum )
{
	if (size + 1 == depth ) {
		table[size][sum]++;
	}else{
		for (int i = 0; i <= 9; ++i ){
			if ( memo[i] == 0 ) {
				memo[i] = 1;
				numnum (size, depth + 1, sum + i*depth );
				memo[i] = 0;
			} // end if
		} // end for
	} // end if
}

int main()
{
	memset(table, 0, sizeof (table ) );

	for (int i = 1; i <= 10; ++i ) {
		memset (memo, 0, sizeof (memo ) );
		numnum (i, 1, 0 );
	} // end for

	int n, s;
	while ( cin >> n >> s ) {
		cout << table[n][s] << endl;
	} // end while

	return 0;
}

Measured memory_bytes: 1172
#include <stdio.h>
using namespace std;

int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(b-a==c-b)
	{	
		 printf("YES\n");
	}
	else{
	printf("NO\n");
	}
	return 0;
}

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

template <int32_t MOD>
struct mint {
    int32_t value;
    mint() : value() {}
    mint(int64_t value_) : value(value_ < 0 ? value_ % MOD + MOD : value_ >= MOD ? value_ % MOD : value_) {}
    inline mint<MOD> operator + (mint<MOD> other) const { int32_t c = this->value + other.value; return mint<MOD>(c >= MOD ? c - MOD : c); }
    inline mint<MOD> & operator += (mint<MOD> other) { this->value += other.value; if (this->value >= MOD) this->value -= MOD; return *this; }
};

int64_t msb(int64_t n) {
    if (not n) return 0;
    return 1ull << (63 - __builtin_clzll(n));
}

constexpr int MOD = 1e9 + 7;
mint<MOD> solve(int64_t l, int64_t r) {
    mint<MOD> cnt = 0;
    for (int64_t k = msb(l); k <= msb(r); k <<= 1) {
        array<array<mint<MOD>, 2>, 2> cur = {};
        cur[k == msb(l)][k == msb(r)] = 1;
        for (int64_t i = k >> 1; i; i >>= 1) {
            array<array<mint<MOD>, 2>, 2> prv = cur;
            cur = {};
            REP (p, 2) REP (q, 2) REP (xy, 3) {
                bool x = (xy >= 2);
                bool y = (xy >= 1);
                if (p and (l & i) and not x) continue;
                if (q and not (r & i) and y) continue;
                bool np = p and ((bool)(l & i) == x);
                bool nq = q and ((bool)(r & i) == y);
                cur[np][nq] += prv[p][q];
            }
        }
        REP (p, 2) REP (q, 2) {
            cnt += cur[p][q];
        }
    }
    return cnt;
}

int main() {
    int64_t l, r; cin >> l >> r;
    cout << solve(l, r).value << endl;
    return 0;
}


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

typedef long long ll ; 
typedef unsigned long long ull ; 
typedef vector<int> vi ; 
typedef vector<vi> vii ;
typedef vector<ll> vl ;
typedef vector<vl> vll ;
typedef set<int> si ; 
typedef map<int,int> mii ; 
typedef map<ll,ll>  mll ; 
typedef map<string,int> msi ;
typedef set<ll> sl ; 
typedef set<char> sc ; 
typedef pair<int,int> pii ;


#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
const int INF = 1 << 29 ; 
#define MOD (ll)(1e9+7)
#define eps 1e-6
#define pb push_back 
#define mp make_pair 
#define DEBUG(x)		cout << '>' << #x << ':' << x << endl;
#define F first 
#define S second 
#define all(s) s.begin,s.end() 

int main() 
{
	ios::sync_with_stdio(0) ;
	cin.tie(NULL) ; 
	int n ;
	cin >> n ;
	vi h(n);
	vi dp(n + 1,INT_MAX);	
	REP(i,n) cin >> h[i];
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for(int i = 2; i < n; ++i) {
		dp[i] = min(dp[i] , dp[i-1] + abs(h[i] - h[i-1]));
		dp[i] = min(dp[i] , dp[i-2] + abs(h[i] - h[i-2]));
	}
	cout << dp[n-1] << endl;
	return 0 ; 
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n;
	cin >> n;
	vector<int> c(n - 1), s(n - 1), f(n - 1);
	for(int i = 0; i < n - 1; i++) {
		cin >> c[i] >> s[i] >> f[i];
	}
	for(int i = 0; i < n; i++) {
		if(i == n - 1) {
			cout << 0 << endl;
			continue;
		}
		int tim = 0;
		for(int j = i; j < n - 1; j++) {
			int k = 0;
			while(s[j] + f[j] * k < tim) {
				k++;
			}
			tim = s[j] + f[j] * k + c[j];
		}
		cout << tim << '\n';
	}
	return 0;
}

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

ave = sum(a)/n
number = []
small = 10**3

for i in range(n):
    if abs(a[i] - ave) < small:
        number = []
        number.append(i)
        small = abs(a[i] - ave)

number.sort()

print(number[0])

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

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

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=1e5+10;
    ll N,K;
    ll A[MAXN];
    inline int getBit(ll v, int i){
        return (v>>i)&1;
    }
    void solve(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>N>>K;
        for(int u=1;u<=N;u++){
            cin>>A[u];
        }
        ll t=0;
        for(int b=62;b>=0;b--){
            int cnt1=0;
            for(int u=1;u<=N;u++){
                cnt1+=getBit(A[u],b);
            }
            if(cnt1<N-cnt1){
                if((t|((1ll)<<b))<=K)
                    t=t|((1ll)<<b);
            }
        }
        ll ans=0;
        for(int u=1;u<=N;u++){
            ans+=A[u]^t;
        }
        cout<<ans;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

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

int main(){
	int N; string S; cin>>N>>S;
	long long ng=0,r=0,g=0,b=0;
	for(int i=0; i<N; i++){
		S[i]=='R'? r++: S[i]=='G'? g++: b++;
		for(int j=i+1,k=i+2; k<N; k+=2,j++)
			if((S[i]^S[j]^S[k]) == ('R'^'G'^'B')) ng++;
	}
	cout<< r*g*b - ng <<endl;
}

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

using namespace std;

int main()
{
  int n;
  cin >> n;
  int a[n], b[n];
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  for (int i = 0; i < n; i++)
  {
    if (a[i] == b[n - 1])
    {
      cout << b[n - 2] << endl;
    }
    else
    {
      cout << b[n - 1] << endl;
    }
  }
}


Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		if (a < b) {
			if (b < c) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 26252
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

// OS : iOS, Android
// ベンダー : Sony, Samsung, Apple
// キャリア : Softbank, au, docomo
// 端末 :  iPhone, Galaxy, Xperia

func main() {
	var S, command string
	var num int

	fmt.Scan(&S, &num)
	s := strings.Split(S, "")

	for i := 0; i < num; i++ {
		fmt.Scan(&command)
		switch command {
		case "print":
			var a, b int
			fmt.Scan(&a, &b)
			ans := s[a : b+1]
			fmt.Println(strings.Join(ans, ""))
		case "reverse":
			var a, b int
			fmt.Scan(&a, &b)
			for i, j := a, b; i < j; i, j = i+1, j-1 {
				s[i], s[j] = s[j], s[i]
			}
		case "replace":
			var a, b int
			var c string
			fmt.Scan(&a, &b, &c)
			for i, j := a, 0; i <= b; i, j = i+1, j+1 {
				s[i] = string(c[j])
			}
		}
	}
}

var reader = bufio.NewScanner(os.Stdin)

func read() string {
	reader.Scan()
	return reader.Text()
}



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

vector<vector<int>> P;
int N, M, ans = 0;

void bfs(int v, map<int, int> used, int cnt)
{
  cnt++;
  if (cnt == N) ans++;
  if (used[v]) return;
  used[v] = 1;
  for (auto t : P.at(v)) {
    if (used[t]) continue;
    bfs(t, used, cnt);
  }
}

int main()
{
	map<int, int> used;
	cin >> N >> M;
	P.resize(N);
	rep(i, M) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		P.at(x).push_back(y);
		P.at(y).push_back(x);
	}

	bfs(0, used, 0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <string>
#include <cstring>
#include <cctype>
#include <numeric>
#include <cstdio>
#include <math.h>
#include <functional>
using namespace std;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define rep(i, n) for (i64 i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (i64 i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define fst first
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define sw swap
#define UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
#define na(a, n) rep(i, n) cin >> a[i];
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;
}
vb d(10);
int ans(int x)
{
    while (x)
    {
        if (d[x % 10])
            return 0;
        x /= 10;
    }
    return 1;
}
//ここからメイン
int main()
{
    int x, a, b;
    cin >> x >> a >> b;
    if (a - b >= 0)
    {
        cout << "delicious";
    }
    else if (x < b - a)
    {
        cout << "dangerous";
    }
    else
    {
        cout << "safe";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100002,M=998244353;
int n,i,m,tmp,b[N],c[N],cnt,j,a[N],d[N],y;
ll k,sum;
bool v[N];
double x;
int main(){
	scanf("%d",&n);
	for (i=1;i<=n;i++){
		scanf("%lf",&x);
		a[i]=x;
		a[i]-=sum;
		sum+=a[i];
		c[i]=i;
	}
	scanf("%d%lld",&m,&k);
	for (i=1;i<=m;i++){
		scanf("%d",&y);
		swap(c[y],c[y+1]);
	}
	for (i=1;i<=n;i++) if (!v[i]){
		cnt=0;
		for (j=i;!v[j];j=c[j]) v[j]=1,b[++cnt]=j;
		tmp=k%cnt;
		for (j=1;j<=cnt;j++) d[b[j]]=a[b[(j+tmp-1)%cnt+1]];
	}
	for (i=1,sum=0;i<=n;i++) sum+=d[i],printf("%lld\n",sum);
}

Measured memory_bytes: 2944
import java.util.*;


public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt(),f=0;
    long[] a=new long[n];
    
  	
    for(int i=0;i<n;i++){
      a[i]=sc.nextLong();
    }
  	Arrays.sort(a);
  	for(int i=0;i<n-1;i++){
  		if(a[i]==a[i+1]){
  			System.out.println("NO");
  			f++;
  			break;
  		}
  	}
  	if(f==0){
  		System.out.println("YES");
  	}
  }
}


Measured memory_bytes: 73036
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double


int32_t main()
{
	
	IOS
	int n;cin>>n;
	vector<vector<int>>A(n+1,vector<int>(2));
	vector<vector<int>>S(n+1,vector<int>(2));
	for(int i=1;i<=n;i++)
	{
		cin>>A[i][0];A[i][1]=-A[i][0];
	}
	S[2][0]=A[1][0]+A[2][0];
	S[2][1]=A[1][1]+A[2][1];
	
	for(int i=3;i<=n;i++)
	{
		S[i][0]=max(S[i-1][0]+A[i][0],S[i-1][1]+A[i][0]);
		S[i][1]=max(S[i-1][0]+A[i][1]+A[i-1][1]-A[i-1][0],S[i-1][1]+A[i][1]-A[i-1][1]+A[i-1][0]);
	}
	cout<<max(S[n][0],S[n][1])<<endl;
			

	
	
			
	
		
			
	
		
	
	
}			
	
	
	
	
	

	

	

	
		


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






#define pf                  printf
#define sf(a)               scanf("%d",&a)
#define sfl(a)              scanf("%lld",&a)
#define sff(a,b)            scanf("%d %d",&a,&b)
#define sffl(a,b)           scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)         scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)        scanf("%lld %lld %lld",&a,&b,&c)
#define sffff(a,b,c,d)      scanf("%d %d %d %d",&a,&b,&c,&d)
#define sffffl(a,b,c,d)     scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define sfffff(a,b,c,d,e)   scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
#define sfffffl(a,b,c,d,e)  scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
#define sfc(a)              scanf("%c",&a)
#define pii                 pair<int,int>
#define ms(a,b)             memset(a,b,sizeof(a))
#define pb(a)               push_back(a)
#define pbp(a,b)            push_back({a,b})
#define db                  double
#define ft                  float
#define ll                  long long
#define ull                 unsigned long long
#define pii                 pair<int,int>
#define ff                  first
#define ss                  second
#define sz(x)               x.size()
#define all(x)              x.begin(),x.end()
#define CIN                 ios_base::sync_with_stdio(0); cin.tie(0)
#define max3(a, b, c)       max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c)       min(a, b) < min(b, c) ? min(a, b) : min(b, c)
#define for0(i,n)           for(int i=0;i<n;i++)
#define for1(i,n)           for(int i=1;i<=n;i++)
#define forrev(i,n)         for(int i=n-1; i>=0; i--)
#define forab(i,a,b)        for(int i=a;i<=b;i++)
#define forba(i,b,a)        for(int i=b;i>=a;i--)
#define stlloop(x)          for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define gcd(a, b)           __gcd(a, b)
#define lcm(a, b)           ((a)*((b)/gcd(a,b)))
#define case1(z)            cout<<"Case "<<z<<": "
#define case2(z)            printf("Case %d: ",z)
#define PI                  acos(-1) //3.14159265358979323846264338328
#define valid(tx,ty)        tx>=0 && tx<row && ty>=0 && ty<col
#define intlim              2147483648
#define N                   200005
#define inf                 100000008
#define mod                 1000000007

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/









int main()
{
    string s;
    cin>>s;
    ll l,k=0,i;
    l=s.length();
    for(i=0;i<l;i++)
    {
        if((i+1)%2==1 && s[i]=='L')
        {
            k=5;
        }
        if((i+1)%2==0 && s[i]=='R')
        {
            k=5;
        }
    }
    if(k==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
	return 0;
}
































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

using namespace std;

typedef long long ll;

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

    int h, n;
    cin >> h >> n;
    int a[n], b[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    int dp[h+1];
    fill(dp, dp+h+1, 1e8+1);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= h; j++) {
            dp[min(h,j+a[i])] = min(dp[min(h,j+a[i])], dp[j] + b[i]);
        }
    }

    cout << dp[h] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mems(a,x) memset(a,x,sizeof(a))
#define first fi
#define second se
using namespace std;
typedef long long ll;
const int mod=1e9+7,MS=105,N=66;
const double eps=1e-8;
ll inv(ll x){return x==1?x:(mod-mod/x)*inv(mod%x)%mod;}
ll inv(ll x,ll mod){return x==1?x:(mod-mod/x)*inv(mod%x,mod)%mod;}
ll qpow(ll a,ll n){ll ans=1;while(n){if(n&1) ans=ans*a%mod;a=a*a%mod;n>>=1;}return ans;}
ll mul(ll a,ll b){ll ans=0;while(b){if(b&1) ans=(ans+a)%mod;a=(a+a)%mod;b>>=1;};return ans;}
ll qpow(ll a,ll n,ll mod){ll ans=1;while(n){if(n&1) ans=ans*a%mod;a=a*a%mod;n>>=1;}return ans;}
ll mul(ll a,ll b,ll mod){ll ans=0;while(b){if(b&1) ans=(ans+a)%mod;a=(a+a)%mod;b>>=1;};return ans;}
struct vec
{
    double x,y;
    vec(double x=0,double y=0):x(x),y(y){}
    vec operator+(const vec&o)const{ return vec(x+o.x,y+o.y);}
    vec operator-(const vec&o)const{ return vec(x-o.x,y-o.y);}
    double operator*(const vec&o)const{ return x*o.x+y*o.y;}
    double operator^(const vec&o)const{ return x*o.y-y*o.x;}
    vec operator/(const double&o)const{ return vec(x/o,y/o);}
    vec operator*(const double&o)const{ return vec(x*o,y*o);}
    void sc(){scanf("%lf%lf",&x,&y);}
    double len(){return sqrt(x*x+y*y);}
};
struct Mat
{
    ll a[MS][MS];
    int n,m;
    Mat(int n=0,int m=0):n(n),m(m) { mems(a,0);}
    Mat operator*(const Mat&B)const
    {
        Mat C(n,B.m);
        for(int i=1;i<=n;i++)
            for(int j=1;j<=B.m;j++)
                for(int k=1;k<=m;k++)
                C.a[i][j]=(C.a[i][j]+a[i][k]*B.a[k][j])%mod;
        return C;
    }
};
int n,k;
vec a[N];
double c[N];
vec s1,s2;
vec polar(double a,double r){return vec(cos(r)*a,sin(r)*a);}
bool intersect(vec c1,vec c2,double r1,double r2)
{
    double d=(c1-c2).len();
    if(d-eps>r1+r2||fabs(r1-r2)-d>0) return false;
    double a=acos((r1*r1+d*d-r2*r2)/(2*r1*d));
    double t=atan2(c2.y-c1.y,c2.x-c1.x);
    s1=c1+polar(r1,t-a);
    s2=c1+polar(r1,t+a);
    return true;
}
bool judge(double T)
{
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            if(!intersect(a[i],a[j],T/c[i],T/c[j])) continue;
            int x=0,y=0;
            for(int k=1;k<=n;k++)
            {
                if(c[k]*(s1-a[k]).len()<=T+eps) x++;
                if(c[k]*(s2-a[k]).len()<=T+eps) y++;
            }
            if(x>=k||y>=k) return true;
        }
        int x=0;
        for(int j=1;j<=n;j++)
            if(c[j]*(a[i]-a[j]).len()<=T+eps) x++;
        if(x>=k) return true;
    }
    return false;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        a[i].sc(),scanf("%lf",&c[i]);
    double l=0,r=200000;
    for(int i=1;i<=50;i++)
    {
        double m=(l+r)/2;
        if(judge(m)) r=m;
        else l=m;
    }
    printf("%.10f\n",(l+r)/2);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;
int dx[7] = {0, -1, 1, 0, -1, 1, 0};
int dy[7] = {1, 0, 1, 0, -1, 0, -1};
int bx[19] = {
    0, 1, 1, 0, -1, -1, 0,
    2, 2, 2, 1, 0, -1, -2, -2, -2, -1, 0, 1
};
int by[19] = {
    0, 1, 0, -1, -1, 0, 1,
    2, 1, 0, -1, -2, -2, -2, -1, 0, 1, 2, 2
};

int main(){
    string str;
    
    const int B = 2;
    REP(i, 19) bx[i] += B;
    REP(i, 19) by[i] += B;

    while(cin >> str && str != "#") {
        int map[256];
        REP(i, 256) map[i] = str[i] == '1';

        int grid[10][10];
        int ngrid[10][10];
        REP(i, 10) REP(j, 10) ngrid[i][j] = -1;
        bool ok = true;
        for(int s = 0; s < (1 << 19); s++) {
            REP(i, 19) {
                int y = by[i];
                int x = bx[i];
                grid[y][x] = (s >> i & 1);
            }

            for(int i = 6; i >= 0; i--) {
                int y = by[i];
                int x = bx[i];
                int t = 0;
                REP(r, 7) {
                    t = (t << 1) | grid[y + dy[r]][x + dx[r]];
                }
                ngrid[y][x] = map[t];
            }

            int x = bx[0], y = by[0];
            int t = 0;
            REP(r, 7) {
                t = (t << 1) | ngrid[y + dy[r]][x + dx[r]];
            }
            if(ngrid[y][x] != map[t]) {
                ok = false;
                break;
            }
        }
        
        cout << (ok ? "yes" : "no") << endl;
    }
    return 0;
}

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

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

  int sqn = sqrt(n);
  long long sum = 1e15;
  for (int i = 1; i <= sqn; i++)
  {
    if(n%i == 0){
      long long sumi = i + n/(long long)i;
      sum = min(sum,sumi);
    }
  }
  cout << sum - 2 << endl;  
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    string s, t, ans = "No";
    cin >> s >> t;
    string trot = t;
    if(t == s) ans = "Yes";
    else{
        for(int i = 0; i < t.size(); ++i){
            char move = trot.at(trot.size() - 1);
            trot.pop_back();
            trot =  move + trot;
            if(trot == s){
                ans = "Yes";
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderC
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();

        Dictionary<long, long> dic = new Dictionary<long, long>();

        long current = 2;
        double sqrt = Math.Sqrt(n);
        while (true)
        {
            if (n % current == 0)
            {
                n /= current;
                if (dic.ContainsKey(current))
                {
                    dic[current]++;
                }
                else
                {
                    dic.Add(current, 1);
                }
            }
            else
            {
                current++;
            }
            if (current > sqrt)
            {
                if (n != 1)
                {
                    dic.Add(n, 1);
                }
                break;
            }
        }

        long answer = 0;

        foreach (var item in dic)
        {
            long num = item.Value;

            long max = num;
            for (long i = 1; i <= max; i++)
            {
                if (num >= i)
                {
                    answer++;
                    num -= i;
                }
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 27856
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1E-9;
const long long INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
#define pb push_back
#define mp make_pair
#define ll long long
int n;
vector<int> primes;
bitset<5000> bs;
vector<int > factor;
map<pair<ll , int> , int> g;
int a[100000];
ll s[100000];
int pow3[15];
int main()
{
	//freopen("input.txt" , "r" , stdin);
	pow3[0] = 1;
	for(int i = 1; i < 15; i++)
		pow3[i] = 3 * pow3[i - 1];

	scanf("%d" , &n);
	bs = ~bs;
	bs[1] = 0;
	for(int i = 2; i <= 3333; i++)
	{
		if(bs[i])
		{
			primes.pb(i);
			for(ll j = (ll)i * i; j <= 3333; j += i)
			{
				bs[j] = 0;
			}
		}
	}
	int m = primes.size();
	int ans = 0;
	for(int i = 0; i < n; i++)
	{
		scanf("%lld" , &s[i]);
		factor.clear();
		for(int j = 0; j < m; j++)
		{
			while(not(s[i] % primes[j]))
			{
				s[i] /= primes[j];
				factor.pb(primes[j]);
			}
		}
		ll q = sqrt(s[i]) + EPS;
		if(s[i] != 1)
		{
			if(q * q == s[i])
			{
				factor.pb(q);
				factor.pb(q);
			}
			else
			{
				factor.pb(s[i]);
			}
		}
		ll hash = 0 , mask = 0;
		ll p = 10000000019LL , p2 = 1;
		ll pp = 1;
		for(int i = 0; i < factor.size();)
		{
			int j = i;
			while(j < factor.size() && factor[j] == factor[i])
				j++;
			int cnt = (j - i) % 3;
			if(cnt)
			{
				mask += cnt * p2;
				p2 *= 3;
				hash += pp * factor[i];
				pp *= p;
			}
			i = j;
		}
 		g[mp(hash , mask)]++;
	}
	bool wasZero = false;
	for(auto it = g.begin(); it != g.end(); it++)
	{
		ll hash1 = it->first.first;
		int mask1 = it->first.second;
		if(!mask1)
		{
			wasZero = true;
			continue;
		}
		int mask2 = 0 , p3 = 1;
		for(int i = 0; i < 15; i++)
		{
			int bit = (mask1 / pow3[i]) % 3;
			if(bit == 1)
				bit = 2;
			else if(bit == 2)
				bit = 1;
			mask2 += bit * p3;
			p3 *= 3;
		}
		//cout << mask2 << endl;
		ans += max(g[mp(hash1 , mask1)] , g[mp(hash1 , mask2)]);
		g[mp(hash1 , mask1)] = g[mp(hash1 , mask2)] = 0;
	}
	if(wasZero)
		ans++;
	printf("%d" , ans);
}


Measured memory_bytes: 13568
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define inf 2147483647
#define mid (l+r)/2
#define lowbit(x) x&-x
#define N 3005
#define log 40
using namespace std;
int n;
int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int a[500005];
int check1(int a1,int b1,int c){return ((a[a1]<=c)&&(a[b1]<=c));}
int check2(int a1,int b1,int c){return ((a[a1]>c)&&(a[b1]>c));}
bool check(int x)
{
	for(int i=0;i<n-1;i++)
	{
		if(check2(n+i,n+i+1,x)||check2(n-i,n-i-1,x))
	        return 0;
		if(check1(n+i,n+i+1,x)||check1(n-i,n-i-1,x))
		    return 1;
	}
	return check1(1,1,x);
} 
int main()
{
	//freopen("x.in,"r",stdin);
	//freopen("x.out,"w",stdout);
	scanf("%d",&n);
	int i;
	for(i=1;i<=2*n-1;i++)
	    scanf("%d",&a[i]);
	int l=1,r=2*n-1;
	while(l<r)
	{
		if(check(mid))
		    r=mid;
		else
		    l=mid+1;
	}
	cout<<r;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	for(int i=0;i<=a;i++)
		if(i*2+(a-i)*4==b){
			cout<<"Yes"<<endl;
			return 0;
		}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i=0; i<(int)(n); ++i)
int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};

int main() {
  ll N; cin >> N;
  ll a[3010]; REP(i, N) cin>>a[i];

  ll ans = 0;
  REP(i, N) {
    ans += a[i]-1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

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

/*（๑•﹏•๑｀) */
int main() {
    queue<PII> Q;
    bool black[1002][1002] = {};
    int H,W;
    cin >> H >> W;
    FORq(i,1,H){
        FORq(j,1,W){
            char c; cin >> c;
            if (c == '#') {
                black[i][j] = true;
                Q.push(MP(i,j));
            }
        }
    }

    int T = 0;

    while(!Q.empty()){
        int N = Q.size();
        T++;
        REP(i,N){
            int h = Q.front().fst;
            int w = Q.front().snd;
            Q.pop();
            REP(j,4){
                int hs = h + dx[j];
                int ws = w + dy[j];

                if ((hs <= 0 || hs > H)) continue;
                if ((ws <= 0 || ws > W)) continue;
                if (black[hs][ws]) continue;
                black[hs][ws] = true;
                Q.push(MP(hs,ws));
            }
        }

    }

    cout << T-1 << endl;
}


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

long long int MOD = 998244353;
const int MAX = 210000;
long long int n, m, k;

long long int fac[MAX], finv[MAX], inv[MAX], pm[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

void pmInit() {
  pm[0] = 1;
  for(int i=1; i<MAX; i++){
    pm[i] = pm[i-1]*(m-1);
    pm[i] %= MOD;
  }
}

long long int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long int f(long long int k){
  long long int t = COM(n-1, k) * m;
  t %= MOD;
  t *= pm[n-1-k];
  t %= MOD;
  return t;
}

int main(){
  cin >> n >> m >> k;
  long long int ans = 0;
  COMinit();
  pmInit();
  for(int i=0; i<=k; i++){
    if(f(i)>0){
      ans += f(i);
      ans %= MOD;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10196
#include <bits/stdc++.h>
#define  Rep(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) Rep(i,0,(n))
#define  all(a) begin(a),end(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
 
int main()
{
    string s;
    cin>>s>>s;
    cout<<"A"<<s[0]<<"C\n";
    
    return 0;
}

Measured memory_bytes: 256
N, M, Q = map(int, input().split())
Q_list = []
for i in range(Q):
  Q_list.append(list(map(int, input().split())))


max_cost = 0
#use dfs to find all possible sequences
def dfs(A):
  global max_cost
  #termination condition
  if (len(A)==N):
    cost = 0
    #calculate cost
    for Q in Q_list:
      a = Q[0]
      b = Q[1]
      c = Q[2]
      d = Q[3]
      if (A[b-1]-A[a-1]==c):
        cost += d
    if (cost>max_cost):
      max_cost = cost
    return 1
  #dfs recursion part
  low = 0
  if (A == []):
    low = 1
  else:
  	low = A[-1]
  for i in range(low, M+1):
    dfs(A + [i])
    
dfs([])
print(max_cost)

Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
    
#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, a, b) for (int i = a;i<=b;i++)
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define mem(x) memset(x, 0, sizeof(x))
#define ritr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define pai pair < int, int> 
#define pal pair < ll, ll> 
#define vi vector <int> 
#define vl vector < ll > 
#define vpai vector < pii > 

const int mod = 1e9+7;
const int INF = INT_MAX;
const int sze = 100005;

ll dp[sze][2];
vi adj[sze];

void dfs(int start,int par){
    if(adj[start].size()==0){
        dp[start][0]=1;
        dp[start][1]=1;
        return;
    }
    ll a=1,b=1;
    for(auto x:adj[start]){
        if(par==x) continue;
        dfs(x,start);
        a=(a*(dp[x][0]+dp[x][1])%mod)%mod;
        b=(b*(dp[x][0])%mod)%mod;
    }
    dp[start][0]=a;
    dp[start][1]=b;
}

void solve() {
    int n;
    cin>>n;
    int m=n-1;
    while(m--){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    dfs(0,-1);
    cout<<(dp[0][0]+dp[0][1])%mod<<endl;
}

int main() {
    IOS;

    int t = 1;
    // cin >> t;
    while (t--) {
        mem(dp);
       solve();
    }

  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll N;
    string S,T;
    cin >> N >> S >> T;
    rep(i, N) {
        cout << S[i] << T[i];
    }
    return 0;
}

Measured memory_bytes: 256