akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[]) {
	vector<vector<int>> v;
	for (int i = 0; i < 3; i++) {
		vector<int> subv;
		for (int j = 0; j < 3; j++) {
			int t;
			cin >> t;
			subv.push_back(t);
		}
		v.push_back(subv);
	}

	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (v[j][k] == t) {
					v[j][k] = 0;
				}
			}
		}
	}

	for (int i = 0; i < 3; i++) {
		int flag = 1;
		for (int j = 0; j < 3; j++) {
			if (v[i][j] != 0) {
				flag = 0;
				break;
			}
		}
		if (flag == 1) {
			cout << "Yes" << endl;
			return 0;
		}
		flag = 1;
		for (int j = 0; j < 3; j++) {
			if (v[j][i] != 0) {
				flag = 0;
				break;
			}
		}
		if (flag == 1) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	if (v[0][0] == 0 && v[1][1] == 0 && v[2][2] == 0) {
		cout << "Yes" << endl;
		return 0;
	}
	if (v[0][2] == 0 && v[1][1] == 0 && v[2][0] == 0) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
}









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

namespace ABC091 {
	class ABC091_A {
		static void Main(string[] args) {
			var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			var AB = input[0] + input[1];
			Console.WriteLine(AB >= input[2] ? "Yes" : "No");
		}
	}
}


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

/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define endl '\n'

const int max4 = 10004;
const int maxx = 100005;
const int max6 = 1000006;
const int lg5 = 17;

const int INF = 2 * 1000000007;
const long long INFLL = 4LL * 1000000000 * 1000000000;

/***************/

int powmod (int a, int b, int mod) {
    int res = 1; a %= mod;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
    }
    return res;
}

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

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

int is_prime (int n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/******Don't forget to use long long when needed!!******/

int arr[maxx];
int main() {
    //freopen("262144.in","r",stdin);
    //freopen("262144.out","w",stdout);
    int n, k;
    cin >> n >> k;
    vector <int> A, B;
    for (int i = 1; i <= n; i++) {
        cin >> arr[i];
        if (arr[i] < 0) A.pb(arr[i]);
        else if (arr[i] > 0) B.pb(arr[i]); else k--;
    }
    if (k == 0) {
        cout << 0 << endl;
        return 0;
    }
    int res = INF;
    if (A.size() >= k) {
        res = min(res, -A[A.size() - k]);
    }
    if (B.size() >= k) {
        res = min(res, B[k - 1]);
    }
    for (int i = 1; i < k; i++) {
        int j = k - i; /// i from A, j from B
        if (A.size() < i || B.size() < j) continue;
        res = min(res, -A[A.size() - i] * 2 + B[j - 1]);
        res = min(res, -A[A.size() - i] + 2 * B[j - 1]);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1404
/*
时间:2020-7-29
书籍：算法和数据结构
内容：数据结构的应用-计算面积
页数：P86
*/
#include<iostream>
#include<stack>
#include<utility>            //pair头文件
#include<vector>
using namespace std;
int main()
{
	stack<int> S1;
	stack<pair<int, int> > S2;                //S2中包含一对数据，分别是该积水最左侧 \ 的位置和该积水处当前的位置
	//stack<pair<int, int>> S2;                //定义模板少了一个空格，部分编译器会报错。
	char ch;
	int sum = 0;
	for (int i = 1; (ch = cin.get()) != '\n'; ++i)
	{
		if (ch == '\\')
			S1.push(i);
		else if (ch == '/'&&S1.size()>0)
		{
			int j = S1.top(); S1.pop();           //j代表当前 / 对应 \ 的位置
			int a = i - j;
			sum += a;
			while (S2.size() > 0 && S2.top().first > j)       //看小的积水是否可以融合成大的积水
			{
				a += S2.top().second; S2.pop();
			}
			S2.push(make_pair(j, a));             //形成新的积水
		}
	}
	vector<int> area;
	while (S2.size() > 0)
	{
		area.push_back(S2.top().second); S2.pop();                 //取出每块积水面积
	}
	cout << sum << endl;
	cout << area.size();
	for (int i = area.size() - 1; i > 0; --i)
	{
		cout<<" " << area[i];                         //注意考虑0的时候表现形式，因此将” “提前
	}
	if(area.size())
		cout <<" "<< area[0];                       //可能不存在积水的情况，极端情况，所以不可以直接area[0];
	cout << endl;
	return 0;
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}

signed main()	
{
    showoff;
    int n;
    cin >> n;
    vector<int>v(n+5);
    FOR(i,1,n){
        int x;
        cin >> x;
        v[x]++;
    }
    FOR(i,1,n+1)cout << v[i] << "\n";
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...

Measured memory_bytes: 4784
import java.util.Scanner;
public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int m = x*y;
		int l = 2*x+2*y;
		System.out.println(m+" "+l);
	}
}

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

long long int min(long long int a, long long int b) {
    if (a < b) {
        return a;
    } else {
        return b;
    }
}

long long int fivemin(long long int a, long long int b, long long int c,
                      long long int d, long long int e) {
    return min(min(min(a, b), min(c, d)), e);
}

int main() {
    long long int N, A, B, C, D, E;
    cin >> N >> A >> B >> C >> D >> E;

    long long int output = 0;
    // output = 5;
    // output += N / fivemin(A, B, C, D, E);
    output = 4;
    output += N / fivemin(A, B, C, D, E);
    if (N % fivemin(A, B, C, D, E) != 0) {
        output++;
    }

    cout << output << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <tuple>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; --i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
ll res[1010];

void prime_factor(int n) {
  for(int i=2; i*i<=n; i++) {
    while(n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if(n != 1) ++res[n];
}

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

  cin >> n;

  FOR(i, 1, n + 1) prime_factor(i);
  ll ans = 1;
  FOR(i, 2, n + 1) {
    ans *= (1LL + res[i]);
    ans %= mod;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
FINGER_MAX = 21
N = int(raw_input())
num = [int(x) for x in raw_input().split(' ')]
table = [[0 for j in range(FINGER_MAX)] for i in range(N)]
table[0][num[0]] = 1

for i in range(1, N-1):
    n = num[i]
    for j in range(FINGER_MAX):
        if j + n < FINGER_MAX:
            table[i][j+n] += table[i-1][j]
        if j - n > -1:
            table[i][j-n] += table[i-1][j]
print table[N-2][num[-1]]


Measured memory_bytes: 4688
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;
int main(void){
    // Your code here!
    int n;
    pair<int,int> a[100000];
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i].first;
        a[i].second=i;
    }
    
    sort(a,a+n);
    for (int i = 0; i < n; i++) {
        std::cout << a[i].second+1 <<" ";
    }
}


Measured memory_bytes: 1536
#include<stdio.h>
int main(void){
  int k;
  scanf("%d",&k);
char s[101];
  scanf("%s",&s);
  if(strlen(s)<=k)printf("%s",s);
  else {for(int i=0;i<k;i++){
	printf("%c",s[i]);
  }
        printf("...");
       }
  return 0;
}

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

struct node{
    vector<int> child;
    int value = 0, total;
};

node t[200001];
int tmp = 0;
int dfs(int n){
    int i;

    tmp += t[n].value;
    t[n].total = tmp;
    for(i = 0; i < t[n].child.size(); i++){
        dfs(t[n].child[i]);
    }
    tmp -= t[n].value;
}

int main(){
    int n, q, i;
    cin >> n >> q;

    for(i = 0; i < n-1; i++){
        int a, b;
        cin >> a >> b;
        t[a].child.push_back(b);
    }
    for(i = 0; i < q; i++){
        int p, x;
        cin >> p >> x;
        t[p].value += x;
    }
    dfs(1);

    for(i = 1; i < n+1; i++){
        cout << t[i].total << " ";
    }
    cout << endl;

}

Measured memory_bytes: 24320
import Control.Monad
import qualified Data.Set as S
 
 
main = do
  [n, m] <- map read . words <$> getLine
  es <- map words <$> replicateM m getLine
  putStr $ solve n es S.empty
 
solve _ [] _ = "IMPOSSIBLE"
solve n (["1", b]:es) s
  | S.member b s = "POSSIBLE"
  | otherwise = solve n es (S.insert b s)
solve n ([a, b]:es) s
  | b /= show n = solve n es s
  | S.member a s = "POSSIBLE"
  | otherwise = solve n es (S.insert a s)

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

ll gcd(ll a,ll b){
  if (a%b==0) return(b);
  else return(gcd(b,a%b));
}
ll lcm(ll a,ll b){
  return a*b/gcd(a,b);
}

vector<int> bfs(vvi L,int S){
  vector<int> v(L.size(),-1);
  v[S]=0;
  queue<int> q;
  q.push(S);
  while(!q.empty()){
    int a=q.front();
    q.pop();
    for(int x:L[a]){
      if (v[x]==-1){
        v[x]=v[a]+1;
        q.push(x);
      }
    }
  }
  return v;
}

void initialize(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
/////////////////////////////////////////

int main(){
  initialize();
  string S;
  cin >> S;
  rep(i,4) cout << S[i];
  cout << " ";
  rep(i,8) cout << S[i+4];
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
li = list(reversed(list(map(int, input().split()))))
li_a = []
a = 1
c = 0
while c<n:
  c += 1
  b = li.pop()
  if b == a:
    a += 1
if a == 1:
  print(-1)
else:
  print(n-a+1)
    
    

Measured memory_bytes: 24744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int p, q, r;
  cin >> p >> q >> r;
  cout << p+q+r - max({p,q,r}) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------
class Graph{

public:
  vector<vector<int>> graphs;
  vector<bool> check; // For DFS
  vector<ll> dist;   // For BFS
  queue<int> q; // For BFS

  Graph(int n){
    graphs.resize(n);
    init(n);
  }
  ~Graph(){}

  void addedge(int u, int v){
    u--; v--;
    graphs[u].push_back(v);
    graphs[v].push_back(u);
  }

  void addedge_cin(int m){
    rep(i,m){
      int a, b;
      cin >> a >> b;
      addedge(a, b);
    }
  }

  void init(int n){
    check.resize(n, false);
    dist.resize(n, -1);
  }

  void reset_dist(){
    rep(i,dist.size()){
      dist[i]=-1;
    }
  }

  void dfs(int v)
  {
    check[v] = true;

    for(auto next_v : graphs[v]){
      if(check[next_v]) continue;
      dfs(next_v);
    }
  }

  void bfs(int v)//----------------------
  {
    dist[v] = 0;
    q.push(v);

    while(!q.empty()){
      int cur_v = q.front();
      q.pop();

      for(int next_v : graphs[cur_v]){
        if(dist[next_v] != -1){
          continue;
        }

        dist[next_v] = dist[cur_v] + 1;
        q.push(next_v);
      }
    }
  }//-----------------------

};

int main(void) {
  int n, x, y;
  cin >> n >> x >> y;
  Graph g(n);
  rep(i,n-1){
    g.addedge(i+1, i+2);
  }
  g.addedge(x, y);

  vec ans(n);
  rep(i,n-1){
    g.reset_dist();
    g.bfs(i);
    REP(j,i+1,n){
      ans[g.dist[j]-1]++;
    }
  }

  rep(i,n-1){
    prt(ans[i]);
  }

}


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    int odd = 1;
    rep(i, 0, n){
        if(a[i]%2) odd *= 1;
        else odd *= 2;
    }
    int ans = pow(3, n);
    cout << ans - odd << endl;
    return 0;
}


Measured memory_bytes: 4008
#include<bits/stdc++.h>
const int N = 4e4 + 5;
const double inf = 1e9;
using namespace std;

int n, p[N], f[N];
double a[N], b[N], c[N], bit[N];

void update(int i){
    while (i < N){
        bit[i]++;
        i += i&(-i);
    }
}

int get(int i){
    int ans = 0;
    while (i > 0){
        ans += bit[i];
        i -= i&(-i);
    }
    return ans;
}

bool check(double x){
    int cnt = 0;
    for (int i = 0; i < N; i++) bit[i] = 0;
    sort(p+1, p+1+n, [x](int i, int j){return ((-a[i]/b[i] * x + c[i] / b[i]) < (-a[j]/b[j] * x + c[j] / b[j]) || ((-a[i]/b[i] * x + c[i] / b[i]) == (-a[j]/b[j] * x + c[j] / b[j]) && (-a[i]/b[i]) > (-a[j] / b[j])));});
    for (int i = 1; i <= n; i++) f[p[i]] = i;
    sort(p+1, p+1+n, [](int i, int j){return (-a[i]/b[i]) < (-a[j]/b[j]);});
    for (int i = 1; i <= n; i++){
        cnt += (i-1) - get(f[p[i]]);
        update(f[p[i]]);
    }
    return (cnt > ((n*(n-1)/2)/2));
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(10);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i] >> b[i] >> c[i];
        p[i] = i;
    }
    double l = -inf, r = inf;
    for (int i = 1; i <= 100; i++){
        double mid = (l + r) / 2;
        if (check(mid)) l = mid;
        else r = mid;
    }
    cout << l << " ";
    for (int i = 1; i <= n; i++) swap(a[i], b[i]);
    l = -inf, r = inf;
    for (int i = 1; i <= 100; i++){
        double mid = (l + r) / 2;
        if (check(mid)) l = mid;
        else r = mid;
    }
    cout << l << " ";
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//Amazing Mazes
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] move = {{0,1},{0,-1},{1,0},{-1,0}};
		while(true){
			int w = sc.nextInt();
			int h = sc.nextInt();
			if((w|h)==0)break;
			sc.nextLine();
			boolean[][] map = new boolean[h][w];
			int[][] wall = new int[2*h-1][];
			for(int i=0;i<2*h-1;i++){
				if(i%2==0){
					wall[i] = new int[w-1];
					for(int j=0;j<w-1;j++)wall[i][j]=sc.nextInt();
				}
				else{
					wall[i] = new int[w];
					for(int j=0;j<w;j++)wall[i][j]=sc.nextInt();
				}
			}
			int step = 1;
			int ans = 0;
			List<int[]> list = new ArrayList<int[]>();
			list.add(new int[]{0, 0});
			map[0][0]=true;
			while(!list.isEmpty()){
				List<int[]> next = new ArrayList<int[]>();
				for(int[] a:list){
					if(a[0]==h-1 && a[1]==w-1){
						ans = step;
						break;
					}
					for(int k=0;k<4;k++){
						int ni = a[0]+move[k][0];
						int nj = a[1]+move[k][1];
						if(0<=ni&&ni<h&&0<=nj&&nj<w&&!map[ni][nj]){
							if(k==0 && wall[a[0]*2][a[1]]==0){
								map[ni][nj] = true;
								next.add(new int[]{ni,nj});
							}
							else if(k==1 && wall[ni*2][nj]==0){
								map[ni][nj] = true;
								next.add(new int[]{ni,nj});
							}
							else if(k==2 && wall[a[0]*2+1][a[1]]==0){
								map[ni][nj] = true;
								next.add(new int[]{ni,nj});
							}
							else if(k==3 && wall[ni*2+1][nj]==0){
								map[ni][nj] = true;
								next.add(new int[]{ni,nj});
							}
						}
					}
				}
				list = next;
				step++;
			}
			System.out.println(ans);
		}
	}
}

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

int desc(const void *a, const void *b) {
  unsigned long *A = (unsigned long *)a;
  unsigned long *B = (unsigned long *)b;
  
  if (*A > *B) return 1;
  if (*A < *B) return -1;
  return 0;
}

/*
int main() {
  int a[] = {2, 3, 1};
  qsort(a, sizeof(a) / sizeof(*a), sizeof(*a), desc);
  printf("%d%d%d", a[0], a[1], a[2]); // "321"
}
*/

int main (void)
{
  unsigned long a[100010], b[100010], c, x, y;

  unsigned long an, bn, mn, min=300000, i;

  scanf("%lu %lu %lu", &an, &bn, &mn);

  for (i=0; i<an; i++) {
    scanf("%lu", &(a[i]));
  }

  for (i=0; i<bn; i++) {
    scanf("%lu", &(b[i]));
  }

  for (i=0; i<mn; i++) {
    scanf("%lu %lu %lu", &x, &y, &c);
    if (min >= a[x-1] + b[y-1] - c) {
      min = a[x-1] + b[y-1] - c;
    }
  }
  
  qsort(a, an, sizeof(unsigned long), desc);
  qsort(b, bn, sizeof(unsigned long), desc);

  if (min >= a[0] + b[0]) {
    printf("%lu", a[0] + b[0]);
  } else {
    printf("%lu", min);
  }
  
  return 0;
  
}

Measured memory_bytes: 2556
#include <stdio.h>

int main(void)
{
	int a[4], b[4];
	int i;
	
	while (scanf("%d", a) != EOF){
		int hit = 0, blow = 0;
		
		for (i = 1; i < 4; i++){
			scanf("%d", a + i);
		}
		for (i = 0; i < 4; i++){
			int j;
			scanf("%d", b + i);
			if (a[i] == b[i]){
				hit++;
			}
			else {
				for (j = 0; j < 4; j++){
					if (i == j) continue;
					if (a[j] == b[i]){
						blow++;
					}
				}
			}
		}
		printf("%d %d\n", hit, blow);
	}
	
	return 0;
}

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

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  sort(A.begin(), A.end());
  ll l = -INF, r = INF;
  while (l+1 < r) {
    ll x = (l+r) / 2;
    bool ok = [&]{
      ll tot = 0;
      rep(i, N){
        int la = 0, ra = N;
        if(A[i] < 0) {
          while (la+1 < ra) {
            int xa = (la+ra) / 2;
            if(A[i] * A[xa] < x) ra = xa;
            else la = xa;
          }
          if (la <= i) tot += (N-1) - i;
          else tot += (N-1) - la;
        } else if(A[i] > 0) {
          while (la+1 < ra) {
            int xa = (la+ra) / 2;
            if(A[i] * A[xa] < x) la = xa;
            else ra = xa;
          }
          if(la > i) tot += la - i;
        } else {
          if (x > 0) tot += (N-1) - i;
        }
      }
      return tot < K;
    }();
    if (ok) l = x; else r = x;
  }
  cout << l << endl;

  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;

int main(){
  int alpha[26]; // 'a'が0番目の配列
  for(int i=0; i<26; i++) alpha[i] = 0; // 配列初期化

  /* 文字数カウント */
  char c;
  int i=0;
  while(scanf("%c", &c) != EOF){
    if(isalpha(c))
      alpha[tolower(c) - 'a']++;
    i++;
  }

  /* 印字 */
  for(int i=0; i<26; i++){
    //cout << to_string(i+'a') << " : " << alpha[i] << endl;
    printf("%c : %d\n", 'a'+i, alpha[i]);
  }
  return 0;
}



Measured memory_bytes: 3216
#include <iostream>
#include <string.h>

using namespace std;
int dp[2][2][100][100];

int calc(int w, int h)
{
	memset(dp, 0, sizeof(dp));
	dp[0][0][0][1] = 1;
	dp[1][1][1][0] = 1;
	for(int i = 0; i < w; ++i)
	{
		for(int j = 0; j < h; ++j)
		{
			if(i != w - 1)
			{
				dp[1][1][i + 1][j] += dp[0][1][i][j] + dp[1][1][i][j];
				dp[0][1][i + 1][j] += dp[0][0][i][j] % 100000;
				dp[1][1][i + 1][j] %= 100000;
				dp[0][1][i + 1][j] %= 100000;
			}
			if(j != h - 1)
			{
				dp[0][0][i][j + 1] += dp[1][0][i][j] + dp[0][0][i][j];
				dp[1][0][i][j + 1] += dp[1][1][i][j];
				dp[0][0][i][j + 1] %= 100000;
				dp[1][0][i][j + 1] %= 100000;
			}
		}
	}
	return ((dp[0][0][w - 1][h - 1] + dp[1][0][w - 1][h - 1] + dp[1][1][w - 1][h - 1] + dp[0][1][w - 1][h - 1]) % 100000); 
}

void solve()
{
	int w, h;
	while(cin >> w >> h, w || h)
	{
		cout << calc(w, h) << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
using System;
using System.Linq;
using System.Collections.Generic;
using static program.Input;
using static program.MyMath;

namespace program {
  class Program {
    static void Main()
    {
      int smash = 0;
      int index = 1;
      var n = ScanInt();
      var a = ScanIntArray();
      for(int i=0; i<n; i++){
        if(a[i] != index)
          smash++;
        else
          index++;
      }
      if(smash == n) Out(-1); else Out(smash);
    }
    static public void Out(object s) { Console.Write($"{s} "); }
  }
  
  static class Input {
    static public int ScanInt() { return int.Parse(Console.ReadLine()); }
    static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
    static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
    static public long ScanLong() { return long.Parse(Console.ReadLine()); }
    static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
    static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); }
    static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); }
    static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); }
    static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); }
    static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); }

    static public string ScanStr() { return Console.ReadLine(); }
    static public string[] ScanStrArray() { return ScanStr().Split(); }
  }
  
  static class MyMath {
    public static int GCD(int a, int b) {
        Func<int, int, int> gcd = null;
        gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
        return a > b ? gcd(a, b) : gcd(b, a);
    }
    public static long GCD(long a, long b) {
        Func<long, long, long> gcd = null;
        gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
        return a > b ? gcd(a, b) : gcd(b, a);
    }
    public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
      if(b==0) {
        x=1; 
        y=0;
        return a;
      }
      var d = extGCD(b, a%b, ref y, ref x);
      y -= a/b *x;
      return d;
    }
    public static int LCM(int a, int b) { return a * b / GCD(a, b); }
    public static long LCM(long a, long b) { return a * b / GCD(a, b); }
  }
}


Measured memory_bytes: 35036
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pb push_back
int main()
{
    ll x,score=0;;
    cin>>x;
    if(x<5)
    {
        score=0;
    }
    else if(x>=500)
    {
        score+=(x/500)*1000;
        x=x%500;
    }
    if(x>=5)
    {
        score+=(x/5)*5;
        x=x%5;
    }
    cout<<score;
    

    return 0;
}


Measured memory_bytes: 256
def main():
    x, y = map(int, input().split())

    res = 'No'

    for i in range(x+1):
        crane = i
        turtle = x - i

        if crane*2 + turtle*4 == y:
            res = 'Yes'
            break
    
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9116
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
using namespace std;

#define mx 200005
vector<int> g[mx];
int vis[mx];

void dfs(int nd, int comp){
    if(vis[nd]>0) return;
    vis[nd]=comp;
    for(auto e : g[nd]) dfs(e,comp);
}

int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    memset(vis,0,sizeof(vis));

    for(int i=0;i<m;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        --x;--y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    int cc=1;
    for(int i=0;i<n;i++) if(!vis[i]){
        dfs(i,cc);
        cc++;
    }

    map<int,int> freq;
    for(int i=0;i<n;i++) freq[vis[i]]++;

    int mf=0;
    for(auto e : freq) if(e.second > mf){
        mf=e.second;
    }
    printf("%d\n",mf);
}


Measured memory_bytes: 21240
#include<cstdio>
#include<vector>
#include<queue>
struct edge
{
	int to,val;
};
std::vector<edge> a[100005];
int n,m,dis[100005],inq[100005],x[200005],y[200005],v[200005],flag,cnt[100005];
void add(int x,int y,int v){a[x].push_back(edge{y,v});}
void spfa(int s)
{
    int sz=1;
	std::queue<int> q;
    dis[s]=0;q.push(s);inq[s]=1;
    while (!q.empty())
    {
    	int v=q.front();q.pop();inq[v]=0;
    	for (int i=0;i<a[v].size();i++)
    	{
    		int u=a[v][i].to;
    		if (dis[u]==2000000000) ++sz;
    		if (dis[u]!=2000000000&&dis[v]+a[v][i].val!=dis[u])
			{
				flag=1;
				return;
			} 
    		if (dis[v]+a[v][i].val<dis[u])
			{
				dis[u]=dis[v]+a[v][i].val;
				if (!inq[u]) q.push(u),inq[u]=1;
				++cnt[u];
				if (cnt[u]>sz+5)
				{
					flag=1;
				    return;
				}
			}
		}
//		for (int i=1;i<=n;i++) printf("%d ",dis[i]);puts("");
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&x[i],&y[i],&v[i]);
		add(x[i],y[i],v[i]),add(y[i],x[i],-v[i]);
	}
	for (int i=1;i<=n;i++) dis[i]=2000000000,inq[i]=0;
	for (int i=1;i<=n;i++)
	{
		if (dis[i]==2000000000) spfa(i);
		if (flag==1) break;
	}
	for (int i=1;i<=m;i++) if (dis[x[i]]+v[i]!=dis[y[i]]) flag=1;
	if (!flag) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 15336
#include <set>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <vector>
#include <tuple>
#include <string>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <limits>
#include <climits>
#include <numeric>
#include <functional>

#define lnd '\n'
// #define reverse(i, n) for(ll i = n-1; i >= 0; --i)
#define from(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, n) for(ll i = 0; i < n; i++)
#define REPN(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(s) (s).begin(), (s).end()
#define rALL(s) (s).rbegin(), (s).rend()
#define sz(s) (int)(s).size()
#define mk make_pair
#define pb push_back
#define sqr(s) ((s) * (s))

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;

template <class T>
T GCD (T a, T b) {
  if(a == 0) return b;
  return GCD(b%a, a);
}

template <class T>
T LCM(T a, T b){
  return a*b/GCM(a,b);
}

template <class T>
T modpow(T x, T p){
    T res = 1;
    while(p > 0){
        if(p&1) res *= x;
        x *= x;
        p /= 2;
    }
    return res;
}

template <class T>
T modpow(T x, T p, ll mod){
    T res = 1;
    while(p > 0){
        if(p&1) res = (res*x)%mod;
        x = (x*x)%mod;
        p /= 2;
    }
    return res%mod;
}

template <class T>
void print(T a[], ll n){
    for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
    cout << endl;
}

template<class T>
void printc(T c){
    for(auto const& v: c) std::cout << v << ' ';
    cout << endl;
}

struct HASH{
  size_t operator()(const pair<long,long>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

bool pair_sort(const pair<int, int> &p1, const pair<int,int> &p2){
    if(p1.first != p2.first) return p1.first < p2.first;
    else return p1.second < p2.second;
}

const int INF = std::numeric_limits<int>::max();
const ll M_INF = std::numeric_limits<ll>::min();
const ll LL_INF = std::numeric_limits<ll>::max();

void solution();
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solution();
    return 0;
}

void solution(){
  int n;
  cin >> n;
  vector<int> a(n);
  ll counts[n];
  memset(counts, 0, sizeof(counts));
  loop(i, n) {
    cin >> a[i];
    --a[i];
    counts[a[i]]++;
  }

  ll total = 0;
  for(auto &i: counts){
    total += (i*(i-1))/2;
  }

  for(auto &i: a){
    ll cur = counts[i]-1;
    ll res = total - (counts[i]*(counts[i]-1)/2) + ((cur*(cur-1))/2);
    cout << res << endl;
  }
}     

Measured memory_bytes: 4992
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
long long int f[1002],F[1002],cnt,V,d,N=1001;
int main(){
  while(cin>>V>>d){
    f[0]=1;
    f[1]=2;
    for(int I=2;I<1002;I++)f[I]=(f[I-1]+f[I-2])%N;
    
    cnt=1;
    sort(f,f+V+1);
    for(int i=2;i<=V;i++){
      //cout<<f[i]<<endl;
      if(f[i-1]+d<=f[i]){
	//	cout<<'-'<<endl;
	cnt++;
      }
    }
    cout<<cnt<<endl;
  }
  return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define repo(i,o,n) for(int i=o;i<(int)(n);i++)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int n,a[55] = {11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381};

main() {
    cin >> n;
    rep(i,n) {
        if (i==n-1) cout << a[i] << endl;
        else cout << a[i] << " ";
    }
}

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

typedef long long ll;

const int N = 2e5 + 5, C = 22;
ll n, ans;
int a[N];
int cnt[C], b;

void add(int d) {
	for (int i = 0; i < C; i++)
		if ((d >> i) & 1) {
			cnt[i]++;
			b += (cnt[i] == 2);
		}
}

void del(int d) {
	for (int i = 0; i < C; i++)
		if ((d >> i) & 1) {
			cnt[i]--;
			b -= (cnt[i] == 1);
		}
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];

	add(a[0]);
	int l = 0, r = 0;
	while (l < n) {
		while (b == 0 && r < n) {
			r++;
			add(a[r]);
		}

		ans += r - l;

		del(a[l]);
		l++;
	}

	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 1024
import math

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

if N % 2 == 1:
  B = [0] * N
  for i in range(1,N):
    b = math.ceil(i / 2) * 2
    B[i] = b
else:
  B = [0] * N
  for i in range(N):
    b = math.floor(i / 2) * 2 + 1
    B[i] = b

if A == B:
  if N % 2 == 1:
    n = (N - 1) // 2
  else:
    n = N // 2
  print(2 ** n % (10 ** 9 + 7))
else:
  print(0)

Measured memory_bytes: 13812
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	s := readString()

	if s[2] == s[3] && s[4] == s[5] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  1000000007;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int bsearch(const vector<ll>& a, ll x){
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if(a[mid] < x) {
      lft = mid;
    }
    else {
      rgt = mid;
    }
  }
  return lft;
}

signed main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  ll ans = 100;
  REP_FROM(i, 'a', 'z'+1) {
    string a(s);
    bool flag = true;
    ll cnt = 0;
    while(flag) {
      flag = false;
      string b(a.size() - 1, '+');
      REP(j,a.size() - 1) { 
        if(a[j] != i && a[j+1] != i) {
          b[j] = '-';
          flag = true;
        }
        else if(a[j] == i) {
          b[j] = a[j];
        }
        else {
          b[j] = a[j+1];
        }
      }
      a = b;
      if(a.size() == 1) {
        flag = true;
      }
     }
     ll tmp = (s.size() - a.size());
     ans = min(ans, tmp);
  }
  char c = s[0];
  REP(i, s.size()) {
    if(s[i] != c) {
      cout << ans << endl;
      return 0;  
    }
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%lld%lld", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define INF 2000000000
#define PI 3.1415926535897932384626
const ll MOD=1e9+7;
struct schedule{
        ll a,b;
}s[200005];
bool cmp(schedule x,schedule y){
        if(x.b==y.b) return x.a<y.a;
        return x.b<y.b;
}
int main(){
        int n;
        while(~getI(n)){
                F(i,0,n) getII(s[i].a,s[i].b);
                sort(s,s+n,cmp);
                bool flag=0,no=0;
                ll t=0,sum=0,maxB=-1;
                F(i,0,n){
                        if(s[i].a>s[i].b) no=1;
                        sum+=s[i].a;
                        maxB=max(maxB,s[i].b);
                }
                if(no||sum>maxB){
                        puts("No");
                        continue;
                }
                F(i,0,n){
                        t+=s[i].a;
                        if(t>s[i].b){
                                flag=1;
                                puts("No");
                                break;
                        }
                }
                if(!flag) puts("Yes");
        }
}

Measured memory_bytes: 3328
def solve(n, m, c, bs, mat_a):
    res = 0
    for i in range(n):
        score = c + sum(mat_a[i][j] * bs[j] for j in range(m))
        res += score > 0
    return res


def main():
    n, m, c = (int(z) for z in input().split())
    bs = [int(z) for z in input().split()]
    mat_a = [[int(z) for z in input().split()] for _ in range(n)]
    res = solve(n, m, c, bs, mat_a)
    print(res)


if __name__ == "__main__":
    main()

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

int main()
{
    long long x;
    cin>>x;
    long long time = 0;
    long long val = 100;

    while(val < x)
    {
        val = val*1.01;
        time++;
    }
    cout<<time;
    return 0;
}
  
  

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

#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

int main(int argc, char **argv) {
  ios::sync_with_stdio(false), cin.tie(0);
  string s;
  cin >> s;
  cout << (s == "ABC" ? "ARC" : "ABC"); 
  return 0;
}

Measured memory_bytes: 3652
N, K = gets.split.map(&:to_i)
MOD = 10 ** 9 + 7

ans = 0
memo = Array.new(K + 1, 0)

K.downto(1) do |x|
  e = K / x
  cnt = e.pow(N, MOD)

  (2 * x).step(K, x) do |y|
    cnt -= memo[y]
    cnt %= MOD
  end

  memo[x] = cnt
  ans += x * cnt
  ans %= MOD
end

puts ans


Measured memory_bytes: 14908
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-15
const int N=2e3+10;
namespace MAIN{
    int n,m;
    struct E{
        int next,to;
        E() {}
        E(res next,res to):next(next),to(to) {}
    }edge[N<<1];
    int head[N],cnt;
    inline void addedge(res u,res v){
        edge[++cnt]=E(head[u],v),head[u]=cnt;
        edge[++cnt]=E(head[v],u),head[v]=cnt;
    }
    int tot;
    void dfs(res x,res fax,res depx){
        if(depx>m/2)tot++;
        for(res i=head[x];~i;i=edge[i].next){
            res tox=edge[i].to;
            if(tox==fax)continue;
            dfs(tox,x,depx+1);
        }
    }
    int ans=inf;
    inline void MAIN(){
        memset(head,-1,sizeof(head));
        scanf("%d",&n),scanf("%d",&m);
        for(res i=1;i<n;i++){
            res u,v;
			scanf("%d",&u),scanf("%d",&v);
            addedge(u,v);
        }
        if(m&1){
            for(res x=1;x<=n;x++)
                for(res i=head[x];~i;i=edge[i].next){
                    res tox=edge[i].to;
                    tot=0;
                    dfs(tox,x,0);
                    dfs(x,tox,0);
                    ans=min(ans,tot);
                }
        }
        else {
            for(res x=1;x<=n;x++)
                tot=0,dfs(x,0,0),ans=min(ans,tot);
        }
        printf("%d\n",ans);
    }
}
int main(){
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	// your code goes here
	vector<int> mountain;
	int x;
	for(int i=0;i<10;i++){
		cin >> x;
		mountain.push_back(x);
	}
	sort(mountain.begin(),mountain.end(),greater<int>());
	for(int i=0;i<3;i++)
	cout << mountain[i] << endl;

	return 0;
}

Measured memory_bytes: 1216
def addone(h,w,m):
	# 指定値の周りに1を足す
	for i in range(-1,2):
		for j in range(-1,2):
			n = m[h+i][w+j]

			#print(h, w, i,j,n)

			if n!="#":
				if n==".": n = "0"
				m[h+i][w+j] = str(int(n)+1)
	#print("---")
	

h, w = map(int, input().split())		# 5 7 2


#m = list( list(input()) for _ in range(h) )
l = list( "." + input() + "." for _ in range(h) )

s = "." * (w+2)

m=[]
m.append( list(s) )
for _ in range(h):
	m.append( list(l[_]) )
m.append( list(s) )

#print(m)


for i in range(1,h+1):
	#print(m[i])
	n = m[i]
	for j in range(1,w+1):
		#print(n[j])
		#print(m[i][j])
		if m[i][j]=="#":
			addone(i,j,m)


for i in range(1,h+1):
	for j in range(1,w+1):
		#print(m[i][j], end='')
		n = m[i][j]
		if n==".": n = "0"
		print(n, end='')
	else:
		print("")


Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <stdio.h>

const int Max = 1000;

void view(int A[],int N){
	std::cout<<A[0];
	for(int i=1;i < N;i++){
		std::cout<<" "<<A[i];
	}
	std::cout << std::endl;
}

void insertion_sort(int A[],int N){
	//int v,j;
	for(int i=1;i<N;i++){
		int v = A[i];
		int j = i - 1;
		while(j >= 0 && A[j] > v){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		view(A,N);
	}
}


int main(){
	int N,R[Max];

	std::cin>>N;
	for(int i=0;i<N;i++)
		scanf("%d",&R[i]);

	view(R,N);	
	insertion_sort(R,N);

	return 0;
}

Measured memory_bytes: 1244
n = int(input())
xy = {}
for i in range(n):
  x,y = map(int,input().split())
  xy[x] = xy.get(x,[]) + [y]
d = {}
for x in xy:
  v0 = xy[x][0]
  while d.get(v0,v0) != v0:
    v0 = d[v0]
  for v in xy[x]:
    v1 = d.get(v,v)
    while d.get(v1,v1) != v1:
      v1 = d[v1]
    d[v1] = v0
for y in d:
  yp = d[y]
  y2 = [y]
  while yp != d[yp]:
    y2 += [yp]
    yp = d[yp]
  for y3 in y2:
    d[y3] = yp
e = {}
for y in d:
  e[d[y]] = e.get(d[y],0)+1
ans = 0
for x in xy:
  ans += e[d[xy[x][0]]] - len(xy[x])
print(ans)

Measured memory_bytes: 75352
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}
map<int,int> mp;

void dfs(int vis[],vector<int> v[],int curr,int depth,int now)
{
	vis[curr]=1;
	cout << now << " " << curr << " " << depth << endl;
	mp[depth]++;
	for(int i=0;i<v[curr].size();i++)
	{
		int j=v[curr][i];
		if(vis[j]==0 && j>curr)
		dfs(vis,v,j,depth+1,now);;
	}
}
int32_t main()
{
	int n,x,y;
	cin >> n >> x >> y;
	
	
	vector<int> v;
	int hash[n+1]={0};
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			int r=j-i;
			int s=abs(x-i)+1+abs(y-j);
			//cout << i << " " << j << " " <<  x << " " << y << endl; 
			hash[min(r,s)]++;
		}
	}
	for(int i=1;i<=n-1;i++)
	cout << hash[i] << endl;
}




Measured memory_bytes: 3580
#include <iostream>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
const double &eps = 1e-3;


int main()
{
    cin.sync_with_stdio(0);

    LD A, B;
    cin >> A >> B;

    cout << LL(A * B + eps);
}

Measured memory_bytes: 3700
import sys
readline = sys.stdin.readline

N = int(readline())

C = [[0] * 19 for i in range(19)]

for i in range(N):
  a = readline().rstrip()
  if "." in a:
    keta = len(a.split(".")[1])
    a = int(a.replace(".","")) * (10 ** (9 - keta))
  else:
    a = int(a) * (10 ** 9)
  temp = a
  cnt2 = 0
  cnt5 = 0
  while a % 2 == 0:
    a //= 2
    cnt2 += 1
  while a % 5 == 0:
    a //= 5
    cnt5 += 1
  C[min(cnt2, 18)][min(cnt5, 18)] += 1

#for c in C:
#  print(c)

ans = 0
# まず、同じグループから2つの数を選ぶ場合の数
for i in range(9, 19):
  for j in range(9, 19):
    n = C[i][j]
    ans += (n * (n - 1)) // 2

# 異なるグループから選ぶ場合の数
ans_diff = 0
for i in range(19):
  for j in range(19):
    for p in range(19):
      for q in range(19):
        if i == p and j == q:
          continue # カウント済
        if i + p < 18 or j + q < 18:
          continue
        ans_diff += C[i][j] * C[p][q]

ans += ans_diff // 2 # 二回カウントしている

print(ans)


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i], a[i]--;

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

    map<ll, ll> mp;
    REP(i, n) mp[a[i]]++;
    set<ll> st;
    REP(i, n) st.insert(i);
    vector<ll> ans;

    auto add = [&](ll x) {
        ans.push_back(x);
        st.erase(x);
        mp[a[x]]--;
        if(mp[a[x]] == 0) mp.erase(a[x]);
    };

    REP(i, n) {
        ll mi = st.size() ? *st.begin() : INF;
        ll mi2 = st.size()>=2 ? *(next(st.begin())) : INF;
        // dump(ans, st, mp);
        if(mp.size() == 2) {
            auto p1 = *mp.begin();
            auto p2 = *(next(mp.begin()));
            if(st.find(p1.first) != st.end() && p2.second == 1) {
                add(p1.first);
                continue;
            }
            if(st.find(p2.first) != st.end() && p1.second == 1) {
                add(p2.first);
                continue;
            }
        } 
        if(st.size() == 3) {
            vector<ll> v;
            for(auto j: st) v.push_back(j);
            bool f0 = true, f1 = true, f2 = true;
            if(a[v[1]] == v[2] && a[v[2]] == v[1]) f0 = false;
            if(i && a[ans.back()] == v[0]) f0 = false;
            if(a[v[0]] == v[2] && a[v[2]] == v[0]) f1 = false;                
            if(i && a[ans.back()] == v[1]) f1 = false;
            if(a[v[0]] == v[1] && a[v[1]] == v[0]) f2 = false;
            if(i && a[ans.back()] == v[2]) f2 = false;

            if(f0) add(v[0]);
            else if(f1) add(v[1]);
            else if(f2) add(v[2]);
            else {
                cout << -1 << endl;
                return 0;
            }
        }
        else if(i == 0) add(0);
        else if(a[ans.back()] == mi) add(mi2);
        else add(mi);
    }

    REP(i, n) cout << ans[i]+1 << (i==n-1 ? '\n': ' ');
    cout << flush;

    return 0;
}

Measured memory_bytes: 12544