akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
#include <functional>
#include <queue>
#include <utility>
#include <map>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<string, PII> PSI;
typedef pair<vector<int>, vector<int>> PVV;
const int INF = 1 << 29;	// 十分大きい値にする, INT_MAX にしないのはオーバーフロー対策

const int MAX_N = 1e+5, MAX_M = 1e+5;
const int MOD = 1000000007;

void solve()
{
	string S;
	bool flag = true;

	cin >> S;
	FOR(i, 0, S.size() - 1) {
		if (S[i] == S[i + 1]) {
			flag = false;
			break;
		}
	}

	if (flag)
		cout << "Good" << endl;
	else
		cout << "Bad" << endl;

}

int main(void)
{
	solve();

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 123456789012

ll gcd(ll  a,ll b){
    if(a<b) swap(a,b);
    if(a%b==0) return b;
    else return gcd(b,a%b);
}
int main(){
    ll i,j;
    ll a,b;
    cin>>a>>b;
    ll g=gcd(a,b);
    ll ans=1;
    for(i=2;i*i<=g;i++){
        if(g%i==0){
            ans++;
            while(g%i==0) g=g/i;
        }
    }
    if(g!=1) ans++;
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

#define int long long
#define ff first
#define ss second
#define pb emplace_back
#define pii pair<int, int>
#define mp make_pair

const int MAXN = 100009;
bool kek[MAXN];
int cnt[MAXN];
int n, m;

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        cnt[i] = 1;
    kek[0] = true;
    for (int j = 0; j < m; j++)
    {
        int x, y;
        cin >> x >> y;
        x--; y--;
        if (cnt[x] == 1)
        {
            if (kek[x])
            {
                kek[x] = false;
                kek[y] = true;
            }
        }
        else
        {
            if (kek[x])
                kek[y] = true;
        }
        cnt[x]--;
        cnt[y]++;
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
        ans += kek[i];
    cout << ans;
}


Measured memory_bytes: 1152
a, b = [int(i) for i in input().split()]

import math
a_ans = list(range(math.ceil(a*12.5), math.ceil((a+1)*12.5)))
b_ans = list(range(b*10, (b+1)*10))

l_ans = sorted(list(set(a_ans) & set(b_ans)))

if len(l_ans) == 0:
  print(-1)
else:
  print(l_ans[0])

Measured memory_bytes: 38512
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}
fn input_i32_vec() -> Vec<i32> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn bs(left: usize, right: usize, l_vec: &Vec<i32>, target: i32) -> usize {
    let mid = (left + right) / 2;
    if right - left <= 1 {
        return left;
    }
    if l_vec[mid] >= target {
        bs(left, mid, l_vec, target)        
    } else {
        bs(mid, right, l_vec, target)
    }
}

fn main() {
    let n: i32 = input();
    let mut l_vec = input_i32_vec();
    l_vec.sort();
    let mut sum = 0;
    for i in 0..(l_vec.len() - 2) {
        for j in (i+1)..(l_vec.len()-1) {
            let mut count = 0;
            sum += bs(j, l_vec.len(), &l_vec, l_vec[i] + l_vec[j]) - j;
        }
    }
    println!("{}", sum);
}

Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define LL long long 
using namespace std;
int dp[1234][1234];
int main(){  
	int a,b;
	cin>>a>>b;
	cout<<(a-1)*(b-1)<<endl;
    return 0;  
}  


Measured memory_bytes: 764
import math

def nCr(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, a, b = map(int, input().split())
v = sorted(list(map(int, input().split())), reverse=True)
ans = 0
ma = sum(v[:a]) / a
for i in range(a, b + 1):
    ave = sum(v[:i]) / i
    if ave == ma:
        p = 1
        for j in set(v[:i]):
            p *= nCr(v.count(j), v[:i].count(j))
        ans += p
print(ma)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,BIT[200001],a[200000],ans,cnt,b[200000];
map<ll,ll> mp;
void BITadd(int a){
    while(a){
        BIT[a]++;
        a-=a&(-a);
    }
    return ;
}
ll BITsum(int a){
    ll tot=0;
    while(a<=200000){
        tot+=BIT[a];
        a+=a&(-a);
    }
    return tot;
}
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    cnt=1;
    for(int i=0;i<n;i++)mp[b[i]]=cnt++;
    for(int i=0;i<n;i++)a[i]=mp[a[i]];
    for(int i=0;i<n;i++){
        ans+=BITsum(a[i]);
        BITadd(a[i]);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 20320
#include <iostream>
using namespace std;
 
    
    
int main()
{ int A,B,C;
cin>>A>>B>>C;
if(A==B&&B==C)
{
    cout<<"No"<<endl;
}
else if (A!=B&&B!=C&&C!=A)
{
    cout<<"No"<<endl;
}
else
{
    cout<<"Yes"<<endl;
}
 

    return 0;
}

Measured memory_bytes: 256
from bisect import insort_left

n = int(input())
values = list(map(int, input().split()))
values = sorted(values)

for _ in range(n - 1):
    if len(values) < 2:
        break
    x = values.pop(0)
    y = values.pop(0)
    new_value = (x + y) / 2.0
    insort_left(values, new_value)

print(values[0])

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


int main() { 
  int i;
  cin>>i;
  if (i%2==0)
  {cout<<0.5<<endl;}
  else{
      double q;
      double p;
      p=(int)(i/2);
      q=(p+1)/i;
      cout<<q<<endl;
  }

}

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

typedef long long lg;

bool able(vector<lg>& ps, lg n) {
	lg const N = ps.size()/2l;
	for (lg i = 1; i <= N; i++) {
		auto beg = begin(ps)+i,
		     ed = beg+N;
		for (int j = 0; j < 3; j++) {
			beg = lower_bound(beg, end(ps), *(beg-1)+n)+1;
			if (beg >= end(ps)) break;
		}
		if (beg <= ed) return true;
	}
	return false;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	lg N;
	cin >> N;
	vector<lg> A(2*N), ps(2*N+1, 0);
	for (auto i = 0; i < N; i++) {
		cin >> A[i];
		A[i+N] = A[i];
	}
	partial_sum(begin(A), end(A), begin(ps)+1);
	lg l = 0, r = 1000000000l*N;
	while (r-l > 1l) {
		auto m = (l+r)/2l;
		(able(ps, m) ? l : r) = m;
	}
	cout << l << endl;
}

Measured memory_bytes: 4168
a,b=map(int,input().split())
list1=[1,3,5,7,8,10,12]
list2=[4,6,9,11]
list3=[2]

if a in list1 and b in list1:
  print("Yes")
elif a in list2 and b in list2:
  print("Yes")
elif a in list3 and b in list3:
  print("Yes")
else: 
  print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  string s;
  R s;
  ll ans=0,cnt=0;
  rrep(i,s.size()) {
    if(s[i]=='W') cnt++;
    else ans+=cnt;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll X,Y;
    cin >> X >> Y;
    bool ok = true;
    if ((Y - 2*X) % 2 != 0) ok = false;
    if ((4*X-Y)%2 != 0) ok = false;

    ll a = (4*X-Y)/2;
    ll b = (Y-2*X)/2;
    if (a < 0) ok = false;
    if (b < 0) ok = false;

    cout << (ok ? "Yes\n" : "No\n");
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  int N, x;

  std::cin >> N >> x;

  std::vector<int> A(N, 0);

  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
  }

  std::sort(A.begin(), A.end());

  int answer = 0;

  for (int i = 0; i < N - 1; i++) {
    if (x >= A[i]) {
      x -= A[i];
      answer++;
    }
  }

  if (A[N-1] == x) {
    answer++;
  }

  std::cout << answer << std::endl;
}


Measured memory_bytes: 888
fn main() {
    let kn = read_vec::<usize>();
    let k = kn[0];
    let n = kn[1];
    let a = read_vec::<usize>();

    let mut d: Vec<usize> = vec![0; n];
    for i in 0..n-1 {
        d[i] = a[i+1] - a[i];
    }
    d[n-1] = a[0] + k - a[n-1];
    let ma = d.iter().max().unwrap();
    let sum: usize = d.iter().sum();
    println!("{}", sum - ma);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 10492
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <stdlib.h>
#include <ctime>
#include <cmath>
#include <complex>
#include <iostream>
#include <cctype>
#include <cstring>
#include <bitset>
#include <stack>
#include <functional>
#include <cassert>
#include <tuple>
#include <iomanip>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define ldb long double
#define mt make_tuple
template<typename T> bool ckmn(T &a, T b){ T c=a;a=min(a,b);return a!=c;}
template<typename T> bool ckmx(T &a, T b){ T c=a;a=max(a,b);return a!=c;}
const int N=105;
int dp[N][N];
char s[N][N];
int main(){
	int n,m;
	scanf("%i %i",&n,&m);
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	dp[1][1]=s[1][1]=='.'?0:1;
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(i!=1 || j!=1){
		dp[i][j]=1e9;
		if(i!=1)ckmn(dp[i][j],dp[i-1][j]+(s[i][j]!=s[i-1][j] && s[i][j]=='#'));
		if(j!=1)ckmn(dp[i][j],dp[i][j-1]+(s[i][j]!=s[i][j-1] && s[i][j]=='#'));
	}
	printf("%i\n",dp[n][m]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
   ll n,k,q;
  cin>>n>>k>>q;
  vector<ll> a(q);
  vector<ll> miu(n);
  rep(i,n){
      miu[i]=0;
  }
  rep(i,q){
    cin>>a[i];
    miu[a[i]-1]++;
  }
  rep(i,n){
      if(k-q+miu[i]<=0){
          cout<<"No"<<endl;
      }
      else{
          cout<<"Yes"<<endl;
      }
  }
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 4e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time"<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//___________________________________________________________________________________________

int main()
{
       int n;
       cin>>n;
       ll a[n];
       arrin(a,n);
       ll ans = 0;
       fri(i,1,n)
       {
              if(a[i] < a[i-1])
              {
                     ans += a[i-1]-a[i];
                     a[i] = a[i-1];
              }
       }
       cout<<ans<<endl;
}


Measured memory_bytes: 5232
////////////////////////////////////////////////////////////////////
// This source code is for Visual C++ 2010 Express
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>
//#include "UnionFind.h"

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		(1000000)
#define Rep(i,n) for(int i = 0; i < (n); i++ )

using namespace std;

typedef vector< vector<int> > mat;
typedef pair<int, int> P;
typedef long long ll;

int main()
{
	string S = "";

	cin >> S;
	sort(S.begin(), S.end());
	if(S[0] == S[1] && S[2] == S[3] && S[1] != S[2]){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

	return 0;
}





Measured memory_bytes: 384
N = gets.to_i
monsters = gets.split.map(&:to_i)
heroes = gets.split.map(&:to_i)
count = 0
N.times do |i|
  rest = heroes[i]
  if rest <= monsters[i]
    count += rest
  else # rest > monsters[i]
    rest -= monsters[i]
    count += monsters[i]
    # i+1の枠
    if rest <= monsters[i+1]
      count += rest
      monsters[i+1] -= rest
    else
      count += monsters[i+1]
      monsters[i+1] = 0
    end
  end
end
puts count


Measured memory_bytes: 15380
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/

int main() {
    ll N;
    cin>>N;
    char prev='!';
    ll prevc=0;
    ll c=0;
    REP(i,N+1){
        char cur;
        if(i==N)cur='!';
        else cin>>cur;
        if(prev=='!')prev=cur;
        if(prev!=cur){
            //cout<<prevc<<","<<c<<endl;
            if(prevc==0){
                if(c==1){
                    ans=3;
                }else{
                    ans=6;
                }
            }else if(prevc==1){
                if(c==1){
                    ans=(ans*2)%1000000007;
                }else{
                    ans=(ans*2)%1000000007;
                }
            }else{
                if(c==1){
                    // 1
                }else{
                    ans=(ans*3)%1000000007;
                }
            }
            prevc=c;
            c=1;
        }else{
            c++;
        }
        prev=cur;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
//ll a[Max];

void solve(){
	ll n,r;
	
	cin>>n>>r;
	if(n>=10){
		cout<<r;
	}else{
		cout<<r+100*(10-n);
	}
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





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

long K, A, B;

int main(void) {

    cin >> K >> A >> B;

    bool f = false;

    for (long i = A; i <= B; i++) {
        if (i%K == 0) {
            f = true;
            break;
        }
    }

    cout << (f ? "OK" : "NG") << endl;

    return 0;

}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;
  
  vector<int>V(N);
  for(int i=0;i<N;i++){
    cin>>V.at(i);
  }
  sort(V.rbegin(),V.rend());  
  int A=0;
  int B=0;
  
  for(int i=0;i<N;i++){
    if(i%2==0){
      A+=V.at(i);
    }
    else{
      B+=V.at(i);
    }
  }
  cout <<A-B<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#define INF 100000000
#define fi first
#define sec second
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int> P;

int n,k;
int cost[5000];
int c[5000],r[5000];
vector<int> e[5000];
vector<P> te[5000];

void dijkstra(){
	rep(i,n) cost[i] = INF;
	cost[0] = 0;
	queue<P> que;
	que.push(P(0,0));
	cost[0] = 0;
	while(true){
		if(que.size()==0) break;
		P p = que.front(); que.pop();
		if(p.sec > cost[p.fi]) continue;
		rep(j,te[p.fi].size()){
			if(cost[te[p.fi][j].fi]<=cost[p.fi]+te[p.fi][j].sec) continue;
			cost[te[p.fi][j].fi]=cost[p.fi]+te[p.fi][j].sec;
			que.push(P(te[p.fi][j].fi,cost[te[p.fi][j].fi]));
		}
	}
	printf("%d\n", cost[n-1]);
}

int main(){
	scanf("%d%d",&n,&k);
	rep(i,n) scanf("%d%d",&c[i],&r[i]);
	rep(i,k){
		int a,b; scanf("%d%d",&a,&b);
		a--;b--;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	rep(i,n){
		rep(j,n) cost[j] = INF;
		queue<P> que;
		que.push(P(i,0));
		cost[i] = 0;
		while(true){
			if(que.size()==0) break;
			P p = que.front(); que.pop();
			if(p.sec == r[i]) continue;
			if(p.sec > cost[p.fi]) continue;
			rep(j,e[p.fi].size()){
				if(cost[e[p.fi][j]]<=p.sec+1) continue;
				cost[e[p.fi][j]] = p.sec+1;
				que.push(P(e[p.fi][j],p.sec+1));
				te[i].push_back(P(e[p.fi][j],c[i]));
			}
		}
		te[i].erase(unique(te[i].begin(),te[i].end()),te[i].end());
	}
	dijkstra();
}

Measured memory_bytes: 125648
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


class UnionFindTree:
    def __init__(self, n):
        self.n = n
        self.parent = list(range(n))
        self.size = [1] * n

    def root(self, i):
        inter = set()
        while self.parent[i]!=i:
            inter.add(i)
            i = self.parent[i]
        r = i
        for i in inter:
            self.parent[i] = r
        return r

    def connect(self, i, j):
        ri = self.root(i)
        rj = self.root(j)
        if ri==rj:
            return
        if self.size[ri]<self.size[rj]:
            self.parent[ri] = rj
            self.size[rj] += self.size[ri]
        else:
            self.parent[rj] = ri
            self.size[ri] += self.size[rj]

n,m = list(map(int, input().split()))
uf = UnionFindTree(n)
for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    uf.connect(a,b)
s = set()
for i in range(n):
    s.add(uf.root(i))
print(len(s)-1)

Measured memory_bytes: 81668
N,K=(int(x) for x in input().split())

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

A=Base_10_to_n(N,K)

print(len(A))

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

using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll mypow(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1)ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
int main(){
    ll n;
    cin>>n;
    cout<<(((mypow(10,n)-2*mypow(9,n))%mod+mod)%mod+mypow(8,n))%mod;
    return 0;
}

Measured memory_bytes: 3620
N = int(input())

def graph(N):
    if N % 2 != 0:
        E = graph(N - 1)
        E.extend((i, N) for i in range(1, N))
    else:
        E = [(i, j) for i in range(1, N)
                    for j in range(i + 1, N + 1) if i + j != N + 1]
    return E

E = graph(N)
print(len(E))
print('\n'.join(' '.join(map(str, e)) for e in E))

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


void solve(string S){
    long long a[2] = {0, 0};
    for (int i = 0; i < S.size(); i++) {
        a[S[i] - '0']++;
    }
    printf("%lld\n", S.size() - (max(a[0], a[1]) - min(a[0], a[1])));
}

int main(){
    string S;
    std::cin >> S;
    solve(move(S));
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

#define MAX_NODE 10000
#define INF 1000000000

using namespace std;

struct Edge {
	int to, w;
	Edge(int to, int w) {
		this->to = to;
		this->w = w;
	}
};
typedef pair<int, int> pii;

vector<Edge> adj[MAX_NODE];
int d[MAX_NODE];

void dijkstra(int n, int start) {
	priority_queue<pii, vector<pii>, greater<pii>> que;
	fill(d, d + n, INF);

	d[start] = 0;
	que.emplace(0, start);
	while (!que.empty()) {
		pii p = que.top();
		que.pop();
		int from = p.second;

		if (d[from] < p.first)
			continue;

		for (auto& e : adj[from])
			if (d[from] + e.w < d[e.to]) {
				d[e.to] = d[from] + e.w;
				que.emplace(d[e.to], e.to);
			}
	}
}

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

	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		while (k--) {
			int v, c;
			cin >> v >> c;
			adj[u].emplace_back(v, c);
		}
	}

	dijkstra(n, 0);

	for (int i = 0; i < n; i++)
		cout << i << " " << d[i] << endl;

	return 0;
}

Measured memory_bytes: 6300
from bisect import bisect_right


cands = []
for i in range(2, 400):
    cur = i
    while cur * i <= 1000:
        cands.append(cur * i)
        cur *= i
cands.sort()

X = int(input())
if X == 1:
    print(1)
else:
    print(cands[bisect_right(cands, X) - 1])


Measured memory_bytes: 9080
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        //var N = int.Parse(ReadLine());
        var a = new int[5];
        for (int i = 0; i < 5; i++)
        {
            a[i] = int.Parse(ReadLine());
        }
        var k = int.Parse(ReadLine());
        var b = true;
        for (int i = 0; i < 5; i++)
        {
            for (int j = 0; j < 5; j++)
            {
                if (Math.Abs( a[i ] - a[j]) > k) b = false;
            }
            
        }
        WriteLine(b? "Yay!" : ":(");
    }
}


Measured memory_bytes: 13140
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define dup(x) x.erase(unique(x.begin(), x.end()),x.end())
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
// https://atcoder.jp/contests/abc172/tasks/abc172_e
ll MOD = 1e9+7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const int N = 5e5 + 5;
ll inv[N], fact[N], ifact[N];
void pre()
{
    inv[1] = fact[0] = fact[1] = ifact[0] = ifact[1] = 1;
    for (int i = 2; i < N; i++)
    {
        inv[i] = mul(MOD - MOD / i, inv[MOD % i], MOD);
        fact[i] = mul(i * 1ll, fact[i - 1], MOD);
        ifact[i] = mul(inv[i], ifact[i - 1], MOD);
    }
    return;
}
ll nCr(ll n, ll r)
{
    if (n >= 0 && r >= 0 && n >= r)
        return mul(fact[n], mul(ifact[r], ifact[n - r], MOD), MOD);
    return 0;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n, m;
    cin >> n >> m;
    pre();
    ll ans = mul(nCr(m, n), fact[n], MOD);
    ans = mul(ans, ans, MOD);
    ll ex = 0;
    for(int i = 1;i<=n;i++){
        ll a = nCr(n, i);
        a = mul(a, mul(nCr(m, i), fact[i], MOD), MOD);
        ll b = mul(nCr(m - i, n - i), fact[n - i], MOD);
        b = mul(b, b, MOD);
        a = mul(a, b, MOD);
        if (i & 1)
            ex = add(ex, a, MOD);
        else
            ex = add(ex, MOD - a, MOD);

    }
    ans = add(ans, MOD - ex, MOD);
    cout << ans;

	return 0;
}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

vector<int> primes;
vector<bool> isPrime(maxn, true);

void sieve(int n = maxn - 10) {
    isPrime[0] = isPrime[1] = false;
    isPrime[2] = true;
    for (int i = 3; i * i <= n; i += 2)
        if (isPrime[i])
            for (int j = i * i; j <= n; j += 2 * i)
                isPrime[j] = false;
    primes.push_back(2);
    for (int i = 3; i <= n; i += 2)
        if (isPrime[i])primes.push_back(i);
}

void solve() {
    sieve();
    int q;
    cin >> q;

    vector<int> v(maxn);
    for (int i = 3; i <= maxn - 10; i += 2) {
        int b = (i + 1) / 2;
        if ((b & 1 or b == 2) and isPrime[b] and isPrime[i])
            v[i] = 1;
    }
    partial_sum(v.begin(), v.end(), v.begin());
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        cout << v[r] - v[l - 1] << endl;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	vector<bool> primes(1000100, true);
	primes[0] = false; primes[1] = false;
	for(int i = 2; i < 1000100; ++i){
		if(primes[i] == false)continue;
		for(int j = 2; i*j < 1000100; ++j){
			primes[i*j] = false;
		}
	}	
	int N ;cin >> N;
	int ans = 1;
	int now = 0;
	int add = 7 % N;
	while(ans < 10000000){
		now *= 10;
		now += add;
		now %= N;
		if(now == 0){
			cout << ans << endl;
			return 0;
		}
		++ ans;
	}
	cout << -1 << endl;
	
 	return 0;
}


Measured memory_bytes: 3708
import java.util.Scanner;
import java.util.Arrays;
 
class Main {
  public static void main(String args[]) {
 
    Scanner scan = new Scanner(System.in);
    int h = scan.nextInt();
    int num = scan.nextInt();
 
    int[] attack = new int[num];
 
    for(int i = 0; i < num; i++){
      h -= scan.nextInt();
    }
 
    if(h < 1){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
 
  }
}

Measured memory_bytes: 50016
#include<iostream>
using namespace std;
int main(void){
  
  int N, M, A, B;
  
  cin >> N >> M;
  
  int count[N];
  for(int i = 0; i < N; i++){
    count[i] = 0;
  }
  
  for(int i = 0; i < M; i++){
    cin >> A >> B;
    count[A-1]++;
    count[B-1]++;
  }
  
  for(int i = 0; i < N; i++){
    cout << count[i] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
N ,L= map(int,input().split())
one_aji = 0
aji = []
answer = []
for i in range(N):
    one_aji = L+i
    if one_aji < 0:
        answer.append(one_aji)
        one_aji *= -1
        aji.append(one_aji)
    else:
        aji.append(one_aji)
        answer.append(one_aji)
zettai = 500
ind = 0
for i, a in enumerate(aji):
    a = int(a)
    if a < zettai:
        zettai = a
        ind = i
         
answer.pop(ind)
print(sum(answer))


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct node {
  int x;
  struct node* prev;
  struct node* next;
} list;
list* head;
list* tail;

list* newnode(int x) {
  list* res = (list*)malloc(sizeof(list));
  res->x = x;
  res->prev = NULL;
  res->next = NULL;
  return res;
}

void deletenode(list* p) {
  p->prev->next = p->next;
  p->next->prev = p->prev;
  free(p);
}

void insert(int x) {
  list* p = newnode(x);
  p->next = head->next;
  p->prev = head;
  head->next->prev = p;
  head->next = p;
}

void delete(int x) {
  list* p;
  for(p = head->next; p != NULL; p = p->next) {
    if(p->x == x) {      
      deletenode(p);
      break;
    }
  }
}

void deleteFirst() {
  deletenode(head->next);
}

void deleteLast() {
  deletenode(tail->prev);
}

void print() {
  list* p;
  int izryt = 0;
  for(p = head->next; p != tail; p = p->next) {
    if(izryt) printf(" ");
    printf("%d", p->x);
    izryt = 1;
  }
  puts("");
}

int main() {
  int n;
  int i;
  char com[256];
  int x;
  head = newnode(-1);
  tail = newnode(-1);
  head->next = tail;
  tail->prev = head;
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%s", com);
    if(strcmp(com, "insert") == 0) {
      scanf("%d", &x);
      insert(x);
    } else if(strcmp(com, "delete") == 0) {
      scanf("%d", &x);
      delete(x);
    } else if(strcmp(com, "deleteFirst") == 0) {
      deleteFirst();
    } else if(strcmp(com, "deleteLast") == 0) {
      deleteLast();
    }    
  }
  print();
  return 0;
}

Measured memory_bytes: 31788
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

int main() {

    string s;

    cin >> s;

    int n = s.size();

    int left = 0;
    int right = n - 1;

    bool isTrue = true;

    int sum = 0;

    while(1) {
        int lCount = left;
        int rCount = right;

        while(left < n && s[left] == 'x')left++;
        while(right >= 0 && s[right] == 'x')right--;

        if(s[left] != s[right]) {
            isTrue = false;
            break;
        }

        sum += abs((left - lCount) - (rCount - right));


        left++;
        right--;

        if(left >= right)
            break;


    }


    if(isTrue == false) {
        cout << -1 << endl;
        return 0;
    }
    cout << sum << endl;

    return 0;

}

Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

int N;

int main() {
    cin >> N;
    ll ans = 0;
    for (int i = 1; i <= N; i++)
        ans += (ll)i * (N - i + 1);
    for (int i = 1; i <= N - 1; i++) {
        int a, b;
        cin >> a >> b;
        ans -= (ll)min(a, b) * (N - max(a, b) + 1);
    }
    cout << ans << endl;
}

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

void _130() {
    int n, x;
    int l[100];
    cin >> n >> x;
    for (int i = 0; i < n; ++i) { 
        cin >> l[i];
    }

    int d = 0;
    for (int i = 0; i < n; ++i) {
        d = d + l[i];
        // cout << d << endl;
        if (d > x) {
            cout << i + 1 << endl;
            return;
        }
    }
    cout << n + 1 << endl;
}

void _131() {
    int n, l;
    cin >> n >> l;

    int sum = (l - 1) * n + (1 + n) * n / 2;
    // cout << sum << endl;

    int taste = 0;
    int min_taste = 100;
    for (int i = 0; i < n; ++i) {
        taste = l + (i + 1) - 1;
        // cout << "taste" << taste << endl;
        if (abs(taste) < abs(min_taste))
            min_taste = taste;
        // cout << min_taste << endl;
    }
    cout << sum - min_taste << endl;
}

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

    int count = 0;
    int second_value = 0;
    for (int i = 0; i < n - 2; ++i) {
        if ((p[i] < p[i + 1]) && (p[i + 1] < p[i + 2])){
            // cout << "1:" << p[i] << " " << p[i + 1] << " " << p[i + 2] << endl;
            count++;
        }
        else if ((p[i] > p[i + 1]) && (p[i + 1] > p[i + 2])){
            // cout << "2:" << p[i] << " " << p[i + 1] << " " << p[i + 2] << endl;
            count++;
        }
    }
    cout << count << endl;
}

void _133() {
    int n, d;
    cin >> n >> d;
    int x[10][10];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < d; ++j) {
            cin >> x[i][j];
        }
    }

    int count = 0;
    float distance = 0;
    for (int i = 0; i < n - 1; ++i) {
        for (int j = i + 1; j < n; ++j) {
            distance = 0;
            for (int k = 0; k < d; ++k) {
                distance += pow(x[i][k] - x[j][k], 2);
                // cout << x[i][k] << " " << x[j][k] << " " << distance << endl;
            }
            distance = pow(distance, 0.5);
            // cout << distance << endl;

            if (abs(distance - ceil(distance)) <= 1e-6)
                count++;
        }
    }

    cout << count << endl;
}

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



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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod =1000000007;


vector<pair<int,int>> g[100005];
VB used(100005,false);

VI ans(100005, -1);


void dfs(int n) {

	for (auto i : g[n]) {
		if (used[i.first])continue;
		used[i.first] = true;
		if (i.second % 2) {
			if (ans[n] == 0) {
				ans[i.first] = 1;
			}
			else ans[i.first] = 0;
		}
		else {
			if (ans[n] == 0) {
				ans[i.first] = 0;
			}
			else ans[i.first] = 1;
		}
		dfs(i.first);
	}


}


int main() {

	int n;
	cin >> n;
	REP(i, n - 1) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].push_back({ b,c });
		g[b].push_back({ a,c });
	}
	ans[0] = 0;
	
	dfs(0);

	REP(i, n) {
		cout << ans[i] << endl;
	}

}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'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'};
char moji2[26]={'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'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int( 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

int n,k;
vector<int> A[MAX];
bool vis[MAX];
int hoge[MAX];

int res = 1;

void solve(int x){
    vis[x] = true;
    int tmp = k;
    itrfor(itr,A[x]){
        tmp -= hoge[*itr];
        hoge[*itr] ++;
        if(tmp == 0){
            res *= 0;
            break;
        }
    }
    hoge[x] ++;
    res *= tmp;
    res %= MOD;
    itrfor(itr,A[x]){
        if(vis[*itr]) continue;
        solve(*itr);
    }


}

signed main(){
    cin >> n >> k;

    int a,b;
    REP(i,n-1){
        cin >>  a >> b;
        A[a-1].push_back(b-1);
        A[b-1].push_back(a-1);
    }

    REP(i,n){
        vis[i] = false;
        hoge[i] = 0;
    }
    solve(0);
    cout << res << endl;
    

}

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

int main(){
    long long int n,m=0;
    cin>>n;
    vector<long long int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    m=accumulate(a.begin(),a.end(),0LL);
    cout<<m-n;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


class UnionFind:
    def __init__(self, N):
        self.Parent = [-1]*(N+1)
    #Aの親を探す。このときParent[A]は親の値からグループサイズに変わる。探索の最適化
    def root(self, A):
        if self.Parent[A] < 0: return A
        self.Parent[A] = self.root(self.Parent[A])
        return self.Parent[A]
    #Aが属しているグループのサイズを求める
    def size(self, A):
        return -self.Parent[self.root(A)]
    
    def connect(self,A,B):
        A = self.root(A)
        B = self.root(B)
        if A == B: return False
        
        if self.size(A) < self.size(B): A,B = B,A
        self.Parent[A] += self.Parent[B]
        self.Parent[B] = A
        return True



N,M = map(int,input().split())
AB = [list(map(int, input().split())) for _ in range(M)]
Uni = UnionFind(N)
ans = [-1]*(M)
ans[M-1] = N*(N-1)//2 
for i in reversed(range(1,M)):
    ans[i-1] = ans[i]
    if Uni.root(AB[i][0]) != Uni.root(AB[i][1]):
        ans[i-1] -= Uni.size(AB[i][0])*Uni.size(AB[i][1])
    Uni.connect(AB[i][0], AB[i][1])
for i in range(M):
    print(ans[i])




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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int maxn = 1e6 + 5;

int x,a,b;

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

  cin>>x>>a>>b;
  x-=a;
  int y = x/b;
  x-=(y*b);
  out(x);
  

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef vector<pii> vpii;
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
    tree_order_statistics_node_update> ost;

const int N=110000;
vi adj[N];
int sg[N];

void dfs(int x, int p) {
    for(int y: adj[x]) if(y!=p) {
        dfs(y, x);
        sg[x]^=1+sg[y];
    }
}

int main() {
    int i, n, u, v;
    scanf("%d", &n);
    for(i=0; i<n-1; i++) {
        scanf("%d%d", &u, &v);
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1, 0);
    printf(sg[1]? "Alice\n" : "Bob\n");
    return 0;
}

Measured memory_bytes: 12544
import sys

def solve():
      input = sys.stdin.readline
      S = input().strip("\n")
      T = input().strip("\n")
      minChange = len(T)
      for i in range(len(S) - len(T) + 1):
            c = 0
            for j in range(len(T)):
                  if S[i + j] != T[j]: c += 1
            minChange = min(minChange, c)
      print(minChange)

      return 0

if __name__ == "__main__":
      solve()

Measured memory_bytes: 9064
n = gets.to_i
cs = gets.split

cs_b = cs.dup

(0..n-1).each do |i|
  (n-1).downto(i+1) do |j|
    if cs_b[j][1].to_i < cs_b[j-1][1].to_i
      tmp = cs_b[j]
      cs_b[j] = cs_b[j-1]
      cs_b[j-1] = tmp
    end
  end
end

puts cs_b.join(" ")
puts 'Stable'

cs_s = cs.dup

(0..n-1).each do |i|
  minj = i
  (i..n-1).each do |j|
    if cs_s[j][1].to_i < cs_s[minj][1].to_i
      minj = j
    end
  end
  next if cs_s[i] == cs_s[minj]
  tmp = cs_s[i]
  cs_s[i] = cs_s[minj]
  cs_s[minj] = tmp
end
puts cs_s.join(" ")
puts cs_s == cs_b ? 'Stable' : 'Not stable'






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

ll dp[20202][256];

int main(){
    for(ll N, M; cin >> N >> M, N;){
        vector<ll>C(M), X(N);
        for(ll i = 0; i < M; i++)cin >> C[i];
        for(ll i = 0; i < N; i++)cin >> X[i];
        for(ll i = 0; i <= N; i++){
            for(ll j = 0; j < 256; j++)dp[i][j] = 1145141919;
        }
        dp[0][128] = 0;
        for(ll i = 0; i < N; i++){
            for(ll j = 0; j < 256; j++){
                if(dp[i][j] == 1145141919)continue;
                for(ll k = 0; k < M; k++){
                    ll nxt = j + C[k];
                    if(nxt < 0)nxt = 0;
                    if(nxt > 255)nxt = 255;
                    dp[i + 1][nxt] = min(dp[i + 1][nxt], dp[i][j] + (nxt - X[i])*(nxt - X[i]));
                }
            }
        }
        ll ans = dp[N][0];
        for(ll i = 0; i < 256; i++)ans = min(ans, dp[N][i]);
        cout << ans << endl;
    }
    return 0;
}



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

// #define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) cerr << #v << ": [ "; for(int __ = 0; __ < v.size(); __++) cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugVP(v) cerr << #v << ": [ "; for(int ___ = 0; ___ < v.size(); ___++) cerr << '{' << v[___].first << ", " << v[___].second << '}' << ((___ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugA(a, n) cerr << #a << ": [ "; for(int ____ = 0; ____ < n; ____++) cerr << a[____] << ((____ != n - 1) ? ", " : ends); cerr << ']' << endl
#define print(args...) fprintf (stderr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int INF = 1e9, MOD = INF + 7 /* INF - 1755647 */;

/////////////////////////////////////////////////////////////////////

const int N = 3e5 + 20;

int a[N];

int32_t main() {

    sync;

    for(int i = 0; i < 5; i++) cin >> a[i];
    int k; cin >> k;
    for(int i = 0; i < 5; i++) for(int j = 0; j < 5; j++) if (abs(a[i] - a[j]) > k) die(":(");
    cout << "Yay!" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    vector<int>A;
    int q;
    cin >> q;
    for(int i = 0; i < q; i++) {
        int x;
        cin >> x;
        if(x == 0) {
            int y;
            cin >> y;
            A.push_back(y);
        }
        if(x == 1) {
            int y;
            cin >> y;
            cout << A[y] << endl;
        }
        if(x == 2) {
            A.pop_back();
        }
    }
}



Measured memory_bytes: 4884
//
//  main.cpp
//  AOJ1165
//
//  Created by aki33524 on 2014/07/09.
//  Copyright (c) 2014年 aki33524. All rights reserved.
//

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

typedef struct {int h, w;} Tyle;
int N;

int dh[] = {0, 1, 0, -1};
int dw[] = {-1, 0, 1, 0};

int main(int argc, const char * argv[])
{
    while(cin>>N, N){
        vector<Tyle> tyles;
        Tyle t;
        t.h = 0; t.w = 0;
        tyles.push_back(t);
        
        for(int i=0; i<N-1; i++){
            int n, d;
            cin >> n >> d;
            Tyle t;
            t.h = tyles[n].h + dh[d];
            t.w = tyles[n].w + dw[d];
            tyles.push_back(t);
        }
        
        int l = 0, r = 0, u = 0, d = 0;
        for(int i=0; i<tyles.size(); i++){
            Tyle t = tyles[i];
            l = min(l, t.w);
            r = max(r, t.w);
            u = min(u, t.h);
            d = max(d, t.h);
        }
        cout << r-l+1 << " " << d-u+1 << endl;
    }
    
    return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	string s;
	cin>>s;

	lli gNum=0,pNum=0;
	REP(i,0,s.size()){
		if(s.at(i)=='g')gNum++;
		else pNum++;
	}

	cout<<max(0LL,(gNum-pNum)/2)<<endl;
	

	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void){

  char s1[11], s2[11], s3[11];
  scanf("%s %s %s", s1, s2, s3);
  printf("%c%c%c\n", s1[0]-'a'+'A', s2[0]-'a'+'A', s3[0]-'a'+'A');

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,l,p,q,i,j,f;scanf("%d%d%d",&n,&k,&l);
  int R[n] = {},T[n] = {},g = 1;queue<int> Q;
  vector<int> v[n];
  for(i=0;i<k;i++){
    scanf("%d%d",&p,&q);p--;q--;
    v[p].push_back(q);
    v[q].push_back(p);
  }
  for(i=0;i<n;i++){
    if(R[i]!=0) continue;
    queue<int>().swap(Q);Q.push(i);
    while(!Q.empty()){
      f = Q.front();Q.pop();R[f] = g;
      for(j=0;j<v[f].size();j++){
        if(R[v[f][j]]==0) Q.push(v[f][j]);
      }
    }
    g++;
  }
  g = 1;vector<int> V[n];
  for(i=0;i<l;i++){
    scanf("%d%d",&p,&q);p--;q--;
    V[p].push_back(q);
    V[q].push_back(p);
  }
  for(i=0;i<n;i++){
    if(T[i]!=0) continue;
    queue<int>().swap(Q);Q.push(i);
    while(!Q.empty()){
      f = Q.front();Q.pop();T[f] = g;
      for(j=0;j<V[f].size();j++){
        if(T[V[f][j]]==0) Q.push(V[f][j]);
      }
    }
    g++;
  }
  int ans[n],c = 1;pair<pair<int,int>,int> S[n];
  for(i=0;i<n;i++){
    S[i].first.first=R[i];
    S[i].first.second=T[i];
    S[i].second=i;
  }
  sort(S,S+n);
  for(i=1;i<n;i++){
    if(S[i].first.first==S[i-1].first.first && S[i].first.second==S[i-1].first.second) c++;
    else{
      for(j=i-c;j<i;j++) ans[S[j].second] = c;
      c = 1;
    }
  }
  for(j=n-c;j<n;j++) ans[S[j].second] = c;
  for(i=0;i<n;i++) printf("%lld ",ans[i]);
  printf("\n");
}

Measured memory_bytes: 60804
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007


int main() {

  int N;
  cin >> N;

  vector<int> a(N+1);
  for(int i = 1;i <= N;i++) {
    cin >> a.at(i);
  }

  int ans = 0;
  for(int i = 1;i <= N;i++) {
    if(a.at(a.at(i)) == i) {
      ans++;
      a.at(i) = 0;
    }
  }

  cout << ans << endl;


}



Measured memory_bytes: 640