akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    int n; cin >> n;
    vector<char> c(n);
    rep(i,n) cin >> c[i];
    vector<int> sum(n+1,0); //左からi個目までに赤が何個あるか
    rep(i,n) {
        if (c[i]=='R') sum[i+1] = sum[i] + 1;
        else sum[i+1] = sum[i];
    }
    int ans = INF;
    rep(i,n+1) {
        int w = i-sum[i];
        int r = sum[n]-sum[i];
        chmin(ans,max(w,r));
    }
    cout << ans << endl;
}

Measured memory_bytes: 4320
/*
 * Matheus Oliveira
 * 09:04:56 26/04/2020
 * c.cpp
*/

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

#define EPS
#define INF
#define MAXN 15
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define sc(x) scanf("%d", &x);
#define sc2(x, y) scanf("%d %d", &x, &y);
#define sc3(x, y, z) scanf("%d %d %d", &x, &y, &z);
#define debug(x) printf("%s: %d\n", #x, x);
#define debugarr(x, bg, ed) printf("%s: ", #x); for(int i = bg; i < ed; i++) printf("%d%c", x[i], (i == ed-1) ? '\n' : ' ');

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

char inp[MAXN];
set<string> m;

int main() {
	int n;

	scanf("%d", &n);
	getchar();
	
	for(int i = 0; i < n; i++) {
		scanf("%s", inp);
		m.insert( string(inp) );
	}

	printf("%d\n", (int)m.size());
	return 0;
}

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m = M)
{
  int ret = n % m;
  if (ret < 0)
    ret += m;
  return ret;
}

int exp(int n, int k)
{
  if (k == 0)
    return 1;
  if (k == 1)
    return n;
  int ax = exp(n, k / 2);
  ax = mod(ax * ax);
  if (k % 2)
    ax = mod(ax * n);
  return ax;
}

int gcd(int a, int b)
{
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
//#define MULTIPLE_TEST_CASE
void solution()
{
  string s;
  cin >> s;
  if (s == "RRS")
    cout << 2 << endl;
  else if (s == "SRR")
    cout << 2 << endl;
  else if (s == "RRR")
    cout << 3 << endl;
  else if (s == "SSS")
    cout << 0 << endl;
  else
    cout << 1 << endl;
}

int32_t main()
{
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--)
    solution();
}


Measured memory_bytes: 3636
var lines = []; var result = 0;

var readline = require("readline");

var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.on('line', function (x) {
  lines.push(x);
});

rl.on('close', function () {
  var N = Number(lines.shift());
  var h = lines.shift().split(" ").map(value => Number(value));


  for (var i = 0; i < 100; i++) {
    var zero = true;

    for (var j = 0; j < N; j++) {

      if (h[j] === 0 && zero === false) { result++; zero = true; }
      if (h[j] === 1) { h[j]--; zero = false; }
      if (1 < h[j]) { h[j]--; zero = false }

    }
    if (0 <= h[N - 1] && zero === false) { result++; }
  }
  console.log(result);
});


Measured memory_bytes: 7628
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define debug(x) cout<<"### x is: "<<x<<"###"<<endl
#define all(a) a.begin(),a.end()
#define tc int t;scanf("%d",&t);while (t--0)
#define int long long
const int MOD=1e9+7;
const int N=1e5+5;
int power(int a, int b) {int ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=MOD) ret%=MOD;if(a>=MOD) a%=MOD;b>>=1;}return ret;}
int invmod(int x) {return power(x,MOD-2);}
int size[N];
int a[N];
void initialize()
{
    for(int i = 1;i<=100000;i++)
    {
        a[i] = i ;
        size[i]=1;
    }
}
int root(int i)
{
    while(a[i]!=i)
    {
        a[i]=a[a[i]]; 
        i=a[i]; 
    }
    return i;
}
void merge(int x,int y)
{
    int u=root(x);
    int v=root(y);
    if(size[u] < size[v])
    {
        swap(u,v);
    }
    a[v] = a[u];
    size[u]+=size[v];

}
int32_t main()
{
	initialize();
	int n,m;
	cin>>n>>m;
	int x,y,z;
	for(int i=1;i<=m;i++)
	{
		cin>>x>>y>>z;
		if(root(x)!=root(y))
		{
			merge(x,y);
		}
	}
	map<int,int>mp;
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		//cout<<root(i)<<endl;
		if(mp[root(i)]==0)
		{
			sum++;
		}
		mp[root(i)]++;
	}
	cout<<sum<<endl;
	




}

Measured memory_bytes: 9088
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
	vector<int> A(3);
	cin >> A[0] >> A[1] >> A[2];
	sort(A.begin(), A.end());
	if (A[0] != A[1] && A[1] == A[2]) {
		cout << A[0] << endl;
	}
	else {
		cout << A[2] << endl;
	}
}

Measured memory_bytes: 256
// ALLAH \\
whoishussain.org
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int t[N], n, k, c;
int main(){
   cin >> n >> c >> k;
for(int i = 0;i < n;i ++) cin >> t[i];
sort(t,t  + n );
int ans = 0, i = 0;
while( i < n ){
ans++;
int en = t[i] + k;
for(int j = 0;i < n && j < c && t[i] <= en; j++,i++);
}
cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<cctype>
#include<vector>
#include <ctype.h>
#include<algorithm>
#include<queue>
#include<string>
#include <math.h>
using namespace std;
int a,b,c,total=0;
vector<int> m, j;
int main() {
	cin >> a;
	for (size_t i = 0; i < a; i++)
	{
		cin >> b;
		m.push_back(b);
		total += b;
	}
	cin >> b;
	for (size_t i = 0; i <b; i++)
	{
		cin >> a>>c;
		cout << total + c - m[a-1] << endl;
	}
	return 0;
	}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
void display(int N, int* arr) {
    for(int i = 0; i < N-1; i++) cout << arr[i] << " ";
    cout << arr[N-1] << endl;
}
void selectionSort(int N, int* arr) {
    int cnt = 0;
    for(int i = 0; i < N-1; i++) {
        int p = N-1;
        for(int j = p; j >= i; j--) {
            if(arr[p] >= arr[j]) p = j;
        }
        if(p == i) continue;
        swap(arr[p], arr[i]);
        cnt++;
    }
    display(N, arr);
    cout << cnt << endl;
}
int main(void){
    int N; cin >> N;
    int arr[N];
    for(int i = 0; i < N; i++) cin >> arr[i];
    selectionSort(N, arr);
}


Measured memory_bytes: 3116
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
using namespace std;
int dfs(int n,int x,vector<int> k,vector<vector<int>> v,vector<int> &a,vector<int> &b,int &count);


int main(){
	int n;
	cin>>n;
	vector<vector<int> > v(n);
	vector<int> k(n);
	int x;
	rep(i,n){
		cin>>x;
		cin>>k[i];
		v[i].resize(k[i]);
		rep(j,k[i]){
			cin>>v[i][j];
			v[i][j]--;
		}
	}
	vector<int> a(n),b(n);
	int count=1;
	a[0]=1;
	dfs(n,0,k,v,a,b,count);

	rep(i,n){
		if(a[i]==0){
			count++;
			a[i]=count;
			dfs(n,i,k,v,a,b,count);
		}
	}


	rep(i,n){
		cout<<i+1<<" "<<a[i]<<" "<<b[i]<<endl;
	}

	return 0;
}
int dfs(int n,int x,vector<int> k,vector<vector<int>> v,vector<int> &a,vector<int> &b,int &count){
	/*if(k[x]==0){
		count++;
		a[x]=count;
	}*/
	rep(i,k[x]){
		if(a[v[x][i]]==0){
			count++;
			a[v[x][i]]=count;
			dfs(n,v[x][i],k,v,a,b,count);
		}
		if(i==k[x]-1){
			k[x]=0;
		}
	}
	if(k[x]==0){
		count++;
		b[x]=count;
	}
	return 0;
}

Measured memory_bytes: 3732
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

typedef long long ll;

using namespace std;

int mo[4]={0,1,0,-1};

int main(){
    int n,p[100]={0},a,b,c,d,count=0,max_n,rank;
    
    scanf("%d",&n);
    
    for(int i=0;i<n*(n-1)/2;i++){
        scanf("%d%d%d%d",&a,&b,&c,&d);
        
        if(c==d){
            p[a-1]++;
            p[b-1]++;
        }else if(c>d){
            p[a-1]+=3;
        }else{
            p[b-1]+=3;
        }
    }
    
    while(count!=n){
        max_n=0;
        rank=count+1;
        for(int i=0;i<n;i++)
            max_n=max(max_n,p[i]);
        
        for(int i=0;i<n;i++)
            if(max_n==p[i]){
                p[i]=-rank;
                count++;
            }
    }
    
    for(int i=0;i<n;i++)
        printf("%d\n",-1*p[i]);
    
    return 0;
}

Measured memory_bytes: 1188
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		
		// 入出力高速化 java.io.* とthrows IOExceptionを忘れずに
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine());
		String[] Ain = br.readLine().split(" ");
		
		long[] A = new long[N];
		A[0] = Integer.parseInt(Ain[0]);
		long sum = A[0];
		
		for(int a=1; a<N; a++) {
			long get = Integer.parseInt(Ain[a]);
			sum += get;
			A[a] = A[a-1]+get;
		}
		
		long ans = sum;
		for(int i=0; i<N; i++) {
			long check = Math.abs((sum-A[i])-A[i]);
			if(check<=ans) {
				ans = check;
			}
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 62664
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;

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

int Level[200005];
int Cnt[2];
int P[200005];
void Read(){
    cin >> N;
    for(int i = 1; i < N; i++){
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
}

void DFS(int node, int father){
    Level[node] = Level[father] + 1;
    Cnt[Level[node] & 1]++;
    for(int i = 0; i < G[node].size(); i++){
        int neighb = G[node][i];
        if(neighb == father)
            continue;
        DFS(neighb, node);
    }
}

void Solve(){
    int rem[] = {N / 3, N / 3, N / 3};
    if(N % 3 >= 1)
        ++rem[1];
    if(N % 3 == 2)
        ++rem[2];
    int Min = 0, Max = 1;
    if(Cnt[0] > Cnt[1])
        swap(Min, Max);
    int from[] = {3, 1, 2};
    if(Cnt[Min] >= rem[2] && Cnt[Max] >= rem[1]){
        for(int i = 1; i <= N; i++){
            if((Level[i] & 1) == Min)
                P[i] = from[2], from[2] += 3;
            else
                P[i] = from[1], from[1] += 3;
        }
        for(int i = 1; i <= N; i++){
            if(P[i] > N)
                P[i] = from[0], from[0] += 3;
        }
    }
    else{

        for(int i = 1; i <= N; i++){
            if((Level[i] & 1) == Min)
                P[i] = from[0], from[0] += 3;
            else
                P[i] = from[1], from[1] += 3;
        }
        for(int i = 1; i <= N; i++){
            //assert(from[2] <= N || P[i] % 3 != 0 || P[i] <= N);
            if(P[i] > N)
                P[i] = from[2], from[2] += 3;

        }
        for(int i = 1; i <= N; i++)
            if(P[i] > N)
                P[i] = from[0], from[0] += 3;
    }

    for(int i = 1; i <= N; i++){
        cout << P[i] << " ";

    }

    cout << '\n';
}
int main()
{
    Read();
    DFS(1, 0);
    Solve();
    return 0;
}


Measured memory_bytes: 19072
#include<bits/stdc++.h>
using namespace std;
struct edge {int u, v, w;};
vector<edge>G;
int L;
void add(int u, int v, int w) {G.push_back((edge) {u , v , w});}
int main() {
  cin >> L;
  int t = 1;
  for (int i = 0; i < 21; ++i) if (L & (1 << i)) t = i;
  for (int i = 1; i <= t - 1; i++) add(i, i+1, 1 << i-1), add(i, i+1, 0);
  add(t, 20, 0);
  add(t, 20, 1 << t-1);
  int g = 1 << t;
  while (g < L) {
    t = 1;
    while ((1 << t) <= L - g) ++t;
    --t;
    add(t+1, 20 , g);
    g |= 1 << t;
  }
  cout << "20 " << G.size() << endl;
  for (auto it = G.begin(); it != G.end(); ++it) cout << it->u << ' ' << it->v << ' ' << it->w << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INT long long
#define MOD 998244353
#define OO 99999998765432100
using namespace std;
string s;
INT n,a,b,c;
 
int main()
{
    ios::sync_with_stdio(false);
    cin>>a>>b>>c;
    if( a+b+c > 21 ) cout<<"bust\n";
    else cout<<"win\n";
}
 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
using namespace std;
string s;int len;
int main()
{
  cin>>s;len=s.size();
  for(int i=0;i<len-1;i++)
    if(s[i]==s[i+1]){printf("%d %d\n",i+1,i+2);return 0;}
  for(int i=0;i<len-2;i++)
    if(s[i]==s[i+2]){printf("%d %d\n",i+1,i+3);return 0;}
  printf("-1 -1\n");
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

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

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

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while(cin >> n){
        int ans = 0;
        int p = 0;
        REP(i, n) {
            int x;
            cin >> x;
            if (x == p) {
                ans ++; p = 0;
            } else {
                p = x;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int w = 0;
  int h = 0;
  int x = 0;
  int y = 0;
  int r = 0;

  scanf("%d", &w);
  scanf("%d", &h);
  scanf("%d", &x);
  scanf("%d", &y);
  scanf("%d", &r);

  if (((x + r) <= w) && ((x - r) >= 0) && ((y + r) <= h) &&(y - r) >= 0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  
  return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n,k;
  cin >> n >> k;
  vector<double> p(n);
  rep(i,n){
    cin >> p[i];
  }

  vector<double> e(n);
  rep(i,n){
    e[i] = (p[i]+1.)*p[i]/2/p[i];
  }
  vector<double> sum(n+1);
  sum[0] = 0.;
  rep(i,n){
    sum[i+1] = sum[i] + e[i];
  }

  double res = 0.;
  for(int i=0;i+k<=n;++i){
    res = max(res,sum[i+k]-sum[i]);
  }

  printf("%.7f\n", res);
  
  return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long n,k;
    cin>>n>>k;
    long long ans=min(n-k*(n/k),abs(n-k*((n+k)/k)));
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 	string number;
  	cin >> number;
   
  	if( (number[0]==number[1] && number[1]==number[2]) ||
      	(number[1]==number[2] && number[2]==number[3])){
      		cout << "Yes" << endl;
    }else{
     	cout << "No" << endl; 
    }
}


Measured memory_bytes: 256
let sum = List.fold_left (+) 0;;
let read_int_ln _ = read_line () |> int_of_string;;

let () =   
	let (n, m) = Scanf.sscanf(read_line()) "%d %d" (fun x y -> (x, y)) in
	let rec get_a a i = 
		if i = n then List.rev a
		else (
			let row = Str.split (Str.regexp " ") (read_line ()) 
					 |> List.map int_of_string 
			in get_a (row :: a) (i + 1)
		) in
	let rec get_b b j = 
		if j = m then List.rev b 
		else get_b (read_int_ln () :: b) (j + 1) in 
	let a_vec = get_a [] 0 in
	let b_vec = get_b [] 0 in
	let solve a_row = List.map2 ( * ) a_row b_vec |> sum |> Printf.printf "%d\n" in
	List.iter solve a_vec
;;


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

int main(){
    int l;
    while(cin >> l){
        string s;
        cin >> s;

        int ans = 0;

        for(int i = 0 ; i < l ; ++i){
            if(s[i] == 'W'){
                int j = i - 1;
                while(j >= 0 && s[j] == 'B'){
                    --j;
                }
                int k = j - 1;
                while(k >= 0 && s[k] == 'W'){
                    --k;
                }
                if((k == -1 || s[k] != 'B') && j >= 0){
                    ans = max(ans, i - j - 1);
                }
                j = i + 1;
                while(j < l && s[j] == 'B'){
                    ++j;
                }
                k = j + 1;
                while(k < l && s[k] == 'W'){
                    ++k;
                }
                if((k == l || s[k] != 'B') && j < l){
                    ans = max(ans, j - i - 1);
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3200
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long int ll;
int main()
{
	int n, a;
	long long int ans=0;
	scanf("%d", &n);
	int x[200001];
	for(int i=0; i<n; i++){
		scanf("%d", &a);
		x[a]=i;
	}
	set<int> st, st1;
	st.insert(-1);
	st.insert(n);
	st1.insert(1);
	st1.insert(-n);
	for(int i=1; i<=n; i++){
		auto itr=st.lower_bound(x[i]);
		int r1=*itr;
		itr=st1.upper_bound(-x[i]);
		int r2=-*itr;
		ans=ans+(ll)i*((ll)r1-(ll)x[i])*((ll)x[i]-(ll)r2);
		st.insert(x[i]);
		st1.insert(-x[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 19712
// #define _CRT_SECURE_NO_WARNINGS
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cassert>
#include <unordered_set>
#include <set>

#define prev asasddlsa
#define rank aljds

using namespace std;

typedef long long ll;

template<typename T>
void print(const vector<T>& s){
    for (auto x : s)
        cout << x << " ";
    cout << endl;
}

const int maxn = 307;

vector<pair<int, int>> s[maxn];
pair<int, int> dist[maxn][maxn];

void dickstra(int st, int n, int L){
    fill(dist[st], dist[st] + n, make_pair(n, 0));
    dist[st][st] = {0, -L};
    set<pair<pair<int, int>, int>> lst;
    for (int i = 0; i < n; i++)
        lst.insert({dist[st][i], i});
    while (lst.size() > 0){
        auto vv = *(lst.begin());
        lst.erase(vv);
        int v = vv.second;
        for (auto u : s[v]){
            pair<int, int> dd = {vv.first.first + 1, -L + u.second};
            if (vv.first.second + u.second <= 0)
                dd = {vv.first.first, vv.first.second + u.second};
            if (dist[st][u.first] > dd){
                lst.erase({dist[st][u.first], u.first});
                dist[st][u.first] = dd;
                lst.insert({dist[st][u.first], u.first});
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, L;
    cin >> n >> m >> L;
    for (int i = 0; i < m; i++){
        int a, b, c;
        cin >> a >> b >> c;
        if (c <= L){
            s[a - 1].push_back({b - 1, c});
            s[b - 1].push_back({a - 1, c});
        }
    }
    for (int i = 0; i < n; i++)
        dickstra(i, n, L);
    int q;
    cin >> q;
    while (q--){
        int st, fin;
        cin >> st >> fin;
        if (dist[st - 1][fin - 1].first != n)
            cout << dist[st - 1][fin - 1].first << "\n";
        else
            cout << -1 << "\n";
    }
    return 0;
}

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

int c[500001];

int main(){
  int n;
  cin>>n;
  int len=0,mx=0;
  while(n--){
    int x;
    cin>>x;
    mx=max(mx,x);
    if(x>5e5)x=5e5;
    if(!c[0]&&(len<x||(len==x&&mx<=x))){
      while(++c[x]==2)c[x--]=0;
      int llen=max(len,1);
      while(c[llen])llen++;
      len=llen-1;
      cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 5044
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

// 無限大を表す値
const long long INF = 1LL<<60;
const int MAX_N = 310;
// 頂点数，辺数
int N, M;
// dp 配列 (INF で初期化します)
vector<vector<long long> > dp(MAX_N, vector<long long>(MAX_N, INF));

void Warshall_Floyd_init(){
    for (int v = 0; v < MAX_N; ++v) dp[v][v] = 0;
    // dp 遷移 (Floyd--Warshall)
    for (int k = 0; k < N; ++k){
        for (int i = 0; i < N; ++i){
            for (int j = 0; j < N; ++j){
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }
}


int main() {
    cin >> N >> M;
    // dp 初期条件
    for (int e = 0; e < M; ++e) {
        int a, b;
        long long w;
        cin >> a >> b >> w;
        dp[a][b] = w;
    }
    
    Warshall_Floyd_init();

    // 結果出力
    // もし dp[v][v] < 0 なら負閉路あり
    bool exist_negative_cycle = false;
    for (int v = 0; v < N; ++v) if (dp[v][v] < 0) exist_negative_cycle = true;
    if (exist_negative_cycle) {
        cout << "NEGATIVE CYCLE" << endl;
    }
    else {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                if (j) cout << " ";
                if (dp[i][j] < INF/2) cout << dp[i][j];
                else cout << "INF";
            }
            cout << endl;
        }
    }                              
}




Measured memory_bytes: 3520
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  long long N=S.size();
  long long zero_even=0,zero_odd=0;
  for(int i=0;i<N;i++){
    if(i%2==0 && S.at(i)=='0'){
      zero_even++;
    }
    else if(i%2==1 && S.at(i)=='0'){
      zero_odd++;
    }
  }
  long long a_1,a_2;
  a_1=(N+1)/2-zero_even+zero_odd;//010...
  a_2=zero_even+N/2-zero_odd;//101...
  cout<<min(a_1,a_2)<<endl;
}


Measured memory_bytes: 3756
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.function.IntConsumer;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {

		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

			IntStream stream = br.lines()
					.mapToInt(Integer::parseInt);

			PrintWriter pw = new PrintWriter(System.out);
			stream.forEach(new IntConsumer() {
				private int i = 0;
				private boolean flg = false;

				@Override
				public void accept(int value) {
					if (value == 0 || flg) {
						flg = true;
						return;
					}
					pw.write(String.format("Case %d: %d", ++i, value));
					pw.write(System.lineSeparator());
				}
			});
			pw.flush();

		} catch (IOException e) {
		}

	}
}



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

int main() {
    int n;
    cin >> n;
    int a[201];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int count =0;
    while(true){
        bool all_even = true;
        for(int i=0;i<n;i++){
            if(a[i] % 2 != 0){
                all_even = false;
            }
        }
        if(all_even){
            for(int i=0;i<n;i++){
                a[i] = a[i] >> 1;
            }
            count++;
        }else{
            break;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import heapq
n,m = map(int,input().split())
a = [int(i) * (-1) for i in input().split()]

heapq.heapify(a)

for _ in range(m):
	a_min = heapq.heappop(a)
	heapq.heappush(a,(-(-a_min//2)))

print(-sum(a))



Measured memory_bytes: 14180
#include<bits/stdc++.h>
#include<vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MOD 1000000007
#define MAX 2000005
#define PMAX 55
#define PRECISION 0.00000000001
#define INF 2000000000
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
int tens[MAX];
int main()
{
    int k,i;
    tens[0]=1;
    scanf("%d",&k);
    for(i=1;i<MAX;i++)
    {
        tens[i]=(tens[i-1]*10)%k;
    }
    int rem=0;
    for(i=0;i<MAX;i++)
    {
        rem=(rem+tens[i]*7)%k;
        if(rem==0) break;
    }
    if(rem)
    {
        printf("-1");
    }
    else
    {
        printf("%d",i+1);
    }
    return 0;
}


Measured memory_bytes: 11632
#include<iostream>
using namespace std;
int main(){
    int a,s,d,k;
    cin>>a>>s>>d>>k;
    if(k<=a){
     cout<<k;
    }
    if(a<k and k<=a+s){
        cout<<a;
    }
    if(k>a+s){
        int x=k-(a+s);
        cout<<a-x;
    }
}

Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int n,m;
    cin >> n >> m;
    
    cerr << "test" << endl;
    
    cout << ( n-1 ) * ( m-1 ) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define LL long long
LL a,b,x,i,j,y;
LL f(LL a){
	return a*a*a*a*a;
}
int main(){
	scanf("%lld",&x);
	for(i=-1000;i<=1000;i++){
		y=f(i)+x;
		for(j=-1000;j<=1000;j++)
			if(f(j)==y){
				printf("%lld %lld\n",j,i);
				return 0;
			}
	}
	return 0;
}

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

int main(){
  long long a, b, n; cin >> a >> b >> n;
  long long cnt;
  if (n >= b) cnt = (a * (b - 1)) / b;
  if (n < b) cnt = (a * n) / b;
  cout << cnt << endl;
  return 0;
}

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

const int nm = 3e5;
int n, a, b[nm], s[nm], t, c, r;
string k;

int main() {
	cin >> n >> k;
	a = 0;
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		b[i]--;
	}
	if (k.size() <= 6) {
		int kInt = stoi(k);
		for (int i = 0; i < kInt; i++)
			a = b[a];
		cout << a + 1 << endl;
		return 0;
	}
	fill(s, s + n, -1);
	c = a;
	for (int i = 0;; i++, c = b[c])
		if (s[c] < 0)
			s[c] = i;
		else {
			r = -s[c];
			t = i - s[c];
			break;
		}
	for (int i = 0, b = 1; i < (int) k.size(); i++, b = b * 10 % t)
		r += (k[k.size() - 1 - i] - '0') * b;
	r %= t;
	if (r < 0)
		r += t;
	for (int i = 0; i < r; i++)
		c = b[c];
	cout << c + 1 << endl;

}



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

int main() {
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	string s;
	cin>>s;
	bool flag=false;
	for(int i=0;i<3;i++){
		if(s[i]=='7')
			flag=true;
			
	}
			
	if(flag)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	
	return 0;
	
}


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

int gcm(int a, int b)
{
  if (a > b)
  {
    int tmp = a;
    a = b;
    b = tmp;
  }

  for (int i = 1; ; ++i)
  {
    if (a % i == 0 and b % (a / i) == 0 )
    {
      return a / i;
    }
  }
}

int main(void)
{
  int a, b;
  while (cin >> a >> b)
  {
    cout << gcm(a, b) << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> a(n);
    set<int> st;
    for(int i=0;i<n;i++){
        int a;cin >> a;
        if(!st.count(a)){
            st.insert(a);
        }
        else{
            st.erase(a);
        }
    }
    cout << st.size() << endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;cin>>N>>M;
  vector<vector<char>>A(N,vector<char>(N));
  vector<vector<char>>B(M,vector<char>(M));
  for(int i=0;i<N;i++){
    string S;cin>>S;
    for(int j=0;j<N;j++)A[i][j]=S.at(j);
  }
  for(int i=0;i<M;i++){
    string S;cin>>S;
    for(int j=0;j<M;j++)B[i][j]=S.at(j);
  }
  for(int i=0;i<N-M+1;i++){
    for(int j=0;j<N-M+1;j++){
      bool b=true;
      for(int k=i;k<i+M;k++){
        for(int l=j;l<j+M;l++){
          if(A[k][l]!=B[k-i][l-j])b=false;
        }
        if(!b)break;
      }
      if(b){puts("Yes");return 0;}
    }
  }
  puts("No");
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <functional>
#include <limits>
#include <queue>
#include <iomanip>
#include <deque>
#include <stack>
#include <cstdio>
#include <cmath>
#include <complex.h>
#include <cstdio>
#include <random>
#include <chrono>
#include <numeric>
#include <cassert>
#include <iso646.h>

using namespace std;

typedef long long i64;

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

    char c0, c1;
    cin >> c0 >> c1;

    if (c0 == '9' || c1 == '9')
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 256
N=int(input())
table=[[int(i) for i in input().split()] for j in range(0,N)]

for i in range(0,N-1):
    a=table[i][0]//table[i+1][0]
    A=table[i][0]%table[i+1][0]
    b=table[i][1]//table[i+1][1]
    B=table[i][1]%table[i+1][1]
    if a>b and A==0:
        table[i+1][0]=a*table[i+1][0]
        table[i+1][1]=a*table[i+1][1]
    elif a>b and not A==0:
        table[i+1][0]=(a+1)*table[i+1][0]
        table[i+1][1]=(a+1)*table[i+1][1]
    elif a<b and B==0:
        table[i+1][0]=b*table[i+1][0]
        table[i+1][1]=b*table[i+1][1]
    elif a<b and not B==0:
        table[i+1][0]=(b+1)*table[i+1][0]
        table[i+1][1]=(b+1)*table[i+1][1]
    elif a==b and A==0 and B==0:
        table[i+1][0]=a*table[i+1][0]
        table[i+1][1]=a*table[i+1][1]
    elif a==b and not A==0 and B==0:
        table[i+1][0]=(a+1)*table[i+1][0]
        table[i+1][1]=(a+1)*table[i+1][1]
    elif a==b and not B==0 and A==0:
        table[i+1][0]=(a+1)*table[i+1][0]
        table[i+1][1]=(a+1)*table[i+1][1]
    elif a==b and not B==0 and not A==0:
        table[i+1][0]=(a+1)*table[i+1][0]
        table[i+1][1]=(a+1)*table[i+1][1]

print(table[N-1][0]+table[N-1][1])


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

void top3()
{
    int *temp = new int;
    int *bil = new int[10];
    int i = 0;

    while(i<10)
    {
        cin >> bil[i];
        if(bil[i] >=0 && bil[i] <= 10000)
            i++;
        else
            exit(1);
    }
    for(int i = 0; i < 10-1; i++)
    {
        for(int j = i+1; j < 10; j++ )
        {
            if(bil[j] > bil[i])
            {
                *temp = bil[i];
                bil[i] = bil[j];
                bil[j] = *temp;
            }
        }
    }
    for(int i = 0; i < 3; i++)
    {
        cout << bil[i]<< endl;
    }
    delete [] bil;
    delete temp;
}


int main () {

    top3();

return 0;

}

Measured memory_bytes: 3092
# 写経
# https://atcoder.jp/contests/abc177/submissions/16463802

import numpy as np
i4 = np.int32
i8 = np.int64
  
def solve(a, b, H, W):
    ret = np.empty(H, i8)
    for i in range(H):
        ret[i] = -1
    dp0 = np.arange(W) #初期位置
    dp = np.arange(W) #現在位置
    arg0 = W - 1
    arg = 0
    for i in range(H):
        r1 = np.searchsorted(dp, a[i])
        r2 = np.searchsorted(dp, b[i])
        if b[i] == W: #右端まで壁が続く場合
            if r1 == 0:
                return ret
            else:
                dp0 = dp0[: r1] #壁があるところより先は無視する
                dp = dp[: r1]
        else:
            dp[r1:r2] = b[i] #合流させる
 
        if arg0 > -1:   #直進する流れが残っている場合
            if r1 <= arg0 < r2: #壁がある場合
                for j in range(r1 - 1, -1, -1):
                    if dp[j] == dp0[j]: 
                        arg0 = j    #ここまで直進してきた他の流れに乗り換える
                        ret[i] = i + 1
                        break
                else:
                    arg0 = -1
                    arg = np.argmin(dp - dp0) #残っている値の中での最小値
                    ret[i] = dp[arg] - dp0[arg] + i + 1
            else:
                ret[i] = i + 1
        else: 
            if r1 <= arg < r2:
                arg = np.argmin(dp - dp0)
            ret[i] = dp[arg] - dp0[arg] + i + 1
        
        
        if i % 1000 == 999:
            m = 0
            prev = dp[0]
            for k in range(1, dp.shape[0]):
                if dp[k] > prev: #dp[0]とは別の流れにあるものについて
                    dp0[m] = dp0[k - 1] #最小のずれを持つもののみ残してまとめる
                    dp[m] = prev 
                    m += 1
                    prev = dp[k]
            else: #流れが一つのみの場合はこの流れの実を追いかける
                dp0[m] = dp0[dp0.shape[0] - 1]
                dp[m] = prev
                m += 1
            dp0 = dp0[: m]
            dp = dp[: m]
            if arg0 > -1: #現在最小である流れなどの情報も更新しておく
                for j in range(m - 1, -1, -1):
                    if dp[j] == dp0[j]:
                        arg0 = j
                        break
            else:
                arg = np.argmin(dp - dp0)
        
    return ret
 
 
def main(in_file):
    stdin = open(in_file)
    H, W = [int(x) for x in stdin.readline().split()]
    ab = np.fromstring(stdin.read(), i8, sep=' ').reshape((-1, 2)).T.copy()
    ans = solve(ab[0] - 1, ab[1], H, W)
    p = '\n'.join([str(x) for x in ans.tolist()])
    print(p)
 
 
def cc_export():
    from numba.pycc import CC
    from numba.types import Array, int64
    cc = CC('my_module')
    cc.export('solve', (Array(int64, 1, 'C'), Array(int64, 1, 'C'), int64, int64))(solve)
    cc.compile()
 
 
if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import solve
    main('/dev/stdin')

Measured memory_bytes: 55324
package main

import "fmt"

func main() {
    var n, m int
    fmt.Scan(&n)

    u := make([]string, 300)

    for i := 0; i < n; i++ {
        fmt.Scan(&u[i])
    }

    fmt.Scan(&m)

    is_lock := true
    for i := 0; i < m; i++ {
        var t string
        fmt.Scan(&t)

        is_include := false
        for j := 0; j < n; j++ {
            if t == u[j] {
                is_include = true
                break
            }
        }
        if is_include == false {
            fmt.Printf("Unknown %s\n", t)
        } else if (is_lock) {
            fmt.Printf("Opened by %s\n", t)
            is_lock = false
        } else {
            fmt.Printf("Closed by %s\n", t)
            is_lock = true
        }
    }
}



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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K, C;
  cin >> N >> K >> C;
  string S;
  cin >> S;
  vector<int> L(N, 0), R(N, 0);
  int cur = 1;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'o') {
      L[i] = cur++;
      i += C;
    }
    if (cur == K + 1) break;
  }
  cur--;
  for (int i = N - 1; i > -1; i--) {
    if (S[i] == 'o') {
      R[i] = cur--;
      i -= C;
    }
    if (cur == -1) break;
  }
  for (int i = 0; i < N; i++) {
    if (L[i] != 0 && L[i] == R[i]) cout << i + 1 << '\n';
  }
  return 0;
}


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

int n;
char up[]={'.','#','.','#'}, down[]={'.','#','#','.'};
string judge, nowup, nowdown;

int main()
{
    cin >> n;
    while(true) {
        bool start = false;
        for(int i=0; i<4; i++) {
            if(start) continue;
            cout << nowup+up[i] << endl << nowdown+down[i] << endl;
            cin >> judge;
            if(judge=="T") {
                nowup+=up[i];
                nowdown+=down[i];
                start = true;
            }
            else if(judge=="F") continue;
            else return 0;
        }
        if(!start) break;
    }
    while(true) {
        bool start = false;
        for(int i=0; i<4; i++) {
            if(start) continue;
            cout << up[i]+nowup << endl << down[i]+nowdown << endl;
            cin >> judge;
            if(judge=="T") {
                nowup=up[i]+nowup;
                nowdown=down[i]+nowdown;
                start = true;
            }
            else if(judge=="F") continue;
            else return 0;
        }
        if(!start) break;
    }

    return 0;
}


Measured memory_bytes: 724
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;


struct SegmentTree{
private:
    int n;
    vector<ll> node;
public:
    SegmentTree(int sz,ll init){
        n=1;
        while(n<sz)n*=2;
        node.resize(2*n-1,init);        
    }
    void update(int k,ll x){
        k+=n-1;
        node[k]+=x;
        while(k>0){
            k=(k-1)/2;
            node[k]=node[2*k+1]+node[2*k+2];
        }
    }
    ll get(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        if(r<=a||b<=l)return 0;
        if(a<=l&&r<=b)return node[k];
        ll xl=get(a,b,2*k+1,l,(l+r)/2);
        ll xr=get(a,b,2*k+2,(l+r)/2,r);
        return xl+xr;
    }
};
int main(){
    int n;
    cin>>n;
    SegmentTree Seg(n,0);
    int q;cin>>q;
    rep(i,q){
        int a,x,y;
        cin>>a>>x>>y;
        if(a)cout<<Seg.get(x-1,y)<<endl;
        else Seg.update(x-1,y);
    }
   return 0;
}


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

void calc(string& s) {
	map<char, char> to;
	char t='a';
	for (auto& c : s)
		to.count(c) ? c=to[c] : c=to[c]=t++;
}

int main() {
	string s,t; cin>>s>>t;
	calc(s); calc(t);
	cout<<(s==t?"Yes":"No")<<"\n";
	return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int a[4];
	
	for(int i=0;i<3;i++){
		cin>>a[i];
	}
	
	
	sort(a,a+3);
	
	cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
	
	
	return 0;
}


Measured memory_bytes: 3176
//       In the name of         ****                      God                     ****

/*

Copyright (C)          JadedBeast

                                   Morocco

created : 24/3/2019
	
*/

#include <bits/stdc++.h>

using namespace std;

inline void JadedBeast() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
const int MAX=1e5+1;
vector <int> v[MAX];
int d[MAX],ans=0;
bool used[MAX];
void addEdge(int x, int y ){
	v[x].push_back(y);
}
void dfs(int s){
	used[s]=true;
	for(int x : v[s]){
		if(!used[x])
			dfs(x);
		d[s]=max(d[s],d[x]+1);
		ans=max(d[s],ans);
	}
}
int main(void) {
	//JadedBeast();
	int n,m,x,y;

	memset(used,false,sizeof(used));
	memset(d,0,sizeof(d));

	scanf("%d %d",&n,&m);

	for(int i=0; i<m ; i++){
		scanf("%d %d",&x,&y);
		addEdge(x,y);	

	}

	for(int i=1 ;i<=n ;i++)
		if(!used[i])
			dfs(i);

	printf("%d",ans);
}

Measured memory_bytes: 8192
import sys
from functools import reduce

MOD = 10 ** 9 + 7

def gcd(a, b):
    while b:
        a, b = b, a % b
    return abs(a)

def lcm(a, b):
    return abs(a // gcd(a, b) * b)

n, *A = map(int, sys.stdin.read().split())

def main():
    l = reduce(lcm, A, 1) % MOD

    res = 0
    for a in A:
        res += l * pow(a, MOD-2, MOD) % MOD
        res %= MOD
    
    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 4580
#include <iostream>
#include <string>
#include <vector>
#include <utility>
using ll=long long;
using namespace std;

int main(){
    ll N,D;
    cin>>N>>D;
    ll x,y;
    int ans=0;
    for(int i=0;i<N;i++){
        cin>>x>>y;
        if(x*x+y*y<=D*D){
            ans++;
        }
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <fstream>
#include <numeric>
#define ll long long 
#define pb push_back
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);   
#define F first 
#define S second
const ll INF = std::numeric_limits<long long>::max(); 
const int IINF = std::numeric_limits<int>::max(); 
const int MOD = 1e9 + 7; 
/*rrrohan*/ 
using namespace std; 
 
/*less than or equal to -> l + r + 1*/
/*upper_bound -> greater than x 
lower_bound -> greater than or equal to x*/
ll gcd(ll a, ll b) //O(log(a+b))
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
}  
/*class dsu{
private: 
	vector <int> r,p; 
public: 
	dsu(int n){
		p.resize(n+1);
		r.resize(n+1);  
		for(int i = 0; i < n+1; i++){
			p[i] = i; 
			r[i] = 0; 
		}
	}
	int findset(int i){
		return (p[i] == i) ? i : (p[i] = findset(p[i])); 
	}
	bool issameset(int a, int b){
		return findset(a) == findset(b); 
	}
	void unionset(int i, int j){
		if(!issameset(i,j)){
			int x = findset(i), y = findset(j); 
			if(r[x] > r[y]){
				p[y]  = x; 
			}else{
				p[x] = y; 
				if(r[x] == r[y]){
					r[y]++; 
				}
			}
		}
	}
};
*/ 

int main(){
	string s; 
	cin >> s; 
	string s1 = s.substr(0,2), s2 = s.substr(2,2); 
	int x = 0, y = 0; 
	for(int i = 0; i < 2; i++){
		x = x*10;  
		x += s1[i] - '0'; 
		y = y*10; 
		y += s2[i] - '0'; 
	} 
	vector <string> v; 
	if(x > 0 && x <= 12){
		v.pb("MMYY"); 
	}
	if(y > 0 && y <= 12){
		v.pb("YYMM"); 
	}
	if(v.size() == 1){
		cout << v[0];
	}else if(v.size() == 2){
		cout << "AMBIGUOUS"; 
	}else if(v.size() == 0){
		cout << "NA"; 
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))//数组(结构体)清零 
#define ll long long
//int A(int a,int b){if(a<b||a<1||b<0)return 0;int k=1;while(b--){k*=a--;}return k;}//数学中的Aab,传递ab,返回Cab//类型为int//如果不符合条件则返回0 
//int C(int a,int b){if(a<b||a<1||b<0)return 0;b=min(a-b,b);int k=A(a,b),t=1;while(--b)k/=++t;return k;}//数学中的Cab,传递ab,返回Cab//类型为int//如果不符合条件则返回0 
//int HW(char*HWa,int HWl,int HWr){if(HWr<HWl)swap(HWl,HWr);for(int i=0;i<(HWr-HWl)/2+1;i++)if(HWa[HWl+i]!=HWa[HWr-i])return 0;return 1;}//传递字符串名,判断区间l r,如果是回文字符串就返回1,否则返回0 
//int SS(int a){if(a>4&&((a-1)%6)&&((a+1)%6))return 0;for(int i=2;i<=sqrt(a);i++)if(a%i==0)return 0;return 1;}//判断一个数是不是质数，是1 否0；请确保a>1; 
/*记得如果改int为long long,就把printf与scanf中相应的%d也改成%lld*/

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	printf("%d %d %d",a,b,c);
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll A, B;
    cin >> A >> B;
    cout << max(0LL, A - 2 * B) << endl;
    return 0;
}


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

using namespace std;

int main(void) {
    int N;
    int A[200001];
    cin >> N;
    A[0] = -1;
    A[1] = -1;
    for (int i = 2; i <= N; i++) {
        cin >> A[i];
    }

    int count[200001];
    for (int i = 0; i <= N; i++) {
        count[i] = 0;
    }
    for (int i = 2; i <= N; i++) {
        count[A[i]]++;
    }

    for (int i = 1; i <= N; i++) {
        cout << count[i];
        if (i != N ) {
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 5148
from itertools import permutations
from copy import deepcopy
from collections import Counter

n,a,b,c = map(int,input().split())
take = []
for _ in range(n):
	take.append(int(input()))
tmp = deepcopy(take)
ans_list = []

sum_abc = 10 ** 5
for abc in permutations([a,b,c],3):
	take = deepcopy(tmp)
	ans = 0
	l = []
	l2 = []
	s = Counter(take)
	#print(s)
	for x in abc:
		res = []
		l2 = []
		take = []
		for i,num in s.items():
			for j in range(num):
				take.append(i)
		#take = list(s)
		for i in range(2**n):
			l = []
			for j in range(len(take)):
					if i & (1<<j):
						l.append(take[j])
			if len(l) == 0:
				continue
			res.append(10*(len(l)-1) + abs(sum(l) - x))
			l2.append(l)
		minimum = sum_abc
		for i in range(len(res)):
			if minimum > res[i]:
				minimum = res[i]
				s2 = l2[i]
		for i in range(len(s2)):
			s[s2[i]] -= 1
			if s[s2[i]] == 0:
				s.pop(s2[i])
		#s = s - s2
		ans += minimum
		#print(res,s,minimum)
	ans_list.append(ans)

print(min(ans_list))


Measured memory_bytes: 3568
#include <bits/stdc++.h>
 using namespace std;
 
int main()
{
	int N;
	cin >> N;
 
	float tot = 0;
	for(int i=0;i<N;i++){
		double At;
		cin >> At;
		tot += (1.0 / At);
	}
 
	cout << 1.0 / tot ;
 return 0;
}

Measured memory_bytes: 3744
function Main(inputs) {
	const inputline = inputs.split("\n").map(x => parseInt(x, 10));
  	const line = inputline[0];
  
  	function base26(number) {
    	　let remainder26 = number % 26;
    	　let division26 = Math.floor(number / 26) ;
    	　let output = (remainder26 != 0) ? String.fromCharCode(64 + remainder26) : (--division26, 'Z');
      	　return (division26 != 0) ? base26(division26) + output : output;
	}
  
  	console.log(base26(line).toLowerCase());
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29564
nx = []
ans = []
while True:
    n, x = list(map(int, input().split()))
    if n == 0 and x == 0:
        break
    nx.append([n, x])

for i in nx:
    n = i[0]
    x = i[1]
    s = [j for j in range(1, n+1)]
    t = 0
    for o in range(0,n-2):
        for p in range(o+1,n-1):
            for q in range(p+1,n):
                if s[o]+s[p]+s[q] == x:
                    t += 1
    ans.append(t)

for i in ans:
    print(i)



Measured memory_bytes: 5604