akhauriyash/Code-Regression huggingface dataset:
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


void Main(){
    int N;
    cin >> N;
    if(N == 1){
        cout << 1.0 << el;return;
    }
    int O, E;
    O=E=0;
    FOR(i, N+1, 1){
        if(i%2){
            O++;
        }else{
            E++;
        }
    }
    cout << (double)O/(O+E) << el;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N);
    ll S(0);
    rep(i,N){
        cin >> A[i];
        S += A[i];
    }
    vector<ll> d;
    for(int i=1;i*i<=S;i++){
        if(S%i==0){
            d.push_back(i);
            d.push_back(S/i);
        }
    }
    int M = d.size();
    vector<ll> a(N);
    ll a_sum,sum_left,sum_right,target_d,d_max(0);
    for(int i=0;i<M;i++){
        target_d = d[i];
        a_sum = 0;
        for(int j=0;j<N;j++){
            a[j] = A[j] % target_d;
            a_sum += a[j];
        }
        sort(ALL(a));
        sum_left = a_sum;
        sum_right = 0;
        ll swap_num = 1e18;
        for(int j=N-1;j>=0;j--){
            sum_left -= a[j];
            sum_right += target_d - a[j];
            if(abs(sum_left - sum_right) % target_d == 0) swap_num = min(swap_num,max(sum_left,sum_right));
        }
        if(swap_num <= K )d_max = max(d_max,target_d);
    }
    cout << d_max << endl;
}

Measured memory_bytes: 256
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});

let numComp = 0;
process.stdin.on('end', () => {
  const [nums] = content
    .trim()
    .split('\n')
    .slice(1)
    .map(nums => nums.split(' ').map(n => +n));
  mergeSort(nums, 0, nums.length);
  console.log(nums.join(' '));
  console.log(numComp);
});

// merge in-place
const merge = (nums, left, mid, right) => {
  const l = nums.slice(left, mid);
  const r = nums.slice(mid, right);
  l.push(Infinity);
  r.push(Infinity);
  let i = j = 0;
  for (let k = left; k < right; k++) {
    nums[k] = l[i] < r[j] ? l[i++] : r[j++];
    numComp++;
  }
};

const mergeSort = (nums, left, right) => {
  if (left + 1 < right) {
    const mid = Math.floor((left + right) / 2);
    mergeSort(nums, left, mid);
    mergeSort(nums, mid, right);
    merge(nums, left, mid, right);
  }
};



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

int main() {
	int n, h, w, m  = 0;

	cin >> n >> h >> w;

	for(int i = 0; i < n; i++){
		int a, b;
		cin >> a >> b;
		if(h <= a && w <= b)
			m++;
	}

	cout << m << endl;

	return 0;
}

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

int main()
{
  int h,w;
  cin>>h>>w;
  int dist[10][10];
  int i,j,k;
  for(i=0;i<10;i++)
    for(j=0;j<10;j++)
    scanf("%d",&dist[i][j]);
  int V = 10;
  for (k = 0; k < V; k++)
    {
        // Pick all vertices as source one by one
        for (i = 0; i < V; i++)
        {
            // Pick all vertices as destination for the
            // above picked source
            for (j = 0; j < V; j++)
            {
                // If vertex k is on the shortest path from
                // i to j, then update the value of dist[i][j]
                if (dist[i][k] + dist[k][j] < dist[i][j])
                    dist[i][j] = dist[i][k] + dist[k][j];
            }
        }
    }

    int ans = 0,xx;

    for(i=0;i<h;i++)
        for(j=0;j<w;j++)
    {

        scanf("%d",&xx);
        if(xx!=-1)
        ans+= dist[xx][1];
    }

    printf("%d\n",ans);


}





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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
  //頂点数と辺数
  int N,M; cin>>N>>M;
  //グラフ情報
  vector<ll> A(M),B(M),C(M);
  rep(i,M){
    cin>>A.at(i)>>B.at(i)>>C.at(i);
    C.at(i)*=(-1);
}
  //視点からの距離
  vector<ll> dist(N,INF);
  //初期化
  dist.at(0)=0;

  for(int loop = 1; loop <= N-1; loop++){
    for(int i = 0; i < M; i++){
      if(dist.at(A.at(i)-1)==INF)continue;
      dist.at(B.at(i)-1)=min(dist.at(A.at(i)-1)+C.at(i),dist.at(B.at(i)-1));
    }
  }

  ll ans = -dist.at(N-1);
  //cout<<ans<<endl;

  //負の閉路の検出
  vector<bool> NC(N,false);//negative cycle

  for(int loop = 1; loop <= N; loop++){
    for(int i = 0; i < M; i++){
      if(dist.at(A.at(i)-1)==INF)continue;
      if(dist.at(B.at(i)-1)>dist.at(A.at(i)-1)+C.at(i)){
        dist.at(B.at(i)-1)=dist.at(A.at(i)-1)+C.at(i);
        NC.at(B.at(i)-1)=true;
      }
      if(NC.at(A.at(i)-1)==true)NC.at(B.at(i)-1)=true;
    }
  }

  if(NC.at(N-1))cout<<"inf"<<endl;
  else cout<<ans<<endl;
    
  return 0;
}

Measured memory_bytes: 256
N=int(input())
m_count=0
a_count=0
r_count=0
c_count=0
h_count=0

for i in range(N):
    name=input()
    if name[0]=='M':
        m_count+=1
    if name[0]=='A':
        a_count+=1
    if name[0]=='R':
        r_count+=1
    if name[0]=='C':
        c_count+=1
    if name[0]=='H':
        h_count+=1

x=[]
x.append(m_count)
x.append(a_count)
x.append(r_count)
x.append(c_count)
x.append(h_count)
c=0
for i in range(len(x)):
    for j in range(i+1,len(x)):
        for k in range(j+1,len(x)):
            c+=x[i]*x[j]*x[k]
print(c)

Measured memory_bytes: 3188
//特殊な状態の列挙
#include <iostream>
#include <vector>
#include <string>
#include <utility>
using namespace std;

string s, t, buf;

inline bool check(int i){
  for(int j=0; j<t.size(); j++){
    if(s[i+j] != t[j] && s[i+j] != '?') return false;
  }
  return true;
}

int main(){
  //input
  cin >> s >> t;
  int count=0;
  bool check_mark=false;

  for(int i=s.size()-t.size(); i>=0; i--){
    if(check(i)) {
      s.replace(i, t.size(), t);
      check_mark = true;
      break;
    }
  }
  if(!check_mark) {cout << "UNRESTORABLE" << endl; return 0;}

  for(int i=0; i<s.size(); i++){
    if(s[i] == '?') s[i] = 'a';
  }

  cout << endl << s << endl;
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;


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

  map<char, int> cnt;
  map<char, int> empty;
  vector<map<char, int>> left_cnt(n, map<char, int>());
  vector<map<char, int>> right_cnt(n, map<char, int>());
  map<string, int> exist;

  rep(i,n){
    left_cnt[i] = cnt;
    cnt[s[i]]++;
  }
  cnt = empty;
  rep(i,n){
    right_cnt[n-i-1] = cnt;
    cnt[s[n-i-1]]++;
  }

  int ans = 0;
  repm(i,1,n-1){
    rep(j,10){
      rep(k,10){
        char left = '0'+j;
        char right = '0'+k;
        string tmp = "";
        tmp.push_back(left);
        tmp.push_back(s[i]);
        tmp.push_back(right);
        if(left_cnt[i][left] && right_cnt[i][right] && !exist[tmp]){
          ans++;
          exist[tmp]++;
        }
      }
    }
  }

  cout << ans << endl;

}

Measured memory_bytes: 31360
#include <cstdio>

int main() {
	int a, b;
  	scanf(" %d %d", &a, &b);
  
  	if (a%2 == 1 && b%2 == 1) {
     	printf("Odd\n"); 
    } else {
     	printf("Even\n"); 
    }
  
}

Measured memory_bytes: 128
a=int(input())
if a<40:
    a=40   
b=int(input())
if b<40:
    b=40  
c=int(input())
if c<40:
    c=40
d=int(input())
if d<40:
    d=40
e=int(input())
if e<40:
    e=40   
print(int((a+b+c+d+e)/5))


Measured memory_bytes: 5592
#include<stdio.h>

const int mod = 1000000007;
int dp[3005][3005];

char brk[3005];

void add(int& x, int y) {
	x = (x + y) % mod;
}

int main() {
	int n; scanf("%d", &n);
	scanf("%s", brk);
	dp[1][1] = 1;
	for (int i = 2; i <= n; i++) {
		int s = 0;
		if (brk[i-2] == '<') {
			//dp[i][j]=Σdp[i-1][k],k<j
			for (int j = 2; j <= i; j++) {
				add(dp[i][j], dp[i][j - 1]);
				add(dp[i][j], dp[i - 1][j - 1]);
			}
		}
		else {
			//dp[i][j]=Σdp[i-1][k],k>=j

			for (int j = i - 1; j; j--) {
				add(dp[i][j], dp[i][j + 1]);
				add(dp[i][j], dp[i - 1][j]);
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)add(ans, dp[n][i]);
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 34048
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int mod = 1000000007;

int main(){
    string s;
    cin>>s;
    bool f=false;
    rep(i,s.size()-1){
        if(s[i]==s[i+1]) f=true;
    }
    if(f) cout<<"Bad"<<endl;
    else cout<<"Good"<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
// 1にしないbit全探索
int main()
{
  ll N, K; cin >> N >> K;
  ll A[N], B[N]; FOR(i,0,N) cin >> A[i] >> B[i];
  ll ans = 0;
  FOR(j,0,32) {
    // jより上は1のとこしかだめ
    if((K>>j)&1) {
      ll mx = 0;
      FOR(l,0,N) {
        bool ok = true;
        FOR(i,j,32) {
          if((!((K>>i)&1)||(i==j)) && (A[l]>>i)&1) ok = false;
        }
        if(ok) mx += B[l];
      }
      ans = max(ans, mx);
    }
  }
  ll mx = 0;
  FOR(l,0,N) {
    bool ok = true;
    FOR(i,0,32) {
      if(!((K>>i)&1) && (A[l]>>i)&1) ok = false;
    }
    if(ok) mx += B[l];
  }
  ans = max(ans, mx);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(){
  int x, y, i, work;
  while(i < 3000){
    scanf("%d %d", &x, &y);
    if(x == 0 && y == 0)break;
    if(x > y){
      work = x;
      x = y;
      y = work;
    }      
    printf("%d %d\n", x, y);
    i++;
  }
  return 0;
}


Measured memory_bytes: 2104
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[derive(Debug)]
struct RL {
    index: usize,
    r_count: usize,
    l_count: usize,
}

impl RL {
    fn new(index: usize) -> RL {
        RL { index: index, r_count: 0, l_count: 0 }
    }
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();

    let mut v = vec![];
    let mut rl = RL::new(0);
    for (i, &c) in s.iter().enumerate() {
        match c {
            'R' => {
                if rl.l_count > 0 {
                    v.push(rl);
                    rl = RL::new(i);
                } else {
                }
                rl.r_count += 1;
            },
            'L' => {
                rl.l_count += 1;
            },
            _ => {},
        }

    }
    v.push(rl);

    let mut ans = vec![0usize; s.len()];

    for rl in v.iter() {


        ans[rl.index+rl.r_count-1] += rl.r_count / 2 + rl.r_count % 2;
        ans[rl.index+rl.r_count] += rl.r_count / 2;
        
        ans[rl.index+rl.r_count-1] += rl.l_count / 2;
        ans[rl.index+rl.r_count] += rl.l_count / 2 + rl.l_count % 2;
    }

    let ans = ans.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(" ");
    println!("{}", ans);

}


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

int gcd(int a, int b){
    while(a != b){
        if(a > b) a = a - b; else b = b - a;
    }
    return a;
}

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

int main(){
    int h, w;
    while(true){
char torus[10][20];
        string str[2048];
        bool ok[2048];
        int num = 0;

        for(int i=0; i<2048; ++i){
            str[i] = "";
            ok[i] = true;
        }

        cin >> h >> w;
        if(h==0 && w==0) break;

        int cml = lcm(w, h);

        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                cin >> torus[i][j];
            }
        }

        //一番長い文字列をつくる

        for(int y=0; y<h; ++y){
            for(int x=0; x<w; ++x){
                for(int i=0; i<h; ++i){
                    str[num] += torus[(y+i)%h][x];
                    str[num+1] += torus[h-(y+i)%h-1][x];
                }
                num += 2;
            }
        }
        for(int y=0; y<h; ++y){
            for(int x=0; x<w; ++x){
                for(int i=0; i<w; ++i){
                    str[num] += torus[y][(x+i)%w];
                    str[num+1] += torus[y][w-(x+i)%w-1];
                }
                num += 2;
            }
        }
        for(int y=0; y<h; ++y){
            for(int x=0; x<w; ++x){
                for(int i=0; i<cml; ++i){
                    str[num] += torus[(y+i)%h][(x+i)%w];
                    str[num+1] += torus[(y+i)%h][w-(x+i)%w-1];
                    str[num+2] += torus[h-(y+i)%h-1][(x+i)%w];
                    str[num+3] += torus[h-(y+i)%h-1][w-(x+i)%w-1];
                }
                num += 4;
            }
        }


        string result = "";

        sort(str, str+num);

        for(int j=num-1; j>0; --j){
            if(str[j][0] != str[j-1][0]){
                ok[j] = false;
            }
        }

        for(int i=1; i<cml; ++i){
            for(int j=num-1; j>0; --j){
                if(ok[j] && str[j].length() >= i && str[j-1].length() >= i){
                    if(str[j][i] == str[j-1][i]){
                        result = str[j];
                        result.resize(i+1);
                    }else{
                        ok[j] = false;
                    }
                }
            }
        }

        cout << ((result.length() == 0) ? "0" : result) << endl;

    }

    return 0;
}

Measured memory_bytes: 1516
# -*- coding: utf-8 -*-
import numpy as np
N = input()
t, x, y = [0], [0], [0]
for _ in range(N):
    _t, _x, _y = map(int, raw_input().split())
    t.append(_t)
    x.append(_x)
    y.append(_y)

txy = np.array([[_t, _x, _y] for _t, _x, _y in zip(t, x, y)], dtype=np.int64)

dm = np.diff(txy, axis=0)

for d in dm:
    total = np.abs(d[1]) + np.abs(d[2])
    if d[0] < total or (d[0] - total) % 2 != 0:
        print 'No'
        exit()

print 'Yes'


Measured memory_bytes: 37020
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);

	int n, p;
	cin >> n >> p;
	string s;
	cin >> s;
	ll res = 0;
	if (p == 2 || p == 5) {
		FORD(i, sz(s), 0) {
			int cyf = (s[i] - '0');
			if (cyf % p == 0) {
				res += (i + 1);
			}
		}
		cout << res << endl;
		return 0;
	}
	map<int, int> wys;
	int mn = 1;
	int curr = 0;
	wys[0] = 1;
	FORD(i, sz(s), 0) {
		curr = (mn * (s[i] - '0') + curr) % p;
		// printf("curr: %d, adding: %d\n", curr, wys[curr]);
		mn = (mn * 10) % p;
		res += wys[curr];
		++wys[curr];
	}
	cout << res << endl;
}

Measured memory_bytes: 916
/*  ex6_2
    B30095    */
#include <stdio.h>
#include <string.h>
#define LEN 100

int main(void){
    int len;
    char str[LEN];
    scanf("%s", str);
    len = strlen(str);
    printf("%c%d%c", str[0], len - 2, str[len - 1]);  // chars between the first and the last are replaced by its numbers. ex: "example" -> "e5e"

    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer N = Integer.parseInt(scan.next());
        Integer p[] = new Integer[N];
        
        for(int i=0;i<N;i++)   
            p[i] = Integer.parseInt(scan.next());

        int tmp = p[0];
        for(int i=1;i<N;i++){
            tmp = tmp ^ p[i];
        }
    
        if(tmp == 0)
            System.out.println("Yes");
        else
            System.out.println("No");

    }

}

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

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {
            var nk = Input3();
            var h = Input3();
            var ans = 0L;

            for(int i = 0;i < nk[0]; i++)
            {
                if (h[i] >= nk[1]) ans++;  
            }

            Console.WriteLine(ans);


        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }
    }
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int h, w;
    cin >> h >> w;
    string s, t = "";
    rep(i, w + 2) t += '#';
    OP(t);
    rep(i, h)
    {
        cin >> s;
        s = '#' + s + '#';
        OP(s);
    }
    OP(t);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define LL long long
LL N, Z, W;
LL A[2010];
LL ans;
int main() {
	std::cin >> N >> Z >> W;
	for (int i = 0; i < N; i++) {
		std::cin >> A[i];
	}
	if (N > 1) {
		ans = std::abs(A[N - 2]-A[N - 1]);
	}
	ans = std::max(ans, std::abs(A[N - 1] - W));
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
//#include<cstdlib>
// 0origin

#define MAX 100
#define INF 2001
#define WHITE 0
#define BLACK 1

int n;

// calculate the minimum cost
int PrimMST(int a[MAX][MAX]){ //refered to http://www.deqnotes.net/acmicpc/prim/#a1
    int v,i,j = 0, color[MAX], mincost, sumcost = 0, connected;
    
    for (i = 0; i < n; i++) {
        color[i] = WHITE;
    }
    
    color[0] = BLACK;
    while (j < n-1){
        
        mincost = INF;
        connected = INF;
        for (v = 0; v < n; v++) {
            if(color[v] == WHITE){
                continue;
            }
            for (i = 0; i < n; i++) {
                //printf("color[%d] : %s, cost %d to %d : %d\n", i, color[i] == 1 ? "BLACK" : "WHITE", v, i, a[v][i]);
                if (color[i] == WHITE && mincost > a[v][i]) {
                    mincost = a[v][i];
                    connected = i;
                    //printf("  min is rewritten : %d\n", mincost);
                }
            }
        
        }
        //printf("\nfin:%d\n\n", mincost);
        sumcost += mincost;
        color[v] = BLACK;
        if (connected != INF) {
            color[connected] = BLACK;
        }
        
        j++;
        
    }
    return sumcost;
}

int main(){
    int i, j, a[MAX][MAX];
    
    scanf("%d", &n);
    
    //printf("\n\n\n");
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            scanf("%d", &a[i][j]);
            if(a[i][j] == -1){
                a[i][j] = INF;
            }
            //printf(" %4d", a[i][j] != INF ? a[i][j] : -1);
        }
        //printf("\n");
    }
    
    printf("%d\n", PrimMST(a));
    
    return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<vector<pair<int, int>>> xy(n, vector<pair<int, int>>(0));

  // |- a[i]
  // |    |--xy<pair>
  // |    |--xy<pair>
  // |
  // |- a[i + 1];


  int input[2];
  int i, j, k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    for (j = 0; j < a[i]; j++) {
      cin >> input[0] >> input[1];
      xy[i].push_back(make_pair(input[0] - 1, input[1]));
    }
  }
  // cout << endl;
  for (i = 0; i < xy.size(); i++) {
    for (j = 0; j < xy[i].size(); j++) {
      // cout << xy[i][j].first << ' ' << xy[i][j].second << endl;
    }
  }
  // /*
  int result = 0;
  bool flag = true;
  for (i = 0; i < pow(2, n); i++) {
    flag = true;
    vector<int> b(n);
    int temp = i;
    int t_sum = 0;
    for (j = 0; j < b.size(); j++) {
      b[j] = temp % 2;
      temp /= 2;
      t_sum += b[j];
      // cout << b[j] << ' ';
    }
    // cout << endl;
    for (j = 0; j < n; j++) {
      // cout << "test ";
      // cout << "j " << j << ' ';
      if (b[j]) {
        // cout << xy[j].size() << ' ';
        for (k = 0; k < xy[j].size(); k++) {
          // cout << k << ' ';
          // cout << "a " << a[j] << " k " << k << ' ' << b[xy[j][k].first] << " [" << xy[j][k].first << "] " << xy[j][k].second << endl;
          if (b[xy[j][k].first] != xy[j][k].second) {
            flag = false;
          }
        }
      } /*else {
        // cout << xy[j].size() << ' ';
        for (k = 0; k < xy[j].size(); k++) {
          // cout << k << ' ';
          // cout << "a " << a[j] << " k " << k << " " <<  b[xy[j][k].first] << "     [" << xy[j][k].first << "] " << xy[j][k].second << endl;
          if (b[xy[j][k].first] == xy[j][k].second) {
            flag = false;
          }
        }
      } */
      // cout << endl;
    }
    if (flag) {
      result = max(result, t_sum);
      // for (j = 0; j < b.size(); j++) {
        // cout << b[j] << ' ';
      // }
      // cout << endl;
    }
  }
  cout << result << endl;
  //*/
  return 0;
}


Measured memory_bytes: 256
S = input()
 
# S_0 = S_1 かつ S_2 = S_3
# S_0 = S_2 かつ S_1 = S_3
# S_0 = S_3 かつ S_1 = S_2
# S_0 = S_1 = S_2 = S_3 を除外
 
if (S[0] == S[1] and S[2] == S[3] and S[1] != S[2]) or (S[0] == S[2] and S[1] == S[3] and S[0] != S[1]) or (S[0] == S[3] and S[1] == S[2] and S[0] != S[1]): print('Yes')
else: print('No')

Measured memory_bytes: 9044
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <string>

using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n ; i++ )
#define For(i, a, b) for(int i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()


int main(void){
    int N, K;
    string S;

    cin >> N >> K;
    cin >> S;

    S[K - 1] = char(S[K - 1] + 32);

    cout << S << endl;

    return 0;
}

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

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

  int sum = 1;
  for(int i = 0; i < n; i++){
    if(sum*2 < sum+k) sum *= 2;
    else sum += k;
  }

  cout << sum << endl;

  return 0;

}


Measured memory_bytes: 256
n=int(input())
while True:
    try:
        a=list(map(int,input().split()))
        if a[0]**2+a[1]**2==a[2]**2:
            print('YES')
        elif a[1]**2+a[2]**2==a[0]**2:
            print('YES')
        elif a[2]**2+a[0]**2==a[1]**2:
            print('YES')
        else:
            print('NO')
    except:
        break;


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//DPと思ったが1e9はでかすぎ
//黒点はせいぜい1e5、それを管理すればいいかな
//1e5**はむりか
//1個うったら9マス+1
//map管理？
int main(){
  ll H,W,N; cin>>H>>W>>N;
  vector<ll> ans(10,0);
  ans[0]=(H-2)*(W-2);
  ll x[3]={-1,0,1};
  map<pair<ll,ll>,ll> mp;
  for(int i=0; i<N; i++){
    ll a,b; cin>>a>>b;
    for(int j=0; j<3; j++){
      ll aa=a+x[j];
      if(aa<=1 || aa>=H) continue;
      for(int k=0; k<3; k++){
        ll bb=b+x[k];
        if(bb<=1 || bb>=W) continue;
        ans[mp[make_pair(aa,bb)]]--;
        mp[make_pair(aa,bb)]++;
        ans[mp[make_pair(aa,bb)]]++;
      }
    }
  }
  for(int i=0; i<=9; i++) cout<<ans[i]<<endl;
}

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

using namespace std;

int main()
{
	long long a, b, c;
	cin >> a >> b >> c;
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0)
		cout << 0 << endl;
	else
		cout << min({a * b, b * c, c * a}) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;

int main()
{
  string s;
  while (getline(cin, s)) {
    for (unsigned int i = 0; i < s.size(); ++i)
      s[i] = toupper(s[i]);
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 0
use std::io;


fn main() {
    let (_, k) = {
        let i = read::<usize>();
        (i[0], i[1] - 1)
    };
    let mut s = read_one::<String>()
        .chars()
        .collect::<Vec<char>>();
    let c = match s[k] {
        'A' => 'a',
        'B' => 'b',
        'C' => 'c',
        _ => unreachable!(),
    };
    s[k] = c;
    for c in s {
        print!("{}", c);
    }
    println!();
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define lli long long int
#define inf 2147483647
#define infll LLONG_MAX
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    int a, b;
    cin >> a >> b;
    int a_min = ceil(a / 0.08);
    int a_max = ceil((a+1) / 0.08) -1;
    int b_min = ceil(b / 0.1);
    int b_max = ceil((b+1) / 0.10) -1;
    a = max(a_min, b_min);
    if(a > min(a_max, b_max)) cout << "-1" << endl;
    else cout << a << endl;
}

Measured memory_bytes: 256
#include <stdio.h>


int main()
{
	int i, n, m, min = 1000000, max = -1000000;
	long long int sum = 0;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &m);
		if (m < min) {
			min = m;
		} if (m > max) {
			max = m;
		}
		sum += m;
	}

	printf("%d %d %lld\n", min, max, sum);

    return 0;
}

Measured memory_bytes: 600
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>




using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const int INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;



void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> a, b;
    for (int i = 0; i < 2 * n; ++i) {
        if (s[i] == 'a')
            a.push_back(i);
        else
            b.push_back(i);
    }
    vector<string> v(n);
    vector<int> lst(n);
    vector<int> ids;
    int st = 1;
    for (int i = 0; i < n; ++i) {
        ids.push_back(b[i]);
        ids.push_back(a[i]);
        for (int j = i; j < n; ) {
            
            if (max(a[j], b[j]) == 2 * j + 1) {
                sort(ids.begin(), ids.end());
                string str = "";
                for (int j = 0; j < ids.size(); ++j) 
                    str.push_back(s[ids[j]]);
                
                v[i] = str;
                lst[i] = ids.back();
                ids.resize(0);
                break;
            }
            ++j;
            if (b[j] < a[j]) {
                ids.push_back(b[j]);
                ids.push_back(a[j]);
            }
        }
    }
    
    vector<string> res;
    vector<int> id;
    for (int i = 0; i < v.size(); ++i) {
        while (!res.empty()) {
            if (res.back() + v[i] < v[i]) {
                res.pop_back();
                id.pop_back();
            }
            else
                break;
        }
        if ((id.empty()) || (lst[id.back()] < min(a[i], b[i]))) {
            res.push_back(v[i]);
            id.push_back(i);
        }
    }
    for (int i = 0; i < res.size(); ++i) {
        cout << res[i];
    }
    cout << endl;

}

//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();


#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}

Measured memory_bytes: 16384
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

char field[1100][1100];

void debug(int N) {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 15; j++) {
            cout << field[i][j] << " ";
        }
        cout << endl;
    }
}

vector<string> solve(int N) {
    vector<string> input;
    for (int i = 0; i < N; i++) {
        string s; cin >> s;
        input.push_back(s);
    }

    for (int i = 0; i < 1100; i++) {
        for (int j = 0; j < 1100; j++) {
            field[i][j] = '#';
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < input[i].length(); j++) {
            field[i][j] = input[i][j];
        }
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < input[i].length()-1; j++) {
            if (field[i][j] == '.' && field[i][j+1] != '.') {
                field[i][j] = '+';
                break;
            }
        }
    }

    for (int x = 0; x < 1100; x++) {
        int cnt = 0;
        int mode = 0;
        for (int y = 0; y < N; y++) {
            if (field[y][x] == '+') {
                if (cnt > 0) {
                    for (int i = y-cnt; i < y; i++) {
                        field[i][x] = '|';
                    }
                }
                cnt = 0;
                mode = 1;
            } else if (field[y][x] == '.'){
                if (mode) cnt++;
            } else {
                mode = 0;
                cnt = 0;
            }
        }
    }

    vector<string> ret;
    for (int i = 0; i < N; i++) {
        string tmp;
        for (int j = 0; field[i][j] != '#'; j++) {
            if (field[i][j] == '.') {
                tmp.push_back(' ');
            } else {
                tmp.push_back(field[i][j]);
            }
        }
        ret.push_back(tmp);
    }

    return ret;
}

int main(void) {
    int N;
    vector<vector<string>> ans;
    while (1) {
        cin >> N;
        if (!N) break;
        ans.push_back(solve(N));
    }

    for (int i = 0; i < ans.size(); i++) {
        for (int j = 0; j < ans[i].size(); j++) {
            cout << ans[i][j] << endl;
        }
    }
}




Measured memory_bytes: 12440
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)

	var s string
	fmt.Scanf("%s", &s)

	res := 0
	x := 0
	for _, c := range s {
		if c == 'I' {
			x += 1
		}
		if c == 'D' {
			x -= 1
		}
		if res < x {
			res = x
		}
	}

	fmt.Println(res)
}


Measured memory_bytes: 512
def check(x):
    if (x*10)//100>=b and (x*8)//100>=a: return True
    else: return False

a,b=map(int,input().split())
l=0 
r=10**9
while(l<r):
    mid=(l+r)//2
    if check(mid):r=mid
    else: l=mid+1
print(l if (l*10)//100==b and (l*8)//100==a else -1)


Measured memory_bytes: 61904
n,m=map(int,input().split())
 
WA=[0]*n
AC=[0]*n
 
for i in range(m):
    problem,status=input().split()
    problem=int(problem)
 
    if status=='WA':
        if AC[problem-1]==1:
            continue
        else:
            WA[problem-1]+=1
    elif status=='AC':
        AC[problem-1]=1

for i in range(n):
    if AC[i]==0:
        WA[i]=0
print(sum(AC),sum(WA))


Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, s, e) for(int i=s; i>=e; i--)
#define reps(i, s, e) for(int i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "no" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "nO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


// dp[i][j] => i 番目までの品物の中から j を超えないように選んだ時の最大価値
ll n, W;
ll dp[110][100010];
ll w[110], v[110];

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

    cin >> n >> W;
    rep(i, n){
        cin >> w[i] >> v[i];
    }

    reps(j, 0, W){
        dp[0][j] = 0;
    }

    rep(i, n){
        reps(j, 0, W){
            if(j >= w[i]){
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
            }else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }

    cout << dp[n][W] << endl;

    return 0;
}


Measured memory_bytes: 80128
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n;
  cin >> n;
  int m = n/15;
  cout << n*800-m*200 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,flg,i,j,a;
	scanf("%d",&n);
	flg=0;
	for(i=0;i<26;i++){
		for(j=0;j<15;j++){
			if(4*i+7*j==n){
					flg=1;
			}
		}
	}
	if(flg==1){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int kuch(int i)
{
    if(i==1)
    return 300000;
    if(i==2)
      return 200000;
    if(i==3)
      return 100000;
    
    return 0;
}
 
int main()
{
   int a,b;
  
   cin>>a>>b;
  
   int sum=0;
  
   if((a+b)==2)
   {
       sum = sum + kuch(a) + kuch(b) + 400000; 
   }
   else
   {
         sum = sum + kuch(a) + kuch(b);
   }
  
   cout<<sum<<endl;
   
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>


int main(){
  int N, M;
  scanf("%d", &N);
  scanf("%d", &M);
  std::vector<int > A(N);
  for (int i=0; i<N; i++){
    scanf("%d", &A[i]);
  }
  int sum=0;
  std::map<int, int> mp;
  mp[0]++;
  long long ans = 0;
  for (int i=0; i<N; i++){
    sum+=A[i];
    sum %= M;
    ans += mp[sum];
    mp[sum]++;
  }
  std::cout << ans << std::endl;
  return 0;
}
 

Measured memory_bytes: 3584
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int K = sc.nextInt();
    int N = sc.nextInt();
    sc.nextLine();
    int[] houses = Arrays.stream(sc.nextLine().split(" "))
      .mapToInt(Integer::parseInt).toArray();
    int maxDistance = houses[0] + (K-houses[N-1]);
    for (int i = 1; i < N; i++) {
      maxDistance = Math.max(maxDistance, houses[i] - houses[i-1]);
    }
    System.out.println(K - maxDistance);
  }
}

Measured memory_bytes: 59284
import collections

N = int(input())
A = map(int, input().split())
A_count = dict(collections.Counter(A))
A_countsort = sorted(A_count, reverse=True)
# print(A_countsort)
hen_list = []
for key in A_countsort:
    if A_count[key] >= 4:
        hen_list.append(key)
        hen_list.append(key)
    elif A_count[key] >= 2:
        hen_list.append(key)

if len(hen_list) >= 2:
    print(hen_list[0]*hen_list[1])
else:
    print(0)

Measured memory_bytes: 74136
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter


def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


n = int(readline())
check = []
for i in range(1, n + 1):
    check += prime_decomposition(i)
ans = 1
mod = 10 ** 9 + 7
for v in Counter(check).values():
    ans *= v + 1
    ans %= mod
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
bool edge[50][50];
int a[50],b[50];
bool visited[50];
int n,m,cnt=0;

void dfs(int v){
  visited[v]=true;
  REP(v2,n){
    if(edge[v][v2]==false)continue;
    if(visited[v2]==true)continue;
    dfs(v2);
  }
}

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  cin>>n>>m;

  REP(i,m){
    cin>>a[i]>>b[i];
    a[i]--;b[i]--;
    edge[a[i]][b[i]]=true;
    edge[b[i]][a[i]]=true;
  }
  REP(i,m){
    edge[a[i]][b[i]]=false;
    edge[b[i]][a[i]]=false;
    // 初期化
    REP(i,n)visited[i]=false;
    bool flag=false;

    dfs(0);

    REP(i,n)if(visited[i]==false)flag=true;
    if(flag){
      cnt++;
    }
    edge[a[i]][b[i]]=true;
    edge[b[i]][a[i]]=true;
  }
  P(cnt);
  return 0;
}


Measured memory_bytes: 256
N, M = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(N)]
C = [[int(i) for i in input().split()] for j in range(M)]

ls1 = []
for i in range(N):
    ls2 = []
    for j in range(M):
        ls2.append(abs(A[i][0] - C[j][0]) + abs(A[i][1] - C[j][1]))
    a = min(ls2)
    ls1.append(ls2.index(a))
for i in ls1:
    print(i+1)

Measured memory_bytes: 3064
use petgraph::algo::dijkstra;
use petgraph::graph::{NodeIndex, UnGraph};
use proconio::input;

fn main() {
    input! {
        n: usize,
        edges: [(usize, usize, usize); n-1],
        q: usize,
        k: usize,
        pairs: [(usize, usize); q],
    }

    //グラフを作る。
    let g = UnGraph::<usize, usize, usize>::from_edges(&edges);

    //ダイクストラ法で頂点kから他の頂点の最短距離を計算
    let res = dijkstra(&g, k.into(), None, |e| *e.weight());


    for (start, end) in &pairs {
        //頂点x_jと頂点kの最短距離 + 頂点kと頂点y_jの最短距離を計算
        let distance =
            res.get(&NodeIndex::new(*start)).unwrap() + res.get(&NodeIndex::new(*end)).unwrap();
        println!("{}", distance);
    }
}

Measured memory_bytes: 19312
#include <bits/stdc++.h>
using namespace std;
bool x_[(int) 2e4], y_[(int) 2e4], dum_[(int) 2e4];
bool *x = x_ + (int) 1e4;
bool *y = y_ + (int) 1e4;
bool *dum = dum_ + (int) 1e4;
signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  string s; cin >> s;
  int n = s.size();
  int xs, ys; cin >> xs >> ys;
  vector<vector<int>> a(2, vector<int>());
  int t = 0, i = 0, d = 0, x0 = 0;
  while (s[i] == 'F') {
    x0++;
    i++;
  }
  for (; i < n; i++) {
    if (s[i] == 'T') {
      if (t) a[d].push_back(t);
      d = 1 - d;
      t = 0;
    } else if (i == n - 1) a[d].push_back(t + 1); 
    else t++;
  }
  x[x0] = y[0] = true;
  for (auto&& i : a[0]) {
    for (int j = -8000; j <= 8000; j++) if (x[j]) dum[j + i] = dum[j - i] = true;
    for (int j = -8000; j <= 8000; j++) {x[j] = dum[j]; dum[j] = false;}
  }
  for (auto&& i : a[1]) {
    for (int j = -8000; j <= 8000; j++) if (y[j]) dum[j - i] = dum[j + i] = true;
    for (int j = -8000; j <= 8000; j++) {y[j] = dum[j]; dum[j] = false;}
  }
  cout << (x[xs] and y[ys] ? "Yes" : "No") << '\n';
  return 0;
}

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

int main() {
	int n;
  	string s;
  	cin >> n >> s;
  
  	if(n % 2 != 0){
      cout << "No" << endl;
      return 0;
    }
  
  	string t1, t2;
  	rep(i, n){
      if(i < n/2) t1.push_back(s.at(i));
      else t2.push_back(s.at(i));
    }
  
  	if(t1 == t2) cout << "Yes" << endl;
  	else cout << "No" << endl;
  	return 0;  
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    map<string, int> M;
    string temp = "", last = {S[0]};
    int ans = 1;
    for (int i = 1; i < (int)S.size(); i++) {
        temp += S[i];
        if (temp != last) {
            ans++;
            last = temp;
            temp = "";
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 720
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;



int main(){
     
    int w,h,n,x,y,a;
    int mx=0,Mx,my=0,My;
    
    cin>>w>>h>>n;
    Mx=w;   My=h;
    for(int i=0;i<n;i++){
        cin>>x>>y>>a;
        switch(a){
            case 1:
                if(x>mx)mx=x;
                break;
            case 2:
                if(x<Mx)Mx=x;
                break;
            case 3:
                if(y>my)my=y;
                break;
            case 4:
                if(y<My)My=y;
                break;
        }
    }
    if((Mx-mx)>=0&&(My-my)>=0)cout<<(Mx-mx)*(My-my)<<endl;
    else cout<<"0"<<endl;
     
    return 0;
}
 

Measured memory_bytes: 256
#!/usr/bin/ruby
require 'mathn'
h={};2.step(36){|i|h[i]=i.prime_division}
while(l=gets.split)!=["0","0"]	
	n=l[0].to_i;m=l[1].to_i(n)
	if n==0 then break end
	x=99999999999999999999
	h[n].each{|a,b|
		z=m;r=0
		while z>0 do r+=(z=z.div a) end
		if x>r.div(b) then x=r.div(b) end
	}
	p x
end

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

const int MAX = 1000000;
const int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int X, Y;
  cin >> X >> Y;
  if((X+Y)%3!=0){
    cout << "0" << endl;
    return 0;
  }
  if(X> 2*Y || Y>2*X){
    cout << "0" << endl;
    return 0;
  }
  int n=X, m=Y;
  int p, q;
  if(X>=Y){
    while((n/m)!=2){
      n++, m--;
    }
    p=m; q=Y-m;
  }else{
    while((m/n)!=2){
      n--, m++;
    }
    p=n; q=X-n;
  }
  if(q==0){
    cout << "1" << endl;
    return 0;
  }
  COMinit();
  cout << COM(p, q) << endl;
  return 0;
}

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

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

	int m1, d1, m2, d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if (m1 < m2) {
		cout << 1 << '\n';
	} else {
		cout << 0 << '\n';
	}
}


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

int main() {
    int n; scanf("%d", &n);
    int a[n]; for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    int num_query; scanf("%d", &num_query);
    int begin, end, t;
    
    for (int i = 0; i < num_query; ++i) {
        scanf("%d%d%d", &begin, &end, &t);
        swap_ranges(a + begin, a + end, a + t);
    }
    
    printf("%d", a[0]);
    for (int i = 1; i < n; ++i) printf(" %d", a[i]);
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 3228