akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)

struct card {
  int num;
  char suit;
};

bool operator==(const card &lhs, const card &rhs) {
  return lhs.num == rhs.num && lhs.suit == rhs.suit;
}

vector<card> bubbleSort(vector<card> c) {
  int n = c.size();
  rep(i,n) for(int j = n - 1; j > i; j--) {
    if(c[j-1].num > c[j].num) swap(c[j], c[j-1]);
  }
  return c;
}

vector<card> selectionSort(vector<card> c) {
  int n = c.size();
  for(int i = 0; i < n - 1; i++) {
    int mini = i;
    for(int j = i + 1; j < n; j++) {
      if(c[j].num < c[mini].num) mini = j;
    }
    swap(c[i], c[mini]);
  }
  return c;
}


int main () {
  int n;

  scanf("%d\n", &n);
  vector<card> c(n);

  rep(i,n){
    if(i > 0) scanf(" ");
    scanf("%c%d", &c[i].suit, &c[i].num);
  }

  vector<card> bsorted = bubbleSort(c);
  rep(i,n) {
    if(i > 0) printf(" ");
    printf("%c%d", bsorted[i].suit, bsorted[i].num);
  }
  printf("\nStable\n");

  vector<card> ssorted = selectionSort(c);
  rep(i,n) {
    if(i > 0) printf(" ");
    printf("%c%d", ssorted[i].suit, ssorted[i].num);
  }
  printf("\n");
  printf(bsorted == ssorted ? "Stable" : "Not stable");
  printf("\n");

  return 0;
}

Measured memory_bytes: 3244
use List::Util qw(max sum);
my ($n, $k) = split(/\s+/, <>);
my ($s) = split(/\s+/, <>);

my (@counts) = ();

my $len = length($s);
my $bit = 1;
my $c   = 0;
for (my $i=0; $i<$len; $i++) {
    #print substr($s, $i, 1), "\n";
    if (substr($s, $i, 1) == $bit) {
	$c++;
    } else {
	push @counts, $c;
	$bit = 1-$bit;
	$c = 1;
    }
}
push @counts, $c;
$len = @counts;
push @counts, 0 for (0..$k*2+1);
#print "$len, ", join(" ", @counts), "\n";

my $sum = sum(@counts[0..$k*2]);
my $max = $sum;
for (my $out=0,$in=$k*2+1; $out<$len; $in+=2,$out+=2) {
    $sum += $counts[$in]+$counts[$in+1] - $counts[$out]-$counts[$out+1];
    $max = max($max, $sum);
}
print "$max\n";


Measured memory_bytes: 15232
//header files
#include <iostream>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;


int main()
{
	char S[3];
	int prefix[3];
	cin>>S;
	if (S[0]=='S') prefix[0]=0;
	else prefix[0]=1;
	for(int i=1;i<3;i++)
	{
		if(S[i]=='R')
			if(S[i-1]=='R')
				prefix[i]=prefix[i-1]+1;
			else
				prefix[i]=1;
		else
			prefix[i]=0;
	}
	/*for (int i = 0; i < 3; ++i)
	{
		cout<<prefix[i]<<endl;
	}*/
	if(prefix[0]==0 && prefix[1]==0 && prefix[2]==0)
		{
			cout<<0;
			return 0;
		}
	if((prefix[0]>=prefix[1])&&(prefix[0]>=prefix[2]))
		cout<<prefix[0];
	else if((prefix[1]>=prefix[0])&&(prefix[1]>=prefix[2]))
		cout<<prefix[1];
	else if((prefix[2]>=prefix[0])&&(prefix[2]>=prefix[1]))
		cout<<prefix[2];
 

	return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    vector<int>a(3);
    for(int i=0;i<3;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    if(a[0]==5 && a[1]==5 && a[2]==7)cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

template <int MOD>
struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
    constexpr Fp operator+(const Fp& r) const noexcept {
        return Fp(*this) += r;
    }
    constexpr Fp operator-(const Fp& r) const noexcept {
        return Fp(*this) -= r;
    }
    constexpr Fp operator*(const Fp& r) const noexcept {
        return Fp(*this) *= r;
    }
    constexpr Fp operator/(const Fp& r) const noexcept {
        return Fp(*this) /= r;
    }
    constexpr Fp& operator+=(const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator-=(const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator*=(const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator/=(const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator==(const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator!=(const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator<<(ostream& os,
                                         const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD>& a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

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

    vector<int> A(N);
    mint sum = 0;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        sum += tmp;
        A[i] = tmp;
    }

    mint output = 0;
    for (int i = 0; i < N; i++) {
        sum -= A[i];
        output += sum * A[i];
    }

    cout << output << endl;

    return 0;
}


Measured memory_bytes: 4044
/* Bismillahir Rahmanir Rahim
There is no god without Allah*/
#include<bits/stdc++.h>
#include<iomanip>
typedef long long ll;
typedef unsigned long long ul;
#define pi acos(-1)
#define ll long long
#define ull unsigned long long
#define vec vector<ll>
#define f1(i,n) for(i=1;i<n;i++)
#define test   ll t;cin>>t;while(t--)

long long int i,j;
using namespace std;

int main()
{
    map<string,int>m;
    test
    {

      string st;cin>>st;
      m[st]++;
    }
    //cout<<"------\n";
    cout<<"AC x "<<m["AC"]<<endl;
    cout<<"WA x "<<m["WA"]<<endl;
    cout<<"TLE x "<<m["TLE"]<<endl;
    cout<<"RE x "<<m["RE"]<<endl;



}
// Alhamdulillah


Measured memory_bytes: 3640
import java.util.*;
import java.io.*;
class Main{
	public static void main(String[]args){
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out, true);
		String str[]=in.nextLine().split(" ");
		Stack<Integer> st=new Stack<>();
		for(int i=0;i<str.length;i++){
			try{
				int a=Integer.parseInt(str[i]);
				st.push(a);
			}catch(Exception e){
				if(str[i].equals("+")){
					int a=st.pop();
					int b=st.pop();
					st.push(a+b);
				}else if(str[i].equals("-")){

					int a=st.pop();
					int b=st.pop();
					st.push(b-a);
				}else{
					int a=st.pop();
					int b=st.pop();
					st.push(a*b);
				}
			}
		}
		out.println(st.pop());
	}

}


Measured memory_bytes: 26208
#include<bits/stdc++.h>
using namespace std;
#define maxn 1000005
typedef long long ll;
ll n,x;
int main()
{
    cin>>x;
    n=x/11;
    n*=2;
    if(x%11>0) n+=((x%11)<=6?1:2);
    cout<<n<<endl;
}


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

using namespace std;

int main(){
    string str;
    cin >> str;
    int n = str.size();
    vector<int> ans(n), left, right;
    for(int i = 0; i < n; i++){
        if(str[i] == 'L'){
            left.push_back(i);
        }else{
            right.push_back(i);
        }
    }
    for(int i = 0; i < n; i++){
        if(str[i] == 'L'){
            int p = *(lower_bound(begin(right), end(right), i) - 1);
            int s = i - p;
            if(s % 2){
                ans[p + 1]++;
            }else{
                ans[p]++;
            }
        }else{
            int p = *upper_bound(begin(left), end(left), i);
            int s = p - i;
            if(s % 2){
                ans[p - 1]++;
            }else{
                ans[p]++;
            }
        }
    }
    for(int i = 0; i < n - 1; i++){
        cout << ans[i] << " ";
    }
    cout << ans[n - 1] << "\n";
}

Measured memory_bytes: 1532
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"YES"<<endl;}else cout<<"NO"<<endl;//条件によってYes、Noを出力する

int main(){
    int n;
    cin>>n;
    map<int,int> d,t;
    rep(i,n){
        int D;
        cin>>D;
        d[D]++;
    }
    bool ans=true;
    int m;
    cin>>m;
    rep(i,m){
        int T;
        cin>>T;
        t[T]++;
    }
    if(n<m){
        ans = false;
    }
    for(auto c:t){
        int dif = c.first;
        int cnt = c.second;
        if(d[dif]<cnt){
            ans = false;
        }
    }
    YN(ans);
}

Measured memory_bytes: 18944
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int i = 0;
        int j = 0;
        int sum = 0;
        int n = sc.nextInt();
        int m = sc.nextInt();
        
        int A[][] = new int[n][m];
        int b[] = new int[m];
        
        for(i=0; i<n; i++){
            for(j=0; j<m; j++){
                A[i][j] = sc.nextInt();
            }
        }
        
        for(j=0; j<m; j++){
            b[j] = sc.nextInt();
        }
        
        for(i=0; i<n; i++){
            sum = 0;
            for(j=0; j<m; j++){
                sum = sum +(A[i][j]*b[j]);
            }
            System.out.println(sum);
        }
        
    }
}



Measured memory_bytes: 40292
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll w[105], v[105], dp[100005];
int main() {
  int n, W;
  cin >> n >> W;
  ll maxc = 0;
  fill(dp + 1, dp + 100005, 0x3f3f3f3f);
  for (int i = 1; i <= n; i++) {
    cin >> w[i] >> v[i];
    maxc += v[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = maxc; j >= v[i]; j--) {
      dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
    }
  }
  for (int j = maxc; j >= 0; j--) {
    if (dp[j] <= W) {
      cout << j << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 1024
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
H = list(t-h[i]*(0.006) for i in range(n))
d = abs(H[0]-a)
k = 1
for i in range(1,n):
  if d > abs(H[i]-a):
    d = abs(H[i]-a)
    k = i + 1
print(k)
    


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int maxn = 1e5+5;
int a[maxn],b[maxn];
ll sum[maxn][55];

int main()
{
    ll n, m;
    cin >> n >> m;
    if(n<m) {
        cout << min(n, m-n);
    }
    else{
        cout << min(n-(1ll)*(n/m)*m, (1ll)*(n/m+1)*m-n);
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
M = list(map(int,input().split()))


def bitsearch():
  nums = [0] * (2 ** N)
  for i in range(2 ** N):
    num = 0
    for j in range(N):
      if (i >> j) & 1:
        num += A[j]
        nums[i] = num
  for q in range(Q):
    if M[q] in nums:
      print("yes")
    else:
      print("no")

bitsearch()



Measured memory_bytes: 42968
#include<bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i = 1; i <= (int)(n); i++)

int main(){
    while(1){
        int n,x;
        cin>>n>>x;
        if(n==0&&x==0)break;
        int count=0;
        reps(i,n){
            reps(j,n){
                reps(k,n){
                    if(i+j+k==x&&i<j&&j<k)count++;
                }
            }
        }
        cout<<count<<endl;
    }
    return 0;
}


Measured memory_bytes: 3084
odd, even = map(int, input().split())
sum_odd = 0
sum_even = 0

if odd != 1:
	for i in range(1, odd):
  		sum_odd += i
else: 
  sum_odd = 0

if even != 1:
  for i in range(1, even):
  	sum_even += i
else:
  sum_even = 0
  
print(sum_odd + sum_even)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;

int main()
{
	int n, k;
	cin >> n >> k;
	int a[N];
	int i;
	for(i = 0; i < n; i++)
		cin >> a[i];
	int ft, lt;
	int tmp = 0;
	while(tmp + k < i){
		ft = a[tmp];
		lt = a[tmp + k];
		if(lt > ft)
			cout << "Yes\n";
		else
			cout << "No\n";
		tmp++;
	}
	return 0;
}

Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
char s[100005], t[100005];
int sum1[2][100005], sum2[2][100005];
int main(){
    scanf("%s%s", s+1, t+1);
    int n = strlen(s+1), m = strlen(t+1);
    for(int i=1;i<=n;i++){
        sum1[s[i]-'A'][i]++;
        sum1[0][i] += sum1[0][i-1];
        sum1[1][i] += sum1[1][i-1];
    }
    for(int i=1;i<=m;i++){
        sum2[t[i]-'A'][i]++;
        sum2[0][i] += sum2[0][i-1];
        sum2[1][i] += sum2[1][i-1];
    }
    int q;
    scanf("%d", &q);
    while(q--){
        int a, b, c, d;
        scanf("%d%d%d%d", &a, &b, &c, &d);
        int B1 = (sum1[0][b] - sum1[0][a-1])*2 + (sum1[1][b] - sum1[1][a-1]);
        int B2 = (sum2[0][d] - sum2[0][c-1])*2 + (sum2[1][d] - sum2[1][c-1]);
        if(B1%3 == B2%3) printf("YES\n");
        else printf("NO\n");
    }
}

Measured memory_bytes: 2304
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<cmath>
#include<string>
#include<algorithm>
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define pi acos(-1.0)
using namespace std;
const int maxn = 1e6+5;

int main(){
	ll n, k; cin >> n >> k;
	n %= k;
	if(n <= abs(n - k)) cout << n << endl;
	else cout << abs(n - k) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string x;
    cin >> x;
    ll ans = SZ(x);
    stack<ll> s;
    rep(i, SZ(x)){
        if(x[i] == 'S'){
            s.push(i);
        }else if(!s.empty()){
            s.pop();
            ans -= 2;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N;cin>>N;
    vector<int> ans(26);
    for(int i=0;i<26;i++)ans.at(i)+=50;
    string S;
    for(int i=0;i<N;i++){
        vector<int> now(26);
        cin>>S;
        for(int i=0;i<S.size();i++)now.at(S.at(i)-'a')++;
        for(int i=0;i<26;i++){
            ans.at(i)=min(ans.at(i),now.at(i));
        }
    }
    for(int i=0;i<26;i++){
        for(int j=0;j<ans.at(i);j++){
            cout<<char('a'+i);
        }
    }
    cout<<endl;
    return 0;
}

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

int h,w,k;
bool g[15][1005];
int bel[15],bks;
int tmp[15],tot[15];

int solve(){
    int res=0;
    memset(tot,0,sizeof(tot));
    for(int i=0;i<w;i++){
        memset(tmp,0,sizeof(tmp));
        for(int j=0;j<h;j++){
            tmp[bel[j]]+=g[j][i];
        }
        bool cut=false;
        for(int j=0;j<=bks;j++){
            if(tmp[j]>k)return 0x3f3f3f3f;
            if(tmp[j]+tot[j]>k){
                cut=true;
            }
        }
        if(cut){
            res++;
            memset(tot,0,sizeof(tot));
        }
        for(int j=0;j<=bks;j++){
            tot[j]+=tmp[j];
        }
    }
    return res;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>h>>w>>k;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char c;
            cin>>c;
            g[i][j]=c=='1';
        }
    }
    int ans=0x3f3f3f3f;
    for(int s=0;s<1<<(h-1);s++){
        bks=0;
        for(int i=0;i<h;i++){
            bel[i]=bks;
            if(s>>i&1)bks++;
        }
        ans=min(ans,__builtin_popcount(s)+solve());
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 384
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
ll n;
ll a[110];
cin>>n;
rep(i,0,n) cin>>a[i];
bool ok=true;
rep(i,0,n){
if(a[i]%2==0){
if(a[i]%3!=0&&a[i]%5!=0)ok=false;
}
}
if(ok) print("APPROVED");
else print("DENIED");
    

}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main()
	{
		int N = GetInt();
		int[] P = new int[N];
		for(int i = 0; i < N; i++)
			P[i] = GetInt() - 1;

		int[] Q = new int[N];
		for(int i = 0; i < N; i++)
			Q[P[i]] = i;
		
		int len = 1;
		int num = 1;
		for(int j = 1; j < N; j++)
		{
			if(Q[j] > Q[j - 1])
				num++;
			else
				num = 1;

			len = Math.Max(len, num);
		}
		
		Console.WriteLine(N - len);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 17284
object Main extends App {
  import math.BigInt

  def solve(N: Int, A: Int, xs: List[Int]): BigInt = {
    val ys = Array(0) ++ xs.map(_ - A)
    val X = math.max(xs.max, A)
    val dp = Array.ofDim[BigInt](N + 1, 2 * N * X + 1)

    dp(0)(N * X) = 1
    for { j <- 0 to N; t <- 0 to 2 * N * X } {
      if (j == 0 && t == N * X) {
        dp(j)(t) = 1
      } else if (j >= 1 && (t - ys(j) < 0 || t - ys(j) > 2 * N * X)) {
        dp(j)(t) = dp(j - 1)(t)
      } else if (j >= 1 && (t - ys(j) >= 0 && t - ys(j) <= 2 * N * X)) {
        dp(j)(t) = dp(j - 1)(t) + dp(j - 1)(t - ys(j))
      } else {
        dp(j)(t) = 0
      }
    }
    val combs = dp(N)(N * X) - 1
    combs
  }

  val sc = new java.util.Scanner(Console.in)
  val n = sc.nextInt()
  val a = sc.nextInt()
  val nums = List.fill(n)(sc.nextInt())
  val ans = solve(n, a, nums)
  println(ans)
}

Measured memory_bytes: 34756
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }

ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}

int main(){
    ios::sync_with_stdio(false);
	int n;
	cin >> n;
	if(n%10==7||(n/10)%10==7||(n/100)%10==7){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
    return 0;
}

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

int stamina(int x, int p){
	return (x-p)*(x-p);
}

int main(){
	int n,p,minS, maxLoc, minLoc;
	int loc[1000];
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> loc[i];
		if(i==0){
			maxLoc = loc[i];
			minLoc = maxLoc;
		}else{
			maxLoc = (maxLoc > loc[i]) ? maxLoc : loc[i];
			minLoc = (minLoc < loc[i]) ? minLoc : loc[i];
		}
	}

	for(int i = minLoc; i <= maxLoc; i++){
		int tmp = 0;
		p = i;
		for (int j = 0; j < n; j++){
			tmp += stamina(loc[j], p);
		}
		if(i==minLoc){
			minS = tmp;
		}else{
			minS = (tmp < minS) ? tmp : minS;
		}
	}

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

}

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

int sosu[500000];
int scmax,sosumi;

void setsosu(int n){
  int flg,j;
  if (n<scmax) return;
  for (int i=scmax+1;i<=n;i++){
    flg=0;
    for (j=sosu[0];j<=sqrt(i);j++){
      //cout << i << " " << j << " " << i%j << endl;
      if (i%j==0){flg =1;break;}
    }
    if (flg==0) sosu[++sosumi]=i;
  }
  scmax =n;
}
int nibutan(int n){
  int l,r,m;
  l=0;
  r=sosumi+1;
  while (l<r){
    m=(l+r)/2;
    if (sosu[m]>n){
      r=m;
    }else if (sosu[m]<n){
      l=m+1;
    }else{
      return 1;
    }
  }
  return 0;
}
int main(){
  int n,ret;
  sosu[0]=2;
  sosu[1]=3;
  sosu[2]=5;
  sosu[3]=7;

  scmax=7;
  sosumi=3;

  while (1){
    cin >> n;
    if (n==0) break;
    ret =0;
    setsosu(n);
    for (int i=sosu[1];i<=n/2;i+=2){
      if (nibutan(i)==1&&nibutan(n-i)==1) {
	ret++;
	//cout << i <<" "<< n-i << endl;

      }
    }
    cout << ret << endl;
  }
  return 0;
}

Measured memory_bytes: 1464
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int n,m;
	while(cin>>n>>m,n||m){
		// cout<<n<<" "<<m<<endl;
		vint v(n);
		rep(i,n){
			cin>>v[i];
		}
		v.PB(0);
		// set<int> se;
		vint se;
		rep(i,n+1){
			rep(j,n+1){
				// se.insert(v[i]+v[j]);
				se.PB(v[i]+v[j]);
			}
		}
		sort(ALL(se));
		se.erase(unique(ALL(se)),se.end());
		// cout<<(int)se.size()<<endl;
		// se.insert(0);
		int ans=0;
		for(auto i:se){
			if(i>m) break;
			auto it=upper_bound(ALL(se),m-i);
			it--;
			ans=max(ans,i+*it);
		}
		cout<<ans<<endl;
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
class DSU{
public:
	DSU(int n){
		parent.resize(n+1);
		size.resize(n+1);
		set_sz=n;
		for(int i=1;i<=n;i++){
			parent[i]=i;
			size[i]=1;
		}
	}
	void union_set(int a, int b){
		a=find_set(a);
		b=find_set(b);
		if(a!=b){
			set_sz--;
			if(size[a]<size[b])
				swap(a,b);
			parent[b]=a;
			size[a]+=size[b];
		}
	}
	int find_set(int v){
		if(v==parent[v])
			return v;
		return find_set(parent[v]);
	}
	int get_num_sets(){
		return set_sz;
	}
private:
	vector<int>parent, size;
	int set_sz;
};
int main(){
	int n,m; cin>>n>>m;
	DSU my_dsu(n);
	while(m--){
		int x,y,z; cin>>x>>y>>z;
		my_dsu.union_set(x,y);
	}
	set<int>st;
	for(int i=1;i<=n;i++){
		int x=my_dsu.find_set(i);
		st.insert(x);
	}
	cout<<st.size()<<endl;
	return 0;
}

Measured memory_bytes: 5760
#!/usr/bin/env python3

N, C, K = list(map(int, input().split()))
t_list = []

for _ in range(N):
    t = int(input().split()[0])
    t_list.append(t)

waiting_n = 0
dead_line_t = float("inf")
bus_count = 0
t_list = sorted(t_list)

for i, t in enumerate(t_list):
    if waiting_n == 0:
        dead_line_t = t + K

    waiting_n += 1

    if waiting_n >= C:
        # 定員に達したので出発する
        waiting_n = 0
        bus_count += 1
        continue

    if i == len(t_list) - 1:
        # 最後の一人はどのみち乗せるしかない
        bus_count += 1
        break

    if t_list[i + 1] > dead_line_t:
        # 出発しないと怒り出す客がいる
        waiting_n = 0
        bus_count += 1
        continue


ans = bus_count
print(ans)


Measured memory_bytes: 8280
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K, H, W, L, R, l, r, u, d, sum, Q;
LL ans;
LL no;
bool b, bb[100001];
string s, t;
int main() {
	cin >> N;
	map <string, LL> m;
	for (int i = 0; i < N; i++) {
		cin >> s;
		m[s]++;
		}
	sum = 0;
	for (auto a = m.begin(); a != m.end(); a++) {
		sum = max(a->second, sum);
	}
	for (auto a = m.begin(); a != m.end(); a++) {
		if(a->second==sum)cout << a->first << endl;
	}
	return 0;
}



Measured memory_bytes: 25216
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    vector<int>a(3);
    rep(i,3) cin >> a[i];
    int ans = 0;
    while(a[0] != a[1] || a[0] != a[2] || a[1] != a[2]) {
        sort(a.begin(),a.end());
        if(a[1] != a[2]) {
            a[0]++;
            a[1]++;
        }
        else a[0] += 2;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
a=[list(map(int,input().split())) for i in range(3)]
n=int(input())
for i in range(n):
    b=int(input())
    for j in range(3):
        for k in range(3):
            if b==a[j][k]:
                a[j][k]=-1
if (a[0][1]==-1 and a[0][2]==-1 and a[0][0]==-1):
    print("Yes")
elif a[1][0]==-1 and a[1][1]==-1 and a[1][2]==-1:
    print("Yes")
elif a[2][0]==-1 and a[2][1]==-1 and a[2][2]==-1:
    print("Yes")
elif a[0][0]==-1 and a[1][0]==-1 and a[2][0]==-1:
    print("Yes")
elif a[0][1]==-1 and a[1][1]==-1 and a[2][1]==-1:
    print("Yes")
elif a[0][2]==-1 and a[1][2]==-1 and a[2][2]==-1:
    print("Yes")
elif a[0][0]==-1 and a[1][1]==-1 and a[2][2]==-1:
    print("Yes")
elif a[2][0]==-1 and a[1][1]==-1 and a[0][2]==-1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 62288
N = int(input())
a = list(map(int, input().split()))

for i in range(N-1):
    a[i+1] += a[i]
j = 0
k = 2
ans = 10**9

# j, i, k(の右側)で区切る
# iを一旦固定して、j, kをそれぞれ右へ移動させる
# iの取り得る値は1〜N-3(N-2の手前)
for i in range(1, N-2):
    while abs(a[j]*2-a[i]) > abs(a[j+1]*2-a[i]):
    # a[j]-(a[i]-a[j]) A:B:C:DのA-B
    # a[j+1]-(a[i]-a[j-1]) A:B:C:DのA-B
    # A-Bが最小となるjを探す
        j += 1
    
    while abs(a[k]*2-a[i]-a[N-1]) > abs(a[k+1]*2-a[i]-a[N-1]):
    # (a[k]-a[i])-(a[N-1]-a[k]) A:B:C:DのC-D
    # (a[k+1]-a[i])-(a[N-1]-a[k+1]) A:B:C:DのC-D
    # C-Dが最小となるkを探す
        k += 1
    
    # 順にA, B, C, Dを出す
    t=[a[j], a[i]-a[j], a[k]-a[i], a[N-1]-a[k]]
    ans = min(ans, max(t)-min(t))

print(ans)

Measured memory_bytes: 108664
a, b = gets.split.map(&:to_i)
loop {
    leap = (a..b).select{|y|
        y % 400 == 0 ? true :
        y % 100 == 0 ? false :
        y % 4 == 0 ? true : false
    }
    puts leap.empty? ? "NA" : leap
    a, b = gets.split.map(&:to_i)
    break if a == 0
    puts
}


Measured memory_bytes: 6852
S = [ord(i) for i in input()] + [96]

def solve() :
  for i in range(len(S) - 1, -1, -1) :
    for j in range(S[i] + 1, 97 + 26) :
      if not j in S[:i+1] :
        S[i] = j
        return ''.join(map(chr, S[:i+1]))
  return -1

print(solve())

Measured memory_bytes: 38384
N,M,D = map(int, input().split())

# 1~Nまでの数字でペアを作るとき、差がDになる組の個数
# (d+1, 1), ..., (N, N - D)のN-D個とこれの左右を入れ替えたやつで2*(N - D)個
tmp = N if D == 0 else (N -D) * 2
# 分母は左右の選び方がそれぞれN個あるのでN**2
# それがM-1項ある
ans = tmp / N**2 * (M-1)

print(ans)

Measured memory_bytes: 2940
import java.util.*;
import java.io.*;

class Main
{
    static class Len
    {	
	int a[]; //= new int[2000010];
	int b[]; //= new int[2000010];
	
	Len(int n)
	{
	    a = new int[n+1];
	    b = new int[n+1];
	}
	

    }

    public static void main(String args[])
    {
	int n;
	int i, j, k;

	String line = new String();
	BufferedReader bin = new BufferedReader(new InputStreamReader(System.in));

	//Read ----------------
	//Read n
	try{
	    line=line=bin.readLine();
	}	
	catch(IOException e){
	    System.out.println("Error");
	}

	n=Integer.parseInt(line);
	Len len = new Len(n);
	j=0;
	//Read A[]
	try{
	    line=bin.readLine();
	    //System.out.println(line);
	    StringTokenizer str = new StringTokenizer(line);   
	    for(i=0; i<n; i++)
		{
		    len.a[i]=Integer.parseInt(str.nextToken());
		    if(j<len.a[i])j=len.a[i];
		}
	}
	catch(IOException e){
	    System.out.println("Error");
	}

	//bin=null;

	//Read end------------


	//sort
	countingSort(len, j, n);

	//print
	StringBuffer s = new StringBuffer(85000);
	for(i=1; i<=n; i++)
	    {
		s.append(len.b[i]);
		if(i!=n)s.append(" ");
	    }
	System.out.println(s);

    }

    static void countingSort(Len len, int max, int n)
    {
	int i, j, k;
	int[] c = new int[max+1];

	for(i=0; i<n; i++)c[len.a[i]]++;

	for(i=0; i<=max; i++)
	    {
		if(i!=0)c[i]+=c[i-1];
	    }

	for(i=n-1; i>=0; i--)
	    {
		len.b[c[len.a[i]]]=len.a[i];
		c[len.a[i]]--;
	    }
    }
}

Measured memory_bytes: 102000
#include<cstdio>
#include<iostream>
using namespace std;
const int N=22;
const int FULLS=(1<<21);
const int mod=1e9+7;
int n,a[N][N],dp[N][FULLS];bool vis[N][FULLS];
inline void Add(int &x,int y){x+=y;x-=x>=mod? mod:0;}
inline int MOD(int x,int y){x+=y;x-=x>=mod? mod:0;return x;}
inline int DFS(int x,int S){
	if(x==n+1)return 1;
	if(vis[x][S])return dp[x][S];
	for(register int i=1;i<=n;i++)
		if(a[x][i]&&!((S>>(i-1))&1))
			Add(dp[x][S],DFS(x+1,S|(1<<(i-1))));
	vis[x][S]=true;return dp[x][S];
}
int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;i++)
		for(register int j=1;j<=n;j++)
			scanf("%d",&a[i][j]);
	printf("%d\n",DFS(1,0));
	return 0;
}

Measured memory_bytes: 207104
#!/usr/bin/env python3
w,h,n = map(int,input().split())
# １行ですでにai がわかっているから逐次的に処理していけば良い。
min_x,min_y = w,h
max_x,max_y = 0,0
for i in range(n):
    x,y,a = map(int,input().split())
    #print(x,y,a)
    if a == 1: max_x = max(max_x,x)
    if a == 2: min_x = min(min_x,x)
    if a == 3: max_y = max(max_y,y)
    if a == 4: min_y = min(min_y,y)
#print(max_x,max_y,min_x,min_y)
print(max(0,min_x - max_x) * max(0,min_y - max_y))

Measured memory_bytes: 3064
# AOJ 0564: Bug Party
# Python3 2018.6.30 bal4u

import heapq
tbl = []
N = int(input())
for i in range(N):
	a, b = map(int, input().split())
	tbl.append((a, b))
tbl.sort()
Q = []
ans = s = sz = 0
for t in tbl:
	s += t[0]
	heapq.heappush(Q, (t[1], t[0]))
	sz += 1
	while sz and sz*Q[0][0] < s:
		s -= Q[0][1]
		heapq.heappop(Q)
		sz -= 1
	if sz > ans: ans = sz
print(ans)


Measured memory_bytes: 68912
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

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

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

    int ali=0;
    int bob=0;
    for(int i=0;i<n;i++){
        if(i%2==0){
            ali = ali + a[i];
        }
        else{
            bob = bob + a[i];
        }
    }
    cout << ali - bob << endl;
    return 0;
       
}

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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

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

  vec<ll> q(N);
  REP(i, N) {
    ll a;
    cin >> a;
    q[i] = a;
  }
  sort(ALL(q), greater<ll>());

  ll answer = 0;
  REP(i, N) { answer = (i % 2 == 0) ? answer + q[i] : answer - q[i]; }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 256
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

sys.setrecursionlimit(10**9)
mod = 10**7+9
inf = 10**20


n,a,b = list(map(int,input().split()))

if n<=a+b:
    l = n//(a+b)
    p = min(n%(a+b),a)
    print((l*a)+p)
else:
    ans = (n//(a+b))*a
    ans += min(n%(a+b),a)
    print(ans)





Measured memory_bytes: 5692
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    string s;
    cin >> s;
    //同じ文字同士が隣り合うような局面がでるような文字のとり方が絶対にできない
    //最終的には最適に取るとxaxaxみたいな交互状態になっているはず
    //xaxaxaみたいな状態になると隣り合わないように取るためには端から取っていく
    //後は両端を気にするだけ
    if(s[0] == s[s.length()-1]){
        if((s.length() - 2) % 2 == 1){
            cout << "Second" << endl;
        }else{
            cout << "First" << endl;
        }
    }else{
        if((s.length() - 2) % 2 == 1){
            cout << "First" << endl;
        }else{
            cout << "Second" << endl;
        }        
    }

}

Measured memory_bytes: 512
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n,ans=0;
  ll a,b,c;
  cin>>a>>b>>c;
  ans=b+c-a;
  if(ans<0)ans=0;
  cout<<ans<<endl;
}


Measured memory_bytes: 888
import scala.io.StdIn

object Main extends App {
    val in = StdIn.readLine.split(" ").map(_.toInt)
    val k = in(0)
    val x = in(1)
    
    val min = x - (k - 1)
    val max = x + (k - 1)
    
    val range = Range(min, max + 1)
    println(range.mkString(" "))
}


Measured memory_bytes: 27192
using System;
using System.Linq;
using System.Collections;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using static System.Console;
using static System.Math;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            MyInputStream cin = new MyInputStream();

            WriteLine(ReadLine().Replace(',', ' '));
        }
    }

    public class MyInputStream
    {
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(char separator = ' ')
        {
            this.separator = separator;
            inputStream = new Queue<string>();
        }

        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = Console.ReadLine().Split(separator);
            for (int i = 0; i < tmp.Length; i++)
            {
                inputStream.Enqueue(tmp[i]);
            }
            return inputStream.Dequeue();
        }
        public string ReadLine() => Console.ReadLine();
        public int ReadInt() => int.Parse(Read());
        public long ReadLong() => long.Parse(Read());
        public double ReadDouble() => double.Parse(Read());
    }

    public class Pair<T1, T2>
    {
        public T1 First;
        public T2 Second;
        public Pair() { First = default(T1); Second = default(T2); }
        public Pair(T1 f, T2 s) { First = f; Second = s; }
        public override string ToString() { return "(" + First + ", " + Second + ")"; }
        public override int GetHashCode() { return First.GetHashCode() ^ Second.GetHashCode(); }
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(this, obj)) return true;
            else if (obj == null) return false;
            var tmp = obj as Pair<T1, T2>;
            return (object)tmp != null && First.Equals(tmp.First) && Second.Equals(tmp.Second);
        }
    }

    #region HashMap
    public class HashMap<K, V> : Dictionary<K, V>
    {
        public HashMap() : base() { }
        public HashMap(int cap) : base(cap) { }
        public HashMap(IDictionary<K, V> dictionary) : base(dictionary) { }
        new public V this[K i]
        {
            get
            {
                V v;
                return TryGetValue(i, out v) ? v : base[i] = default(V);
            }
            set { base[i] = value; }
        }
    }
    #endregion
}


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

int main() {
	int n,k,p,ans;
	
	cin>>n;
	
	for(int i=0;i<n;i++){
		
		cin>>k>>p;
		
		ans=k%p;
		
		if(ans==0)ans=p;
		
		cout<<ans<<endl;
	
		
	}
	return 0;
}

Measured memory_bytes: 3076
# import bisect
from collections import Counter, deque # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    N=int(input())
    A=list(map(int,input().split()))

    AA=Counter(A)

    ans=0
    for k in AA.keys():
       ans=max(ans,AA[k+1]+AA[k]+AA[k-1])
    print(ans)


resolve()

Measured memory_bytes: 56044
# 1
# https://atcoder.jp/contests/diverta2019/tasks/diverta2019_a
if False:
    N,K=map(int,input().split())
    print(N-K+1)

# 2
# https://atcoder.jp/contests/m-solutions2019/tasks/m_solutions2019_b
if True:
    print('NO' if input().count('x')>7 else 'YES')


# 3
# https://atcoder.jp/contests/m-solutions2019/tasks/m_solutions2019_a

# 4
# https://atcoder.jp/contests/agc037/tasks/agc037_a


# 5
# https://atcoder.jp/contests/agc041/tasks/agc041_a

Measured memory_bytes: 2940
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<int> gr[114514];
int dp[114514];
int out=0;
int dfs(int v,int u){
	vector<int> cal(36,0);
	rep(i,gr[v].size()){
		int w=gr[v][i];
		if(u==w) continue;
		int t=dfs(w,v);
		rep(j,30){
			if((t&(1<<j))) cal[j]++;
		}
	}
	int ma=-1,mi=36;
	rep(i,30){
		if(cal[i]>1) ma=max(ma,i);
	}
	REP(j,ma+1,30){
		if(cal[j]<1) mi=min(mi,j);
	}
	out=max(out,mi);
	dp[v]=0;
	rep(i,30){
		if(i==mi) dp[v]+=(1<<i);
		else if(i>mi && cal[i]>0) dp[v]+=(1<<i);
	}
	//cout<<v<<' '<<u<<' '<<dp[v]<<endl;
	return dp[v];
}
int main()
{
	int n,a,b;
	cin>>n;
	rep(i,n-1){
		cin>>a>>b;a--;b--;gr[a].pb(b);gr[b].pb(a);
	}
	dfs(0,-1);
	cout<<out<<endl;
}


Measured memory_bytes: 23560
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << (h2-h1)*60 + m2-m1 - k << endl;
    return 0;
}


Measured memory_bytes: 3580
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int maxn = 210000;

struct edge{
	int v,next;
};

edge g[maxn << 1];
int head[maxn], dist[maxn];
queue<int> q;

void insert(int u,int v){
	static int id;
	g[++id].v = v;
	g[id].next = head[u];
	head[u] = id;
}

void bfs(int source){
	memset(dist, 0, sizeof dist);
	dist[source] = 1;
	while (!q.empty()) q.pop();
	q.push(source);
	while (!q.empty()){
		int u = q.front();
		q.pop();
		for (int i = head[u];i;i = g[i].next){
			int v = g[i].v;
			if (dist[v] == 0){
				dist[v] = dist[u] + 1;
				q.push(v);
			}
		}
	}
}

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1;i < n;i++){
		int x, y;
		scanf("%d%d",&x ,&y);
		insert(x, y);
		insert(y, x);
	}
	bfs(1);
	int maxid = 0;
	for (int i = 1;i <= n;i++){
		if (dist[i] > dist[maxid]) maxid = i;
	}
	bfs(maxid);
	int diameter = 0;
	for (int i = 1;i <= n;i++) diameter = max(diameter, dist[i]);
	if (diameter % 3 == 2) printf("Second\n");
	else printf("First\n");
    return 0;
}



Measured memory_bytes: 5760
#include <iostream>
using namespace std;
int main(void){
    
    int R, G, B, num;
    
    cin >> R >> G >> B;
    
    num = 10 * G + B;
    
    if (num % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
    
}

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

namespace ITP1_4_B
{
    public class Program

    {
        public static void Main(string[] args)
        {
            double line = ReadDouble();
            Console.WriteLine("{0} {1}", (line * line * Math.PI).ToString("F6"),(2 * line*Math.PI).ToString("F6"));
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }

}



Measured memory_bytes: 18020
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

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

	for (int i = 0; i <= N; i++)
	{
		if (int(i * 1.08) == N)
		{
			cout<<i<<endl;
			return 0;
		}
	}

	cout<<":("<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 400010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x;
    cin >> x;
    rep(a,1001){
        ll k = a*a*a*a*a;
        rep(b,a){
            ll l = b*b*b*b*b;
            if (k-l == x){
                PRINT(a << " " << b);
                return 0;
            }
            else if (k+l == x){
                PRINT(a << " " << -b);
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n, m, a, b;
  cin >> n >> m;
  a = m/n;
  for (int64_t i=a; i>=1; i--){
    if (m%i==0){
      cout << i;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3564
public class Main {
	public static void main(String[] args) {
		java.util.Scanner s = new java.util.Scanner(System.in);
		int[] p = new int[s.nextInt()];
		for(int i=0;i<p.length;i++) {
			p[i]=s.nextInt();
		}
		System.out.println(calc(p)?"YES":"NO");
	}
	public static boolean calc(int[] p) {
		int count = 0;
		for(int i=0;i<p.length;i++) {
			if(p[i] != i+1) {
				count++;
			}
		}
		if(count==0 || count==2) {
			return true;
		}else {
			return false;
		}
	}
}


Measured memory_bytes: 21844
N, T = map(int, input().split())
t = list(map(int, input().split()))
s = T
f = t[0] + T
for i in range(N-1):
  s += T
  if f > t[i+1]:
    s -= f - t[i+1]
  f = t[i+1] + T
print(s)


Measured memory_bytes: 26836
#include<stdio.h>

//配列の出力
void Outsort(int A[],int N){
  int i;
  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}

//挿入ソート
void insertionSort(int A[],int N){
  int i, j, v;
  for(i=0;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j] > v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    Outsort(A,N);
  }
}

int main(){
  int N, i, j;
  int A[1000];

  scanf("%d",&N);
  if(N>100||N<1)return 0;
  for(i=0;i<N;i++) scanf("%d",&A[i]);


  insertionSort(A,N);
  
  return 0;
}





Measured memory_bytes: 2700