akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * 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;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int a = in.nextInt();
			int b = in.nextInt();
			int c = in.nextInt();
			out.println(a + b == c || b + c == a || c + a == b ? "Yes" : "No");
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

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

	}
}


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

int n;
int a[200005];
int l[200005], r[200005];
stack<int> st;

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	for (int i = 1; i <= n; ++i) {
		while (st.size() && a[st.top()] > a[i]) st.pop();
		l[i] = (st.size() ? st.top() + 1 : 1);
		st.push(i);
	}
	while (st.size()) st.pop();
	for (int i = n; i >= 1; --i) {
		while (st.size() && a[st.top()] > a[i]) st.pop();
		r[i] = (st.size() ? st.top() - 1 : n);
		st.push(i);
	}
	long long res = 0;
	for (int i = 1; i <= n; ++i) {
		res += 1LL * (i - l[i] + 1) * (r[i] - i + 1) * 1LL * a[i];
	}
	cout << res << '\n';
}

Measured memory_bytes: 3456
#include <stdio.h>
#include <stdlib.h>
#define V 10000
int main(){
  int i,j,n;
  int *A,*B;
  int C[V+1];
  scanf("%d",&n);
  A=malloc(sizeof(int)*n);
  B=malloc(sizeof(int)*n);
  for(i=0;i<=V;i++) C[i]=0;
  for(i=0;i<n;i++){
    scanf("%d",&A[i+1]);
    C[A[i+1]]++;
  }
  for(i=1;i<=V;i++) C[i]+=C[i-1];
  for(j=1;j<=n;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
  for(i=1;i<=n;i++){
    if (i>1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
}





Measured memory_bytes: 17468
x, y = map(int, input().split())
ans = float("inf")
rx, ry = -x, -y
# 最初にBを押して、最後に押す場合
if rx <= ry:
    ans = min(ans, ry-rx + 2)
# 最初にBを押して、最後に押さない場合
if rx <= y:
    ans = min(ans, y - rx + 1)
# 最初にBを押さず、最後に押す場合
if x <= ry:
    ans = min(ans, ry - x + 1)
# 最初にBを押さず、最後に押さない場合
if x <= y:
    ans = min(ans, y - x)
print(ans)

Measured memory_bytes: 78984
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s[110],t[110];
int main(){
	scanf("%s%s",s+1,t+1);
	bool mk=true;
	for(int i=1;i<=strlen(s+1);++i)if(s[i]!=t[i]){
		mk=false;
		break;
	}
	cout<<(mk ? "Yes" : "No")<<endl;
	return 0;
}




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

main()
{
    int n; cin>>n;
    long long k; cin>>k;
    vector<long long> po,ne;
    long long ze=0;
    for(int i=0;i<n;++i)
    {
        int a; cin>>a;
        if(a>0) po.push_back(a);
        else if(a<0) ne.push_back(-a);
        else ze++;
    }
    sort(begin(po),end(po));
    sort(begin(ne),end(ne));

    auto judge=[&](long long x)->bool
    {
        long long cnt=0;
        if(x>=0)
        {
            cnt+=(long long)po.size()*ne.size();
            cnt+=ze*(n-ze);
            cnt+=ze*(ze-1)/2;
            // po
            {
                for(auto i=begin(po);i!=end(po);++i)
                {
                    cnt+=upper_bound(begin(po),i,x/(*i))-begin(po);
                }
            }
            //ne
            {
                for(auto i=begin(ne);i!=end(ne);++i)
                {
                    cnt+=upper_bound(begin(ne),i,x/(*i))-begin(ne);
                }
            }
        }
        else
        {
            x=-x;
            for(long long &e:po)
            {
                cnt+=end(ne)-lower_bound(begin(ne),end(ne),(x+e-1)/e);
            }
        }

        return cnt>=k;
    };

    long long ok=1e18;
    long long ng=-1e18-1;
    while(ok-ng>1)
    {
        long long mid=(ok+ng)/2;
        if(judge(mid))
        {
            ok=mid;
        }
        else
        {
            ng=mid;
        }
    }
    cout << ok << "\n";
}

Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

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

    int i;
    int n;
    int s[100];

    cin >> n;
    for(i = 0; i < n; ++i)
        cin >> s[i];
        
    int sum = accumulate(begin(s), begin(s) + n, 0);
    if(sum % 10 != 0)
        cout << sum << "\n";
    else{
        sort(begin(s), begin(s) + n);
        for(i = 0; i < n; ++i){
            if(s[i] % 10 == 0){
                if(i == n -1){
                    cout << 0 << "\n";
                    return 0;
                }
                else continue;
            }
            else break;
        }
        cout << sum - s[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int x = sc.nextInt();
        sc.close();

        if (x > Math.pow(a, 2) * b / 2) {
            double emp = Math.pow(a, 2) * b - x;
            double h = emp / Math.pow(a, 2);
            double h1 = a * h * 2 / a;
            double c = Math.sqrt(Math.pow(a, 2) + Math.pow(h1, 2));
            double cos = (Math.pow(a, 2) + Math.pow(c, 2) - Math.pow(h1, 2)) / (2 * a * c);
            double r = Math.acos(cos);
            System.out.println(Math.toDegrees(r));

        } else {
            double h = (double) x / Math.pow(a, 2);
            double a1 = a * h * 2 / b;
            double c = Math.sqrt(Math.pow(a1, 2) + Math.pow(b, 2));
            double cos = (Math.pow(a1, 2) + Math.pow(c, 2) - Math.pow(b, 2)) / (2 * a1 * c);
            double r = Math.acos(cos);
            System.out.println(Math.toDegrees(r));
        }
    }
}


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

#define ll long long
#define endl '\n'
#define pb push_back

const int mod = 1e9 + 7;
const int MAXN = 1e5;

vector<int> arr[MAXN];
bool seen[MAXN][2];
ll dp[MAXN][2];// 0->white and 1-> black

ll sol(int v,int c,int parent){
	if(dp[v][c] != -1) return dp[v][c];


	//cout << v << " " << c <<  " " << parent << endl;

	ll val = 1;

	for(int i = 0;i < arr[v].size();i++){
		if(c == 0){
			if(arr[v][i] != parent) val = (val * (sol(arr[v][i],0,v) + sol(arr[v][i],1,v)))%mod;
		}

		else{
			if(arr[v][i] != parent) val = (val * sol(arr[v][i],0,v))%mod;
		}
	}

	dp[v][c] = val;
	return dp[v][c];
}

int main(){

	int n;
	cin >> n;

	for(int i = 0;i < n-1;i++){
		int u,v;
		cin >> u >> v;

		arr[u-1].pb(v-1);
		arr[v-1].pb(u-1);
	}


	memset(seen,false,sizeof(seen));
	memset(dp,-1,sizeof(dp));

	ll ans = (sol(0,0,-1) + sol(0,1,-1))%mod;

	cout << ans << endl;
}


Measured memory_bytes: 14464
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=2005;
bitset<N*N> dp;
int a[N];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n;
  cin>>n;
  int sum=0;
  rep(i,1,n+1)
    {
      cin>>a[i];
      sum+=a[i];
    }
  sort(a+1,a+n+1);
  dp.set(0);
  rep(i,1,n+1)
    dp|=(dp<<a[i]);
  rep(i,(sum+1)/2,N*N)
    if(dp.test(i))
      {
	cout<<i<<endl;
	return 0;
      }
  return 0 ;
}


Measured memory_bytes: 1792
#!/usr/bin/env python
n, c = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(c)]
C = [list(map(int, input().split())) for _ in range(n)]

grid = [[0]*c for _ in range(3)]
for i in range(n):
    for j in range(n):
        grid[(i+j)%3][C[j][i]-1] += 1

points = []
for i in range(3):
    row = []
    for color in range(1, c+1):
        x = 0
        for j, m in enumerate(grid[i]):
            x += m * D[j][color-1]
        row.append([x, color])
    points.append(row)

for i in range(3):
    points[i].sort()

ans = 1000*n*n
for i in range(27):
    x = points[0][i//9]
    y = points[1][i//3%3]
    z = points[2][i%3]
    if x[1] == y[1] or y[1] == z[1] or z[1] == x[1]:
        continue
    ans = min(ans, x[0]+y[0]+z[0])
print(ans)

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

int main(){
  int n;
  cin >> n;
  int act[n][3];
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      cin >> act[i][j];
    }
  }

  int dp[n+1][3];
  dp[0][0] = dp[0][1] = dp[0][2] = 0;
  for (int i = 1; i <= n; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      dp[i][j] = max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]) + act[i-1][j];
    }
  }

  int ans = max({dp[n][0],dp[n][1],dp[n][2]});
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

ll n;

bool check(ll a) {
    string t = to_string(a);
    bool f1 = 0, f2 = 0, f3 = 0;
    for(const char &c : t) {
        if(c == '3') {
            f1 = 1;
        }
        if(c == '5') {
            f2 = 1;
        }
        if(c == '7') {
            f3 = 1;
        }
    }
    return (f1 && f2 && f3);
}

ll dfs(ll now) {
    if(now > n) {
        return 0;
    }
    ll res = check(now);
    res += dfs(10 * now + 3);
    res += dfs(10 * now + 5);
    res += dfs(10 * now + 7);
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cout << dfs(0) << endl;
}

Measured memory_bytes: 256
n, k = [int(a) for a in input().split()]
V = [int(a) for a in input().split()]

ans = 0
have = []  # 手元にある宝石の価値のリスト
val = 0  # 手元にある宝石の価値の和

for l in range(0, min(k, n) + 1):
    for r in range(0, min(k - l, n - l) + 1):
        have = V[0 : l]
        if r > 0:
            have += V[-r : ]
        have.sort()
        val = sum(have)

        # 負の数をできるだけ戻す
        for d in range(0, min(l + r, k - l - r)):
            if have[d] > 0: break
            val -= have[d]

        ans = max(ans, val)

print(ans)


Measured memory_bytes: 41192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;

#define pb push_back
#define F  first
#define S  second
#define int ll
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define edl "\n"
#define ceils(s,n) (s+n-1)/n
#define str string
#define add insert
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)

const int MOD = 1e9 + 7, N = 5e5 + 10;
const ll LINF = LLONG_MAX;
int n,a,b,c,d,ans;
str s1,s2;
char ch1,ch2,ch3;
int32_t main() {
    fast();
    cin >>a >> b >> n ;
  	int r=min(ceils(n,a),ceils(n,b));
  


    cout<< r ;
    return 0;
}
 

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

int n,m,cnt,b[N]; bool bo[N];
struct node{ int x,y; }a[N];
bool cmp1(node u,node v){ return u.x<v.x; }
struct cmp2{
	bool operator()(int u,int v){ return a[u].y>a[v].y; }
};
priority_queue<int,vector<int>,cmp2> Q;
int main(){
	scanf("%d%d",&n,&m);
	int i,k,now,ans=0;
	for (i=1; i<=n; i++) scanf("%d%d",&a[i].x,&a[i].y);
	sort(a+1,a+n+1,cmp1);
	for (i=1; i<=n; i++){
		bo[i]=1; Q.push(i);
		ans++;
		if (ans>a[i].x){
			k=Q.top(); Q.pop();
			bo[k]=0; ans--;
		}
	}
	for (i=1; i<=n; i++) if (!bo[i] && a[i].y<=m) b[++cnt]=a[i].y;
	sort(b+1,b+cnt+1);
	for (i=1,now=m-ans; i<=cnt; i++)
		if (now){
			ans++; now=min(now-1,m-b[i]);
		}
	printf("%d\n",n-ans);
	return 0;
}


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


int main()
{
    int k;
    int a,b;
    cin>>k>>a>>b;
    int ak=a/k;
    int bk=b/k+1;
    int num=ak*k;
    while(ak<=bk)
    {
        num=ak*k;
        if(a<=num&&num<=b)
        {
            cout<<"OK"<<endl;
            return 0;
        }
        ak+=1;
    }
    cout<<"NG"<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll x, a;
    cin >> x >> a;
    cout << (x < a ? 0 : 10) << endl;
    return 0;
}

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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

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

int main(){
    string s;
    cin >> s;
    cout << count(s.begin(), s.end(), '1') << endl;
    return 0;
}


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

int main()
{
    string s;
    cin >> s;
    if(((s[0] == s[1]) && (s[0] == s[2])) || ((s[1] == s[2]) && (s[1] == s[3]))) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

VI g[100010], a(100010), v;
bool used[100010];

void dfs(int x) {
  used[x] = true;
  v.push_back(a[x]);
  for(int i: g[x]) {
    if(!used[i]) {
      dfs(i);
    }
  }
}

signed main(void)
{
  int n, m;
  cin >> n >> m;
  REP(i, n) cin >> a[i];
  REP(i, m) {
    int x, y;
    cin >> x >> y;
    g[x].PB(y);
    g[y].PB(x);
  }

  if(m == n-1) {
    cout << 0 << endl;
    return 0;
  }
  if(n < 2*(n-m-1)) {
    cout << "Impossible" << endl;
    return 0;
  }

  VI vec;
  int ret = 0, cnt = 0;
  REP(i, n) {
    if(!used[i]) {
      v.clear();
      dfs(i);
      sort(ALL(v));
      ret += v[0];
      // cout << i << " " << ret << endl;
      cnt++;
      FOR(i, 1, v.size()) {
        vec.PB(v[i]);
      }
    }
  }
  sort(ALL(vec));

  for(int i=0; cnt<2*(n-m-1) && i<vec.size(); ++i,++cnt) {
    ret += vec[i];
  }
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 9460
import java.util.Scanner;


public class Main {

    static int N = 1000;
    
    public static int lcs(String X, String Y) {
        int result = 0;
        int maxl = 0;
        int c[][] = new int[N+1][N+1];
        int m = X.length();
        int n = Y.length();
        for(int i = 1; i <= m; i++){
            for(int j = 1; j <= n; j++) {
                String s1 = String.valueOf(X.charAt(i-1));
                String s2 = String.valueOf(Y.charAt(j-1));
                if(s1.equals(s2)){
                    c[i][j] = c[i-1][j-1] +1;
                } else {
                    if(c[i-1][j] >= c[i][j-1]){
                        c[i][j] = c[i-1][j];
                    } else {
                        c[i][j] = c[i][j-1];
                    } 
                }
                if(maxl >= c[i][j]){
                   result = maxl;
                } else {
                   result = c[i][j];
                }
            }
        }
        
        return result;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int q = sc.nextInt();
        for(int i = 0; i < q; i++) {
            String X = sc.next();
            String Y = sc.next();
            System.out.println(lcs(X, Y));
        }
        
    }
    
}

Measured memory_bytes: 296308
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=200005;
int n,i,j,a[N],p[N],l,b[N],ans[N],g,G,cnt;
bool v[N];
int Abs(int a)
{
	return a>0?a:-a;
}
int gcd(int a,int b)
{
	if(!b)
		return a;
	return gcd(b,a%b);
}
int main()
{
	scanf("%d",&n);
	for(i=n;i>=0;--i)
		scanf("%d",a+i);
	for(i=2;i<=n;++i)
	{
		if(!v[i])
			p[++l]=i;
		for(j=1;j<=l&&p[j]*i<=n;++j)
		{
			v[p[j]*i]=true;
			if(i%p[j]==0)
				break;
		}
	}
	G=Abs(a[0]);
	for(i=1;i<=n;++i)
		G=gcd(G,Abs(a[i]));
	g=G;
	for(i=2;i*i<=g;++i)
		if(g%i==0)
		{
			ans[++cnt]=i;
			while(g%i==0)
				g/=i;
		}
	if(g>1)
		ans[++cnt]=g;
	for(i=1;i<=l;++i)
	{
		for(j=0;j<=n;++j)
			b[j]=(a[j]%p[i]+p[i])%p[i];
		for(j=n;j-p[i]+1>=1;--j)
		{
			b[j-p[i]+1]=(b[j-p[i]+1]+b[j])%p[i];
			b[j]=0;
		}
		for(;j>=0;--j)
			if(b[j]!=0)
				break;
		if(j<0&&G%p[i]!=0)
			ans[++cnt]=p[i];
	}
	sort(ans+1,ans+1+cnt);
	for(i=1;i<=cnt;++i)
		printf("%d\n",ans[i]);
	return 0;
}


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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main(){
  int n;
  cin >> n;
  vector<ll>a(100000);
  int cnt = 0;
  rep(i, 0, n){
      ll b;
      cin >> b;
      if(b>100000){
        cnt++;
        continue;
      }
      b--;
      a[b]++;
  }
  rep(i, 0, 100000){
      if(a[i]==0)continue;
      if(a[i]>i+1)cnt += a[i]-(i+1);
      if(a[i]<i+1) cnt += a[i];
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3940
/**

     .=     ,        =.
  _  _   /'/    )\,/,/(_   \ \
   `//-.|  (  ,\\)\//\)\/_  ) |
   //___\   `\\\/\\/\/\\///'  /
,-"~`-._ `"--'_   `"""`  _ \`'"~-,_
\       `-.  '_`.      .'_` \ ,-"~`/
 `.__.-'`/   (-\        /-) |-.__,'
   ||   |     \O)  /^\ (O/  | .        <-  BESSIE THE COW / BESITE SOV
   `\\  |         /   `\    /
     \\  \       /      `\ /
      `\\ `-.  /' .---.--.\
        `\\/`~(, '()      ('
         /(O) \\   _,.-.,_)
        //  \\ `\'`      /
       / |  ||   `""""~"`
     /'  |__||
           `o

*/


//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

using ll = long long;

const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


bool DEBUG = 0;
#define debug(x) if (DEBUG) {cerr << #x << " = " << x << "\n";}
#define debug_vec(x) if (DEBUG) {cerr << #x << " = {"; for(auto a : x) cerr << a << ","; cerr << "}" << endl;}

#define int ll

typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, a[N], pos[N];
main() {
    file("sort");
    ios;
    cin >> n;
    fo(i, 1, n, 1) cin >> a[i], pos[a[i]] = i;
    int cur = 1, ans = 0;
    fo(i, 1, n, 1) {
        if (a[i] == cur) {
            ++cur;
            continue;
        }
        ++ans;
    }
    if (cur == 1) return !(cout << -1);
    cout << ans;
    cerr << "\nTime elapsed: " << (clock() + 0.0) / CLOCKS_PER_SEC;
    return 0;
}
/**

*/


Measured memory_bytes: 3456
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

const MOD: i64 = 1e9 as i64 + 7;

fn main() {
    let (n, k): (usize, usize) = read();

    let mut dp: Vec<Vec<Vec<i64>>> = vec![vec![vec![0; 2]; n+1]; n+1];
    dp[n][0][0] = 1;
    for i in (1..n+1).rev() {
        for j in (0..n+1).rev() {
            for k in 0..2 {
                let base = dp[i][j][k];
                if base == 0 {
                    continue
                }
                if j >= 1 && k == 0 {
                    dp[i][j-1][0] += base;
                    dp[i][j-1][0] %= MOD;
                }

                dp[i-1][j][0] += base;
                dp[i-1][j][0] %= MOD;

                dp[i-1][j+1][1] += base;
                dp[i-1][j+1][1] %= MOD;
            }
        }
    }

    let mut ans = (dp[1][n-k][0] + dp[1][n-k][1]) % MOD;
    for x in 1..n-k {
        ans *= 2;
        ans %= MOD;
    }
    println!("{}", ans);
}

Measured memory_bytes: 174332
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <string>
#include <time.h>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <string.h>
using namespace std;

//#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
//#define cin in
//#define cout out
#define pii pair<int,int>
#define ll long long
#define db double
#define ld long double
#define uset unordered_set
#define umap unordered_map

ifstream in("input.txt");
ofstream out("output.txt");

int main()
{
	int a, b;
	cin >> a >> b;
	cout << max({ a - b,a + b, a * b });
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const double eps = 0.0000001;
const double PI = acos(-1.0);
const int MOD = 1e9+7;
const int N  = 1e3+5;

char a[N][N];
int dp[N][N];

int solve (int i, int j) {
	if (a[i][j] == '#') return 0;
	if (i == 1 && j == 1) return 1;
	if (i < 1 || j < 1) return 0;
	if (dp[i][j] != -1) return dp[i][j];
	dp[i][j] = (solve(i-1, j) + solve(i,j -1))%MOD;
	return dp[i][j];
}

signed main(){
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif  
    IOS;

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < N; i++)
    	for (int j = 0; j < N; j++)
    		dp[i][j] = -1;
    for (int i = 1; i <= n; i++) {
    	for (int j = 1; j <= m; j++) {
    		cin >> a[i][j];
    	}
    }
    cout << solve(n, m);
    return 0;
}


Measured memory_bytes: 9216
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll A;
  cin>>A;
  string B;
  cin>>B;
  string BB;
  for(int i=0;i<B.size();++i) {
    if(B[i]=='.') continue;
    BB += B[i];
  }
  ll BBB = stoi(BB);
  cout<<A*BBB/100<<endl;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
string solve() {
	var(string, s, t);
	map<char, char> mst, mts;
	rep(i, 0, len(s)) {
		if (mst.find(s[i]) == mst.end()) {
			mst[s[i]] = t[i];
		} else  if (mst[s[i]] != t[i]) {
			return "No";
		}
		if (mts.find(t[i]) == mts.end()) {
			mts[t[i]] = s[i];
		} else if (mts[t[i]] != s[i]){
			return "No";
		}
	}
	return "Yes";
}
int main() {
	print(solve());
	return 0;
}


Measured memory_bytes: 916
#include<stdio.h>
#include<math.h>
int main()
{
    int x,y,n;
    scanf("%d %d",&x,&y);
    n = (x+y)/2;
    if (sqrt(pow(x-n,2))!=sqrt(pow(y-n,2)))
    {
        printf("IMPOSSIBLE");
    }
    else
    {
        printf("%d",n);
    }
    
   
}

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

int main(){
	ll n,a,b,c,d;scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
	rep(i,n){
		if(a+c*i-d*(n-i-1)<=b&&b<=a+d*i-c*(n-i-1)){puts("YES");return 0;}
	}
	puts("NO");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
#define MOD 1e9 + 7
#define N 1e5 + 10
bool cmp(ll a,ll b)
{
	return (a>b);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll a,b,c;
	cin>>a>>b>>c;
	vector<ll> v;
	ll x=__gcd(a,b);
	ll i=0,count=0;
	for(i=1;i<=100;i++)
	{
		if(a%i==0 and b%i==0)
		{
			v.pb(i);
		}
	}
	sort(v.begin(),v.end(),cmp);
	cout<<v[c-1];
}	

Measured memory_bytes: 256
import java.util.Scanner;

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

        int correct = 1;
        int wrong = 0;
        for (int i = 0; i < n; i++) {
            final int a = scanner.nextInt();
            if (a == correct) {
                correct++;
            } else {
                wrong++;
            }
        }

        if (correct == 1) {
            System.out.println(-1);
        } else {
            System.out.println(wrong);
        }
    }
}


Measured memory_bytes: 66404
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

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

    cout << min(int(B / A), C) << endl;

}

Measured memory_bytes: 256
/*input
2
3 4
3
500 300 200
5
138 138 138 138 138
*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define is_empty(v) v.empty()
#define vs			vector< string >
#define vvi			vector< vector< ll,ll > >
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define inf         1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define reprr(i,a,b) for(ll int i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define sum(v)      accumulate(v.begin(),v.end(),(ll)0)
//map <long long int,long long int> ma;
//set <long long int, greater <long long int> > s;


int solve()
{
	ll n;cin>>n;
	vi a(n);
	rep(i,0,n) cin>>a[i];
	sort(a.begin(), a.end());
	double last=a[0];
	rep(i,1,n)
		last = (last+a[i])/2;
	printf("%.6f\n",last);
}

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

	ll t=1;
	// cin>>t;
	while(t--)
		solve();
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int n, x[105], y[105];
double mx, z[105], PI = acos(-1.0);
int main() {
	int i, j, k;
	scanf("%d", &n);
	for(i=0; i<n; i++) scanf("%d%d", &x[i], &y[i]);
	for(i=0; i<n; i++) {
		for(j=k=0; j<n; j++) if(i!=j) z[k++] = atan2(y[j]-y[i], x[j]-x[i]);
		sort(z, z+k);
		mx = z[0] - z[k-1] + 2*PI ;
		for(j=1; j<k; j++) mx = max(mx, z[j] - z[j-1]);
		printf("%.9f\n", max(0., (mx-PI)/2./PI));
	}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
typedef long long ll;

using namespace std;



int main() {
    int n, a, b;
    cin>>n>>a>>b;
    cout<<min(n*a, b)<<endl;

    return 0;
}

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

using lli = long long;
using pii = pair<int, int>;
using pll = pair<lli, lli>;
using Double = long double;
template<typename T>
using Vector = vector<vector<T>>;
template<typename T>
using Prior = priority_queue<T>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;

#define IOS() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define X first
#define Y second
#define Push push_back
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()

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

	lli a = 1, b = 1, c, d;
	while (n--) {
		cin >> c >> d;
		if (c < d) {
			a = (a - 1) / c * c + c;
			if (b <= a / c * d) b = a / c * d;
			else {
				b = (b - 1) / d * d + d;
				a = b / d * c;
			}
		}
		else {
			b = (b - 1) / d * d + d;
			if (a <= b / d * c) a = b / d * c;
			else {
				a = (a - 1) / c * c + c;
				b = a / c * d;
			}
		}
		// cout << "NOW: " << a << ", " << b << "\n";
	}

	cout << a + b << "\n";
}

int main() {
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

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

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

int main() {
	int n;
	cin>>n;
	int h[n+1];
	for(int i=1;i<=n;i++)cin>>h[i];
	
	int dp[n+1];
	dp[0]=0;dp[1]=0;
	dp[2]=abs(h[2]-h[1]);
	for(int i=3;i<=n;i++){
	    dp[i]=minimum(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2]);
	    //cout<<dp[i]<<" ";
	}
	
	cout<<dp[n]<<endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

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

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}



int main(){
    int n,k;
    cin >> n >> k;
    int a[n];
    rep(i,n) cin >> a[i];
    n-=k;
    k--;
    int ans = 1;
    ans+=(n/k);
    if(n%k!=0){
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
import sys


def solve(N: int):
    from math import ceil
    return int(ceil(N / 1000) * 1000) - N


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    print(solve(N))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


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

int cmp(const void *a,const void *b){
  return *(int *)a-*(int *)b;
}

int gcd(int a,int b){
  if(b==0) return a;
  int r=a%b;
  while(r>0){
    a=b;b=r;r=a%b;
  }
  return b;
}

void run(void){
  int n,k;
  scanf("%d%d",&n,&k);
  int *a=(int *)calloc(n,sizeof(int));
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  qsort(a,n,sizeof(int),cmp);
  int g=a[0];
  for(i=1;i<n;i++) g=gcd(g,a[i]-a[i-1]);
  if(k<=a[n-1] && k%g==0){
    puts("POSSIBLE");
  } else {
    puts("IMPOSSIBLE");
  }
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 892
import sys
input = sys.stdin.readline
ri = lambda: int(input())
#rl = lambda: [int(x) if x.isdecimal() else x for x in input().split()]
#rl = lambda: list(input().split()))
rl = lambda: map(int,input().split())
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7

N = ri()
D = list(rl())
D.sort()
print(D[N//2]-D[N//2-1])

Measured memory_bytes: 14016
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
template<class T> 
inline void read(T& x)
{
	char c = getchar(); T p = 1, n = 0;
	while(c < '0' || c > '9'){if(c == '-') p = -1; c = getchar();}
	while(c >= '0' && c <= '9'){n = n * 10 + c - '0'; c = getchar();}
	x = p * n;
}
template<class T, class U>
inline void read(T& x, U& y){read(x), read(y);}
template<class T, class U, class V>
inline void read(T& x, U& y, V& z){read(x), read(y), read(z);}
int main()
{
	long long n, a, b; read(n, a, b);
	if(a > b)
	{
		puts("0"); return 0;
	}
	if(n == 1 && a != b)
	{
		puts("0"); return 0;
	}
	long long ans = a + b * (n - 1) - b - a * (n - 1) + 1;
	printf("%lld\n", max(ans, 0ll));
	return 0;	
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define int long long
#define ll long long
#define pp pair<int,int>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int max(int x, int y)
{
    return x>y ? x : y;
}
int min(int x, int y)
{
    return x<y ? x : y;
}
void _(int&a , int b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
ll n,m,q;vector<ll> a[50];
ll cl(ll a,ll b)
{
    return (a/b)+(!(!(a%b)));
}
ll ans=-1;
void dfs(ll i,ll j,vector<ll> v)
{
    if(j==n)
    {
        ll dans=0;
        // for (int u = 0; u < v.size(); ++u)
        // {
        //     cout << v[u] << " ";
        // }
        // cout << "\n";
        for (int u = 0; u < q; ++u)
        {
            if(v[a[u][1]] -v[a[u][0]]==a[u][2])dans+=a[u][3];
        }
        ans=max(ans,dans);
        return ;
    }
    for(int u=i;u<=m;u++)
    {
        vector<ll> v1=v;v1.push_back(u);
        dfs(u,j+1,v1);
    }

}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> m >> q;
    for (int i = 0; i < q; ++i)
    {
        ll u1,u2,u3,u4;cin  >> u1 >> u2 >> u3 >> u4;u1--;u2--;/*u3--;u4--;*/
        a[i].push_back(u1);a[i].push_back(u2);
        a[i].push_back(u3);a[i].push_back(u4);
    }vector<ll> v;
    dfs(1,0,v);
    cout << ans;
    }

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    vector<ll> l(n);
    rep(i,n) cin>>l[i];
    ll res=0;
    sort(l.begin(),l.end());
    rep(i,n)rep(j,n){
        if(i>=j)continue;
        if(l[i]==l[j])continue;
        ll buf=l[i]+l[j];
        for(int k=j+1;k<n;k++){
            if(l[i]==l[k]||l[j]==l[k])continue;
            if(l[k]<buf){
                res++;
                //cout<<i+1<<" "<<j+1<<" "<<k+1<<endl;
                //cout<<l[k]<<" "<<buf<<endl;
            }
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <set>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(n);++i)

using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;

Graph G;
queue<int> q;
vector<int> d;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	G.assign(N, vector<Edge>());
	REP(i, N - 1) {
		int u, v, w;
		cin >> u >> v >> w;
		--u, --v;
		G[u].push_back(Edge(v, w));
		G[v].push_back(Edge(u, w));
	}

	q.push(0);
	d.assign(N, -1);
	d[0]=0;
	while (!q.empty()) {
		int f = q.front(); q.pop();
		for (auto v : G[f]) {
			if (d[v.first] == -1) {
				d[v.first] = (v.second+d[f])%2;
				q.push(v.first);
			}
		}
	}
	for (auto v : d) {
		cout << v<< endl;
	}
	return 0;
}

Measured memory_bytes: 6784
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define fi first
#define se second
#define mk make_pair
using namespace std;
int n,m,y,x;
vector<int>v[200001];
bool b[200001];
void dfs(int p,int d){
  if(d==2)return;
  r(i,v[p].size()){
    if(!b[v[p][i]]){
      b[v[p][i]]=1;
      dfs(v[p][i],d+1);
    }
  }
}
main(){
  cin>>n>>m;
  r(i,m){
    cin>>x>>y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1,0);
  if(b[n])cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 12144
#!/usr/bin/env python3
import sys

def main():
    import itertools
    input = sys.stdin.readline
    _ = int(input())
    l = list(map(int, input().split()))
    ans = 0
    for i in itertools.combinations(l, 3):
        if len(set(i)) == 3 and abs(i[0] - i[1]) < i[2] < i[0] + i[1]:
            ans += 1
    print(ans)




if __name__ == '__main__':
    main()


Measured memory_bytes: 73944
#include <iostream>

using namespace std;


typedef struct{
  int f,b,t,u,r,l;
}_sai;

void dice(_sai* tmp,char muki){
  int b1=(*tmp).f,b2=(*tmp).b,b3=(*tmp).t,b4=(*tmp).u,b5=(*tmp).r,b6=(*tmp).l;
  if(muki=='S'){
    (*tmp).u=b1;
    (*tmp).f=b3;
    (*tmp).t=b2;
    (*tmp).b=b4;
  }
  else if(muki=='N'){
    (*tmp).t=b1;
    (*tmp).b=b3;
    (*tmp).u=b2;
    (*tmp).f=b4;
  }
  //  int b1=(*tmp).f,b2=(*tmp).b,b3=(*tmp).t,b4=(*tmp).u,b5=(*tmp).r,b6=(*tmp).l;
  else if(muki=='E'){
    (*tmp).r=b3;
    (*tmp).u=b5;
    (*tmp).l=b4;
    (*tmp).t=b6;
  }
  else if(muki=='W'){
    (*tmp).l=b3;
    (*tmp).u=b6;
    (*tmp).r=b4;
    (*tmp).t=b5;
  }


}

int main(){
  _sai s;
  string x;
  cin>> s.t>> s.f>> s.r>> s.l>> s.b>> s.u>>x;

  for(int i=0; i<(int)x.size(); i++){
    dice(&s,x[i]);
  }
  cout << s.t<<endl;
  return 0;
}



Measured memory_bytes: 3204
#include <iostream>
#include <string>
int n;

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

constexpr int MAXN = 100;
unsigned int A, B;

int main() {
    std::cin >> A >> B;
    int cnt = 0;
    for (unsigned int i = A; i <= B; i++) {
        unsigned int u = i % 100;
        unsigned int k = (u / 10) + (u % 10) * 10;
        if ((i/1000) == k) {
            cnt++;
        }
    }
    std::cout << cnt << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 300001
vector<vector<int>>dp;
int func(vector<int>&v, int i, int j)
{
    if(i>j)
    return 0;
    if(dp[i][j]!=-1)
    return dp[i][j];
    dp[i][j]=0;
    return dp[i][j]=max(v[i]+min(func(v,i+2,j),func(v,i+1,j-1)),v[j]+min(func(v,i,j-2),func(v,i+1,j-1)));
}
void solve()
{
    int n; cin>>n;
    vector<int> v(n);int sum=0;
    for(int i=0;i<n;i++)
    cin>>v[i],sum+=v[i];
    dp.resize(n+1,vector<int>(n+1,-1));
    int comp=func(v,0,n-1);
    cout<<comp-(sum-comp);
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1;
    while(test--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 70912
fun gcd(a: Int, b: Int): Int =
        when (b) {
            0 -> a
            else -> gcd(b, a % b)
        }

fun main(args: Array<String>) {
    readLine()
            ?.split(regex = """\s+""".toRegex())
            ?.map { it.toInt() }
            ?.toIntArray()
            ?.let { println(gcd(it[0], it[1])) }
}


Measured memory_bytes: 31332