akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        SyntheticKadomatsu solver = new SyntheticKadomatsu();
        solver.solve(1, in, out);
        out.close();
    }

    static class SyntheticKadomatsu {
        List<Integer> l;
        int n;
        int a;
        int b;
        int c;
        int result = Integer.MAX_VALUE;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            n = in.nextInt();
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            l = new ArrayList<>();

            for (int i = 0; i < n; i++) {
                l.add(in.nextInt());
            }

            recursive(0, 0, 0, 0, 0);
            out.println(result);
        }

        public void recursive(int score, int num, int aa, int bb, int cc) {
            if (num == n) {
                if (aa == 0 || bb == 0 || cc == 0) {
                    return;
                }
                score += Math.abs(a - aa) + Math.abs(b - bb) + Math.abs(c - cc);
                result = Math.min(score, result);
                return;
            }
            recursive(aa == 0 ? score : score + 10, num + 1, aa + l.get(num), bb, cc);
            recursive(bb == 0 ? score : score + 10, num + 1, aa, bb + l.get(num), cc);
            recursive(cc == 0 ? score : score + 10, num + 1, aa, bb, cc + l.get(num));
            recursive(score, num + 1, aa, bb, cc);

        }

    }
}



Measured memory_bytes: 39184
#include<iostream>
#include <math.h> 
using namespace std;

const double PI =3.141592653589793238462643383;

int main()
{
	double A,B,C,D;
	cin >>A>>B>>C>>D;
	C = C/12*2+(D/60)/6;
	D = D/60*2;
	C = C-D;
	
	A = sqrt(A*A+B*B-2*A*B*cos(C*M_PI)) ;
	cout.precision(20);
	cout <<fixed<<A;
    return 0;

}

Measured memory_bytes: 4212
import numpy as np

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

ans = 1
count = np.zeros(N + 1, dtype="int")
count[0] = 3

for i in A:
    ans *= max(0, count[i] - count[i + 1])
    ans %= 1000000007
    count[i + 1] += 1

print(ans)

Measured memory_bytes: 23372
#include <iostream>
#include <vector>
using namespace std;
vector<int> before(28);
vector<int> after(28);
int main(){
	int n, x, cnt, cnt_max;
	string s;
	cin >> n >> s;
	cnt_max = 0;
	for(int i=1; i<n-1; i++){
		cnt = 0;
		for(int j=0; j<28; j++){
			before[j] = 0;
			after[j] = 0;
		}
		for(int j=0; j<i; j++){
			x = s[j] - 'a';
			before[x]++;
		}
		for(int j=i; j<n; j++){
			x = s[j] - 'a';
			after[x]++;
		}
		for(int i=0; i<28; i++){
			if(before[i] > 0 && after[i] > 0){
				cnt++;
			}
		}
		cnt_max = max(cnt_max, cnt);
	}
	cout << cnt_max << endl;
	return 0;
}


Measured memory_bytes: 256
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;

//(int)'a'は97 (int)'A'は65
//おまじない



int main() {
	
	int x, a, b;
	cin >> x >> a >> b;

	cout << min(min(a + b, x + b), a + x);





	return 0;
}


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

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

	if(n==1) {
		printf("Hello World\n");
	}
	else if(n==2) {
		long a, b;
		scanf("%ld", &a);
		scanf("%ld", &b);
		printf("%d\n", a+b);
	} 
    return 0;
}

Measured memory_bytes: 128
n,w=map(int,input().split())
a,b=[0]*n,[0]*n
for i in range(n):a[i],b[i]=map(int,input().split())
dp=[[0]*(w+1) for i in range(n+1)]
for i in range(1,n+1):
	for j in range(1,w+1):
		if j<a[i-1]:dp[i][j]=dp[i-1][j]
		else:dp[i][j]=max(dp[i-1][j],b[i-1]+dp[i-1][j-a[i-1]])
print(dp[-1][-1])

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;	
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

const ll INF = 1LL << 61;

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

const ll mod = 1000000007;


int main() {
	ll k, a, b;
	cin >> k >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	return 0;
}


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

int main(void) {
    int N,X,Y; cin >> N >> X >> Y;
    int A[N+10] = {0};
    for(int i=1; i<=N-1; i++) {
        for(int j=i+1; j<=N; j++) {
          int mm = min({abs(j-i),abs(X-i)+1+abs(j-Y),abs(Y-i)+1+abs(j-X)});
          A[mm]++;
        }
    }
    for(int i=1; i<=N-1; i++) cout << A[i] << endl;
    return 0;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  static const int MAX_LEN = 1e6 + 5;
  static char s[MAX_LEN];
  static int equal[MAX_LEN], bigger[MAX_LEN];

  cin >> s;
  int n = strlen(s);
  reverse(s, s + n);
  bigger[n] = 1;

  for (int i = n - 1; ~i; --i) {
    int x = s[i] - '0';
    equal[i] = min(equal[i + 1] + x, bigger[i + 1] + 10 - x);
    bigger[i] = (x == 9)
                    ? bigger[i + 1]
                    : (min(equal[i + 1] + x + 1, bigger[i + 1] + 10 - (x + 1)));
  }

  cout << equal[0] << '\n';
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll N; cin >> N;
  ll A[N]; rep(i,N) cin >> A[i];

  ll sum = 0; rep(i,N) sum = (sum+A[i]) % MOD;
  ll result = sum * sum % MOD;
  rep(i,N) result = (result-A[i]*A[i]%MOD+MOD) % MOD;
  result = result * inv(2) % MOD;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 5200
/*
#include<rabbit>;
using blueHulkStress;
using AceOfSpades;
*/
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = (1e-9);
typedef long long ll;
typedef unsigned long long ull;
#define flush fflush(stdout), cout.flush()
#define all(v) ((v).begin()),((v).end())
#define rall(v) ((v).rbegin()),((v).rend())
#define clr(v,line) memset(v,line,sizeof(v))
#define rep(i,n) for(int(i)=0;(i)<(int)(n);(i)++)
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define lcm(a,b) (a*(b/__gcd(a,b)))
#define P 1000000007
#define endl '\n'
const int dx[] = {1,-1,0,0,1,-1,1,-1};
const int dy[] = {0,0,1,-1,1,-1,-1,1};
const int dxhorse[] = {-2,-2,-1,-1,1,1,2,2};
const int dyhorse[] = {1,-1,2,-2,2,-2,1,-1};

int main(int argc, char const *argv[])
{
	
	int n, k;cin>>n>>k;
	vi v(k);
	rep(i,k)cin>>v[i];

	while(1)
	{
		bool f = 0;
		for(auto i:to_string(n))
		{
			f|=count(all(v),i-'0');
		}
		if(!f)return cout<<n,0;
		n++;
	}
}

Measured memory_bytes: 384
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define PB push_back
#define MP make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<29)
#define LLINF (1LL<<60)
#define MOD 1000000007
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
typedef pair<int, int> P;

int main() {
    string s;
    int distL[100000] = {}, distR[100000] = {}, ans[100000] = {},  l = -1, r;
    bool check[100000] = {};
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'L') {
            for (int j = l + 1; j <= i; j++) {
                distL[j] = i - j;
            }
            l = i;
        }
    }
    r = s.length();
    for (int i = s.length() - 1; i >= 0; i--) {
        if (s[i] == 'R') {
            for (int j = r - 1; j >= i; j--) {
                distR[j] = j - i;
            }
            r = i;
        }
    }
    
    for (int i = 0; i < s.length(); i++) {
        if (i == 0 || distL[i]!=0 || (distL[i]==0 && distL[i-1]!=0)) {
            if (distL[i] % 2 == 0)ans[i + distL[i]]++;
            else ans[i + distL[i] - 1]++;
            check[i] = true;
        }
    }
    for (int i = s.length() - 1; i >= 0; i--) {
        if (!check[i]) {
            if (distR[i] % 2 == 0)ans[i - distR[i]]++;
            else ans[i - distR[i] + 1]++;
            check[i] = true;
        }
    }
    for (int i = 0; i < s.length(); i++) {
        cout << ans[i] << ' ';
    }
    return 0;
}


Measured memory_bytes: 1920
def main():
    h, w = [int(x) for x in input().split()]
    matrix = [list(input()) for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if matrix[i][j] == '.':
                continue
            # Above
            if i > 0:
                if matrix[i - 1][j] == '#':
                    continue
            # Left
            if j > 0:
                if matrix[i][j - 1] == '#':
                    continue
            # Right
            if j < w - 1:
                if matrix[i][j + 1] == '#':
                    continue
            # Below:
            if i < h - 1:
                if matrix[i + 1][j] == '#':
                    continue

            # The cell is black and no adjacent black cell.
            return 'No'

    return 'Yes'


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3064
a,b,c = gets.split.map(&:to_i).sort

ans = 0

at = (c-a)/2
ans += at
a += at*2

bt = (c-b)/2
ans += bt
b += bt*2

a,b,c = [a,b,c].sort

if a==b && b==c
  p ans
elsif a+1==b && b==c
  p ans+2
elsif a==b && b+1==c
  p ans+1
end

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

using namespace std;

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

const int INF = 1000000000; //
const ll LINF = (ll) 4000000000000000000; //
const ll MOD = (ll) 1000000007; //
const double PI = 3.1415926535898; //

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())

//------------------------------------------------------

int main() {
    int n, c, k;
    cin >> n >> c >> k;
    int t[n];
    rep(i, n) cin >> t[i];

    sort(t, t + n);
    int ans = 0;
    int i = 0;
    while (i < n) {
        int bus_cnt = 0;
        int top = i;
        while (bus_cnt < c && t[i] <= t[top] + k) {
            i++;
            bus_cnt++;
        }
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
import math
def Minkowski(r, n, x, y):
    sum_dif = 0
    for i in range(n):
        dif = abs(x[i] - y[i])
        sum_dif += dif ** r
    print(sum_dif ** (1 / r))

def Chebyshev(n, x, y):
    max_dif = 0
    for i in range(n):
        dif = abs(x[i] - y[i])
        max_dif = max(dif, max_dif)
    print(max_dif)

n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))
Minkowski(1, n, x, y)
Minkowski(2, n, x, y)
Minkowski(3, n, x, y)
Chebyshev(n, x, y)



Measured memory_bytes: 5720
#include<bits/stdc++.h>
// #define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
#define ODD 1
#define EVEN 0

signed main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    bool bocchi = false;
    /* i means row, j means col */
    rep(i, h){
        rep(j, w){
            if(i == 0 || i == h-1 || j == 0 || j == w-1) continue;
            if(s[i][j] =='#' && s[i-1][j] == '.' && s[i][j+1] == '.' && s[i+1][j] == '.' && s[i][j-1] == '.') bocchi = true;
        }
    }
    if(!bocchi) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <bitset>
#include <map>
#include <vector>
#include <string>
#include <climits>
#include <algorithm>
#include <string>
using namespace std;

int main() {
    
    int N, K;
    cin >> N >> K;
    vector<int> M(N+1,0);
    
    for(int i = 0; i < K; i++){
        int d;
        cin >> d;
        for(int j = 0; j < d; j++){
            int A;
            cin >> A;
            M[A]++;
        }
    }
    
    int ans = 0;
    for(int i = 1; i <= N; i++){
        if(M[i] == 0) ans++;
    }
    
    cout << ans << endl;
    
    
    return 0;
    
}



Measured memory_bytes: 3192
n, k = map(int,input().split())
a = list(map(int,input().split()))
li = [[] for i in range(n)]
step = 0
li[0].append(step)
pos = 1
noLoop = True

while k > 0:
    pos = a[pos - 1]
    k -= 1
    if noLoop:
        step += 1
        li[pos - 1].append(step)
        if len(li[pos - 1]) == 2:
            loop = li[pos - 1][1] - li[pos - 1][0]
            k %= loop
            noLoop = False
print(pos)

Measured memory_bytes: 41296
#include <iostream>
using namespace std;
char c;
int main()
{
    cin>>c;
    if(c=='A')
        cout<<'T';
    else
        if(c=='T')
            cout<<'A';
        else
            if(c=='C')
                cout<<'G';
            else
                cout<<'C';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  ll A,B,K;
  cin>>A>>B>>K;
  
  if(A<K){
    ll ansb=B-K+A;
    if(B-K+A<0)
      ansb=0;
    cout<<0<<" "<<ansb<<endl;
    return 0;
  }
  else{
    ll ansa=A-K;
    if(ansa<0)
      ansa=0;
    cout<<ansa<<" "<<B<<endl;
    return 0;
  }
    
}


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

int main()
{
	char s[100];
	while (cin>>s)
	{
		int len = strlen(s)-8;
		for (int i = 0; i < len; i++)
			putchar(s[i]);
		cout << endl;

	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
ans = 0
cnt = 0
for i in range(1, n):
    if h[i - 1] >= h[i]:
        cnt += 1
    else:
        ans = max(ans, cnt)
        cnt = 0
ans = max(ans, cnt)
print(ans)

Measured memory_bytes: 14252
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


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


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
using namespace std;
#define ll long long
#define MAX 200200
#define MOD 1000000007
void add(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
const int py=2010;
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int a[MAX],b[MAX],n,ans;
int f[4500][4500];
int inv[9000],jc[9000],jv[9000];
int C(int n,int m){return 1ll*jc[n]*jv[m]%MOD*jv[n-m]%MOD;}
int main()
{
	n=read();
	for(int i=1;i<=n;++i)a[i]=read(),b[i]=read();
	for(int i=1;i<=n;++i)f[py-a[i]][py-b[i]]+=1;
	for(int i=1;i<=py*2;++i)
		for(int j=1;j<=py*2;++j)
			add(f[i][j],f[i-1][j]),add(f[i][j],f[i][j-1]);
	inv[0]=inv[1]=jc[0]=jv[0]=1;
	for(int i=1;i<py<<2;++i)jc[i]=1ll*jc[i-1]*i%MOD;
	for(int i=2;i<py<<2;++i)inv[i]=1ll*inv[MOD%i]*(MOD-MOD/i)%MOD;
	for(int i=1;i<py<<2;++i)jv[i]=1ll*jv[i-1]*inv[i]%MOD;
	for(int i=1;i<=n;++i)add(ans,f[a[i]+py][b[i]+py]);
	for(int i=1;i<=n;++i)add(ans,MOD-C(2*(a[i]+b[i]),2*a[i]));
	ans=1ll*ans*inv[2]%MOD;printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 74880
class node:
    def __init__(self, parent, left, right):
        self.p = parent
        self.l = left
        self.r = right

def preParse(u):
    if u == -1:
        return
    print(" " + str(u), end = '')
    preParse(T[u].l)
    preParse(T[u].r)

def inParse(u):
    if u == -1:
        return
    inParse(T[u].l)
    print(" " + str(u), end = '')
    inParse(T[u].r)

def postParse(u):
    if u == -1:
        return
    postParse(T[u].l)
    postParse(T[u].r)
    print(" " + str(u), end = '')

n = int(input())
T = [node(-1, -1, -1) for _ in range(n)]
for _ in range(n):
    info = list(map(int, input().split(" ")))
    T[info[0]].l = info[1]
    T[info[0]].r = info[2]
    if info[1] != -1:
        T[info[1]].p = info[0]
    if info[2] != -1:
        T[info[2]].p = info[0]

print("Preorder")
for i in range(n):
    if T[i].p == -1:
        preParse(i)

print("\n" + "Inorder")
for i in range(n):
    if T[i].p == -1:
        inParse(i)

print("\n" + "Postorder")
for i in range(n):
    if T[i].p == -1:
        postParse(i)

print("")


Measured memory_bytes: 5620
import itertools
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
seq = [A,B,C,D,E]
L = list(itertools.permutations(seq))
ans = float('inf')
for i in range(len(L)):
  sub = 0
  for j in range(4):
    if L[i][j]%10 != 0:
      sub += L[i][j]-(L[i][j]%10)+10
    else:
      sub += L[i][j]
  sub += L[i][4]
  if sub <= ans:
    ans = sub
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    
    int ans = 0;
    while(x > 0 && y > 0){
        if(a+b >= 2*c){
            ans += 2*c;
        }else{
            ans += a+b;
        }
        x--; y--;
    }
    while(x > 0){
        ans += (a >= 2*c ? 2*c : a);
        x--;
    }
    while(y > 0){
        ans += (b >= 2*c ? 2*c : b);
        y--;
    }

    cout << ans << "\n";

    return 0;
}

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

int main() {
    int A,B;
    cin >> A >> B;
    int res=INT32_MAX;
    for(int i=1;i<1100;i++){
        if((int)(i*0.08)==A && (int)(i*0.1)==B){
            res=min(i,res);
        }
    }
    if(res==INT32_MAX)cout<<-1;
    else cout<<res;
    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
    using namespace std;
    typedef int sign;
    typedef long long ll;
    #define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
    #define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
    const int N=2e3+5;
    template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
    template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
    template<typename T>T read()
    {
    	T ans=0,f=1;
    	char ch=getchar();
    	while(!isdigit(ch)&&ch!='-')ch=getchar();
    	if(ch=='-')f=-1,ch=getchar();
    	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
    	return ans*f;
    }
    template<typename T>void write(T x,char y)
    {
    	if(x==0)
    	{
    		putchar('0'),putchar(y);
    		return;
    	}
    	if(x<0)
    	{
    		putchar('-');
    		x=-x;
    	}
    	static char wr[20];
    	int top=0;
    	for(;x;x/=10)wr[++top]=x%10+'0';
    	while(top)putchar(wr[top--]);
    	putchar(y);
    }
    void file()
    {
    #ifndef ONLINE_JUDGE
    	freopen("in","r",stdin);
    	freopen("out","w",stdout);
    #endif
    }
    const int mo=998244353;
    int k,n,ans;
    void input()
    {
    	k=read<int>(),n=read<int>();
    }
    int pw[N],C[N<<1][N<<1];
    void init()
    {
    	pw[0]=1;
    	For(i,1,n)pw[i]=(pw[i-1]<<1)%mo;
    	C[0][0]=1;
    	For(i,1,4000)
    	{
    		C[i][0]=1;
    		For(j,1,i)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mo;
    	}
    }
    int Comb(int x,int y)
    {
    	return C[x+y-1][x];
    }
    int cal(int num1,int num2,int tot)
    {
    	int res=0;
    	For(i,0,min(num1,tot))res=(res+1ll*pw[i]*Comb(tot-i,num2+i)%mo*C[num1][i]%mo)%mo;
    	return res;
    }
    void work()
    {
    	int num1,num2;
    	For(now,2,k*2)
    	{
    		if(now<=k+1)
    		{
    			num2=k-now+1;
    			num1=(now-1)/2;
    		}
    		else
    		{
    			num2=now-k-1;
    			num1=(k*2-now+1)/2;
    		}
    	//	cout<<now<<' '<<num1<<' '<<num2<<endl;
    		ans=cal(num1,num2,n);
    		if(now%2==0)ans=(ans+cal(num1,num2,n-1))%mo;
    		write(ans,'\n');
    	}
    }
    int main()
    {
     
    	input();
    	init();
    	work();
    	return 0;
    }

Measured memory_bytes: 61440
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
struct pos { int x, y, z; };
vector<int> x, y, z;
vector<pair<pos, pos>> fish;
int num[100][100][100];
int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		pos a,b;
		cin >> a.x >> a.y >> a.z >> b.x >> b.y >> b.z;
		fish.push_back(make_pair(a, b));
		for (int i = 0; i < 1; i++) {
			x.push_back(a.x+i);
			y.push_back(a.y+i);
			z.push_back(a.z+i);
			x.push_back(b.x+i);
			y.push_back(b.y+i);
			z.push_back(b.z+i);
		}
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	sort(z.begin(), z.end());
	x.erase(unique(x.begin(), x.end()), x.end());
	y.erase(unique(y.begin(), y.end()), y.end());
	z.erase(unique(z.begin(), z.end()), z.end());
	for (auto f : fish) {
		int up = lower_bound(x.begin(), x.end(), f.second.x) - x.begin();
		for (int i = lower_bound(x.begin(), x.end(), f.first.x) - x.begin(); i < up; i++) {
			int up = lower_bound(y.begin(), y.end(), f.second.y) - y.begin();
			for (int j = lower_bound(y.begin(), y.end(), f.first.y) - y.begin(); j < up; j++) {
				int up = lower_bound(z.begin(), z.end(), f.second.z) - z.begin();
				for (int k = lower_bound(z.begin(), z.end(), f.first.z) - z.begin(); k < up; k++) {
					num[i][j][k]++;
				}
			}
		}
	}
	ll ans = 0;
	for (int i = 0; i < x.size()-1; i++) {
		for (int j = 0; j < y.size()-1; j++) {
			for (int l = 0; l < z.size()-1; l++) {
				if (num[i][j][l] >= k) {
					ans += (ll)(x[i + 1] - x[i])*(y[j + 1] - y[j])*(z[l + 1] - z[l]);
				}
			}
		}
	}
	cout << ans << endl;
}

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



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

    cin >> s;
   
    int sum=0;
    for(int i=0;i<n-2;i++){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
  $len = intval(fgets(STDIN));
  $str = trim(fgets(STDIN));

  if($len%2==1){
    echo "No\n";
  }else{
    $str1 = substr($str, 0, $len/2);
    $str2 = substr($str, $len/2);
    
    if(strcmp($str1,$str2)==0){
      echo "Yes\n";
    }else{
      echo "No\n";
    }
  }

Measured memory_bytes: 4732
#include <bits/stdc++.h>
#define ch(x,y) strstr(x,y)
using namespace std;
int main(void)
{
	int a,t=1;
	int n=5,e=3,w=4,s=2,o=1,u=6;
	char b[10];
	cin >> a;
	while(a != 0){
		for(int i = 0;i < a;i++){
			cin >> b;
			if(ch(b,"North") != NULL){
				swap(n,o);
				swap(o,s);
				swap(s,u);
			}
			if(ch(b,"East") != NULL){
				swap(e,o);
				swap(o,w);
				swap(w,u);
			}
			if(ch(b,"West") != NULL){
				swap(w,o);
				swap(o,e);
				swap(e,u);
			}
			if(ch(b,"South") != NULL){
				swap(s,o);
				swap(o,n);
				swap(n,u);
			}
			if(ch(b,"Right") != NULL){
				swap(n,w);
				swap(w,s);
				swap(s,e);
			}
			if(ch(b,"Left") != NULL){
				swap(n,e);
				swap(e,s);
				swap(s,w);
			}
			t += o;
		}
		cout << t << endl;
		n=5;
		e=3;
		w=4;
		s=2;
		o=1;
		u=6;
		t = 1;
		cin >> a;
	}
	
	return 0;
}

Measured memory_bytes: 3004
#include <iostream>
#include <string>
#define llint long long

using namespace std;

llint n;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	if(n%2){
		cout << 0 << endl;
		return 0;
	}
	n /= 2;
	
	llint mul = 5, ans = 0;
	while(1){
		ans += n / mul;
		mul *= 5;
		if(mul > 1e18) break;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n]={};
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=n-1; i>=0; i--) {
    if(a[i-1]>a[i]) {
      a[i-1]--;
    }
    if(a[i-1]>a[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int n;cin>>n;
    int b[n-1];rep(i,n-1)cin>>b[i];
    int a[n];
    a[0]=b[0];a[n-1]=b[n-2];
    rep1(i,n-2){
        a[i]=min(b[i],b[i-1]);
    }
    int ans=0;
    rep(i,n){
        ans+=a[i];
    }
    co(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

int main() {
	int n; ll a, b; cin >> n >> a >> b;
	ll x[100003];
	for (int i = 0; i < n; ++i) cin >> x[i];
	ll ans = 0;
	for (int i = 1; i < n; ++i) {
		if ((x[i] - x[i - 1])*a < b) ans += (x[i] - x[i - 1])*a;
		else ans += b;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import bisect
#D2
n = int(input())
a = [int(input()) for j in range(n)]

dp = [a[0]]
for i in range(1,n):
    if dp[-1] < a[i]:
        dp.append(a[i])
        #print(0,dp)

    else:
        dp[bisect.bisect_left(dp, a[i])] = a[i]
        #print(1,bisect.bisect_left(dp, a[i]),dp)
print(len(dp))

Measured memory_bytes: 12472
from fractions import gcd

def lcm(x, y):
    return x * y // gcd(x, y)

a, b, c, d = map(int, input().split())
count = (b - a + 1) - (b // c - (a - 1) // c) - (b // d - (a - 1) // d) + (b // lcm(c, d) - (a - 1) // lcm(c, d))
print(count)

Measured memory_bytes: 5048
def main():
    N=int(input())
    A=[int(_) for _ in input().split()]
    left=0
    right=sum(A)
    ans=right
    for i in range(N):
        left+=A[i]
        right-=A[i]
        ans = min(ans, abs(left-right))
    print(ans)

main()

Measured memory_bytes: 26764
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int a = 0;
    int b = 0;
    int c = 0;
    int ans = 0;
    for (int i = 0; i < N; i++) {
      char[] s = scanner.next().toCharArray();
      if (s[0] == 'B' && s[s.length - 1] != 'A') b++;
      if (s[0] != 'B' && s[s.length - 1] == 'A') a++;
      if (s[0] == 'B' && s[s.length - 1] == 'A') c++;
      for (int j = 0; j < s.length - 1; j++) {
        if (s[j] == 'A' && s[j + 1] == 'B') ans++;
      }
    }
    if (c > 1) ans += c - 1;
    if (c > 0) {
      if (a > 0 && b > 0) {
        ans += 2;
        a--;
        b--;
      } else if (a > 0) {
        ans += 1;
        a--;
      } else if (b > 0) {
        ans += 1;
        b--;
      }
    }
    ans += Math.min(a, b);

    System.out.println(ans);
  }
}


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


ans = set()
for i in range(n-1, -1, -1):
  for j in range(i+1,n+1,i+1):
    if j in ans:
      a[i] += 1
  if a[i]%2 == 1:
    ans.add(i+1)
print (len(ans))
print (*ans)

Measured memory_bytes: 19632
// AtCoderIsFucking.cpp

#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <algorithm>

using namespace std;


string weather[] = { "Sunny", "Cloudy", "Rainy" };
string S;

int main()
{
	cin >> S;

	int m = S == weather[0] ? 0 : (S == weather[1] ? 1 : 2);

	int n = (m + 1) % 3;

    cout << weather[n];
}



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


struct Node{
  int key;
  struct Node *r,*l,*p;
};

 struct Node *B,*NIL;

void insert(int k){
   struct Node *y = NIL;
   struct Node *x = B;
   struct Node *z;

   z = (struct Node *)malloc(sizeof(struct Node));
   z->key = k;
   z->l = NIL;
   z->r = NIL;

   while(x!=NIL){
     y = x;
     
     if(z->key < x->key){
       x = x->l;
     }
     else x = x->r;
   }
   
   z->p = y;
   if(y == NIL ){
     B=z;
   }
   else if(z->key < y->key){
       y->l = z;
     }
   else y->r = z;
}




void inorder(struct Node *u){
  if(u==NIL) return;
  inorder(u->l);
  printf(" %d",u->key);
  inorder(u->r);
}

void preorder(struct Node *u){
  if(u == NIL )return;
  printf(" %d",u->key);
  preorder(u->l);
  preorder(u->r);
}

int main(){
  
  int i,x,y;
  char G[8];
  scanf("%d",&x);
  
  for(i=0;i<x;i++){
    scanf("%s",&G);
    
    if(G[0] == 'i'){
      scanf("%d",&y);
      insert(y);
    }
    
    else if(G[0] == 'p'){
      inorder(B);
      printf("\n");
      preorder(B);
      printf("\n");
    }
  }
  return 0;
}

  



Measured memory_bytes: 25140
import sys
def main():
    input = sys.stdin.readline
    N,M=map(int, input().split())
    AB=[tuple(map(lambda x:int(x)-1, input().split())) for _ in range(M)]

    uf = UnionFindTree(N)
    mx = N*(N-1)//2
    ans = [mx]*M
    for i in range(M-1,0,-1):
        a,b = AB[i]
        ans[i-1] = ans[i] - (0 if uf.same(a, b) else uf.size(a)*uf.size(b))
        uf.union(a, b)

    for a in ans: print(a)

class UnionFindTree:
    def __init__(self, n):
        self.parent = [-1] * n

    def find(self, x):
        p = self.parent
        while p[x] >= 0: x, p[x] = p[x], p[p[x]]
        return x

    def union(self, x, y):
        x, y, p = self.find(x), self.find(y), self.parent
        if x == y: return
        if p[x] > p[y]: x, y = y, x
        p[x], p[y] = p[x] + p[y], x

    def same(self, x, y): return self.find(x) == self.find(y)
    def size(self, x): return -self.parent[self.find(x)]


if __name__ == '__main__':
    main()

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

int main() {
	int n;
    cin >> n;
    vector<int> data(n);
    for (int i = 0; i < n; i++){
        cin >> data.at(i);
    }

    int pos = 0, allcost = 0;
    for (int i = 0; i < n; i++){
        allcost += abs(pos - data.at(i));
        pos = data.at(i);
    }
    allcost += abs(pos);

    for (int i = 0; i < n; i++){
        int cost = allcost;
        if (i == 0){
            cost -= abs(data.at(0));
            cost -= abs(data.at(0) - data.at(1));
            cost += abs(data.at(1));
        }
        else if(i == n - 1){
            cost -= abs(data.at(n - 2) - data.at(n - 1));
            cost -= abs(data.at(n - 1));
            cost += abs(data.at(n - 2));
        }
        else{
            cost -= abs(data.at(i - 1) - data.at(i));
            cost -= abs(data.at(i) - data.at(i + 1));
            cost += abs(data.at(i - 1) - data.at(i + 1));
        }

        cout << cost << endl;
    }


}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int a[7];
int b[7];
int main(){
	//int n;
	//cin>>n;
	int k=0;
	for(int i=1;i<=5;i++){
		cin>>a[i];
		if(a[i]%10==0)b[i]=0;
		else b[i]=10-a[i]%10;
	}
	int ma=0; 
	for(int i=1;i<=5;i++){
		ma=max(ma,b[i]);
	}
	for(int i=1;i<=5;i++){
		if(ma==b[i]){
			if(k==0){
				k=a[i];
				a[i]=a[i+1];
				continue;
			}
		}
		if(k!=0){
			a[i]=a[i+1];
		}
	}
	int ans=0;
	for(int i=1;i<=4;i++){
		if(a[i]%10==0)ans+=a[i];
		else ans=ans+a[i]+10-a[i]%10;
	}
	cout<<ans+k; 
	return 0; 
}

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

using namespace std;

int E[40][20];
int F[40][20];

int dp[10][60][40];

int C, D, W, X;

void init() {
  fill((int*)dp, (int*)dp + sizeof(dp) / sizeof(int), -1);
}

void solve() {
  dp[X][W][0] = 0;
  for (int d = 1; d <= D; d++) {
	for (int w = 0; w <= W; w++) {
	  for (int x = 0; x <= X; x++) {
		int mx = (dp[x][w][d - 1] >= 0) ? dp[x][w][d - 1] : -1;
		
		for (int i = 0; i < C; i++) {
		  if (w + F[d][i] > W) {
			continue;
		  }
		  if (dp[x][w + F[d][i]][d - 1] >= 0) {
			mx = max(mx, dp[x][w + F[d][i]][d - 1] + E[d][i]);
		  }
		}

		for (int i = 0; i < C; i++) {
		  for (int j = i; j < C; j++) {
			int f = 0, e = 0;
			for (int k = i; k <= j; k++) {
			  if (E[d][k] == 0) {goto next;}
			  f += F[d][k];
			  e += E[d][k];
			  if (w + f > W) {
				goto next;
			  }
			}
			if (dp[x + 1][w + f][d - 1] >= 0) {
			  mx = max(mx, dp[x + 1][w + f][d - 1] + e);
			}
		  next:;
		  }
		}
		dp[x][w][d] = mx;
	  }
	}
  }

  int mx = 0;
  for (int i = 0; i <= W; i++) {
	for (int j = 0; j <= X; j++) {
	  mx = max(dp[j][i][D], mx);
	}
  }
  cout << mx << endl;
}

int main() {
  while (cin >> C >> D >> W >> X) {
	if (C == 0 && D == 0 && W == 0 && X == 0) {
	  break;
	}

	init();
	
	for (int i = 0; i < C; i++) {
	  for (int j = 1; j <= D; j++) {
		cin >> E[j][i];
	  }
	}
	for (int i = 0; i < C; i++) {
	  for (int j = 1; j <= D; j++) {
		cin >> F[j][i];
	  }
	}
	solve();
  }
}

Measured memory_bytes: 964
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
> ;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    string u,l;
    cin>>u>>l;
    reverse(u.begin(),u.end());
    out((u==l?"YES":"NO"));
    
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] L = new int[N];
		for (int i = 0; i < N; i++) {
			L[i] = sc.nextInt();
		}
		long ans = 0;
		for (int i = 0; i < N - 2; i++) {
			for (int j = i + 1; j < N - 1; j++) {
				for (int k = j + 1; k < N; k++) {
					if (L[i] != L[j] && L[j] != L[k] && L[k] != L[i]) {
						if (isTriangle(L[i], L[j], L[k])) {
							ans++;
						}
					}
				}
			}
		}
		System.out.println(ans);
	}

	public static boolean isTriangle(int x, int y, int z) {
		return (x + y > z) && (x + z > y) && (y + z > x);
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

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

	map<int,int> m;
	for (int i=0;i<n;++i)
	{
		int j;
		cin >> j;
		m[j]=1;
	}

	if (m.count(x)==0)
	{
		cout << x << endl;
		return 0;
	}

	for (int i=1;;++i)
	{
		if (m.count(x-i)==0)
		{
			cout << x-i << endl;
			return 0;
		}
		if (m.count(x+i)==0)
		{
			cout << x+i << endl;
			return 0;
		}
	}
}







Measured memory_bytes: 3624
from collections import deque
h,w=map(int,input().split())
ttt=0
d=["#"]
c=[]
for i in range(h):
    ca=input()
    ttt+=ca.count("#")
    ca=list(ca)
    b=["#"]
    b.extend(ca)
    b.extend(d)
    c.append(b)
c.insert(0,['#']*(w+2))
c.append(['#']*(w+2))
# print(a,c)

kouho=deque([[1,1]])
kouho2=deque([])
ans=0
for _ in range(10**9):
    if kouho==deque([]):
        ans+=1
        if kouho2==deque([]):
            print(-1)
            exit()
        kouho=kouho2
        # print(kouho,ans)
        kouho2=deque([])
    a,b=kouho.popleft()
    # print(a,b)
    if a==h and b==w:
        print(h*w-ans-1-ttt)
        exit()
    if c[a][b]=='.':
        c[a][b]='#'
        kouho2.append([a,b-1])
        kouho2.append([a-1,b])
        kouho2.append([a+1,b])
        kouho2.append([a,b+1])

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    priority_queue<pair<long long, long long> > q;
    int n,m;
    cin>>n>>m;
    for(int i = 0;i<n;i++)
    {
        long long pom;
        cin>>pom;
        q.push(make_pair(pom,1LL));
    }
    for(int i = 0;i<m;i++)
    {
        long long pom,pom2;
        cin>>pom2>>pom;
        q.push(make_pair(pom,pom2));
    }
    long long suma=0;
    int ile=0;
    while(ile<n)
    {
        if(q.top().second>n-ile)
        {
            suma+=(n-ile)*q.top().first;
            ile=n;
        }else{
            suma+=q.top().first*q.top().second;
            ile+=q.top().second;
        }
        q.pop();
    }
    cout<<suma;
}


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

struct node{
	unsigned int key;
	struct node *next;
	struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
	NodePointer cur = nil->next;
	while (cur != nil) {
		if (cur->key == key) break;
		cur = cur->next;
	}
	return cur;
}

void init(){
	nil = (NodePointer)malloc(sizeof(struct node));
	nil->next = nil;
	nil->prev = nil;
}

void printList(){
	NodePointer cur = nil->next;
	int isf = 1;
	while (1){
		if (cur == nil) break;
		if (isf == 0)  printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
		isf = 0;
	}
	printf("\n");
}

void deleteNode(NodePointer t){
	if (t == nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	NodePointer t = nil->next;
	if (t == nil) return;
	deleteNode(t);
}

void deleteLast(){
	NodePointer t = nil->prev;
	if (t == nil) return;
	deleteNode(t);
}

void deleteKey(int key){
	NodePointer t = listSearch(key);
	if (t != nil) deleteNode(t);
}


void insert(int key){
	NodePointer x;
	x = (NodePointer)malloc(sizeof(struct node));
	x->key = key;
	x->prev = nil;
	x->next = nil->next;
	x->next->prev = x;
	nil->next = x;
}

int main(){
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for (i = 0; i < n; i++){
		scanf("%s%d", com, &key);
		if (com[0] == 'i') { insert(key); np++; size++; }
		else if (com[0] == 'd') {
			if (strlen(com) > 6){
				if (com[6] == 'F') deleteFirst();
				else if (com[6] == 'L') deleteLast();
			}
			else {
				deleteKey(key); nd++;
			}
			size--;
		}
	}

	printList();
	return 0;
}

Measured memory_bytes: 31788
#include <iostream>
#include <string>

int n;

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


unsigned long int N, M;
int main() {
    std::cin >> N >> M;

    if ((N >= 2) && (M >= 2)) {
        std::cout << (N - 2) * (M - 2) << std::endl;
    }
    else if ((N <2) && (M < 2)) {
        std::cout << 1 << std::endl;
    }else {
        std::cout << std::max(N, M) - 2 << std::endl;
    }
}

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

int n, a[2000];

bool solve(int i, int m)
{
    if (m == 0)
        return true;
    if (i >= n)
        return false;
    return solve(i + 1, m) || solve(i + 1, m - a[i]);
}
int main()
{
    int q, m;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        cin >> m;
        bool ans = solve(0, m);
        if (ans)
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
}


Measured memory_bytes: 3088
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vll l(n+1);
    l[0]=2LL;
    l[1]=1LL;
    for(int i=2;i<=n;i++){
        l[i]=l[i-1]+l[i-2];
    }
    cout << l[n] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,q[1000010];
char s[1000010],t[1000010];
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	scanf("%s",t+1);
	int ans=0;
	int l=1,r=0;
	for (int i=n,j=n;i;i--)
	{
		bool f=false;
		while (j && s[j]!=t[i])
		{
			j--;
			f=true;
		}
		if (!j)
		{
			puts("-1");
			return 0;
		}
		if (i==j)
		{
			j--;
			l=1;
			r=0;
			continue;
		}
		if (!f)
		{
			continue;
		}
		while (l<=r && q[l]-r+l>i)
		{
			l++;
		}
		q[++r]=j;
		ans=max(ans,r-l+1);
	}
	cout<<ans<<endl;
	return 0;
}
//蓝桥春雪君归日，秦岭秋风我去时。
//每到驿亭先下马，循墙绕柱觅君诗。
//——白居易《蓝桥驿见元九诗》

Measured memory_bytes: 6144
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static boolean is_same(int fst_top, int fst_front, int fst_left, int fst_right, int fst_back, int fst_bottom,
			int snd_top, int snd_front, int snd_left, int snd_right, int snd_back, int snd_bottom){
		
		for (int v = 0; v < 4; v++) {
			for (int t = 0; t < 4; t++) {
				for(int k = 0; k < 4; k++){
				
					if(fst_top == snd_top && fst_front == snd_front && fst_left == snd_left && 
							fst_right == snd_right && fst_back == snd_back && fst_bottom == snd_bottom){
						return true;
					}
					
					int tmp = fst_front;
					fst_front = fst_left;
					fst_left = fst_back;
					fst_back = fst_right;
					fst_right = tmp;
				}
				
				int tmp = fst_bottom;
				fst_bottom = fst_right;
				fst_right = fst_top;
				fst_top = fst_left;
				fst_left = tmp;
			}

			int tmp = fst_bottom;
			fst_bottom = fst_front;
			fst_front = fst_top;
			fst_top = fst_back;
			fst_back = tmp;
		}
		
		return false;
	}
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		
		int[][] arr = new int[n][6];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < 6; j++){
				arr[i][j] = sc.nextInt();
			}
		}
		
		boolean any_same = false;
		for(int i = 0; i < n; i++){
			for(int j = i + 1; j < n; j++){
				any_same |= is_same(arr[i][0], arr[i][1], arr[i][2], arr[i][3], arr[i][4], arr[i][5],
						arr[j][0], arr[j][1], arr[j][2], arr[j][3], arr[j][4], arr[j][5]);
			}
		}

		System.out.println(any_same ? "No" : "Yes");
	}
}

Measured memory_bytes: 20788
a=input().split(" ")
k=int(a[0])
n=int(a[1])
b=input().split(" ")
num=[]
for i in range(n):
    num.append(int(b[i]))

num=sorted(num)
dis_list=[]
for i in range(n):
    if i==0:
        dis=num[0]+k-num[n-1]
    else:
        dis=num[i]-num[i-1]
    dis_list.append(dis)
dis_list=sorted(dis_list)
print(k-dis_list[n-1])

Measured memory_bytes: 28080
import java.util.Arrays;
import java.util.Scanner;
import static java.lang.Math.*;
public class Main {
	static boolean check(String a,String b) {
		if(a.length() != b.length())return false;
		for(int i = 0;i < a.length();i ++) {
			if(a.charAt(i) == b.charAt(0) && (a.substring(i, a.length()) + a.substring(0, i)).equals(b)) {
				return true;
			}
		}
		return false;
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String a = in.nextLine();
		String b = in.nextLine();
		System.out.println(check(a,b) ? "Yes" : "No");
	}
}


Measured memory_bytes: 23892