akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const double EPS = 1e-8;
const int MOD = 1000000007;
const int INF = 1<<29;
bool bipartite_matching_dfs(
	int v, const vector< vector<int> > &conn,
	vector<bool> &used, vector<int> &match)
{
	used[v] = true;
	for(int i = 0; i < conn[v].size(); ++i){
		int u = conn[v][i], w = match[u];
		if(w < 0 || (!used[w] && bipartite_matching_dfs(w, conn, used, match))){
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}
//O(E√V)
int bipartite_matching(const vector< vector<int> > &conn){
	int res = 0;
	vector<int> match(conn.size(), -1);
	vector<bool> used(conn.size(), false);
	for(int v = 0; v < conn.size(); ++v){
		if(match[v] < 0){
			fill(used.begin(), used.end(), false);
			if(bipartite_matching_dfs(v, conn, used, match)){ ++res; }
		}
	}
	return res;
}

int n, m, l;

int g[101][101];

int main(){
	ios::sync_with_stdio(false);
	while(cin >> n >> m >> l, n){
		REP(i, n)REP(j, n) g[i][j] = i==j ? 0 : INF;
		REP(i, m){
			int u, v, d;
			cin >> u >> v >> d;
			g[u][v] = g[v][u] = d;
		}
		REP(k, n)REP(i, n)REP(j, n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
		vector<pii> q(l);
		REP(i, l) cin >> q[i].first >> q[i].second;
		vector<vi> gg(l*2);
		REP(i, l)REP(j, l)if(i!=j){
			const int u = q[j].first;
			const int v = q[i].first;
			const int t = q[i].second - q[j].second;
			if(g[u][v] <= t){
				gg[j].emplace_back(l+i);
				gg[l+i].emplace_back(j);
			}
		}
		cout << l - bipartite_matching(gg) << endl;
	}
	return 0;
}

Measured memory_bytes: 6544
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


signed main(){
  int n,k;cin>>n>>k;int a[210000];fill(a,a+210000,0);
  rep(i,n){
    int aa;cin>>aa;a[aa]++;
  }
  sort(a,a+210000,greater<int>());
  int ans = 0;
  repd(i,k,210000){
    ans += a[i];
    if(a[i] == 0)break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<time.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define lson l,mid,pos<<1
#define rson mid+1,r,pos<<1|1
using namespace std;

const int maxn=100000+10;
//const int maxm=2000+5;
//const ll mod=1e9 + 7;
//const int inf=0x3f3f3f3f;
//const double PI=acos(-1);
//const double eps=1e-8;
//int dir[4][2]={0,1,1,0,0,-1,-1,0};
//const ll INF = 0x3f3f3f3f3f3f3f3fLL;
//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;}
//ll inv(ll b){if(b==1) return 1; return (mod-mod/b)*inv(mod%b)%mod;}
//ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}


char s[maxn];
char str[maxn];

int main()
{
    scanf("%s", s);
    int len = strlen(s);
    int cnt = 0;
    for(int i = 0 ; i < len; i++)
    {
       if(s[i] != 'x')
        str[cnt++] = s[i];
    }
    if(cnt == 0)
    {
        cout<<0<<endl;
        return 0;
    }
    for(int i = 0 ; i < cnt/2; i++)
    {
        if(str[i] != str[cnt-i-1])
        {
            cout<<"-1"<<endl;
            return 0;
        }
    }
    int ans1 = 0, ans2 = len-1;
    int sum = 0;
    while(ans1 < ans2)
    {
        if(s[ans1] != s[ans2])
        {
            sum++;
            if(s[ans1] == 'x')
            {
                ans1++;
            }
            else
            {
                ans2--;
            }
        }
        else
        {
            ans1++;
            ans2--;
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 384
import math
from queue import PriorityQueue


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_sum = sum(A)
B_sum = sum(B)
diff = B_sum - A_sum
if diff < 0:
    print("No")
    exit()

cnt = 0
for a, b in zip(A, B):
    if a < b:
        cnt += math.ceil((b - a) / 2)

if cnt > diff:
    print("No")
else:
    print("Yes")


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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()

const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const double EPS = 1e-10;

using ll = long long;
using P = pair<int,int>;
template<class T = int> using V = vector<T>;

template<class T> bool inline chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool inline chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T = int> T inline input() { T x; cin >> x; return (x); }
template<class T> void inline print(T x) { cout << x << '\n'; }
#define debug(x) cerr << #x << ": " << x << endl;

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

  string S;
  cin >> S;

  size_t l = S.size();

  EACH(i,1,l/2) {
    if (S.substr(0,l/2-i) == S.substr(l/2-i,l/2-i)) {
      cout << l - 2*i << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3592
n, k = map(int, input().split())
s = input()

if k == 1:
    print(s[k-1].lower()+s[k:])
elif k == n:
    print(s[:k-1]+s[k-1].lower())
else :
    print(s[:k-1]+s[k-1].lower()+s[k:])

Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Threading;

namespace ConsoleApp19
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] array = line.Split(' ');

            int a = int.Parse(array[0]);
            int b = int.Parse(array[1]);
            int up = 0;
            int down = 0;

            if (a < b)
            {
                up = b;
                down = a;
            }
            else
            {
                up = a;
                down = b;
            }

            for(int i=0;i < up; i++)
            {
                Console.Write(down);
            }
        }
    }
}



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

using namespace std;

typedef long long ll;

struct Stu{
	pair<int, int> coor;
	int dis;
	int go;
};

int main(){
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	Stu s[n];
	vector<pair<int, int>>	check;
	for(int i=0; i<n; i++){
		cin >> s[i].coor.first >> s[i].coor.second;
		s[i].dis = 1e9;
	}
	for(int i=0, x, y; i<m; i++){
		cin >> x >> y;
		check.push_back({x, y});
	}
	for(int i=0; i<n; i++)
		for(int x = 0 ; x<m; x++){
			if((abs(check[x].first - s[i].coor.first) + abs(check[x].second - s[i].coor.second)) < s[i].dis){
				s[i].dis = abs(check[x].first - s[i].coor.first) + abs(check[x].second - s[i].coor.second);
				s[i].go = x+1;
			}
		}
	for(int i=0; i<n; i++)
		cout << s[i].go << endl;
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N, K int
	var x, y int
	var sum int

	fmt.Scan(&N)
	fmt.Scan(&K)
	fmt.Scan(&x)
	fmt.Scan(&y)

	for i := 1; i <= N; i++ {
		if i > K {
			sum += y
		} else {
			sum += x
		}
	}

	fmt.Println(sum)
}


Measured memory_bytes: 512
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

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

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

    int a,b,c;
    cin >> a >> b >> c;
    if(a + b + c >= 22)
		cout << "bust";
	else
	{
		cout << "win";
	}
	


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

// const LL INF=1e18;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int n=s.size();
    VI L(n+1),R(n+1);
    LL sum=0;
    L[0]=0;
    REP(i,n) {
        if ( s[i]=='<' ) L[i+1]=L[i]+1;
        // else L[i+1]=L[i]-1;
    }
    R[n]=0;
    for ( int i=n-1; i>=0; i-- ) {
        // if ( s[i]=='<' ) R[i]=R[i+1]-1;
        if ( s[i]=='>' ) R[i]=R[i+1]+1;
    }
    REP(i,n+1) {
        // cout << L[i] << ' ' << R[i] << '\n';
        sum+=max(L[i],R[i]);
    }
    cout << sum << "\n";
    return 0;
}


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

int main(){

  int N;
  double x;
  cin >> N;
  vector<int> vec(N);
  
  x = 0;
  
  for(int i = 0; i < N; i++){
  	cin >> vec.at(i);
    x += 1.0 /vec.at(i);
  }
  
  cout << 1 / x << endl;
  
  
}

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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define mp make_pair
#define r0 return 0

/* const */
const int inf = 1e9 + 7;
const int dxl[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dyl[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dxs[4] = {1, 0, -1, 0};
const int dys[4] = {0, 1, 0, -1};

/* main */
signed main(void)
{
    int n, x;
    cin >> n >> x;
    int cnt = 1;
    int a = 0;
    vector<int> v(n);
    rep(i, n)
    {
        cin >> v[i];
        a += v[i];
        if (a <= x)
        {
            cnt++;
        }
        else
        {
            cout << cnt << endl;
            return 0;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
 
using namespace std;
 
const int MAX_N = int(1e6) + 10;
const long long int MOD=1e9+7;
const long long int INF=1e18;
 
 
typedef long long int ll;
typedef unsigned long long int llu;


ll max(ll a,ll b){
	return a>b?a:b;
}
#define N 1000000000000000000
int main()
{
	ll n; cin>>n;
  ll a[n];
  for(int i=0;i<n;++i)cin>>a[i];
  ll ans=1;
  sort(a,a+n);
  int flag=0;
  for(int i=0;i<n;++i){
    if(a[i]==0){
      ans=0;
      break;
    }
    ll zz=N/ans;
      if(a[i]>zz){
        flag=1;
      }
      else ans=ans*a[i];
    
  }
  if(flag){
    cout<<-1;
    return 0;
  }
  cout<<ans;
}

Measured memory_bytes: 4404
/*author : Yashvardhan
Wednesday, January 30, 2019
2:10 PM
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define endl '\n'

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#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

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;
const int N = 100005;

int n,m;
vi g[N];
int visited[N] = {0};
int dp[N+1];

int pow(int a, int b, int m)
{
	int ans = 1;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int solve(int source){
	if(dp[source] != -1) return dp[source];
	vi neigh = g[source];
	if(neigh.size() == 0) return dp[source] = 0;
	int maxi = -1;
	for(int i = 0; i < neigh.size() ; i++){
		int curri = neigh[i];
		visited[curri] = -1;
		int val = solve(curri);
		maxi = max(maxi,val);
	}
	return dp[source] = 1 + maxi;
}

signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	cin>>n>>m;

	for(int i = 0; i < m ; i++){
		int x,y;
		cin>>x>>y;
		g[x].pb(y);
	}
	
	for(int i = 0; i < n + 1 ; i++){
		dp[i] = -1;
	}
	
	for(int i = 1; i <= n ; i++){
		if(!visited[i]){
			visited[i] = 1;
			solve(i);
		}
	}
	int maxi = -1;
	for(int i = 1; i <= n  ; i++){
		maxi = max(maxi,dp[i]);
	}
	cout<<maxi<<endl;

	t2 = clock();
	cerr<<endl<<t2-t1<<endl;
	
	return 0;
}



Measured memory_bytes: 12032
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
int main()
{
	int a[100010];
	int b[100010];
	int n;
	cin>>n;
	memset(b,0,sizeof(b));
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		b[a[i]]++;
	}
	int max=0;
	for(int i=0;i<100000;i++)
	{
		if(b[i]+b[i+1]+b[i+2]>max)
		max=b[i]+b[i+1]+b[i+2];
	}	
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000000000000003 //1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  string S;
  cin>>S;

  bool aru[26]={};
  rep(i,S.length()){
    char c=S[i];
    aru[c-'a']=true;
  }

  rep(i,26){
    if(aru[i]==false){
      cout<< (char)('a'+i) <<"\n";
      return;
    }
  }

  cout<< "None"<<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 512
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
typedef pair<ll  ,ll > pll;

const ll maxn =2e6;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

int n;
set<string>st;
map <string , int > mp;
int mx = 0;

int main(){
    migmig
    cin >> n;
    while(n--){
        string inp;
        cin >> inp;
        mp[inp] ++;
        mx = max(mx , mp[inp]);
        st.insert(inp);
    }
    for (auto it = st.begin() ; it != st.end() ; it ++){
        if(mp[*it] ==mx) cout << *it << endl;
    }


    return(0);
}


//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


Measured memory_bytes: 33280
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

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

    if(X == 1){
        cout << 1 << endl;
    }else{
        double max = 0;
        for(int i = 2; i <= int(sqrt(X)); i++){
            for(int j = 2; j <= 10; j++){
                double result = pow(i, j);
                if(result > max & result <= X){
                    max = result;
                }else if(result > X){
                    break;
                }
            }
        }
        cout << max << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    int N, D;
    cin >> N >> D;

    vector<vector<int>> X(N, vector<int>(D));
    REP(i, N){
        REP(j, D){
            cin >> X[i][j];
        }
    }

    double Dist;
    int ans = 0;
    REP(i, N-1){
        FOR(j, i+1, N-1){
            double D1 = 0;
            REP(k, D){
                D1 += pow((double)X[i][k] - X[j][k], 2);
            }
            Dist = sqrt(D1);
            if (floor(Dist) == Dist) ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
using namespace std;

int gcd(int a,int b){
    if(a==0)return b;
    if(b==0)return a;

    int M=max(a,b);
    int m=min(a,b);
    return gcd(m,M%m);
}

int main(){
    int N,A[100010],ans=0;cin>>N;
    for(int i=0;i<N;++i){
        cin>>A[i];
        ans=gcd(ans,A[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

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

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

    ll N;
    cin >> N;
    vec P(N), Q(N);
    Rep (i, N) {
        cin >> P[i];
        P[i]--;
    }
    Rep (i, N) {
        cin >> Q[i];
        Q[i]--;
    }

    vec array;
    Rep (i, N) array.push_back(i);

    ll tmp = 0, a = -1, b = -1;
    do {
        bool fa = true, fb = true;
        Rep (i, N) {
            if (array[i] != P[i]) fa = false;
            if (array[i] != Q[i]) fb = false;
        }
        if (fa) a = tmp;
        if (fb) b = tmp;
        tmp++;
    } while (next_permutation(array.begin(), array.end()));


    cout << abs(a-b) << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val h = readLine()!!.split(" ").map(String::toInt).toMutableList()
    var i = 0
    var left = 0
    var count = 0
    var countFlag = false
    while (h.sum() > 0) {
        if (h[i] > 0) {
            h[i]--
            i++
            if (!countFlag) {
                count++
                countFlag = true
            }

        } else if (h[i] == 0 && countFlag) {
            i = left
            countFlag = false

        } else {
            left = i
            i++
        }

        if (i == n) {
            i = left
            countFlag = false
        }
    }
    println(count)
}



Measured memory_bytes: 37692
#include <stdio.h>

int main(){
	int n, count, ans = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		count = 0;
		if (i % 2 == 0) {
			continue;
		}
		for (int j = 1; j <= i; ++j) {
			count += (i % j == 0 ? 1 : 0);
		}
		ans += (count == 8 ? 1 : 0);

	}

	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
main :: IO ()
main = do
    s <- getLine
    let n = length s
        a = take n $ cycle "01"
        b = take n $ cycle "10"
     in print $ n - max (cntEq s a) (cntEq s b)
  where
    cntEq :: String -> String -> Int
    cntEq x y = length . filter (uncurry (==)) $ zip x y


Measured memory_bytes: 7164
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define llong long long
using namespace std;

signed main(){
	set<int> s;
	for(int i = 0; i < 4; i++){
		int t; cin >> t; s.insert(t);
	}
	if(s.find(1) != s.end() && s.find(9) != s.end() && s.find(7) != s.end() && s.find(4) != s.end()){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}


	return 0;
}



Measured memory_bytes: 256
n = int(input())
if n%1.08==0:
  print(int(n//1.08))
else:
  x_init=n//1.08 + 1
  x_n = int(1.08*x_init)
  if x_n ==n:
    print(int(x_init))
  else:
    print(':(')

Measured memory_bytes: 9104
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define mod 1000000007


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }
    
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }
    
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


int main() {
    int N, K, L; cin >> N >> K >> L;
    UnionFind road(N);
    UnionFind train(N);


    for(int i=0; i<K; i++){
        int p, q; cin >> p >> q;
        p--; q--;
        road.unite(p, q);
    }
    
    for(int i=0; i<L; i++){
        int r, l; cin >> r >> l;
        r--; l--;
        train.unite(r, l);
    }
    
    map<PII, int> M;
    for(int i=0; i<N; i++)
        M[PII(road.root(i), train.root(i))]++;
    
    for(int i=0; i<N; i++){
        if(i!=N-1) cout << M[PII(road.root(i), train.root(i))] << " ";
        else cout << M[PII(road.root(i), train.root(i))];
    }
    
    cout << endl;
    return 0;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans = LINF;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            chmin(ans, i + n / i - 2LL);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// SeeAlso: https://atcoder.jp/contests/abc079/tasks/abc079_c

#include <bits/stdc++.h>

#define MAX 4
using namespace std;

int main() {
    string S;
    int num[MAX];
    
    cin >> S;

    for (int i = 0; i < MAX; i++) {
        num[i] = S[i] - '0';
    }

    string ans;

    for (int bits; bits < 1 << 3; bits++) {
        int sum = num[0];
        for (int i = 0; i < 3; i++) {
            sum += ((bits >> i) & 1) ? num[i + 1] : -num[i + 1];
        }
        if (sum == 7) {
            ans.push_back(S[0]);
            for (int i = 0; i < 3; i++) {
                char operand = ((bits >> i) & 1) ? '+' : '-';
                ans.push_back(operand);
                ans.push_back(S[i + 1]);
            }
            ans += "=7";
            cout << ans << "\n";
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int divide2(int a){
  int cnt = 0;
  while(a%2==0){
    cnt++;
    a = a/2;
  }
  return cnt;
}

int main()
{
  ll N;
  cin >> N;

  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  int cnt = 0;
  REP(i,N){
    cnt+=divide2(A.at(i));
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define repeat(i,a,b) for(int i=(a),i##__end=(b);i<i##__end;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,i##__end=(a);i>=i##__end;i--)
#define mst(a,x) memset((a),(x),sizeof(a))
#define pii pair<int,int>
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n,m;
	cin>>n>>m;
	n-=2*m;
	cout<<max(n,0ll)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
#define INF (1LL << 28)
using namespace std;

string S;
int p[26], h[200000], cnt[26][200000];

int main(void) {
  cin >> S;

  REP(i, 0, 26) p[i] = pow(2, i);

  REP(i, 0, 26) REP(j, 0, S.length()) cnt[i][j] = 0;
  REP(i, 0, S.length()) cnt[S[i] - 'a'][i] = 1;
  REP(i, 0, 26) REP(j, 1, S.length()) cnt[i][j] += cnt[i][j - 1];

  REP(i, 0, S.length()) {
    h[i] = 0;
    REP(k, 0, 26) if(cnt[k][i] & 1) h[i] ^= p[k];
  }

  vector<int> dp(1 << 26, INF);
  dp[0] = 0;
  vector<int> ans(S.length(), INF);

  REP(i, 0, S.length()) {
    ans[i] = min(ans[i], dp[h[i]] + 1);
    REP(k, 0, 26) ans[i] = min(ans[i], dp[h[i] ^ p[k]] + 1);
    dp[h[i]] = min(dp[h[i]], ans[i]);
  }
  cout << ans[(int) S.length() - 1] << endl;
}


Measured memory_bytes: 284548
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
using Graph = vector<vector<int>>;
using Graph_Wei = vector<vector<pair<int,int>>>;
using ll = long long;
const long long INF = 1LL<<60; // 仮想的な無限大の値
vector<bool> seen;

Graph G;

const int MAX_N = 10000;
int main() {
    
    int n = 0;
    cin >> n;
    int a[MAX_N];
    
    //2の約数の個数を数える
    int sum =0;
    for(int i=0;i < n;i++){
        cin >> a[i];
        while(a[i] % 2 == 0){
            sum++;
            a[i] /= 2;
        }
    }
    
    cout << sum << endl;


    return 0;

}

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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int64_t a,b,q;
  cin >> a >> b >> q;
  vector<int64_t> s(a),t(b);
  rep(i,a){
    cin >> s[i];
  }
  rep(i,b){
    cin >> t[i];
  }
  rep(i,q){
    int64_t x;
    cin >> x;
    auto sritr = lower_bound(s.begin(),s.end(),x);
    auto slitr = sritr;
    int64_t sl,sr;
    if(sritr == s.end()){
      sr = 100000000000000;
    }else{
      sr = *sritr;
    }
    if(slitr == s.begin()){
      sl = -100000000000000;
    }else{
      --slitr;
      sl = *slitr;
    }
    //printf("%ld,%ld\n",sl,sr);
    auto tritr = lower_bound(t.begin(),t.end(),x);
    auto tlitr = tritr;
    int64_t tl,tr;
    if(tritr == t.end()){
      tr = 100000000000000;
    }else{
      tr = *tritr;
    }
    if(tlitr == t.begin()){
      tl = -100000000000000;
    }else{
      --tlitr;
      tl = *tlitr;
    }
    //printf("%ld,%ld\n",tl,tr);
    vector<int64_t> dist(8);
    dist[0] = abs(sl - x) + abs(sl - tl);
    dist[1] = abs(tl - x) + abs(tl - sl);
    dist[2] = abs(sr - x) + abs(sr - tr);
    dist[3] = abs(tr - x) + abs(tr - sr);
    dist[4] = abs(sl - x) + abs(sl - tr);
    dist[5] = abs(tl - x) + abs(tl - sr);
    dist[6] = abs(sr - x) + abs(sr - tl);
    dist[7] = abs(tr - x) + abs(tr - sl); 
    sort(dist.begin(),dist.end());
    cout << dist[0] << endl;
  }
  
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = i / (n / 2);
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(int x){
        return Size[root(x)];
    }
};


int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    UnionFind uni(2 * N);
    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        uni.merge(a, b + N);
        uni.merge(b, a + N);
    }
    set<i_i> st;
    //ll maxi = 0;
    bitset<50001> bits;
    bits[0] = true;
    for(int i = 0; i < N; i++) {
        if(uni.issame(i, i + N)) {
            cout << -1 << endl;
            return 0;
        }
        i_i tmp = {uni.root(i), uni.root(i+N)};
        if(tmp.first < tmp.second) swap(tmp.first, tmp.second);
        if(st.count(tmp)) continue;
        st.insert(tmp);
        //cerr << i << " " << uni.size(i) << " " << uni.size(i+N) << endl;
        //maxi += max(uni.size(i), uni.size(i+N));
        bits = (bits << uni.size(i)) | (bits << uni.size(i+N));
    }
    /*
    cerr << maxi << endl;
    ll ans = maxi * (N - maxi) - M;
    cout << ans << endl;
    */
    for(ll i = N / 2; i >= 0; i--) {
        if(bits[i]) {
            cout << i * (N - i) - M << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 10640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  uint64_t N;
  cin >> N;
  
  uint64_t res = N;
  
  for (uint64_t i=1; i*i<=N; i++) {
    if ( N % i == 0) {
      uint64_t j = N / i;
      res = min( res, i + j - 2 );
    }
  }
  
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,f,t) for(int i=f;i<t;i++)
int main()
{
    int N; cin >> N;
    string S; cin >> S;
    string T;
    int level = 0;
    for (char c : S) {
        if (c == '(') { level++; T += "("; }
        else if (level == 0) { T = "(" + T + ")"; }
        else { level--; T += ")"; }
    }
    T += string(level, ')');
    cout << T << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

typedef struct {
    int x;
    int y;
} POINT;

int main(void)
{
    POINT data[3000];
    static char exist[5001][5001];
    int i, j;
    int n;
    int max;
    int dx, dy;
    
    while (1){
        scanf("%d", &n);
        
        if (n == 0){
            break;
        }
        
        memset(exist, 0, sizeof(exist));
        for (i = 0; i < n; i++){
            scanf("%d%d", &data[i].x, &data[i].y);
            exist[data[i].x][data[i].y] = 1;
        }
        
        max = 0;
        for (i = 0; i < n; i++){
            for (j = 0; j < n; j++){
                if (i == j){
                    continue;
                }
                dx = data[j].x - data[i].x;
                dy = data[j].y - data[i].y;
                if (dx < 0){
                    dx *= -1;
                }
                if (dy < 0){
                    dy *= -1;
                }
                
                if (data[i].x + dy <= 5000 && data[i].y + dx <= 5000 &&
                        data[j].x + dy <= 5000 && data[i].y + dx <= 5000 &&
                            exist[data[i].x + dy][data[i].y + dx] && exist[data[j].x + dy][data[j].y + dx] && dx * dx + dy * dy > max){
                    max = dx * dx + dy * dy;
                }
            }
        }
        
        printf("%d\n", max);
    }
    
    return (0);
}

Measured memory_bytes: 24000
#include<iostream>
#include<stdio.h>
#include<string>
#include <math.h>
using namespace std;
# define maxn 100001

int main(){
  // int n,m,a[maxn],b[maxn],c[maxn],cnt(0),sum(0);
  long long n,k,c[maxn]={0},cnt(0),sum(0);
  cin>>n>>k;
  // for(int i(0);i<n;i++){
  //   cin>>a[i];
  // }
  for(int i(0);i<n;i++){
    int a,b;
    cin>>a>>b;
    c[a]+=b; // 要素が個数
  }
  for (int i(1);i<maxn;i++){
    if(c[i]>=k){
      cout<<i;
      return 0;
    }
    k-=c[i];
  }
  // for (int i(1);i<maxn;i++){
  //   cnt+=c[i];
  //   if(cnt>=k){
  //     cout<<i;
  //     return 0;
  //   }
  // }
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define pq priority_queue
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 2000000009
string add[4];
int main()
{
	string s;
	cin>>s;
	add[0]="dream";
	add[1]="dreamer";
	add[2]="erase";
	add[3]="eraser";
	int sz=s.size();
	if (sz<5){
		cout<<"NO";
		return 0;
	}
	int i;
	for (i=0;i<sz;i++){
		if (sz-i<5){
			cout<<"NO";
			return 0;
		}
		//cout<<endl;
		//cout<<i<<endl;
		string buf=s.substr(i,5);
		//cout<<buf<<endl<<s.substr(i,5)<<endl;
		if (buf==add[0]||buf==add[2]){
			i=i+5;
			//cout<<i<<endl;
			if (sz-i<1){
				--i;
				continue;
			}
			if (s[i]=='r'&&buf==add[2]) i++;
			else if (sz-i>1&&s[i]=='e'&&s[i+1]=='r'&&buf==add[0]&&s[i+2]!='a') i+=2;
			//cout<<i<<endl;
			--i;
		}
		else{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
}

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

constexpr ll MOD = 1000000007;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

ll alp[26];

int main() {
  int n;
  string s;
  cin >> n >> s;
  rep(i, 0, n) alp[s[i] - 'a']++;

  ll ans = 1;
  rep(i, 0, 26) { ans = ans * (alp[i] + 1) % MOD; }
  ans -= 1;
  cout << ans << endl;
  return 0;
}

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

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	string st[7]={ "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	string s;
	cin >> s;
	for(int i=0;i<7;i++){
		if(s==st[i]){
			cout << 7-i << endl;
			break;
		}
	}
}


Measured memory_bytes: 256
class Union():
    def __init__(self, N):
        self.Parent = []
        for i in range(N):
            self.Parent.append(-1)

    def root(self, A):
        if (self.Parent[A] < 0):
            return A
        else:
            self.Parent[A] = self.root(self.Parent[A])
            return self.Parent[A]
    def size(self, A):
        return int(-1 * self.Parent[self.root(A)])


    def connect(self, A, B):
        A = self.root(A)
        B = self.root(B)
        if (A == B):
            return False

        if (self.size(A) < self.size(B)):
            A, B = B, A
        self.Parent[A] += self.Parent[B]
        self.Parent[B] = A
        return True


N, M = map(int, input().split())
X = [-1 for _ in range(M)]
Y = [-1 for _ in range(M)]
Z = [-1 for _ in range(M)]

for i in range(M):
    x, y, z = map(int, input().split())
    X[i], Y[i], Z[i] = x - 1, y - 1, z - 1

ans = N

uni = Union(N)

for i in range(M):
    uni.connect(X[i], Y[i])

parents = []

for i in range(N):
    parents.append(uni.root(i))
print(len(set(parents)))




Measured memory_bytes: 22660
<?php

myMain($argv);

class Util
{
    private static $isDebug = false;
    private static $startTime;

    public static function input($isSplitSpace = false)
    {
        $input = trim(fgets(STDIN));
        if (!$isSplitSpace) {
            return $input;
        }

        return explode(' ', $input);
    }

    public static function arrToStr($arr)
    {
        return implode(",", $arr);
    }

    public static function enablingDebug()
    {
        self::$isDebug = true;
        self::$startTime = time();
    }

    public static function DebugLog($text, $isReturn = true)
    {
        if (self::$isDebug) {
            echo $text;
            if ($isReturn) {
                echo PHP_EOL;
            }
        }
    }

    public static function varDump($obj)
    {
        if (self::$isDebug) {
            var_dump($obj);
        }
    }

    public static function arrFirst($arr)
    {
        if (empty($arr) || !is_array($arr)) {
            return null;
        }

        return current($arr);
    }

    public static function printBench()
    {
        if (!self::$isDebug) {
            return;
        }

        echo sprintf(" Time: %.3f s" . PHP_EOL, time() - self::$startTime);
    }
}

function myMain($argv)
{
    if (!empty($argv[1])) {
        Util::enablingDebug();
    }

    // START
    list($n, $leastTrack) = Util::input(true);
    $bList = [];
    for ($i = 0; $i < $n; ++$i) {
        $bList[] = Util::input();
    }

    $left = max($bList);
    $right = array_sum($bList);
    while ($right - $left > 1) {
        $mid = floor(($left + $right) / 2);
        if (isOkP($mid, $leastTrack, $bList)) {
            $right = $mid;
        } else {
            $left = $mid;
        }
        Util::DebugLog($left . "   " . $right);
    }

    if (isOkP($left, $leastTrack, $bList)) {
        echo $left . PHP_EOL;
    } else {
        echo $right . PHP_EOL;
    }

    // bench
    Util::printBench();
}

// 1. 荷物をトラックに運び入れる
// 2. トラックに詰めなかった場合は
//   2-1. 次のトラックがある場合は、今のトラックを出発させ、次のトラックを呼ぶ
//   2-2. 次のトラックがない場合は、チャレンジ失敗
function isOkP($p, $leastTrack, $bList)
{
    $leastP = $p;
    foreach ($bList as $b) {
//        Util::DebugLog(sprintf("  b: %d, leastP: %d, track: %d  ", $b, $leastP, $leastTrack), 0);
//        Util::DebugLog("  b: " . $b, 0);
        // 1
        if ($leastP >= $b) {
            $leastP -= $b;
//            Util::DebugLog(sprintf("  leastP: %d ", $leastP));
            continue;
        }

        // 2
        if ($leastTrack > 1) {
            // 2-1
            $leastTrack -= 1;
            $leastP = $p - $b;
//            Util::DebugLog(sprintf("  leastP: %d, track: %d  ", $leastP, $leastTrack));
            continue;
        }

        // 2-2
        return false;
    }

    return true;
}



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

int main(void){

    long long A,B;
    int K;
    cin >> A >> B >> K;
    
    int cont = 0;
    while(true){
        
        if(A%2==1)A--;
        B += A/2;
        A = A/2;
        cont++;
        if(cont == K)break;

        if(B%2==1)B--;
        A += B/2;
        B = B/2;
        cont++;
        if(cont == K)break;        
    
    }
    
    cout << A <<" "<<B<<endl;
}


Measured memory_bytes: 256
// B - Multiplication 2
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using INT = __int128_t;

int main(){
	int n; cin>>n;
	INT inf = INT(1e18) + 1;
	INT ans = 1;
	while(n--){
		ll a; cin>>a;
		ans = min(ans*a, inf);
	}
	if(ans == inf) puts("-1");
	else cout<< (ll)ans <<endl;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+50;
const int oo = 22;
int n, d, q;
int a[N];
map<int,int > M;
int P[N][oo];
signed main(){
	cin >> n;
	for(int i=1;i<=n;i++) cin >> a[i];
	cin >> d;
	for(int i=1;i<=n;i++){
		int v = a[i] + d;
		int k = lower_bound(a+1,a+n+1,v) - a;
		if(a[k]>v||k==n+1)	k--;
		P[i][0] = k;
	}
	for(int j=1;(1<<j)<=n;j++){
		for(int i=1;i<=n;i++){
			P[i][j] = P[P[i][j-1]][j-1];
		}
	}
	
	cin >> q;
	while(q--){
		int u, v;
		cin >> u >> v;
		if(u>v) swap(u,v); 
		int lg = log2(n);
		int ans = 0;
		for(int i=lg;i>=0;i--){
			if(P[u][i]<v){
				u = P[u][i];
				ans+=(1<<i);
			}
		}
		cout << ans+1 << endl;
	}
}

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

int main(){
    long long int N;
    cin >> N;
    int ans = 0;
    for(long long i=2;i*i<=N;i++){
        int cur = 0;
        while (N % i == 0) {
            cur++;
            N /= i;
        }
        for(int j=1;j<=cur;j++) {
            ans++; cur -= j;
        }
    }
    if(N>1) ans++;
    cout << ans << endl;

	return 0;
   
}

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

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int n;
	char s[5000+2];

	while(scanf("%d\n%[a-z]\n", &n, s)==2)
	{
		vvi m(n+1);
		for(auto&mm:m) mm.assign(n+1, 0);

		for(int i=0;i<n;i++)
		{
			for(int j=i;j<n;j++)
			{
				if(s[i]==s[j])
				{
					m[i+1][j+1]=m[i][j]+1;
				}
				else
				{
					m[i+1][j+1]=0;
				}
			}
		}
/*
		for(auto&mm:m)
		{
			for(int v:mm) printf("%d ", v);
			printf("\n");
		}
*/
		int ans=0;
		for(int i=1;i<=n;i++)
		{
			for(int j=i;j<=n;j++)
			{
				if(m[i][j]+i<=j)
				{
					ans=max(ans, m[i][j]);
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 98048
#include <stdio.h>

int main(void) {
  int i, w, h, n, mw = 0, mh = 0, x, y, a;
  scanf("%d%d%d", &w, &h, &n);
  for(i = 0; i < n; ++i) {
    scanf("%d%d%d", &x, &y, &a);
    if(a == 1 && x > mw) mw = x;
    if(a == 2 && x < w) w = x;
    if(a == 3 && y > mh) mh = y;
    if(a == 4 && y < h) h = y;
  }
  printf("%d", (w - mw > 0 ? w - mw : 0) * (h - mh > 0 ? h - mh : 0));
  return 0;
}

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

using ll = long long;

constexpr ll inf = 1e18;

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> xl, xr = {0};
    for(int i = 0; i < n; ++i) {
        ll x; cin >> x;
        if(x < 0) xl.push_back(x);
        else      xr.push_back(x);
    }
    xl.push_back(0);
    reverse(begin(xl), end(xl));
    const int n1 = xl.size(), n2 = xr.size();
    vector<ll> sum1(n1), sum2(n2);
    for(int i = 0; i + 1 < n1; ++i) {
        sum1[i + 1] = sum1[i] - xl[i + 1] + xl[i];
    }
    for(int i = 0; i + 1 < n2; ++i) {
        sum2[i + 1] = sum2[i] + xr[i + 1] - xr[i];
    }

    ll ans = inf;
    for(int i = 0; i <= k; ++i) {
        if(i >= (int)sum1.size() || k - i >= (int)sum2.size()) continue;
        ll mi = min(sum1[i], sum2[k - i]);
        ans = min(ans, mi + (sum1[i] + sum2[k - i]));
    }

    cout << ans << endl;
}


Measured memory_bytes: 2036