akhauriyash/Code-Regression huggingface dataset:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split(" ")))
L.sort()

num_triangles = 0
for i in range(N-2): 
    for j in range(i+1, N-1):
        idx = bisect_left(L, L[i]+L[j], j+1)
        num_triangles += idx-j-1
print(num_triangles)


Measured memory_bytes: 3188
// to be build tomorrow
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<pair<int, int>, null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update> 
#include <bits/stdc++.h> 
using namespace std; 
ordered_set s[200005];
struct pt {
    long long x, y;
    pt() {}
    pt(long long _x, long long _y) : x(_x), y(_y) {}
    pt operator-(const pt& p) const { return pt(x - p.x, y - p.y); }
    long long cross(const pt& p) const { return x * p.y - y * p.x; }
    long long cross(const pt& a, const pt& b) const { return (a - *this).cross(b - *this); }
};

int sgn(const long long& x) { return x >= 0 ? x ? 1 : 0 : -1; }

bool inter1(long long a, long long b, long long c, long long d) {
    if (a > b)
        swap(a, b);
    if (c > d)
        swap(c, d);
    return max(a, c) <= min(b, d);
}

bool check_inter(const pt& a, const pt& b, const pt& c, const pt& d) {
    if (c.cross(a, d) == 0 && c.cross(b, d) == 0)
        return inter1(a.x, b.x, c.x, d.x) && inter1(a.y, b.y, c.y, d.y);
    return sgn(a.cross(b, c)) != sgn(a.cross(b, d)) &&
           sgn(c.cross(d, a)) != sgn(c.cross(d, b));
}
using pp = pair <ll, ll>;
ll dp[30][30][2];
ll valid(ll f1, ll pos, string s, string cur, ll count)
{
    if (pos == s.length())
    {
        // cout << cur << "\n";
        if (stoull(cur))
        return 1;
        return 0;
    }
    if (dp[pos][count][f1] != -1)
    return dp[pos][count][f1];
    if (f1 == 1)
    {
        dp[pos][count][f1] = valid(f1, pos+1,s, cur+'0', count) + valid(f1, pos+1,s, cur + '1', count+1);   
    }
    else 
    {
        if (s[pos] == '0')
        {
            dp[pos][count][f1] = valid (f1, pos+1, s, cur+'0', count);
        }
        else if (s[pos] == '1')
        dp[pos][count][f1] = valid(0, pos+1, s, cur+'1', count+1) + valid(1, pos+1, s, cur + '0', count);
        else 
        dp[pos][count][f1] = valid(1, pos+1, s, cur+'1',count+1) + valid(1, pos+1, s, cur+'0', count);
    }
    return dp[pos][count][f1];
}
int main ()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    while (t--)
    {
    ll n, k;
    cin >> n >> k;
    ll p[n];
    for (auto &i : p)
    cin >> i;
    sort(p, p+n);
    ll sum = 0;
    ll c = 0;
    for (auto i : p)
    {
        sum += i;
        c++;
        if (c == k)
        break;
    }
    cout << sum;
    }
    return 0;
}

Measured memory_bytes: 22440
#include<iostream> 
    using namespace std;
    int main(){
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int H,S,H1,S2;    cin >> H >> S >> H1 >> S2;
        while(H > 0 && H1 > 0){
            H1 -= S;
            if(H1 <= 0){
                cout << "Yes";
                return 0;
            }
            H -= S2;
            if(H <= 0){
                cout << "No";
                return 0;
            }
        }
        return 0;
    }

Measured memory_bytes: 3064
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		int median = 0;
		long ans= 0;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt()-i-1;
		}
		Arrays.sort(A);
		if(N % 2 == 1)
			median = A[N/2];
		else
			median = (A[N/2-1] + A[N/2]) / 2;
		for(int i = 0; i < N; i++)
			ans += Math.abs(A[i]-median);
		System.out.println(ans);
		
	}

}

Measured memory_bytes: 84452
#include <cstdio>


int count(int p, int q, int n, int low, int max, int acc) {
	if (p == 0) return 1;
	if (n == 0) return 0;

	int result = 0;
	for (int i = low; i * acc <= max; i++) {
		result += count(p * i - q, i * q, n - 1, i, max, i * acc);
	}

	return result;
}

int main() {
	while (true) {
		int p, q, a, n;

		scanf("%d%d%d%d", &p, &q, &a, &n);
		if (!(p|q|a|n)) break;

		printf("%d\n", count(p, q, n, 1, a, 1));
	}

	return 0;
}

Measured memory_bytes: 1028
#include<cstdio>
#include<algorithm>
using namespace std;
int a,b,c,k,ans;
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	for(int i=min(a,b);i;--i){
		if(a%i==0&&b%i==0) ++k;
		if(k==c){ans=i;break;}
	}
    printf("%d",ans);
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(){
	string day[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	string input; cin >> input;
	int i = 0;
	for(; i < 7; i++){
		if(input == day[i]){
			break;
		}
			
	}
	int totalDays = 0;
	bool cek = false;
	while(1){
		if(i == 7)
			i = 0;
		if(day[i] == "SUN" && cek){
			break;
		}
		cek = true;
		totalDays++;
		i++;
	}
	cout << totalDays << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

struct GameData
{
    vector<int64_t> healths;
    int64_t direct;
    int64_t collateral;
};

int64_t DirectNeeded(const GameData &game, int64_t health, int64_t moves)
{
    auto diff = game.direct - game.collateral;
    return max<int64_t>(0, (health - game.collateral * moves + diff - 1) / diff);
}

bool CanBeat(const GameData &game, int64_t moves)
{
    int64_t needed = 0;
    for (const auto &h : game.healths) {
        needed += DirectNeeded(game, h, moves);
    }
    return needed <= moves;
}

int64_t Solve(const GameData &game)
{
    int64_t moves = 0;
    int64_t power = (1LL << 32);

    while (power > 0) {
        auto next_moves = moves + power;
        power >>= 1;

        if (!CanBeat(game, next_moves)) {
            moves = next_moves;
        }
    }
    return moves + 1;
}

GameData ReadGameData()
{
    GameData game;
    int n;

    cin >> n >> game.direct >> game.collateral;
    game.healths.resize(n);

    for (auto &h : game.healths) {
        cin >> h;
    }
    return game;
}

int main()
{
    auto res = Solve(ReadGameData());
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<long long ll> 
#define pb push_back
#define f(i,x,n) for (i=x;i<n;i++)
ll visited[1000000];
vector<ll> a[1000000];
ll c = 0;
void dfs(ll k){
    if(visited[k]!=1){
        visited[k]=1;
        c=c+1;
        for(ll i=0;i<(ll)a[k].size();i++){
            if(visited[a[k][i]]!=1)
            dfs(a[k][i]);
        }
    }

}

 
void solve(){
    ll n,m;
    cin >> n >> m;
    for(ll i=0;i<m;i++){
        ll x,y;
        cin >> x >> y;
        a[x].pb(y);
        a[y].pb(x);
    }
    
    ll ans=0;
    for(ll i=1;i<=n;i++){
        c=0;
         if(visited[i]==0){
            dfs(i);
            ans=max(ans,c);
        }
        //cout << c <<" ";
        
    }
    cout << ans <<endl;
}
int main(){
	ios_base::sync_with_stdio(false); 
     	cin.tie(NULL);
	ll t=1;
	while(t--)
	solve();	
	
}

Measured memory_bytes: 40904
from sys import stdin, stdout
def gmi(): return map(int, stdin.readline().strip().split())
def gms(): return map(str, stdin.readline().strip().split())
def gari(): return list(map(int, stdin.readline().strip().split()))
def gars(): return list(map(int, stdin.readline().strip().split()))
def gs(): return stdin.readline().strip()
def gls(): return list(stdin.readline())
def gi(): return int(stdin.readline())

n = gi()
ar = gari()
c = 0
ans = 0
s = sum(ar)
sub = 0
for i in ar[:-1]:
    sub +=  ar[c]
    ans += i*(s-sub)
    c += 1
print(ans%1000000007)








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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n,m; cin >> n >> m;
  cout << (n == m ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
check :: String -> Bool -> String
check str False =if (length str ) == 1 then "No" else
   if(take 1 str)=="C" then check (drop 1 str) True else check (drop 1 str) False
check str True = if(length str) == 0 then "No" else
  if (take 1 str)== "F" then "Yes" else check (drop 1 str) True

main = do
        n <- getLine
        putStrLn (check n False)

Measured memory_bytes: 508
#include <cstdio>

int main(){
	long a, b;
	while( scanf(" %ld %ld", &a, &b) != EOF ){
		int count=0;
		long c = a+b;
		
		while(c!=0){
			c/=10;
			++count;
		}
		
		printf("%d\n", count);
	}
	
	return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;



int main() {
    li a, b, n;
    cin >> n >> a >> b;
    cout << min(a, b) << " " << max(0ll, (a + b - n)) << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

long long int powint(long long int a, long long int b) {
	assert(b >= 0);
	if (b == 0)return 1;
	if (b == 1)return a;
	long long int ans = 1;
	long long int aa = powint(a, b / 2);
	ans *= aa*aa;
	if (b % 2)ans *= a;
	return ans;
}

string st;
int a = 0;
void check(const int num) {
	if (num < 0 || num >= 1024)throw(false);
}
int getnum() {
	int num = 0;
	while (isdigit(st[a])) {
		num = num * 2 + st[a] - '0';
		a++;
	}
	check(num);
	return num;
}
int getexpr(const int isstart);
int getkakko();
int getka() {
	if (st[a] == '(') {
		int num=getkakko();
		return num;
	}
	else if(isdigit(st[a])){
		return getnum();
	}
	else {
		throw(false);
	}
}
pair<int,int> getso() {
	int num = getka();
	bool fst = false;
	while (1) {
		if (a == st.size() || st[a] == ')'||st[a]=='+'||st[a]=='-') {
			return make_pair(fst,num);
		}
		else if (st[a] == '*') {
			fst = true;
			a++;
			int n_num = getka();
			num *= n_num;
			check(num);
		}
		else {
			throw(false);
		}
	}
}
pair<int, int> getexpr() {
	auto p(getso());
	bool fst = p.first;
	int num = p.second;
	while (1) {
		if (a == st.size()) {
			return make_pair(fst,num);
		}
		else if (st[a] == '+') {
			fst = true;
			a++;
			int n_num = getso().second;
			num += n_num;
			check(num);
		}
		else if (st[a] == '-') {
			fst = true;
			a++;
			int n_num = getso().second;
			num -= n_num;
			check(num);
		}
		else {
			throw(false);
		}
	}
}
int getkakko() {
	if (st[a] == '(') {
		a++;
	}
	else {
		throw(false);
	}
	auto p(getso());
	int num = p.second;

	int fst = p.first;
	while (1) {
		if (a == st.size()) {
			throw(false);
		}else if( st[a] == ')') {
			if (!fst) throw(false);
			else break;
		}
		else if (st[a] == '+') {
			fst = true;
			a++;
			int n_num = getso().second;
			num += n_num;
			check(num);
		}
		else if (st[a] == '-') {
			fst = true;
			a++;
			int n_num = getso().second;
			num -= n_num;
			check(num);
		}
		else {
			throw(false);
		}
	}
	if (st[a] == ')') {
		a++;
		return num;
	}
	else {
		throw(false);
	}
}
int main() {
	string base; cin >> base;
	st = base;
	string aa = "01+-*()";
	vector<int>unknowns;
	for (int i = 0; i < base.size(); ++i) {
		if (base[i] == '.') {
			unknowns.emplace_back(i);
		}
	}
	int ans = -1;
	for (int i = 0; i < powint(7, unknowns.size()); ++i) {
		int num(i);
		a = 0;
		for (int j = 0; j < unknowns.size(); ++j) {
			st[unknowns[j]] = aa[num % 7];
			num /= 7;

		}
		
		try {
			int num = getexpr().second;
			ans=max(ans,num);
		}
		catch (...) {
			
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,a,b,c;
    t = 1;
    while(t--) {
     cin >> a >> b >> c;
     if(a + b >= c)
      cout << "Yes" << endl;
     else
      cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// Code by H~$~C
#include <bits/stdc++.h>
using namespace std;

int main() {
#define int long long
  int n;
  cin >> n;
  vector<pair<int, int> > arr(n);
  for (int i = 0; i < n; ++i) {
    int x, l;
    cin >> x >> l;
    arr[i].first = x + l;
    arr[i].second = x - l;
  }
  sort(arr.begin(), arr.end());
  int last = -2e9;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (last <= arr[i].second) {
      ++ans;
      last = arr[i].first;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44

using namespace std;

const int MAXH = (int) 2e5 + 5;

vector <int> arr[MAXH + 1];
map < pair <int, int>, bool > mp;

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n, h, w;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> h >> w >> n;
    swap(h, w);
    for(i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;
        arr[y].push_back(x);
        mp[{x, y}] = 1;
    }
    for(i = 1; i <= h; i++) {
        arr[i].push_back(w + 1);
        sort(arr[i].begin(), arr[i].end());
    }
    int x = 1, y = 1, cnt = 0;
    int ans = 2 * MAXH;
    while(x <= w && y <= h) {
        pair <int, int> aux = {x, y};
        auto it = upper_bound(arr[y].begin(), arr[y].end(), x);
        if(it != arr[y].end()) {
            ans = min(ans, cnt + (*it - x));
            if(x < w && mp[{x + 1, y}] == 0) {
                x++;
            }
        }
        //cerr << x << " " << y << "\n";
        if(y < h && mp[{x, y + 1}] == 0) {
            y++;
        }
        //cerr << x << " " << y << "\n";
        if(aux.first == x && aux.second == y) {
            ans = min(ans, cnt + 1);
            break;
        }
        cnt++;
    }
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}



Measured memory_bytes: 47872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;

int cnt[110];
int main() {
    int n,k;
    cin >> n >> k;
    for (int i = 0; i < k; i++) {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++) {
            int a;
            cin >> a;
            cnt[a]++;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (cnt[i] == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

int main() {
    int n, h, w;
    cin >> n >> h >> w;
    cout << (n - h + 1) * (n - w + 1) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
using namespace std;

int main(){
    int n;
    string str;
    cin>>n;
    while(n--){
        cin>>str;
        int lev=0,level=0,i,last=0;
        string num;
        for(i=0;i<str.length();i++)
            if(str[i]!='[')
                break;
        level=i;
        vector<vector<int> >vec;
        vector<int>v,las,peo;
        vec.resize(level,v);
        las.resize(level,0);
        peo.resize(level,0);
        for(int i=0;i<str.length();i++){
            if(str[i]=='['){
                lev++;
            }
            else if(str[i]==']'){
                if(lev==level){
                    last = stoi (num);
                    vec[lev-1].push_back(last);
                }
                else{
                    int tem=0;
                    vector<int>te;
                    int temp=0;
                    for(;las[lev-1]<vec[lev].size();las[lev-1]++){
                        te.push_back(vec[lev][las[lev-1]]);
                        temp++;
                    }
                    sort(te.begin(),te.end());
                    for(int ii=0;ii<(temp+1)/2;ii++)
                    {
                        if(lev==level-1)tem+=(te[ii]+1)/2;
                        else tem+=te[ii];
                    }
                    vec[lev-1].push_back(tem);
                }
                num="";
                lev--;
            }
            else
                num+=str[i];
        }
        cout<<vec[0][0]<<endl;
    }
    
}

Measured memory_bytes: 1308
/*
 * stable sort check
 *
 */

#include <stdio.h>
#define MAX 36

typedef struct{
    char type;
    int number;
}Card;

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

    int i, j, key_num, k;
    char c, key_type;
    Card card_b[n], card_s[n];
    for(i=0;i<n;i++){
        scanf(" %c%d", &c, &k);
        card_b[i].type = card_s[i].type = c;
        card_b[i].number = card_s[i].number = k;
    }

    //Bubble Sort Algo
    for(i=0; i<=n-1; i++){
        for(j=n-1; j>=i+1; j--){
            if(card_b[j].number < card_b[j-1].number){
                key_num = card_b[j].number;
                key_type = card_b[j].type;
                card_b[j].number = card_b[j-1].number;
                card_b[j].type = card_b[j-1].type;
                card_b[j-1].number = key_num;
                card_b[j-1].type = key_type;
            }
        }
    }

    for(i=0;i<n-1;i++){
        printf("%c%d ", card_b[i].type, card_b[i].number);
    }
    printf("%c%d\n", card_b[n-1].type, card_b[n-1].number);
    printf("Stable\n");
    

    int minj;
    //Selection Sort Algo
    for(i=0; i<=n-2; i++){
        minj = i;
        for(j=i; j<=n-1; j++){
            if(card_s[j].number < card_s[minj].number){
                minj = j;
            }
        }

        if(minj != i){
            key_num = card_s[i].number;
            key_type = card_s[i].type;
            card_s[i].number = card_s[minj].number;
            card_s[i].type = card_s[minj].type;
            card_s[minj].number = key_num;
            card_s[minj].type = key_type;
        }
    }

    int isStable = 1;
    for(i=0;i<n-1;i++){
        printf("%c%d ", card_s[i].type, card_s[i].number);
        if(card_s[i].type != card_b[i].type && card_s[i].number == card_b[i].number){
            isStable = 0;
        }
    }
    printf("%c%d\n", card_s[n-1].type, card_s[n-1].number);
    printf(isStable ? "Stable\n" : "Not stable\n");

    return 0;

}



Measured memory_bytes: 2072
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
signed main(){
	
    double a,b,x;
    cin>>a>>b>>x;
    double s,t,s2,t2;
    t=a;
    s=x/(a*a);
    t2=b;
    s2=s*t*2/a-t2;
    if(s2<0){
        s2=s*t*2/t2;
        printf("%.7lf",atan(t2/s2)/3.14159265*180.0);
    }
    else{
        printf("%.7lf",atan((b-s2)/a)/3.14159265*180.0);
    }
    
    //cout<<t<<" "<<s<<" "<<t2<<" "<<s2<<endl;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
const lli inf=1e18;
const int mod=1e9+7;
int main(){
IOS;
int n,i;
cin>>n;
int b[n-1];
for(i=0;i<n-1;i++){
    cin>>b[i];
}
int sum=b[0];
for(i=1;i<n-1;i++){
    if(b[i-1]>b[i]){
        sum+=b[i];
    }
    else sum+=b[i-1];
}
sum+=b[n-2];
cout<<sum<<endl;
}


Measured memory_bytes: 256
#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repl(i, a, b) for(ll i = a; i < (b); ++i)
#define repd(i, a, b) for(int i = b; i >= (a); --i)
#define repdl(i, a, b) for(ll i = b; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
#endif
#ifndef _TEMPLATE_OPT
#define _TEMPLATE_OPT
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#endif
using namespace std;

namespace std {
  template<typename T, typename K> struct hash<pair<T, K>> {
    size_t operator()(pair<T, K> const& p) const noexcept {
      size_t h1 = std::hash<T>{}(p.first);
      size_t h2 = std::hash<K>{}(p.second);
      return h1 ^ (h2 << 1);
    }
  };
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  int h, w, n; read(h, w, n);
  vector<pair<int, int>> locs;

  if (n == 0) {
    write(1ll * (h - 2) * (w - 2));
    rep(i, 0, 9) write(0);
    return 0; 
  }

  locs.reserve(n * 9);

  rep(i, 0, n) {
    int x, y; read(x, y);
    rep(a, -2, 1) rep(b, -2, 1)
      if (1 <= x + a && x + a <= h - 2 && 1 <= y + b && y + b <= w - 2)
        locs.push_back({x + a, y + b});
  }

  sort(all(locs));

  vector<ll> ans(10);

  pii prev = locs[0];
  int cnt = 0;
  for (auto p : locs) { 
    if (p == prev) cnt++;
    else {
      ans[cnt]++;
      cnt = 1;
      prev = p;
    }
  }
  ans[cnt]++;

  ans[0] = 1ll * (h - 2) * (w - 2);
  rep(i, 1, 10) ans[0] -= ans[i];

  rep(i, 0, 10) write(ans[i]);
}



Measured memory_bytes: 10296
#include <bits/stdc++.h>
using namespace std;
vector<int> di(int m){
    vector<int> a;
    for(int i=1;i*i<=m;i++){
        if(m%i==0){
            a.push_back(i);
            a.push_back(m/i);
        }
    }
    sort(a.begin(),a.end());
    return a;
}
int main(){
  int n,m;
  vector<int> a;
  cin >> n >> m;
  a = di(m);
  for(auto i:a){
      if(n<=i){
          cout << m/i << endl;
          break;
      }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){
  int x,y;
  cin >> x >> y;
  int a = 0;
  if(x == 1)a = 300000;
  else if(x == 2)a = 200000;
  else if(x == 3)a = 100000;
  else a = 0;
  int b = 0;
  if(y == 1)b = 300000;
  else if(y == 2)b = 200000;
  else if(y == 3)b = 100000;
  else b = 0;
  int ans = a + b;
  if(x == 1 && y == 1)cout << ans + 400000 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 256
use std::io;


/// https://beta.atcoder.jp/contests/abc072/tasks/abc072_b
fn main() {
    let s = read_one::<String>().chars().collect::<Vec<char>>();

    for i in 0..s.len() {
        if i % 2 == 0 { print!("{}", s[i]); }
    }
    println!();
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	vector<int> A(a);
	vector<int> B(b);
	vector<int> C(c);
	for(int &h: A)cin>>h;
	for(int &h: B)cin>>h;
	for(int &h: C)cin>>h;
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	sort(C.begin(),C.end());
	ll out=0;
	int it = a-1;
	int jt = c-1;
	vector<int> ans;
	while(x)
	{
		ans.push_back(A[it--]);
		x--;
	}
	it = b-1;
	while(y)
	{
		ans.push_back(B[it--]);
		y--;
	}
	int z =ans.size();
	sort(ans.begin(),ans.end());
	for(int i=0;i<z;i++)
	{
		if(C[jt]>ans[i])
			out+=C[jt--];
		else out+=ans[i];
	}
	cout<<out<<'\n';
	
}


Measured memory_bytes: 2552
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

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

  ll ans = 0;
  ll hu = 0, k = 0;
  rep(i,N) hu += a[i] * b[i];
  rep(i,N) k += b[i];
  ans = (k - 1) + (hu - 1) / 9;
  cout << ans << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define SIZE 5005
#define INF 1000000005
#define ll long long
#define MS(x,y) memset(x,y,sizeof x);
#define FOR(i,x,y) for(int i = x; i <= y; ++i)
#define rFOR(i,x,y) for(int i = x; i >= y; --i)
#define pb push_back
using namespace std;

int n;
int a[100007];

int main()
{
    scanf("%d",&n);
    FOR(i,0,n - 1)
        scanf("%d",&a[i]);
    sort(a,a + n);
    int l = 0;
    int r = 0;
    int ans = 0;
    while(r < n)
    {
        if(a[r] - a[l] <= 2)
        {
            ans = max(ans,r - l + 1);
            ++r;
        }else
        {
            while(a[r] - a[l] > 2)
                ++l;
            ans = max(ans,r - l + 1);
        }
    }
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()

ll N, L[100000], R[100000];

int main() {
    cin >> N;
    REP(i, N) cin >> L[i] >> R[i];
    sort(L, L + N, greater<ll>());
    sort(R, R + N);

    int ok_count = 0;
    REP(i, N) if (L[i] > R[i]) ok_count++;

    ll l_ans = 0, r_ans = 0;
    ll l_now = 0, r_now = 0;
    REP(i, ok_count) {
        l_ans += abs(L[i] - l_now);
        l_ans += abs(R[i] - L[i]);
        l_now = R[i];
        r_ans += abs(R[i] - r_now);
        r_ans += abs(L[i] - R[i]);
        r_now = L[i];
    }

    if (L[ok_count] > l_now) {
        l_ans += abs(L[ok_count] - l_now);
        l_ans += abs(L[ok_count]);
    }
    else {
        l_ans += abs(l_now);
    }
    if (R[ok_count] < r_now) {
        r_ans += abs(R[ok_count] - r_now);
        r_ans += abs(R[ok_count]);
    }
    else {
        r_ans += abs(r_now);
    }

    cout << max(l_ans, r_ans) << endl;
    return 0;
}

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

int main() {
  string N;
  cin >> N;
  bool flag = true;
  for(int i = 1; i <= N.size(); i += 2){
    if(N.at(i - 1) == 'L') flag = false;
  }
  for(int i = 2; i <= N.size(); i += 2){
    if(N.at(i - 1) == 'R') flag = false;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>
#define MOD 1000000007
#define REP(i,st,num)for(int i=(st);i<(num);++i)
#define ll long long
using namespace std;

string toStr(string s) {
    int c[27]={0,};
    string r="";
    REP(i,0,10) {
        c[s[i]-'a']++;
    }
    REP(i,0,26){
        r+=to_string(c[i])+"_";
    }
    return r;
}

int main() {
    ios::sync_with_stdio(false);
    int N;
    string s;
    unordered_map<string,ll> mp;
    cin>>N;
    REP(i,0,N){
        cin>>s;
        string k=toStr(s);
        mp[k]++;
    }
    ll ans=0;
    for(auto kv:mp) {
        if(kv.second>1){
            ans+=(kv.second)*(kv.second-1)/2;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 16932
#include<stdio.h>
#include<string.h>
using namespace std;

#define LIM 519430400
#define LEN 13

char H[LIM][LEN];


int toInt(char str) {
  if ( str == 'A' ) return 1;
  else if ( str == 'C' ) return 2;
  else if ( str == 'G' ) return 3;
  else if ( str == 'T' ) return 4;
  else return 0;
}

long long getKey(char str[]) {
  int i, m, p = 1, sum = 0;
  for ( i = 0; i < strlen(str); i++ ) {
    m = toInt(str[i]);
    sum += m * p;
    p *= 5;
  }
  return sum;
}

int h1(long long key) { return key % LIM; }
int h2(long long key) { return 1 + (key % (LIM - 1)); }
long long hashValue(long long key, int i) { return h1(key) + i * h2(key); }

int insert(char str[]) {
  long long key = getKey(str);
  for ( int i = 0; i < LIM; i++ ) {
    long long h = hashValue(key, i);
    if (strcmp(H[h], str) == 0) return 1;
    else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 1;
    }
  }
  return 0;
}
int find(char str[]) {
  long long key = getKey(str);
  for ( int i = 0; i < LIM; i++ ) {
    long long h = hashValue(key, i);
    if (strcmp(H[h], str) == 0) return 1;
    else if (strlen(H[h]) == 0) return 0;
  }
  return 0;
}

int main() {
  int n;
  char com[6], str[12];
  scanf("%d", &n);

  while( scanf("%s %s", com, str) != EOF ) {
    if ( com[0] == 'i' ) {
      insert(str);
    } else {
      if (find(str)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }

  return 0;
}



Measured memory_bytes: 48320
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;


int main(){

    int N,ans=0;
    cin >> N;

    for(int i=0;i<=25;i++){
        for(int j=0;j<=15;j++){
            int temp=i*4+j*7;
            if(temp==N){
                cout << "Yes"<<endl;
                return 0;   
            }
        }
    }

    cout << "No"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEFINE
#include "../../DEBUG.hpp"
#endif

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long a, b;
  while (cin >> a >> b) {
    long long gg = __gcd(a, b);
    long long l = (a * b) / gg;
    cout << gg << " " << l << '\n';
  }
  return 0;
}



Measured memory_bytes: 3156
<?php
  $stdin = fopen('php://stdin', "r");

  fscanf($stdin, "%d %d %d", $a, $b, $c);

  $r = [$a, $b, $c];
  $cnt = 0;

  while (true) {
    // min => $r[0], mid => $r[1], max => $r[2]
    // 全部同じなら処理終了
    if ($r[0]==$r[1] && $r[0]==$r[2]) {
      echo $cnt.PHP_EOL;
      break;
    }

    sort($r);

    // max-minの差が2以上ならminに2を足す
    if ($r[2]-$r[0] >= 2) {
      $r[0] += 2;

    // 違うならminとmidに1を足す
    } else {
      $r[0] += 1;
      $r[1] += 1;
    }

    $cnt++;
  }


Measured memory_bytes: 4728
#ifdef __STRICT_ANSI__
#undef __STRICT_ANSI__
#endif
#include<iostream>
//#include<bits/stdc++.h>
#include<cstdio>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<ctime>
#include<algorithm>
#include<cmath>
#include<vector>
#define showtime fprintf(stderr,"time = %.15f\n",clock() / (double)CLOCKS_PER_SEC)
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
typedef long long ll;
typedef long long LL;
typedef unsigned long long ull;
#define MP make_pair
#define PII pair<int,int>
#define PFI pair<double,int>
#define PLL pair<ll,ll>
#define F first
#define S second
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
//freopen("1005.in","r",stdin);
//freopen("data.out","w",stdout);
typedef vector<ll> Vec;
typedef vector<Vec> Mat;
const double eps = 1e-8;
const double PI = acos(-1.);
const double E = 2.71828182845904523536;
const int MOD = (int)1e9+7;
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x7f7f7f7f;
const int N = 1e5 + 7;
const int M = 2000000 + 5;

inline int popcnt(int x){return __builtin_popcount(x); }
inline int clz(int x){return __builtin_clz(x);} //末尾的 0，即对 lowbit 取log
inline int clz(LL x){return __builtin_clzll(x);}
inline int lg2(int x){ return !x ? -1 : 31-clz(x);}
inline int lg2(LL x){ return !x ? -1 : 63-clz(x);}

int n,x,y;
ll a[111111];
int main(){
	scanf("%d",&n);
	for(int i = 0; i < n; i ++){
	 	scanf("%lld",&a[i]);
		if(a[i]&1) x++;
		else y ++;
	}
	if(x%2==0) puts("YES");
	else puts("NO");
	// odd + odd = even
	// odd + even = odd
	
	return 0;
}


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

int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (a < b && b < c)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
}


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

int main(){

    int N;
    cin >> N;

    vector<int> mochis(N);
    for (int i=0; i<N; i++) {
        cin >> mochis[i];
    }
    sort(mochis.begin(), mochis.end());
    mochis.erase(unique(mochis.begin(), mochis.end()), mochis.end());
    
    cout << mochis.size() << endl;
}

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

using namespace std;
typedef long long LL;
const int LEN = 1e6 + 10;
int arr[LEN];
vector<int> period;
LL cnt = 0;

void InsertSort(int n, int k) {
    for (int i = k; i <= n; i++) {
        int key = arr[i];
        int j = i - k;
        while (j >= 0 && arr[j] > key) {
            arr[j + k] = arr[j];
            j -= k;
            cnt++;
        }
        arr[j + k] = key;
    }
}

void ShellSort(int n) {
    cnt = 0;
    int k = 1;
    while (k <= n) {
        period.push_back(k);
        k = 3 * k + 1;
    }
    for (int i = period.size() - 1; i >= 0; i--) {
        InsertSort(n, period[i]);
    }
}

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    ShellSort(n);
    cout << period.size() << endl;
    for (int i = period.size() - 1; i >= 0; i--)
        cout << period[i] << (i == 0 ? '\n' : ' ');
    cout << cnt << endl;
    for (int i = 1; i <= n; i++)
        cout << arr[i] << endl;
    return 0;
}



Measured memory_bytes: 6956
#include<bits/stdc++.h>
#define ll double
#define fr(a,b) for(int i = a; i < b; i++)
#define mod 1000000007
#define triplet pair<int,pair<int,int>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
 
ll dp[301][301][301];
ll solve(int one, int two, int three, int& n)
{
    if(one < 0 || two < 0 || three < 0)
        return 0;
    if(three == 0 && two == 0 && one == 0)
        return 0;
 
    if(dp[one][two][three] > 0)
        return dp[one][two][three];
 
    int remaining = one + two + three;
    ll exp_val = n+one*solve(one-1,two,three,n) + two*solve(one+1,two-1,three,n) +
                    three*solve(one,two+1,three-1,n);
 
    return dp[one][two][three] = exp_val/remaining;
}
 
int main(){
    int i,j,t,n,m,p,k;
    //fast_io;
    //cin>>t;
    t=1;
    while(t--)
    {
        cin>>n;
        int one=0,two=0,three=0;
 
        fr(0,n){
            int x;
            cin >> x;
            if(x == 1)one++;
            else if(x == 2)two++;
            else three++;
        }
 
        memset(dp, -1, sizeof dp);
        cout<<fixed<<setprecision(9)<<solve(one,two,three,n);
    }
    return 0;
}

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


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

	int n, x, cnt = 0;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> x, cnt += (x & 1 and i & 1);
	cout << cnt << '\n';


	return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<vl> mat;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const double PI = 4*atan(1);
const ll INF = 1e18;
const int MX = 100001;

int N,M;
bitset<1000> reach[1000];
int flow[1000][1000];
vi adj[1000];
set<pi> bad;
vpi edge;

void init() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> M;
    F0R(i,M) {
        int x,y; cin >> x >> y;
        x--, y--;
        edge.pb({x,y});
        adj[x].pb(y);
        reach[x][y] = 1;
    }
    F0R(k,N) 
        F0R(i,N) if (reach[i][k])
            reach[i] |= reach[k];
}

bool posi[1000], ok[1000];

void dfs(int cur, int x) {
    if (posi[cur] || cur == x) return;
    posi[cur] = 1;
    for (int i: adj[cur]) dfs(i,x);
}

void genBad(int x) {
    F0R(i,N) posi[i] = 0, ok[i] = 1;
    for (int i: adj[x]) {
        if (posi[i]) ok[i] = 0;
        dfs(i,x);
    }
    F0R(i,N) posi[i] = 0;
    F0Rd(I,sz(adj[x])) {
        int i = adj[x][I];
        if (posi[i]) ok[i] = 0;
        dfs(i,x);
    }
    for (int i: adj[x]) {
        if (ok[i]) bad.insert({x,i});
    }
}

int main() {
    init();
    F0R(i,N) genBad(i);
    for (auto a: edge) {
        if (reach[a.s][a.f]) {
            if (bad.count(a)) cout << "diff\n";
            else cout << "same\n";
        } else {
            if (!bad.count(a)) cout << "diff\n";
            else cout << "same\n";
        }
    }
}

// read the question correctly (is y a vowel?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)

Measured memory_bytes: 13552
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  while(1){
    c-=b;
    if(c<=0){
      cout << "Yes" << endl;
      break;
    }
    a-=d;
    if(a<=0){
      cout << "No" << endl;
      break;
    }
  }
}


Measured memory_bytes: 3616
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"_,t,a,*h=map(int,open(0).read().split());m=[abs(t-6e-3*x-a)for x in h];print(m.index(min(m))+1)\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 3408
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
char s[11];
cin >> s;
int num = strlen(s);
int ans=INF;
int temp;
REP(i,num-2) {
  temp=abs(((s[i]-'0')*100+(s[i+1]-'0')*10+s[i+2]-'0')-753);
  ans=min(ans,temp);
}
cout << ans <<endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};

int main() {

	char a;
	cin>>a;
	int b=a;
	if(b<=90)cout<<"A"<<endl;
	else cout<<"a"<<endl;

	return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main(void)
{
  int i,n,box,max,min;
  long sum;
  scanf("%d",&n);
  scanf("%d",&box);
  max=box;
  min=box;
  sum=box;
  for(i=1;i<n;i++){
    scanf("%d",&box);
    sum=sum+box;
    if(box > max)max=box;
    if(box < min)min=box;
  }
  printf("%d %d %ld\n",min,max,sum);

  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <stack>
#include <queue>
#define mod 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

// nのk乗をmで割った余り(n^k(mod m))を求める
ll pow_mod(ll n, ll k, ll m){
    if(k == 0){
        return 1;
    }
    else if(k % 2 == 1){
        return pow_mod(n, k-1, m) * n % m;
    }
    else{
        ll t = pow_mod(n, k/2, m);
        return t * t % m;
    }
}

int main(void)
{
    ll N, ans=0;

    cin >> N;

    ans += pow_mod(10,N,mod);
    ans -= pow_mod(9,N,mod);
    ans -= pow_mod(9,N,mod);
    ans += pow_mod(8,N,mod);

    while(ans<0){
        ans += mod;
    }

    ans %= mod;

    cout << ans << endl;

    return 0;
}

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

#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);

int main() {
    fast_io;

    ll n,m;
    cin>>n>>m;

    vector<int> c_arr(n+1);
    vector<int> w_arr(n+1);

    for(int i=0;i<m;i++) {
        int p;
        string s;
        cin>>p>>s;

        int c_ans=0;
        int w_ans=0;
        if(c_arr[p]!=1) {
            if(s=="WA") {
                w_arr[p]++;
            }
            else {
                c_arr[p]=1;
            }
        }
    }

    int c_ans=0;
    int w_ans=0;
    for(int i=1;i<=n;i++) {
        if(c_arr[i]==1) {
            c_ans++;
            w_ans+=w_arr[i];
        }
    }


    cout<<c_ans<<' '<<w_ans<<endl;
    
}




Measured memory_bytes: 4000