akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;
int s[(1 << 20)][50];
vector<int> v[51];
int p;
int n, m, a[50], b[50], cnt, cnt2;
ll ans;

int dfs(int x, int y, int z) {
  if (x == z) {
    for (int j = 0; j < n - 1; j++) {
      if (a[j] == x && b[j] == y || a[j] == y && b[j] == x) {
        s[p][j] = 1;
      }
    }
    return 1;
  }
  for (int i = 0; i < v[x].size(); i++) {
    if (v[x][i] != y && dfs(v[x][i], x, z) == 1) {
      for (int j = 0; j < n - 1; j++) {
        if (a[j] == x && b[j] == y || a[j] == y && b[j] == x) {
          s[p][j] = 1;
        }
      }
      return 1;
    }
  }
  return 0;
}

int main() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i] >> b[i];
    v[a[i]].push_back(b[i]);
    v[b[i]].push_back(a[i]);
  }
  cin >> m;
  ans = (1LL << (n - 1));
  for (int i = 0; i < m; i++) {
    cin >> a[n] >> b[n];
    p = (1 << i);
    dfs(a[n], -1, b[n]);
  }
  for (int i = 1; i < (1 << m); i++) {
    for (int j = m - 1; j >= 0; j--) {
      if ((1 << j) & i) {
        p = j;
        break;
      }
    }
    cnt = 0;
    for (int j = 0; j < n - 1; j++) {
      if (s[(1 << p)][j] || s[i ^ (1 << p)][j]) {
        s[i][j] = 1;
        cnt++;
      }
    }
    cnt2 = 0;
    for (int j = 0; j < m; j++) {
      if (i & (1 << j)) {
        cnt2++;
      }
    }
    if (cnt2 % 2) {
      ans -= (1LL << (n - 1 - cnt));
    } else {
      ans += (1LL << (n - 1 - cnt));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 205056
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)


n = int(input())
G = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    G[a].append([b,i])

ans = [None]*(n-1)
def rec(cur,color):
    cnt = 1
    for (to, j) in G[cur]:
        if cnt == color:
            cnt += 1
        ans[j] = cnt
        rec(to, cnt)
        cnt += 1
rec(0, 0)
print(max(ans))
print(*ans, sep="\n")

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, t[101], d[101], v[101];
int sp[40404];
void solve(){
	cin >> n;
	for(int i = 1; i <= n; ++i){
		cin >> t[i];
		t[i] <<= 1;
		d[i] = d[i-1]+t[i];
	}
	for(int i = 1; i <= n; ++i){
		cin >> v[i];
		v[i] <<= 1;
		fill(sp+d[i-1], sp+d[i], v[i]); //max
	}
	
	for(int i = 1; i <= n; i++){
		if(v[i] > v[i-1]){
			for(int j = d[i-1]; j < d[i]; ++j){
				chmin(sp[j], v[i-1]+j-d[i-1]);
			}
		}
		if(v[i] > v[i+1]){
			for(int j = d[i+1]; j >= d[i]; --j){
				chmin(sp[j], v[i+1]+d[i+1]-j);
			}
		}
	}
	for(int i = 1; i < 40000; ++i){
		chmin(sp[i], sp[i-1]+1);
	}
	for(int i = 40000; i > 0; --i){
		chmin(sp[i], sp[i+1]+1);
	}
	
	i64 ans = 0;
	for(int i = 1; i < 40000; i++){
		ans += sp[i];
		
	}
	printf("%.10f\n", ans/4.0);
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


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

import sys

WHITE, GRAY, BLACK = 0, 1, 2
D_MAX = int(1e7 + 1)


def generate_adj_matrix(v_info):
    for v_detail in v_info:
        v_index = int(v_detail[0])
        v_adj_length = int(v_detail[1])
        v_adj_list = v_detail[2:]
        # assert len(v_adj_list) == v_adj_length * 2
        for j in range(0, v_adj_length * 2, 2):
            init_adj_matrix[v_index][v_adj_list[j]] = int(v_adj_list[j + 1])

    return init_adj_matrix


def dijkstra_path():
    path_list[0] = 0

    while True:
        min_cost = D_MAX
        current_vertex = None
        for i in range(vertices_num):
            if color[i] is not BLACK and path_list[i] < min_cost:
                min_cost = path_list[i]
                current_vertex = i

        if min_cost == D_MAX:
            break

        color[current_vertex] = BLACK

        for adj_vertex in range(vertices_num):
            current_v_weight = adj_matrix[current_vertex].get(str(adj_vertex), -1)
            if current_v_weight < 0:
                continue
            elif color[adj_vertex] is not BLACK:
                if path_list[current_vertex] + current_v_weight < path_list[adj_vertex]:
                    path_list[adj_vertex] = path_list[current_vertex] + current_v_weight
                    parent_list[adj_vertex] = current_vertex
                    color[adj_vertex] = GRAY

    return path_list


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices_num = int(_input[0])
    init_vertices_table = list(map(lambda x: x.split(), _input[1:]))
    # assert len(init_vertices_table) == vertices_num

    parent_list, path_list = [-1] * vertices_num, [D_MAX] * vertices_num
    color = [WHITE] * vertices_num
    init_adj_matrix = tuple({} for _ in range(vertices_num))
    adj_matrix = generate_adj_matrix(init_vertices_table)
    ans = dijkstra_path()
    for j in range(vertices_num):
        print(j, ans[j])

Measured memory_bytes: 8692
#include <iostream>

int main(void){
	char mei[64];
	int n;

	while(true){
		std::cin >> n;
		if(!n) break;

		int dC = 1;
		int dN = 5;
		int dS = 2;
		int dE = 3;
		int dW = 4;
		int dX = 6;

		int rNS = 0;
		int rEW = 0;
		int rRL = 0;
		int sum = 1;

		for(int i=0; i<n; i++){
			std::cin >> mei;
			switch(mei[0]){
			case 'N':{
				int _dX = dX;
				dX = dN;
				dN = dC;
				dC = dS;
				dS = _dX;
			}break;

			case 'S':{
				int _dX = dX;
				dX = dS;
				dS = dC;
				dC = dN;
				dN = _dX;
			}break;

			case 'E':{
				int _dX = dX;
				dX = dE;
				dE = dC;
				dC = dW;
				dW = _dX;
			}break;

			case 'W':{
				int _dX = dX;
				dX = dW;
				dW = dC;
				dC = dE;
				dE = _dX;
			}break;

			case 'R':{
				int _dN = dN;
				dN = dW;
				dW = dS;
				dS = dE;
				dE = _dN;
			}break;

			case 'L':{
				int _dN = dN;
				dN = dE;
				dE = dS;
				dS = dW;
				dW = _dN;
			}break;

			}

			sum += dC;

		}

		std::cout << sum << '\n';

	}

	return 0;
};

Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
int a[222222];
int n,l,r,ans,mid;
inline int big(int x,int y,int z){ return a[x]>z&&a[y]>z; }
inline int small(int x,int y,int z){ return a[x]<=z&&a[y]<=z; }
inline bool Trial(int k)
{
    for(register int i=0;i<n-1;++i)
    {
        if(big(n-i,n-i-1,k)||big(n+i,n+i+1,k)) return false;
        if(small(n-i,n-i-1,k)||small(n+i,n+i+1,k)) return true;
    }
    return small(1,1,k);
}
int main()
{
    scanf("%d",&n);
    for(register int i=1;i<(n<<1);++i) scanf("%d",&a[i]);
    l=1;r=n*2-1;
    while(l<r)
    {
        mid=(l+r)/2;
        if(Trial(mid)) r=mid;
        else l=mid+1;
    }
    ans=r;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int K; cin >> K;
  string S; cin >> S;
  for (int i = 0; i < S.size(); ++i) {
    if (i > K - 1) {
      cout << "..." << endl;
      return 0;
    }
    cout << S[i];
  }
  cout << endl;
}


Measured memory_bytes: 3600
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):
            total=500*i+100*j+50*k
            if total==x:
                cnt=cnt+1
print(cnt)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
	int k, n, t;
	int p[1000];

	cin >> n >> k;

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

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (p[i] > p[j]) {
				t = p[i];
				p[i] = p[j];
				p[j] = t;
			}
		}
	}

	int sum = p[0];

	for (int i = 1; i < k; i++) {
		sum = sum + p[i];
	}

	cout << sum;
}

Measured memory_bytes: 3152
import java.util.*;

class Main { 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();
        int A = 0;
        
        char[] s = S.toCharArray();
        char[] t = T.toCharArray();

        for (int i = 0; i < 3; i++) {
            if (s[i] == t[i]) {
                A++;
            }
        }
        System.out.println(A);
    }
}

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

int main()
{
  int n;
  int x = n;

  cin >> n;

  for(int i = 1; i <= n; i++){
    if(i % 3 == 0){
      cout << " " << i;
    }else{
  int x = i;
  while(x != 0){
      if(x % 10 == 3){
      cout << " " << i;
      break;
    }else{
    x /= 10;}
  }
  }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3072
n, k = map(int, input().split())
x = list(map(int, input().split()))
ans=4*10**8
# zip関数は多い元は無視する.
for a, b in zip(x, x[k-1:]):
    cand = b-a + min(abs(a), abs(b))
    ans = min(cand, ans)
print(ans)

Measured memory_bytes: 14388
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;
#define INF 1e9+7

int dfs(int k, vi& index, vvi& edges, vi& dp, vi& ans, int p = -1){
  int t = lower_bound(dp.begin(), dp.end(), index[k]) - dp.begin();
  int old = dp[t];
  dp[t] = index[k];
  ans[k] = t;
  if(p != -1) ans[k] = max(ans[k], ans[p]);
  for(auto i : edges[k]){
    if(ans[i]) continue;
    dfs(i, index, edges, dp, ans, k);
  }
  dp[t] = old;
  return 0;
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n; cin >> n;
  vi a(n);
  for(int &i : a) cin >> i;
  vvi edges(n);
  for(int i = 0; i < n-1; i++){
    int u, v; cin >> u >> v;
    u--, v--;
    edges[u].push_back(v);
    edges[v].push_back(u);
  }

  vi ans(n, 0);
  vi dp(n, INF);
  dp[0] = 0;
  dfs(0, a, edges, dp, ans);
  for(int i = 0; i < n; i++){
    cout << ans[i] << endl;
  }


  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 33784
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

void trans(double tx, double ty, double &x, double &y) 
{
    x += tx;
    y += ty;
}

void rotate(double theta, double &x, double &y) 
{
    double tx = x;
    double ty = y;

    x = cos(theta) * tx - sin(theta) * ty;
    y = sin(theta) * tx + cos(theta) * ty;
}

int main()
{
    double x1, y1, x2, y2, xq, yq;
    char ch;

    cout << setiosflags(ios::fixed) << setprecision(6);
    while (cin >> x1 >> ch >> y1 >> ch >> x2 >> ch >> y2
           >> ch >> xq >> ch >> yq) {
        double theta = atan((y2 - y1) / (x2 - x1));

        trans(-x1, -y1, xq, yq);
        rotate( -theta, xq, yq);
        yq *= -1;
        rotate( theta, xq, yq);
        trans(x1, y1, xq, yq);
        
        cout << xq << " " << yq << endl;
    }
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x, a, b; cin >> x >> a >> b;
  cout << (x - a) % b << endl;

  return 0;
};


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1E5;
int n;
int a[N], b[N], c[2 * N];
LL s[N + 1];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        c[2 * i] = a[i];
        c[2 * i + 1] = b[i];
    }
    sort(c, c + 2 * n);
    for (int i = 0; i < n; ++i)
        s[i + 1] = s[i] + c[i];
    LL ans = min(accumulate(a, a + n, 0LL), accumulate(b, b + n, 0LL));
    for (int i = 0; i < n; ++i) {
        int x = lower_bound(c, c + 2 * n, a[i]) - c;
        int y = lower_bound(c, c + 2 * n, b[i]) - c;
        if (x > y)
            swap(x, y);
        if (x < n - 2 && y < n - 1)
            ans = min(ans, s[n]);
        else if (x < n - 2)
            ans = min(ans, s[n - 1] + c[y]);
        else
            ans = min(ans, s[n - 2] + a[i] + b[i]);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int n,t,a;
	cin >> n >> t >> a;
	int h;
	int res = 0;
	int manko = 1e9;
	for(int i = 1; i <= n; ++i){
		cin >> h;
		int K = 1000*t-h*6-1000*a;
		if(K<0) K = -K;
		if(manko > K){
			manko = K;
			res = i;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  atcoder-intervals-2
//
//  Created by r on 6/11/19.
//  Copyright © 2019 r. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
using namespace std;

//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007

typedef long long ll;


ll add(ll a, ll b) {
    a += b;
    if(a >= MOD) {
        a -= MOD;
    }
    return a;
}
ll sub(ll a, ll b) {
    a -= b;
    if(a < 0) {
        a += MOD;
    }
    return a;
}
void add_self(ll& a, ll b) {
    a = add(a, b);
}
void sub_self(ll& a, ll b) {
    a = sub(a, b);
}

const ll MAXN = 200010;

vector<pair<ll, ll>> intervals[MAXN];
ll N, M;
ll t[4*MAXN];
ll lazy[4*MAXN];
ll dp[MAXN];

void push(ll v) {
    t[v*2] += lazy[v];
    lazy[v*2] += lazy[v];
    t[v*2+1] += lazy[v];
    lazy[v*2+1] += lazy[v];
    lazy[v] = 0;
}

void update(ll v, ll tl, ll tr, ll l, ll r, ll addend) {
    if (l > r)
        return;
    if (l == tl && tr == r) {
        t[v] += addend;
        lazy[v] += addend;
    } else {
        push(v);
        ll tm = (tl + tr) / 2;
        update(v*2, tl, tm, l, min(r, tm), addend);
        update(v*2+1, tm+1, tr, max(l, tm+1), r, addend);
        t[v] = min(t[v*2], t[v*2+1]);
    }
}

ll query(ll v, ll tl, ll tr, ll l, ll r) {
    if (l > r)
        return inf;
    if (l <= tl && tr <= r)
        return t[v];
    push(v);
    ll tm = (tl + tr) / 2;
    return min(query(v*2, tl, tm, l, min(r, tm)),
               query(v*2+1, tm+1, tr, max(l, tm+1), r));
}

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    ll total = 0;
    cin >> N >> M;
    for (ll i = 2; i<=M+1; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        a++;
        b++;
        intervals[b].push_back({a, c});
        total+=c;
    }
    
    for (int i = 2; i<=N+2; i++) {
        dp[i] = query(1, 1, N+2, 1, i-1);
        for (auto li:intervals[i]) {
            update(1, 1, N+2, 1, li.first-1, li.second);
        }
        update(1, 1, N+2, i, i, dp[i]);
    }
    cout << total-dp[N+2] << endl;
    return 0;
}





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

using namespace std;

typedef long long ll;

const int INF = 1e9+7;


int main()
{
    int n, m;
    cin >> n >> m;
    vector <vector <ll>> dp(n+1, vector <ll> (m+1, 0));

    dp[1][1] = 1;
    for (int i=1; i<=n; ++i)
    {
        for (int j=1; j<=m; ++j)
        {
            char t;
            cin >> t;
            if (t=='.')
                dp[i][j] += (dp[i-1][j] + dp[i][j-1])%INF;
            dp[i][j]%=INF;
        }
    }
    cout << dp[n][m];
    return 0;
}

Measured memory_bytes: 8064
a = int(input())
b = [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(b[a-1])

Measured memory_bytes: 38384
/*
すぬけくんは文字列 
s
 の連続した一部分(部分文字列という)を取り出して先頭が A であり末尾が Z であるような文字列を作ることにしました。
 すぬけくんが作ることのできる文字列の最大の長さを求めてください。 なお，
s
 には先頭が A であり末尾が Z であるような部分文字列が必ず存在することが保証されます。
*/

#include <iostream>
#include <string>
using namespace std;



int main() {
    string s;
    cin >> s;
    
    int a= 0;
    int z = 0;
    for (int i = 0; i < s.length(); ++i){
    	if (s[i]=='A'){
    		a = i;
    		break;
    	}
    }
    for (int i = 0; i < s.length(); ++i){
    	if (s[i]=='Z'){
    		z = i;
    	}
    	// cout << i;
    }
    cout << z - a + 1;

}

Measured memory_bytes: 640
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    long N = lread();
    if (N == 6)
    {
        writeln(1);
        return;
    }
    long x = (N * 2 + 10) / 11;
    if (5 <= x * 11 / 2 - N)
    {
        x--;
    }
    writeln(x);
}


Measured memory_bytes: 256
def solve():
    h, w = map(int, input().split())
    maze = []
    for i in range(h):
        maze.append(input())

    # for i in range(h):
    #     print(maze[i])

    nwall = 0
    for i in range(h):
        for j in range(w):
            if maze[i][j] == '#':
                nwall += 1

    q = []
    q.insert(0, (0,0))
    hist = [[0 for i in range(w)] for j in range(h)]
    hist[0][0] = 1


    while(len(q) > 0):
        x, y = q.pop()

        if x == w-1 and y == h-1:
            return h*w - nwall - hist[h-1][w-1]

        for i in range(0, 4):
            nx, ny = x+[1,0,-1,0][i], y+[0,1,0,-1][i]

            if nx<0 or nx>=w or ny<0 or ny>=h:
                continue
            if maze[ny][nx] == '#':
                continue
            if hist[ny][nx] >= 1:
                continue
            # print("x,y", x,y)
            # print("nx,ny", nx,ny)

            q.insert(0, (nx,ny))
            hist[ny][nx] = hist[y][x] + 1

    return -1


print(solve())

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S; cin >> S;
  int N = S.length();
  bool ans = true;
  for(int i = 0; i < N; i++){
    if(i % 2 == 0 && S[i] == 'L') ans = false;
    else if(i % 2 == 1 && S[i] == 'R') ans = false;
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
L=[	7151,8111,8741,8431,9241,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]
print(' '.join(map(str,L[:int(input())])))


Measured memory_bytes: 38256
INF = 10 ** 20
 
N = int(input())
coin_list = [1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)]
dp = [INF]*(N+1)
dp[0] = 0
 
for amount in range(1,N+1):
	for coin in coin_list[::-1]:
	    if amount-coin >= 0: dp[amount] = min(dp[amount], dp[amount-coin]+1)
 
print(dp[N])

Measured memory_bytes: 43100
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;
typedef pair<int, int> P;   //cost, to
static const int INF = 1e9;
static const int SIZE = 101;
int par[SIZE];
int rk[SIZE];
int d[SIZE];
int n;

struct edge
{
	int u, v, cost;
};

struct edge2
{
	int to, cost;
};

bool comp(const edge& e1, const edge& e2)
{
	return(e1.cost < e2.cost);
}

void init()
{
	for (int i = 0; i < SIZE; ++i)
	{
		par[i] = i;
		rk[i] = 0;
	}
}

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

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

bool same(int a, int b)
{
	return(find(a) == find(b));
}

int kruskal(vector<edge>& es)
{
	init();
	int res = 0;
	sort(es.begin(), es.end(), comp);
	for (int i = 0; i < es.size(); ++i)
	{
		edge e = es[i];
		if (!same(e.u, e.v))
		{
			unite(e.u, e.v);
			res += e.cost;
		}
	}
	return(res);
}

int prim(vector<edge2>* G)
{
	vector<bool> isUsed(n);
	for (int i = 0; i < n; ++i)
	{
		isUsed[i] = false;
	}
	priority_queue<P, vector<P>, greater<P> > pque;
	P p = make_pair(0, 0);
	pque.push(p);
	int res = 0;
	while (!pque.empty())
	{
		P p = pque.top();
		pque.pop();
		int v = p.second;
		if (isUsed[v])
		{
			continue;
		}
		isUsed[v] = true;
		res += p.first;
		for (int i = 0; i < G[v].size(); ++i)
		{
			edge2 e = G[v][i];
			pque.push(P(e.cost, e.to));
		}
	}
	return(res);
}


void solve()
{
	cin >> n;

// For Kruskal
	//vector<edge> es;
	//for (int i = 0; i < n; ++i)
	//{
	//	for (int j = 0; j < n; ++j)
	//	{
	//		int cost;
	//		cin >> cost;
	//		if (cost != -1)
	//		{
	//			edge e;
	//			e.u = i;
	//			e.v = j;
	//			e.cost = cost;
	//			es.push_back(e);
	//		}
	//	}
	//}
	//cout << kruskal(es) << endl;

// For Prim
	vector<edge2> G[SIZE];
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			int cost;
			cin >> cost;
			if (j >= i && cost != -1)
			{
				edge2 e1, e2;
				e1.to = j;
				e1.cost = cost;
				e2.to = i;
				e2.cost = cost;
				G[i].push_back(e1);
				G[j].push_back(e2);
			}
		}
	}
	cout << prim(G) << endl;
}

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

Measured memory_bytes: 1444
import fractions
n, X = map(int, input().split())
x = list(map(int, input().split()))
l = []
for _x in x:
        l.append(abs(_x - X))
gcd = l[0]
for i in range(1, n):
    gcd = fractions.gcd(gcd, l[i])
print(gcd)

Measured memory_bytes: 88852
#include <iostream>
#include <string>
using namespace std;
int main(){
string n[2];
int a,b,c,d,i;
cin >> n[0]>>n[1];
a = n[0].size();
b = n[1].size();
if (a > b){
cout << "GREATER";
return 0;
}
if (a < b){
cout << "LESS";
return 0;
}
if (a==b){
for (i=0;i<a;i++){
c = (int)(n[0].front()-'0');
d = (int)(n[1].front()-'0');
if (c > d){
cout << "GREATER";
return 0;
}
if (c<d){
cout << "LESS";
return 0;
}
}//for文終了
cout << "EQUAL";
return 0;
}//if文終了
return 0;
}//main 終了

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair< int , int > Pi;

int main()
{
  int H, W, N, mas[1000][1000], dp[1000][1000];

  while(cin >> H >> W >> N, H){
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        cin >> mas[i][j];
        dp[i][j] = 0;
      }
    }
    dp[0][0] = N - 1;
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        if(i + 1 < H) dp[i + 1][j] += (dp[i][j] + !mas[i][j]) >> 1;
        if(j + 1 < W) dp[i][j + 1] += (dp[i][j] + mas[i][j]) >> 1;
      }
    }
    int h = 0, w = 0;
    while(h != H && w != W){
      if((dp[h][w] + mas[h][w]) % 2) w++;
      else h++;
    }

    cout << h + 1 << " " << w + 1 << endl;

  }
}

Measured memory_bytes: 8972
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1001001001;
const ll LINF = 100100100100100100;

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

int main() {
  int N, M; cin >> N >> M;
  VVI G(N);
  rep(i,M){
    int a, b; cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
  }
  int S, T; cin >> S >> T;
  S--; T--;
  int dist[100005][3];
  rep(i,N)rep(j,3) dist[i][j]=INF;

  queue<P> q; q.push(P(S,0));
  dist[S][0] = 0;
  while(!q.empty()){
    int v = q.front().first;
    int l = q.front().second;
    q.pop();
    for(int u : G[v]){
      int nl = (l+1)%3;
      if(dist[u][nl]!=INF) continue;
      dist[u][nl] = dist[v][l]+1;
      q.push(P(u,nl));
    }
  }
  int ans = dist[T][0];
  if(ans==INF) ans = -1;
  else ans /= 3;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6912
#include <iostream>

int main() {
  char C11, C12, C13;
  char C21, C22, C23;

  std::cin >> C11 >> C12 >> C13;
  std::cin >> C21 >> C22 >> C23;

  if ( C11 == C23 && C12 == C22 && C13 == C21 ) {
    std::cout << "YES" << std::endl;
  } else {
    std::cout << "NO" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();

        int r = in.nextInt();
        int c = in.nextInt();

        int[] rSum = new int[c + 1];

        for (int i = 0; i < r; i++) {
            int cSum = 0;
            for (int j = 0; j < c; j++) {
                int num = in.nextInt();
                cSum += num;
                rSum[j] += num;
                rSum[c] += num;
                sb.append(num).append(" ");
            }
            sb.append(cSum).append("\n");
        }
        for (int i = 0; i < c; i++) {
            sb.append(rSum[i]).append(" ");
        }
        sb.append(rSum[c]).append("\n");

        System.out.print(sb.toString());
    }
}

Measured memory_bytes: 30436
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n, k; cin>>n>>k;

    int maxk = (n - 1) * (n - 2) / 2;

    if(k > maxk){
        cout << -1 << endl;
        return 0;
    }

    int rest = maxk - k;

    vector<P> ans;
    for(int i=2; i<=n; i++){
        ans.emplace_back(1, i);
    }

    for(int i=2; i<=n; i++){
        for(int j=i+1; j<=n; j++){
            if(rest > 0){
                ans.emplace_back(i, j);
            }

            rest--;
        }
    }

    cout << ans.size() << endl;
    for(auto i : ans){
        cout << i.first << " " << i.second << endl;
    }

    return 0;
}

Measured memory_bytes: 384
fun main(args: Array<String>){
  val a = readLine()!!.toInt()
  val b = readLine()!!.toInt()
  val c = readLine()!!.toInt()
  val d = readLine()!!.toInt()
  val e = readLine()!!.toInt()
  val k = readLine()!!.toInt()
  
  val allOk = isOk(a, b, k) &&
  isOk(a, c, k) &&
  isOk(a, d, k) && 
  isOk(a, e, k) &&
  isOk(b, c, k) &&
  isOk(b, d, k) &&
  isOk(b, e, k) &&
  isOk(c, d, k) &&
  isOk(c, e, k) &&
  isOk(d, e, k) 
  
  println(if(allOk) "Yay!" else ":(")
}

fun isOk(n: Int, m: Int, k: Int): Boolean{
	val r = if(n >= m) n - m else m - n
	return k >= r
}

Measured memory_bytes: 33568
from collections import Counter,defaultdict,deque
from heapq import heapify,heappop,heappush
import sys,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

def conb(n,r): 
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n,p = inpl()
a = inpl()
res = 0
odd = 0
even = 0
for i in a:
    if i%2:
        odd += 1
    else:
        even += 1
# print(odd,even)
tmp = 0 if p == 0 else 1
for i in range(tmp,odd+1,2):
    for j in range(0,even+1):
        res += conb(odd,i) * conb(even,j)
print(res)

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

class BIT{
    long long *tree;
    int depth;

    public:
    BIT(unsigned int n){
        for(depth=0;(1<<depth)<n;depth++) ;
        tree = new long long[1<<depth]();
    }

    void add(unsigned int index, long long value){
        index++;
        for(;index<=(1<<depth);index+=index&-index){
            tree[index-1]+=value;
        }
    }

    long long sum(unsigned int index){
        index++;
        long long s=0;
        for(;index>0;index-=index&-index){
            s+=tree[index-1];
        }

        return s;
    }

    long long sum(unsigned int left, unsigned int right){
        return sum(right-1) - sum(left-1);
    }

    ~BIT(){
        delete[] tree;
    }
};
/*
    BIT bit(N);     // 長さ N の列について管理
    bit.add(i, v);  // 列(0-indexed)の i 番目に v を加算
    bit.sum(i);     // 列(0-indexed)の 0 番目から i 番目までの i+1 個の要素の和を返す
                    // i 番目も和に*含まれる*ことに注意
    bit.sum(l,r);   // 列の i ∈ [l, r) 番目の要素の和を返す
                    // r 番目は和に*含まない*ことに注意
*/

int pos[4001], num[4001];
int cost[4001][2001];
int dp[2001][2001];

int main(){
    int N;
    cin >> N;

    for(int i=1;i<=2*N;i++){
        char c;
        int a;
        cin >> c >> a;
        if(c=='B') a+=N;
        pos[a]=i;
        num[i]=a;
    }

    for(int ac=0;ac<=N;ac++){
        BIT bit_w(2*N+1), bit_b(2*N+1);
        for(int i=ac+1;i<=N;i++){
            bit_w.add(pos[N+i], 1);
            bit_b.add(pos[i], 1);
        }
        for(int n=N;n>=1;n--){
            cost[n][ac]=bit_w.sum(pos[n]);
            bit_w.add(pos[n],1);
            cost[N+n][ac]=bit_b.sum(pos[N+n]);
            bit_b.add(pos[N+n],1);
        }
    }

    dp[0][0]=0;
    for(int j=1;j<=N;j++) dp[0][j]=dp[0][j-1]+cost[N+j][0];
    for(int i=1;i<=N;i++) dp[i][0]=dp[i-1][0]+cost[i][0];
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            dp[i][j]=min(dp[i-1][j]+cost[i][j], dp[i][j-1]+cost[N+j][i]);
        }
    }
    cout << dp[N][N] << endl;

    return 0;
}

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

using namespace std;

int main(){
  int D, G;
  cin >> D >> G;
  
  vector<pair<long, long>> v(D);
  for(int i=0; i<D; i++) cin >> v[i].first >> v[i].second;

  long minc = 100000;
  for(long bit=0; bit<(1<<D); bit++){
    long point = 0;
    long count = 0;
    long addIndex=-1;
    for(long i=0; i<D; i++){
      if(bit & (1<<i)){
        point += v[i].first * 100 * (i+1) + v[i].second;
        count += v[i].first;
      }else{
        addIndex = i;
      }
    }
    
    if (point >= G){
      minc = min(minc, count);
      continue;
    }
    
    if(addIndex!=-1){
      long sub = G - point;
      long addcount = (sub + 100 * (addIndex+1) - 1)/(100 * (addIndex+1));
      if (addcount > v[addIndex].first-1) continue;
      minc = min(minc, count + addcount);
    }
  }
  
  cout << minc;
  return 0; 
}

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

// headers {{{
using namespace std;
// using namespace rel_ops;
 
const double pi=acos(-1.0);
const double eps=1e-11;
const int INF=0x7FFFFFFF;
template<class T> inline bool checkmin(T &a,T b){return b<a?a=b,1:0;}
template<class T> inline bool checkmax(T &a,T b){return b>a?a=b,1:0;}
template<class T> inline T sqr(T x){return x*x;}
template<class T> inline bool bit(T a, int b) {return (a>>b)&1;}
inline int popcount(int n) { return __builtin_popcount(n); }
inline int popcount(long long n) { return __builtin_popcountll(n); }
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define eb(args...) emplace_back(args)
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ff first
#define ss second
#define sz(g) int(g.size())
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
#ifdef LOCAL
#define dout cerr 
void out() { dout << endl; }
template<typename A, typename... B> void out(A a, B... b) { dout << ' ' << a; out(b...); }
#define dbg(args...) dout << __LINE__ << ":(" << #args << ") -> ", out(args)
template<class T>void show(T a, int n){for(int i=0; i<n; ++i) cout<<a[i]<<' '; cout<<endl;}
template<class T>void show(T a, int r, int l){for(int i=0; i<r; ++i)show(a[i],l);cout<<endl;}
constexpr bool local = true;
#else
#define dbg(...)
#define dout if(true);else cerr
#define out(...)
#define show(...)
constexpr bool local = false;
#endif
// }}}

int main() {
    int64 a, b, v, w, t;
    while (cin >> a >> v >> b>> w >> t) {
        int64 del = abs(a-b);
        if (a == b) {
            cout << "YES\n"; continue;
        }
        if (v < w) {
            cout << "NO\n"; continue;
        }
        if ((v-w) * t >= del) {

            cout << "YES\n"; continue;
        }
        cout << "NO\n"; continue;
    }
    return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

int fastpow(int x, int n, int m){
    int a = 1;
    IREP(i, 64){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

vec yakusu(int N){
    vec y(0);
    for(int i = 1; i * i <= N; i++) if(N % i == 0) y.push_back(i);
    vec y2 = y;
    IREP(i, y.size()) if(y[i] * y[i] < N) y2.push_back(N / y[i]);
    return y2;
}

signed main(){

    int S; cin >> S;
    vec y = yakusu(S);
    int mod = 1000000007;

    int ans1 = 0, ans2 = 0, ans3 = 0;

    //f(l)=f(r)の場合
    for(int t: y){
        int fl = S / t;
        // t <= 9*10^(fl-1)なら足す
        if(fl >= 9 || t <= 9 * fastpow(10, fl - 1, INF)){
            ans1 += 9 * fastpow(10, fl - 1, mod) - t + 1 + mod;
            ans1 %= mod;
        }
    }
    //cout << ans1 << endl;

    //f(l)<f(r)<=8の場合
    //l<10^7まで
    vec pow10(10, 1);
    FOR(i, 1, 10) pow10[i] = 10 * pow10[i - 1];
    int l = 1, r = 1, s = 1;
    int fl = 1, fr = 1;
    while(l < pow10[7] && r < pow10[8] && l <= r){
        while(s < S && r < pow10[8]){
            r += 1;
            fr = Upper_bound(pow10, r);
            s += fr;
        }
        if(s == S && fl != fr && r < pow10[8]){
            ans2 = (ans2 + 1) % mod;
        }
        s -= fl;
        l += 1;
        fl = Upper_bound(pow10, l);
    }
    //cout << ans2 << endl;

    //f(l)>=9 f(r)=f(l)-1
    //l>=10^8より足りなくなることはない
    int tmax = S / 8;
    ans3 = tmax;
    for(int d: y) if(d <= tmax) ans3--;
    //cout << ans3 << endl;

    int ans = (ans1 + ans2 + ans3) % mod;
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	
	int x;
	int i=1;
	
	while(1){
		scanf("%d",&x);
		if (x == 0) {
			break;
		}
		printf("Case %d: %d\n",i,x);
		i++;
	}
	
	return 0;
}

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

int main() {
    char c;
    cin >> c;
    string str = "aiueo";
    if (count(str.begin(), str.end(), c) > 0) {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
A, B, C, D = [int(c) for c in input().split()]

p, q = max(C, D), min(C, D)
while q: p, q = q, p%q
E = C*D//p

Cmult_ge_A = A if A%C==0 else A+C-A%C
Dmult_ge_A = A if A%D==0 else A+D-A%D
Emult_ge_A = A if A%E==0 else A+E-A%E

nC = (B-Cmult_ge_A)//C+1
nD = (B-Dmult_ge_A)//D+1
nE = (B-Emult_ge_A)//E+1

print(B-A+1-nC-nD+nE)

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

int c(int a,int b)
{
    return (a+b);
}

int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    if(c(n,a)>=b){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 888
// https://atcoder.jp/contests/abc075/tasks/abc075_c

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int N, M, a, b, cnt;
unordered_map<int, set<int>> g;
vector<pair<int, int>> s;

void check(int n, pair<int, int> &p, set<int> &v)
{
  for (auto &d : g[n])
  {
    if (p.first == min(n, d) && p.second == max(n, d))
      continue;

    auto r = v.insert(d);
    if (r.second)
      check(d, p, v);
  }
  return;
}

int main()
{
  cnt = 0;
  cin >> N >> M;
  REP(i, N)
  {
    g[i] = {};
  }
  REP(i, M)
  {
    cin >> a >> b;
    if (b < a)
      swap(a, b);
    s.push_back(make_pair(a - 1, b - 1));
    g[a - 1].insert(b - 1);
    g[b - 1].insert(a - 1);
  }

  for (auto &ss : s)
  {
    set<int> v = {0};
    check(0, ss, v);
    if (v.size() < N)
      cnt++;
  }

  cout << cnt << '\n';

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1e9 + 7;
int N;
int x[100010];
ll fct[100010] = {1};

int main(){
    cin >> N;
    ll base = 1;
    for(int i = 0; i < N; i++){
         fct[i + 1] = fct[i] * (ll)(i + 1) % mod;
        cin >> x[i];
    }
    ll ans = 1;
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(cnt * 2 + 1 <= x[i]) cnt++;
        else ans = ans * (cnt + 1) % mod;
    }
    for(int i = 1; i <= cnt; i++){
        ans = ans * (ll)i % mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
from collections import Counter

n=int(input())
l=[int(i) for i in input().split()]
n=len(l)
l1=l[0::2]
l2=l[1::2]
c1=Counter(l1).most_common(2)
c2=Counter(l2).most_common(2)

if c1[0][0]!=c2[0][0]:
    ans=n-c1[0][1]-c2[0][1]
    print(int(ans))
else:
    if len(c1)==1 or len(c2)==1:
        print(n//2)
    else:
        res1=n-c1[1][1]-c2[0][1]
        res2=n-c1[0][1]-c2[1][1]
        ans=min(res1,res2)
        print(int(ans))


Measured memory_bytes: 15972
import decimal
import math

N = int(input())
i = 2
counter = {}
while i * i < N:
  cnt = 0
  while N % i == 0:
    cnt += 1
    N //= i
  counter[i] = cnt
  i += 1

if N != 1:
  counter.setdefault(N, 0)
  counter[N] += 1
#print (counter)

ans = 0

for i, v in counter.items():
  p = 1
  while True:
    if v - p >= 0:
      #print (i**p)
      v -= p
      ans += 1
      p += 1
    else:
      break

print (ans)

Measured memory_bytes: 93408
package main

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

// AtCoder Functions
var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()

	B := make([]int, N-1)
	for i := 0; i < N-1; i++ {
		B[i] = nextInt()
	}

	A := make([]int, N)
	A[0] = B[0]
	if N > 2 {
		if B[0] > B[1] {
			A[1] = B[1]
		} else {
			A[1] = B[0]
		}
		for i := 2; i < N-1; i++ {
			if B[i] >= B[i-1] {
				A[i] = B[i-1]
			} else {
				A[i] = B[i]
			}
		}
		A[N-1] = B[N-2]
	} else {
		A[1] = B[0]
	}

	ret := 0
	for i := 0; i < N; i++ {
		ret += A[i]
	}
	fmt.Println(ret)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>

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

int main() {
  int N;

  std::cin >> N;
  std::vector<int> A(N);
  std::vector<int> G_ord(N+1);

  std::cin >> A[0];
  G_ord[0] = A[0];
  G_ord[1] = A[0];

  for (int i=1; i<N; i++) {
    std::cin >> A[i];
    G_ord[i+1] = gcd(G_ord[i], A[i]);
  }

  std::vector<int> G_rev(N+1);
  G_rev[N] = A[N-1];
  G_rev[N-1] = A[N-1];

  for (int i=N-2; i>=0; i--) {
    G_rev[i] = gcd(G_rev[i+1], A[i]);
  }

  int ans = G_rev[1];

  for (int i=1; i<N-1; i++) {
    ans = std::max(ans, gcd(G_ord[i], G_rev[i+1]));
  }

  ans = std::max(ans, G_ord[N-1]);

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int N;

void maxHeap(vector<ll>& a, ll x){
	int l = x*2;
	int r = x*2+1;
	if(l > N && r > N) return;
	int largest = 0;
	if(l<=N && a[l] > a[x]){
		largest = l;
	}else{
		largest = x;
	}
	if(r<=N && a[r] > a[largest]) largest = r;
	if(largest != x){
		int y = a[x];
		a[x] = a[largest];
		a[largest] = y;
		maxHeap(a, largest);
	}
}

int main(){
	cin >> N;
	vector<ll> a(N+1);
	for(int i = 1;i<= N;i++){
		cin >> a[i];
	}
	for(int i = N/2; i >=1; i--){
		maxHeap(a, i);
	}
	rep(i, N){
		cout <<" " << a[i+1];
	}
	cout << endl;
}



Measured memory_bytes: 6680
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

mia = sorted([i for i in a if i < 0], reverse=True)
pla = sorted([i for i in a if i >= 0])

cnt = 1
if len(pla) == 0 and k % 2 == 1:
    for i in mia[:k]:
        cnt = cnt * i % mod
else:
    while k > 0:
        if k == 1 or len(mia) <= 1:
            if len(pla) == 0:
                cnt *= mia.pop()
            elif len(pla) > 0:
                cnt *= pla.pop()
            k -= 1
        elif len(pla) <= 1:
            cnt *= mia.pop() * mia.pop()
            k -= 2
        elif pla[-1] * pla[-2] > mia[-1] * mia[-2]:
            cnt *= pla.pop()
            k -= 1
        elif pla[-1] * pla[-2] <= mia[-1] * mia[-2]:
            cnt *= mia.pop() * mia.pop()
            k -= 2
        cnt %= mod
print(cnt)


Measured memory_bytes: 31684
monsu, teisyutu = gets.chomp.split(' ').map{|n| n.to_i}

ac = 0
pe = 0
hash = {}


while true
  row = gets
  if row == nil
    break
  end
  q, result = row.chomp.split(' ')
  q = q

  if hash[q] == nil
    hash[q] = {}
  end

  if hash[q][:passed] != true
    if result == 'WA'
      if hash[q][:wa] == nil then
        hash[q][:wa] = 1
      else
        hash[q][:wa] = hash[q][:wa] + 1
      end
    elsif result == 'AC'
      hash[q][:passed] = true
      ac = ac + 1
      if hash[q][:wa] == nil then
        hash[q][:wa] = 0
      end
      pe = pe + hash[q][:wa]
    end
  end
end

puts "#{ac} #{pe}"

Measured memory_bytes: 43132
using System;
using System.Linq;
using System.Collections.Generic;

namespace myApp
{
    class Program
    {
        static bool LinearSearch(int[] A, int n, int key) {
            int i = 0;
            A[n] = key; // 番兵
            while (A[i] != key) i++;
            return i != n;
        }
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var S = new int[100000 + 1];
            var temp = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToArray();
            Array.Copy(temp, S, n);

            var q = int.Parse(Console.ReadLine());
            var T = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToArray();

            var sum = 0;
            for (int i = 0; i < q; i++) {
                if (LinearSearch(S, n, T[i])) sum++;
            }

            Console.WriteLine(sum);
        }
    }
}



Measured memory_bytes: 18320
#include<iostream>
using namespace std;
int main () {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  for (int i = 0; i <= N; i ++) {
    for (int j = 0; j <= N; j ++) {
      int A = R * i + G * j;
      int n = N - A;
      //cout << n << endl;
      if (n >= 0 && n % B == 0) ans ++;
    }
  }
  cout << ans << endl;
}



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

using i64 = int64_t;

vector<i64> divisor(i64 n) {
    vector<i64> res;
    for (i64 i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i)
                res.push_back(n / i);
        }
    }
    return res;
}

constexpr i64 MAX = 1e5;

int main(){
    int n;
    cin >> n;
    for(i64 i=1;i<=MAX;++i){
        auto div = divisor(i);
        if((i64)div.size() == n){
            cout << i << endl;
            break;
        }
    }

    return 0;
}



Measured memory_bytes: 3136
#include<iostream>
#include<cstdio>
using namespace std;
static const int MAX=100000;

int parent(int i){return i/2;}
int left(int i){return i*2;}
int right(int i){return i*2+1;}

int main(){
    int H,A[MAX+1];
    cin>>H;

    for(int i=1;i<=H;i++)cin>>A[i];
    for(int i=1;i<=H;i++){
        cout<<"node "<<i<<": key = "<<A[i]<<", ";                                                 
        if(parent(i)>=1)
            cout<<"parent key = "<<A[parent(i)]<<", ";
        if(left(i)<=H)
            printf("left key = %d, ",A[left(i)]);
        if(right(i)<=H)
            printf("right key = %d, ",A[right(i)]);
        putchar('\n');
    }   
    return 0;
    
}



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

int main(){
    int k ,s;
    cin >> k >> s;
    int ans = 0;
    for(int x = 0; x <= k; ++x){
        for(int y = 0; y <= k; ++y){
            int z = s - x - y;
            if(0 <= z && z <= k)ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll a,b,ans;
	char c;
	int d;
	cin>>a>>b>>c>>d;
	b = b*100;
	b += d;
	ans = (a*b)/100;
	cout<<ans<<endl;
}


Measured memory_bytes: 3628