akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

#define MAX_N (50)

int main(int argc, char *argv[]) {
  // read inputs
  int N, as[MAX_N];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &as[i]);
  }

  // solve

  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int is_sorted = 1;
      int tmp = as[i];
      as[i] = as[j];
      as[j] = tmp;
      for (int k = 1; k < N; k++) {
        if (as[k - 1] > as[k]) {
          is_sorted = 0;
        }
      }
      if (is_sorted) {
        printf("YES\n");
        return 0;
      }
      tmp = as[i];
      as[i] = as[j];
      as[j] = tmp;
    }
  }

  int is_sorted = 1;
  for (int k = 1; k < N; k++) {
    if (as[k - 1] > as[k]) {
      is_sorted = 0;
    }
  }
  if (is_sorted) {
    printf("YES\n");
    return 0;
  }

  printf("NO\n");

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(auto i = (N) - 1; i >= 0; i -= 1)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define rand mtrand
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cout << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cout << #v << " = "; array_out(v , ##__VA_ARGS__);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
#endif
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = 0x1FFFFFFFFFFFFFFFLL;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}

using P = pair<int,int>;
random_device seed_gen; mt19937_64 mtrand(seed_gen());
constexpr int MOD = 1000000007;
//////////////////////////////////////////


int main(){
  ini(N);
  vl D(N); in(D);
  ini(M);
  vl T(M); in(T);
  sort(all(D));
  sort(all(T));

  auto itt = T.begin();
  auto itd = D.begin();
  while(itt != T.end() && itd != D.end()){
    while(itd != D.end() && *itd != *itt) itd++;
    if(itd == D.end()) break;
    itd++; itt++;
  }
  out(itt == T.end() ? "YES" : "NO");
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
using namespace std;
int a, b, k;
int main() {
	cin >> k;
	cin >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK";
			return 0;
		}
	}
	cout << "NG";
	return 0;
}

Measured memory_bytes: 3600
// include
#include <array>
#include <algorithm>
#include <set>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <string>
#include <unordered_map>


// pow(10, 15) 10の15乗

//  多倍長整数
#include <boost/multiprecision/cpp_int.hpp>
using big_int = boost::multiprecision::cpp_int;


// ============================================
int main() {

  int R, G, B, K;
  std::cin >> R >> G >> B;
  std::cin >> K;

  for (int i = 0; i < K; i++) {
    if (R >= G) {
      G *= 2;
    } else if (G >= B) {
      B *= 2;
    }
  }
  
  if (G > R && B > G) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  
  
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<62)-1
#define MAX 1000000000
signed main(){
    int N,C; cin>>N>>C;
    vi A(N),B(N);
    rep(i,0,N) cin>>A[i];
    rep(i,0,N) cin>>B[i];
    vii D(N,vi(C+1)),dp(N+1,vi(C+1));
    dp[0][0]=1;
    rep(i,0,N){
        REP(j,A[i],B[i]){
            int sum=1;
            REP(k,0,C){
                D[i][k]+=sum;
                D[i][k]%=MOD;
                sum*=j;
                sum%=MOD;
            }
        }
    }
    rep(i,0,N){
        REP(j,0,C){
            REP(k,0,C-j){
                dp[i+1][j+k]+=dp[i][j]*D[i][k]%MOD;
                dp[i+1][j+k]%=MOD;
            }
        }
    }
    cout<<dp[N][C]<<endl;
}



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

int getgcd(int a, int b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

int main()
{
	int N, A[100000], i, gcd1, gcd2, gcd3, Ans, sub;
	cin >> N;
	for (i = 0; i < N; i++)
		cin >> A[i];


	if (N > 2) {
		gcd1 = getgcd(A[0], A[1]);
		gcd2 = getgcd(A[0], A[2]);
		gcd3 = getgcd(A[1], A[2]);
		if (gcd3 > gcd2&&gcd3 > gcd1) {
			sub = A[1];
			A[1] = A[0];
			A[0] = sub;
		}

		Ans = A[0];
		for (i = 2; i < N; i++) {
			gcd1 = getgcd(Ans, A[1]);
			gcd2 = getgcd(Ans, A[i]);
			if (gcd1 > gcd2) {
				Ans = gcd1;
				A[1] = A[i];
			}
			else
				Ans = gcd2;
		}

		cout << Ans;
	}
	else {
		if (A[0] > A[1])
			cout << A[0];
		else
			cout << A[1];
	}
}


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



int main(){
    int n,m,an=0;
    cin>>n>>m;
    vector<int> s(n+1,1);
    rep(i,m){
        int a;
        cin>>a;
        s[a]=0;
    }
    vector<int> c(n+2,0);
    c[n]=1;
    rep(i,n){
        if(s[n-1-i]==0){
            c[n-1-i]=0;
            continue;
        }
        else{
            c[n-1-i]=c[n-i]+c[n-i+1];
            c[n-1-i]%=MOD;
        }
    }
    cout<<c[0]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, M: int, L: "List[int]", R: "List[int]"):
    print(max(min(R)-max(L)+1, 0))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    L = [int()] * (M)  # type: "List[int]"
    R = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(N, M, L, R)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10868
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
    int n;
    string x;
    cin>>n>>x;
    bool flag;
    string y=x;
    while(1)
    {
        flag=false;
        for(int i=0;i+1<y.length();++i)
        {
            if(y[i]=='('&&y[i+1]==')')
            {
                y.erase(i,2);
                flag=true;
                break;
            }
        }
        if(!flag)
        {
            break;
        }
    }
    for(int i=0;i<y.length();++i)
    {
        if(y[i]=='(')
        {
            x.push_back(')');
        }
        else
        {
            x.insert(x.begin(),'(');
        }
    }
    cout <<x<<endl;
    return 0;
}


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

#define INC(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define DEC(i, a, b) for(int (i) = (a); (i) > (b); --(i))
#define REP(i, n)    INC(i, 0, n)
#define comp(a, b) int comp(const void *(a), const void *(b))

typedef unsigned int uint;
typedef unsigned long ul;
typedef long long  ll;
typedef unsigned long long ull;

const int MOD = 1e9 + 7;

using namespace std;

void TFprint(bool b, std::string T, std::string F){
    if(b){
        cout << T << endl;
    }else{
        cout << F << endl;
    }
}

int abs(int x){
    return x > 0? x : -x;
}

int max(int a, int b){
    return a > b? a : b;
}

int min(int a, int b){
    return a < b? a : b;
}

void init(int both[26]) {
    for(int i = 0; i < 26; ++i) {
        both[i] = 0;
    }
}
int n;

void check(char * str, int both[26], int div) {
    for(int i = 0; i < div; ++i) {
        both[str[i] - 'a'] = 1;
    }
    for(int i = div; i <= n; ++i) {
        if(both[str[i] - 'a'] == 1)
        both[str[i] - 'a'] = 2;
    }
}

int count(int both[26]) {
    int ret = 0;
    for(int i = 0; i < 26; ++i) {
        if(both[i] == 2) ret++;
    }
    return ret;
}

int main(){
    cin >> n;
    char str[n];
    cin >> str;
    int both[26];
    int ans = -1;
    for(int div = 0; div < n; ++div) {
        init(both);
        check(str, both, div);
        ans = max(ans, count(both));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse4,sse4.2,popcnt,abm,mmx,avx")
#endif
#include <bits/stdc++.h>

using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
typedef long long Long;
typedef double Double;

template <class U, class V>
istream& operator>>(istream& is, pair<U, V>& p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) {
    is >> x;
  }
  return is;
}

template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto& x : v) {
    os << x << " ";
  }
  return os;
}

vector<int> a, b, res;

int n;


const int RANDOM =
    chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);

bool validate() {
  bool valid = true;
  for (int i = 0; i < n; ++i) {
    valid &= (a[i] != res[i]);
  }
  return valid;
}

bool solve() {
  res = b;
  for (int t = 0; t < 300; ++t) {
    rotate(begin(res), begin(res) + rng() % n, end(res));
    if (validate()) return true;
  }
  res = b;
  reverse(all(res));
  for (int t = 0; t < 300; ++t) {
    if (validate()) return true;
    shuffle(all(res), rng);
  }
  return false;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif
  cin >> n;
  a.resize(n), b.resize(n), res.resize(n);
  cin >> a >> b;

  if (solve()) {
    cout << "Yes" << endl;
    cout << res << endl;
    return 0;
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 5564
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

int main(){
  int n;
  cin>>n;
  vi p(n);
  for(int i=0; i<n; i++)cin>>p[i];

  int ans = 0;
  for(int i=1; i<n-1; i++){
    if(max({p[i-1], p[i], p[i+1]})!=p[i] 
    && min({p[i-1], p[i], p[i+1]})!=p[i])ans++;
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int n;
  scanf("%d",&n);
  char s[n+1];
  char t[n+1];
  scanf("%s",s);
  scanf("%s",t);
  char m[2*n+1];
  for(int k=0;k<2*n-1;k=k+2){
    m[k]=s[k/2];
    m[k+1]=t[k/2];
  }
  for(int l=0;l<2*n;l++){
    printf("%c",m[l]);
  }
  printf("\n");
  return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
const ll mo=1000000007;

ll modpow(ll a, ll n=mo-2) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}
ll comb(ll N_, ll C_) {
	const int NUM_=1400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}
ll hcomb(int P_,int Q_) { return (P_==0&&Q_==0)?1:comb(P_+Q_-1,Q_);}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	
	if(K>=N) {
		cout<<hcomb(N,N)<<endl;
		return;
	}
	if(K==1) {
		cout<<1LL*N*(N-1)%mo<<endl;
	}
	else {
		ll ret=0;
		FOR(i,K+1) {
			int lef=N-i;
			ret+=comb(N,i) * hcomb(lef,i)%mo;
		}
		cout<<ret%mo<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 33024
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val s = sc.next().toCharArray()


  val list = mutableListOf<Int>()
  for (c in 'a'..'z') {
    if (!s.contains(c)) {
      continue
    }
    var t = s
    var count = 0
    while (true) {
      if (t.groupBy { it }.size == 1) {
        break
      }

      val tmp = CharArray(t.size - 1) { ' ' }
      for (i in 0 until tmp.size) {
        if (t[i] == c || t[i+1] == c) {
          tmp[i] = c
        } else {
          tmp[i] = t[i]
        }
      }
      count++
      t = tmp
    }
    list.add(count)
  }

  println(list.min())
}

Measured memory_bytes: 47908
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	string s; cin>>s;
	int n=s.size();
	int ans=0;
	rep(i,0,n-1){
		if(s[i]!=s[i+1]) ++ans;
	}
	cout<<ans;
	

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5;

int main(){
	int n;
	cin>>n;
	int a[MAX];
	int M=0;
	rep(i,n){
		cin>>a[i];
		M=max(a[i],M);
	}
	int R=0;
	rep(i,n)if(abs(2*a[i]-M)<abs(2*R-M))R=a[i];
	cout<<M<<" "<<R;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; }
#define YES(condition) if(condition){ cout << "YES" << '\n'; }else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition){ cout << "yes" << '\n'; }else{ cout << "no" << '\n'; }





int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n), b(n);
    REP(i, n){
        cin >> a[i] >> b[i];
    }
    
    ll ans = 0;
    REP(i, n){
        if((k | a[i]) == k){
            ans += b[i];
        }
    }
    
    for(ll i = 30; i >= 0; i--){
        if(!(k & (1 << i))) continue;
        
        ll k2 = k ^ (1 << i), t = 0;
        for(ll j = 0; j < i; j++){
            t <<= 1;
            t |= 1;
        }
        k2 |= t;
        
        // cout << k2 << endl;
        
        ll sum = 0;
        REP(j, n){
            if((k2 | a[j]) == k2){
                sum += b[j];
            }
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define MAXN 101

int n, a[MAXN], ans = 1000000009;

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = -100; i < 101; i++){
        int mi = 0;
        for(int j = 0; j < n; j++){
            mi += (a[j] - i) * (a[j] - i);
        }
        ans = min(ans, mi);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n,m= map(int, input().split()) 
judge=[0]*n
cor=0
pen=0
inf=10**6

for i in range(m):
  a,s = input().split()
  a=int(a)
  if s=='WA':
    judge[a-1]+=1
    
  else:
    if judge[a-1]>-1:
      cor+=1
      pen+=judge[a-1]
      judge[a-1]=-inf

print(cor,pen)

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

int main(){
	int a,b,k;
	cin >> a >> b >> k;
	
	for(int i = 0;i < k;i++){
		if(i%2==0){ 
			if(a%2){
				a--;
			}
			a/=2;
			b+=a;
		} 
		else{
			if(b%2){
				b--;
			}
			b/=2;
			a+=b;
		}
	}
	cout << a << " " << b;
}

Measured memory_bytes: 256
def list_divisor(x):
    res = []
    i = 1

    while i ** 2 <= x:
        if x % i == 0:
            res.append(i)
            if i ** 2 != x:
                res.append(x // i)

        i += 1

    return res

def resolve():
    n = int(input())
    divisors = sorted(list_divisor(n))

    l = len(divisors)
    if l % 2 == 0:
        print(max(len(str(divisors[l // 2 - 1])), len(str(divisors[l // 2]))))

    else:
        print(len(str(divisors[l // 2])))
        
resolve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
  {int N, M; cin >> N >> M;
  vector<vector<int>> g(N);
  for (int i = 0; i < M; ++i) {int A, B; cin >> A >> B; g[--A].push_back(--B); g[B].push_back(A);}
  vector<int> ans(N);
  queue<int> q; ans[0] = -1; q.push(0);
  while (q.size())
    {auto v = q.front(); q.pop();
    for (auto u : g[v]) {if (!ans[u]) {ans[u] = v + 1; q.push(u);}}}
  puts("Yes"); for (int i = 1; i < N; ++i) cout << ans[i] << endl;}

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

#define int long long

signed main() {
	
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	vector<int> a(n);
	for(auto &x:a)
		cin >> x;
		
	sort(a.rbegin(),a.rend());
		
	int x[2],c=1,l=a[0],d=0;
	x[0] = 0;x[1]=0;
	for(int i = 1;i < n;i++){
		if(a[i] == l)
			c++;
		if(a[i] != l || i == n-1){
			if(d==0 && c > 3)
				x[d++] = x[d++] = l;
			else if(c > 1)
				x[d++] = l;
		}
		if(d >= 2)
			break;
		if(a[i] != l)
			c = 1;
		l = a[i];
	}
	
	cout << x[0]*x[1] << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
 
 
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> l(n);
  rep(i,n) cin >> l[i];
  sort(l.rbegin(),l.rend());
  int ans = 0;
  rep(i,k) ans += l[i];
  cout << ans << endl;
}


Measured memory_bytes: 3616
#include<vector>
#include<queue>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<stack>
#include<string>
#include<map>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<29
#define MAX 30
using namespace std;
int n,m,p,a,b;

int main(){
  int tes,x,y;
  double tk;
  int d[31][31];
  double dp[1<<9][31];
  vector<double> ticket;
  while(true){
    cin >> n >> m >> p >> a >> b;
    if(n+m+p+a+b == 0)break;
    ticket.clear();   
    rep(i,31)rep(j,31)d[j][i] = INF;

    rep(i,n){
      cin >> tk;
      ticket.push_back(tk);
    }
    rep(i,p){
      cin >> x >> y >> tes;
      d[x][y] = d[y][x] = tes;
    }
  
    for(int i=0;i<(1<<9);i++){
      for(int j=0;j<31;j++)dp[i][j] = INF;
    }
    dp[(1<<n)-1][a] = 0;

    double ans = INF;
    for(int S = (1<<n)-1; S>=0 ;S--){
      ans = min(ans,dp[S][b]);
      for(int v = 1; v<=m ;v++){
	for(int t = 0; t<n ;t++){
	  if(!(S>>t &1))continue;
	  for(int u = 1; u<=m;u++){
	    if(d[v][u] == INF)continue;	    
	    dp[S & ~(1<<t)][u] = min(dp[S & ~(1<<t)][u],dp[S][v] + (double)(d[v][u]/ticket[t]) );	    
       
	  }
	}
      }
    }
    if(ans == INF)cout << "Impossible" << endl;
    else printf("%.3f\n",ans);
 
  }
  return 0;
}

Measured memory_bytes: 1432
a = gets.chomp
b = gets.chomp



res = true
table = {}
# a.chars.each_with_index do |i, idx|
#   ac = i
#   bc = b[idx]
#   if (table[ac].nil? || table[ac] == bc) && (table[bc] != ac || table[bc].nil?)
#     table[ac] = bc
#     table[bc] = ac
#   else
#     puts "#{ac} => #{table[ac]}(not #{bc}) / #{bc} => #{table[bc]}(not #{ac})"
#     res = false
#     break
#   end
#   puts "#{ac} => #{table[ac]} / #{bc} => #{table[bc]}"
# end

acs = {}
bcs = {}
a.chars.each { |c| acs[c] ||= 0; acs[c] += 1 }
b.chars.each { |c| bcs[c] ||= 0; bcs[c] += 1 }

sorted_acs = acs.sort_by { |i, j| j}
sorted_bcs = bcs.sort_by { |i, j| j}

sorted_acs.size.times do |i|
  if sorted_acs[i][1] != sorted_bcs[i][1]
    res = false
    break
  end
end

puts res ? "Yes" : "No"

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

#define fastread std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define pb push_back
#define mp make_pair
#define print(a) for(auto x:a) cout<<x<<' ';cout<<endl;
#define printM(b) for(auto y:b) {print(y);}
#define printP(p) cout<<p.first<<' '<<p.second<<endl;

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;

int main()
{
	fastread;
	
	ll n, m, i, j;
    string s, t;

    cin>>s>>t;

    n = s.length();
    m = t.length();

    string dp[2][m+1];

    for(j=0 ; j<=m ; ++j)
        dp[0][j] = "";
    for(i=1 ; i<=n ; ++i)
        for(j=1 ; j<=m ; ++j)
        {
            if(s[i-1] == t[j-1])
                dp[i%2][j] = dp[(i+1)%2][j-1] + s[i-1];
            else
            {
                if(dp[(i+1)%2][j].length() >= dp[i%2][j-1].length())
                    dp[i%2][j] = dp[(i+1)%2][j];
                else
                    dp[i%2][j] = dp[i%2][j-1];
            }
        }
    
    cout<<dp[n%2][m];
    
    return 0;
}

Measured memory_bytes: 17016
def input_int_list():
    return [int(thing) for thing in input().split(" ")]

def int_input():
    return int(input())


def print_ans(string):
    print(string)
    exit()

def yes():
    print("Yes")
    exit()

def no():
    print("No")
    exit()

import numpy as np

N,M,X=input_int_list()
np_list=[np.array(input_int_list(),dtype=int) for i in range(N)]
kakaku_list=[]
for i in range(2**N):
    the=np.zeros((1,M),dtype=int)
    kakaku=0
    for j in range(N):
        if format(i,"b").zfill(N)[j]=="1":
            the=the+np_list[j][1:]
            kakaku=kakaku+np_list[j][0]
    if (the>=X).all():
        kakaku_list.append(kakaku)
if len(kakaku_list)!=0:
    print_ans(min(kakaku_list))
else:
    print_ans(-1)



Measured memory_bytes: 27356
w,h,n=map(int,input().split())
x,y=map(int,input().split())
a=0
for _ in range(n-1):
    px,py=map(int,input().split())
    dx,dy=px-x,py-y
    if dx*dy<0:a+=sum(map(abs,[dx,dy]))
    else:a+=max(map(abs,[dx,dy]))
    x,y=px,py
print(a)

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int mini = 0, maxi = 0;
    vector<int> a(n), color(9);
    rep (i, n) {
      cin >> a[i];
    }
    rep (i, n) {
      int tmp = a[i] / 400;
      if (tmp > 8) tmp = 8;
      color[tmp]++;
    }
    int cnt = 0;
    rep (i, 8) {
      if (color[i] > 0) cnt++;
    }

    if (cnt == 0) {
      mini = 1;
    } else {
      mini = cnt;
    }
    maxi = color[8] + cnt;

    cout << mini << " " << maxi << endl;

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = 0X3F3F3F3F;
const ll N = 1e5+7;
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS() std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
int main()
{
	IOS();
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<s.size()/2;i++)
	{
		if(s[i]!=s[s.size()-i-1]) ans++;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int y = sc.nextInt();
        boolean finish = false;
        int[] ans = new int[3];
        for (int i = 0; i * 10000 <= y; i++) {
            int a = i * 10000;
            if (i > n || finish)
                break;
            for (int j = 0; a + (j * 5000) <= y; j++) {
                int b = j * 5000;
                if (i + j > n || finish)
                    break;
                int num = n - i - j;
                if (a + b + (num * 1000) == y) {
                    finish = true;
                    ans[0] = i;
                    ans[1] = j;
                    ans[2] = num;
                    break;
                }
            }
        }
        if (finish) {
            System.out.println(ans[0] + " " + ans[1] + " " + ans[2]);
        } else {
            System.out.println("-1 -1 -1");
        }
    }
}

Measured memory_bytes: 22740
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

int main(){
    map<LL, LL> count;
    LL N;
    LL K;
    cin >> N;
    cin >> K;
    REP(i, N){
        LL a, b;
        cin >> a >> b;
        count[a]+=b;
    }
    LL sum = 0;
    foreach(i, count){
        sum += i.second;
        if(sum>=K){
            cout << i.first << endl;
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
main(){
  string a,b;
  cin>>a>>b;
  bool topcodeer_is_honest=b=="H";
  bool atcodeer_is_honest=a=="H";
  if(!atcodeer_is_honest)topcodeer_is_honest=!topcodeer_is_honest;
  cout<<(topcodeer_is_honest?"H":"D")<<endl;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a=list(map(int,input().split()))
Z=[list(map(int,input().split()))[::-1] for _ in range(m)]
d=[]
e=0
a.sort()
Z.sort(reverse=True)
for c,b in Z:
    d+=[c]*b
    e+=b
    if e>n:
        break

for i , (x,y) in enumerate(zip(a,d)):
    if x<y:
        a[i]=y

print(sum(a))


Measured memory_bytes: 26732
n=int(input())
a=list(map(int,input().split()))
count=0
for i in range(1,n-1):
    if a[i-1]<a[i]and a[i]<a[i+1] or a[i-1]>a[i]and a[i]>a[i+1]:
        count+=1
print(count)

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>

using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
const ll MOD = 1e9 + 7;
//const ll MOD  = 998244353;
//ll MOD;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

//最大公約数
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; 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;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

//約数の列挙O(√n)
vector<ll> divisor(ll n){
    vector<ll> res(0);
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n/i) res.push_back(n/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}



int main(void){
  int K, X;
  cin >> K >> X;
  for(int i = -K+1; i <= K - 1; i++){
    cout << X + i << " ";
  }

}


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

vector<P> t(10);

int x[10], y[10];
int facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

double dis(int i, int j){
  double dx = t[i].first - t[j].first;
  double dy = t[i].second - t[j].second;
  return pow(dx*dx+ dy*dy, 0.5);
}

double dis2(int i, int j){
  double dx = x[i] - x[j];
  double dy = y[i] - y[j];
  return pow(dx*dx+ dy*dy, 0.5);
}

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

  vector<int> v(N);
  rep(i, N){
    v[i] = i+1;
    cin >> x[i+1] >> y[i+1];
  }
  double sum = 0;
  do{
    rep(i, N-1){
      sum += dis2(v[i], v[i+1]);
    }
  }while(next_permutation(v.begin(), v.end()));
  cout << setprecision(12) << sum / facctorialMethod(N) << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

ll x;

int main(int argc, char const *argv[]) {
	cin >> x;
	// if (x < 11) {
	// 	cout << x / 6 + 1 << endl;
	// 	return 0;
	// }

	ll a = x / 11 * 2;
	x %= 11;
	ll b;
	if (x == 0) {
		b = 0;
	}
	else {
		b = (x-1) / 6 + 1;
	}

	cout << a + b << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
#include <bits/stdc++.h>
#include<cstring>
using namespace std;
int main()
{
    int a[100005];
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int l=a[n-1];
    cout<<l<<" ";
    if(l%2)
    {
         for(int i=0;i<n;i++)
    {
        if(a[i]==l/2||a[i]==(l+1)/2)
        {

            cout<<a[i]<<endl;
            return 0;
        }
        if(a[i]>(l+1)/2)
        {
            if(l-a[i]>a[i-1])
                cout<<a[i];
            else
                cout<<a[i-1];
                cout<<endl;
            return 0;
        }


    }
    }
    else
    {
         for(int i=0;i<n;i++)
    {
        if(a[i]==l/2)
        {

            cout<<a[i]<<endl;
            return 0;
        }
        if(a[i]>l/2)
        {
            if(l-a[i]>a[i-1])
                cout<<a[i];
            else
                cout<<a[i-1];
                cout<<endl;
            return 0;
        }

    }
    }
    cout<<a[n-2]<<endl;
    return 0;


}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int n;

int main() {
    cin >> n;
    vector<int> v1(n), v2(n), sorted;
    rep(i, n) cin >> v1[i];
    rep(i, n) cin >> v2[i];
    sorted = v1;
    sort(all(sorted));
    int a = 0, b = 0;
    do {
        a++;
    } while (next_permutation(all(v1)));
    do {
        b++;
    } while (next_permutation(all(v2)));
    cout << abs(a - b) << endl;
    return 0;
}

Measured memory_bytes: 3628
package main

import (
	"fmt"
)

func Reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func reverseInts(s []int) []int {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
	return s

}

func main() {
	var A, B int
	fmt.Scanf("%v %v", &A, &B)

	for i := B - A + 1; i < A+B; i++ {
		fmt.Printf("%v ", i)
	}

}


Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,s;
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
	s=a+b*5+c*10+d*50+e*100+f*500;
	if(s>=1000){
		printf("1\n");
	}
	else{
		printf("0\n");
	}
	return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define repo(i,o,n) for(int i=o;i<(int)(n);i++)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int a,b,c,cnt;

main() {
    cin >> a >> b >> c;
    for(int i=100;i>0;i--) {
        if (!(a%i) && !(b%i)) cnt++;
        if (cnt == c) {cout << i << endl;return 0;}
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 25, M = 1e6 + 25, oo = 1e9+7, mxmsk = 1 << 16;
const long long OO = 1e18+25;
    
#define f first
#define s second
int t, n,a[N], mxele=-1, mn = oo, idx,idx1;
int main()
{
    scanf("%d",&n);
    for(int i=0; i<n;i++) 
    {
        scanf("%d", a+i);
        if(a[i] > mxele)
        {
            mxele = a[i];
            idx = i;
        }
    }
    for(int i=0; i<n; i++)
    {
        if(idx == i) continue;
        if(max(a[i], mxele-a[i]) < mn)
        {
            mn = max(a[i], mxele-a[i]);
            idx1 = i;
        }
    }
    printf("%d %d",a[idx] , a[idx1]);
    return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        int[] B = new int[N];
        for (int i = 0; i < N; i++) {
            B[i] = sc.nextInt();
        }
        int[] C = new int[N-1];
        for (int i = 0; i < N-1; i++) {
            C[i] = sc.nextInt();
        }
        sc.close();


        System.out.println(Buffet(N, 0, A, B, C));
    }
    public static int Buffet(int N, int index, int[] A, int[] B, int[] C) {
        if (index == N) {
            return 0;
        }
        int score = B[A[index]-1];
        if (index != 0 && A[index-1] + 1 == A[index]) {
            score += C[A[index-1]-1];
        }
        return score + Buffet(N, index + 1, A, B, C);
    }
}


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

ll INF = 1LL << 60;

vector<vector<char>> vec;
vector<pair<int, int>> direct = {{1,0},{-1, 0}, {0,1}, {0, -1}};
vector<vector<int>> dist;
queue<pair<int, int>> que;
int H, W;

int
bfs()
{

  while(!que.empty()){
    int x = que.front().first;
    int y = que.front().second;
    que.pop();
    rep(i, 0, 4){
      int dx = x + direct[i].first;
      int dy = y + direct[i].second;
      if(dx < 0 || dx >= H || dy < 0 || dy >= W) continue;
      if(vec[dx][dy] == '#') continue;
      if(dist[dx][dy] == -1){
        dist[dx][dy] = 1 + dist[x][y];
        que.push({dx, dy});
      }
    }
  }

  int ans = 0;
  rep(i, 0,H){
    rep(k, 0, W){
      ans = max(ans, dist[i][k]);
    }
  }
  return ans;
}

int 
main() {

  cin >> H >> W;
  vec.resize(H);
  dist.resize(H, vector<int>(W, -1));
  rep(i, 0, H){
    rep(k, 0, W){
      char c; cin >> c;
      vec[i].push_back(c);
      if(vec[i][k] == '#') dist[i][k] = 0, que.push({i, k});
    }
  }

  int ans = bfs();


  cout << ans << endl;

}


Measured memory_bytes: 13456
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll x, y;
  cin >> x >> y;
  FORe(i, 0, x){
    ll t = 2*i+4*(x-i);
    if(y == t){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
#define MAX 100
main(){
    int N, A, B, C, X, L[MAX];
    while( cin >> N >> A >> B >> C >> X && N ){
	for ( int i = 0; i < N; i++ ) cin >> L[i];
	int p = 0;
	for ( int f = 0; f <= 10000; f++, X = (A*X+B)%C ){
	    if ( L[p] == X ) p++;
	    if ( p >= N ) { cout << f << endl; break; }
	}
	if ( p < N ) cout << -1 << endl;
    }
}

Measured memory_bytes: 864
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
 
#pragma comment(linker, "/STACK:336777216")  
 
using namespace std;

const int MAXN = 100000 + 10;

int N;
int A[MAXN], B[MAXN], C[MAXN];

void Work()
{
	scanf("%d", &N);
	for (int i = 0; i < N; i ++) scanf("%d", &A[i]);
	for (int i = 0; i < N; i ++) scanf("%d", &B[i]);
	for (int i = 0; i < N; i ++) scanf("%d", &C[i]);
	sort(A, A + N);
	sort(B, B + N);
	sort(C, C + N);
	long long Ans = 0;
	for (int i = 0; i < N; i ++)
	{
		long long a = lower_bound(A, A + N, B[i]) - A;
		long long b = N - (upper_bound(C, C + N, B[i]) - C);
		Ans += a * b;
	}
	printf("%lld\n", Ans);
}

int main()
{
	Work();
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, num, digit, rev = 0;
     scanf("%d",&num);
     n = num;
     do
     {
         digit = num % 10;
         rev = (rev * 10) + digit;
         num = num / 10;
     } while (num != 0);
     if(n==rev)
      printf("Yes");
     else
	  printf("No"); 
	 return 0; 
}

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> a(N), b(N), c(M), d(M);
    for(int i=0; i<N; i++) cin >> a[i] >> b[i];
    for(int i=0; i<M; i++) cin >> c[i] >> d[i];
    
    int dist;
    pair<int,int> mi; mi.second=1e9;
    for(int i=0; i<N; i++){
        mi.second = 1e9;
        for(int j=0; j<M; j++){
            dist = abs(a[i]-c[j])+abs(b[i]-d[j]);
            //cout <<" "<< dist << endl;
            if(dist<mi.second){
                mi.first = j;
                mi.second = dist;
            }
        }
        cout << mi.first+1 << endl;
    }
}



Measured memory_bytes: 256
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

#define bp __builtin_popcountll
#define MOD  1000000007
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
const int N = 200005;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

void solve()
{
   ll a,b,c;
   cin >> a >> b >> c;
   ld temp = a+b;
   ld temp1 = a*b;
   temp1 = sqrt(temp1);
   temp1 = 2*temp1;
   temp += temp1;
   if(temp<c)
   {
   	    cout<<"Yes";
   }
   else
   {
   	    cout<<"No";
   }
}
 
int main()
{
    FAST;
    ll t = 1;
   // cin >> t;
    while(t--)
    {
    	solve();
    }
}

Measured memory_bytes: 256
from sys import stdin
readline = stdin.buffer.readline

def main():
    N = int(readline().rstrip())
    A = list(map(int, readline().rstrip().split()))
    ans = 0
    h = A[0]
    for a in A:
        if a > h:
            h = a
        elif a < h:
            ans += h - a
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 101220
// inputに入力データ全体が入る
function Main(input) {
  
   var input = input.split(" "); 
    var A= parseInt(input[0], 10);
    
    var P= parseInt(input[1], 10);
   var a = 0;
   var a = Math.floor(P /2);
   var b = P % 2;
   var c = Math.floor((A * 3 + b ) / 2 );
   var d = (A * 3 + b ) % 2 ;
 //  console.log(a,b,c,d);
   console.log( a + c);
 
  
 
  	   }    //    1    
     
  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  


Measured memory_bytes: 7372
n = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
# n = 6
# A = [3, 14, 159, 2, 6, 53]
# B = [58, 9, 79, 323, 84, 6]
# C = [2643, 383, 2, 79, 50, 288]
A.sort()
B.sort()
C.sort()
# X[i]=B[i]<C[j]なるjの個数
X = []
j = 0
for i in range(n):
    while j < n and B[i] >= C[j]:
        j += 1
    X.append(n-j)
# S[i]=sum(X[:i])
S = [0]
for i in range(n):
    S.append(S[-1]+X[i])
# A[i]<B[j]なるjに対してS[n]-S[j]をたす
j = 0
ans = 0
for i in range(n):
    while j < n and A[i] >= B[j]:
        j += 1
    ans += S[n]-S[j]
print(ans)


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

int main(){
	int n;cin>>n;
  	vector<int>l(n);
   for(auto&& w:l)cin>>w;
  sort(begin(l),end(l));
  int sm=0;
  for(int i=0;i<n-1;i++)sm+=l[i];
  string ans;
  if(sm>l[n-1])ans="Yes";
  else ans="No";
  cout<<ans<<endl;

}


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

typedef long long int ll;

int main () {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s;
    cin >> s;
    
    if (s[0]=='R' && s[1]=='R' && s[2]=='R') cout << 3 << "\n";
    else if ((s[0]=='R' && s[1]=='R') || (s[1]=='R' && s[2]=='R')) cout << 2 << "\n";
    else if (s[0]=='R' || s[1]=='R' || s[2]=='R') cout << 1 << "\n";
    else cout << 0 << "\n";
    
}


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

signed main(){
    int N;
    cin>>N;
    vector<string> S(N);
    vector<int> p(N);
    REP(i,N) cin>>S[i]>>p[i];
    vector<int> ord(N);
    iota(ord.begin(),ord.end(),0);
    sort(ord.begin(),ord.end(),
         [&](int x,int y){
             if(S[x]!=S[y])return S[x]<S[y];
             else return p[x]>p[y];
         }
    );
    REP(i,N) cout<<ord[i]+1<<endl;
}

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

int main(){
  int N;
  string s, t;
  cin >> N >> s >> t;
  int k;
  int Ans=-1;
  for(int i=0; i<=N; i++){
    k=1;
    for(int j=0; j<N-i; j++){
      if(s.at(j+i)!=t.at(j)){
        k=0;
        break;
      }
    }
    if(k==1){
      Ans=i;
      break;
    }
  }
  cout << Ans+N << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int ans[100010];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		ans[A - 1] = i + 1;
	}
	for (int i = 0; i < N; i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
}


Measured memory_bytes: 3940
#データの読み込み
n, x = input().split()
n = int(n)
x = int(x)
m = []
i_min = 0
gokei = 0
#n個の入力に対するループ
for i in range(n):
  #問題からの入力をintに変換してリストへ格納
  m.append(int(input()))
  #全部を1つずつ作った場合の粉量の合計
  gokei = gokei + m[i]
  #使う粉量が一番少ないドーナツを見つける
  if m[i_min] > m[i]:
    i_min = i
#全部を1つずつ作った後に残る粉量
x = x - gokei
print(int(x/m[i_min]) + n)

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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = n;
  if (n >= b-1) x = b-1;
  ll ans = a*(x%b)/b;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
import std.stdio;
import std.conv;
import std.string;

void main() {
  int S = to!int(chomp(readln()));

  int s = S % 60;
  S /= 60;

  int m = S % 60;
  S /= 60;

  int h = S;

  writeln(to!string(h) ~ ":" ~ to!string(m) ~ ":" ~ to!string(s));
}

Measured memory_bytes: 2464