akhauriyash/Code-Regression huggingface dataset:
def gcd(a, b):
    while b: a, b = b, a % b
    return a
def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2, 7, 61] if n < 1<<32 else [2, 3, 5, 7, 11, 13, 17] if n < 1<<48 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1: continue
        while y != n - 1:
            y = y * y % n
            if y == 1 or t == n - 1: return 0
            t <<= 1
    return 1
def findFactorRho(n):
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g): return g
            elif isPrimeMR(n // g): return n // g
            return findFactorRho(g)
def primeFactor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i * i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k: ret[i] = k
        i += i % 2 + (3 if i % 3 == 1 else 1)
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1: ret[n] = 1
    if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
    return ret

def divisors(N):
    pf = primeFactor(N)
    ret = [1]
    for p in pf:
        ret_prev = ret
        ret = []
        for i in range(pf[p]+1):
            for r in ret_prev:
                ret.append(r * (p ** i))
    return sorted(ret)


N = int(input())
A = [int(a) for a in input().split()]
X = [0] * 1000001
for a in A:
    X[a] += 1

ans = 0
for a in A:
    if X[a] > 1:
        continue
    for d in divisors(a)[:-1]:
        if X[d]:
            break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 121472
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;
string acgt="ACGT";

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,q;
  cin>>n>>q;
  string s;
  cin>>s;
  int l=s.length();
  vector<int>ac(l,0),sac(l+1,0);
  rep(i,l-1)
  {
    if(s[i]==acgt[0]&&s[i+1]==acgt[1])ac[i]=1;
  }
  rep(i,l)sac[i+1]+=ac[i]+sac[i];
  //rep(i,l+1)cout<<sac[i];
  rep(i,q)
  {
    int le,r;
    cin>>le>>r;
    le--;r--;
    int res=sac[r]-sac[le];
    cout<<res<<endl;
  }




  return 0;

}


Measured memory_bytes: 1872
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  bool f = 1;
  for (int i = 0; i < 10100; i++) {
    int j = i;
    int a = 0.08 * j;
    int b = 0.1 * j;
    if (A == a && B == b) {
      cout << j <<endl;
      f = 0;
      break;
    }
  }
  if (f) {
    cout << -1 <<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int x,t;
  cin>>x>>t;
  x-=t;
  if(x<0){
    x=0;
  }
  cout<<x<<"\n";

  return 0;
}

Measured memory_bytes: 3576
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==5&&b==5&&c==7||a==5&&b==7&&c==5||a==7&&b==5&&c==5){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()

	n := sc.ReadString()

	exists := false
	for _, ni := range n {
		if ni == '7' {
			exists = true
		}
	}
	if exists {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

func Abs64(x int64) int64 {
	if x >= 0 {
		return x
	}
	return -x
}

func Min64(values ...int64) int64 {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max64(values ...int64) int64 {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow64(base int64, exponent uint) int64 {
	answer := int64(1)
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 1756
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(m)]

ans = 0

for i in range(m):
    ab2 = ab[:i] + ab[i+1:]
    uf = UnionFind(n)
    for a,b in ab2:
        uf.union(a-1,b-1)
    if uf.group_count() > 1:
        ans += 1

print(ans)


Measured memory_bytes: 41072
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>
#include <iomanip>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
    ll int jhogeo = 1;
    rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
    return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}

int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}

int sei(ll int sssei){
  if(sssei>0){
    return sssei;
  }else{
    return 0;
  }
}


int main(){
  int a,b; cin>>a>>b;
  rep(i,0,a){
    string s; cin>>s;
    cout<<s<<endl<<s<<endl;
  }
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//cout<<fixed<<setprecision(n);  //小数点n桁まで表示

//  vector<pair<int,int>> data(N);  //2つのデータを格納、.first/.secondで参照
// pairのソートはfirst優先の昇順

Measured memory_bytes: 256
import heapq as h
import math
import numpy as np
import copy
import itertools

 
# x,y = map(int,input().split())
n = int(input())
s = input()
# a = list(map(int,input().split()))
alphabet = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
def change(a,n):
    ix = alphabet.index(a)
    ix += n
    return alphabet[ix%26]
new = ''
for tmp in s:
    new += change(tmp,n)
print(new)





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

int main() {
  
  int a,b;
  cin >> a >> b;
  int total = 0;
  for(int i = 1; i < 4; i++){
    if(a == i || b ==  i) total += i;
  }
  
  if(total == 3) cout << 3 << endl;
  else if(total == 4) cout << 2 << endl;
  else if(total == 5) cout << 1 << endl;

}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'

template <class T>
void updatemax(T& a, T b) { if (b > a) a = b; }

int b[(int)2e5+1];
int main() {
    fastio;
    ll N;
    cin >> N;
    for (int i=2; i <= N; ++i) {
        int j;
        cin >> j;
        b[j]++;
    }
    rep1(i,N) {
        cout << b[i] << endl;
    }
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  double e;
  ll d;
  while(cin >> d >> e && d && e != 0.0){
    double ans = inf;
    REP(i,1,d+1){
      ans = min(ans,abs(sqrt(i*i+(d-i)*(d-i)) - e));
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3288
#include <stdio.h>

int main(void)
{
    int n;
    scanf("%d", &n);

    int t_score = 0, h_score = 0;

    int i;

    for (i = 0; i < n; i++) {
        char t_card[101], h_card[101];

        scanf("%s", t_card);
        scanf("%s", h_card);

        int j;

        for (j = 0; t_card[j] != '\0' || h_card[j] != '\0'; j++) {
            if (t_card[j] > h_card[j]) {
                t_score += 3;
                break;
            } else if (t_card[j] < h_card[j]) {
                h_score += 3;
                break;
            }
        }

        if (t_card[j] == '\0' && h_card[j] == '\0') {
            t_score++;
            h_score++;
        }
    }

    printf("%d %d\n", t_score, h_score);

    return 0;
}


Measured memory_bytes: 2032
from collections import deque

N, M = map(int, input().split())
graph = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    graph[a].append(b)
    graph[b].append(a)
    
dist = [-1] * N
dist[0] = 0
    
queue = deque([0])

while queue:
    v = queue.popleft()
    for nv in graph[v]:
        if (dist[nv] != -1):
            continue
        dist[nv] = v
        queue.append(nv)

print("Yes")
for i in dist[1:]:
    print(i+1)


Measured memory_bytes: 95076
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

const int MAXN = 100100;
int A[MAXN];
ll sum[MAXN];

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A, A+N);
	for (int i = 0; i < N; i++)
		sum[i+1] = sum[i]+A[i];
	int now = 0;
	while (1) {
		ll total = sum[now+1];
		int i = now+1;
		for (; i < N; i++) {
			if (total*2 < A[i]) break;
			total += A[i];
		}
		if (i == N) {
			cout << N-now << endl;
			break;
		}
		now = i;
	}
	return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
int main()
{
    double x1,x2,y1,y2,z1,z2,p,q,a,b,c;
    while(scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&z1,&x2,&y2,&z2)!=EOF)
        {
    a=(y2*z1-y1*z2);
    b=(x1*z2-x2*z1);
    c=(x1*y2-x2*y1);
    p=a/c;
    q=b/c;
    if(p==-0)p=0;
    if(q==-0)q=0;
    printf("%0.3lf %0.3lf\n",p,q);
       }
    return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    int n, K, q;
    scanf("%d%d%d", &n, &K, &q);
    int a[n];
    rep(i, n) scanf("%d", &a[i]);

    int ans = mod;
    rep(i, n){
        vector<int> u, v;
        int l = 0;
        while(l < n){
            if(a[l] < a[i]){
                ++l;
                continue;
            }
            int r = l;
            while(r < n && a[r] >= a[i]) ++r;
            For(j, l, r) u.push_back(a[j]);
            l = r;

            sort(u.begin(), u.end());
            rep(j, u.size()-K+1) v.push_back(u[j]);
            u.clear();
        }
        if(v.size() < q) continue;
        sort(v.begin(), v.end());
        chmin(ans, v[q-1] - a[i]);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
std::map<std::string, ll> mp;

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

  rep( i, N ) {
    std::string S;
    std::cin >> S;

    ++mp[S];
  }

  printf( "AC x %lld\n", mp["AC"] );
  printf( "WA x %lld\n", mp["WA"] );
  printf( "TLE x %lld\n", mp["TLE"] );
  printf( "RE x %lld\n", mp["RE"] );

  return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
using ll   = long long;
using pll  = pair<ll,ll>;
using vll  = vector<pll>;
using vvll = vector<vll>;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define dmax(a,b) a=max(a,b)

int main() {
    int n; cin >> n;
    vll a(1<<n);
    vvll dp(1<<n, vll(2));
    rep(i,1<<n) {
        scanf("%ld", &a[i].first);
        a[i].second = i;
        dp[i][0] = a[i];
    }
    rep(b,1<<n) {
        rep(i,n) {
            int nb = b | (1<<i);
            if (nb == b) continue;
            if (dp[b][0].first > dp[nb][0].first) {
                dp[nb][1] = dp[nb][0];
                dp[nb][0] = dp[b][0];
            } else if (
                dp[b][0].second != dp[nb][0].second and 
                dp[b][0].first > dp[nb][1].first
            ) {
                dp[nb][1] = dp[b][0];
            }
            if (dp[b][1].first > dp[nb][1].first) {
                dp[nb][1] = dp[b][1];
            }
        }
    }
    ll ans = 0;
    rng(i,1,1<<n) {
        dmax(ans, dp[i][0].first + dp[i][1].first);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 25600
#include<stdio.h>
int main()
{
	long long N,M,num,x,p;
	while(~scanf("%lld%lld",&N,&M))
	{
		x=M/2;
		if(N>=x) num=x;
		else
		{
			num=N;
			M-=2*N;
			p=M/4;
			num+=p;
		}
		printf("%lld\n",num);
	}
	return 0;
}

Measured memory_bytes: 128
import queue
height,width=map(int,input().split())

graph=[input() for _ in range(height)]

dxs = [0, 0, 1, -1]
dys = [1, -1, 0, 0]
max_step=[]
for h in range(height):
    for w in range(width):
        if graph[h][w]=='#':
            continue

        route = [[-1]*width for _ in range(height)]
        route[h][w] = 0

        # start x,y,経路数
        q = queue.Queue()
        q.put([w,h,0])

        while not q.empty():
            nx,ny,nn = q.get()

            for dx,dy in zip(dxs, dys):
                x = nx+dx
                y = ny+dy
                if   width<=x \
                  or height<=y \
                  or x < 0 \
                  or y < 0 \
                  or graph[y][x]=='#' \
                  or route[y][x]!=-1:
                    continue
                route[y][x] = nn + 1
                q.put([x, y, nn+1])
        
        max_step.append(max(max(step) for step in route))
        
print(max(max_step))

Measured memory_bytes: 4080
import Data.List
main = do
  [n,x] <- map read . words <$> getLine
  a <- map read . words <$> getLine
  let b = sort a
      ac = scanl (+) 0 b
      ans =if sum a == x then n else min (n-1) $ (+) (-1) $ length $ filter (x>=) ac 
  print ans

Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
typedef long long ll;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int par[100010];
int depth[100010];

void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        depth[i]=0;
    }
}
int find(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x] = find(par[x]);
    }
}
void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x==y)return;
    if(depth[x]<depth[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(depth[x]==depth[y])depth[x]++;
    }
}
bool same(int x,int y){
    return find(x) == find(y);
}

int p[100010];
int main(){
    int n,m;
    cin >> n >> m;
    init(n+1);
    FOR(i,1,n+1)cin >> p[i];
    rep(i,m){
        int x,y;
        cin >> x >> y;
        unite(x,y);
    }
    int ans=0;
    FOR(i,1,n+1){
        if(same(i,p[i]))ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

V<string> s;
int n;
string ans;

bool dfs(int pos, int a, int b, int c) {
    if (pos == n) return true;
    if (s[pos] == "AB") {
        if (a == 0 && b == 0) return false;
        if (a > 0) {
            if (dfs(pos + 1, a - 1, b + 1, c)) {
                ans.push_back('B');
                return true;
            } 
        }
        if (b > 0) {
            if (dfs(pos + 1, a + 1, b - 1, c)) {
                ans.push_back('A');
                return true;
            }
        }
        return false;
    } else if (s[pos] == "BC") {
        if (b == 0 && c == 0) return false;
        if (c > 0) {
            if (dfs(pos + 1, a, b + 1, c - 1)) {
                ans.push_back('B');
                return true;
            } 
        }
        if (b > 0) {
            if (dfs(pos + 1, a, b - 1, c + 1)) {
                ans.push_back('C');
                return true;
            }
        }
        return false;
    } else {  // AC
        if (a == 0 && c == 0) return false;
        if (c > 0) {
            if (dfs(pos + 1, a + 1, b, c - 1)) {
                ans.push_back('A');
                return true;
            } 
        }
        if (a > 0) {
            if (dfs(pos + 1, a - 1, b, c + 1)) {
                ans.push_back('C');
                return true;
            }
        }
        return false;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c; cin >> n >> a >> b >> c;
    s.resize(n);
    for (int i = 0; i < n; i++) cin >> s[i];
    if (dfs(0, a, b, c)) {
        cout << "Yes\n";
        reverse(ALL(ans));
        for (int i = 0; i < ans.size(); i++) cout << ans[i] << '\n';
    } else cout << "No\n";
    return 0;
}


Measured memory_bytes: 12944
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d;
	
	
	cin>>a>>b>>c>>d;
	
	if(a-c<=d && a-c>=0){cout<<"Yes"<<endl;}
	else if(c-a<=d && c-a>=0){cout<<"Yes"<<endl;}
	else if(c-b<=d && c-b>=0)
	{
		if(b-a<=d && b-a>=0)
		{
		cout<<"Yes"<<endl;
		}
	}else if(a-b<=d && a-b>=0)
	{
		if(b-c<=d&&b-c>=0)
		{
		cout<<"Yes"<<endl;
		}
	}else cout<<"No"<<endl;
	
	
return 0;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<string ,int >mp;
map<string ,int >::iterator it;
string an[200000+7];
int main()
{
    int n;
    cin>>n;
    string s;
    int ans=0;
    for(int i=1;i<=n;i++){
        cin>>s;
        mp[s]++;
        ans=max(ans,mp[s]);
    }
    int pos=0;
    for(it=mp.begin();it!=mp.end();it++){
        if(it->second==ans) an[pos++]=it->first;
    }
    sort(an,an+pos);
    for(int i=0;i<pos;i++) cout<<an[i]<<endl;

    return 0;
}


Measured memory_bytes: 26752
import sys
sys.setrecursionlimit(500000)

N = int(input())
E = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b = map(int, input().split())
    E[a].append((b, i))
    E[b].append((a, i))

K = max(len(e) for e in E)
print(K)

Ans = [-1] * (N-1)
def dfs(v, pc=-1, p=-1):
    c = 1
    for u, idx in E[v]:
        if (u == p):
            continue
        if (c == pc): 
            c += 1
        Ans[idx] = c
        dfs(u, c, v)
        c += 1

dfs(1)
print("\n".join(map(str, Ans)))

Measured memory_bytes: 85636
import math
N = int(input())

def primary(x):
  D = {}
  for num in range(2, int(math.sqrt(x))+2):
    while x % num == 0:
      if num in D:
        D[num] += 1
      else:
        D.setdefault(num, 1)
      x = x // num
  if x > 1:
    D.setdefault(x, 1)
  if not D:
    return 0
  else:
    return D

primaryN = primary(N)
#print(primary(N))
a = 0
if N == 1:
  print(0)
elif primary(N) == 0:
  print(1)
else:
  for i in primaryN:
    j = 1
    while primaryN[i] > 0:
      primaryN[i] = primaryN[i] - j
      if primaryN[i] >= 0:
        a = a + 1
      j = j + 1
  print(a)

Measured memory_bytes: 9236
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

//最小公倍数
ll lcm(ll x, ll y){
	ll g = gcd(x,y);
	return x/g*y;
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

int main() {
	int a,b;cin>>a>>b;
	if(a > 0){
		cout << "Positive" << endl;
	}else if(a == 0){
		cout << "Zero" << endl;
	}else{
		if(b >= 0){
			cout << "Zero" << endl;
		}else{
			if((abs(b-a)+1)%2){
				cout << "Negative" << endl;
			}else{
				cout << "Positive" << endl;
			}
		}
	}
}



Measured memory_bytes: 256
/* Coached by rainboy */
#include <stdio.h>

int length(long long n) {
	return n == 0 ? 0 : length(n / 10) + 1;
}

int max(int a, int b) {
	return a > b ? a : b;
}

int main() {
	long long n, a, a_;

	scanf("%lld", &n);
	a_ = 1;
	for (a = 1; a <= n / a; a++)
		if (n % a == 0 && a_ < a)
			a_ = a;
	printf("%d\n", max(length(a_), length(n / a_)));
	return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <queue>
#include <tuple>
#include <cmath>
#include <map>
#include <cstring>

template<typename T> bool chmax( T &a, const T &b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T &b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#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 rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

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

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


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

	string s;
	cin >> s;

	bool flg = true;
	rep( i, s.size() )
	{
		if ( i != A )
		{
			if ( s[i] < '0' || s[i] > '9' )
			{
				flg = false;
				break;
			}
		}
		else
		{
			if ( s[i] != '-' )
			{
				flg = false;
				break;
			}
		}
	}

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

	return ( 0 );
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] S = sc.next().toCharArray();
		char[] k = "CODEFESTIVAL2016".toCharArray();
		int cnt = 0;
		for(int i = 0; i < 16; i++) {
			if(S[i] != k[i]) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 9680
// Ryo Kamoi
#define DEBUG

#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<set>

using namespace std;

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

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

int INF = 1000000000;

ll n, m;
bool broken[100100];
ll dp[100100];
ll R = 1000000007;
int main(){
  cin >> n >> m;

  REP(i, n) {
    broken[i] = false;
    dp[i] = 0;
  }

  REP(i, m) {
    ll a;
    cin >> a;
    broken[a-1] = true;
  }

  if (!broken[0]) dp[0] = 1;
  if (!broken[1]) dp[1] = dp[0]+1;
  for(int i=2; i<n; i++) {
    if (broken[i]) continue;
    dp[i] = (dp[i-1] + dp[i-2]) % R;
  }
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 1152
#include <iostream>

using namespace std;

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

  int min = x - (k - 1);
  int max = x + (k - 1);

  for (int i=min; i<=max; i++) {
    if (i > min) {
      cout << " ";
    }
    cout << i;
  }

  return 0;
}


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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT_ON(bit, i) (bit & (1LL << i))

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<typename T> using VVVV = std::vector<std::vector<std::vector<std::vector<T>>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }
template<typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }
template<class T> inline std::vector<T> unique(std::vector<T> v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v;
}
// 初項s, 交差dのn個の数列の和
long long sum_of_arithmetic_progression(long long s, long long d, long long n) {
    return n * (2 * s + (n - 1) * d) / 2;
}

const int INF = 1 << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = {0, -1, 0, 1}, dx4 = {1, 0, -1, 0};
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;


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

	int MOD = 1000000000 + 7;
	int H, W;
	cin >> H >> W;

	V<string> f(H);
	FOR(i, 0, H) {
	    cin >> f[i];
	}
	VV<LL> dp(H, V<LL>(W));
	dp[0][0] = 1;
	FOR(y, 0, H) {
	    FOR(x, 0, W) {
            if (y + 1 < H and f[y + 1][x] != '#') {
                (dp[y + 1][x] += dp[y][x]) %= MOD;
            }
            if (x + 1 < W and f[y][x + 1] != '#') {
                (dp[y][x + 1] += dp[y][x]) %= MOD;
	        }
	    }
	}

	print(dp[H - 1][W - 1] % MOD);


	return 0;
}

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

int n, m, a, b, c, dp[4096];
vector<int> v;
int main() {
    cin >> n >> m;
    for(int i = 0; i < 4096; i++) dp[i] = 1e9;
    while(m--) {
        cin >> a >> b;
        int t = 0;
        while(b--) {
            cin >> c;
            t += (1 << --c);
        }
        if(dp[t] == 1e9) v.push_back(t);
        dp[t] = min(dp[t], a);
    }
    int s = (1 << n);
    for(int i = 0; i < s; i++) {
        for(int j = 0; j < v.size(); j++) {
            int p = (i | v[j]);
            dp[p] = min(dp[p], dp[i] + dp[v[j]]);
        }
    }
    if(dp[s-1] == 1e9) cout << -1;
    else cout << dp[s-1];
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+5;
int ans;
int x[N];
int l[N],r[N];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    memset(l,-1,sizeof l);
    memset(r,-1,sizeof r);
    int z=n+1;
    for(int i=1;i<=n;i++){
        scanf("%d",&x[i]);
        if(x[i]==0)
            k--;
        if(z==n+1&&x[i]>0){
            z=i;
            for(int j=1;z-j>0;j++)
                l[j]=-x[z-j];
        }
    }
    if(z==n+1)
        for(int j=1;z-j>0;j++)
            l[j]=-x[z-j];
    for(int i=z;i<=n;i++)
        r[i-z+1]=x[i];
    l[0]=r[0]=0;
    int ans=1e9;
    for(int i=0;i<=k;i++)
        if(l[i]!=-1&&r[k-i]!=-1)
            ans=min(ans,l[i]+r[k-i]+min(l[i],r[k-i]));
    if(ans==1e9)
        ans=0;
    printf("%d\n",ans);
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int ans = 0;
    rep(i, n) {
        while(i+1 < n && a[i] == a[i+1]) ++i;

        if(i+1 < n && a[i] > a[i+1]) {
            while(i+1 < n && a[i] >= a[i+1]) ++i;
        }

        else if(i+1 < n && a[i] <= a[i+1]) {
            while(i+1 < n && a[i] <= a[i+1]) ++i;
        }

        ans++;
    }

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

Measured memory_bytes: 3728
#include<iostream>

using namespace std;

int main(){
	long ooo,min,max,sum = 0;
	int box[99999];

	cin >> ooo;

	for (int i = 0; i < ooo; i++){
		cin >> box[i];
		sum += box[i];
	}

	min = max = box[0];

	for (int i = 0; i < ooo-1; i++){
		if (min > box[i + 1]){
			min = box[i + 1];
		}
	}

	for (int i = 0; i < ooo - 1; i++){
		if (max < box[i + 1]){
			max = box[i + 1];
		}
	}

	cout << min << " " << max << " " << sum << endl;

	
	

}


Measured memory_bytes: 3156
#include <cstdio>
using namespace std;
const int INF = 200005;
int N, ans;
int main() {
  scanf("%d", &N);
  for(int i = 1, P, min = INF; i<= N; ++i) {
    scanf("%d", &P);
    if(min > P) min = P, ++ans;
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 128
/*
  AOJ 0593
  Title:Vote
  @kankichi573
*/
#include <stdio.h>

// #define max(x,y) (((x)>(y))?(x):(y))
// #define min(x,y) (((x)<(y))?(x):(y))
int N,M,A[1000],B[1000];
int vote[1000];
int kouho(int iin)
{
  int hiyou,i;
  hiyou=B[iin];
  for(i=0;i<N;i++)
    if(A[i]<=hiyou)
      {
	//printf("KH=%d\n",i);
	return(i);
      }
  return(-1);
}
int max_kouho(int vote[])
{
  int i,max_,max_i;
  max_=0;max_i=-1;
  for(i=0;i<N;i++)
    if(max_<vote[i])
      {
	max_=vote[i];
	max_i=i;
      }
  return(max_i);
}
int solve()
{
  int i;

  for(i=0;i<M;i++)
    vote[kouho(i)]++;
  return(max_kouho(vote));
}

main()
{
  int i;
  scanf("%d %d",&N,&M);
  for(i=0;i<N;i++)
    scanf("%d",&A[i]);
  for(i=0;i<M;i++)
    scanf("%d",&B[i]);
  printf("%d\n",solve()+1); //0base=>1base
  return(0);
}

Measured memory_bytes: 608
import numpy as np
def solve():
    def do(x,y,a):
        if a == 1:
            square[0:x:, :] *= 0
        if a == 2:
            square[x::, :] *= 0
        if a == 3:
            square[:, 0:y:] *= 0
        if a == 4:
            square[:, y::] *= 0

    W, H, N = map(int, input().split())
    #w-1, h-1の格子点上
    square = np.array([[1 for _ in range(H)] for _2 in range(W)], dtype=np.int32)

    for i in range(N):
        x,y,a= map(int, input().split())
        do(x,y,a)

    print(np.sum(square))




if __name__ == '__main__':
    solve()

Measured memory_bytes: 12564
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

def dfs(x):
    for i in tree[x]:
        if al[i]<0:
            al[i]=0
            dfs(i)
    
        
    
n,m=MI()
lis=[LI() for i in range(m)]
#print(lis)
cou=0
for i in range(m):
    tree=[[] for i in range(n)]
    for j in range(m):
        if i!=j:
            tree[lis[j][0]-1].append(lis[j][1]-1)
            tree[lis[j][1]-1].append(lis[j][0]-1)
    count=0
    for k in range(n):
        al=[-1]*n
        al[k]=0
        dfs(k)
        #print(al)
        if not -1 in al:
            count+=1
    if count!=n:
        cou+=1
print(cou)    

Measured memory_bytes: 3316
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner c=new Scanner(System. in);
		char r[]=c.nextLine().toCharArray();

		for(int i=0;i<r.length;i++){
			if('z'>=r[i]&r[i]>='a')
			r[i]=(char)(r[i]-'a'+'A');
		}
		System.out.println(r);
	}
}

Measured memory_bytes: 17140
#include <cstdio>

int n,x[50],y[50];

int main(){
  for(int c=1;;c++){
    float a=0;
    scanf("%d",&n); if(!n) break;

    for(int i=0; i<n; i++)
      scanf("%d %d",&x[i],&y[i]);

    for(int i=0; i<n; i++)
      a += 0.5*(x[i]*y[(i+1)%n]-y[i]*x[(i+1)%n]);

    a *= a>0?1:-1;

    printf("%d %.1f\n",c,a);
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
#define MOD 1'000'000'007
using namespace std;
typedef long long ll;
typedef long double ld;

struct unionFind{
    int* par;                       //親
    int* rank;                      //木の深さ
    int* scale;                     //木のサイズ
    unionFind(int n);
    ~unionFind();
    int find(int x);                //木の根を求める
    void unite(int x,int y);        //xとyの属する集合を併合
    bool same(int x,int y);         //xとyが同じ集合に属するか否か
    int size(int x);                //xの属する集合のサイズ
};

unionFind::unionFind(int n){
    par=new int[n];
    rank=new int[n];
    scale=new int[n];
    for(int i=0;i<n;i++){
        par[i]=i;
        rank[i]=0;
        scale[i]=1;
    }
}

unionFind::~unionFind(){
    delete[] par;
    delete[] rank;
    delete[] scale;
}

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

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

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

int unionFind::size(int x){
    x=find(x);
    return scale[x];
}

int N,M;
int p[100000];
int x[100000], y[100000];

int main(){
    cin>>N>>M;
    rep(i,N) cin>>p[i];
    rep(i,M) cin>>x[i]>>y[i];

    unionFind uf(N+1);
    rep(i,M){
        uf.unite(x[i],y[i]);
    }

    int ans=0;
    repn(i,N){
        if(uf.same(i,p[i-1])) ans++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 5524
N,D = gets.split.map(&:to_i)
X = []

(1..N).each do |n|
  X << gets.split.map(&:to_i)
end

count = 0

X.each_with_index do |x, i|
  (i+1...N).each do |y|
    temp = 0
    D.times do |d|
      temp += (x[d] - X[y][d]) ** 2
    end
    count += 1 if Math.sqrt(temp).to_s =~ /^[0-9]+.0$/
  end
end

puts count

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define ll  long long
#define mod 1000000007
#define ve vector
#define pi pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define all(v) v.begin(),v.end()
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int inf=1e9+5;


ll power(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b/=2;
	}
	return res;
}





void solve()
{
int x,n,i;
    cin>>x>>n;
  unordered_map<int,int>mp;
    for(i=0;i<n;i++)
    {
     int y;
        cin>>y;
        mp[y]++;
    }
    
    for(i=0;i<150;i++)
    {

      if(!mp[x-i])
      {
       cout<<x-i;
          return ;
      }
      else if(!mp[x+i])
      {
       cout<<x+i;
          return ;
      }
      
    }
    
}

signed main()
{
//#ifndef ONLINE_JUDGE
    //  freopen("input.txt","r",stdin);
    //  freopen("output.txt","w",stdout);
//#endif
    FAST;

     int t=1;
   //  cin>>t;
     while(t--)
    	solve();
    return 0;
}



Measured memory_bytes: 3660
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll r;
  vl A;
  cin >> r;
  cout << 3 * r * r << endl;

  return 0;
}


Measured memory_bytes: 256