akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

const int NMAX = 3100;
int dp[NMAX][NMAX] = {};

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

    string s, t; cin >> s >> t;

    for(int i=0; i<s.size(); ++i){
        for(int j=0; j<t.size(); ++j){
            if(s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
            chmax(dp[i+1][j+1], dp[i][j+1]);
            chmax(dp[i+1][j+1], dp[i+1][j]);
        }
    }

    string res = "";
    int i = (int)s.size(), j = (int)t.size();
    while(0<i && 0<j){
        // (i-1, j) -> (i, j)と更新されていた場合
        if(dp[i][j] == dp[i-1][j]) --i;
        else if(dp[i][j] == dp[i][j-1]) --j;
        else { res += s[i-1]; --i; --j; }
    }

    reverse(res.begin(), res.end());
    cout << res << endl;

	return 0;
}


Measured memory_bytes: 37120
#include <stdio.h>
#include <stack>
#include <bitset>
#include <vector>
using namespace std;
#define PB push_back
const int N=1e4+10;
stack<int> s;
bitset<N>in,went;
vector<int> graph[N],ng[N];
int low[N],dep[N],t=0,p[N],lea=0,root=0;
int max(int a,int b){return a>b?a:b;}
void dfs(int now){
    in[now]=went[now]=true;
    low[now]=dep[now]=++t;
    s.push(now);
    for(int i:graph[now]){
        if(!went[i])dfs(i);
        if(in[i])low[now]=min(low[now],low[i]);
    }
    if(low[now]==dep[now]){
        while(s.top()!=now){
            p[s.top()]=now;
            in[s.top()]=false;
            s.pop();
        }
        p[now]=now;
        in[now]=false;
        s.pop();
    }
    return ;
}
int main(){
    int n,m,l,r,cnt=0;
    bool roo[N];
    scanf("%d%d",&n,&m);
    while(m--){
        scanf("%d%d",&l,&r);
        graph[l].PB(r);
    }
    went.reset();
    in.reset();
    for(int i=0;i<n;i++){
        roo[i]=true;
        if(!went[i])dfs(i);
    }
    for(int i=0;i<n;i++)for(int j:graph[i])if(p[i]!=p[j]){
        ng[p[i]].PB(p[j]);
        roo[p[j]]=false;
    }
    went.reset();
    for(int i=0;i<n;i++)if(p[i]==i){
        if(roo[i])root++;
        if(ng[i].empty())lea++;
        cnt++;
    }
    if(cnt==1)printf("0\n");
    else printf("%d\n",max(root,lea));
}


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

#define REP(i, n) for (int i=0;i<int(n);++i)
#define FOR(i, a, b) for (int i=int(a);i<int(b);++i)
#define EACH(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

struct HeavyLight {
  int pathCount,n;
  vector<int>size,parent,in,out,path,pathSize,pathPos,pathRoot;
  vector<vector<int> > tree;//, len;
  
  HeavyLight(vector<vector<int> >tree)
    :pathCount(0),n(tree.size()),size(n),parent(n),in(n),out(n),
     path(n),pathSize(n),pathPos(n),pathRoot(n),tree(tree){
    int time=0;
    dfs(0,-1,time);
    buildPaths(0,newPath(0));
    /*
    len=vector<vector<int> >(pathCount);

    REP(i,pathCount){
      int m=pathSize[i];
      len[i].resize(2*m);
      fill(ALL(len[i]),0);
      fill(len[i].begin()+m,len[i].begin()+2*m,1);
      for(int j=2*m-1;j>1;j-=2)len[i][j>>1]=len[i][j]+len[i][j^1];
    }
    */
  }

  void dfs(int u, int p, int &k){
    in[u]=k++, parent[u]=p, size[u]=1;
    EACH(v,tree[u])if(*v!=p)dfs(*v, u, k),size[u]+=size[*v];
    out[u]=k++;
  }

  int newPath(int u){ pathRoot[pathCount]=u; return pathCount++; }

  void buildPaths(int u, int pt){
    path[u]=pt, pathPos[u]=pathSize[pt]++;
    EACH(v,tree[u])if(*v != parent[u])
      buildPaths(*v, 2*size[*v] >= size[u] ? pt : newPath(*v));
  }

  bool isAncestor(int p, int ch){
    return in[p] <= in[ch] && out[ch] <= out[p];
  }

  int lca(int a,int b){
    for(int root; !isAncestor(root=pathRoot[path[a]],b);a=parent[root]);
    for(int root; !isAncestor(root=pathRoot[path[b]],a);b=parent[root]);
    return isAncestor(a,b)?a:b;
  }
};


int main(void){
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<vector<int> >tree(n);
  
  REP(i,n){
    int k;
    cin >> k;
    REP(j,k){
      int ch;
      cin >> ch;
      tree[i].push_back(ch);
    }
  }

  HeavyLight hl = HeavyLight(tree);

  int q;
  cin >> q;
  while(q--){
    int u,v;
    cin >> u >> v;
    cout << hl.lca(u,v) << "\n";
  }
  
  return 0;
}

Measured memory_bytes: 24696
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
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); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<40;
const ll MOD = 1000000007;

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

  ll n;
  cin >> n;
  vector<ll> w(n), s(n), v(n);
  REP(i, n) cin >> w[i] >> s[i] >> v[i];

  vector<ll> idx(n);
  iota(ALL(idx), 0);
  sort(ALL(idx), [&](ll l, ll r){
    return w[l] + s[l] < w[r] + s[r];
  });
  // cout << idx << endl;

  ll ma = 20010;
  vector<vector<ll>> dp(n, vector<ll>(ma+1));
  FOR(i, w[idx[0]], ma+1) dp[0][i] = v[idx[0]];
  FOR(i, 1, n) REP(j, ma+1) {
    dp[i][j] = dp[i-1][j];
    if(j-w[idx[i]] <= s[idx[i]] && j >= w[idx[i]]) {
      chmax(dp[i][j], dp[i-1][j-w[idx[i]]] + v[idx[i]]);
    }
  }

  // REP(i, n) {
  //   REP(j, ma+1) {
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  ll ans = 0;
  REP(i, ma+1) chmax(ans, dp[n-1][i]);
  cout << ans << endl;

  return 0;
}


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

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

    priority_queue<int> a;
    for (int i = 0; i < n; i++)
    {
        int buf;
        cin >> buf;
        a.push(buf);
    }

    for (int i = 0; i < m; i++)
    {
        int buf = a.top();
        a.pop();
        a.push(buf / 2);
    }

    long long ans = 0;
    while (!a.empty())
    {
        ans += a.top();
        a.pop();
    }

    cout << ans << endl;
}

Measured memory_bytes: 892
#include <cstdio>
using namespace std;
int main(void){
    int n;
    scanf("%d",&n);
    double x = n*8/100;
    int v=0;
    for(int i=n-(int)x;i<=n;i++){
        if(i*1.08 >= n){
            v=i;
            break;
        }
    }
    if(v==0 || (int)(v*1.08) != n) printf(":(\n");
    else printf("%d\n",v);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 12743568/4;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;

vector<vector<string> > dic(MOD);

ll makeHash(string str){
    ll key = 0;
    for(int i = 0; i < str.length();i++){
        if(str[i] == 'A'){
            key += 1;
        }else if(str[i] == 'C'){
            key += 2;
        }else if(str[i] == 'G'){
            key += 3;
        }else{
            key += 4;
        }
        key *= 5;
    }
    return key%MOD;
}

void insert(string str){
    ll key = makeHash(str);
    key %= MOD;
    dic[key].push_back(str);
}

bool findStr(string str){
    ll key = makeHash(str);
    key %= MOD;
    for(int i = 0; i < dic[key].size();i++){
        if(dic[key][i] == str) return true;
    }
    return false;
}


int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string order,str;
    for(int i = 0; i < n;i++){
        cin >> order >> str;
        if(order == "insert"){
            insert(str);
        }else{
            if(findStr(str)){
                cout << "yes" << endl;
            }else{
                cout << "no" << endl;
            }
        }
    }
    

    return 0;
}


Measured memory_bytes: 115880
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

typedef pair<int,int> P;
typedef long long ll;

ll gcd(ll a, ll b){
	while(true){
		ll tmp = a % b;
		if(tmp==0) break;
		a = b;
		b = tmp;
	}
	return b;
}


int main(){
	int N;
	ll X;
	cin >> N >> X;
	ll x[100000];
	for(int i=0;i<N;i++) cin >> x[i];

	ll d[100000];
	d[0] = abs(x[0] - X);
	for (int i=1;i<N;i++) d[i] = abs(x[i] - x[i-1]);

	ll ans = d[0];
	for (int i = 1; i < N; i++)	ans = gcd(max(ans,d[i]),min(ans,d[i]));

	cout << ans << endl;
	return 0;
}


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

long long dfs(vector<vector<long long>> x, long long K, long long idx)
{
    long long base = 1;
    for (long long i = 0; i < idx; i++)
    {
        base *= 2;
    }
    bitset<40> b(K);
    if (idx == 0)
    {
        if (b[idx] == 0)
        {
            return x[idx][1];
        }
        else
        {
            return max(x[idx][0], x[idx][1]);
        }
    }
    if (b[idx] == 0)
    {
        return x[idx][1] + dfs(x, K, idx - 1);
    }
    else
    {
        long long ret = x[idx][1];
        for (long long i = 0; i < idx; i++)
        {
            ret += max(x[i][0], x[i][1]);
        }
        return max(x[idx][0] + dfs(x, K, idx - 1), ret);
    }
}

int main()
{
    long long N, K;
    cin >> N >> K;
    long long A;
    long long count[40] = {};
    for (long long i = 0; i < N; i++)
    {
        cin >> A;
        bitset<40> b(A);
        for (int j = 0; j < 40; j++)
        {
            count[j] += b[j];
        }
    }

    vector<vector<long long>> x(40, vector<long long>(2, 0));
    long long base = 1;
    for (long long i = 0; i < 40; i++)
    {
        x[i][0] = base * (N - count[i]);
        x[i][1] = base * count[i];
        base *= 2;
    }
    long long ans = dfs(x, K, 40 - 1);
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#define swap(type, a, b) {type tmp = a; a = b; b = tmp;}

int bubbleSort(int *a, int n) {
    int i, j, sum, flag;
    j = 0; sum = 0; flag = 1;
    while (flag) {
        flag = 0;
        for (i = n - 1; i > j; i--) {
            if (a[i] < a[i - 1]) {
                swap(int, a[i], a[i - 1]);
                sum++;
                flag = 1;
            }
        }
        j++;
    }
    return sum;
}

int main(void) {
    int N;
    scanf("%d", &N);
    int A[N];
    int idx, ans;

    for (idx = 0; idx < N; idx++) {
        scanf("%d", &A[idx]);
    }

    ans = bubbleSort(A, N);

    for (idx = 0; idx < N; idx++) {
        printf("%d", A[idx]);
        if (idx < N - 1) printf(" ");
        else printf("\n");
    }

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

    return 0;
}


Measured memory_bytes: 2112
#include <stdio.h>
#include <string.h>
#define LEN 100005
 
typedef struct pp {
  char name[100];
  int t;
} P;
 
P Q[LEN];
int head, tail, n;
 
void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}
 
P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}
 
int min(int a,int b) {
  return a < b ? a : b; 
}
 
int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  
  scanf("%d %d",&n ,&q);
  for(i=1; i<=n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1; tail = n + 1;
 
  while(head != tail) {
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else {
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}


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

//#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
//typedef pair<int,int> P;
//typedef pair<int,P> PP;

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

const double EPS=1e-8;
const double INF=1e12;

typedef complex<double> P;

namespace std {
	bool operator<(const P &a,const P &b) {
		return real(a)!=real(b)?real(a)<real(b):imag(a)<imag(b);
	}
}

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

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

int ccw(P a,P b,P c) {
	b-=a;c-=a;
	if(cross(b,c)>0) 	return +1;
	if(cross(b,c)<0) 	return -1;
	if(dot(b,c)<0)	 	return +2;
	if(norm(b)<norm(c)) return -2;
	return 0;
}

vector<P> convex(vector<P> ps) {
	int n=(int)ps.size(),k=0;
	sort(ALL(ps));
	vector<P> ch(2*n);
	for(int i=0;i<n;ch[k++]=ps[i++]) {
		while(k>=2&&ccw(ch[k-2],ch[k-1],ps[i])<=0) --k;
	}
	for(int i=n-2,t=k+1;i>=0;ch[k++]=ps[i--]) {
		while(k>=t&&ccw(ch[k-2],ch[k-1],ps[i])<=0) --k;
	}
	ch.resize(k-1);
	return ch;
}

int n;

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

	cin>>n;
	vector<P> ps;
	map<P,int> idx;
	REP(i,n) {
		double x,y;cin>>x>>y;
		ps.pb(P(x,y));
		idx[P(x,y)]=i;
	}
	vector<double> ans(n,0.0);
	vector<P> res=convex(ps);

	int sz=(int)res.size();
	if(sz==2) {
		for(auto p:res) ans[idx[p]]=0.5;
	}
	else {
		REP(i,sz) {
			P prv=res[(i-1+sz)%sz],crt=res[i],nxt=res[(i+1)%sz];
			double result=arg((crt-nxt)/(prv-crt));
			if(result<0) result+=2*PI;
			ans[idx[crt]]=result/(2*PI);
		}
	}
	REP(i,n) printf("%.12f\n",ans[i]);

	return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <regex>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1000000007;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//myfuncs
//素数判定
template<class T> inline T isPrime(T x) {
	bool ret = true;
	if (x < 2) {
		ret = false;
	}
	for (LL i = 2; i <= sqrt(x); i++) {
		if (x%i == 0) {
			ret = false;
		}
	}
	return ret;
}

//Union FInd
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for(int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	int num[100050] = {};
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		num[a]++;
	}
	int m = 0;
	for (int i = 0; i < 100020; i++) {
		int s = num[i] + num[i+1] + num[i+2];
		m = max(m,s);
	}
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
	
	int n,a[222222];
	cin>>n;
	long long x=0,y=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		y+=a[i];
	}
	long long min=1000000000000000000;
	//min=std::min(min,abs(x-y));
	for(int i=0;i<n-1;i++){
		x+=a[i];
		y-=a[i];
		min=std::min(min,abs(x-y));
	}
	cout<<min<<endl;

}

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

int main()
{
    vector<int> v;
    int n, x, q, a, b, c;
    cin >> n;
    while (n--)
    {
        cin >> x;
        v.push_back(x);
    }
    cin >> q;
    while (q--)
    {
        cin >> a >> b >> c;
        cout << (count(v.begin() + a, v.begin() + b, c)) << endl;
    }
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//


int main() {
    init();
    string s;
    cin >> s;
    ll N = s.size();
    bool ok = false;
    rep(i,N-1)repe(j,i+1,N){
        if (s[i]=='C'&&s[j]=='F') ok = true;
    }
    cout << ((ok) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
 
// 并?集相?数据与算法
#define MAX_N 100000 + 16
int parent[MAX_N];
int height[MAX_N];
 
void init(const int& n)
{
	for (int i = 0; i < n; ++i)
	{
		parent[i] = i;
		height[i] = 0;
	}
}
 
int find(const int& x)
{
	if (parent[x] == x)
	{
		return x;
	}
	else
	{
		return parent[x] = find(parent[x]);
	}
}
 
void unite(int x, int y)
{
	x = find(x);
	y = find(y);
	if (x == y)
	{
		return;
	}
 
	if (height[x] < height[y])
	{
		parent[x] = y;
	}
	else
	{
		parent[y] = x;
		if (height[x] == height[y])
		{
			++height[x];
		}
	}
}
 
bool same(const int& x, const int& y)
{
	return find(x) == find(y);
}
// End Of 并?集
 
// 原始的?用它来描述
vector<int> children[MAX_N];
int parent_tree[MAX_N];
bool marked[MAX_N];
int ancestor[MAX_N];
// ?条指令被拆分? 操作 + 目?
stack<char> operation;
stack<int>  target;
 
void bfs(int index, int the_ancestor)
{
	queue<int> q_index;
	queue<int> q_ancestor;
	q_index.push(index);
	q_ancestor.push(the_ancestor);
	while (!q_index.empty())
	{
		the_ancestor = q_ancestor.front(); q_ancestor.pop();
		index = q_index.front(); q_index.pop();
		if (marked[index] == true)
		{
			the_ancestor = index;
		}
		ancestor[index] = the_ancestor;
		for (vector<int>::iterator it = children[index].begin(); it != children[index].end(); ++it)
		{
			q_index.push(*it);
			q_ancestor.push(the_ancestor);
		}
	}
}
 
///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
 
	int N, Q;
	while (cin >> N, cin >> Q, N)
	{
		for (int i = 0; i < N; ++i)
		{
			children[i].clear();
			marked[i] = false;
		}
		marked[0] = true;
		int p;
		for (int i = 1; i < N; ++i)
		{
			cin >> p; --p;
			parent_tree[i] = p;
			children[p].push_back(i);
		}
		for (int i = 0; i < Q; ++i)
		{
			char o;
			int t;
			cin >> o >> t; --t;
			if (o == 'M')
			{
				if (marked[t])
				{
					continue;
				}
				else
				{
					marked[t] = true;
				}
			}
			operation.push(o);
			target.push(t);
		}
		bfs(0, 0);
		init(N);
		for (int i = 0; i < N; ++i)
		{
			unite(i, ancestor[i]);
		}
		unsigned long long result = 0;
		while (!operation.empty())
		{
			char o = operation.top(); operation.pop();
			int t = target.top(); target.pop();
			if (o == 'Q')
			{
				result += ancestor[find(t)] + 1;	// ?目index从1?始
			}
			else
			{
				// ?行“反染色”操作，之后?个?点的祖先??其父?点的祖先
				int p = ancestor[find(parent_tree[t])];
				unite(t, parent_tree[t]);
				ancestor[find(t)] = p;
			}
		}
		cout << result << endl;
	}
	
 
	return 0;
}

Measured memory_bytes: 11588
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#define Mod 1000000007
#define INF 1e14
typedef long long int ll;
ll fast(ll n,ll a)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll res=fast(n/2,a)%Mod;
        if(n%2==0)
        {
            return (((res%Mod)*(res%Mod))%Mod);
        }
        else{
            return (((((res%Mod)*a)%Mod)*res)%Mod);
        }
    }
}

int main()
{
   ll n;
   cin>>n;
   ll i,a[n+1];
   for(i=1;i<=n;i++)
   {
       cin>>a[i];
   }
   ll b[n+1],c[n];
   for(i=1;i<=n;i++)
   {
       cin>>b[i];
   }
   for(i=1;i<=n-1;i++)
   {
       cin>>c[i];
   }
   ll ans=0;
   ans+=b[a[1]];
   for(i=2;i<=n;i++)
   {
       if(a[i]-a[i-1]==1)
       {
           ans+=b[a[i]];
           ans+=c[a[i]-1];
       }
       else
       {
           ans+=b[a[i]];

       }
   }
   cout<<ans;


}


Measured memory_bytes: 256
import math
N = int(input())
z = 0
for a in range(N):
    for b in range(min(a,math.floor(N/(a+1)))):
        if N - (a+1)*(b+1) > 0:
            z = z+2
        else:
            pass
    if N - (a+1)*(a+1) > 0:
        z = z+1
    else:
        pass
print(z)

Measured memory_bytes: 9116
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int main()
{
	char X,Y;
	int a[3], i, j, buf;

	a[0] = 1;
	a[1] = 0;
	a[2] = 0;

	while(scanf("%c,%c%*c", &X, &Y) != EOF){
		if(X == 'A')
			i = 0;
		else if(X == 'B')
			i = 1;
		else
			i = 2;
		if(Y == 'A')
			j = 0;
		else if(Y == 'B')
			j = 1;
		else
			j = 2;

		buf = a[i];
		a[i] = a[j];
		a[j] = buf;
	}
	if(a[0] == 1)
		printf("A\n");
	else if(a[1] == 1)
		printf("B\n");
	else
		printf("C\n");

	return 0;
}

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

int main()
{
	int64_t n;
	cin >> n;
	vector<int64_t> xs(n), ys(n);
	for (int64_t i = 0; i < n; i++)
	{
		cin >> xs[i] >> ys[i];
	}

	vector<int64_t> as(n), bs(n);
	for (int64_t i = 0; i < n; i++)
	{
		as[i] = xs[i] + ys[i];
		bs[i] = xs[i] - ys[i];
	}

	cout << max(*max_element(as.begin(), as.end()) - *min_element(as.begin(), as.end()), *max_element(bs.begin(), bs.end()) - *min_element(bs.begin(), bs.end())) << endl;

	return 0;
}

Measured memory_bytes: 9532
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long int lli;
const long long int MaxN=300005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}

	void solve(){
		int N,i,j,p,q;
		string word;
		cin>>word;
		N=word.size();
		for(i=0;i<N;i++){
			if(word[i]=='?')word[i]='D';
		}
		cout<<word;
	}
int main(){
	//cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
}


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

int main()
{
  string s;
  cin >> s;
  sort(s.begin(), s.end());

  string t;
  cin >> t;
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());

  if(s < t) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;

}


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

const int MOD = 1000000007;

int main() {
    int N, K;
    std::cin >> N >> K;

    std::vector<std::vector<std::vector<int>>> dp(
        N + 1,
        std::vector<std::vector<int>>(
            N + 1,
            std::vector<int>(K + 1)
        )
    );

    dp[0][0][0] = 1;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= i; j++) {
            for (int k = 0; k <= K; k++) {
                if (k + (j + 1) * 2 <= K) {
                    int& x = dp[i + 1][j + 1][k + (j + 1) * 2];
                    x += dp[i][j][k];
                    x %= MOD;
                }

                if (k + j * 2 <= K) {
                    int& x = dp[i + 1][j][k + j * 2];
                    x += 1LL * dp[i][j][k] * (j * 2 + 1) % MOD;
                    x %= MOD;
                }

                if (0 < j && k + (j - 1) * 2 <= K) {
                    int& x = dp[i + 1][j - 1][k + (j - 1) * 2];
                    x += 1LL * dp[i][j][k] * (j * j) % MOD;
                    x %= MOD;
                }
            }
        }
    }

    std::cout << dp[N][0][K] << "\n";
}

Measured memory_bytes: 26240
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  ll n, q; cin >> n >> q;
  string s; cin >> s;
  vi cnt(n, 0);
  REP(i,1,n) {
    if (s[i-1]=='A' && s[i]=='C') {
      cnt[i] = 1;
    }
    cnt[i] += cnt[i-1];
  }
  // rep(i,n) { cout << cnt[i] << " \n"[i==n-1]; }
  rep(i,q) {
    int l, r; cin >> l >> r; l--; r--;
    cout << cnt[r] - cnt[l] << endl;
  }
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(ll i=0;i<n;i++)
#define Rip(i,n) for(ll i=1;i<=n;i++)
#define all(V) V.begin(),V.end()
#define ll long long
#define ld long double
#define MOD 1000000007
#define mod 998244353
#define sec setprecision
#define Pair pair<ll,ll>
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using namespace std;
ll gcd(ll a, ll b)
{
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
ll pow(ll x, ll n) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (pow((x * x)%mod , n / 2)%mod);
	else
		return (x * pow(x, n - 1))%mod;
}
int main() {
	ll a, b, c; cin >> a >> b >> c;
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0)cout << 0 << endl;
	else {
		cout << min({ a * b, a * c, b * c }) << endl;
	}
}

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

int main(){
    using namespace std;
    constexpr unsigned long MOD = 1000000007;
    vector<unsigned long> tapi(1048576, 1), tapu(1048576), tape(1048576);
    unsigned long ans{0}, t{500000004}, a{0}, z{0}, A;cin >> A;
    while(cin >> A)if(a ^= A){
        (tapu[a] += (tapi[a] += tapu[a] * (z - tape[a])) %= MOD) %= MOD;
        ans += tapi[a];
        tape[a] = z;
    }else ++z, (t *= 2) %= MOD;
    cout << (a ? tapi[a] : (ans + t) % MOD) << endl;
    return 0;
}

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

const int MaxN = 100000 + 5;

int N;
int A[MaxN];

void init() {
    scanf("%d", &N);
    for (int i = 1; i <= N; ++i)
        scanf("%d", &A[i]);
}

void solve() {
    bool ok = false;
    for (int i = 1; i <= N; ++i)
        if (A[i] % 2 == 1) ok = true;
    if (ok) puts("first");
    else puts("second");
}

int main() {
    init();
    solve();
    return 0;
}

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

int N;
double dp[301][301][301];

double rec(int a, int b, int c){
    if(dp[a][b][c] >= -0.5) return dp[a][b][c];
    double ret = 0;
    if(a>0) ret += rec(a-1, b, c) * a;
    if(b>0) ret += rec(a+1, b-1, c) * b;
    if(c>0) ret += rec(a, b+1, c-1) * c;
    ret += N;
    ret /= (a+b+c);
    dp[a][b][c] = ret;
    return ret;
}

int main(){
    cin >> N;
    vector<int> num(4, 0);
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        num[a]++;
    }
    for(int i=0; i<=300; i++) for(int j=0; j<=300; j++) for(int k=0; k<=300; k++) dp[i][j][k] = -1;
    dp[0][0][0] = 0;
    cout << fixed << setprecision(10) << rec(num[1], num[2], num[3]) << endl;
    return 0;
}

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

int main(void) {

	int m, f, r;

	while(true) {
		cin >> m >> f >> r;
		if(m==-1 && f==-1 && r==-1)	break;

		if(m==-1 || f==-1)		cout << "F" << endl;
		else if(m+f >= 80)		cout << "A" << endl;
		else if(m+f >= 65)		cout << "B" << endl;
		else if(m+f >= 50)		cout << "C" << endl;
		else if(r >= 50)		cout << "C" << endl;
		else if(m+f >= 30)		cout << "D" << endl;
		else					cout << "F" << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()

    ret = MAX
    for i in range(1, int((N + 1)**0.5)+1):
        if N % i == 0:
            j = N // i
            ret = min(ret, i + j - 2)
    print(ret)


if __name__ == '__main__':
    main()


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

#define int long long
#define REP(i, l, r) for (int i=(l); i<(r); ++i)
#define RREP(i, r, l) for (int i=(r); i>(l); --i)
#define vi vector<int>
#define vb vector<bool>
#define pii pair<int,int>
#define tiii tuple<int,int,int>
#define tiiii tuple<int,int,int,int>
#define popcount __builtin_popcountll

const int INF = 1LL<<60;
const int MOD = 1000000007;

template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
string to_string(string s) {return s;}
template <typename A, typename B>
string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> t) {return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ")";}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> t) { return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")";}
template <typename A>
string to_string(vector<A> v) {
    bool first = true;
    string result = "[";
    for (A i : v) {
        if (!first) result += ", ";
        first = false;
        result += to_string(i); 
    }
    return result + "]";
}

string bin_string(int x) {
    const int d = 32;
    string result(d, ' ');
    RREP(i, d-1, -1) result[d-1-i] = '0'+((x&1LL<<i)!=0);
    return result;
}

int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}

main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int a, b;
    cin >> a >> b;
    cout << a*b/__gcd(a,b);
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    int n, m;

    scan(n);
    scan(m);

    auto visited = new bool[](n + 1);
    auto adj = new int[][](n + 1, 0);
    auto rank = new int[](n + 1);

    foreach (i ; 0 .. m) {
        int ai, bi;
        scan(ai, bi);
        adj[bi] ~= ai;
    }

    int num = 1;

    void dfs(int v) {
        visited[v] = true;

        foreach (u ; adj[v]) {
            if (!visited[u]) {
                dfs(u);
            }
        }

        rank[num++] = v;
    }

    foreach (i ; 1 .. n + 1) {
        if (!visited[i]) dfs(i);
    }

    writefln("%(%s\n%)", rank[1 .. $]);

    bool uniq = true;

    foreach (i ; 1 .. n) {
        int a = rank[i], b = rank[i + 1];

        bool exist = false;

        foreach (u ; adj[b]) {
            if (u == a) exist = true;
        }

        uniq &= exist;
    }

    writeln(uniq ? 0 : 1);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

const int nm = 2e5;
int n, smax, smin, dmax, dmin;

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int x, y, s, d;
		cin >> x >> y;
		s = x + y;
		d = x - y;
		if (!i) {
			smax = s;
			smin = s;
			dmax = d;
			dmin = d;
		} else {
			smax = max(smax, s);
			smin = min(smin, s);
			dmax = max(dmax, d);
			dmin = min(dmin, d);
		}
	}
	cout << max(smax - smin, dmax - dmin) << endl;
}


Measured memory_bytes: 3580
local function reada(n,m)m=m or 1 r={}for i=1,m do r[i]={}end for i=1,n do for j=1,m do r[j][i]=io.read"*n"end end return unpack(r)end
N=io.read"*n"
H=reada(N)
for i=1,N-1 do
	if(H[i]-H[i+1]<0)then
		H[i+1]=H[i+1]-1
	end
end
for i=1,N-1 do
	if(H[i]-H[i+1]>0)then print"No"return end
end
print"Yes"


Measured memory_bytes: 1280
n, k = map(int, input().split())
h = [0] * n
for i in range(n):
    h[i] = int(input())
h.sort(reverse=True)

l = []
for i in range(n - k + 1):
    l.append(- h[i + k - 1] + h[i])

res = min(l)
print(res)

Measured memory_bytes: 17024
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  int n,i,a,s,dmin=1e5;
  cin >> n;
  for (i=0;i<n;i++){
    cin >> a;
    s=0;
    while (a%2==0){
      a/=2;
      s++;
    }
    if (dmin>s) dmin=s;
  }
  cout << dmin << endl;
  return 0;
}

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

public class Main {
  private static int solve(int a, int b) {
    int diff = b - a;
    return diff * (diff - 1) / 2 - a;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int a = reader.nextInt();
    int b = reader.nextInt();
    out.println(solve(a, b));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define rep(i,n) for(int i = 0; i < (n); i++)

template<class T, class U>
using umap = unordered_map<T, U>;
using ll = long long;

ll n;
vector<vector<ll>> a;
umap<ll, vector<ll>> to;
int main(){
  cin >> n;
  const ll MAXN = 1010;
  const ll MAXV = MAXN*MAXN*0.5;
  a.resize(n, vector<ll>(n-1));
  // ll tbl[MAXN][MAXN] = {};
  // ll v = 0;
  // rep(i,n){
  //   rep(j,n){
  //     if(i < j)tbl[i][j] = v++;
  //   }
  // }
  auto id = [&](ll i, ll j){
	   if(i > j) swap(i, j);
	   return i*1000 + j;//tbl[i][j];
	 };
  rep(i, n){
    rep(j, n-1){
      cin >> a[i][j];a[i][j]--;
      if(j)to[id(i,a[i][j-1])].push_back(id(i,a[i][j]));
    }
  }
  
  // ll dist[MAXV] = {};
  umap<ll,ll> dist;
  set<ll> vst, fin;
  auto dfs = [&](ll i, auto func) -> ll{
	       if(vst.count(i) == 1) {
		 if(fin.count(i) == 0) return -1;
		 return dist[i];
	       }
	       vst.insert(i);
	       ll ret = 1;
	       for(auto&e : to[i]){
		 ll d = func(e, func);
		 if(d == -1) return -1;
		 else ret = max(ret, d + 1);
	       }
	       fin.insert(i);
	       dist[i] = ret;
	       return dist[i];
	     };
  ll ans = 1;
  rep(i,MAXV){
    ll val = dfs(i, dfs);
    if(val == -1){
      ans = -1; break;
    }
    ans = max(ans, val);
  }
  cout << ans << endl;
  return 0;
}













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

const int N = 1e5 + 5;

int n;
string s;
set<int> st;


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);    
  
    cin >> n >> s;
    int ret = 0;
    st.insert(0);
    for (auto it : s){
      if (it == 'I')
        ret++;
      else
        ret--;
      st.insert(ret);
    }    

    cout << *--st.end() << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define SZ(x) ((int)x.size()-1)
#define ms(a,b) memset(a,b,sizeof a)
#define F(i,a,b) for (int i=(a);i<=(b);++i)
#define DF(i,a,b) for (int i=(a);i>=(b);--i)
using namespace std;
inline LL read(){
	char ch=getchar(); LL w=1,c=0;
	for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
	for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48);
	return w*c;
}
const int M=2e5+10;
int n; 
LL a[M],b[M],c[M],ta[M],tb[M];
int s[M],tp; 
double slope(int x,int y){
	return (a[x]-a[y])*1.0/(x-y);
}
int main(){
	n=read(); 
	F(i,1,n) a[i]=read();
	F(i,1,n) b[i]=read();
	int mx=0;
	F(i,1,n){
		if (a[i]>a[mx]) mx=i;
	}
	int j=mx; 
	F(i,1,n+1){
		ta[i]=a[j];
		tb[i]=b[j];
		j++; 
		if (j>n) j=1;
	}
	F(i,1,n+1) a[i]=ta[i],b[i]=tb[i];
	F(i,3,n+1){
		c[i]=2ll*(b[i-1]+c[i-1])-c[i-2];
		a[i]-=c[i];
	}
//	F(i,1,n+1) cout<<a[i]<<" a\n";
	F(i,1,n+1){
		while (tp>1&&slope(s[tp-1],s[tp])<slope(s[tp],i)) tp--;
		s[++tp]=i;
	}
	LL ans=0;
	F(i,2,tp){
		int len=s[i]-s[i-1]+1;
		ans+=a[s[i-1]]*len+a[s[i]]*(len-2);
//		double del=(a[s[i]]-a[s[i-1]])*1.0/len,bg=a[s[i-1]];
//		F(j,s[i-1]+1,s[i]-1){
//			bg+=del;
//			ans+=bg+c[j];
//		}
//		ans-=a[s[i]]*2;
	}
	F(i,1,n) ans+=c[i]*2;
	cout<<fixed<<setprecision(12)<<ans/(2.0*n)<<"\n"; 
	return 0;
}


Measured memory_bytes: 12284
#include <cmath>
#include <iostream>
#include <complex>
#include <utility>
#include <vector>
using namespace std;
using P = complex<double>;
using L = pair<P,P>;
using C = pair<P,double>;
using Poly = vector<P>;
#define X real()
#define Y imag()
const double EPS = 1e-7, pi = acos(-1.0);

double dot(P a, P b){ return a.X*b.X + a.Y*b.Y; }
double cross(P a, P b){ return a.X*b.Y - a.Y*b.X; }
P projection(P a, P b) {return dot(a,b)/norm(b)*b;}

int ccw(P a, P b, P c){
  b -= a, c -= a;
  if(cross(b,c) > EPS) return +1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < 0) return +2;
  if(norm(b) + EPS < norm(c)) return -2;
  return 0;
}

double ps_dist(P a, L s){
  P sf = s.first, ss = s.second;
  if(dot(ss-sf,a-sf) >= 0 and dot(sf-ss,a-ss) >= 0)
    return abs(cross(sf-ss,a-ss))/abs(sf-ss);
  return min(abs(a-sf),abs(a-ss));
}

double pl_dist(P a, L s){
  P sf = s.first, ss = s.second;
  return abs(cross(sf-ss,a-ss))/abs(sf-ss);
}

vector<P> cpcl(C c, L l){
  double d = pl_dist(c.first,l), r = c.second;
  P lf = l.first, ls = l.second;
  P m = lf + projection(c.first-lf,ls-lf);
  P x = sqrt(r*r-d*d)/abs(ls-lf)*(ls-lf);
  vector<P> cp(2,m);
  cp[0] -= x;
  cp[1] += x;
  return cp;
}

double common_area_cp(C c, Poly p){
  double ret = 0, r = c.second;
  int n = p.size();
  for(int i = 0; i < n; ++i) p[i] -= c.first;
  for(int i = 0; i < n; ++i){
    P cur = p[i], nex = p[(i+1)%n];
    if(abs(cur*nex) < EPS) continue;
    double d = arg(nex/cur);
    ret += r*r*d/2.;
    if(ps_dist(P(0,0),L(cur,nex)) < r -EPS){
      vector<P> cps = cpcl(C(P(0,0),r),L(cur,nex));
      P a, b;
      if(ccw(cur,nex,cps[0]) == 0 and
         ccw(cur,nex,cps[1]) == 0)
        a = cps[0], b = cps[1];
      else if(!ccw(cur,nex,cps[0]))
        a = cps[0], b = nex;
      else if(!ccw(cur,nex,cps[1]))
        a = cur, b = cps[1];
      else
        a = cur, b = nex;
      if(abs(a*b) < EPS) continue;
      d = arg(b/a);
      ret += cross(a,b)*0.5 - r*r*d*0.5;
    }
  }
  return ret;
}

int main(){
  int N;
  double R;
  cin >> N >> R;
  vector<P> pol;
  for(int i = 0; i < N; ++i){
    double x, y;
    cin >> x >> y;
    pol.emplace_back(x,y);
  }
  double ans = 0;
  for(int i = 0; i < R; ++i){
    C c(P(0,0),i+1);
    double a = (i+1)*(i+1)*pi;
    if(not i){
      ans += common_area_cp(c,pol);
      //cerr << common_area_cp(c,pol) << endl;
      continue;
    }
    double t = common_area_cp(c,pol) - common_area_cp(C(P(0,0),i),pol);
    if(i%2) ans += a - i*i*pi - t;
    else ans += t;
  }
  printf("%.12f\n",ans);
}



Measured memory_bytes: 3496
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

typedef pair<int,int> P;
typedef long long ll;

int main(){
	int N;
	cin >> N;
	
	int ans = 0;
	for(int i=1;i<=N;i+=2){
		int cnt = 0;
		for(int j=1;j<=N;j++){
			if(i%j==0) cnt++;
		}
		if(cnt==8) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

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

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int A = in(),B = in(),C = in();
    int dai = max({A,B,C})*3;
    A = A + B + C;
    dai -= A;
    if(dai %2 == 0){
        cout << dai/2 << "\n";
    }else{
        cout << dai/2 + 2 << "\n";
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

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

  std::vector<int> v;
  int a,b,c;
  cin >> a >> b >> c;
    v.push_back(a);
       v.push_back(b);
       v.push_back(c);
  sort(v.begin(),v.end());
  if(v[2]==v[1]+v[0]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256