akhauriyash/Code-Regression huggingface dataset:
use std::cmp;

fn main() {
    let mut sc = Scanner::new();
    let n = sc.usize_read();
    let m = sc.usize_read();
    let a: Vec<Vec<usize>> = (0..n)
        .map(|_| (0..m).map(|_| sc.usize_read() - 1).collect())
        .collect();

    let mut ans = n;
    let mut dead = vec![false; m];
    loop {
        let mut count = vec![0; m];
        for a in &a {
            for &a in a {
                if dead[a] {
                    continue;
                }
                count[a] += 1;
                break;
            }
        }

        let max = *count.iter().max().unwrap();
        if max == 0 {
            break;
        }
        ans = cmp::min(ans, max);
        for (i, &a) in count.iter().enumerate() {
            if a == max {
                dead[i] = true;
            }
        }
    }

    println!("{}", ans);
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn usize_read(&mut self) -> usize {
        self.read()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


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

int main(){
    int64_t n;
    cin >> n;
    int64_t a[100010];
    int64_t ans = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        ans += a[i]-1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int preT=0;
        int preX=0;
        int preY=0;

        for(int i=0;i<N;i++){
            int postT=sc.nextInt();
            int postX=sc.nextInt();
            int postY=sc.nextInt();

            int dt=postT-preT;
            int dist=Math.abs(postX-preX)+Math.abs(postY-preY);
            if((dt<dist)||(dist-dt)%2!=0){
                System.out.println("No");
                return;
            }

            preT=postT;
            preX=postX;
            preY=postY;
        }

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

Measured memory_bytes: 86444
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

struct UnionFind{
	vector<int> par, ran, setSize;
	UnionFind(int n){
		init(n);
	}
	void init(int n){
		par.resize(n + 1);ran.resize(n + 1);setSize.resize(n + 1);
		for(int i = 0; i <= n; i++)par[i] = i, ran[i] = 0, setSize[i] = 1;
	}
	int head(int v){
		if(v == par[v])return v;
		return par[v] = head(par[v]);
	}
	bool unite(int u, int v){
		u = head(u);
		v = head(v);
		if(u != v){
			if(ran[u] < ran[v])swap(u, v);
			par[u] = v;
			setSize[u] += setSize[v];
			if(ran[u] == ran[v])ran[u]++;
			return true;
		}
		return false;
	}
	bool isSame(int u, int v){
		return par[head(u)] == par[head(v)];
	}
};

int main(){
	FIO
	
	int n, q;
	cin >> n >> q;
	UnionFind DSU(n);
	while(q--){
		int op, u, v;
		cin >> op >> u >> v;
		if(op == 0){
			DSU.unite(u, v);
		}else {
			if(DSU.isSame(u, v))cout << "1\n";
			else cout << "0\n";
		}
	}
	return 0;
}



Measured memory_bytes: 3332
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    int N, K;
    cin >> N >> K;
    if (K == 1)cout << 0 << endl;
    else cout <<N-K << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    vector<pll> G[20];
    REP(i, N){
    	ll A;
    	cin >> A;
    	REP(j, A){
    		ll x, y;
    		cin >> x >> y;
    		x--;
    		G[i].push_back({x, y});
    	}
    }

    ll M = (1ll<<N);
    ll res = 0;
    REP(mask, M){
    	//dump(mask)
    	bool ok = true;
    	REP(i, N){
    		if(mask>>i & 1){
    			REP(j, G[i].size()){
    				ll hito = G[i][j].first;
    				ll doti = G[i][j].second;
    				if((mask>>hito & 1) != doti) ok = false;
    			}
    		}
    	}
    	if(ok){
    		ll tmp = __builtin_popcountll(mask);
    		res = max(res, tmp);
    	}
    	//dump(ok)
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <climits>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define fish        push_front
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Deque       std::deque
#define PQueue      std::priority_queue
#define Set         std::set
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define HashMap     std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm   ( A x,  B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    inline boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    int S, ans;

    signed call_of_Cthulhu( signed datum ) {

        String s;
        read s;
        for ( int i = 0; i < s.size(); i++ ) {
            if ( s[i] == 'T' ) {
                if ( S ) {
                    ans += 2;
                    S--;
                }
            }
            else {
                S++;
            }
        }

        echo s.size()-ans fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


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

int main(){
  string s,t;
  cin >> s >> t;
  
  size_t length =t.length();
  char x = t[length - 1];
  if(t == s + x){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3612
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
const LL INF = (1LL << 31) - 1;
const LL MOD = 1000000007LL;
using namespace std;
struct SegTree {
	LL *val;
	LL *lazy;
	int N;
	SegTree(int n) {
		N = 1;
		while (N < n) {
			N *= 2;
		}
		val = new LL[2 * N - 1];
		lazy = new LL[2 * N - 1];
		rep(i, 2 * N - 1) {
			val[i] = INF;
			lazy[i] = -1;
		}
	}
	void eval(int k) {
		if (lazy[k] != -1) {
			val[k] = lazy[k];
			if (k < N - 1) lazy[2 * k + 1] = lazy[k], lazy[2 * k + 2] = lazy[k];
		}
		lazy[k] = -1;
	}
	void update_q(int a, int b, LL x, int k, int l, int r) {
		eval(k);
		if (r <= a || b <= l) return;
		if (a <= l&&r <= b) {
			lazy[k] = x;
			eval(k);
			return;
		}
		if (k < N - 1) {
			update_q(a, b, x, k * 2 + 1, l, (l + r) / 2);
			update_q(a, b, x, k * 2 + 2, (l + r) / 2, r);
			val[k] = min(val[2 * k + 1], val[2 * k + 2]);
		}
	}
	LL min_q(int a, int b, int k, int l, int r) {
		eval(k);
		if (r <= a || b <= l) return INF;
		if (a <= l&&r <= b) return val[k];
		return min(min_q(a, b, k * 2 + 1, l, (l + r) / 2), min_q(a, b, k * 2 + 2, (l + r) / 2, r));
	}
};
int main() {
	int n, q;
	cin >> n >> q;
	SegTree S(n);
	rep(i, q) {
		int type;
		cin >> type;
		if (type) {
			int s, t;
			cin >> s >> t;
			cout << S.min_q(s, t + 1, 0, 0, S.N) << endl;
		}
		else {
			int s, t, x;
			cin >> s >> t >> x;
			S.update_q(s, t + 1, x, 0, 0, S.N);
		}
	}
}

Measured memory_bytes: 7176
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
 
using namespace std;

string S; 
typedef long long ll;
ll dp[30];

string num(int s,int e){
  string x="";
  for(int i=s; i<=e; i++){
    x=x+S[i]; 
  }
  return x;
}

int main(){
 
cin>>S;

int sz=S.size();

for(int i=sz-1; i>=0; i--){
 for(int j=i; j<=sz-1; j++){
 	ll add=atoll(num(i,j).c_str());
 	if(sz-1-j>=1) dp[sz-i]+=add*(1<<sz-2-j)+dp[sz-1-j];
 	else dp[sz-i]+=add;
 }
}

cout<<dp[sz]<<endl;

return 0;
 
}

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

int main()
{
    int n, a, b, n2;
    cin >> n;
    n2 = n;
    cin >> a >> b;
    for (int i = 1;; i++) {
        n = n2;
        n = n * i;
        if (a <= n && n <= b) {
            cout << "OK" << endl;
            return 0;
        }
        if (n > b) break;
    }
    cout << "NG" << endl;
}


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

using namespace std;

using int64 = long long;
const int64 INF = 1LL << 60;

int main() {
  int64 N, M, A[50], B[50], C[50], D[50];
  cin >> N >> M;
  for(int i = 0; i < N; i++) cin >> A[i] >> B[i];
  for(int i = 0; i < M; i++) cin >> C[i] >> D[i];
  for(int i = 0; i < N; i++) {
    int64 near = INF;
    for(int j = 0; j < M; j++) {
      near = min(near, abs(A[i] - C[j]) + abs(B[i] - D[j]));
    }
    for(int j = 0; j < M; j++) {
      if(near == abs(A[i] - C[j]) + abs(B[i] - D[j])) {
        cout << j + 1 << endl;
        break;
      }
    }
  }
}



Measured memory_bytes: 256
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n  =sc.nextInt();
      int k = sc.nextInt();
      long m = 0;
      long s = 0;
      m = (long)n/k;
      if(k%2==0){
        s = (long)(n+k/2)/k;
      }
      System.out.println(m*m*m+s*s*s);
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}


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

int main() {
	int n; cin >> n;
	vector<pair<int, int>> lim;

	for (int i = 0; i < n; i++) {
		pair<int, int> buf;
		cin >> buf.second >> buf.first;
		lim.push_back(buf);
	}
	sort(lim.begin(), lim.end());

	bool poss = true;
	long long p = 0;
	for (int i = 0; i < lim.size(); i++) {
		p += lim[i].second;
		if (lim[i].first < p) {
			poss = false; break;
		}
	}

	cout << (poss ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 2420
#include <cstdio>

bool query(long long x){
	printf("? %lld\n",x);
	fflush(stdout);
	char s[10];
	scanf("%s",s);
	return s[0]=='Y';
}

int main(){
	long long X=1000000000;
	for (;!query(X);X/=10);
	if (X==1000000000)
		for (X=1;!query(X+1);X*=10);
	else{
		int l=X/10,r=X-1;
		if (!r) X=10;
		else
		for (;l<=r;){
			int mid=(l+r)>>1;
			if (query(mid)) X=mid*100ll,l=mid+1;
				else r=mid-1;
		}
		for (;!query(X);X+=10);
		X/=10;
	}
	printf("! %lld\n",X);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 504
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        n: u64,
        m: u64,
        mut a: [u64; n],
    }

    a.sort();
    a.reverse();
    let sum: u64 = a.iter().sum();
    let ans = if 4 * m * a[(m - 1) as usize] >= sum {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}


Measured memory_bytes: 2160
r, g, b, n = map(int, input().split())
x, y, z = sorted([r, g, b])

count=0
for i in range(0, n+x, x):
    for j in range(i, n+y, y):
        res = n-j
        if res%z == 0:
            count += 1
print(count)


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

int debug = 0;

int main()
{
    int n, k;
    vector<ll> h;
    ll tmp;
    cin >> n >> k;
    rep(i,n){
        cin >> tmp;
        h.push_back(tmp);
    }

    sort(h.begin(), h.end(), greater<ll>());

    ll sum=0;
    for (int i = k; i < n;++i){
        sum += h[i];
    }

    cout << sum << endl;
}

Measured memory_bytes: 2420
#include<stdio.h>
#include<algorithm>
#include<set>
using namespace std;
int dx[]={-2,-2,-2,-1,-1,-1,0,0,0};
int dy[]={-2,-1,0,-2,-1,0,-2,-1,0};
pair<int,int> f[1100000];
long long ret[10];
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int sz=0;
	for(int i=0;i<c;i++){
		int p,q;scanf("%d%d",&p,&q);
		p--;q--;
		for(int j=0;j<9;j++){
			int tx=p+dx[j];
			int ty=q+dy[j];
			if(tx>=0&&ty>=0&&tx<a-2&&ty<b-2){
				f[sz++]=make_pair(tx,ty);
			}
		}
	}
	std::sort(f,f+sz);
	int cnt=0;
	for(int i=0;i<sz;i++){
		if(i&&(f[i].first!=f[i-1].first||f[i].second!=f[i-1].second)){
			ret[cnt]++;
			cnt=1;
		}else{
			cnt++;
		}
	}
	if(sz)ret[cnt]++;
	long long cur=0;
	for(int i=0;i<10;i++)cur+=ret[i];
	ret[0]=(long long)(a-2)*(b-2)-cur;
	for(int i=0;i<10;i++)printf("%lld\n",ret[i]);
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
const long long INF =10000000;
typedef pair<int,int> P;
      
int main() {
  int N,Q;
  cin >> N >>Q;
  string S;
  cin >> S;
  
  vector<int> s(N+1,0);
  for(int i = 0;i<N;i++){
    if(S[i] == 'A' && S[i+1] == 'C' && i+1<N) s[i+1] = s[i] + 1;
    else s[i+1] = s[i];
  }
  for (int q = 0; q < Q; ++q) {
        int l, r; cin >> l >> r;
        // 0-indexed にする
        cout << s[r-1] - s[l-1] << endl;
    }
}

Measured memory_bytes: 1408
from collections import Counter
n = int(input())
A = [int(i) for i in input().split()]
A1 = Counter(A[::2]).most_common()
A2 = Counter(A[1::2]).most_common()

if A1[0][0] == A2[0][0]:
    if len(A1) == 1 and len(A2) == 1:
        ans = n // 2
    elif len(A1) == 1 and len(A2) != 1:
        ans = n // 2 - A2[1][1]
    elif len(A1) != 1 and len(A2) == 1:
        ans = n // 2 - A1[1][1]
    else:
        temp1 = n - A1[0][1] - A2[1][1]
        temp2 = n - A1[1][1] - A2[0][1]
        ans = min(temp1, temp2)
else:
    if len(A1) == 1 and len(A2) == 1:
        ans = 0
    elif len(A1) == 1 and len(A2) != 1:
        ans = n // 2 - A2[0][1]
    elif len(A1) != 1 and len(A2) == 1:
        ans = n // 2 - A1[0][1]
    else:
        ans = n - A1[0][1] - A2[0][1]
        
print(ans)

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

#define MOD (1000000000+7)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define nl '\n'
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i > (b); i--)
#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];
#define debug(x) cerr << #x << " = " << (x) << endl;

// template starts
typedef long long int ll;
// template ends here
//#define endl '\n'

const int MAXN = 200005;
int key[MAXN];

int get_key(int k){
	while(k != key[k]) k = key[k];
	return k;
}

void join(int k1, int k2){
	int g1 = get_key(k1), g2 = get_key(k2);
  	if(rand()%2) key[g1] = g2;
  	else key[g2] = g1;
}
void solve(){
	int N, Q;
  	cin >> N >> Q;
  	while(Q--){
		int t, u, v;
      	cin >> t >> u >> v;
      	if(t == 0) join(u,v);
      	else cout << (get_key(u) == get_key(v)) << "\n";
    }
}

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

int main(){
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	//startTime = clock();
	srand(time(0));
	int T;
    for(int i = 1; i < MAXN; i++) key[i] = i;
	//cin >> T;
	T = 1;
    while(T--){
		solve();
	}
	
	//cout << getCurrentTime() << endl;
	return 0;
}


Measured memory_bytes: 4400
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

#[allow(dead_code)]
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn input<T: FromStr>(&mut self) -> T {
        self.read().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let a: i64 = sc.input();
    let b: i64 = sc.input();
    let c: i64 = sc.input();
    let x: i64 = sc.input();
    let y: i64 = sc.input();

    let mut ans = c * std::cmp::max(x * 2, y * 2);
    for z in 0..std::cmp::max(x * 2, y * 2) {
        let na = if x > z / 2 { x - z / 2 } else { 0 };
        let nb = if y > z / 2 { y - z / 2 } else { 0 };
        ans = std::cmp::min(ans, a * na + b * nb + c * z);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    a=int(input())
    b=int(input())
    c=int(input())
    x=int(input())

    cnt=0
    for i in range(a+1):
        for j in range(b + 1):
            for k in range(c + 1):
                if 500*i+100*j+50*k==x:
                    cnt+=1
    print(cnt)

resolve()

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <set>
#include <iterator>

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

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

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

    rep(i ,n + 1) {
        for (int j = 0; j < n - i + 1; ++j) {
            if (i * 10000 + j * 5000 + (n-i-j) * 1000 == y) {
                cout << i << " " << j << " " << n-i-j << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    string Z;
    cin >> Z;
    int A = int(Z[0])-48, B = int(Z[1])-48, C = int(Z[2])-48, D = int(Z[3])-48;
    int sum = A, ans;
    for(int i=0;i<(1<<3);i++){
        sum = A;
        for(int j=0;j<3;j++){
            if( 1<<j & i ) sum += int(Z[j+1])-48;
            else sum -= int(Z[j+1])-48;
        }
        if (sum == 7){
            ans = i;
            break;
        }
        //cout << i << ' '<<sum <<endl;
    }
    char pm[3];
    for(int i=0;i<3;i++){
        if( ans & 1<<i ) pm[i] = '+';
        else pm[i] = '-';
    }
    cout << A << pm[0] <<B<<pm[1]<<C<<pm[2]<<D<<"=7"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define MOD (int)(1000000007)
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N,M; cin >> N >> M; ll ans = 1;
    if(abs(N-M)>1) cout << 0 << endl;
    else if(N==M){
        rep(i,N){
            ans=ans*(i+1)%MOD;
        }
        rep(i,M){
            ans=ans*(i+1)%MOD;
        }
        ans=ans*2%MOD;
        cout << ans << endl;
    }
    else {
        rep(i,N){
            ans=ans*(i+1)%MOD;
        }
        rep(i,M){
            ans=ans*(i+1)%MOD;
        }
        cout << ans << endl;   
    }
   
    return 0;
}

Measured memory_bytes: 256
k = int(input())
listA = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(listA[k-1])

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;

typedef long long LL;
#define lowbit(x) ((x)&(-x))
#define INF 0x3f3f3f3f
#define memset(a,b) memset(a,b,sizeof(a))
#define	GE() printf(">----------\n")
#define	IN() freopen("in.txt","r",stdin)
#define	OUT() freopen("out.txt","w",stdout)
const int mod=1000000007;
const LL inf=0x3f3f3f3f3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-8;
const int maxn=105;

LL one(LL x, LL y){
    LL tmp=inf, a, b, c;
    if(x>=3){
        c=x%3;
        a=(x-c)/3;
        if(c==0){
            return 0;
        }
        else if(c==1){
            a++;b=(x-a)/2;
        }
        else if(c==2){
            a++;b=x-a*2;
        }
        tmp=min(tmp, abs(a*y-b*y));
    }
    return tmp;
}

LL two(LL x, LL y){
    LL tmp=inf, a, b, c, d, mx, mn;
    a=x/2;
    b=x-a;
    c=y/2;
    d=y-c;
    mx=max(max(a*y, b*c), b*d);
    mn=min(min(a*y, b*c), b*d);
    while(a&&mx-mn<tmp){
        tmp=mx-mn;
        a--;
        b++;
        mx=max(max(a*y, b*c), b*d);
        mn=min(min(a*y, b*c), b*d);
    }
    return tmp;
}

int main()
{
    int x, y;
    while(~scanf("%d%d", &x, &y)){
        LL ans=inf;
        ans=min(ans, one(x, y));
        ans=min(ans, one(y, x));
        ans=min(ans, two(x, y));
        ans=min(ans, two(y, x));
        printf("%lld\n", ans);
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cstring>

using namespace std;
using ll = long long;
using pint = pair<int, int>;

ll INF = 1LL << 60;

int main() {
	int N;
	cin >> N;
	vector<int> A(N), B(N), C(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> B[i];
	for (int i = 0; i < N; i++) cin >> C[i];
	sort(A.begin(), A.end());
	sort(C.begin(), C.end());

	ll count = 0;
	for (int i = 0; i < N; i++) {
		count += (lower_bound(A.begin(), A.end(), B[i]) - A.begin())
			* (C.end() - upper_bound(C.begin(), C.end(), B[i]));
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 4576
package main

import "fmt"

func rot(s string) (t string){
  t = ""
  for _, r := range s {
    t = string(r) + t
  }
  return
}

func main(){
  var s1, s2 string
  fmt.Scan(&s1, &s2)
  if rot(s1) == s2{
    fmt.Println("YES")
  }else{
    fmt.Println("NO")
  }
}

    

Measured memory_bytes: 512
N, K, L = [int(_) for _ in input().split()]


def find(a, x):
    stack = []
    while a[x] != x:
        stack += [x]
        x = a[x]
    while stack:
        a[stack.pop()] = x
    return x


def unite(a, x, y):
    x = find(a, x)
    y = find(a, y)
    if x != y:
        a[x] = min(x, y)
        a[y] = a[x]


a_road = [i for i in range(N)]
for _ in range(K):
    p, q = [int(_) - 1 for _ in input().split()]
    unite(a_road, p, q)
a_railway = [i for i in range(N)]
for _ in range(L):
    r, s = [int(_) - 1 for _ in input().split()]
    unite(a_railway, r, s)
memo = {}
for i in range(N):
    memo[a_road[i], a_railway[i]] = memo.get(
        (find(a_road, i), find(a_railway, i)), 0) + 1

print(' '.join(str(memo[a_road[i], a_railway[i]]) for i in range(N)))


Measured memory_bytes: 55052
#include<bits/stdc++.h>
#define int long long 
#define mod 1000000007 
using namespace std ;

int32_t main(){

	 ios::sync_with_stdio(false) ; cin.tie(NULL) ; 
	 
	 
	int n;
	cin>>n;
	int r=n%10;
	if(r==2||r==4||r==5||r==7||r==9)
	cout<<"hon";
	if(r==0|| r==1||r==6||r==8)
	cout<<"pon";
	if(r==3)
	cout<<"bon";
	return 0;



}

Measured memory_bytes: 3604
// AOJ 2924 City
// 2019.4.7 bal4u

#include <stdio.h>

int main()
{
	int h, w, s, t;
	char *a[] = { "Yes", "No" };
	scanf("%d%d%d%d", &h, &w, &s, &t);
	puts(a[(h & 1) & (w & 1) & ((s + t) & 1)]);
	return 0;
}



Measured memory_bytes: 2144
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  int H,N;
  cin>>H>>N;
  VI A(N),B(N);
  rep(i,N) cin>>A[i]>>B[i];
  VL dp(20010);
  rep(i,20009) dp[i+1]=1e9;
  rep(i,N){
    rep(j,20010){
      if(j>=A[i]) dp[j]=min(dp[j],dp[j-A[i]]+B[i]);
    }
  }
  ll ans=1e9;
  rep(i,20010) if(i>=H and dp[i]!=1e9) ans=min(ans,dp[i]);
  cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>

using namespace std;


int main() {
	long long A, B, C, K;

	cin >> A >> B >> C >> K;

	long long ans = A - B;


	if (K % 2 == 0) {
		cout << ans << endl; 
	} else {
		cout << -ans << endl; 
	}

	return 0;

}

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

int main(){
#define int ll
  int a,b; cin >> a >> b;
  int c = b - a;
  int h = (1 + c) * c / 2;
  cout << h - b << endl;
}

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

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

int a, b;
int n;
int maze[22][22];
int x, y;
int dp[22][22];

int main()
{
  while(cin >> a >> b, a){
    rep(i, a) rep(j, b) maze[i][j] = false;
    rep(i, a) rep(j, b) dp[i][j] = 0;
    cin >> n;
    rep(i, n){
      cin >> x >> y;
      maze[x - 1][y - 1] = true;
    }

    dp[0][0] = 1;
    rep(i, a) rep(j, b){
      if(!maze[i + 1][j]) dp[i + 1][j] += dp[i][j];
      if(!maze[i][j + 1]) dp[i][j + 1] += dp[i][j];
    }

    cout << dp[a - 1][b - 1] << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
using namespace std;
signed main() {
	string N;
	cin >> N;

	if (N.at(0) == N.at(2)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3616
# abc168 D
n, m = gets.split.map(&:to_i)
ab = m.times.map {
  gets.split.map(&:to_i).map{|x|x-1}
}


nodes = Array.new(n){ [] }
ab.each do |(a,b)|
  nodes[a] << b
  nodes[b] << a
end

lens = Array.new(n, 0)

# pp nodes

sirube = Array.new(n, nil)

stack = [ 0 ] # index, len

until stack.empty?
  s = stack.shift
  nodes[s].size.times do |ind|
    tonari_ind = nodes[s][ind]
    if sirube[tonari_ind].nil?
      sirube[tonari_ind] = s
      stack << tonari_ind
    end
  end

end

# p sirube

if sirube[1..-1].any? {|x|x.nil?}
  puts 'No'
else
  puts 'Yes'
  puts sirube[1..-1].map{|x|x+1}.join("\n")
end





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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

signed main()
{
	int m, k;
	cin >> m >> k;

	if(m == 1){
		if(k){
			cout << -1 << endl;
		}else{
			cout << "0 0 1 1" << endl;
		}
		return 0;
	}

	int n = 1<<m;
	if(k >= n){
		cout << -1 << endl;
		return 0;
	}

	deque<int> ans;
	ans.push_back(k);
	rep(i, 0, n){
		if(i != k){
			ans.push_back(i);
			ans.push_front(i);
		}
	}
	ans.push_back(k);
	
	rep(i, 0, ans.size()){
		cout << ans[i] << " \n"[i==ans.size()-1];
	}

	return 0;
}


Measured memory_bytes: 3968
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j,p;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
  for(i=0;i<=VMAX;i++) C[i]=0;

  for(i=0;i<n;i++){
    scanf("%d",&p);
    A[i+1]=p;
    C[A[i+1]]++;

  }
  for(i=1;i<=VMAX;i++) C[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");

  return 0;
}



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

int Answer;

bool isSorted(vector<int> &A) {
    for(int i = 0; i < A.size() - 1; ++i) {
        if(A[i] > A[i + 1]) return false;
    }
    return true;
}

int main() {
    int N; cin >> N;
    vector<int> A(N + 1), B(N);
    for(int i = 0; i <= N; ++i) cin >> A[i];
    for(int i = 0; i < N; ++i) cin >> B[i];
    long long ans = 0;
    for(int i = 0; i < N; ++i) {
        if(A[i] >= B[i]) {
            ans += B[i];
            A[i] -= B[i];
        } else if(A[i] + A[i + 1] >= B[i]) {
            ans += B[i];
            A[i + 1] -= (B[i] - A[i]);
            A[i] = 0;
        } else {
            ans += A[i] + A[i + 1];
            A[i] = A[i + 1] = 0;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
//もう二度とつかわん//
//    ↓ ↓　↓　　 //
#define ll long long
//    ↑　↑　↑    //
//フェルマー方程式の恨み//
#define rep(i,n) for(int i=0;i<n;i++)
#define ggr getchar(); getchar();return 0;
using namespace std;
signed main() {
	string s;
	ll k;
	cin >> s >> k;
	ll cnt = 0;
	char memo = s[0];
	if (s.size() == 1)cout << s[0] << endl;
	else if (s[0] != '1')cout << s[0] << endl;
	else {
		rep(i, s.size()) {
			if (s[i] == '1' && s[i + 1] == '1')cnt++;
			else {
				memo = s[i + 1];
				break;
			}
		}
		cnt++;
		if (cnt < k)cout << memo << endl;
		else cout << 1 << endl;
	}
	ggr
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
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; }
ll mod= 1e9 + 7;


int N,q;  //N頂点M辺
vector<int> visited;
vector<vector<int>> G;


int main() {
    cin >> N >>q;
    ll ans[N]={};
    G = vector<vector<int>>(N); // サイズを確保する
    visited = vector<int>(N, 0); // 全頂点を「未訪問」に初期化
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        // 頂点番号を 0-indexed とする
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    rep(i,q){
      ll a,b;
      cin >> a >> b;
      a--;
      ans[a]+=b;
    }
    
    queue<int> que;
    int ft=0;

    que.push(ft); // ft を橙色頂点にする
    visited[ft]=1; // 初期条件 (頂点 ft を初期ノードとする)

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (visited[nv] != 0) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv についてキューに追加する（距離情報を更新する場合はvisited[v]+1）
            visited[nv] = 1;
            ans[nv]+=ans[v];
            que.push(nv);
        }
    }
    rep(i,N)cout << ans[i] <<" ";
    cout << endl;

}

Measured memory_bytes: 17988
#include<iostream>
using namespace std;
int main(){
  int num[101]={0};
  int n;
  while(cin>>n){
    num[n]++;
  }
  int max=0;
  for(int i=1;i<=100;i++){
    if(num[i]>max)max=num[i];
  }
  for(int i=1;i<=100;i++){
    if(num[i]==max)cout<<i<<endl;
  }
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll ans = 1, mn = a[0];
    for (ll i = 1; i < n; ++i) {
        if (a[i] <= mn) ++ans;
        mn = min(mn, a[i]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1792
import sys
S = sorted(set(input()))

alp = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

for i in range(len(alp)):
  if (i>len(S)-1):
    print(alp[i])
    sys.exit()
  elif S[i] != alp[i]:
    print(alp[i])
    sys.exit()

print('None')


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


signed main(){
    int M,L,R;
    while(cin>>M>>L>>R,M||L||R){
        vint P(M);rep(i,M)cin>>P[i];
        sort(all(P));reverse(all(P));

        int val=0,ma=0;
        for(int i=L-1;i<R;i++){
            int tmp=P[i]-P[i+1];
            if(tmp>=val){
                val=tmp;
                ma=i+1;
            }
        }
        cout<<ma<<endl;
    }
    return 0;
}

Measured memory_bytes: 3176
def f(n):
    if (n % 2) == 0:
        return int(n / 2)
    else:
        return int(3 * n + 1)

s = int(input())

memo = []

for m in range(1,1000000000000000):
    if m == 1:
        memo.append(s)
    else:
        if f(memo[-1]) in memo:
            print(int(m))
            exit(0)
        else:
            memo.append(f(memo[-1]))


Measured memory_bytes: 2940
n=int(input())
a=list(map(int,input().split()))
tmp=0
ca=[0]
for ai in a:
  tmp+=ai
  ca.append(tmp)
from bisect import bisect_right,bisect_left
ans=float('inf')

# 数列をまず半分に区切る。左i個と右n-i個 2<=i,n-i
f,g=1,3
for i in range(2,n-1):
  while abs(ca[i]-ca[f]-ca[f])>abs(ca[i]-ca[f+1]-ca[f+1]):
    f+=1
  while abs((ca[-1]-ca[g])-(ca[g]-ca[i]))>abs((ca[-1]-ca[g+1])-(ca[g+1]-ca[i])):
    g+=1
  l=(ca[f],ca[i]-ca[f],ca[-1]-ca[g],ca[g]-ca[i])
  ans=min(ans,max(l)-min(l))
  #print(l)
print(ans)


Measured memory_bytes: 32256
x,y=map(int,input().split())
mod=10**9+7
n_max=10**6+1
F=[0]*(n_max+1)
F[0]=1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
def comb(x,y):
  return (F[x]*pow(F[x-y],mod-2,mod)*pow(F[y],mod-2,mod))%mod
a,b=2*y-x,2*x-y
if a<0 or b<0:
  print(0)
elif a%3!=0 or b%3!=0:
  print(0)
else:
  a//=3
  b//=3
  print(comb(a+b,a))


Measured memory_bytes: 43764
#include <bits/stdc++.h>
////////////////////////////////////////////////////////////
#define all(x) (x).begin(), (x).end() 
const int inf = 1e9;
const long long INF=1e15;
#define endl '\n'
#define forn(i, n) for(int i=0;i<(n);++i)
#define pb push_back
#define eb emplace_back
#define fastio ios::sync_with_stdio(false);cin.tie(0); //cout.tie(0);

using namespace std;

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

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

/*
(Ai,Bi)≠(Cj,Dj)
(Ai,Bi)≠(Dj,Cj)
*/
int main() {
	fastio;
	int n, m, k; cin >> n >> m >> k;
	vector<vi> f(n), b(n);
	forn(i, m) {
		int A, B; cin >> A >> B;
		A--, B--;
		f[A].pb(B);
		f[B].pb(A);
	}
	forn(i, k) {
		int C, D; cin >> C >> D;
		C--, D--;
		b[C].pb(D);
		b[D].pb(C);
	}
	vi com(n, -1);
	vi coms(n, 0);
	int label = 0;
	function<void(int)> dfs = [&](int here) {
		com[here] = label; coms[label]++;
		for(int next:f[here]) if(com[next] == -1) dfs(next);
	};
	forn(i, n) {
		if(com[i] == -1) {
			dfs(i);
			label++;
		}
	}
	forn(i, n) {
		int ans = coms[com[i]] - 1;
		for(int v:b[i]) if(com[i] == com[v]) ans--;
		ans -= f[i].size();
		cout << ans << " ";
	}
}

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

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

	int l = s.length();
	int h = l / 2;
	string s1 = s.substr(0, h);
	string s2 = s.substr(h, h + l % 2);

	int p = 0;
	for (int i = 0; i < h; ++i) {
		if (s1[i] != s2[s2.length() - 1 - i]) {
			++p;
		}
	}

	cout << p;
	
	return 0;
}
	

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#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;
using ll = long long;
using u64 = uint_fast64_t;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    ll ans = 1;
    rep(i,N) {
        if (A[i]==0) {
            cout << 0 << ln;
            return 0;
        }
    }
    ll MAX = 1e18;
    rep(i,N) {
        if (A[i] >= MAX*2/ans) {
            cout << -1 << ln;
            return 0;
        }
        ans *= A[i];
    }

    if (ans > MAX) {
        cout << -1 << ln;
        return 0;
    }

    cout << ans << ln;
}

Measured memory_bytes: 3972
#include <iostream>

using namespace std;

int main() {
    
    int i, a, b, c, cls;
    cin >> a >> b >> c;
    cls = 0;
    for (int i = a; i <= b; i++) 
    {
    if (c%i == 0)
    cls++;
    }
        cout << cls << endl;
    
}


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

const int MOD = 1000000007;

int64_t modpow(int64_t x, int64_t n) {
    x = x%MOD;
    if(n==0) return 1;  //再帰の終了条件

    else if(n%2==1) {
        return (x*modpow(x, n-1))%MOD;  //nが奇数ならnを1ずらす
    }
    else return modpow((x*x)%MOD, n/2)%MOD;  //nが偶数ならnが半分になる
}

int64_t comb(int64_t n, int64_t k) {
    int64_t x = 1;
    for(int i=n-k+1; i<=n; i++) {
        x = x*i%MOD;
    }

    int64_t y = 1;
    for(int i=1; i<=k; i++) {
        y = y*i%MOD;
    }
    y = modpow(y, MOD-2);

    return x*y%MOD;
}

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

    int all = modpow(2,n) -1;
    int muri = comb(n,a) + comb(n,b);

    int ans = all - muri;
    while(ans<0) {
        ans += MOD;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    ll n,dis; cin>>n;
    map<int,int> me;
    ll ad;
    rep(i,n+1){
        cin>>ad;
        if(me.count(ad)){
            dis=i-me[ad]+1; break;
        }
        else{
            me[ad]=i;
        }
    }
    vector<ll> v(n+2,0); v[1]=1;
    for(int i=2;i<=n+1;i++){
        v[i]=(-v[MOD%i]*(MOD/i))%MOD;
    }
    ll c=1,d=1;
    rep(i,n+1){
        c=((c*(n+1-i))%MOD)*v[i+1]%MOD;
        c=(c+MOD)%MOD;
        cout<<(c-d+MOD)%MOD<<endl;
        d=((d*(n+1-dis-i))%MOD)*v[i+1]%MOD;
        d=(d+MOD)%MOD;
    }
}

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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 1000000007

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    ll a = 0, n;
    cin >> n;
    vi arr(n);
    REP(i, 0, n)
        cin >> arr[i];
    vi diff(n-1);
    REP(i, 0, n-1)
        diff[i] = arr[i+1] - arr[i];
    for (ll i = 0; i < n-1; i++) {
        ll j = i, c = 0;
        while (j < n-1 && diff[j] <= 0) {
            c += diff[j];
            j++;
        }
        a = min(a, c);
        i = j;
    }
    if (a < -1)
        cout << "No\n";
    else
        cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 1792
x, k, d = map(int, input().split())
x = abs(x)
if x >= k * d:
    print(x - k * d)
else:
    cnt = x // d
    if cnt % 2 == k % 2:
        if x > 0:
            point = x - cnt * d
        else:
            point = 0
    else:
        if x > 0:
            point = x - (cnt+1) * d
        else:
            point = d
    print(abs(point))


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

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

	int ans = 0;

	for (int i = 0; i < s.size() / 2; i++)
	{
		if (s[i] != s[s.size() - i - 1])
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define N_ 201000
struct point{
	int a,b;
	bool operator <(const point &p)const {
		return (long long)p.a*(b+1) < (long long)a*(p.b+1);
	}
};
using namespace std;
vector<int> v1; //B
vector<point> v2; //A
int N;
long long D[40], S[N_], T;
int main() {
	cin >> N >> T;
	for(int i = 0; i< N; i++){
		int a, b;
		cin >> a >> b;
		if(!a) v1.push_back(b);
		else v2.push_back({a,b});
	}
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	for(int i = 1 ; i< 40; i++) D[i] = 1e15;
	int sz = v2.size();
	for(int i = 0; i< sz; i++) {
		for(int j = 38; j>= 0 ; j--){
			if(D[j] > T) continue;
			D[j+1] = min(D[j+1], D[j] + 1 + (D[j]+ 1 )* v2[i].a +  v2[i].b);
		}
	}
	int m = v1.size();
	for(int i = 1; i<=m; i++) S[i] = S[i-1] + v1[i-1] + 1;
	
	int res = 0;
	for(int i = 0; i<= m; i++) for(int j = 0; j< 40; j++)if (S[i] + D[j] <= T) res = max(res, i + j);
	cout << res;
	
	return 0;
}

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

using namespace std;

#define ll long long

const int N=1e6+5,MOD=1000000007;

int n,b[N],a[N],q,m,u,v,tc,k,l,ans,x;

char s[N];

int main(){ 
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
   
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int add=min(a-b,c);
    printf("%d\n",c-add);

}   


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = int(1e9);
typedef long long int ll;

/* -- template -- */

ll memo[100000];

ll dfs(int x){
    if(x < 0)return 0;
    if(x == 0)return 1;
    if(memo[x] == 0)memo[x] = (dfs(x - 1) + dfs(x - 2))%1000000007;
    return memo[x];
}

int main(){
    int N, M;cin >> N >> M;
    bool stair[N + 1];
    rep(i, N + 1)stair[i] = true;
    for(int i = 0;i < M;++i){
        int a;cin >> a;
        stair[a] = false;
    }
    ll ans = 1;
    int count = 0;
    for(int i = 0;i < N + 1;++i){
        if(stair[i] == false){
            ans = (ans * dfs(count - 1)) % 1000000007;
            count = 0;
        }else{
            count += 1;
        }
    }
    ans = (ans * dfs(count - 1)) % 1000000007;
    cout << ans;
}


Measured memory_bytes: 4224