akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  string S;
  cin >> S;

  int A = (int)S.at(0) - '0', B = (int)S.at(1) - '0', C = (int)S.at(2) - '0', D = (int)S.at(3) - '0';

  if (A + B + C + D == 7) cout << A << '+' << B << '+' << C << '+' << D << "=7" << "\n";
  else if (A + B + C - D == 7) cout << A << '+' << B << '+' << C << '-' << D << "=7" << "\n";
  else if (A + B - C + D == 7) cout << A << '+' << B << '-' << C << '+' << D << "=7" << "\n";
  else if (A - B + C + D == 7) cout << A << '-' << B << '+' << C << '+' << D << "=7" << "\n";
  else if (A + B - C - D == 7) cout << A << '+' << B << '-' << C << '-' << D << "=7" << "\n";
  else if (A - B - C + D == 7) cout << A << '-' << B << '-' << C << '+' << D << "=7" << "\n";
  else if (A - B + C - D == 7) cout << A << '-' << B << '+' << C << '-' << D << "=7" << "\n";
  else cout << A << '-' << B << '-' << C << '-' << D << "=7" << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tlll tuple<ll, ll, ll>

int main() {
    double eps = 1e-6;
    int n;
    double x[55], y[55];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];

    double ans = 1e10;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                double px, py;
                py = ((x[k] - x[i]) * (x[i] * x[i] + y[i]*y[i] - x[j]*x[j] - y[j]*y[j]) 
                - (x[j] - x[i]) * (x[i] * x[i] + y[i]*y[i] - x[k]*x[k] - y[k]*y[k]))
                / (2 * (x[k] - x[i]) * (y[i] - y[j]) - 2 * (x[j] - x[i]) * (y[i] - y[k]));
                if (x[i] == x[j]) {
                    px = double(2 * (y[i] - y[k]) * py - (x[i] * x[i] + y[i]*y[i] - x[k]*x[k] - y[k]*y[k])) 
                    / (2 * (x[k] - x[i]));
                }
                else {
                    px = double(2 * (y[i] - y[j]) * py - (x[i] * x[i] + y[i]*y[i] - x[j]*x[j] - y[j]*y[j])) 
                    / (2 * (x[j] - x[i]));
                }
                double r = pow(pow((px - x[i]), 2) + pow(py - y[i], 2), 0.5);
                //cerr << r << endl;
                bool ok = 1;
                for (int l = 0; l < n; l++) {
                    if (l == i || l == j || l == k) continue;
                    if ((px - x[l]) * (px - x[l]) + pow(py - y[l], 2) - r * r > eps) ok = 0;
                }

                //cout << px _ py << endl;

                if (ok) ans = min(ans, r);
            }
        }
    }
    cerr << setprecision(16) << ans << endl;

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            double px = (x[j] + x[i]) / 2, py = (y[j] + y[i]) / 2;
            double r = pow(pow((px - x[i]), 2) + pow(py - y[i], 2), 0.5);
            bool ok = 1;
            for (int k = 0; k < n; k++) {
                if (k == i || k == j) continue;
                //if (i == 0 && j == 3) cout << k _ abs((px - x[k]) * (px - x[k]) + pow(py - y[k], 2) - r * r) << endl;
                if ((px - x[k]) * (px - x[k]) + pow(py - y[k], 2) - r * r > eps) ok = 0;
            }
            //cerr << i _ j _ r << endl;
            if (ok) {
                //cout << i _ j _ r << endl;
                ans = min(ans, r);
            }
        }
    }

    cout << setprecision(16) << ans << endl;



}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;

using namespace std;

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

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000001

int main() {
    string s;cin >> s;
    vector<int> ans;

    for(int i = 0; i < 26; i++) {
        vector<bool> a(s.size(),false);
        bool x=false;
        for(int j = 0; j < s.size(); j++) {
            if(s[j]==(char)(i+97)) {
                a[j]=true;
                x=true;
            }
        }

        if(!x) continue;

        int p=0;
        while(1){
            bool y=true;
            for(int j = 0; j < a.size(); j++) {
                if(!a[j]) y=false;
            }

            if(y){
                ans.push_back(p);
                break;
            }

            for(int j = 0; j < a.size()-1; j++) {
                if(a[j+1]) a[j]=true;
            }
            a.pop_back();
            p++;            
        }        
    }
    sort(ans.begin(),ans.end());
    cout << ans[0] << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <cstdio>

const int MN = 21;

int N, K, s[1 << MN], tr[1 << MN][2];
int f[MN][1 << MN], Ans;

int main() {
	scanf("%d%d", &N, &K);
	for (int i = 0; i <= N; ++i)
		for (int x = 0; x < 1 << i; ++x)
			scanf("%1d", &f[i][1 << i ^ x]);
	s[0] = -1;
	for (int A = 1; A < 2 << N; ++A) s[A] = s[A >> 1] + 1;
	for (int A = 2; A < 2 << N; ++A)
		if (A >> (s[A] - 1) & 1) {
			tr[A][1] = A ^ 1 << s[A];
			tr[A][0] = tr[tr[A][1]][0];
		} else {
			tr[A][0] = A ^ 3 << (s[A] - 1);
			tr[A][1] = tr[tr[A][0]][1];
		}
	for (int i = N; i >= 1; --i) {
		for (int A = 1 << i; A < 2 << N; ++A) {
			if (!f[i][A]) continue;
			int _ = A >> i, B = (A & ((1 << i) - 1)) ^ 1 << i;
			if (tr[B][0]) f[s[tr[B][0]]][(_ << 1 ^ 1) << s[tr[B][0]] ^ tr[B][0]] += f[i][A];
			if (tr[B][1]) f[s[tr[B][1]]][(_ << 1 ^ 0) << s[tr[B][1]] ^ tr[B][1]] += f[i][A];
			f[0][_] += f[i][A];
		}
	}
	Ans = 1;
	for (int A = 2; A < 2 << N; ++A) if (f[0][A] >= K && s[A] > s[Ans]) Ans = A;
	int j = N;
	while (~Ans >> j & 1) --j;
	while (j--) printf("%d", Ans >> j & 1);
	puts("");
	return 0;
}

Measured memory_bytes: 194688
n,k=map(int,input().split())
X=[int(i) for i in input().split()]
road=[]
for i in range(n-k+1):
    if X[i]<=0 and X[i+k-1]>=0:
        r=min(abs(X[i]),X[i+k-1])+X[i+k-1]-X[i]
    elif X[i]<=0 and X[i+k-1]<=0:
        r=abs(X[i])
    else:
        r=X[i+k-1]
    road.append(r)

print(min(road))


Measured memory_bytes: 14252
s = input()

ints = list(map(int,s))
min = 1000000
for i in range(len(ints)-2) :
    if min >= abs((100*ints[i]+10*ints[i+1]+ints[i+2])-753) :
        min = abs((100*ints[i]+10*ints[i+1]+ints[i+2])-753)

print(min)

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

int main(){
    ll x;
    cin >> x;
    ll m = 100;
    ll cnt = 1;
    for(int i = 0; i >= 0; i++){
        m *= 1.01;
        if(m >= x){
            cout << cnt << endl;
            break;
        }
        cnt++;
    }
}

Measured memory_bytes: 3636
function main(input) {
  const N = Number(input)
  const arr = Array.from(new Array(N)).map((e, i) => i + 1)
  // console.log(arr)
  const sum = arr.reduce((h, e) => {
    if (e % 5 !== 0 && e % 3 !== 0) {
      return h + e
    } else {
      return h
    }
  }, 0)
  console.log(sum)

}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 60400
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var m = int.Parse(line[0]);
            var nmin = int.Parse(line[1]);
            var nmax = int.Parse(line[2]);
            if (m == 0 && nmin == 0 && nmax == 0) break;
            var pre = 0;  var gapmax = 0;  var maxi = 0;
            for (int i = 0; i < m; i++)
            {
                var t = int.Parse(Console.ReadLine().Trim());
                if (i == nmin - 1) pre = t;
                else if (i >= nmin && i <= nmax)
                {
                    if (pre - t >= gapmax) { gapmax = pre  - t;  maxi = i; }
                    pre = t;
                }
            }
            Console.WriteLine(maxi);
        }
    }
}

Measured memory_bytes: 9260
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main()
{
	int n,maxv,sumv=0,total=0,j=1;
	cin>>n>>maxv;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
		sumv+=a[i];
		if (sumv<=maxv&&j!=0)  total++;
		else j=0;
	}
	cout<<total+1<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Tap Dance
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            String S = sc.next();

            for (int i = 1; i <= S.length(); i++) {
                char c = S.charAt(i - 1);

                if (i % 2 == 1) {
                    if (c == 'R' || c == 'U' || c == 'D') {
                    } else {
                        System.out.println("No");
                        System.exit(0);
                    }
                } else {
                    if (c == 'L' || c == 'U' || c == 'D') {
                    } else {
                        System.out.println("No");
                        System.exit(0);
                    }
                }
            }

            System.out.println("Yes");
        }
    }

}


Measured memory_bytes: 22868
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	int A, B, C; cin >> A >> B >> C;

	int ans = min(
			{abs(A-B) + abs(B-C),
			abs(A-C) + abs(C-B),
			abs(B-A) + abs(A-C),
			abs(B-C) + abs(C-A),
			abs(C-A) + abs(A-B),
			abs(C-B) + abs(B-A)}
			);


	cout << ans << endl;
	return 0;

}


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

const int INF = 1e9;
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> dp(1 << n, INF);
    dp[0] = 0;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        int add = 0;
        for (int j = 0; j < b; j++) {
            int c;
            cin >> c;
            add |= 1 << (c - 1);
        }
        for (int j = 0; j < 1 << n; j++) {
            dp[j | add] = min(dp[j | add], dp[j] + a);
        }
    }
    int ans = dp[(1 << n) - 1];
    cout << (ans == INF ? -1 : ans) << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
x = gets.split.map(&:to_f)
y = gets.split.map(&:to_f)
d1 = 0
d2 = 0
d3 = 0
di = 0
n.times do |i|
  tmp = (x[i] - y[i]).abs
  d1 += tmp
  d2 += tmp**2
  d3 += tmp**3
  di = [di, tmp].max
end

puts d1
puts d2**(1.0 / 2)
puts d3**(1.0 / 3)
puts di



Measured memory_bytes: 8980
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
int N,M;
vector<vector<int>> G;

void dfs(int v,vector<bool> &seen,int &res){
    bool end = true;
    for(int i=0;i<seen.size();i++){
        if(!seen[i]&&i!=v) end = false;
    }
    if(end){
        ++res;
        return;
    }
    seen[v] = true;
    for(auto nv:G[v]){
        if(seen[nv]) continue;
        dfs(nv,seen,res);
    }
    seen[v] = false;
}

int main(){
    cin >> N >> M;
    G.assign(N,vector<int>());
    rep(i,M){
        int a,b;cin >> a >> b;
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<bool> seen(N,false);
    int res = 0;
    dfs(0,seen,res);
    cout << res << endl;
}

Measured memory_bytes: 256
n = int(input())

ans = n
for i in range(n + 1):
    cnt = 0
    t = i
    while t > 0:
        cnt += t % 6
        t //= 6
    t = n - i
    while t > 0:
        cnt += t % 9
        t //= 9
    ans = min(ans, cnt)

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

vector<int> prime_n;
bool prime[100001];

vector < pair < ll, ll > > p_f(ll x) { // 素因数分解　エストラテネスのふるいで求めた素数表が必要
	vector < pair<ll, ll> > ans;
	while (x > 1) {
		bool flag = false;
		for (int i = 0; i < prime_n.size(); i++) {
			if (x % prime_n[i] == 0) {
				x /= prime_n[i];
				if (ans.empty() || ans[ans.size() - 1].first != prime_n[i])ans.push_back(pair<ll, ll>(prime_n[i], 1));
				else ans[ans.size() - 1].second++;
				flag = true;
				break;
			}
		}
		if (flag == false) {
			ans.push_back(pair<ll, ll>(x, 1));
			break;
		}
	}
	return ans;
}

int main() {
	fill(prime, prime + 100001, true); //素数
	prime[0] = prime[1] = false;
	for (int i = 2; i < 100001; i++) {
		if (prime[i] == true) {
			prime_n.push_back(i);
			for (int j = 2; i * j < 100001; j++) {
				prime[i * j] = false;
			}
		}
	}

	ll N, P;
	cin >> N >> P;
	ll ans = 1;
	vector < pair < ll, ll > > fac = p_f(P);
	for (int i = 0; i < fac.size(); i++) {
		ans *= max((ll)pow(fac[i].first, (fac[i].second / N)), 1LL);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 10;
const int p = 1000000007;
long long a[maxn], dp[2005][2005];
int main() {
    string s;   cin >> s;
    if (s.size() & 1) {
        printf("No\n");
    }
    else {
        bool flag = true;
        for (int i = 0; i < (int)s.size(); i++) {
            if (i & 1) {
                if (s[i] != 'i') {
                    flag = false;
                    break;
                }
            }
            else {
                if (s[i] != 'h') {
                    flag = false;
                    break;
                }
            }
        }
        if (flag) {
            printf("Yes\n");
        }
        else {
            printf("No\n");
        }
    }
    getchar(); getchar();
    return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
a = []
a.append(' ' * (w + 2))
for i in range(h):
    a.append(' ' + input() + ' ')
a.append(' ' * (w + 2))
ans = [[None for _ in range(w)] for _ in range(h)]
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if a[i][j] == '#':
            ans[i - 1][j - 1] = '#'
        elif a[i][j] == '.':
            ans[i - 1][j - 1] = str(''.join(a[k][l] for k in range(i - 1, i + 2) for l in range(j - 1, j + 2)).count('#'))
for value in ans:
    print(''.join(value))
        

Measured memory_bytes: 42076
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pi pair<ll,int> 
#define pii pair<int,ll>
 
ll mod = 1e9+7;
ll INF = 1e17;
ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}
int main()
{
    IOS
    ll n;
    cin>>n;
    cout<<ceil(n/2.0)<<endl;
    return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d[100],tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
long out[100];

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
        cin.tie(0);
        cout.tie(0);
    ios::sync_with_stdio(false);

    cin>>n>>k;
    rep(i,k)cin>>d[i];
    rep(i,k)out[d[i]]=1;
    rrep(i,n,ohara){
        s=to_string(i);
        int ok=0;
        rep(j,Size(s)){
            if(out[s[j]-'0']==1){
                ok=1;
                break;
            }
        }
        if(ok)continue;
        Cout(i);
        return 0;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
main(){
  char h[16][16];
  int am[10],pm[10];
  int max[10],mo[10];
  int i,j,temp;
  for(i=0;i<9;i++){
    scanf("%s %d %d",h[i],&am[i],&pm[i]);
    max[i]=am[i]+pm[i];
    mo[i]=am[i]*200+pm[i]*300;
  }
  for(i=0;i<9;i++){
    printf("%s %d %d\n",h[i],max[i],mo[i]);
  }
  return 0;
}

Measured memory_bytes: 0
S = input()
a, b, c, d = int(S[0]), int(S[1]), int(S[2]), int(S[3])
if a+b+c+d == 7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a+b+c-d == 7:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a+b-c+d == 7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a+b-c-d == 7:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
elif a-b+c+d == 7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
elif a-b+c-d == 7:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
elif a-b-c+d == 7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
elif a-b-c-d == 7:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
using Graph = vector<vector<int>>;

// 全探索

int main() {
  ll n; cin >> n;
  Vl x(n), y(n), h(n);
  rep(i, 0, n) cin >> x[i] >> y[i] >> h[i];

  Rep(cx, 0, 100) Rep(cy, 0, 100){
    bool f = true; ll H;
    int j = 0;
    while(h[j] < 1) j++;
    H = h[j]+abs(cx-x[j])+abs(cy-y[j]);
    
    rep(i, 0, n){
      if(h[i] != max(H-abs(x[i]-cx)-abs(y[i]-cy), 0LL)) f = false;
    }
    if(f){
      cout << cx << " " << cy << " " << H << endl;
    }
  }

  return 0;
}


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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    int n, cnt[3] = {0, 0, 0}, a, b;
    cin >> n >> a >> b;
    rep(i, 0, n) {
        int t; cin >> t;
        if (t <= a) cnt[0]++;
        else if (t <= b) cnt[1]++;
        else cnt[2]++;
    }
    cout << min(cnt[0], min(cnt[1], cnt[2])) << endl;
}

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

using namespace std;

int main(void)
{
    int i,n;
    string str;
    
    cin >> str;
    n = (int)str.length();
    
    for (i = n - 1; i >= 0; i--) {
        cout << str[i];
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 1172
A['   '];
M;
B, X, Y;
W, J, I;
main() {
  scanf("%d%d", &I, &M);
  for (; ~scanf("%d%d", &X, &Y);) {
    for (B = Y + 1, J = 1; J * J <= M; J++)
      I = (X + J - 1) / J, W = Y / J + 1, A[I]++, A[W < B ? W : B]--, B = I;

    for (I = 1; I < B; I++)
      if ((X - 1) / I < Y / I)
        A[I]++, A[I + 1]--;
  }
  for (I = 1; I <= M; I++) {
    A[I] += A[I - 1];
    printf("%d\n", A[I]);
  }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

char f(char u, char v) {
  if (u == 'm' && v == 'm')
    return 'L';
  else if (u == 'm')
    return 'D';
  else if (v == 'm')
    return 'U';
  else
    return 'R';
}

signed main() {
  int N;
  cin >> N;
  vector<int> X(N), Y(N);
  rep(i, N) {
    cin >> X[i] >> Y[i];
  }

  int parity = (X[0] + Y[0] + 10000000000) % 2;
  rep(i, N) {
    if ((X[i] + Y[i] + 10000000000) % 2 != parity) {
      cout << -1 << '\n';
      return 0;
    }
  }

  bool even = (parity == 0);
  rep(i, N) {
    X[i] -= even;
  }

  int keta = 32;
  int m = keta + even;
  vector<int> d(keta);
  int bin = 1;
  rep(i, keta) {
    d[i] = bin;
    bin *= 2;
  }

  reverse(all(d));
  if (even)
    d.pb(1);

  cout << m << endl;
  cout << d << endl;


  rep(i, N) {
    int U = X[i] + Y[i];
    int V = X[i] - Y[i];

    int u = 0, v = 0;
    rep(j, keta) {
      int num = u - d[j], nup = u + d[j];
      char uc;
      if (abs(num - U) < abs(nup - U)) {
        uc = 'm';
        u = num;
      } else {
        uc = 'p';
        u = nup;
      }

      int nvm = v - d[j], nvp = v + d[j];
      char vc;
      if (abs(nvm - V) < abs(nvp - V)) {
        vc = 'm';
        v = nvm;
      } else {
        vc = 'p';
        v = nvp;
      }

      cout << f(uc, vc);
    }
    if (even)
      cout << 'R';
    cout << '\n';
  }
}

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

const int INF = 10000009;
char maze[20][20];
int W, H, sx, sy;
int ans = 1;
int d[20][20];
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };

void bfs() {
	queue< pair<int, int> > que;
	for (int i = 0; i < H; i++)for (int j = 0; j < W; j++) d[i][j] = INF;
	que.push(make_pair(sx, sy));
	d[sy][sx] = 0;
	while (que.size()) {
		pair<int, int> p = que.front(); que.pop();
		for (int i = 0; i < 4; i++) {
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (nx >= 0 && nx < W && ny >= 0 && ny < H && maze[ny][nx] != '#') {
				if (d[ny][nx] == INF) {
					que.push(make_pair(nx, ny));
					d[ny][nx] = 0;
					ans++;
				}
			}
		}
	}
}
int main() {
	while (cin >> W >> H && W + H) {
		ans = 1;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cin >> maze[i][j];
				if (maze[i][j] == '@') {
					sy = i; sx = j;
				}
			}
		}
		bfs();
		cout << ans << endl;
	}
}


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

using namespace std;

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

#define All(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   string s;
   cin >> s;
   int size = s.size() - 1;
   for(;size>=2;size--){
      if(size%2==1)continue;
      if(s.substr(0,size/2) == s.substr(size/2,size/2)){
         cout << size << endl;
         return 0;
      }
   }
   return 0;
}

Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())

    lst = list(map(int, input().split()))
    lst.sort()
    if N>=M:
        print(0)
        return

    diff = []
    for i in range(M-1):
        diff.append(lst[i+1] - lst[i])
    diff.sort()
    
    if N==1:
        print(sum(diff))
    else:
        rmdiff = diff[:-(N-1)]
        print(sum(rmdiff))
main()

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

int main() {
    int s, w;
    cin >> s >> w;
    if(w>=s) cout << "unsafe" << endl;
    else cout << "safe" << endl; 
    return 0;
}

Measured memory_bytes: 3636
a, b = map(int, input().split())
#x * 0.08 = a
#x * 0.1 = b

xa = int(a/0.08)
xb = int(b/0.1)

ans = -1
x = min(xa, xb)
for i in range(-20, 30):
  x_tmp = x + i
  #print(x_tmp, int(x_tmp*0.08), int(x_tmp*0.1))
  if int(x_tmp*0.08)==a and int(x_tmp*0.1)==b:
    ans = x_tmp
    break

if ans==-1:
  print(-1)
else:
  print(int(ans))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){ //for debug
    ll n = vec.size();
    cout << "------------------------------------\n" ;
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
    cout << "------------------------------------\n" ;
}

void pr2d(vector<vector<ll>> vec){ // for debug
    ll h = vec.size();
    ll w = vec.at(0).size();
    cout << "------------------------------------\n" ;
    rep(i,h){
        rep(j,w){
            cout << vec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
    cout << "------------------------------------\n" ;
}

int main(){
    ld a,b,c; cin >>a >> b >> c ;
    if(sqrt(a)+sqrt(b)+2e-15<sqrt(c)){
        cout << "Yes" ;
    }else{
        cout << "No";
    }
}


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

int main(void) {
	int N, i; cin >> N;
	long int a[87];
	a[0] = 2;
	a[1] = 1;

	if (N <= 1) { cout << "1" << endl; return 0; }

	for (i = 2; i <= 86; i++) {
		a[i] = a[i - 1] + a[i - 2];
	}

	cout << a[N] << endl;
	return 0;
}


Measured memory_bytes: 256
H1, M1, H2, M2, K = map(int, input().split())

if M1>M2:
    H = H2-H1-1
    M = 60+M2-M1
else:
    H = H2-H1
    M = M2-M1
time = H*60+M
if time>=K:
    print(time-K)
else:
    print(0)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

long long gcd(long long a, long long b) {
    for(;;) {
        if(a == 0)
            return b;
        b %= a;
        if(b == 0)
            return a;
        a %= b;
    }
}

long long lcm(long long a, long long b) {
    long long temp = gcd(a, b);
    return temp ? (a / temp * b) : 0;
}

int main() {
    ll A, B;
    cin >> A >> B;
    cout << lcm(A, B) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,i;
    cin>>n;
    unsigned long long a[n],s;
    for(i=0;i<n;i++)cin>>a[i];
    s=a[0];
    for(i=1;i<n;i++){
        s=(a[i]/(__gcd(a[i],s)))*s;
    }
    cout<<s;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


N, K = na()

if K > ((N-1) * (N-2) / 2):
    print(-1)
else:
    M = (N-1) + (N-1) * (N-2) // 2 - K
    print(M)
    for i in range(N-1):
        print(1, (i+2))
    cnt = M - (N-1)
    if cnt == 0:
        exit()
    for i in range(2, N+1):
        for j in range(i+1, N+1):
            cnt -= 1
            print(i, j)
            if cnt == 0:
                break
        if cnt == 0:
            break


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

class Point{
    List<Integer> coordinates = new ArrayList<>();

    Point(List<Integer> list){
        this.coordinates=list;
    }
    
     double getDistance(Point another){
         double distance=0;
         for(int i=0;i<coordinates.size();i++){
             distance+=Math.pow((this.coordinates.get(i)-another.coordinates.get(i)),2);
         }
         distance=Math.sqrt(distance);
         return distance;
     }
}



public class Main{
    

    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());
            int ans=0;
            int n=sc.nextInt();
            int d=sc.nextInt();


            List<Point> allPoint = new ArrayList<>();
            for(int i=0;i<n;i++){
                List<Integer> list = new ArrayList<>();
                for(int j=0;j<d;j++){
                    list.add(sc.nextInt());
                }
                Point point= new Point(list);
                allPoint.add(point);
            }
            sc.close();
            
            for(int i=0;i<n;i++){
                for(int j=i+1;j<n;j++){
                    double dist=allPoint.get(i).getDistance(allPoint.get(j));
                    if(Math.floor(dist)==dist){
                        ans++;
                    }
                }
            }
            System.out.println(ans);
    }
}
    

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

using namespace std;

string s[102];

int C[102], R[102];

int H, W;

int main(void) {
	cin >> H >> W;
	string tmp;

	for (int i = 1; i <= H; i++) {
		cin >> tmp;
		s[i] = "%" + tmp;
	}

	for (int i = 1; i <= H; i++) {
		int sign = 0;
		for (int j = 1; j <= W; j++) {
			if (s[i][j] == '#') { sign = 1; }
		}
		if (sign == 0) { C[i] = 1; }
	}

	for (int j = 1; j <= W; j++) {
		int sign = 0;
		for (int i = 1; i <= H; i++) {
			if (s[i][j] == '#') { sign = 1; }
		}
		if (sign == 0) { R[j] = 1; }
	}

	/*for (int i = 1; i <= W; i++) {
		cout << R[i] << endl;
	}*/

	for (int i = 1; i <= H; i++) {
		if (C[i] == 1) { continue; }
		for (int j = 1; j <= W; j++) {
			if (R[j] == 0) { cout << s[i][j]; }
		}
		cout << endl;
	}

	//system("pause");
	return 0;
}

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

int main(){
  ll n,m,ans=1; cin >>n >>m;
  const ll M = 1e9 + 7;
  if(abs(n-m)>1){
    cout << 0 << endl;
    return 0;
  }
  if(n==m) ans*=2;
  for(ll i = 1; i<=n; i++) ans=ans*i%M;
  for(ll i = 1; i<=m; i++) ans=ans*i%M;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
import fractions
from functools import reduce
def gcd(*i):
    return reduce(fractions.gcd, i)
def main():
    N = int(input())
    A = list(map(int, input().split()))
    L=[0]
    R=[0]
    for i in range(N):
        L.append(gcd(L[i],A[i]))
        R.append(gcd(R[i],A[-(i+1)]))
    R=R[::-1]
    ans=[]
    for i in range(N):
        ans.append(gcd(L[i],R[i+1]))
    print(max(ans))
if __name__ == "__main__":
    main()

Measured memory_bytes: 16604
using System;

class AtCoder
{    
    static void Main(string[] args)
     {
        int n = int.Parse(Console.ReadLine());
        int a = int.Parse(Console.ReadLine());

        int amari = n % 500;

        var s = amari <= a ? "Yes" : "No";

        Console.WriteLine(s);
     }
 }

Measured memory_bytes: 11092
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>
     
using namespace std;
     
typedef long long ll;
     
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
     
#define MOD 1000000007

int main(){
  ll n;
  cin>>n;
  ll a[8] = {1800,1600,1400,1200,1000,800,600,400};
  rep(i,0,8){
    if(a[i]<=n&&n<a[i]+200){
      cout << i+1 << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL;
  typedef pair<ll,char> PLC;
  typedef pair<char,ll> PCL;

double snuke_num(ll n){
  ll N = n;
  ll digit_sum = 0;
  while(n!=0){
    digit_sum += n%10;
    n/=10;
  }
  return (double)N/digit_sum;
}

vector<ll> make_snuke(){
  int i;
  vector<ll> snuke;
  REP(i,9) snuke.push_back(i+1);
  REP(i,9) snuke.push_back((i+1)*10+9);
  ll s = 100;
  REP(i,13){
    for(ll j=2;j<=200;j++){
      snuke.push_back(j*s-1);
    }
    s *= 10;
  }
  sort(snuke.begin(),snuke.end());
  double min = 1e+16;
  ll pre = 0;
  vector<ll> ans;
  for(i=snuke.size()-1;i>=0;i--){
    if(pre==snuke[i])continue;
    double snukeNum = snuke_num(snuke[i]);
    if(snuke_num(snuke[i]) <= min){
      ans.push_back(snuke[i]);
      min = snukeNum;
    }
    pre = snuke[i];
  }
  sort(ans.begin(),ans.end());
  return ans;
}

int main(void){
  ll K;cin >> K;
  vector<ll> ans = make_snuke();
  int i;REP(i,K) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 256
s=input()
ans=0
for i in range(len(s)):
  cnt=0
  for j in range(i,len(s)):
    if s[j]!="A" and s[j]!="T" and s[j]!="C" and s[j]!="G":
      break
    else:
      cnt+=1
  if ans<=cnt:
    ans=cnt
print(ans)

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

int main(){
  int N,A;
  cin >> N;
  A=N%10;
  if(A==0 || A==1 || A==6 || A==8){
    cout << "pon" << endl;
  }
  else if(A==3){
    cout << "bon" << endl;
  }
  else{
    cout << "hon" << endl;
  }
}

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

int main() {
  string S;
  cin >> S;

  for(int i=0;i<3;i++){
    if(S.at(i) == '7'){
      cout << "Yes" << endl;
      return 0;
    }else{
      continue;
    }
  }

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

Measured memory_bytes: 3624
// :)
// "Khodaya, be man "Tagwaye setiz" biamooz ta
//  dar anbuh masuliat nalaghzam ..." -Shariati
#include <bits/stdc++.h>
using namespace std;

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

#define F first
#define S second
#define MP make_pair

const int MAX = 2e5+9;
const ll MOD = 1e9+7;

ll a[MAX], dp[25];

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	memset(dp, -1, sizeof dp);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	ll ans = 0;
	ll last = -1;
	for (int i = 0; i < n; i++) {
		ll mx = -1;
		for (int k = 0; k < 20; k++)
			if ((1 << k) & a[i])
				mx = max(mx, dp[k]);
		last = max(last, mx);
		ans += i-last;
		for (int k = 0; k < 20; k++)
			if ((1 << k) & a[i])
				dp[k] = i;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cstdlib>

using namespace std;

int n;

void countingSort(int *A, int *B, int k){
  int C[10010] = {};

  for(int i = 1;i <= n;i++) C[A[i]]++;
  for(int i = 1;i <= k;i++) C[i] += C[i - 1];
  for(int i = n;i >= 1;i--){
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }
}

int main(){

  int k = 0;
  int *a, *b;

  cin >> n;
  a = (int *)malloc(sizeof(int) * n + 1);
  b = (int *)malloc(sizeof(int) * n + 1);
  for(int i = 1;i <= n;i++){
    cin >> a[i];
    k = max(k, a[i]);
  }

  countingSort(a, b, k);

  for(int i = 0;i < n;i++){
    cout << (i?" ":"");
    cout << b[i + 1];
  }
  cout << endl;

  return 0;
}



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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using v = vector<T>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

inline ll inl() {
    ll x;
    cin >> x;
    return x;
}

inline string ins() {
    string x;
    cin >> x;
    return x;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        ll n;
        cin >> n;
        vl p(n);
        rep(i, n) cin >> p[i];
        vl sorted(p);
        sort(all(sorted));

        for (ll i = 0; i < n; ++i) {
            for (ll j = 0; j < n; ++j) {
                swap(p[i], p[j]);
                for (ll l = 0; l < n; ++l) {
                    if (p[l] != sorted[l]) break;
                    if (l == n - 1) {
                        cout << "YES" << endl;
                        return 0;
                    }
                }
                swap(p[i], p[j]);
            }
        }
        cout << "NO" << endl;
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def solve():
    n, m = map(int, input().split())
    am = set(int(input()) for i in range(m))
    ans = [0] * (n + 10)
    ans[0] = 1
    md = 10 ** 9 + 7
    for i in range(n):
        if (i + 1) not in am:
            ans[i + 1] += ans[i]
            ans[i + 1] %= md
        if (i + 2) not in am:
            ans[i + 2] += ans[i]
            ans[i + 2] %= md
    print(ans[n])

if __name__=="__main__":
    solve()


Measured memory_bytes: 58232
#include<stdio.h>
int main()
{
	int N,i,s1=0,s2=0,s3=0;
	scanf("%d",&N);
	long int a[200000]={0};
	for(i=0;i<N;i++)
	{
		scanf("%ld",&a[i]);
	}
	for(i=0;i<N;i++)
	{
		if(a[i]%2!=0)//奇数 
		{
			s1++;
		}
		else if(a[i]%4==0) 
		{
			s2++;
		}
		else//不能被4整除的偶数 
		{
			s3++;
		}
	}

		if(s1==s2+1&&s2!=0&&s3==0)
		{
			printf("Yes");
		}
		else if(s1<=s2)	printf("Yes");
		else printf("No");
	return 0;
}

Measured memory_bytes: 1664
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n,k;
vector<int> usable;
queue<int> q;
int bfs(){
    
    Rep(i,usable.size()){
        q.push(usable[i]);
    }
    int m;
    while(q.size()){
        m = q.front();q.pop();
        if(m>=n)return m;
        Rep(i,usable.size()){
            int s=m*10+usable[i];
            q.push(s);
        }
    }
    return -1;
}
int main() {
    cin >> n >> k;
    vector<int> d(k);
    SORT(d);
    Rep(i,k){
        cin >> d[i];
    }int cnt = 0;
    Rep(i,10){
        if(d[cnt]!=i){
            usable.push_back(i);
        }else{
            cnt++;
        }
    }
    put(bfs());
}


Measured memory_bytes: 512
// Aizu 2185: Petting Cats
// 2017.9.20 bal4u@uu

#include <stdio.h>

int main()
{
	int t, n, x, y, x1, y1, x2, y2, ans;

	scanf("%d", &t);
	while (t-- > 0) {
		scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &n);
		x2 += x1, y2 += y1;
		ans = 0; while (n-- > 0) {
			scanf("%d%d", &x, &y);
			if (x >= x1 && x <= x2 && y >= y1 && y <= y2) ans++;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1680
# -*- coding: utf-8 -*-
"""
D - Cake 123
https://atcoder.jp/contests/abc123/tasks/abc123_d
AC
"""
import sys


from itertools import product

def solve(X, Y, Z, K, A, B, C):
    # 解説の解法#2
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)
    res = []
    for i, a in enumerate(A, start=1):
        for j, b in enumerate(B, start=1):
            for k, c in enumerate(C, start=1):
                if i*j*k > K:
                    break
                res.append(a+b+c)
    return sorted(res, reverse=True)[:K]


def main(args):
    X, Y, Z, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    C = [int(c) for c in input().split()]
    ans = solve(X, Y, Z, K, A, B, C)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 9564
#include<iostream>
#include<cmath>
#include<queue>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
#include<string>
#include<utility>
#include<set>
#include<map>
#include<stack>
#include<vector>
#define inf 0x3f3f3f3f
#define LL long long
using namespace std;
LL mod = 1000000007;
int T;
int n;
char s1[100];
char s2[100];
int cnt[100];
int main()
{
   while(~scanf("%d",&n))
   {
        scanf("%s",s1);
        scanf("%s",s2);
        int p = 0;
        for(int i = 0;i < n;i++){
            if(i+1<n&&s1[i]==s1[i+1]){
                cnt[p++] = 2;
                i++;
            }
            else
            {
                cnt[p++] = 1;
            }
        }
        LL sum = 0;
        if(cnt[0]==1)
            sum = 3;
        else
            sum = 6;
        for(int i = 0;i<p-1;i++){
            if(cnt[i]==1&&cnt[i+1]==2){
                sum *= 2;
                sum%=mod;
            }
            if(cnt[i]==1&&cnt[i+1]==1){
                sum*=2;
                sum%=mod;
            }
            if(cnt[i]==2&&cnt[i+1]==1){
                sum*=1;
            }
            if(cnt[i]==2&&cnt[i+1]==2){
                sum*=3;
                sum%=mod;
            }
        }
        cout<<sum<<endl;
   }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int A, B;
  cin >> A >> B;
  if(A > B)swap(A, B);
  if((B - A) % 2 == 0)cout << A + ((B - A) / 2) << endl;
  else cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

object Main extends App{
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val al = List.fill(n)(sc.nextInt)

  val (max, semiMax) =
    al.foldLeft((0, 0)){case ((m, sm), a) =>
      if (a >= m) (a,m)
      else if(a >= sm) (m, a)
      else (m, sm)
    }

  al.foreach { a =>
    println {
      if (a == max) semiMax
      else max
    }
  }
}


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

int main(){
	int n;
	while(cin >> n,n){
		int a[20000] = {},wid = n;
		bool flag = false;
		for(int i = 0;i < n;i++) cin >> a[i];
		for(int i = 0;i <= 10000;i++){
			bool f = true;
			for(int j = 0;j < wid;j++) if(a[j] != j + 1) f = false;
			if(f){
				flag = true;
				cout << i << endl;
				break;
			}
			int prev = 0;
			a[wid] = wid;
			for(int j = 0;j < wid;j++) a[j]--;
			for(int j = 0;j <= wid;j++){
				if(a[j]) a[prev++] = a[j];
			}
			wid = prev;
		}
		if(!flag) cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
 
using namespace std;
 
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;
 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define Get(t, i) get<(i)>((t))
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto a : b)

#define int ll
 
const int inf = 1 << 25;
const ll INF = 1LL << 55;

// Dijkstra's algorithm with a heap: Single-source shoretest paths
struct edge
{
  int to, weight;
  edge(){}
  edge(int to, int weight):to(to), weight(weight){}
};

struct Dijkstra
{
  vector< vector<edge> > graph;
  vector<int> distance;
  Dijkstra(int sz):graph(sz), distance(sz, INF){}
  void add_edge(int from, int to, int weight, bool is_bidirect = false)
  {
    graph[from].push_back(edge(to, weight));
    if(is_bidirect) graph[to].push_back(edge(from, weight));
  }
  int shortest_path(int source, int destination = -1)
  {
    priority_queue<Pi, vector<Pi>, greater<Pi> > que;
    que.push(Pi(0, source));
    distance[source] = 0;
    while(!que.empty()) {
      Pi p = que.top(); que.pop();
      int v = p.second;
      if(v == destination) return p.first;
      if(distance[v] < p.first) continue;
      for(edge e : graph[v]) {
	if(distance[v] + e.weight < distance[e.to]) {
	  distance[e.to] = distance[v] + e.weight;
	  que.push(Pi(distance[e.to], e.to));
	}
      }
    }
    return -1;
  }
};

signed main()
{
  int V, E, r; cin >> V >> E >> r;
  Dijkstra sssp(V);
  while(E--) {
    int s, t, d; cin >> s >> t >> d;
    sssp.add_edge(s, t, d);
  }
  sssp.shortest_path(r);
  for(int i = 0; i < V; i++) {
    if(sssp.distance[i] == INF) puts("INF");
    else cout << sssp.distance[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 18316
#include<bits/stdc++.h>
using namespace std;
int main()
  {
  char ch[6];
  int count = 0;
  cin>>ch;
  for(int i=0;i<6;i++)
    {
    if(ch[i]=='1')
      count++;
    }
  cout<<count<<endl;
  }

Measured memory_bytes: 3584
#include <stdio.h>
#include <algorithm>

int main() {
	int N, L[200], sum = 0;
	scanf("%d", &N);
	for (int i = 0; i < 2 * N; i++)
		scanf("%d", L + i);
	std::sort(L, L + (2 * N));
	for (int i = 0; i < N; i++)
		sum += L[i * 2];
	printf("%d\n", sum);
}

Measured memory_bytes: 128