akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct WE {
    int W, E;
};

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

    // cout << N << endl;
    
    string str;
    cin >> str;
    
    vector<WE> from_west(N);
    vector<WE> from_east(N);
    from_west[0] = {0, 0};
    from_east[N-1] = {0, 0};
    if(str[0]=='W') {
        from_west[0].W++;
    } else {
        from_west[0].E++;
    }
    if(str[N-1]=='W') {
        from_east[N-1].W++;
    } else {
        from_east[N-1].E++;
    }
    
    for(int n=1; n<N; n++) {
        if(str[n]=='W') {
            from_west[n].W = from_west[n-1].W+1;
            from_west[n].E = from_west[n-1].E;
        } else {
            from_west[n].W = from_west[n-1].W;
            from_west[n].E = from_west[n-1].E+1;
        }
        if(str[N-1-n]=='W') {
            from_east[N-1-n].W = from_east[N-n].W+1;
            from_east[N-1-n].E = from_east[N-n].E;
        } else {
            from_east[N-1-n].W = from_east[N-n].W;
            from_east[N-1-n].E = from_east[N-n].E+1;
        }
    }
    

    int ans=3*1e5+1;
    for(int n=1; n<N; n++) {
        // cout << from_west[n-1].W << ", " << from_east[n].E << endl;
        // cout << from_west[n-1].E << ", " << from_east[n].W << endl;
        ans = min(ans, from_west[n-1].W+from_east[n].E);
        // ans = min(ans, from_west[n-1].E+from_east[n].W);
    }

    ans = min(ans, min(from_west[N-1].W, from_east[0].E));
    
    cout << ans << endl;
    
    return 0;
    
}

Measured memory_bytes: 5380
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
big=max(A)
bigsize=A.count(big)
if bigsize==1:
    a=sorted(A)
    next=a[-2]
    for i in range(N):
        if A[i]==big:
            print(next)
        else:
            print(big)
else:
    for i in range(N):
        print(big)


Measured memory_bytes: 18808
# メモ：問題文と解答がかみ合ってない気がする。
# そもそも「入力例 1」で「人1・4は2とコミュニケーション取れる」とあるが、
# これは定義に反している気がする。
# 人1・4に共通言語はないし、人1・4がコミュニケーション取るには1人では無理（人2・3両方必要）。

from collections import defaultdict


class UnionFind:

    def __init__(self, n):
        self.n = n
        # root[x] < 0ならそのノードが根かつその絶対値が木の要素数
        self.root = [-1] * (n + 1)
        self.rank = [0] * (n + 1)

    def find_root(self, node):
        if self.root[node] < 0:
            return node
        else:
            self.root[node] = self.find_root(self.root[node])
            return self.root[node]

    def union(self, one_node, other_node):
        one_node = self.find_root(one_node)
        other_node = self.find_root(other_node)
        if one_node == other_node:
            return
        elif self.rank[one_node] > self.rank[other_node]:
            self.root[one_node] += self.root[other_node]
            self.root[other_node] = one_node
        else:
            self.root[other_node] += self.root[one_node]
            self.root[one_node] = other_node
            if self.rank[one_node] == self.rank[other_node]:
                self.rank[other_node] += 1

    def group_size(self, node):
        return - self.root[self.find_root(node)]


def main():
    N, M = list(map(int, input().split()))
    lang_member_map = defaultdict(list)
    for n in range(N):
        for lang in input().split()[1:]:
            lang_member_map[lang].append(n)
    tree = UnionFind(N)
    for members in lang_member_map.values():
        if len(members) <= 1:
            continue
        n1 = members[0]
        for n2 in members[1:]:
            tree.union(n1, n2)
    if tree.group_size(0) == N:
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()

Measured memory_bytes: 23188
l = []
counter = 0
ans_list = []

n = int(input())
b_list = [0 for _ in range(n)]
l = list(map(int, input().split()))

for i in range(n,0,-1):
    index = n // i
    if index == 1: # 倍数がないとき
        b_list[i-1] = l[i-1]
    else:
        sum = 0
        for j in range(2, index+1):
            sum = sum + b_list[(i * j)-1]
        #print(l[i-1], sum)
        if l[i-1] != sum % 2:
            b_list[i-1] = 1

    if b_list[i-1] == 1:
        counter += 1
        ans_list.append(str(i))

#print(ans_list)
print(counter)
if ans_list != []:
    print(' '.join(sorted(ans_list)))


Measured memory_bytes: 17408
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b;





    c=abs(a-b);
    if(c>1)
        {
    printf(":(");
        }
    else
    {
         printf("Yay!");
    }
}



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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n,a,b;cin>>n>>a>>b;
  string s;cin>>s;
  rep(i,0,n){
    if(s[i]=='a'){
      ans1(a+b>0);
      //if(a+b>0)res++;
      a--;
    }
    else if(s[i]=='b'){
      ans1(a+b>0&&b>0);
      if(b>0)b--;
    }
    else cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 876
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import java.util.Set;


public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();

		List<Set> list = new ArrayList<>();

		for(int i = 0; i < n+1; i++) {
			Set<Integer> adj = new HashSet<>();
			list.add(adj);
		}

		for(int i = 0; i < m; i++) {
			int a = scan.nextInt();
			int b = scan.nextInt();

			Set<Integer> tmpa = list.get(a);
			tmpa.add(b);
			list.set(a, tmpa);

			Set<Integer> tmpb = list.get(b);
			tmpb.add(a);
			list.set(b, tmpb);
		}

		int[] dist = new int[n+1];
		dist[0] = 0;
		int[] ans = new int[n+1];

		Set<Integer> endcheck = new HashSet<>();
		endcheck.add(1);
		Set<Integer> start = new HashSet<>();
		start.add(1);

		do {
			Set<Integer> tmpst = new HashSet<>();

			Iterator<Integer> stit = start.iterator();
			while(stit.hasNext()) {
				int v1 = stit.next();

				int tdist = dist[v1] + 1;
				Set<Integer> adj = list.get(v1);
				Iterator<Integer> adjit = adj.iterator();
				while(adjit.hasNext()) {
					int v2 = adjit.next();
					if(!endcheck.contains(v2)) {
						tmpst.add(v2);

						if(dist[v2] < 1 || dist[v2] > tdist) {
							dist[v2] = tdist;
							ans[v2] = v1;
						}
					}

				}
			}

			start = tmpst;
			endcheck.addAll(tmpst);

		}while(endcheck.size() < n);

		System.out.println("Yes");
		for(int i = 2; i < n+1; i++) {
			System.out.println(ans[i]);
		}


	}

}



Measured memory_bytes: 104532
n = int(input())
a_list = list(map(int, input().split()))

sum_a = sum(a_list)
a_list_even_sum = 0
for i in range(len(a_list)):
    if i % 2 == 1:
        a_list_even_sum += a_list[i]

x1 = sum_a - 2 * a_list_even_sum
print (x1)
pre = x1
for i in range(2, n + 1):
    present = 2 * a_list[i-2] - pre
    print (present)
    pre = present

Measured memory_bytes: 14032
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)

//-----------------------------------------------

//------------------------------------------------
int main(){
  ll n,count;
  cin>>n;
  vector<ll> a(n+1);//a[0],b[0]は考えたくない
  vector<ll> b(n+1);//はいいてたら１、からなら０
  vector<ll> c(0);
  rep(i,1,n+1) {
    cin>>a.at(i);
}
    rrep(i,n,1){
      count=0;
      rep(k,2,n+1){
        if(i*k>n) break;
        if(b.at(i*k)==1) count+=1;
      }
      if(a.at(i)==count%2) b.at(i)=0;
      if(a.at(i)!=count%2) b.at(i)=1;
      if(b.at(i)==1) c.push_back(i);
    }
    cout<<c.size()<<endl;
    rep(i,0,c.size()) cout<<c.at(i)<<endl;
}


Measured memory_bytes: 4980
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = 2000000000;
// const ll MOD = 1000000007;

struct Pos {
  int h, w;
  int len;
};

int H, W;
char S[51][51];
int num_black;
int min_len;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
      if (S[i][j] == '#') {
        num_black++;
      }
    }
  }

  bool goal = false;
  queue<Pos> q;
  q.push(Pos{0, 0, 1});
  while (!q.empty()) {
    Pos p = q.front();
    q.pop();
    if (p.h == H - 1 && p.w == W - 1) {
      goal = true;
      min_len = p.len;
      break;
    }

    // up
    if (p.h - 1 >= 0 && S[p.h - 1][p.w] != '#') {
      S[p.h - 1][p.w] = '#';
      q.push(Pos{p.h - 1, p.w, p.len + 1});
    }
    // down
    if (p.h + 1 < H && S[p.h + 1][p.w] != '#') {
      S[p.h + 1][p.w] = '#';
      q.push(Pos{p.h + 1, p.w, p.len + 1});
    }
    // left
    if (p.w - 1 >= 0 && S[p.h][p.w - 1] != '#') {
      S[p.h][p.w - 1] = '#';
      q.push(Pos{p.h, p.w - 1, p.len + 1});
    }
    // right
    if (p.w + 1 < W && S[p.h][p.w + 1] != '#') {
      S[p.h][p.w + 1] = '#';
      q.push(Pos{p.h, p.w + 1, p.len + 1});
    }
  }

  if (goal) {
    cout << H * W - num_black - min_len << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a; i<=b; ++i)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using vl=vector<ll>;
using vp=vector<pll>;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,d;
    cin>>n>>d;
    ll cnt=0;
    FOR(i,1,n){
        ll x,y;
        cin>>x>>y;
        if(d*d>=x*x+y*y) ++cnt;
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 3652
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

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

		ArrayList<Double> list = new ArrayList<Double>();

		while (sc.hasNext()) {
			list.add(sc.nextDouble());
		}

		Collections.sort(list);

		System.out.println((list.get(0) - list.get(list.size() - 1)) * -1);

	}

}

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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
    };
} init;

int A, B, C, D;
int f(int x) {
    return x - x / C - x / D + x / (C * D / gcd(C, D));
}
signed main() {
    cin >> A >> B >> C >> D;
    cout << f(B) - f(A - 1) << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort()
a.reverse()
j=[];x=-2
for i in range(n-1):
  if a[i]==a[i+1] and x!=i:
    j.append(a[i])
    x=i+1
  if len(j)>=2:
    break
j.append(0)
j.append(0)
print(j[0]*j[1])

Measured memory_bytes: 14252
#ifdef loc
    #include "../codes/loc_debug.h"
#else
    #include <bits/stdc++.h>
    #define pr(...)
    #define pra(a,n)
    #define praa(a,n,m)
    #define prl()
#endif
using namespace std;

typedef long long ll;
#define sz(a) int(a.size())
const int N = 100005;

int mod = 998244353;
int po(int x, int y) {
    int ret = 1;
    while(y > 0) {
        if(y & 1) {
            ret = (ret * (ll)x) % mod;
        }
        x  = (x * (ll)x) % mod;
        y /= 2;
    }
    return ret;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int tot = 1;
    for(int i = 1; i <= n; i++) {
        tot = (tot * (ll)3) % mod;
    }
    int cur = 1;
    tot -= 2;
    for(int i = 1; i < n / 2; i++) {
        cur = (cur * (ll)2) % mod;
        cur = (cur * (ll)(n - i + 1)) % mod;
        cur = (cur * (ll)po(i, mod - 2)) % mod;
        tot -= cur;
        if(tot < 0) {
            tot += mod;
        }
        tot -= cur;
        if(tot < 0) {
            tot += mod;
        }
    }
    cout << tot << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n;
	cin >> n;
	cout << n * (n - 1) / 2 << endl;
}

Measured memory_bytes: 256
/*
 * author :Sadik Hassan(_sad_)
 *
*/
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include "bits/stdc++.h"
using namespace std;
using   ll =          long long;
using   ld =          long double;
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define MP            make_pair
#define PI            (acos(-1.0))
#define rep1(i,n)     for(int i=1;i<=n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         (int)s.size()
#define all(x)        (x).begin(), (x).end()
#define rall(x)       (x).rbegin(), (x).rend()
#define w(t)          int t;cin>>t;while(t--)
#define TSU(s)        transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSL(s)        transform(s.begin(),s.end(),s.begin(),::tolower);
#define _SAD()     	  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(3);

typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = (int)2e5+5;
const ll MOD =(ll)1e9+7;
const ll INF = (ll)1e18+5;
const int nn=1e5+5;

int main()
{
    _SAD()
    string s,k;
    cin>>s>>k;
    int cnt=1e5,n=SZ(s)-SZ(k);
    for(int i=0;i<=n;i++)
    {
        int sap=0,p=0;
        for(int j=i;j<SZ(k)+i;j++)
        {
            if(s[j]!=k[p])
            {
                sap++;
            }
            p++;
        }
        cnt=min(sap,cnt);
    }
    cout<<cnt<<nl;
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define mp make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define LLINF (1<<60)
#define MOD 1000000007
#define rep(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

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

    int a, b, k;
    cin >> a >> b >> k;
    for (int count = 0; count < k; count++) {
        if (count % 2 == 0) {
            if (a % 2 == 1) {
                a -= 1;
                int t = a / 2;
                a -= t;
                b += t;
            }
            else {
                int t = a / 2;
                a -= t;
                b += t;
            }
        }
        else {
            if (b % 2 == 1) {
                b -= 1;
                int t = b / 2;
                b -= t;
                a += t;
            }
            else {
                int t = b / 2;
                b -= t;
                a += t;
            }
        }
    }
    cout << a << ' ' << b << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
using vi = vector <int>;
using vvi = vector <vi>;

class unionFindTree{
	private:
		vector <int> tree;
		vector <int> rank;

	public:
		unionFindTree(int sz){
			tree = vector <int> (sz);
			rank = vector <int> (sz, 0);
			for(int i = 0; i < tree.size(); i++)
				tree[i] = i;
		}

		int root(int x){
			return tree[x] == x ? x : tree[x] = root(tree[x]);
		}

		bool same(int a, int b){
			return root(a) == root(b);
		}

		void unite(int a, int b){
			a = root(a);
			b = root(b);
			if(a == b)return;

			if(rank[a] < rank[b]) swap(a, b);

			tree[b] = a;
			rank[a] += rank[a] == rank[b];
		}
};


signed main(){
	int n, q;
	cin >> n >> q;
	unionFindTree uft(n);
	rep(i, q){
		int p, a, b;
		cin >> p >> a >> b;
		if(!p)
			uft.unite(a, b);
		else
			cout << uft.same(a, b) << endl;

	}
}

Measured memory_bytes: 3256
#include<stdio.h>
#define NMAX 200200
int main(void){
	int from[2*NMAX],to[2*NMAX];
	int uf[2*NMAX],size[2*NMAX];
	int n,m;
	int i,j,k;
	int h,flg,tmp;
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d%d",&from[i],&to[i]);
	}
	for(i=0;i<=n;i++){
		uf[i]=i;
		size[i]=1;
	}
	for(i=0;i<m;i++){
		j=from[i]-1;
		k=to[i]-1;
		while(j!=uf[j]) j=(uf[j]=uf[uf[j]]);
		while(k!=uf[k]) k=(uf[k]=uf[uf[k]]);
		
		if(j!=k){
			if(size[j]<size[k]){
				uf[j]=k;
			}else{
				uf[k]=j;
				if(size[j]==size[k]) size[j]++;
			}
		}
	}
	k=0;
	for(i=0;i<n;i++){
		j=i;
		while(j!=uf[j]) j=(uf[j]=uf[uf[j]]);
		if(j==i) k++;
	}
		
	printf("%d\n",k-1);
	return 0;
}


Measured memory_bytes: 3272
// copied by Nurstan Duisengaliev
// skatal
#include <bits/stdc++.h>
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) x.size()
 
using namespace std;
 
const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
vector <int> g[N];
int dp[N];
bool used[N];
int ans = 0;
void dfs (int v) {
	used[v] = 1;
	for (auto to : g[v]) {
		if (used[to] == 0) {
			dfs (to);
			dp[v] = max (dp[to] + 1, dp[v]);
			ans = max (ans, dp[v]);
			
		}
		else {
			dp[v] = max (dp[to] + 1, dp[v]);	
			ans = max (ans, dp[v]);
		}
	}
}
void solve () {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= m; i ++) {
		int l, r;
		cin >> l >> r;
		g[l].pb (r);
	}
	for (int i = 1; i <= n; i ++) {
		if (used[i] == 0) {
			dfs (i);
		}
	}
	cout << ans;
}
 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//	cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	
}

Measured memory_bytes: 10624
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int d = stdIn.nextInt();
		int x = stdIn.nextInt();
		int num = 0;
		int ans;
		int [] an = new int[n];
		for(int i = 0; i < n; i++){
			an[i] = stdIn.nextInt();
		}
		for(int i = 0; i < n; i++){
			for(int j = 0; j*an[i]+1 <= d; j++)
				num++;
		}
		ans = num + x;
		System.out.println(ans);
	}
}

Measured memory_bytes: 21076
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

int main(){
  int a;
  cin >> a;
  cout << a + a*a + a*a*a << endl;

  return 0;
}



Measured memory_bytes: 3196
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;


int main(void) {
	int n;
	cin >> n;
	vector<long long> a(n);
	map<int,int> count;
	for(int i=0; i<n; i++){
		cin >> a[i];
		count[a[i]]++;
	}
	long long ans=0;
	sort(a.begin(),a.end());
	for(int i=0; i<n; i++){
      	if(i!=0 && a[i]==a[i-1])continue;
		if(count[a[i]]>0){
			ans+=(count[a[i]]>=a[i]?count[a[i]]-a[i]:count[a[i]]);
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main()
{
    int N, M, ans;
    cin >> N >> M;
    ans = N;
    for(int i=1; i<=M; i++){
        int A;  cin >> A;
        ans = ans - A;
    }
    if(ans >= 0)
        cout << ans;
    else
        cout << -1;
}

Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        String s = ns();
        int numr = 0;
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i)=='R') numr++;
        }
        int ans = 0;
        for (int i = 0; i < numr; i++) {
            if(s.charAt(i)=='W') ans ++;
        }
        out.println(ans);
    }

    final int mod = 1000000007;
    final BigInteger MOD = BigInteger.valueOf(mod);
    int mul(int x, int y){
        int val = (int)((x * 1L * y) % mod);
        return val>=0 ? val : val+mod;
    }
    int add(int x, int y) {
        x += y;
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 36636
import heapq

N,M=map(int,input().split())
jobs=[[] for i in range(M)]

for i in range(N):
  a,b=map(int,input().split())
  if a>M:
    continue
  else:
    jobs[M-a].append(b)
ans=0
l=[]
for i in range(M-1,-1,-1):
  for j in jobs[i]:
    heapq.heappush(l,-j)
  if len(l):
    ans+=-heapq.heappop(l)
print(ans)

Measured memory_bytes: 18468
#include<bits/stdc++.h>
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mem(ara,n) memset(ara,n,sizeof ara)
#define loop(i,j,n) for(i=j;i<n;i++)
#define rloop(i,j,n) for(i=n;i>=j;i--)
#define INF 2147483647
#define ll long long
#define pii pair<int,int>
#define eps 1e-9
#define mii map<int,int>
#define vi vector<int>
#define all(n) n.begin(),n.end()
#define inf INF
#define INFLL 9223372036854775807
using namespace std;
int main()
{
    int n,m,cnt=0,i,j,k,tc,t;
    int a[100005],b[100005],p[100005],c[100005]={0};
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>p[i];
        a[i]=i;
        b[i]=n-i+1;
        //cout<<a[i]<<endl;
    }
    int x,y;
    int last=a[p[1]]+b[p[1]];
    for(i=2;i<=n;i++)
    {
        x=a[p[i]]+b[p[i]];
        if(last>=x)
        {
            y=last-x+1;//cout<<last<<" "<<x<<" "<<p[i]<<endl;
            for(j=p[i];j<=n;j++)a[j]+=y;
            for(j=p[i];j>0;j--)b[j]+=y;

        }
        last=a[p[i]]+b[p[i]];
    }
    for(i=1;i<=n;i++)cout<<a[i]<<" ";cout<<endl;
    for(i=1;i<=n;i++)cout<<b[i]<<" ";cout<<endl;
    //for(i=1;i<=n;i++)cout<<a[p[i]]+b[p[i]]<<" ";

}


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

using namespace std;

#define LL long long
#define N 300
#define INF 0x3f3f3f3f3f3f3f3fLL
#define B 233

const LL mod=1000000007;
LL n,p,mx,ans,a[N],c[N];
map<LL,vector< pair<LL,LL> > > mp;
struct node{LL b,c,i;}b[N];

bool cmp(node x,node y){return x.b<y.b;}

LL popcount(LL x,LL y){
	if (x>=y) return INF;
	LL ret=0;
	for (LL i=60;i>=0;i--)
		if (((x>>i)&1)!=((y>>i)&1)){
			ret++;
			return ret;
		}
		else ret+=(x>>i)&1;
	return INF;
}

int main(){
	scanf("%lld%lld",&n,&p);
	for (LL i=1;i<=n;i++) scanf("%lld",&a[i]);
	for (LL i=0;i<=60;i++){
		memset(b,0,sizeof b);
		for (LL j=1;j<=n;j++) b[j].b=a[j]%(1LL<<i),b[j].c=a[j]/(1LL<<i),b[j].i=j;
		sort(b+1,b+n+1,cmp);
		for (LL j=0;j<=n;j++){
			LL k=((j==0)?0:popcount(b[j].b,b[j+1].b)),hsh=0;
			LL mn=p-k-i; bool fl=0;
			b[j].c--;
			if(j!=0&&b[j].c<0) break;
			for (LL k=1;k<=n;k++){
				if (b[k].c<0){fl=1; break;}
				mn=min(mn,b[k].c);
			}
			if (mn<0 || fl) continue;
			for (LL k=1;k<=n;k++) c[b[k].i]=b[k].c;
			for (LL k=2;k<=n;k++) hsh=((hsh*B+(c[k]-c[k-1]))%mod+mod)%mod;
			sort(c+1,c+1+n);c[1]=c[n];
			mp[hsh].push_back(make_pair(max(c[1]-mn,0ll),c[1]));
		}
	}
	for (map<LL,vector< pair<LL,LL> > >::iterator i=mp.begin();i!=mp.end();i++){
		vector< pair<LL,LL> > &vec=i->second;// puts("-----");
		sort(vec.begin(),vec.end()); mx=0;
		for (LL j=0;j<(LL)vec.size();j++){
			if (mx<=vec[j].second){ans=(ans+vec[j].second-max(vec[j].first,mx)+1)%mod; mx=vec[j].second+1;}
		}
	}
	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
const long long INF = 1LL << 60;

int main() {
  int X; cin>>X;
  bool owari=0;
  for(int i=-120; i<=120; i++){
    for(int j=-120; j<=120; j++){
      long long A=pow(i, 5);
      long long B=pow(j, 5);
      if(A-B==X){
        cout<<i<<" "<<j<<endl;
        owari=1;
        break;
      }
    }
    if(owari) break;
  }
}


Measured memory_bytes: 3996
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
using Point = complex<double>;

#define X real()
#define Y imag()
double dot(Point a, Point b) {
    return (a.X * b.X + a.Y * b.Y);
}
using Line = pair<Point, Point>;
Point Projection(Line s, Point p) {
    Point vase = s.second - s.first;
    p -= s.first;
    return s.first + dot(p, vase) / norm(vase) * vase;
}
Point Reflection(Line s, Point p) {
    return p + (Projection(s, p) - p) * 2.0;
}
double cross(Point a, Point b) {
    return a.X * b.Y - a.Y * b.X;
}
int ccw(Point a, Point b, Point c) {
    if (cross(b - a, c - a) > EPS)return 1;
    if (cross(b - a, c - a) < -EPS)return -1;
    if (dot(b - a, c - a) < -EPS)return 2;
    if (abs(b - a) + EPS < abs(c - a))return -2;
    return 0;
}
bool isOrthogonal(Line a, Line b) {
    return dot(a.second - a.first, b.second - b.first) ? 0 : 1;
}
bool isParallel(Line a, Line b) {
    return cross(a.second - a.first, b.second - b.first) ? 0 : 1;
}
bool isCross(Line a, Line b) {
    if (ccw(a.first, a.second, b.first) * ccw(a.first, a.second, b.second)<=0 and
        ccw(b.first, b.second, a.first) * ccw(b.first, b.second, a.second)<=0) {
        return true;
    }
    return false;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Point p1, p2, p3, p4;
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        double x1, x2, y1, y2, x3, x4, y3, y4;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        p1 = Point(x1, y1);
        p2 = Point(x2, y2);
        p3 = Point(x3, y3);
        p4 = Point(x4, y4);
        Line l1 = Line(p1, p2), l2 = Line(p3, p4);
        if (isCross(l1, l2))cout << 1 << endl;
        else cout << 0 << endl;
    }
    return 0;

}


Measured memory_bytes: 3360
fun main(args: Array<String>) {
    val (H, W, K) = listOfInt()
    val MOD = 1000000007
    val dp = Array(H + 1) { IntArray(W) }
    dp[0][0] = 1
    for (i in 0 until H) {
        for (j in 0 until W) {
            for (k in 0 until (1 shl (W - 1))) {
                var ok = true
                for (l in 0 until W - 2) {
                    if ((k shr l) and 1 == 1 && (k shr (l + 1)) and 1 == 1) {
                        ok = false
                    }
                }
                if (ok) {
                    if (j >= 1 && (k shr (j - 1)) and 1 == 1) {
                        dp[i + 1][j - 1] += dp[i][j]
                        dp[i + 1][j - 1] %= MOD
                    } else if (j <= W - 2 && (k shr j) and 1 == 1) {
                        dp[i + 1][j + 1] += dp[i][j]
                        dp[i + 1][j + 1] %= MOD
                    } else {
                        dp[i + 1][j] += dp[i][j]
                        dp[i + 1][j] %= MOD
                    }
                }
            }
        }
    }
    println(dp[H][K - 1])
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 38880
#include<bits/stdc++.h>
using namespace std;
#define int            int64_t
#define double         long double
#define nitro          ios_base::sync_with_stdio(false);cin.tie(0);
#define vi             vector<int64_t>
#define vpii           vector<pair<int,int>>
#define si             set<int>
#define pub            push_back
#define puf            push_front
#define pob            pop_back
#define pof            pop_front
#define PI             3.1415926535897932384626433832795
#define read(a)        for(auto& x : a) cin>> x
#define endl           '\n'
#define gap            ' '
#define min3(a,b,c)    min(a, min(b, c))
#define max3(a,b,c)    max(a, max(b, c))
#define MOD            1000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main()
{
    nitro
    int n,k;cin>>n>>k;
    vpii a(n);
    for(auto&x:a) cin>>x.first>>x.second;
    sort(a.begin(),a.end());
    for(int i=1;i<n;++i) a[i].second+=a[i-1].second;
    for(auto x:a) if(x.second>=k) return cout<<x.first,0;
}
    


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

struct arrow{
  long s;
  long e;
};

vector<arrow> a;
long N;
long M;
long s, e;
long n_cut = 0, pos_cut = 0;

void load_vars(){
  cin >> N >> M;
  for (int i = 0; i < M; i++){
    cin >> s >> e;
    a.push_back(arrow{s,e});
  }
}

void sort_arrow(){
  sort(a.begin(), a.end(), 
       [](const arrow& x, const arrow& y){
         return x.e < y.e;
       }
       );
//  sort(fruits.begin(), fruits.end(), 
//     [](const fruit& x, const fruit& y) { return x.name < y.name;});
}

int main() {
  load_vars();
  sort_arrow();
  
  for(int i = 0; i < M; i++){
    if (a[i].s >= pos_cut){
      pos_cut = a[i].e;
      n_cut ++;
      //cout << pos_cut << " " << n_cut << endl;
    }
  }
/*  cout << a[0].s << " " << a[0].e << endl;
  cout << a[1].s << " " << a[1].e << endl;
  cout << a[2].s << " " << a[2].e << endl;
  cout << a[3].s << " " << a[3].e << endl;
  cout << a.begin() << " " << a.end() << endl;
*/
  cout << n_cut << endl;
}

Measured memory_bytes: 2420
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

int main(){
  int n;
  cin >> n;
  int a,b,c;
  a=n/100;
  b=(n/10)%10;
  c=n%10;
  if(a==7||b==7||c==7) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3568
#include<iostream>

using namespace std;

int bekijou(int);

int main(){

  int in,data[10];

  while(cin >> in){

    for(int i = 0; i < 10; i++) data[i] = 0;

    for(int i = 0;i < 10; i++){
      data[i] = in % 2;
      in /= 2;
    }
    int out = 0;

    for(int i = 0; i < 10; i++){
      if(data[i] == 1 && out == 0){
	cout << bekijou(i);
	out++;
      }else if(data[i] == 1){
	cout << " " << bekijou(i);
      }
    }
    cout << endl;
  }
  return 0;
}
  
int bekijou(int n){
  int ret = 1;

  for(int i = 0; i < n; i++){
    ret *= 2;
  }

  return ret;
}

Measured memory_bytes: 0
N, M = map(int, input().split())
H = list(map(int, input().split()))
L = [1 for _ in range(N)]

for i in range(M):
    A,B = map(int,input().split())
    ma = H[A-1]
    mb = H[B-1]
    if (ma > mb):
        L[B-1] = 0
    elif (ma == mb):
        L[B-1] = 0
        L[A-1] = 0
    else:
        L[A-1] = 0
print(sum(L))

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

#define rep(i,a,b)      for(int i=a;i<=b;i++)
#define revp(i,a,b)     for(int i=b;i>=a;i--)

int a,b;
int main()
{
   

    cin>>a>>b;
    if(b==1)
        cout<<0;
    else if(a==2)
        cout<<b-1;
    else if(b<=a)
        cout<<1;
    else if(b%(a-1)==0 || b%(a-1)==1)
        cout<<b/(a-1);
    else 
        cout<<b/(a-1)+1;
}




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

int cost[10][10];
string dp[1 << 10][10];

void chmin(string &a, string b)
{
	if (a.size() > b.size()) a = b;
	else if (a.size() == b.size() && a > b) a = b;
}

int main()
{
	int n;
	while (cin >> n, n){
		vector<string> s(n);
		for (int i = 0; i < n; i++) cin >> s[i];
		for (int i = 0; i < s.size(); i++){
			bool f = false;
			for (int j = 0; j < s.size(); j++){
				if (i == j) continue;
				if (s[j].find(s[i]) != string::npos) f = true;
			}
			if (f){
				swap(s[i--], s.back());
				s.pop_back();
			}
		}
		for (int i = 0; i < s.size(); i++){
			for (int j = 0; j < s.size(); j++){
				if (i == j) continue;
				cost[i][j] = s[j].size();
				for (int k = 0; k <= min(s[i].size(), s[j].size()); k++){
					string ss = string(s[i], s[i].size() - k, k);
					string tt = string(s[j], 0, k);
					if (ss == tt) cost[i][j] = s[j].size() - k;
				}
			}
		}
		fill_n(*dp, 10 * (1 << 10), string(128, 'z'));
		for (int i = 0; i < s.size(); i++){
			dp[1 << i][i] = s[i];
		}
		for (int i = 0; i < (1 << s.size()); i++){
			for (int j = 0; j < s.size(); j++){
				for (int k = 0; k < s.size(); k++){
					if (~i & (1 << j)) continue;
					if (i & (1 << k)) continue;
					string t = string(s[k], s[k].size() - cost[j][k], cost[j][k]);
					chmin(dp[i | (1 << k)][k], dp[i][j] + t);
				}
			}
		}
		string res = string(128, 'z');
		for (int i = 0; i < s.size(); i++){
			chmin(res, dp[(1 << s.size()) - 1][i]);
		}
		cout << res << endl;
	}
}

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

int main()
{
    int n = 0, i = 0, j = 0, x = 0, y = 0;
    cin >> n;
    for(i = 1; i <= n; i += 2)
    {
        for(j = 1; j <= n; j++)
        {
            if(i % j == 0)
            {
                x++;
            }
            if(j > i)
            {
                break;
            }
        }
        if(x == 8)
        {
            y++;
        }
        x = 0;
    }

    cout << y;


return 0;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

ll w , h , x , y;

int main()
{
    _FastIO;
    cout.precision(9);
    cin >> w >> h >> x >> y;
    long double ans = 1.0 * (w * h) * 1.0 / 2.0 * 1.0;
    cout << fixed << ans;
    cout << " ";
    x *= 2;
    y *= 2;
    if(x == w && h == y){
        cout << "1" << endl;
    }
    else
        cout << "0" << endl;
    return 0;
}


Measured memory_bytes: 256
import fractions

a,b,c,d = map(int, input().split())
x = (b//c - (a - 1)//c)
y = (b//d - (a - 1)//d)
z = (b//((c * d)//fractions.gcd(c,d)) - (a - 1)//((c * d)//fractions.gcd(c,d)))

print(int((b - a + 1) - (x + y - z)))


Measured memory_bytes: 5048
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

while True:
    n,x = LI()
    cnt = 0
    if n == x == 0:
        break
    for b in range(2,n):
        for a in range(1,b):
            for c in range(b+1,n+1):
                if a+b+c == x:
                    cnt += 1
    print(cnt)


Measured memory_bytes: 5604
n,x = (int(i) for i in input().split())
y = [int(i) for i in input().split()]
ans = abs(y[0]-x)
def gcd(a,b):
	if a%b==0: return b
	else: return gcd(b,a%b)
for i in range(1,n): ans = gcd(ans,abs(x-y[i]))
print(ans)

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

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<ll> a(n);
	ll ans=1;
	for(int i=0;i<n;i++){
		cin >> a[i];
		if(i){
			if(a[i]<=a[i-1])ans++;
		}
	}
	cout << ans << endl;
	cout << n << endl;
}


Measured memory_bytes: 3588
import itertools
n, m, x = map(int, input().split())
list_CA = [ list(map(int,input().split(" "))) for i in range(n)]
l = [i for i in range(1, n+1)]
ans = pow(10, 9)
for i in range(1, n+1):
    k = list(itertools.combinations(l, i))
    for j in range(len(k)):
        h = [0]*m
        cnt = 0
        for q in k[j]:
            for g in range(m):
                h[g] += list_CA[q-1][g+1]
            cnt += list_CA[q-1][0]
        c = 0
        for v in h:
            if v >= x:
                c += 1
        if c == m:
            ans = min(cnt, ans)

if ans == pow(10, 9):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9352
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, q;
string s;
vector<i64> as, ms, cs;
int main() {
  cin >> n >> s;
  init_n(as, n + 1);
  init_n(ms, n + 1);
  init_n(cs, n + 1);
  for (i64 i = 1; i <= n; ++i) {
    char c = s[i - 1];
    ms[i] = ms[i - 1] + (c == 'M');
    cs[i] = cs[i - 1] + (c == 'C');
    as[i] = as[i - 1] + (c == 'C') * ms[i - 1];
  }
  cin >> q;
  while (q--) {
    i64 k;
    cin >> k;
    i64 ans = 0;
    for (i64 i = 1; i <= n; ++i) {
      if (s[i - 1] == 'D') {
        i64 r = min(i + k - 1, n);
        ans += as[r] - as[i - 1] - (cs[r] - cs[i - 1]) * ms[i - 1];
      }
    }
    cout << ans << '\n';
  }
  return 0;
}


Measured memory_bytes: 26884
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)

	allFactors := make(map[int]int)

	for i := 2; i <= n; i++ {
		factors := pf(i)

		for k, v := range factors {
			_, ok := allFactors[k]
			if ok {
				allFactors[k] += v
			} else {
				allFactors[k] = v
			}
		}
	}

	c2, c4, c14, c24, c74 := countNum(allFactors)

	ans := c4*
		(c4-1)*
		(c2-2)/2 +
		c24*(c2-1) +
		c14*(c4-1) +
		c74

	fmt.Println(ans)
}

func countNum(factors map[int]int) (c2, c4, c14, c24, c74 int) {
	for _, v := range factors {
		if v >= 2 {
			c2++
		}
		if v >= 4 {
			c4++
		}
		if v >= 14 {
			c14++
		}
		if v >= 24 {
			c24++
		}
		if v >= 74 {
			c74++
		}
	}

	return
}

func pf(num int) map[int]int {
	if num == 1 {
		return make(map[int]int)
	}

	ret := make(map[int]int)
	maxPrime := num
	for num%2 == 0 {
		ret[2]++
		num /= 2
	}

	for i := 3; i*i <= maxPrime; i = i + 2 {
		if num == 1 {
			break
		}

		for num%i == 0 {
			_, ok := ret[i]
			if ok {
				ret[i]++
			} else {
				ret[i] = 1
			}
			num /= i
		}
	}

	if num > 2 {
		_, ok := ret[num]
		if ok {
			ret[num]++
		} else {
			ret[num] = 1
		}
	}

	return ret
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back 
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
#define Uniq(v) v.erase(unique(All(v)),v.end())
typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
typedef pair<string, int> Psi;
const int INF = (1<<30);
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

int main()
{
  ll N;
  ll nt, na;
  ll T, A;

  cin >> N;
  cin >> T >> A;
  nt = T; na = A;

  Rep(i, N-1) {
    cin >> T >> A;
    ll bai = 1;
    if( nt % T == 0 ) bai = max(bai, nt / T);
    else bai = max(bai, nt / T + 1);
    if( na % A == 0 ) bai = max(bai, na / A);
    else bai = max(bai, na / A + 1);
    nt = T * bai; na = A * bai;
  }

  cout << nt + na << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{

  int X;
  int uresisa = 0;

  scanf("%d", &X);

  while(X>5) {
    if ( X >= 500 ) {
      X-=500;
      uresisa+=1000;
    } else if ( X >= 5 ) {
      X-=5;
      uresisa+=5;
    }
  }

  printf("%d\n", uresisa);

  return 0;
}


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

int main() {
	string s;
	cin >> s;
	char c = s.at(0);
	ll ans = 1;
	for (int i = 1; i < s.length(); i++) {
		if (c == s.at(i))continue;
		else {
			c = s.at(i);
			ans++;
		}
	}
	cout << ans -1  << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
const int M=2e5+10;
#define pb push_back

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,m,fr[M],to[M],nxt[M],tt,s,t,id[N],h[N];
bool vis[N][N],can[M];
vector<int> E[N];

void adde(int u,int v) {
	fr[++tt]=u,to[tt]=v,nxt[tt]=h[u],h[u]=tt;
	E[u].push_back(v);
}

void dfs(int u) {
	vis[s][u]=1;
	if(id[u]) return;
	id[u]=t;
	for(auto v:E[u]) if(!id[v]&&v!=s) dfs(v);
}

int main() {
	cin>>n>>m;
	for(int i=1,u,v;i<=m;i++) u=gi(),v=gi(),adde(u,v);
	for(s=1;s<=n;s++) {
		memset(id,0,sizeof(id));
		vector<int> son;
		for(int i=h[s],v;v=to[i],i;i=nxt[i])
			son.push_back(v),dfs(t=v);
		reverse(son.begin(),son.end());
		for(int i=h[s],v;v=to[i],i;i=nxt[i])
			if(id[v]!=v) can[i]=1;
		memset(id,0,sizeof(id));
		for(auto v:son) dfs(t=v);
		for(int i=h[s],v;v=to[i],i;i=nxt[i])
			if(id[v]!=v) can[i]=1;
	}
	for(int i=1;i<=m;i++) {
		int u=fr[i],v=to[i];
		if((can[i])==(vis[v][u])) cout<<"same\n";
		else cout<<"diff\n";
	}
	return 0;
}


Measured memory_bytes: 6272
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 200100;
signed main(){
    int n;
    cin>>n;
    vector<int> p(n);
    for(int i=0;i<n;i++)cin>>p[i];
    int res[d5];
    for(int i=0;i<d5;i++)res[i]=0;
    unordered_map<int,int> D;
    for(int i=0;i<n;i++){
        if(D[p[i]-1]<i)res[p[i]]=res[p[i]-1]+1;
        else res[p[i]]=1;
    }
    int ans=0;
    for(int i=0;i<=n;i++)ans=max(ans,res[i]);
    cout<<n-ans<<endl;
}

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

#define rep(i, j, k) for(int i = (int) j; i < (int) k; ++i)
#define sz(x) ((int) (x).size())
#define ll long long
#define mp make_pair
#define pii pair<int, int >
#define fi first
#define se second
#define pb push_back
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define zero(x) memset((x), (0), sizeof (x))
#define zerox(x, y) memset((x), (y), sizeof (x))

using namespace std;

int main()
{
#ifdef PIT
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
#endif //PIT

	ios_base::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	int f = 0;
	while(n) {
		if(n % 10 == 9) f = 1;
		n /= 10;
	}
	if(f) cout << "Yes" << endl;
	else cout << "No" << endl;
	
#ifdef PIT
flush(cout);
cerr << endl << "Time: " << (clock() / double(CLOCKS_PER_SEC)) << endl;
#endif //PIT
	return 0;
}


Measured memory_bytes: 256
import itertools
A = int(input())
B = int(input())
C = int(input())
X = int(input())

a = list(range(0,A+1))
b = list(range(0,B+1))
c = list(range(0,C+1))

fifty = X/50
ans = 0

for i in itertools.product(a, b, c):
    if 10*i[0]+2*i[1]+i[2] == fifty:
        ans += 1

print(ans)

Measured memory_bytes: 3064