akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

int main(){
	int A,B;
	cin >> A >> B;

	if(A-B*2>0){
		cout << A-B*2 << endl;
	}else{
		cout << "0" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  long long sum=0;
  sum=accumulate(a,a+k,0);
  cout<<sum<<endl;
  
  return 0;
}

Measured memory_bytes: 3636
/* it was worth becoming a chemist */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "puts"
#define F first
#define S second

const db EPS = (db) 1e-9;
const int inf = 1e9;
const ll INF = 1e18;
const int mod = 1e6 + 3;
const int MAXN = 2e5 + 5;

int main() {
	//freopen(NAME".in", "r", stdin);
	//freopen(NAME".out", "w", stdout);


	ios_base::sync_with_stdio(0);
	cin.tie(0);            	
	cout.tie(0);
	cout << setprecision(6) << fixed;

	string s = "";
	for (char i = 'a'; i <= 'z'; i++) {
		s += i;
	}
	s = s + s;
	
	int n;
	string t;
	cin >> n >> t;
	
	for (int i = 0; i < sz(t); i++) {		
		if (t[i] + n <= 'Z') t[i] += n;
		else {
			int x = n;
			x -= ('Z' - t[i] + 1);
			t[i] = 'A';
			t[i] += x;
		}
	}
	cout << t;
	return 0;	
}    


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	int a,b,c, t, n;
	while(cin >> a >> b >> c, a + b + c !=0){
		vector<int> h;
		vector<int> p;
		queue< vector<int> > que;
		p.push_back(-1);
		for(int i = 0; i < a + b + c; i++)
			p.push_back(2);
		cin >> n;
		for(int i = 0; i < n; i++){
			h.clear();
			cin >> a >> b >> c >> t;
			if(t == 1){
				p[a] = p[b] = p[c] = 1;
			}
			else{
				h.push_back(a);
				h.push_back(b);
				h.push_back(c);
				h.push_back(t);
				que.push(h);
			}
		}
		while(!que.empty()){
			a = que.front()[0];
			b = que.front()[1];
			c = que.front()[2];
			
			if(p[a] == 2 && p[b] == 1 && p[c] == 1)
				p[a] = 0;
			if(p[a] == 1 && p[b] == 2 && p[c] == 1)
				p[b] = 0;
			if(p[a] == 1 && p[b] == 1 && p[c] == 2)
				p[c] = 0;
			
			que.pop();
		}
		for(int i = 1; i < p.size(); i++)
			cout << p[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1276
#include<stdio.h>
#include<algorithm>
using namespace std;
struct work{
	long long u;
	long long l;
}a[200005];
bool cmp(work a,work b)
{
	return a.l<b.l;
}
int main()
{
	long long n,i,d,j;
	while(~scanf("%lld",&n))
	{int w=0;
	 long long sum=0;
	 for(i=0;i<n;i++)
	 {scanf("%lld%lld",&a[i].u,&a[i].l);
	 }
	 sort(a,a+n,cmp);
	 for(i=0;i<n;i++)
	 {sum+=a[i].u;
	  if(sum>a[i].l){w=1;break;}
	 }
	if(w==1)printf("No\n");
	else printf("Yes\n");
	}
}

Measured memory_bytes: 3328
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int m = n * 3;
        long[] a = new long[m];
        for (int i = 0; i < m; i++) {
            a[i] = scanner.nextInt();
        }
        PriorityQueue<Long> queue = new PriorityQueue<>();
        long[] max = new long[n + 1];
        long sum = 0;
        for (int i = 0; i < m; i++) {
            queue.add(a[i]);
            if (i >= n && i <= n * 2) {
                max[i - n] = sum;
                sum -= queue.poll();
            }
            sum += a[i];
        }

        queue = new PriorityQueue<>(Comparator.reverseOrder());
        long[] min = new long[n + 1];
        sum = 0;
        for (int i = m; i > 0; i--) {
            queue.add(a[i - 1]);
            if (i >= n && i <= n * 2) {
                min[i - n] = sum;
                sum -= queue.poll();
            }
            sum += a[i - 1];
        }
        long ans = Long.MIN_VALUE;
        for (int i = 0; i <= n; i++) {
            ans = Math.max(ans, max[i] - min[i]);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 100532
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

LL gcd(LL x,LL y){
	if(y==0)	return x;
	else	return gcd(y,x%y);
}
LL lcm(LL x,LL y){
	return x*y/gcd(x,y);
}

LL A[100000];

int main(void){
    int N;
    LL K;
    cin>>N>>K;
    REP(i,N)
        cin>>A[i];
    sort(A,A+N);
    LL d=gcd(A[0],A[1]);
    REP(i,N)
        d=gcd(d,A[i]);
    REP(i,N)
        if(A[i]>=K && (A[i]-K)%d==0){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
    cout<<"IMPOSSIBLE"<<endl;
     return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}

int n, m;
priority_queue<int> pq;

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

    cin >> n >> m;
    for (int i=0; i<n; i++) {
        int a;
        cin >> a;
        pq.push(a);
    }

    for (int i=0; i<m; i++) {
        int x = pq.top();
        pq.pop();
        x /= 2;
        pq.push(x);
    }

    ll ans = 0LL;
    while (!pq.empty()) {
        ans += pq.top();
        pq.pop();
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 892
N = gets.to_i
As = gets.split.map(&:to_i)

l,r = 0,0
xor,sum =As[0],As[0]
ans = 0
flag = false

loop do
    break if (r == N)
    if (r != 0)
        if flag
            xor ^= As[r]
            sum += As[r]
        else
            xor ^= As[l-1]
            sum -= As[l-1]
        end
    end

    if xor == sum
        flag = true
        ans += r - l + 1
        r = r + 1
    else
        flag = false
        l = l + 1
    end
end

puts ans


Measured memory_bytes: 16420
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc072
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');

            int X = int.Parse(str[0]);
            int t = int.Parse(str[1]);
            if (X - t < 0)
            {
                Console.WriteLine(0);
            }else
            {
                Console.WriteLine(X - t);
            }
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFL = 1LL<<60;

int count(string s) {
  set<char> a;
  for (char c : s) a.insert(c);
  return a.size();
}

int calc(string s, char t) {
  int n = 0;
  while (count(s) > 1) {
    n++;
    rep(i, s.size()-1) {
      if (s[i+1] == t) s[i] = t;
    }
    s.pop_back();
  }
  return n;
}

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

  string s;
  cin >> s;

  int ans = INF;

  for (char c = 'a'; c <= 'z'; c++) {
    if (s.find(c) == string::npos) continue;
    chmin(ans, calc(s, c));
  }

  cout << ans << endl;

  return 0;
}


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

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a % 2 != 0 && b % 2 != 0){
	cout << "Yes" << endl;
  }
  else{
	cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int h,w;
    cin >> h >> w;
    char a[h][w];
    REP(i,h){
        REP(j,w)cin >> a[i][j];
    }
    bool change=true;
    bool end = false;
    while(!end){
        end = true;
        REP(i,h){
            change = true;
            REP(j,w){
                if(!(a[i][j] == '.' || a[i][j] == ',')){
                    change = false;
                }
            }
            if(change){
                end = false;
                REP(j,w){
                    a[i][j]=',';
                }
            }
        }
        REP(i,w){
            change = true;
            REP(j,h){
                if(!(a[j][i] == '.' || a[j][i] == ',')){
                    change = false;
                }
            }
            if(change){
                end = false;
                REP(j,h){
                    a[j][i] = ',';
                }
            }
        }
        end = true;
    }
   
    bool flag;
    REP(i,h){
        flag = false;
        REP(j,w){
            if(a[i][j]!=','){
                cout << a[i][j];
                flag = true;
            }
        }
        if(flag)
        cout << endl;
    }
    

    return 0;
}

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

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int s,w;
    cin >> s >> w;
    string ans = w >= s ? "unsafe" : "safe";
    cout << ans;
}









Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
long long int n;
int main()
{
    cin>>n;
    for(int i=sqrt(n);i>=1;i--)
    {
        if(n%i==0){
            int t=i,l=n/i;
            int s=1;
            while(l>=10){
                s++;
                l/=10;
            }
        cout<<s;
        return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int mod = 1e9 + 7;

typedef vector<vector<long long>> mat;

mat mat_mul(mat A, mat B) {
  int H = A.size();
  int W = B[0].size();
  int K = A[0].size();

  mat C(H, vector<ll>(W, 0));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      for (int k = 0; k < K; k++) {
        (C[i][j] += A[i][k] * B[k][j]) %= mod;
      }
    }
  }
  return C;
}

void pow_mat (mat &dp, mat &A, ll k){
  while (k) {
    if (k & 1) dp = mat_mul(dp, A);
    A = mat_mul(A, A);
    k >>= 1;
  }
}

int main() {
  int n;
  ll k;
  cin >> n >> k;
  mat A(n, vector<ll>(n)), dp(n, vector<ll>(n, 0));
  rep(i,n) rep(j,n) cin >> A[i][j];
  rep(i,n) dp[i][i] = 1;
  pow_mat(dp, A, k);
  int res = 0;
  rep(i,n) rep(j,n) (res += dp[i][j]) %= mod;
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 3700
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#define MN 100005
using namespace std;
typedef long long ll;
int n,x[MN],y[MN];ll ans,res;bool vis[MN];
struct node{
	int x,id;
	friend bool operator<(node x,node y){return x.x>y.x;}	
};
struct node2{
	int x,id;
	friend bool operator<(node2 x,node2 y){return x.x<y.x;}
};
priority_queue<node>q0;
priority_queue<node2>q1;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&x[i],&y[i]);
		q1.push((node2){x[i],i}),q0.push((node){y[i],i});
	}int nxt,now;
	ans+=abs(q0.top().x);nxt=1;now=q0.top().x;
	vis[q0.top().id]=1;q0.pop();
	while(1){
		if(nxt==0){
			while((!q0.empty())&&vis[q0.top().id])q0.pop();
			if(q0.empty()||now<=q0.top().x)break;
			ans+=abs(now-q0.top().x),now=q0.top().x;vis[q0.top().id]=1;q0.pop();
		}
		else{
			while((!q1.empty())&&vis[q1.top().id])q1.pop();
			if(q1.empty()||now>=q1.top().x)break;
			ans+=abs(now-q1.top().x),now=q1.top().x;vis[q1.top().id]=1;q1.pop();
		} 
		nxt^=1;
	}res=max(res,ans+abs(now));ans=0;
	while(!q0.empty())q0.pop();while(!q1.empty())q1.pop();memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;i++)q1.push((node2){x[i],i}),q0.push((node){y[i],i});
	ans+=abs(q1.top().x);nxt=0;now=q1.top().x;
	vis[q1.top().id]=1;q1.pop();
	while(1){
		if(nxt==0){
			while((!q0.empty())&&vis[q0.top().id])q0.pop();
			if(q0.empty()||now<=q0.top().x)break;
			ans+=abs(now-q0.top().x),now=q0.top().x;vis[q0.top().id]=1;q0.pop();
		}
		else{
			while((!q1.empty())&&vis[q1.top().id])q1.pop();
			if(q1.empty()||now>=q1.top().x)break;
			ans+=abs(now-q1.top().x),now=q1.top().x;vis[q1.top().id]=1;q1.pop();
		} 
		nxt^=1;
	}res=max(res,ans+abs(now));
	printf("%lld\n",res);
}



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

typedef long long ll;
typedef pair<ll,int> P;
ll const INF = INT64_MAX;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

struct edge {
    ll w;int u;int v;
    bool operator<(const edge& a) const {
        return w < a.w;
    }
};

struct SegmentTree {
private:
    int n;
    vector<P> node;
public:
    SegmentTree(vector<P> v) {
        int sz = v.size();
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2*n-1,P(INF,-1));
        for (int i = 0;i < sz;++i) node[i+n-1] = v[i];
        for (int i = n-2;i >= 0;--i) node[i] = min(node[2*i+1],node[2*i+2]);
    }

    void update(int x,P val) {
        x += (n-1);
        node[x] = val;
        while (x > 0) {
            x = (x-1)/2;
            node[x] = min(node[2*x+1],node[2*x+2]);
        }
    }

    P getmin(int a,int b,int k = 0,int l = 0,int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return P(INF,-1);
        if (a <= l && r <= b) return node[k];
        P vl = getmin(a,b,2*k+1,l,(l+r)/2);
        P vr = getmin(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
};

struct UnionFind {
private:
    vector<int> par,depth;
public:
    UnionFind (int n) {
        par.resize(n);
        depth = vector<int>(n,0);
        for (int i = 0;i < n;++i) par[i] = i;
    }

    int find(int x) {
        if (par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x,int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (depth[x] < depth[y]) par[x] = y;
        else {
            par[y] = x;
            if (depth[x] == depth[y]) depth[x]++;
        }
    }

    bool same(int x,int y) {
        return find(x) == find(y);
    }
};


int main() {
    int n;
    ll d,ans = 0;
    cin >> n >> d;
    vector<ll> a(n);
    vector<P> b;
    vector<edge> edgelist;
    SegmentTree segL(vector<P>(n,P(INF,-1))),segR(vector<P>(n,P(INF,-1)));
    UnionFind kruskal(n);
    
    for (int i = 0;i < n;++i) cin >> a[i];
    for (int i = 0;i < n;++i) b.push_back(P(a[i],i));

    sort(b.begin(),b.end());

    for (P p : b) {
        int i = p.second;
        P mnL = segL.getmin(0,i),mnR = segR.getmin(i,n);
        if (mnL.first < INF) {
            int j = mnL.second;
            edgelist.push_back(edge{a[i]+a[j]+(ll)(i-j)*d,i,j});
        }
        if (mnR.first < INF) {
            int j = mnR.second;
            edgelist.push_back(edge{a[i]+a[j]+(ll)(j-i)*d,i,j});
        }
        segL.update(i,P(a[i]+(ll)(n-i)*d,i));
        segR.update(i,P(a[i]+(ll)i*d,i));
    }

    sort(edgelist.begin(),edgelist.end());
    for (edge e : edgelist) {
        if (kruskal.same(e.u,e.v)) continue;
        ans += e.w;
        kruskal.unite(e.u,e.v);
    }
    cout << ans << endl;
    return 0;
}

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


int main(){
  int a,b;
  cin >> a >>b;
  if(a ==1){
    a = 100;
  }
  if(b ==1){
    b = 100;
  }
  if(a<b){
    cout <<"Bob" << endl;
  }
  else if(a == b){
    cout << "Draw" << endl;
  }
  else{
    cout <<"Alice" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long
#define rep(i, a, b) for(ll i = (ll)a; i < (ll)b; i++)
using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a+b < c+d) cout << "Right\n";
  else if(a+b > c+d) cout << "Left\n";
  else cout << "Balanced\n";
}

Measured memory_bytes: 3604
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
if b > a:
    av = a + v * t
    bw = b + w * t
    
    if av >= bw:
        print("YES")
    else:
        print("NO")
else:
    av = a - v * t
    bw = b - w * t

    if av <= bw:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9200
from itertools import accumulate

n, k = list(map(int, input().split()))
p = [0] + list(accumulate([(int(d) + 1) / 2 for d in input().split()]))

ans = 0
for i in range(k, n+1):
    ans = max(ans, p[i] - p[i-k])

print(ans)

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

int main()
{
    long long n,i,q,ans[100000],x;
    cin>>n;
    long long a[n];
    for (i = 0; i <= 100000; i++) ans[i]=0;
    for (i = 0; i < n; i++)
    {
        cin>>a[i];
        ans[a[i]]++;
    }
    x=0;
    for (i = 0; i <= 100000; i++) x+=i*ans[i];
    cin>>q;
    long long b[q],c[q];
    for (i = 0; i < q; i++)
    {
        cin>>b[i]>>c[i];
        x+=(c[i]-b[i])*ans[b[i]];
        cout<<x<<endl;
        ans[c[i]]+=ans[b[i]];
        ans[b[i]]=0;
    }
}

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

using namespace std;

using P = pair<long, long>;

struct edge {int i, j; long d;};

struct uftree {
    int *par, *rank, *size;
    uftree(int N) {
        par = new int[(size_t)N];
        rank = new int[(size_t)N];
        size = new int[(size_t)N];
        for (int i = 0; i < N; i++) {
            par[i]  = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
    int root(int x) {
        if (par[x] == x)
            return x;
        else {
            int r         = root(par[x]);
            size[x]       = size[par[x]];
            return par[x] = r;
        }
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] > rank[y])
            par[y] = x;
        else {
            par[x] = y;
            if (rank[x] == rank[y]) rank[y]++;
        }
        size[x] += size[y];
        size[y] = size[x];
    }
    int getsize(int x) {
        root(x);
        return size[x];
    }
    bool same(int x, int y) { return root(x) == root(y); }
};

int main() {
    int n;
    cin >> n;
    P cities[n];
    for (auto &c: cities) cin >> c.first >> c.second;
    vector<int> xrank(n), yrank(n);
    iota(xrank.begin(), xrank.end(), 0);
    iota(yrank.begin(), yrank.end(), 0);
    sort(xrank.begin(), xrank.end(), [&](int l, int r) {
        return cities[l].first < cities[r].first;
    });
    sort(yrank.begin(), yrank.end(), [&](int l, int r) {
        return cities[l].second < cities[r].second;
    });
    vector<edge> es;
    int prev = -1;
    for (auto xr:xrank) {
        if (prev >= 0) {
            long d = cities[xr].first - cities[prev].first;
            es.push_back({prev, xr, d});
        }
        prev = xr;
    }
    prev = -1;
    for (auto yr:yrank) {
        if (prev >= 0) {
            long d = cities[yr].second - cities[prev].second;
            es.push_back({prev, yr, d});
        }
        prev = yr;
    }
    sort(es.begin(), es.end(), [](edge l, edge r) {
        return l.d < r.d;
    });
    uftree uft(n);
    long sum = 0;
    for (auto e:es) {
        if (uft.same(e.i, e.j)) continue;
        uft.unite(e.i, e.j);
        sum += e.d;
    }
    cout << sum << '\n';
    return 0;
}

Measured memory_bytes: 8688
#include <stdio.h>

int main(void){

   int cards[128][14] = {{0}};

   int i, n, num;

   char c;

   scanf("%d", &n);

   for(i = 0; i < n; i++) {

   scanf("%c", &c);

   scanf("%c %d", &c, &num);

   cards[c][num] = 1;  }

   for(i = 1; i <= 13; i++) {

       if(cards['S'][i] == 0) {

           printf("S %d\n", i);

       }

   }

   for(i = 1; i <= 13; i++) {

       if(cards['H'][i] == 0) {

           printf("H %d\n", i);

       }

   }

   for(i = 1; i <= 13; i++) {

       if(cards['C'][i] == 0) {

           printf("C %d\n", i);

       }

   }

   for(i = 1; i <= 13; i++) {

       if(cards['D'][i] == 0) {

           printf("D %d\n", i);

       }

   }

}


Measured memory_bytes: 2144
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0

for i in range (A+1):
    for p in range(B+1):
        for q in range(C+1):
            if i*500 + p*100 + q*50 == X:
                cnt += 1

print(cnt)            



Measured memory_bytes: 3060
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n, i; cin >> n >> i;
    cout << n - i + 1 << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

typedef pair<int, vector<int> > P;

void dfs() {

}

int main(void) {
  int n, m, x;
  cin >> n >> m >> x;
  vector<P> tbl(n);
  rep(i, n) {
    cin >> tbl[i].first;
    rep(j, m) {
      tbl[i].second.resize(m);
      cin >> tbl[i].second.at(j);
    }
  }

  int end = (1 << n);

  vector<int> buy(n);

  int mn = INT_MAX;

  for (int i = 0; i < end; i++) {
    for (int j = 0; j < n; j++) {
      buy[j] = i & (1 << j);
    }

    vector<int> sum(m, 0);
    int cost = 0;
    for (int j = 0; j < n; j++) {
      if (buy[j]) {
        for (int k = 0; k < m; k++) {
          sum[k] += tbl[j].second.at(k);
        }
        cost += tbl[j].first;
      }
    }

    bool upx = true;
    for (int j = 0; j < m; j++) {
      if (sum[j] < x) {
        upx = false;
      }
    }

    if (upx) {
      mn = min(mn, cost);
    }
  }

  cout << (mn == INT_MAX ? -1 : mn) << endl;

  return 0;
}


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

char g[107][107];

void fill( char c ) {
	for ( int i = 0; i < 107; i++ ) {
		for ( int j = 0; j < 107; j++ ) {
			g[i][j] = c;
		}
	}   
}

int main() {
	//freopen("out.txt", "w", stdout);
	int a, b;
	cin >> a >> b;
	if ( a == 1 && b == 1 ) {
		cout << "2 2\n";
		cout << "#.\n";
		cout << "..";
		return 0;
	}
	if ( a >= b ) {
		fill( '.' );
		int cnt = 0, ind = 0;
		for ( int j = 2; j <= 99; j += 2 ) {
			for ( int i = 2; i <= 98; i += 2 ) {
				if ( cnt == a - 1 ) {
					break;
				}
				g[i - 1][j] = '#';
				g[i - 1][j + 1] = '#';
				g[i][j + 1] = '#';
				g[i + 1][j] = '#';
				g[i + 1][j + 1] = '#';
				cnt++;
				if ( j == 2 )
					ind = i + 1;
			}
		}
		for ( int i = 1; i <= ind; i++ ) {
			g[i][1] = '#';
		}
		b--;
		for ( int i = 1; i <= 100; i++ ) {
			for ( int j = 1; j <= 100; j++ ) {
				if ( !b ) break;
				if ( g[i - 1][j - 1] != '#' && g[i - 1][j] != '#' &&
					g[i - 1][j + 1] != '#' && g[i][j - 1] != '#' &&
					g[i][j] != '#' && g[i][j + 1] != '#' && g[i + 1][j - 1] != '#' &&
					g[i + 1][j] != '#' && g[i + 1][j + 1] != '#' ) {
					g[i][j] = '#';
					b--;
				}
			}
			if ( !b ) break;
		}
	}
	else {
		fill( '#' );
		int cnt = 0, ind = 0;
		for ( int j = 2; j <= 99; j += 2 ) {
			for ( int i = 2; i <= 98; i += 2 ) {
				if ( cnt == b - 1 ) {
					break;
				}
				g[i - 1][j] = '.';
				g[i - 1][j + 1] = '.';
				g[i][j + 1] = '.';
				g[i + 1][j] = '.';
				g[i + 1][j + 1] = '.';
				cnt++;
				if ( j == 2 )
					ind = i + 1;
			}
		}
		for ( int i = 1; i <= ind; i++ ) {
			g[i][1] = '.';
		}
		a--;
		for ( int i = 1; i <= 100; i++ ) {
			for ( int j = 1; j <= 100; j++ ) {
				if ( !a ) break;
				if ( g[i - 1][j - 1] != '.' && g[i - 1][j] != '.' &&
					g[i - 1][j + 1] != '.' && g[i][j - 1] != '.' &&
					g[i][j] != '.' && g[i][j + 1] != '.' && g[i + 1][j - 1] != '.' &&
					g[i + 1][j] != '.' && g[i + 1][j + 1] != '.' ) {
					g[i][j] = '.';
					a--;
				}
			}
			if ( !a ) break;
		} 
	}
	cout << "100 100\n";
	for ( int i = 1; i <= 100; i++ ) {
		for ( int j = 1; j <= 100; j++ ) {
			cout << g[i][j];
		}
		cout << '\n';
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a,a1,a2,a3,i,sum=0,avg=0;
	while(1){
		cin>>a;
		if(a==0) break;
		for(i=0;i<a;i++){
			cin>>a1>>a2>>a3;
			sum=a1+a2+a3;
			avg=sum/3;
			if(a1==100||a2==100||a3==100||avg>=80||(a1+a2)/2>=90)
				printf("A\n");
			else if(avg>=70||avg>=50&&a1>=80||avg>=50&&a2>=80)
				printf("B\n");
			else
				printf("C\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
int main() {
  ll n,m;
  cin >> n >> m;
  vl a(m),b(m);
  rep(i,m){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  vl x(n,0),y(n,1);
  x[0]=1;
  rep(i,m){
    y[b[i]]++;
    y[a[i]]--;
    if(x[a[i]]==1){
      x[b[i]]=1;
    }
    if(y[a[i]]==0){
      x[a[i]]=0;
    }
  }
  ll sum=0;
  rep(i,n){
    sum +=x[i];
  }
  cout << sum << endl;
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int adj[100][100];
int ans = 0;
int used[100];
int n, m;

void dfs(int i, int cnt){
	if(cnt == n){
		ans++;
		return;
	}

	for(int j=0; j<n; j++){
		if(adj[i][j] == 1 && used[j] != 1){
			used[j] = 1;
			dfs(j, cnt+1);
			used[j] = 0;
		}
	}

}

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	cin >> n >> m;

	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			adj[i][j] = 0;
		}
	}

	for(int i=0; i<m; i++){
		int t1, t2;
		cin >> t1 >> t2;
		t1--;
		t2--;
		adj[t1][t2] = adj[t2][t1] = 1;
	}

	used[0] = 1;
	dfs(0, 1);

	cout << ans << endl;
	
	return 0;
}


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

int main() {
long long int H, W;
 cin >> H >> W;
  
  if (H == 1 || W == 1){
   cout << 1 << endl;
  }
  
  else if (H * W % 2 == 0){
   cout << H * W / 2 << endl;
  }
  
  else{
   cout << (H * W + 1) / 2 << endl;
  }
}

Measured memory_bytes: 256
using System;
using System.Text;

namespace atc
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = new Solve();
            s.Exe();
            Console.ReadLine();
        }
    }
    
    class Solve
    {
        public void Exe()
        {
            int k = int.Parse(Console.ReadLine());
            const string acl = "ACL";
            var ret = new StringBuilder();
            for (int i = 0; i < k; i++)
            {
                ret.Append(acl);
            }
            Console.WriteLine(ret.ToString());
        }
    }
}


Measured memory_bytes: 27256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

using namespace std;

int gcd(int n, int m) {
    if (n == 0)
        return m;
    return gcd(m % n, n);
}

int bit_count(int i) {
    i = i - ((i >> 1) & 0x55555555);
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
    i = (i + (i >> 4)) & 0x0f0f0f0f;
    i = i + (i >> 8);
    i = i + (i >> 16);
    return i & 0x3f;
}

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    if (b <= a) {
        cout << "delicious" << endl;
    } else if (b <= a + x) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int tot;
struct trie{
	int ch[26],t[26];
}tr[N<<2];
int cnt[26];
void extend(string id){
	for(int i=0;i<='z'-'a';++i) cnt[i]=0;
	int n=id.size();
	for(int i=0;i<n;++i) cnt[id[i]-'a']++;
	int p=0;
	for(int i=0;i<n;++i){
		for(int j=0;j<='z'-'a';++j)
			tr[p].t[j]+=(cnt[j]>0);
		if(!tr[p].ch[id[i]-'a']) tr[p].ch[id[i]-'a']=++tot;
		p=tr[p].ch[id[i]-'a'];
		cnt[id[i]-'a']--;
	}
}
int query(string id){
	int n=id.size(),p=0;
	if(n==1) return tr[0].t[id[0]-'a'];
	for(int i=0;i<n-1;++i){
		if(!tr[p].ch[id[i]-'a']) return 0;
		p=tr[p].ch[id[i]-'a']; 
		//cout<<p<<" "<<id[i]-'a'<<endl;
	}
	return tr[p].t[id[n-1]-'a'];
}
void Reverse(string &s){
	int i=0,j=s.size()-1;
	while(i<j) swap(s[i],s[j]),++i,--j;
}
string id[N];
int main(){
	int n,len;
	cin>>n;long long ans=0;
	for(int i=1;i<=n;++i){
		cin>>id[i];
		Reverse(id[i]);
		extend(id[i]);
	}
	for(int i=1;i<=n;++i)
		ans+=query(id[i]);
	cout<<ans-n;
	return 0;
}

Measured memory_bytes: 239088
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
using namespace std;

const int INF=12345678;
int n,par,dist[100005];
vector<int> nei[100005],v;
queue<int> q;

void DFS(int x,int pr){
	dist[x]=1;
	v.push_back(x);
	if(x==n-1){
		par=v[(v.size()+1)/2];
		//return;
	}
	for(int i=0;i<nei[x].size();i++){
		int now=nei[x][i];
		if(pr==now) continue;
		DFS(now,x);
		dist[x]+=dist[now];
	}
	v.pop_back();
}

int main(){
	cin>>n;
	for(int i=0;i<n-1;i++){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		nei[x].push_back(y);
		nei[y].push_back(x);
	}
	par=-1;
	DFS(0,0);
	if(dist[par]*2<n) puts("Fennec");
	else puts("Snuke");
	return 0;
}

Measured memory_bytes: 11256
s=input()
K=int(input())
N=len(s)
L=set()
for i in range(N+1):
    for j in range(i,i+K+1):
        #print(s[i:j])
        L.add(s[i:j])
ans=sorted(list(L))
ans.remove('')
print(ans[K-1])

Measured memory_bytes: 39792
def main(): 
    N = [int(_) for _ in input().split()]
    A = N[0]
    B = N[1]
    C = N[2]
    K = N[3]

    result = 0
    if A >= K:
        print(K)
        return
    if A < K:
        K = K - A
        result = A
    if B >= K:
        print(result)
        return
    if B < K:
        K = K - B
    if C >= K:
        result = result - K
        print(result)
        return
    if C < K:
        result = result - C
        print(result)
        return

if __name__ == "__main__":
    main()


Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
int n,k;
int w[100010];
int cnt=1,tmp=0;
int c=1;

bool ok(int P){
  cnt=1;
  tmp=0;
  for(int i=0;i<n;i++){
    if(w[i]>P){
      cnt = k+1;
      break;
    }
    tmp += w[i];
    //cout << "tmp:" << tmp << endl;
    //cout << "cnt:" << cnt << endl;
    if(tmp>P){
      i--;
      cnt++;
      tmp=0;
    }
  }
  if(cnt<=k)return true;
  else return false;
}

int main(){
  cin >> n >> k;
  for(int i=0;i<n;i++){
    cin >> w[i];
  }
  //if(ok(12)) cout << "true" << endl;
  long long l=0,h=1000000000000;
  while(l+1<h){
    int m=(l+h)/2;
    if(ok(m)==1)h=m;
    else l=m;
    //cout << "l" << c << "::" << l << endl;
    //cout << "h" << c << "::" << h << endl;
    c++;
  }
  cout << h << endl;

}



Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	ll ans = 1;
	FOR(i,0,n){
		ll k;
		cin >> k;
		ans = lcm(ans,k);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3236
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <cstring>
#include <string>
#include <math.h>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repp(i, m, n) for(int i = m; i < (int)n; i++)
#define reps(i, n) for(int i = 1; i <= (int)n; i++)
#define pb push_back
const int    INF = 100000000;
const double EPS = 1e-10;
const long long MOD = 998244353;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;

ll kaijo[300010], inv[300010];

ll beki(ll a, ll b)
{
	if(b==0) return 1;
	else if(b%2==0)
	{
		ll tmp=beki(a, b/2);
		return (tmp*tmp)%MOD;
	}
	else return (beki(a, b-1)*a)%MOD;
}

ll inv_(ll a)
{
	return beki(a, MOD-2);
}

ll comb(ll a, ll b)
{
	return (kaijo[a]*inv[b])%MOD*inv[a-b]%MOD;
}


int main()
{
	ll n, a, b, k;
	cin >> n >> a >> b >> k;

	kaijo[0]=1;
	inv[0]=1;
	reps(i, n)
	{
		kaijo[i]=((ll)kaijo[i-1]*(ll)i)%MOD;
		inv[i]=inv_(kaijo[i]);
	}

	ll ans=0;

	rep(i, n+1)
	{
		ll t=k-(ll)i*a;
		if(t>=0 && t%b==0 && t/b<=n)
		{
			ll tt=comb(n, (ll)i)*comb(n, t/b)%MOD;
			ans=(ans+tt)%MOD;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
import numpy as np
A = list(map(int,input().split()))
B = []
N = A[0]
D = A[1]
while len(B) < N:
    B.append(list(map(int,input().split())))
k,l = 0,1
count = 0
while k < N - 1:
    while l < N:
        dis = 0
        for _ in range(D):
            dis += (B[k][_] - B[l][_]) ** 2
        if int(np.sqrt(dis)) == np.sqrt(dis):
            count += 1
        l += 1
    k += 1
    l = k + 1
print(count)  
    


Measured memory_bytes: 12468
MOD = 10 ** 9 + 7

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

csum_invs = [0]
t = 0
for i in range(1, n + 1):
    t += pow(i, MOD - 2, MOD)
    t %= MOD
    csum_invs.append(t)
# print(csum_invs)

fact = []
t = 1
for i in range(1, n + 1):
    t *= i
    t %= MOD
    fact.append(t)
# print(fact)

ans = 0
for i in range(n):
    # print(i)
    t = a[i] * (csum_invs[n - i] + csum_invs[i + 1] - 1)
    t %= MOD
    ans += t

ans *= fact[-1]
ans %= MOD

print(ans)

'''
逆元の求め方: フェルマーの小定理
    a ** (-1) ≡ a ** (p - 2) (mod p)
    b / a ≡ b * a **(p - 2)
    だから、/ a をしたければ、* a ** (p -2) をすればよい
'''

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


def main():
    args = input().split()
    N = int(args[0])
    A = int(args[1])
    B = int(args[2])

    counter = 0
    for i in range(1, N + 1):
        sumValue = sum(list(map(lambda x: int(x), list(str(i)))))
        if sumValue >= A and sumValue <= B:
            counter += i

    print(counter)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define MAX 100007
typedef pair< int,int > ii;
int n;
int a[MAX];
vector< ii > v;

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
		v.push_back(ii(a[i]-1,2));
		v.push_back(ii(a[i]+2,1));
	}
	sort(v.begin(),v.end());

	int x=a[0],xv=1, cv=0;
	
	for(int i=0;i<v.size();i++){
		ii tmp=v[i];
		if(tmp.second==2)cv++;
		else {
			if(cv>=xv){
				x=tmp.first-1;
				xv=cv;
			}
			cv--;
		}
	}
	if(cv>=xv){
		x=v[v.size()].first-1;
		xv=cv;
	}
	printf("%d\n",xv);
}


Measured memory_bytes: 2676
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    A_odd = A[1::2]
    A_even = A[0::2]
    dict_odd = {-1:0}
    dict_even = {-1:0}
    for i in A_odd :
        if i not in dict_odd :
            dict_odd[i] = 1
        else:
            dict_odd[i] += 1
    for i in A_even :
        if i not in dict_even :
            dict_even[i] = 1
        else:
            dict_even[i] += 1
    dict_odd  = sorted(dict_odd.items(), key = lambda x : x[1],reverse=True)
    dict_even = sorted(dict_even.items(), key=lambda x: x[1], reverse=True)

    if dict_even[0][0] != dict_odd[0][0] :
        max_odd = dict_odd[0][1]
        max_even = dict_even[0][1]
        print(N - max_even - max_odd)
    else:
        if dict_odd[0][1] > dict_even[0][1]:
            max_odd = dict_odd[0][1]
            max_even = dict_even[1][1]
            print(N - max_even - max_odd)
        elif dict_even[0][1] > dict_odd[0][1] :
            max_odd = dict_odd[1][1]
            max_even = dict_even[0][1]
            print(N - max_even - max_odd)
        else:
            max_odd = max(dict_even[1][1],dict_odd[1][1])
            print(N - dict_even[0][1] - max_odd)
            
            


if __name__ == '__main__':
    main()

Measured memory_bytes: 20192
n, a, b = map(int, input().split())
t_ans = 0

for i in range(1, n+1):
    i = str(i)
    ans = 0
    for j in range(len(i)):
        ans += int(i[j])
    if a <= ans and ans <= b:
        t_ans += int(i)
print(t_ans)

Measured memory_bytes: 40812
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((int64_t *)a) < *((int64_t *)b) ? -1 : 1;
}

int compare_f2(const void *a, const void *b) {
	return *((uint64_t *)a) > *((uint64_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
	uint64_t result = 1;

	for (uint64_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

int main(void) {
	char s[101];

	scanf("AtCoder %s Contest", s);

	printf("A%cC", s[0]);

	return 0;
}


Measured memory_bytes: 128
def is_prime(num):
    if num < 2:
        return False
    elif num == 2:
        return True
    elif num % 2 == 0:
        return False

    from math import sqrt
    sqrtnum = sqrt(num)
    i = 3
    while (i <= sqrtnum):
        if num % i == 0:
            return False
        i += 2
    return True

X = int(input().rstrip())

while True:
    if is_prime(X):
        print(X)
        break
    X += 1

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
bool vis[20];
bool check(int x){
    while(x){
        if(vis[x%10])
            return 0;
        x/=10;
    }
    return 1;
}
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=k;i++){
        int x;
        scanf("%d",&x);
        vis[x]=1;
    }
    for(int i=n;;i++){
        if(check(i)){
            printf("%d\n",i);
            return 0;
        }
    }
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] A = new int[N + 1];
		
		for(int i = 1; i <= N; i++) {
			A[i] = sc.nextInt();
		}
		
		int[] L = new int[N + 1];
		int[] R = new int[N + 1];
		L[0] = A[1];
		R[0] = A[N];
		
		for(int i = 1; i <= N; i++) {
			L[i] = gcd(L[i - 1], A[i]);
			R[i] = gcd(R[i - 1], A[N - i + 1]);
		}
		
		int max = 0;
		L[0] = A[2];
		R[0] = A[N - 1];
		
		for(int i = 0; i <= N - 1; i++) {
			max = Math.max(gcd(L[i], R[N - i - 1]), max);
		}
		System.out.println(max);
	}
	
	public static int gcd(int a, int b) {
		int c = 0;
		if(b == 0) {
			return a;
		}
		if(b > a) {
			c = a;
			a = b;
			b = c;
		}
		return gcd(b, a % b);
	}
	
}


Measured memory_bytes: 52004
/*
   * * * * *       *        * * * * * * * * * * * * * * * * * * * * * * * *     * * * * * * *               * *               * * * * * * * * * *
   * * * * *      * *       * * * * * * * * * * * * * * * * * * * * * *    *    * * * * * * *              * * *             * ** * * * * * * * * *
   * *           * * *            * *     * *     * *      * *          * * *   * * *       *             * * * *           * * * *       * *    * *
   * * * * *    * * * *           * *     * *     * *       * * * * * * *  * *  * * * * * * *            * * * * *         * *  * *       * * * * *
   * * * * *   * * * * *          * *     * *     * *        * * * * ** *   * * * * * * * * *           * * * * * *       * *   * * * *   * * * *
         * *  * * * * * *   * *   * *     * *     * *       * * * * * * *    * ** *     * * *          * * * * * * *     * *    * * * *   * *  * *
         * * * *       * *  * *   * *     * *     * *      * *          *     * * *     * * *         * *       * * *   * *     * *       * *   * *
   * * * * ** *         * * * * * * * * * * * * * * * * * * * * * * * * *      *  * * * * * * * * * ** *         * * * * *      * * * * * * *    * *
   * * * * * *           * ** * * * * * * * * * * * * * * * * * * * * * *       * * * * * * * * * * * *           * * * *       * * * * * * *     * *
*/

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <set>
#define ll long long
using namespace std;

ll dp[1000005],A[1000005]={-1,1,-1,3,-1,-1,-1,1,-1,9,-1};
int main()
{
    ios::sync_with_stdio(0);
    ll n,sum=0,a=7;
    cin>>n;
    char s[]="7";
    if(n<=10)
    {
        cout<<A[n];
        return 0;
    }
    while(!dp[a])
    {
        if(!a)
        {
            cout<<sum+1;
            return 0;
        }
        dp[a]=1;
        a=(a*10+7)%n;
        sum++;
    }
    cout<<-1;

    return 0;
}


Measured memory_bytes: 11032
//実装が重そうな問題はある程度考えてから書く
//初期化を忘れずに（特に二分探索とか）
//コーナーケースを考えて（特に場合分けとか）
#include <bits/stdc++.h>
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int LL
#define zero 0LL
using namespace std;
template<typename T> inline void maximize(T &a,T b){a=max(a,b);}
template<typename T> inline void minimize(T &a,T b){a=min(a,b);}
template<typename T> inline bool middle(T a,T b,T c){return b<=a && a<=c;}
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
inline void outputVI(VI x){REP(i,SI(x)){cout << three(i," ","") << x[i];}OUT("");}
const int SIZE1=1e6+1000;
const int SIZE2=2010;
const int SIZE3=400;
const int SIZE=SIZE1;
const LL p=7+1e9;
const LL INF=1LL<<60;
const long double EPS=1e-7;
string s;
ut N,M,K,X,L,Y,D;

signed main(){
	VI A(3);
	REP(i,3) cin >>A[i];
	int maxim=MAX(A);
	int sum=0;
	REP(i,3) sum+=A[i];
	int need=(maxim*3-sum);
	if(need%2==0) cout << need/2 << endl;
	else cout << need/2+2 << endl; 
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>
#include<numeric>

using namespace std;

int n,m,q;
long long ans[505][505];

int main(){
  cin>>n>>m>>q;
  for(int i=0;i<m;i++){
    int x,y;cin>>x>>y;
    x--;y--;
    ans[x][y]++;
  }

  for(int i=1;i<n;i++){
    ans[n-1][i] += ans[n-1][i-1];
  }
  for(int i=n-2;i>=0;i--){
    ans[i][0] += ans[i+1][0];
  }
  for(int i=n-2;i>=0;i--){
    for(int j=1;j<n;j++){
      ans[i][j] = ans[i][j] + ans[i+1][j] + ans[i][j-1] - ans[i+1][j-1];
    }
  }

  for(int i=0;i<q;i++){
    int x,y;cin>>x>>y;
    x--;y--;
    cout<<ans[x][y]<<endl;
  }
  return 0;
}

Measured memory_bytes: 2944
q=input()
x=[int(i) for i in input().split()]
cnt=input()
y=[int(i) for i in input().split()]

if max(x) >= max(y):
    MAX=max(x)
else:
    MAX=max(y)

dic = {}

for k in x :
    if k in dic.keys() :
        dic[k] += 1
    else :
        dic[k] = 1
    
for i in y :
    if i in dic.keys() :
        dic[i] -= 1
        if dic[i] == -1 :
            print('NO')
            exit()
    else :
        print('NO')
        exit()
print('YES')


Measured memory_bytes: 41816