akhauriyash/Code-Regression huggingface dataset:
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
A=nl()

ans=0
for i in range(1,N+1):
    if(i%2==1):
        if(A[i-1]%2==1):
            ans+=1

print(ans)
        


Measured memory_bytes: 10448
S=list(input())
left=S[0:(len(S)-1)//2]
right=S[(len(S)-1)//2+1:]

def is_kaibun(string):
    if string==string[::-1]:
        return True
    else:
        return False



def yes():
    print("Yes")
    exit()
def No():
    print("No")
    exit()
if not left ==right:
    No()
else:
    if is_kaibun(left):
        yes()
    else:
        No()

Measured memory_bytes: 3064
n = int(input())
s = [list(input()) for i in range(n)]
cnt_dic = {}
sum_cnt = 0

for i in range(n):
    s[i].sort()
    if str(s[i]) in cnt_dic:
        cnt_dic[str(s[i])] = cnt_dic[str(s[i])] + 1
    else:
        cnt_dic[str(s[i])] = 1

for n in cnt_dic.values():
    sum_cnt += int( n * (n-1) / 2)

print(sum_cnt)

Measured memory_bytes: 41464
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
#define _LIBCPP_DEBUG 0
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)	
using namespace std;


int max(int a,int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}


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

	vector<int> a(300);

	rep(i, n) {
		cin >> a[i];
	}

	int count = 0;

	while (true) {
		bool exist_odd = false;
		rep(i, n) {
			if (a[i] % 2 != 0) {
				exist_odd = true;
			}
		}
		if (exist_odd)
			break;
		rep(i, n) {
			a[i] /= 2;
		}
		++count;
	}

	cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <regex>
#include <string>
#include <cstdlib>
#include <math.h>
using namespace std;
int main() {
  long long A, B;
  cin >> A >> B;

  long long big, small;
  if (A > B) {
    big = A;
    small = B;
  } else {
    big = B;
    small = A;
  }

  long long n = 1;
  while(true) {
    long long t = big * n;
    if (t % small == 0) {
      cout << t << endl;
      return 0;
    }
    n++;
  }
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int):
    def is_prime(n):
        i = 2
        while i * i <= n:
            if n % i == 0:
                return False
            i += 1
        return True
    def comb(n, k):
        if n < k:
            return 0
        ret = 1
        for i in range(k):
            ret *= n - i
            ret //= (i + 1)
        return ret
    primes = []
    for i in range(2, N + 1):
        if is_prime(i):
            primes.append(i)

    count = [0] * (N + 1)
    def count_up(n):
        for p in primes:
            while n >= p and n % p == 0:
                count[p] += 1
                n //= p
        return
    for i in range(2, N + 1):
        count_up(i)
    count.sort(reverse=True)
    over_75 = 0
    over_25 = 0
    over_15 = 0
    over_5 = 0
    over_3 = 0
    for c in count:
        if c >= 2:
            over_3 += 1
        if c >= 4:
            over_5 += 1
        if c >= 14:
            over_15 += 1
        if c >= 24:
            over_25 += 1
        if c >= 74:
            over_75 += 1
    ret = (over_75 + over_25 * (over_3 - 1) +
           over_15 * (over_5 - 1) +
           comb(over_5, 2) * (over_3 - 2))
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import math
import numpy as np
N, D = map(int, input().split())

x_list = np.array([list(map(int, input().split())) for i in range(N)])

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        l = math.sqrt(np.sum((x_list[j]-x_list[i])**2))
        if l.is_integer():
            ans += 1
print(ans)


Measured memory_bytes: 12408
a,b,c=input().split()
d = int(a)*7+int(b) #一週間で手に入るコイン
e = int(c)//d #必要な週の数
f = int(c)-d*e #残りのコイン
if f<=6*int(a) and f%int(a)>0 : g=f//int(a)+1
elif f<=6*int(a) and f%int(a)<=0 : g=f/int(a)
else : g=7
print(int(e*7+g))


Measured memory_bytes: 5600
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b; cin >> a >> b;
    if(a%3==0 || b%3==0 || (a+b)%3==0) cout << "Possible";
    else cout << "Impossible";
    cout << endl;
    return 0;
}



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

#define ll long long
#define lp(i,n) for(int i=0; i<n; i++)
#define pb push_back
const long double pi=3.141592654;
#define OSOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;




int main()
{
	OSOS
	int n;
	cin>>n;
	if(n%2)
		cout<<n/2+1;
	else
		cout<<n/2;
}


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

int main()
{
  int n,r,c=0;
  cin>>n;
   while(n>0){
    r=n%10;
    n=n/10;
    if(r==7){
      c++;
    }
   }
    if(c>=1)
    cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3132
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
#include<limits>
#include<iomanip>
#include<set>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 100000000
#define NUM 1000000007
#define all(x) begin(x), end(x)

int main() {
	int n;
	cin >> n;
	VI a(n),y;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		y.push_back(a[i]);
	}
	
	sort(all(y));

	//for (int i = 0; i < n; i++)cout << y[i] << endl;

	int right = y[n / 2 - 1];
	int left = y[n / 2];
	//cout << right << " " << left << endl;
	for (int i = 0; i < n; i++) {
		if (a[i] < left) cout << left << endl;
		else cout << right << endl;
	}

	return 0;

}

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

#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define VPII vector<PII>
#define LD long double
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000 // array max range

int N,M;
vector<vector<bool>> ab;
vector<bool> visited;
vector<int> route;
int dfs(int depth,int now){
    if(depth == N-1){
        R(i,N){
            if(!visited[i]) break;
            if(i==N-1){
                return 1;
            }
        }
        return 0;
    }
    int ans = 0;

    R(i,N){
        if((ab[now][i] || ab[i][now]) && !visited[i]){
            visited[i] = true;
            ans += dfs(depth+1,i);
            visited[i] = false;
        }
    }
    return ans;
}
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(11);
    cerr << fixed << setprecision(6);
    cin >> N >> M;
    //ab.assign(M,vector<bool>(M,false));
    ab.assign(N,vector<bool>(N,false));
    visited.assign(N,false);
    int a,b;
    R(i,M){
        cin >> a >> b;
        a--;
        b--;
        ab[a][b] = true;
    }
    visited[0]=true;
    cout << dfs(0,0) << endl;
    return 0;
}


Measured memory_bytes: 3676
n = int(input())
a = []
for i in range(n):
    cmd = list(map(int, input().split()))
    if cmd[0] == 0:
        a.append(cmd[1])
    elif cmd[0] == 1:
        print(a[cmd[1]])
    elif cmd[0] == 2:
        a.pop(-1)



Measured memory_bytes: 13360
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
#define REP(i,n) for (int i = 0; i <(n); ++i)
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << 
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " ";} cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  //input
  string s;
  cin >> s;
  //文字列sのサイズn取得
  int n = s.size();

  //部分文字列の長さを決定　n-7
  int m = n - 7;
  //サイズ７の文字列Tの作製して比較REP(k,0,8) //0-7まで
  //keyenceとTの比較　bool okを定義

  
  bool ok = false;
  REP(k,8){
    string T = "";
    REP(i,k){
      T += s[i];
    }
    REP2(i,k+m,n){
      T += s[i];
    }
    //cout << T << endl;
    if(T == "keyence") {
      ok = true;
      break;
    }
  }

  //output
  if(ok) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll inf = 1e13;

int main() {
  ll N; cin >> N;
  vector<P> vec;
  vec.push_back(P(1, N));
  for(ll i = 2; i*i <= N; i++) {
    if(N%i==0) vec.push_back(P(i, N/i));
  }
  ll ans = inf;
  for(auto v : vec) {
    ans = min(ans, v.first+v.second-2);
  }
  cout << ans << endl;

  return 0;
}


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

int main()
{
    int n, m;
    cin >> n >> m;
    int ac[100002]{0};
    int wa[100002]{0};
    for(int i = 0; i < m; i++){
        int p;
        cin >> p;
        p--;
        string s;
        cin >> s;
        if(s == "AC") ac[p] = 1;
        if(s == "WA" && ac[p] == 0) wa[p]++;
    }
    int sac = 0, swa = 0;
    for(int i = 0; i < n; i++){
        sac += ac[i];
        if(ac[i] == 1) swa += wa[i];
    }
    cout << sac << " " << swa << endl;
}

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

namespace ABC
{
    class Abc173
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int ov = N % 1000;
            if (ov == 0)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(1000 - ov);
            }

            Console.ReadLine();
        }

    }
}

Measured memory_bytes: 27536
let is_triangle a b c =
    a**2.0 +. b**2.0 = c**2.0

let () =
    let n = Scanf.scanf "%d\n" (fun x -> x) in
    for i = 1 to n do
        let lengthes = Scanf.scanf "%f %f %f\n" (fun a b c -> [|a; b; c|]) in
        Array.sort compare lengthes ;

        let a, b, c = lengthes.(0), lengthes.(1), lengthes.(2) in
        let result  = if (is_triangle a b c) then "YES" else "NO" in
        Printf.printf "%s\n" result ;
    done

Measured memory_bytes: 3580
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  int a,p;
  cin >>a>>p;
  cout <<(3*a+p)/2<<endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
/*
template<class... T>
ostream& operator<<(ostream& os, tuple<T...>& t) {
	for (size_t i = 0; i < tuple_size< tuple<T...> >::value; ++i) {
		if (i) os << " ";
		os << get<0>(t);
	}
	return os;
}
*/
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

string to_s(int n) {
    stringstream ss; ss << n;
    string s; ss >> s;
    return s;
}
struct Node {
    map<int, Node> m;
};
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
    int n; cin >> n;
    vector<int> v(n); cin >> v;
    Node root = Node();
    REP(i, n) {
        Node *node = &root;
        FOR(j, i, n) {
            if ( !node->m.count(v[j]) ) {
                node->m[v[j]] = Node();
            }
            node = &node->m[v[j]];
        }
    }
    REP(i, 1e7) {
        string s = to_s(i);
        Node *node = &root;
        bool f = false;
        REP(j, s.size()) {
            int d = s[j]-'0';
            if ( node->m.count(d) ) {
                node = &node->m[d];
            }
            else {
                f = true;
                break;
            }
        }
        if (f) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 49884
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N, X;
  cin >> N >> X;
  vector<ll> L(N);
  for (ll i = 0; i < N; i++) {
    cin >> L[i];
  }
  vector<ll> D(N + 1);
  D[0] = 0;
  for (ll i = 1; i < N + 1; i++) {
    D[i] = D[i - 1] + L[i - 1];
  }
  const ll ans = count_if(cbegin(D), cend(D), [X](auto x) { return x <= X; });
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> H(N);
	for (int i = 0; i < N; ++i) {
		cin >> H[i];
	}
	vector<int> dp(N);
	for (int i = 1; i < N; ++i) {
		dp[i] = dp[i - 1] + abs(H[i] - H[i - 1]);
		if (i >= 2) dp[i] = min(dp[i], dp[i - 2] + abs(H[i] - H[i - 2]));
	}
	cout << dp[N - 1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=2e5+10;
int N;
int cnt[MAXN];
int A[MAXN];
void solve()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    for(int u=1;u<=N;u++){
        cin>>A[u];
        if(u>=A[u])cnt[u-A[u]]++;
    }
    ll ans=0;
    for(int u=1;u<=N;u++){
        if(u+A[u]<MAXN)
            ans+=cnt[u+A[u]];
        if(u>=A[u])cnt[u-A[u]]--;
    }
    cout<<ans;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

Measured memory_bytes: 5108
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace E
{
	internal class Program
	{
		static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };

		public static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var an = Console.ReadLine().Split().Select(int.Parse).ToList();
			var max = an.Max();
			var min = an.Min();
			var allPlusNum = max + min > 0 ? max : min;
			var isPlusMode = allPlusNum >= 0;
			var allPlusNumIdx = an.FindIndex(a => a == allPlusNum);

			an = an.ConvertAll(a => a += allPlusNum);
			an[allPlusNumIdx] -= allPlusNum;

			var secondList = new List<int>(n);
			if (isPlusMode)
			{
				for (var i = 0; i < n - 1; i++)
				{
					if (an[i] > an[i + 1])
					{
						an[i + 1] += an[i];
						secondList.Add(i + 1);
					}
				}
			}
			else
			{
				for (var i = n - 1; i >= 1; i--)
				{
					if (an[i - 1] > an[i])
					{
						an[i - 1] += an[i];
						secondList.Add(i + 1);
					}
				}
			}

			sw.WriteLine(n - 1 + secondList.Count);

			for (var i = 0; i < n; i++)
			{
				if (i != allPlusNumIdx) { sw.WriteLine($"{allPlusNumIdx + 1} {i + 1}"); }
			}

			foreach (var ax in secondList) { sw.WriteLine($"{ax} {ax + (isPlusMode ? 1 : -1)}"); }

			sw.Flush();
		}
	}
}

Measured memory_bytes: 13524
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int N;
	cin >> N;

	if (N >= 30)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}

	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

//3
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){

ios::sync_with_stdio(false);
cin.tie(0);
long long int n,m;
cin>>n>>m;

vector<int> a(n);

for(int i=0;i<m;i++){
int k;
cin>>k;
for(int j=0;j<k;j++){
int s;
cin>>s;
s--;
a[s] |= 1<<i;
}

}

int p=0;
for(int i=0;i<m;i++){
int x;
cin>>x;
p |= x<<i;
}

int ans=0;

for(int s=0;s<(1<<n);s++){
int t=0;
for(int i=0;i<n;i++){
if(s>>i & 1){
t^=a[i];
}

}

if(t==p){
ans++;
}
}


cout<<ans<<endl;

}



//cout << fixed << setprecision(5) <<(n*2)*M_PI << endl;



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

int n,m;
bool graph[60][60] = {false};
bool vis[60] = {false};

void dfs(int x)
{
	if(vis[x]) return;
	vis[x] = true;
	for(int i = 0; i < n; i++){
		if(graph[x][i]) dfs(i);
	}
	return;
}

int main()
{
	int cnt = 0;
	int a[60] = {0};
	int b[60] = {0};
	std::cin >> n >> m;
	for(int i = 0; i < m; i++){
		std::cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		graph[a[i]][b[i]] = true;
		graph[b[i]][a[i]] = true;
	}
	
	for(int i = 0; i < m; i++){
		for(int j = 0; j < n; j++) vis[j] = false;
		graph[a[i]][b[i]] = false;
		graph[b[i]][a[i]] = false;
		dfs(0);
		for(int j = 0; j < n; j++)
			if(!vis[j]){
				cnt++;
				break;
			}
		graph[a[i]][b[i]] = true;
		graph[b[i]][a[i]] = true;
	}

	std::cout << cnt;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,s=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        if(i%3==0||i%5==0)
            continue;
        s+=i;
    }
    cout<<s<<endl;
}


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

main(){
  int data[100][2], ans[101];
  int seki[17], q=0;
  for(int i=0;i<100;i++){
    if(i%5==1){
      data[i][0]=5;
    }
    else{
      data[i][0]=2;
    }
    data[i][1]=17*(i%2)+3*(i%3)+19;
  }
  for(int i=0;i<17;i++){
    seki[i]=0;
  }
  
  for(int i=0;i<1000;i++){
    // printf("!%d! ", i);
    for(int j=0;j<17;j++){
      //printf("%2d ", seki[j]);
    }
    //printf("\n");
    for(int j=0;j<17;j++){
      if(seki[j]>0){
	seki[j]--;
      }
    }

    while(q<=i/5){
      int tmp=q;
      if(data[q][0]==2){
	for(int j=0;j<16;j++){
	  if(seki[j]==0 && seki[j+1]==0){
	    seki[j]=seki[j+1]=data[q][1];
	    ans[q]=i-q*5;
	    q++;
	    break;
	  }
	}
      }
      else{
	for(int j=0;j<13;j++){
	  if(seki[j]==0 && seki[j+1]==0 && seki[j+2]==0 && seki[j+3]==0 && seki[j+4]==0){
	    seki[j]=seki[j+1]=seki[j+2]=seki[j+3]=seki[j+4]=data[q][1];
	    ans[q]=i-q*5;
	    q++;
	    break;
	  }
	}
      }
      if(tmp==q) break;
    }
  }
  
  int n;
  while(cin >> n){
    cout << ans[n] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 0
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \|     |//  `.
            /  \|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            pass the Test!
*/
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;

int main(){
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    ll V;
    cin >> V;
    ll P;
    cin >> P;
    vector<ll> A(N,0);
    for(ll i=0;i<N;i++){
        cin>>A[i]
    ;}
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    vector<ll> ikou(N+1,0);
    for(ll i=N-1;i>=0;i--){
        ikou[i]=ikou[i+1]+A[i]
    ;}
    ll ans=P-1;
    for(ll i=P;i<N;i++){
        if(A[P-1]-A[i]<=M&&M*V-M*(N-i+P-1)<=(A[i]+M)*(i-P+1)-(ikou[P-1]-ikou[i]))ans=i;
        else break;
    ;}
    cout<<ans+1<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define N 2000009
#define ll long long
#define ld long double
#define ff first
#define ss second
#define inf 1000000005
#define mod 1000000007
using namespace std;
int n, k, a[109];
string ans[2] = {"Second", "First"};
int main() {
    cin>>n>>k;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
    }
    vector<bool> winf(k + 1);
    winf[0] = 0;
    for(int i=1;i<=k;i++) {
        for(int j=1;j<=n;j++) {
            if(a[j] <= i && winf[i - a[j]] == 0) {
                winf[i] = 1;
                break;
            }
        }
    }
    cout<<ans[winf[k]]<<endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin>>n;
  int a[n],b[n];
  int diff=0;
  for(int i=1;i<=n;i++){
    cin>>a[i-1];
    b[i-1]=i;
  }
  for(int i=0;i<n;i++){
    if(a[i]!=b[i]){
      diff++;
    }
  }
  if(diff<=2){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
  int input, sec, min, hour;
  scanf("%d", &input);
  hour = input / 3600;
  min = (input - hour * 3600) / 60;
  sec = input - (hour * 3600 + min *60);
  printf("%d:%d:%d\n", hour, min, sec);
  return 0;
}

Measured memory_bytes: 592
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int N;
    cin >> N;
    vi a(N);
    REP(i, N) cin >> a[i];

    vi dp(1e6+10, 0);
    REP(i, N) {
        if (dp[a[i]] != 0) {
            dp[a[i]] = 2;
            continue;
        }
        int y = a[i];
        while (INRANGE(y, 1, (int)1e6+10))
        {
            dp[y]++;
            y += a[i];
        }

    }

    int ans = 0;
    REP(i, N) {
        if (dp[a[i]] == 1) ans++;
    }

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


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

void solve()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> adj(N);
    vector<int> H(N);
    REP0 (i, N)
    {
        cin >> H[i];
    }
    REP1 (i, M)
    {
        int A, B;
        cin >> A >> B;
        A--;
        B--;
        adj[A].push_back(B);
        adj[B].push_back(A);
    }

    int ans = 0;
    REP0 (i, N)
    {
        bool is_good = true;
        for (auto v : adj[i])
        {
            if (H[i] <= H[v])
                is_good = false;
        }
        ans += is_good;
    }

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

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 8708
#include<bits/stdc++.h>
using namespace std;
 
int N,M;
 
int v[100001];
vector<pair<int,int>>e[100001];
 
void dfs(int i,int x){
	v[i]=x;
	for(auto a:e[i]){
		if(v[a.first]){
			if(v[i]+a.second!=v[a.first]){
				cout<<"No";
				exit(0);
			}
		}else{
			dfs(a.first,v[i]+a.second);
		}
	}
}
 
main(){
	cin>>N>>M;
	for(int i=0;i<M;++i){
		int L,R,D;
		scanf("%d%d%d",&L,&R,&D);
		e[L].push_back({R,D});
		e[R].push_back({L,-D});
	}
	for(int i=1;i<=N;++i){
		if(!v[i]){
			dfs(i,(int)1e9);
		}
	}
	cout<<"Yes";
}

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

using namespace std;

#define ALL(c) c.begin(), c.end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define DB(a) cerr << #a << " = " << (a) << endl;
#define OUT( a , n ) for( int J = 0; J < (n); J++ )cout<< (a)[J] << " \n"[J == (n) - 1 ]
#define WAIT cout << flush , system("PAUSE");
#define lowbit(x) ((x) & (-x))
#define CONTAINS(a, x) ((a).find(x) != (a).end())
#define endl '\n'
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repi(i,0,n)

typedef long long li;

const int N = 1e6+100;

int n;
vector<int> G[N];

int d1[N];
int d2[N];
bool mk[N];

void bfs(int u , int * dist){
	memset(mk , 0 , sizeof mk);
	queue<int> q;
	q.push(u);
	mk[u] = true;
	while(!q.empty()){
		int top = q.front();q.pop();

		for(auto v : G[top]){
			if(!mk[v] && dist[v] == 0){
				dist[v] = dist[top] + 1;
				mk[v] = true;
				q.push(v);
			}
		}
	}
}

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

	cin >> n;
	for( int i = 0; i < n - 1; i++ ){
		int u , v;cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}

	bfs(1, d1);
	bfs(n ,d2);

	int a = 0;
	int b = 0;

	for( int i = 1; i <= n; i++ ){
		if(d1[i] <= d2[i]){
			a++;
		}else b++;
	}

	a-- , b--;

	if(a > b){
		cout << "Fennec" << endl;
	}else cout << "Snuke" << endl;


    return 0;
}


Measured memory_bytes: 30976
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;
vector<int> prime;
ll p[N];
void seive(){
    p[0] = p[1] = 1;
    for(int i = 2; i < N; i++){
        if(p[i]) continue;
        prime.PB(i);
        for(int j = i + i; j < N; j += i){
            p[j] = 1;
        }
    }
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    seive();
    int n;
    cin >> n;
    cout << prime[lower_bound(ALL(prime), n) - prime.begin()];
    return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define ll long long int
#define pb(i) push_back(i)
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--)
    {
        string str;
        cin>>str;
        int sum=0;
        for(int i=0;i<str.size();i++)
            sum+=str.at(i)-'0';
        if(sum%9==0)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
}


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

int main() {
  int a, b;
  cin >> a >> b;
  
  int x = a * b / 2;
  int y = a * b;
  
  x = x * 2;
  
  if (x == y){
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n;
  cin >> n;
  vi c(n - 1), s(n - 1), f(n - 1);
  REP(i, n - 1) { cin >> c[i] >> s[i] >> f[i]; }
  REP(i, n) {
    int ans = 0;
    FOR(j, i, n - 1) {
      if (ans <= s[j]) {
        ans = s[j] + c[j];
      } else if (ans % f[j] == 0) {
        ans += c[j];
      } else {
        ans += f[j] - (ans % f[j]) + c[j];
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
#from scipy.misc import comb

N = int(input())
S = []
for _ in range(N):
    s = input()
    S.append(s)

cnt = [10000]*26
for s in S:
    for i in range(26):
        cnt[i] = min(cnt[i], s.count(chr(97+i)))

ans = ""
for i in range(26):
    if cnt[i] < 10000: ans += chr(97+i)*cnt[i]

print(ans)

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int D; cin >> D;
    cout << "Christmas";
    REP(i,25-D) cout << " Eve";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
n = raw_input()
a = map(int, raw_input().split(' '))
import collections
q = 0
cc = collections.Counter(a)
for k in cc:
	q += cc[k] * (cc[k]-1) /2


for e in a:
	q -= cc[e] * (cc[e]-1) /2
	cc[e]-=1 
	q += cc[e] * (cc[e]-1) /2
	print q
	q -= cc[e] * (cc[e]-1) /2
	cc[e]+=1 
	q += cc[e] * (cc[e]-1) /2
	



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

int main()
{
    int k;
    int ans = 0;
    cin >> k;
    for (int a = 1; a < k + 1; a++)
    {
        for (int b = 1; b < k + 1; b++)
        {
            for (int c = 1; c < k + 1; c++)
            {
                ans += __algo_gcd(a, __algo_gcd(b, c));
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3168
#include <stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d",&a);
	scanf("%d",&b);
	if(a==b){return -1;}
	if(a>3||a<1||b>3||b<1){return -1;}
	c=a+b;
	if(c==3){printf("3");}
	else if(c==4){printf("2");}
	else if(c==5){printf("1");}
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <tuple>
#include <queue>
using namespace std;

typedef long long ll;

#define INF 100000000;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define eps 1.0e-14;

using pint = pair<ll,ll>;

int main(){
	int a,b; cin >> a >> b;
	cout << ((a*3)+b)/2 << endl;
	return 0;
}

Measured memory_bytes: 256
a,b,c,x,y = map(int,input().split())

ans = 10000000000000000000000000000

for i in range(max(x,y)+1):
    price = 2*i*c + max(0,x-i)*a + max(0,y-i)*b
    
    if ans > price:
        ans = price
    
    else:
        continue
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a;
  cin >> a;
  string ans = a;
  if(a == "A"){
    ans = "A";
  }else if(a == "B"){
    ans = "A";
  }else if(a == "C"){
    ans = "A";
  }else if(a == "D"){
    ans = "A";
  }else if(a == "E"){
    ans = "A";
  }else if(a == "F"){
    ans = "A";
  }else if(a == "G"){
    ans = "A";
  }else if(a == "H"){
    ans = "A";
  }else if(a == "I"){
    ans = "A";
  }else if(a == "J"){
    ans = "A";
  }else if(a == "K"){
    ans = "A";
  }else if(a == "L"){
    ans = "A";
  }else if(a == "M"){
    ans = "A";
  }else if(a == "N"){
    ans = "A";
  }else if(a == "O"){
    ans = "A";
  }else if(a == "P"){
    ans = "A";
  }else if(a == "Q"){
    ans = "A";
  }else if(a == "R"){
    ans = "A";
  }else if(a == "S"){
    ans = "A";
  }else if(a == "T"){
    ans = "A";
  }else if(a == "U"){
    ans = "A";
  }else if(a == "V"){
    ans = "A";
  }else if(a == "W"){
    ans = "A";
  }else if(a == "X"){
    ans = "A";
  }else if(a == "Y"){
    ans = "A";
  }else if(a == "Z"){
    ans = "A";
  }else{
    ans = "a";
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(void) {
    int n, i, sum_profit = 0, temp_profit;
    scanf("%d", &n);
    int v[n], c[n];
    for ( i = 0; i < n; i++ ) {
        scanf("%d", &v[i]);
    }
    for ( i = 0; i < n; i++ ) {
        scanf("%d", &c[i]);
    }
    for ( i = 0; i < n; i++ ) {
        temp_profit = v[i] - c[i];
        if ( temp_profit > 0 ) {
            sum_profit += temp_profit;
        }
    }
    printf("%d\n", sum_profit);
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int A= sc.nextInt();
    char op=sc.next().charAt(0);
    int B=sc.nextInt();
    if(op=='+') {
      System.out.println(A+B);
    } else {
      System.out.println(A-B);
    }

  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin>>t;
    string s;
    cin>>s;
    int c=0;
    if(t%2!=0){
        cout<<"No";
        //return 0;
    }
    //int c=0;
    else{
        for(int i=0;i<t/2;i++){
            if(s[i]==s[i+t/2]){
                c++;
            }
        }
        if(c==t/2){
            cout<<"Yes";
        }
        else{
            cout<<"No";
        }
    }
    return 0;
}

Measured memory_bytes: 256
class UnionFindWeighted
  def initialize(n)
    @parent = (0...n).to_a # 親の番号
    @rank = Array.new(n, 0) # 木の深さ
    @diff_weight = Array.new(n, 0) # 親との重みの差
  end

  def root(x)
    return x if @parent[x] == x
    r = root(@parent[x])
    @diff_weight[x] += @diff_weight[@parent[x]]
    @parent[x] = r
    return r
  end

  def weight(x)
    root(x)
    return @diff_weight[x]
  end

  def same?(x, y)
    root(x) == root(y)
  end

  def diff(x, y)
    # x と y とが同じグループにいるとき、weight(y) - weight(x) を返す
    # 同じグループでないならnil
    return nil if !same?(x, y)
    return weight(y) - weight(x)
  end

  def merge(x, y, w)
    # weight(y) - weight(x) = wとなるように結合
    w += weight(x)
    w -= weight(y)
    x, y = root(x), root(y)
    return false if x == y
    if @rank[x] < @rank[y]
      x, y = y, x
      w = -w
    end
    @rank[x] += 1 if @rank[x] == @rank[y]
    @parent[y] = x
    @diff_weight[y] = w
    return true
  end
end

n, q = gets.split.map(&:to_i)
uf = UnionFindWeighted.new(n)
ans = []
q.times do
  query = gets.split.map(&:to_i)
  if query[0] == 1
    x, y = query[1..-1]
    ans << (uf.diff(x, y) || "?")
  else
    x, y, z = query[1..-1]
    uf.merge(x, y, z)
  end
end

puts ans



Measured memory_bytes: 15436
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<cmath>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<stdio.h>
#include<queue>
using namespace std;
int main()
{
  int x,a,b;
  cin>>x>>a>>b;
  x-=a;
  x-=x/b*b;
  cout<<x<<endl;
  system("pause");
  return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(auto &t:a)cin>>t;return i;}
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T> void prArr(T a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  string s;
  cin>>s;
  
  int n = s.size();
  for(int i=0;i<n;i++){
    if(i+1<n && s[i] == s[i+1]) cout<<i+1<<" "<<i+2<<endl,exit(0);
    if(i+2<n && s[i] == s[i+2]) cout<<i+1<<" "<<i+3<<endl,exit(0);
  }
  
  cout<<-1<<" "<<-1<<endl;
  return 0;
}


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

int main()
{
	int N;
	string S;
	cin >> N >> S;
	vector<int> B(N+1, 0);
	vector<int> W(N+1, 0);

	int black = 0, red = 0;
	int x = N - 1; int y = 0;
	for(int i = 0; i < N-1; i++){
            for(int j = x; j >= 0;j--){
        if(S[j] == 'R' || !j){
            x = j;
            break;
        }
	}
		if(S[i] == 'W' && S[x] == 'R' && x > i){
			swap(S[i], S[x]);
			x --;
			y ++;
		}
	}
	for (int i = 0; i < N; i++) {
        if (S[i] == 'W') {
			black++;
		}
		B[i + 1] = black;
		if (S[N - i - 1] == 'R') {
			red++;
		}
		W[N - i - 1] = red;
	}

	int ans = 10e8;
	for (int i = 0; i <= N; i++) {
		ans = min(ans, B[i] + W[i]);
	}

	cout << ans + y << endl;
}

Measured memory_bytes: 5240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF 1000000000
#define loop(i,a,b) for(int i=a;i<b;i++)
int main()
{
    //freopen("contest.txt","r",stdin);
    //freopen("contest.txt","w",stdout);
    IOS
    int n;
    cin>>n;
    int r=n%10;
    if(r==2 || r==4 ||r==5 ||r==7 || r==9)
        cout<<"hon"<<endl;
    else if(r==0 || r==1 ||r==6 ||r==8)
        cout<<"pon"<<endl;
    else if(r==3)
        cout<<"bon"<<endl;


    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	int n;
	cin >> n;
	map<char, int> m;
	rep(i, n) {
		char c;
		cin >> c;
		m[c]++;
	}
	cout << (m.size() == 3 ? "Three" : "Four") << endl;
}


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

const int MAX = 100000;

int n, k, r, s, p;
char hand[MAX];

int point(char rsp){
    if(rsp == 's') return r;
    if(rsp == 'p') return s;
    if(rsp == 'r') return p;
}




int main(){ 
    cin >> n >> k >> r >> s >> p;

    string t;
    cin >> t;

    long long ans = 0;
    
    if(n <= k){
        k = n;
    }

    for(int i = 0; i < k; i++){
        ans += point(t[i]);
        if(t[i] == 's') hand[i] = 'r';
        if(t[i] == 'p') hand[i] = 's';
        if(t[i] == 'r') hand[i] = 'p';
    }

    if(k == n){
        cout << ans << endl;
        return 0;
    }

    for(int i = k; i < n; i++){
        if(t[i] != t[i-k]){
            ans += point(t[i]);
            if(t[i] == 's') hand[i%k] = 'r';
            if(t[i] == 'p') hand[i%k] = 's';
            if(t[i] == 'r') hand[i%k] = 'p'; 
        }else{
            if(t[i] == 's' && hand[i%k] == 'r') hand[i%k] = 'x';
            else if(t[i] == 'p' && hand[i%k] == 's') hand[i%k] = 'x';
            else if(t[i] == 'r' && hand[i%k] == 'p') hand[i%k] = 'x';
            else{
                ans += point(t[i]);
                if(t[i] == 's') hand[i%k] = 'r';
                if(t[i] == 'p') hand[i%k] = 's';
                if(t[i] == 'r') hand[i%k] = 'p'; 
            }
        }
    }

    cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  int B = 0;
  int64_t C = 0;
  for (int i = 0; i < N - 1; i++) {
    if (A.at(i) > A.at(i + 1)) {
      B = A.at(i) - A.at(i + 1);
      C += B;
      A.at(i + 1) += B;
    }
  }
  cout << C << endl;
}


Measured memory_bytes: 4008
import java.util.Scanner;
import java.lang.Math;

class Main{
        public static void main(String args[]){
                Scanner scan=new Scanner(System.in);
                double r=scan.nextDouble();
                double s=r*r*Math.PI;
                double l=2*r*Math.PI;
                String ss=String.format("%.5f",s);
                String ll=String.format("%.5f",l);
                System.out.println(ss+" "+ll);
        }
}

Measured memory_bytes: 28276
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
#define mod 1000000007
#define inf 1000000000
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
 
int main(){
  ll n, m;
  cin >> n >> m;
 
  vector<ll> ans(n, 0);
  bool no = false;
  for(ll i = 0; i < m; i++){
    ll s, c;
    cin >> s >> c;
    s--;
    if(n > 1 && s == 0 && c == 0) no = true;
    else if(ans[s] == 0 || ans[s] == c) ans[s] = c;
    else {
      no = true;
    }
  }
 
  if(no){
    cout << -1 << endl;
    return 0;
  }
 
  if(n > 1 && ans[0] == 0){
    ans[0] = 1;
  }
 
  for(ll i = 0; i < n; i++){
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

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

int main(){

  string S;
  cin>>S;
  
  if(S=="AAA" || S=="BBB")cout<<"No"<<endl;

  else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 500005;

int n, i, res, f, tab[55];
string s[55];
char t[105];

int main() {
scanf("%d", &n);
for (i=0;i<n;i++) {
	scanf("%s", t);
	s[i] = t;
	scanf("%d", &tab[i]);
}
scanf("%s", t);
res = 0;
f = 0;
for (i=0;i<n;i++) {
	if (f) res += tab[i];
	if (t == s[i]) f = 1;
}
printf("%d\n", res);
}





Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        sc.close();

        if ((a <= c && b >= c) || (a >= c && b <= c)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }

}

Measured memory_bytes: 21844