akhauriyash/Code-Regression huggingface dataset:
class UF():
  def __init__(self, N):
    self._parent=[n for n in range(0, N)]
    self._size=[1] * N

  def find_root(self, x):
    if self._parent[x]==x:return x
    self._parent[x]=self.find_root(self._parent[x])
    return self._parent[x]

  def unite(self, x, y):
    gx=self.find_root(x)
    gy=self.find_root(y)
    if gx==gy:return

    if self._size[gx]<self._size[gy]:
      self._parent[gx]=gy
      self._size[gy]+=self._size[gx]
    else:
      self._parent[gy]=gx
      self._size[gx]+=self._size[gy]

  def size(self, x):
    return self._size[self.find_root(x)]

  def samegroup(self, x, y):
    return self.find_root(x)==self.find_root(y)

  def groupnum(self):
    N=len(self._parent)
    ans=0
    for i in range(N):
      if self.find_root(i)==i:
        ans+=1
    return ans

  def reset(self):
    self._parent=[n for n in range(0, n)]

n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
ct=0
UF=UF(n)
for i in range(m):
  for j in range(m):
    if j!=i:
      UF.unite(l[j][0]-1,l[j][1]-1)
  if UF.groupnum()!=1:ct+=1
  UF.reset()
print(ct)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
using ll = long long;

int main(){
    int a, b, c, x;
    cin >> a >> b >> c >> x;

    int count = 0;
    int i, j, k;
    for(i = a; i >= 0; i--){
        for(j = b; j >= 0; j--){
            for(k = c; k >= 0; k--){
                if(500*i + 100*j + 50*k == x){
                    count++;
                }
            }
        }
    }

    cout << count << endl;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const ll mod = 1000000007;
ll inv[10000100];
ll FactorialInv[10000100];
ll Factorial[10000100];
ll beki(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}
void init_combination(){
    const int MAX = 10000002;
    Factorial[0] = 1;
    inv[0] = 1;
    for(int i = 1; i <= MAX; i++){
        Factorial[i] = Factorial[i - 1] * i % mod;
    }
    FactorialInv[MAX] = beki(Factorial[MAX], mod - 2);
    for(ll i = MAX - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
    for(int i = 1; i <= MAX; i++) {
        inv[i] = FactorialInv[i] * Factorial[i-1] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}

ll f(ll X, ll Y) {
    ll ret = 0;
    ll tmp = beki(2, mod - 2);
    for(int i = 0; i <= X + Y; i++) {
        tmp *= 2;
        tmp %= mod;
        if(i - 1 >= X) {
            tmp -= combination(i-1, i - 1 - X);
        }
        if(i - 1 >= Y) {
            tmp -= combination(i-1, Y);
        }
        tmp += 3 * mod;
        tmp %= mod;
        //cerr << i << " " << tmp << endl;
        ret += tmp;
        ret %= mod;
    }
    cerr << ret << endl;
    return ret;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    init_combination();
    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    ll ans = 0;
    ans += f(r2, c2);
    ans -= f(r1-1, c2);
    ans -= f(r2, c1-1);
    ans += f(r1-1, c1-1);
    ans %= mod;
    ans += mod;
    ans %= mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 234752
from itertools import combinations as ic
N = int(input())
L = map(int, input().split())
A = list(ic(L, 3))
ans = 0
for i in A:
  if 2 * max(i) - sum(i) < 0 and len(set(i)) == 3:
    ans += 1
else:
  print(ans)

Measured memory_bytes: 20580
/*
ID: computerbox --> Huseyn Hajiyev
LANG: C++
TASK: target_mode_on
*/
#include <bits/stdc++.h>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define _CRT_SECURE_NO_WARNINGS
//#include <boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#define FAST_READ ios_base::sync_with_stdio(0);
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAXN 2000
//cin.ignore (7777, '\n');

using namespace std;

#define debug(args...)(Debugger()) , args
class Debugger
{
  public:
  Debugger(const std::string& _separator=", ") :
  first(true),separator(_separator){}
  template<typename ObjectType>
  Debugger& operator,(const ObjectType& v)
  {
        if(!first)cerr<<separator;
        cerr<<v;
        first=false;
        return *this;
  }
  ~Debugger() {cerr<<endl;}      
  private:
    bool first;
    string separator;
};
 
template <typename T1, typename T2>
inline ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
   return os<<"("<<p.first<<", "<<p.second<<")";
}
template<typename T>
inline ostream &operator<<(ostream & os,const vector<T>& v)
{
    bool first=true;
    os<<"[";
    for(unsigned ll i=0;i<v.size();i++)
    {
        if(!first)os<<", ";
        os<<v[i];
        first=false;
    }
        return os<<"]";
}
template<typename T>
inline ostream &operator<<(ostream & os,const set<T>&v)
{
    bool first=true;
    os<<"[";
    for(typename set<T>::const_iterator ii=v.begin();ii!=v.end();++ii)
    {
        if(!first)os<<", ";
        os<<*ii;
        first=false;
    }
    return os<<"]";
}
template<typename T1, typename T2>
inline ostream &operator<<(ostream & os,const map<T1, T2>&v)
{
        bool first=true;
        os<<"[";
        for(typename map<T1,T2>::const_iterator ii=v.begin(); ii!=v.end();++ii)
        {
            if(!first)os<<", ";
            os<<*ii;
            first=false;
        }
        return os<<"]";
}

ll n,x;
ll X;
vector<ll>massiv;
int main(){
FAST_READ;
//cin.tie(0);
cin>>n>>X;
for(ll i=1;i<=n;i++)
{
  cin>>x;
  massiv.pb(x);
}
sort(all(massiv));
ll minn=abs(massiv[0]-X);
for(ll i=1;i<massiv.size();i++)
{
  minn=__gcd(abs(massiv[i]-X),minn);
}
cout<<minn<<endl;




return 0;
} 


Measured memory_bytes: 1400
S = input()
S = S[::-1]
T = ['dream', 'dreamer', 'erase', 'eraser']

T_rev = []

for i in range(len(T)):
	T_rev.append(T[i][::-1])

flag = True
i = 0
while i < len(S):
	for j in range(len(T)):
		ed = i + len(T_rev[j])
		# print(S[i:ed])
		if (S[i:(i + len(T_rev[j]))] == T_rev[j]):
			i += len(T[j])
			flag = True
			break
		else:
			flag = False

	if(flag == False):
		break

if(flag):
	print('YES')
else:
	print('NO')

Measured memory_bytes: 3188
#include <iostream>

int main(){
  int N;
  std::cin >> N;
  if (N % 10 == 3) std::cout << "bon";
  else if (N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8) std::cout << "pon";
  else std::cout << "hon";
  return 0;
}

Measured memory_bytes: 3020
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  map<int, int> cnt[2];
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    cnt[i % 2][a]++;
  }
  vector<vector<pair<int, int>>> v(2);
  for (int i = 0; i < 2; i++) {
    for (auto& p : cnt[i]) v[i].emplace_back(p.second, p.first);
    v[i].emplace_back(0, -1);
    sort(v[i].rbegin(), v[i].rend());
  }
  int ans = 1 << 30;
  for (int i = 0; i < min(3, (int) v[0].size()); i++) {
    for (int j = 0; j < min(3, (int) v[1].size()); j++) {
      if (v[0][i].second != v[1][j].second) {
        ans = min(ans, n - v[0][i].first - v[1][j].first);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

bool dp[5010][10010];
int a[10]={0,2,5,5,4,5,6,3,7,6};
int main(){
	int n,m,x;vector<int> v;
	cin >> n >> m;
	for(int i=0;i<m;i++){
		cin >> x;v.push_back(x);
	}
	sort(v.begin(),v.end());reverse(v.begin(),v.end());
	memset(dp,false,sizeof(dp));
	dp[0][0]=1;
	for(int i=0;i<5005;i++){
		for(int j=0;j<n+1;j++){
			if(!dp[i][j]) continue;
			for(int k=0;k<m;k++) dp[i+1][j+a[v[k]]] = true;
		}
	}
	int d=0;
	for(int i=0;i<5005;i++){
		if(dp[i][n]) d = max(d,i);
	}
	string out="";
	for(int i=d;i>0;i--){
		x=0;
		for(int j=0;j<m;j++){
			if(dp[i-1][n-a[v[j]]])  x=max(x,v[j]);
		}
		out+=('0'+x);n-=a[x];
	}
	cout << out <<endl;
	return 0;
}

Measured memory_bytes: 49280
gets.to_i.times do
  arr = gets.split ' '
  arr = arr.map { |x| x.to_i }
  arr.sort!
  if arr[2]*arr[2] == arr[1]*arr[1] + arr[0]*arr[0] then
    puts 'YES'
  else
    puts 'NO'
  end
end

Measured memory_bytes: 6096
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
signed main(){
	int a,b;
	cin>>a>>b;
	cout<<(a+b-1)/b<<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    if (n % 2 == 0) {
      System.out.println((n/2)*(n/2));
    } else {
      System.out.println(((n+1)/2)*((n-1)/2));
    }
  }
}

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

int main() {
	int N;
    cin >> N;
	string s;
	cin >> s;
    list<char> S;
    for (int i = 0; i < N; i++) {
        S.push_back(s[i]);
    }
	list<char> A;
	for (int i = 0; i < N; i++) {
		if (A.back() == '(' && s[i] == ')') {
			A.pop_back();
		} else {
			A.push_back(s[i]);
		}
	}
    while (A.back() == '(') {
        A.pop_back();
        S.push_back(')');
    }
    while (A.front() == ')') {
        A.pop_front();
        S.push_front('(');
    }
    for (auto it = S.begin(); it != S.end(); it ++) {
        cout << *it;
    }
    cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <sstream>
#include <cstdlib>
using namespace std;
int main(){
	int n,a[1001],q,b,e,k;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	cin>>q;
	for(int j=0;j<q;j++){
		cin>>b>>e>>k;
		cout<<count(a+b,a+e,k)<<endl;
	}
	return 0;
}


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

int main() {
  long N,K;
  cin >> N >> K;
  vector<int> A(N,0);
  for(int i = 0;i<N;i++){
    cin >> A.at(i);
  }
  long cnt = 0;
  long d = ((K - 1) * K) / 2 % 1000000007;
  for(int i = 0 ;i < N;i++){
    long cnt1 = 0;
    long cnt2 = 0;
    for(int j = i + 1 ; j < N; j++){
      if(A.at(i) > A.at(j)){
        cnt1++;
      }
    }
    for(int j = 0 ; j < i + 1; j++){
      if(A.at(i) > A.at(j)){
        cnt2++;
      }
    }
    cnt += cnt1 * K  % 1000000007;
    cnt += ((cnt1 + cnt2) * d ) % 1000000007;
//    cnt += (cnt1 * (((K + 1) * K) / 2) % 1000000007) % 1000000007;
//    cnt += (cnt2 * (((K - 1) * K) / 2) % 1000000007) % 1000000007;
    cnt %= 1000000007;
  }
  cout << cnt % 1000000007 << endl;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
  typedef long long ll;
#define pii  pair<int,int>
#define vpii vector<pii>
#define vll  vector<ll>
#define vi  vector<int>
#define pb push_back
#define f  first
#define s  second
#define all v.begin(),v.end()
#define fio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
typedef unsigned long long ulll;
 
using namespace std ;
int main () {

  string s;
  cin>>s;
  
  int ct=0;
  if(s[0]=='1')
    ct++;
  
  if(s[1]=='1')
    ct++;
    
    if(s[2]=='1')
    ct++;
  
   cout<<ct;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
char T[16] = "0123456789TJQKA";
char V[5] = "SHCD";
int P[4][13]; char E; string S;
int main() {
	while (true) {
		cin >> E; if (E == '#')break;
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 13; j++)P[i][j] = 0;
		}
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 13; j++) {
				cin >> S;
				for (int k = 0; k < 15; k++) {
					if (S[0] == T[k])P[i][j] += k * 4;
				}
				for (int k = 0; k < 4; k++) {
					if (S[1] == V[k])P[i][j] += k;
				}
				if (S[1] == E)P[i][j] += 100;
			}
		}
		int N = 0, W = 0, M = 0;
		for (int i = 0; i < 13; i++) {
			int maxn = 0, maxid = 0;
			for (int j = 0; j < 4; j++) {
				if (maxn < P[j][i] && (P[j][i] % 4 == P[M][i] % 4 || P[j][i] >= 100)) {
					maxn = P[j][i]; maxid = j;
				}
			}
			M = maxid;
			if (maxid % 2 == 0)N++;
			else W++;
		}
		if (N > W)cout << "NS " << N - 6 << endl;
		else cout << "EW " << W - 6 << endl;
	}
	return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define int long long
using namespace std;

vector<int> G[101010], color;
vector<pair<int, int>> edge;
map<pair<int, int>, int> ans;

void dfs(int n, int pre, int pre_color) {
  int now_color = 1;
  for (auto x : G[n]) {
    if (x != pre) {
      if (now_color == pre_color) {
        now_color++;
      }

      ans[make_pair(n, x)] = now_color;
      ans[make_pair(x, n)] = now_color;

      dfs(x, n, now_color);
      now_color++;
    }
  }
}

signed main() {
  int N;
  cin >> N;
  map<int, int> mp;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
    color.push_back(i + 1);
    edge.push_back(make_pair(a, b));
    mp[a]++;
    mp[b]++;
  }

  int K = -1, mxP;
  for (auto x : mp) {
    if (K < x.second) {
      K = x.second;
      mxP = x.first;
    }
  }

  cout << K << endl;

  dfs(mxP, -1, -1);

  for (auto x : edge) {
    cout << ans[make_pair(x.first, x.second)] << endl;
  }
  return 0;
}

Measured memory_bytes: 27620
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e18;
const ll N = 3e5;
const ll bits = 20;
const ld pi = 3.14159265358979323846;
const ll mod = 1e9+7;
const ll p = 29;

int main(){

    FASTIO;
    PRECISION; 
    
    int n,m;
    cin>>n>>m;

    vector<int>arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr.begin(),arr.end());
    vector<array<int,2>>store(m);
    for(int i=0;i<m;i++){
        cin>>store[i][0]>>store[i][1];
    }

    // for(int i=0;i<n;i++){
    //     cout<<arr[i]<<" ";
    // }
    // cout<<"\n";

    sort(store.begin(),store.end(),[&](array<int,2>a,array<int,2>b){
        return a[1]>b[1];
    });

    int ptr = 0;

    for(int i=0;i<m;i++){
        int cntr = 0;
        // cout<<store[i][0]<<" "<<store[i][1]<<"\n";
        while(ptr<n && arr[ptr]<store[i][1] && cntr<store[i][0]){
            arr[ptr] = store[i][1];
            ptr++;
            cntr++;
        }
    }

    // for(int i=0;i<n;i++){
    //     cout<<arr[i]<<" ";
    // }

    // cout<<"\n";

    ll sum = 0;
    for(int x: arr){
        sum+=x;
    }
    cout<<sum<<"\n";
}


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

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    int n; cin >> n;
    vector <int> ps;
    int p;
    REP(i, n){
        cin >> p;
        ps.push_back(p);
    }
    int ans = 0;
    REP(i, n-2){
        int f = ps[i];
        int s = ps[i+1];
        int t = ps[i+2];
        if ((f<=s and s<=t) or (t<=s and s<=f)){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

#define int long long

int A[100010], B[100010];

signed main() {
    int n;
    
    std::cin >> n;
    
    for(int i = 0; i < n; ++i) {
        std::cin >> A[i] >> B[i];
    }
    
    int sum = 0;
    for(int i = n - 1; i >= 0; --i) {
        A[i] += sum;
        if(A[i] % B[i] != 0) {
            sum += (A[i] / B[i] + 1) * B[i] - A[i];
        }
    }
    
    std::cout << sum << std::endl;
}

Measured memory_bytes: 1920
#include<stdio.h>

#define N 10000
#define NIL -1

struct Node {int parent,left,right;};

struct Node T[N];
void Depth(int , int );
int Height(int );
int Sibling(int );
void print(int );
int n,D[N],H[N];
int main(){
  int v,left,right,root=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++)T[i].parent=NIL;

  for(int i;i<n;i++){
    scanf("%d%d%d",&v,&left,&right);
    T[v].left=left;
    T[v].right=right;
    if(left!=NIL)T[left].parent=v;
    if(right!=NIL)T[right].parent=v;}

  for(int i=0;i<n;i++)
    if(T[i].parent==NIL)root=i;

  Depth(root,0);
  Height(root);

  for(int i=0;i<n;i++)print(i);
  return 0;}

void Depth(int u, int d){
  if(u==NIL)return;
  D[u]=d;
  Depth(T[u].left,d+1);
  Depth(T[u].right,d+1);
}

int Height(int u){
  int h1=0,h2=0;
  if(T[u].left!=NIL)
    h1=Height(T[u].left)+1;
  if(T[u].right!=NIL)
  h2=Height(T[u].right)+1;
  return H[u]=(h1>h2?h1:h2);}

int Sibling(int u){
  if(T[u].parent==NIL)return NIL;
  if(T[T[u].parent].left!=u&&T[T[u].parent].left!=NIL)
    return T[T[u].parent].left;
  if(T[T[u].parent].right!=u&&T[T[u].parent].right!=NIL)
    return T[T[u].parent].right;
  return NIL;}

void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",Sibling(u));
  int deg=0;
  if(T[u].left!=NIL)deg++;
  if(T[u].right!=NIL)deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].parent==NIL){
    printf("root\n");
  }else if (T[u].left==NIL&&T[u].right==NIL){
    printf("leaf\n");
  }else{
    printf("internal node\n");
  }}




Measured memory_bytes: 2692
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first) {
        return a.first < b.first;
    } else {
        return a.second < b.second;
    }
}
long long GCD(long long a, long long b) {
    if(b == 0)
        return a;
    else
        return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}
vector<pair<long long, long long>> prime_factorize(long long n) {
    vector<pair<long long, long long>> res;
    for(long long p = 2; p * p <= n; ++p) {
        if(n % p != 0)
            continue;
        int num = 0;
        while(n % p == 0) {
            ++num;
            n /= p;
        }
        res.push_back(make_pair(p, num));
    }
    if(n != 1)
        res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    long long A, B;
    cin >> A >> B;
    vector<pair<long long, long long>> asoin = prime_factorize(A);
    vector<pair<long long, long long>> bsoin = prime_factorize(B);
    vector<pair<long long, long long>> kouyaku;
    for(auto as : asoin) {
        for(auto bs : bsoin) {
            if(as.first == bs.first) {
                kouyaku.push_back(
                    make_pair(as.first, min(as.second, bs.second)));
            }
        }
    }
    kouyaku.push_back(make_pair(1, 1));
    // for(auto k : kouyaku) {
    //     cout << k.first << "," << k.second << endl;
    // }
    cout << kouyaku.size() << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

Int n;

void func(Int cur,int use,Int &counter){
    if(cur>n) return;
    if(use == 0b111) ++counter;
    func(cur*10+7,use|0b100,counter);
    func(cur*10+5,use|0b010,counter);
    func(cur*10+3,use|0b001,counter);
}
int main(){
    cin >> n;
    Int res = 0;
    func(0,0,res);
    cout << res << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}

bool check(char c) {
  if (c == 'A' || c == 'T' || c == 'G' || c == 'C')
    return true;
  else
    return false;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  std::string s;
  cin >> s;
  int result = 0;
  for (int i = 0; i < s.size(); i++) {
    int temp = 0;
    for (int j = i; j < s.size(); j++) {
      if (check(s[j])) {
        temp++;
      } else {
        break;
      }
    }
    result = std::max(result, temp);
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  string s;
  cin >> s;
  vector <ll> v(26, 0);
  rep(i, s.size()) {
    char c = s.at(i);
    ll n = c - 'a';
    v.at(n)++;
  }
  ll flag = 1;
  rep(i, 26) {
    if (!v.at(i)) {
      char c = 'a' + i;
      cout << c << endl;
      flag = 0;
      break;
    }
  }
  if (flag) cout << "None" << endl;
}

Measured memory_bytes: 512
#!/usr/bin/env python3

wd = "SUN MON TUE WED THU FRI SAT".split()
wd = list(reversed(wd))

def solve(S: str):
    idx = wd.index(S)
    return idx+1


def main():
    S = input().strip()
    answer = solve(S)
    print(answer)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9088
import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int K = sc.nextInt();
	int[] p = new int[N];
	for (int i=0;i<N;i++) {
	    p[i] = sc.nextInt();
	}
	Arrays.sort(p);
	int minSum = 0;
	for (int i=0;i<K;i++) {
	    minSum += p[i];
	}
	System.out.print(minSum);
    }
}


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

int main()
{
    string S;
    cin >> S;
    if(S == "MON")
        cout << 6 << endl;
    else if(S == "TUE")
        cout << 5 << endl;
    else if(S == "WED")
        cout << 4 << endl;
    else if(S == "THU")
        cout << 3 << endl;
    else if(S == "FRI")
        cout << 2 << endl;
    else if(S == "SAT")
        cout << 1 << endl;
    else
        cout << 7 << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
def f(v):
    if dp[v] != 0:
        return dp[v]
    res = 0
    for i in graph[v]:
        res = max(res,f(i)+1)
    dp[v] = res
    return res
N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(M):
    x, y = map(int, input().split())
    graph[x-1].append(y-1)
dp = [0]*N
for i in range(N):
    f(i)
print(max(dp))

Measured memory_bytes: 125168
N, M = map(int, input().split())

data = {}
ps = [0] * N
ACs = []

num_ac = 0
num_wa = 0


for i in range(M):
    p, S = input().split()
    p = int(p) - 1

    if ps[p] == 0:
        ps[p] = 1
        data[p] = {'AC':0, 'WA':0}

    if S == 'AC' and data[p]['AC'] == 0:
        ACs.append(p)
        data[p]['AC'] += 1
        num_ac += 1
        num_wa += data[p]['WA']

    if S == 'WA' and data[p]['AC'] == 0:
        data[p][S] += 1

print(num_ac, num_wa)


Measured memory_bytes: 89048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    ll N;
    string a;
    vector<string> A;
    cin >> N;
    REP(i,N){
        cin >> a;
        A.push_back(a);
    }
    
    
    ll D[60][35]={};
    
    REP(i,N){
        ll r=0,t=0,f=0;
        REP(j,A[i].size()){
            if(A[i][j]=='.'){
                r=A[i].size() - j - 1;
            }
        }
        
        ll R=0;
        REP(j,A[i].size()){
            if(A[i][j]=='.')continue;
            R*=10;
            R+=A[i][j]-'0';
        }
        
        
        ll k = R;
        while(k%2==0){
            t++;
            k/=2;
        }
        k = R;
        while(k%5==0){
            f++;
            k/=5;
        }
        
        D[t-r+10][f-r+10]++;
        //cout << A[i] MM t-r MM f-r << endl;
    }
    
    
    ll Ans=0;
    
    REP(i,55){
        REP(j,35){
            REP(k,55){
                REP(l,35){
                    
                    if(min(i+k,j+l)>=20 && !(i==k && j==l)){
                        Ans+=D[i][j]*D[k][l];
                        
                        /*if(D[i][j]*D[k][l]!=0){
                            cout << i-10 MM j-10 MM k-10 MM l-10 <<"  "<< D[i][j] MM D[k][l] << endl;
                        }*/
                    }
                    
                }
            }
        }
    }
    
    Ans/=2;
    
    REP(i,55){
        REP(j,35){
            
            if(min(i,j)>=10){
                Ans += D[i][j]*(D[i][j]-1) /2;
            }
            
        }
    }
    
    cout << Ans << endl;
    
    return 0;
}



Measured memory_bytes: 11592
from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
# from itertools import accumulate
# from collections import deque
import random

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

n = int(input())
p = np.zeros(n, dtype = int)
for i in range(n):
    p[i] = int(input())

print(p.sum() - int(p.max()/2) )


Measured memory_bytes: 13540
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define llong long long
#define ldouble long double
#define uint unsigned int
#define ullong unsigned long long
#define udouble unsigned double
#define uldouble unsigned long double
#define modinc(x) {if(x>=P) x-=P;}
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>
#define piiii pair<pair<int,int>,pair<int,int> >
#define pli pair<llong,int>
#define pll pair<llong,llong>
#define Memset(a,x) {memset(a,x,sizeof(a));}
#define U ((1<<n)-1)
using namespace std;

const int N = 15;
const int P = 1e9+7;
int g[N+2][(1<<N)+2];
int cnt[N+2][(1<<N)+2];
llong dp[(1<<N)+2];
int n,m;

int main()
{
	scanf("%d%d",&n,&m);
	llong tot = 1ll;
	for(int i=1; i<=m; i++) tot = (tot<<1)%P;
	for(int i=1; i<=m; i++)
	{
		int x,y; scanf("%d%d",&x,&y);
		x--; y--; cnt[x][1<<y] = 1;
	}
	for(int i=0; i<n; i++)
	{
		cnt[i][0] = 0;
		for(int j=1; j<=U; j++)
		{
			int lb = j&(-j);
			cnt[i][j] = cnt[i][j^lb]+cnt[i][lb];
//			printf("cnt%d %d %d\n",i,j,cnt[i][j]);
		}
	}
	dp[0] = 1ll; dp[3] = 1ll;
	for(int i=4; i<=U; i++)
	{
		if((i&3)==3 || (i&3)==0)
		{
			dp[i] = 1ll;
			for(int j=i; j>0; j=(j-1)&i)
			{
				if(j==i) continue;
				if((j&3)==3 || (j&3)==0)
				{
					llong cur = dp[j];
					for(int k=0; k<n; k++)
					{
						if(j&(1<<k))
						{
							cur *= (1ll<<cnt[k][i^j])-1ll; cur %= P;
						}
						else if(i&(1<<k))
						{
							cur *= (1ll<<cnt[k][j]); cur %= P;
						}
					}
					dp[i] += cur; modinc(dp[i]);
				}
			}
//			printf("%d %lld\n",i,dp[i]);
		}
	} printf("%lld\n",(tot-dp[U]+P)%P);
	return 0;
}

Measured memory_bytes: 4224
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    ll N,T;
    cin >> N >> T;
    vector<ll> A(N);
    REP(i,0,N){
        cin >> A[i];
    }

    ll mn=INF, ans=0, submx=0;
    REP(i,0,N){
        mn=min(A[i],mn);
        if(A[i]-mn > submx){
            submx=A[i]-mn;
            ans=1;
        }else if(A[i]-mn==submx){
            ans++;
        }
    }
    P(ans);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
#define num 1000000007
//#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define up(a,b) (((a)%(b)==0)?((a)/(b)):((a)/(b))+1)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) (a>b)?(a>c)?a:c:(b>c)?b:c
#define min3(a,b,c) (a<b)?(a<c)?a:c:(b<c)?b:c
#define avg(a,b) ((a)+(b))/2
#define push push_back
#define pop pop_back
#define mp make_pair
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;

ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b, a%b);
}
bool prime[3001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=3000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=3000; i += p) 
                prime[i] = false; 
        } 
    } 
}
ll powe[20];
void power()
{
	powe[0]=1;
	REP(i,1,20)
	{
		powe[i]=(powe[i-1]*10)%num;
        if(powe[i]<0)
        powe[i]+=num;
	}
}
struct vertex
{
	vll adj;
};
void dfs(ll i,vertex V[], bool vis[], ll dist[])
{
	vis[i]=true;
	//cout<<i<<" ke liye\n";
	for(auto x : V[i].adj)
	{
		if(!vis[x])
		{
			dfs(x,V,vis,dist);
		}
		dist[i]=max(dist[i],1+dist[x]);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,w;
	cin>>n>>w;
	pll p[105];
	ll dp[n+1][100001];
	
	REP(i,0,n)
	{
		cin>>p[i].f>>p[i].s;
	}
	REP(i,0,n+1)
	{
		REP(j,0,100001)
		{
			if(j==0)
			{
				dp[i][j]=0;
			}
			else if(i==0)
			{
				dp[i][j]=num;
			}
			else if(p[i-1].s<=j)
			{
				dp[i][j]=min(dp[i-1][j-p[i-1].s]+p[i-1].f,dp[i-1][j]);
			}
			else
			{
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	ll ans=0;
	REP(i,0,100001)
	{
		if(dp[n][i]<=w)
		{
			assmax(ans,i);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    string arr[102];
    int n,m;
    while(scanf("%d%d",&n,&m) != EOF ) {
        for(int i = 0;i < n;i++) {
            cin>>arr[i];
        }
        for(int i = 0;i < n;i++) {
            for(int j  = 0;j < n;j++) {
                if(arr[i]<arr[j]) {
                    string str = arr[i];
                    arr[i] = arr[j];
                    arr[j] = str;
                }
            }
        }
        for(int i = 0;i < n;i++) {
            cout<<arr[i];
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.algorithm, std.math, std.array;

void main() {
  int n;
  readf("%d\n", &n);
  auto a = readln.chomp.split.map!(to!int);
  long[int] counts;
  foreach(ai;a) {
    long c = counts.get(ai, 0);
    counts[ai] = c+1;
  }
  long sum = 0;
  foreach(v;counts.byValue) sum += v*(v-1)/2;
  for(int k=0; k<n; k++) {
    long x = sum - counts[a[k]] + 1;
    writeln(x);
  }
}



Measured memory_bytes: 26640
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

int sign[8][3]{
	{1,1,1},
	{1,1,-1},
	{1,-1,1},
	{1,-1,-1},
	{ -1,1,1 },
	{ -1,1,-1 },
	{ -1,-1,1 },
	{ -1,-1,-1 },

};

vector<int> vals[8];

signed main() {
	int N, M;
	cin >> N >> M;

	for (int i = 0; i < N; i++) {
		int x, y, z;
		cin >> x >> y >> z;
		for (int j = 0; j < 8; j++) {
			int value = sign[j][0]*x+ sign[j][1] * y+ sign[j][2] * z;
			vals[j].push_back(value);
		}
	}

	int ans = 0;

	for (int i = 0; i < 8; i++) {
		int anscand = 0;
		sort(vals[i].begin(), vals[i].end());
		reverse(vals[i].begin(), vals[i].end());
		
		for (int j = 0; j < M; j++) {
			anscand += vals[i][j];
		}
		if (ans < anscand) ans = anscand;
	}

	cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 384
s = input()
c = 0
last = ''
cache = ''
for x in s:
    if last != cache+x:
        c += 1
        last = cache+x
        cache = ''
    elif last != x:
        c += 1
        last = x
    elif last != cache+x:
        c += 1
        last = cache+x
        cache = ''
    else:
        cache += x

print(c)

Measured memory_bytes: 3500
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> N;
	set<string>s;
	for (int i = 0; i < N; i++) {
		string t;
		cin >> t;
		s.insert(t);
	}
	if (s.size() == 3) {
		cout << "Three\n";
	}
	else {
		cout << "Four\n";
	}
	return 0;
}

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

int main() {
  int a,b,c;
  cin >> a >> b;
 c=(a+b)/2;
  if((a+b)%2==0){
  cout << c <<endl;
  }
  else if ((a+b)%2==1){
     cout << c+1 <<endl;
   }
  
}

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

int main() {
  char s[4];
  int a, b, c, d;
  scanf("%c", &s[0]); scanf("%c", &s[1]); scanf("%c", &s[2]); scanf("%c", &s[3]); 
  a = s[0] - '0'; b = s[1] - '0'; c = s[2] - '0'; d = s[3] - '0'; 
  if (a-b-c-d == 7)  printf("%d-%d-%d-%d=7\n", a, b, c, d);
  else if (a-b-c+d == 7)  printf("%d-%d-%d+%d=7\n", a, b, c, d);
  else if (a-b+c-d == 7)  printf("%d-%d+%d-%d=7\n", a, b, c, d);
  else if (a-b+c+d == 7)  printf("%d-%d+%d+%d=7\n", a, b, c, d);
  else if (a+b-c-d == 7)  printf("%d+%d-%d-%d=7\n", a, b, c, d);
  else if (a+b-c+d == 7)  printf("%d+%d-%d+%d=7\n", a, b, c, d);
  else if (a+b+c-d == 7)  printf("%d+%d+%d-%d=7\n", a, b, c, d);
  else if (a+b+c+d == 7)  printf("%d+%d+%d+%d=7\n", a, b, c, d);
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}

//線分
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

//外積
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}

//内積
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

bool orthogonal(const L &l1, const L &l2){
  return (dot(l1[0]-l1[1], l2[0]-l2[1]) <= EPS && dot(l1[0]-l1[1], l2[0]-l2[1]) >= -EPS);
}
 
bool parallel(const L &l1, const L &l2){
  return (cross(l1[0]-l1[1], l2[0]-l2[1]) <= EPS && cross(l1[0]-l1[1], l2[0]-l2[1]) >= -EPS);
}


int main() {
  int Q; cin >>Q;
  REP(q, Q){
    int x0, y0, x1, y1, x2, y2, x3, y3;
    scanf("%d %d %d %d %d %d %d %d", &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3);
    L l1 = L(P(x0, y0), P(x1, y1)), l2 = L(P(x2, y2), P(x3, y3));
    if(orthogonal(l1, l2)) cout <<1 <<endl;
    else if(parallel(l1, l2)) cout <<2 <<endl;
    else cout <<0 <<endl;
  }
  return 0;
}

Measured memory_bytes: 1256
import heapq as hq
N,M = map(int,input().split())
A = [-int(i) for i in input().split()]
hq.heapify(A)
for i in range(M):
    x = hq.heappop(A)
    x = -(-x>>1)
    hq.heappush(A,x)
print(sum([-i for i in A]))

Measured memory_bytes: 14184
//In The Name Of God
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define L(x) (2*(x))
#define R(x) ((2*(x))+1)
#define pii pair<int, int>
#define pb push_back
using namespace std;
const int N = 4e2 + 5, Mod = 1e9 + 7, P = 727, Lg = 22, TOF = 1900;


int Dp[Lg][(1 << Lg)], A[Lg][Lg];
vector< int > V[Lg];
int main(){
      ios_base::sync_with_stdio(0); cin.tie(0);
      int n; cin >> n;
      for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                  cin >> A[i][j];
      for(int j = 1; j < (1 << n); j++)
            V[__builtin_popcount(j)].pb(j);
      for(int i = 0; i < n; i++){
            for(int j = 0; j < (int)V[i + 1].size(); j++){
                  int mask = V[i + 1][j], cur =  V[i + 1][j];
                  while(cur){
                        int ct = __builtin_ctz(cur);
                        cur ^= (1 << ct);
                        if(A[i][ct]){
                              if(i)
                                    Dp[i][mask] = (Dp[i][mask] + Dp[i - 1][mask ^ (1 << ct)]) % Mod;
                              else
                                    Dp[i][mask] = 1;
                        }
                  }
            }
      }
      cout << Dp[n - 1][(1 << n) - 1];
      return 0;
}



Measured memory_bytes: 187836
#include <iostream>
using namespace std;
typedef long long int ll;
int main() {
	int N, K;
	cin >> N >> K;
	ll ans = 0;
	for(int i = 1; i <= N; i++){
		int M = N % i;
		ans += (ll)(N - M) / i * (ll)max(0, i - K);
		ans += max(0, M - K + 1);
		//cout << ans << endl;
	}
	if(K == 0) cout << (ll)N * (ll)N << endl;
	else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll inf=1000000007;
const ll maxinput=100005;
const ll mod=998244353;
#define mp make_pair
int main()
{
    int n,k;cin>>n>>k;
    int h[n];for(int i=0;i<n;i++)cin>>h[i];

    int dp[n]; //dp[i] is the minimum cost of reaching stone i
    dp[0]=0;dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=inf;
        for(int j=1;j<=k;j++)
        {
            if(i-j<0)
                break;
            dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
        }
    }
    cout<<dp[n-1]<<"\n";
}

Measured memory_bytes: 1024
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    h = H % 2 
    w = W % 2
    for i in range(H//2):
        if w == 0:
            print("#."*(W//2)) 
        else:
            print("#."*(W//2)+"#") 
        if w == 0:
            print(".#"*(W//2)) 
        else:
            print(".#"*(W//2)+".")
    if h == 1:
        if w == 0:
            print("#."*(W//2)) 
        else:
            print("#."*(W//2)+"#") 
    print()


Measured memory_bytes: 5612
#include <bits/stdc++.h>	
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

// random_device rd; mt19937 g(rd());    
                                        	
using namespace std;
using namespace __gnu_pbds;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}

template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
const int mod = (int)1e9 + 7;

int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();
	int a, b;
	cin >> a >> b;
	for(int i = 1; i <= 1000; i++)
		if(i * 8 / 100 == a && i * 10 / 100 == b) cout << i, exit(0);
	cout << -1 << endl;	
}      

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

int main(){
    ll N,Q;
    cin >> N >> Q;
    vector<ll> c(N),l(Q),r(Q), pi(N,-1);
    vector<vector<ll>> ps(N);
    vector<vector<Pll>> qs(N);
    rep(i,N){
        cin >> c[i];
        c[i]--;
    }
    rep(i,Q){
        cin >> l[i] >> r[i];
        l[i]--;r[i]--;
        qs[l[i]].push_back(Pll(r[i],i));
    }
    rep(i,N){
        ll s = pi[c[i]];
        if(s != -1) ps[s].push_back(i);
        pi[c[i]] = i;
    }
    BIT<ll> d(N);
    vector<ll> ans(Q);
    for(ll i = N-1;i>=0;i--){
        for(auto&s:ps[i]) d.add(s,1);
        for(auto&p:qs[i]){
            ans[p.se] = p.fi - i + 1 - d.sum(p.fi);
        }  
    }
    rep(i,Q){
        cout << ans[i] << endl;
    }
}

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

int define(int data){
   int ans=0;
  for (int i=0;i<5;i++){
    ans += data % 10;
    data /= 10;
  }
  return ans;
}

int main() {
  int N;//データ
  int A,B;//上限:A,下限:B
  int ans = 0; //答え
  
  //入力部
  cin >>N>>A>>B;
  
  //計算部:0～9999までの足し算
  for (int i=1;i <= N ;i++){
    int norm = 0;
    norm = define(i);
    if(A <= norm && B >= norm)
      ans += i;
  }
  //出力部
  cout << ans<< endl;
}

    
  
  
  
    
  
  


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

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

    int a[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];
    
    int counter = 0;
    while(true){
        bool flag = false;
        for(int i = 0; i < n; i++){
            if(a[i] % 2 != 0)
                flag = true;
        }
        if(flag)
            break;

        for(int i = 0; i < n; i++)
            a[i] /= 2;

        ++counter;
    }

    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string n;
  cin >>n;
  int y=0;
  for(int i=0;i<4;i++){
   if(n[i]=='+') y++;
   if(n[i]=='-') y--;
  
  }
 
  
    cout <<y<< endl;
   
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cstring>
#include <ctime>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <unordered_map>
typedef long long INT;
#define mp make_pair
#define pb push_back
#define SZ(s) ((s).size())
using namespace std;
typedef pair<int,int> pii;

vector<pii> nei[100005];
unordered_map<int,int> dist[100005];
unordered_map<int,vector<int> > nei2[100005];
int n,m;
vector<int> hvcol[100005];

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		nei[a].pb(mp(b,c));
		nei[b].pb(mp(a,c));
		nei2[a][c].pb(b);
		nei2[b][c].pb(a);
		hvcol[a].pb(c);
		hvcol[b].pb(c);
	}
	priority_queue<pair<int,pii> > pq;
	pq.push(mp(0,mp(1,0)));
	dist[1][0]=0;
	while(SZ(pq)){
		pair<int,pii> P=pq.top();
		pq.pop();
		int dis=-P.first,whr=P.second.first,col=P.second.second;
		if(dist[whr][col]!=dis){
			continue;
		}
		if(!dist[whr].count(0)||dist[whr][0]>dis){
			pq.push(mp(-dis,mp(whr,0)));
			dist[whr][0]=dis;
		}
		if(col==0){
			for(int i=0;i<SZ(hvcol[whr]);i++){
				if(!dist[whr].count(hvcol[whr][i])||dist[whr][hvcol[whr][i]]>dis+1){
					pq.push(mp(-dis-1,mp(whr,hvcol[whr][i])));
					dist[whr][hvcol[whr][i]]=dis+1;
				}
			}
		}else{
			for(int i=0;i<SZ(nei2[whr][col]);i++){
				int to=nei2[whr][col][i];
				if((!dist[to].count(col)||dist[to][col]>dis)){
					pq.push(mp(-dis,mp(to,col)));
					dist[to][col]=dis;
				}
			}
		}
	}
	int minx=1234567890;
	for(int i=0;i<=1000000;i++){
		if(dist[n].count(i)){
			minx=min(minx,dist[n][i]);
		}
	}
	printf("%d\n",minx!=1234567890?minx:-1);
	return 0;
}

Measured memory_bytes: 86836