akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
const Int MOD = 1000000007;
const Int MAX = 10000;
Int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
Int COM(int n, int k) {
    if (n < k || n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
    COMinit();
    Int S; cin >> S;
    Int ans = 0;
    for (int n = 1; n <= 1000; n++) {
        Int sum = S - n * 2;
        if (sum < n) continue;
        Int t = COM(sum - 1, n - 1);
        ans = (ans + t) % MOD;
    }
    cout << ans << endl;
    return 0;
}

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

double x[4], y[4];
int main(void){
    double eps = 1e-10;
    int n;
    cin >> n;
    rep(data, n) {
        rep(i, 4) cin >> x[i] >> y[i];
        if(x[1]==x[0] && x[3]==x[2]) {
            if(y[1]!=y[0] && y[3]!=y[2]) cout << "YES" << endl;
            else cout << "NO" << endl;
        } else if(x[1]==x[0] && x[3]==x[2]) cout << "NO" << endl;
        else if(abs((y[1]-y[0])/(x[1]-x[0]) - (y[3]-y[2])/(x[3]-x[2])) < eps) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
}

Measured memory_bytes: 1228
#include <stdio.h>
#include <math.h>
 
int main(void){
    int i,n,s[1000];
    double h,sum;
     
    while(1){
 
        scanf("%d",&n);
        if(!n) break;
         
        sum = 0;
        h = 0;
         
        for(i=0;i<n;i++){
            scanf("%d",&s[i]);
            sum += s[i];
        }
     
        sum /= n;
     
   //     printf("%lf ",sum);
         
        for(i=0;i<n;i++){
            h += pow(s[i]-sum, 2.0);
        }
             
        h /= n;
 
   //     printf("%lf ",h);
 
        printf("%lf\n",pow(h,1.0/2.0));
     
    }
     
    return 0;
}


Measured memory_bytes: 2040
#include <iostream>
#include <string>
#include <array>
#define llt long long int

using namespace std;

const int INF = 10000000;
int main()
{
    int n;

    cin >> n;
    array<int, 250> a;

    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    int cnt = INF;

    for (int i = 0; i < n; i++)
    {
        int count = 0;

        while (a[i] % 2 == 0)
        {
            a[i] /= 2;
            count++;
        }

        if (cnt > count)
            cnt = count;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
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();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

map<string,int> memo;
int n;
string s,g;

const int MAX=INT_MAX/10;
int dfs(string &s,string &g,vs &a,vs &b){
	if(EXIST(memo,s)){
		return memo[s];
	}
	if(s.size()>10){
		return MAX;
	}
	if(s==g){
		return 0;
	}
	int ret=MAX;
	REP(i,n){
		string after;
		int prev=0;
		int pos=0;
		while(1){
			pos=s.find(a[i],pos);
			FOR(j,prev,(pos==s.npos?s.size():pos)){
				after+=s[j];
			}
			if(pos==s.npos){
				break;
			}
			after+=b[i];
			pos+=a[i].size();
			prev=pos;
		}
		if(prev>0){
			ret=min(ret,dfs(after,g,a,b)+1);
		}
	}
	return memo[s]=ret;
}

int main(){
	while(cin>>n,n){
		memo.clear();
		vs a(n),b(n);
		REP(i,n){
			cin>>a[i]>>b[i];
		}
		cin>>s>>g;
		int ans=dfs(s,g,a,b);
		cout<<(ans==MAX?-1:ans)<<endl;
	}

}

Measured memory_bytes: 1420
n=int(input())
l=list(map(int, input().split()))
s=set(l)
d=dict()

for x in l:
    d[x]=0
for x in l:
    d[x]+=1


sum = 0
for key in d.keys():
    a = d[key]
    sum += (a*(a - 1)) // 2


for x in l:
    print(sum - d[x] +1)

Measured memory_bytes: 29312
n=int(input())
a=list(map(int,input().split()))
tmp=float("inf")
flg=True
b=list(map(lambda x:abs(x),a))
ans=sum(b)
t=sum(b)
for i in range(n):
    if a[i]==0:
        print(ans)
        exit()
    if a[i]<0:
        if flg:
            flg=False
        else:
            flg=True
    if abs(a[i])<tmp:
        tmp=abs(a[i])
if flg:
    print(ans)
else:
    print(ans-2*tmp)

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

#define FOR(i,a,b)    for (int i=(a)  ;i<(b) ;i++)
#define RFOR(i,a,b)   for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)      for (int i=0    ;i<(n) ;i++)
#define RREP(i,n)     for (int i=(n)-1;i>=0  ;i--)
#define EACH(i,a,b)   for (int i=(a)  ;i<=(b);i++)
#define REACH(i,a,b)  for (int i=(b)  ;i>=(a);i--)
#define ALL(a)        (a).begin(),  (a).end()
#define RALL(a)       (a).rbegin(), (a).rend()
#define YES()         printf("YES\n")
#define NO()          printf("NO\n")
#define Yes()         printf("Yes\n")
#define No()          printf("No\n")
#define in(a,x,b)     ((a) <= (x) && (x) < (b))

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

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

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

const int dxs[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dys[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

int prime[1001001];
bool is_prime[1001001];

int sieve(int n) {
  int p = 0;
  for (int i = 0; i < n; i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < n; i++){
    if (is_prime[i]){
      prime[p++] = i;
      for (int j = 2*i; j < n; j+=i) is_prime[j] = false;
    }
  }
  return p;
}

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

  string S;
  cin >> S;
  int ans = 0;
  int cnt = 0;
  for (auto c : S) {
    if (c == 'A' || c == 'C' || c == 'G' || c == 'T') cnt++;
    else {
      chmax(ans, cnt);
      cnt = 0;
    }
  }
  chmax(ans, cnt);
  cout << ans << endl;
}



Measured memory_bytes: 3656
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
const int maxn = 2e3+5;
typedef long long ll;
int Dis[maxn];
int main(void)
{
	int n, x, y;
	scanf("%d %d %d", &n, &x, &y);
	for (int i = 1; i < n; i++) {
		for (int j = i + 1; j <= n; j++) {
			int l = i, r = j, dis = r - l;
			if (l <= x && r >= y) {
				dis -= y - x - 1;
			}
			else if (l <= x && r < y && r > x) {
				if (r - x > y - r + 1)
					dis = x - l + y - r + 1;
			}
			else if (l > x && l < y && r >= y) {
				if (l - x + 1+ r-y < dis)
					dis = l - x + 1 + r - y;
			}
			else if (l > x && r < y) {
				if (l - x + 1 + y - r < dis)
					dis = l - x + 1 + y - r;
			}
			Dis[dis]++;
		}
	}
	for (int i = 1; i <= n - 1; i++)
		printf("%d\n", Dis[i]);
	return 0;
}

Measured memory_bytes: 128
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	string s, t; cin >> s >> t;
	int ans = 0;
	forl(i, 0, 3) if(s[i] == t[i]) ans++;
	println(ans);
}



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

int main() {
  int table[3][3];
  int iscalled[3][3];
  int n;
  int callednumber;
  int bingo;

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      iscalled[i][j] = 0;
    }
  }

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      scanf("%d", &table[i][j]);
    }
  }

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%d", &callednumber);

    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 3; k++) {
        if (callednumber == table[j][k]) {
          iscalled[j][k] = 1;
        }
      }
    }
  }

  for (int i = 0; i < 3; i++) {
    bingo = 1;
    for (int j = 0; j < 3; j++) {
      if (iscalled[i][j] == 0) {
        bingo = 0;
      }
    }

    if (bingo == 1) {
      printf("Yes\n");
      return 0;
    }
  }

  for (int i = 0; i < 3; i++) {
    bingo = 1;
    for (int j = 0; j < 3; j++) {
      if (iscalled[j][i] == 0) {
        bingo = 0;
      }
    }

    if (bingo == 1) {
      printf("Yes\n");
      return 0;
    }
  }

  bingo = 1;
  for(int i = 0; i < 3; i++) {
    if (iscalled[i][i] == 0) {
      bingo = 0;
    }
  }

  if (bingo == 1) {
    printf("Yes\n");
    return 0;
  }

  bingo = 1;
  for (int i = 0; i < 3; i++) {
    if (iscalled[i][2-i] == 0) {
      bingo = 0;
    }
  }

  if (bingo == 1) {
    printf("Yes\n");
    return 0;
  }

  printf("No\n");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
int n, p;
LL odd, even, ans;
int main () {
    scanf ("%d%d", &n, &p);
    for (int i = 1; i <= n; i++) {
        int a;
        scanf ("%d", &a);
        if (a%2 == 0) even++;
        else odd++;
    }
    ans = 1;
    for (int i = 0; i < odd; i++) {
        ans *= 2;
    }
    if (p == 0 && odd == 0) ans *= 2;
    ans /= 2;
    for (int i = 0; i < even; i++) {
        ans *= 2;
    }
    printf ("%lld\n", ans);
}


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

int main() {
    string up, down;
    cin >> up >> down;

    if (up.at(0) == down.at(2) && up.at(1) == down.at(1) && up.at(2) == down.at(0)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

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

        int n = sc.nextInt();

        int[] b = new int[n];

        for (int i=0; i<n-1; i++){
            b[i] = sc.nextInt();
        }

        int[] a = new int[n];
        a[0] = b[0];

        for (int i=1; i<n; i++){
            a[i] = Math.min(b[i-1], b[i]);
        }

        long sum = 0;

        for (int i=0; i<n-1; i++){
            sum += a[i];
        }
        sum += b[n-2];
        System.out.println(sum);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
#define np basic_string::npos
int main(void){
    ll n,in;
    cin>>n;
    bool sw=true;
    vector<int> tab(n,0);
    for(int i=0;i<n;i++){
        cin>>in;
        tab[in]++;
    }
    for(int i=n-1;i>=0;i-=2){
        if(tab[i]!=2&&i!=0)sw=false;
        if(tab[i]!=1&&i==0)sw=false;
    }
    ll ans=1;
    if(sw){
        for(int i=1;i<n;i+=2){
            ans*=2;
            ans%=1000000007;
        }
        cout<<ans<<endl;
    }
    else cout<<"0"<<endl;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

const int MAX = 5010;

class Union_Find {
  public:
    int par[MAX], rank[MAX], size[MAX], gnum;
    int info[MAX];
    
    Union_Find(int N) {
        gnum = N;
        for (int i = 0; i < N; i++) {
            par[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }

    int find(int x)
    {
        if (par[x] == x) {
            return x;
        }
        return par[x] = find(par[x]);
    }

    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y) return;
        
        if (rank[x] < rank[y]) {
            par[x] = y;
            info[y] = min(info[y], info[x]);
            size[y] += size[x];
        } else {
            par[y] = x;
            size[x] += size[y];
            info[x] = min(info[y], info[x]);
            if (rank[x] == rank[y]) {
                rank[x]++;
            }
        }
        gnum--;
    }

    bool same(int x, int y)
    {
        return (find(x) == find(y));
    }

    int getSize(int x)
    {
        return size[find(x)];
    }

    int groups()
    {
        return gnum;
    }
};

int main() {

  int N; cin >> N;

  Union_Find uf(N);
  map<string, int> mp;
  int A[N];
  int v = 0;
  rep(i, N) {
    string s; cin >> s;
    if(mp.find(s) == mp.end()) {
      mp[s] = v++;
    }
    cin >> A[i];
    uf.info[mp[s]] = A[i];
  }

  assert(v == N);

  int M; cin >> M;
  rep(i, M) {
    string s, t ;cin >> s >> t;
    uf.unite(mp[s], mp[t]);
  }

  ll sum = 0;

  rep(i, N) {
    sum += uf.info[uf.find(i)];
  }

  cout << sum << endl;
  
  return 0;
}

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

//BEGIN CUT HERE
template<typename T,bool directed>//directedは有向のこと
struct Fordfulkerson{
  struct edge{
    int to,cap,rev;
    edge(){}
    edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
  };

  vector<vector<edge>> G;
  vector<int> used;

  Fordfulkerson(){}
  Fordfulkerson(int n):G(n),used(n){}//n個の頂点

  void add_edge(int from,int to,T cap){
    G[from].emplace_back(to,cap,G[to].size());//edgeのrevには逆辺の番号が入る
    G[to].emplace_back(from,directed?0:cap,G[from].size()-1);//有向グラフならcapは0
  }

  T dfs(int v,int t,T f){//v->tにfの流量を道が見つかり次第通していく感じ　通った量が返り値
    if(v==t) return f;//ゴール
    used[v]=true;//通った確認
    for(int i=0;i<(int)G[v].size();i++){
      edge &e = G[v][i];
      if(!used[e.to]&&e.cap>0){//まだ通ってなくてcap的にいける場所があるなら
        T d=dfs(e.to,t,min(f,e.cap));//そこからtまで通せるだけ通そうとして見る
        if(d>0){//dだけ通った
          e.cap-=d;//流量を減らす
          G[e.to][e.rev].cap+=d;//逆辺の流量を増やす
          return d;//d通せた
        }
      }
    }
    return 0;
  }

  int flow(int s,int t,T lim){
    T fl=0;
    while(1){
      fill(used.begin(),used.end(),0);//usedの初期化
      T f=dfs(s,t,lim);//sからtまで逆辺を考慮しつつ通す
      if(f==0) break;//全く通らないなら終了
      fl+=f;//通ってるなら流量を増やす
      lim-=f;//初期流量を減らす
    }
    return fl;
  }

  int flow(int s,int t){//全力で流す
    return flow(s,t,numeric_limits<T>::max()/2);
  }

};
//END CUT HERE

signed main(){
  int n,m;cin>>n>>m;
  vector<string> s(n);
  for(int i=0;i<n;i++)cin>>s[i];
  Fordfulkerson<int,1> fl(n*m+2);
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if((i+j)&1){
        fl.add_edge(n*m,i*m+j,1);
        if(i+1<n&&s[i][j]=='.'&&s[i+1][j]=='.')
          fl.add_edge(i*m+j,(i+1)*m+j,1);
        if(i-1>=0&&s[i][j]=='.'&&s[i-1][j]=='.')
          fl.add_edge(i*m+j,(i-1)*m+j,1);
        if(j+1<m&&s[i][j]=='.'&&s[i][j+1]=='.')
          fl.add_edge(i*m+j,i*m+j+1,1);
        if(j-1>=0&&s[i][j]=='.'&&s[i][j-1]=='.')
          fl.add_edge(i*m+j,i*m+j-1,1);
      }
      else fl.add_edge(i*m+j,n*m+1,1);
    }
  }
  cout<<fl.flow(n*m,n*m+1)<<endl;
  for(int i=0;i<n*m;i++){
    for(auto e:fl.G[i]){
      int y1=i/m,x1=i%m,y2=e.to/m,x2=e.to%m;
      if(!((y1+x1)&1)||y2>=n||e.cap)continue;
      if(i>e.to)swap(y1,y2),swap(x1,x2);
      if(y1==y2)s[y1][x1]='>',s[y2][x2]='<';
      else s[y1][x1]='v',s[y2][x2]='^';
    }
  }
  for(int i=0;i<n;i++)cout<<s[i]<<endl;
}


Measured memory_bytes: 4876
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;

int n;
int mp[1<<20];

int tohash(string &s){
	int a = 0;
	FOR(i,n){
		a *= 4;
		if(s[i] == 'r') a += 1;
		else if(s[i] == 'g') a += 2;
		else a += 3;
	}
	return a;
}

int decodeC(int hash,int i){
	return (hash >> (2*i)) & 3;
}

bool OK(int hash){
	int c = decodeC(hash,0);
	for(int i = 1; i < n; i++)
		if(decodeC(hash,i) != c) return false;
	return true;
}

void setC(int& hash,int i,int v){
	hash = (hash & ~(3 << (2*i))) | (v << (2*i));
}

typedef pair<int,int> P;

int main(){
	string s;
	while(cin>>s,s!="0"){
		n = sz(s);
		memset(mp,0x7F,sizeof(mp));
		mp[tohash(s)] = 0;

		int ans = -1;

		priority_queue<P,vector<P>,greater<P> > q;
		q.push(P(0,tohash(s)));

		while(!q.empty()){
			P p = q.top(); q.pop();
			int v = p.second;
			if(mp[v] < p.first) continue;

			if(OK(v)){
				ans = p.first;
				break;
			}

			for(int i = 0; i < n-1; i++){
				int hash = p.second;
				int c = decodeC(hash , i) ^ decodeC(hash, i + 1);
				if(c == 0) continue;
				setC(hash,i,c);
				setC(hash,i+1,c);
				if(mp[hash] > p.first + 1){
					mp[hash] = p.first + 1;
					q.push(P(p.first + 1,hash));
				}
			}
		}

		if(ans == -1) puts("NA");
		else cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 5352
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty())return out;
    constexpr bool is_vector_v = is_vector<T>::value;
    if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
    else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
    return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

vector<int> dp;

void dfs(vector<vector<int>>& path,int v){
    if(path[v].size()==0){
        dp[v] = 0;
    }else{
        vector<int> t;
        REP(i,path[v].size()){
            int next=path[v][i];
            if(dp[next]>=0){
                t.push_back(dp[next]);
            }else{
                dfs(path,next);
                t.push_back(dp[next]);
            }
        }
        sort(all(t));
        int l = t.size();
        REP(i,l){
            t[i]+=l-i;
        }
        dp[v]=*max_element(all(t));
    }
    return;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n,-1);
    dp.resize(n);
    fill(all(dp),-1);
    vector<vector<int>> path(n);
    REP(i,n-1){
        cin >> a[i+1];
        a[i+1]--;
        path[a[i+1]].push_back(i+1);
    }
    dfs(path,0);
    put(dp[0]);
    return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<p> edges;
  ll res = 0;

  for (ll i = 1; i <= n; ++i) {
    res += i * (n-(i-1));
  }
  for (ll i = 0; i < n-1; ++i) {
    ll from, to;
    cin >> from >> to;
    from--; to--;
    edges.push_back({from, to});
    ll minv = min(from, to);
    ll maxv = max(from, to);
    res -= (minv+1) * (n-maxv);
  }
  cout << res << endl;
}


Measured memory_bytes: 7388
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;

int main(){

	ll a, b, k, ans[201]={0};
	cin >> a >> b >> k;
	int n=0;

	for(int i=a; i<a+k; i++){
		ans[n]=i;
		n++;
	}
	for(int i=b; b-k<i; i--){
		ans[n]=i;
		n++;
	}
	sort(ans, ans+n+1);
	for(int i=0; i<201; i++){
		if(ans[i]!=0 && ans[i]!=ans[i+1] && ans[i]<=b && ans[i]>=a){
			cout << ans[i] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, arr[200002],temp;
int main()
{
	cin>>n;
  	for(int i=1;i<n;i++)
    {
      cin>>temp;
      arr[temp-1]++;
    }
  	for(int i=0;i<n;i++)
      cout<<arr[i]<<" ";
}

Measured memory_bytes: 4304
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll N,M,Q;
ll ans;
ll A[50];
ll B[50];
ll C[50];
ll D[50];
ll a[50];
 
 
int main(){
    cin >> N >> M >> Q;
    if((M-1)<=Q){
        ans = N*(M-1)/M;
    } else {
        ans = (N*Q)/M;
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 3624
N = int(input())

ll = [input() for i in range(N)]

zoro_count = 0
for s in ll:
    d1 = s[0]
    d2 = s[2]

    if d1 == d2:
        zoro_count += 1
        if (zoro_count == 3):
            print("Yes")
            quit()
    else:
        zoro_count = 0

print("No")


Measured memory_bytes: 9168
"""

銀貨の枚数,時間で最小値を計算推移？
Sがでかいなら普通に最小距離　おｋ

Sが小さい時
島をcostmax+1個に分ける
→dijkstraで解ける

"""
from collections import deque
N,M,S = map(int,input().split())

lis = [ [] for i in range(N) ]
costsum = 0

for i in range(M):

    U,V,A,B = map(int,input().split())
    U -= 1
    V -= 1

    lis[U].append([V,A,B])
    lis[V].append([U,A,B])

    costsum += A

CD = []
for i in range(N):
    c,d = map(int,input().split())
    CD.append([c,d])

if S >= costsum:

    q = deque([0])
    dis = [float("inf")] * N
    dis[0] = 0

    while len(q) > 0:
        now = q.popleft()
        for i in range(len(lis[now])):
            nex,a,b = lis[now][i]

            if dis[nex] > dis[now] + b:
                dis[nex] = dis[now] + b
                q.append(nex)

    for i in range(1,N):
        print (dis[i])

else:

    import heapq

    dis = [ [float("inf")] * (costsum+1) for i in range(N) ]
    able = [ [True]  * (costsum+1) for i in range(N) ]
    end = 0
    q = [[0,0,S]]
    dis[0][S] = 0

    while len(q) > 0:
        
        if end == (costsum+1)*N:
            break

        ncost,nv,ns = heapq.heappop(q)
        if not able[nv][ns]:
            continue
        able[nv][ns] = False
        end += 1

        for i in range(len(lis[nv])):

            nex,a,b = lis[nv][i]

            if ns >= a and dis[nex][ns-a] > dis[nv][ns] + b:
                dis[nex][ns-a] = dis[nv][ns] + b
                heapq.heappush(q,[dis[nex][ns-a] , nex , ns-a])

        pl = 1
        C,D = CD[nv]
        if ns+C<=costsum and dis[nv][ns+pl*C] > dis[nv][ns] + D:
            dis[nv][ns+pl*C] = dis[nv][ns] + D
            heapq.heappush(q, [dis[nv][ns+pl*C],nv,ns+pl*C])

    #print (dis)
    for i in range(1,N):
        print (min(dis[i]))

Measured memory_bytes: 107368
N,K=map(int,input().split())
ans=float('inf')
point=[tuple(map(int,input().split())) for i in range(N)]
point.sort(key=lambda x:x[0])
for i in range(N-K+1):
    for j in range(i+K,N+1):
        check=point[i:j]
        x=check[-1][0]-check[0][0]
        check.sort(key=lambda x:x[1])
        for k in range(j-i-K+1):
            y=check[k+K-1][1]-check[k][1]
            ans=min(ans,x*y)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    map<char,int>mp;
    string s;
    cin>>s;
    int n=s.length();
    for(long long int i=0;i<n;i++)
    {
        char ch=s[i];
        if(mp[s[i]]!=0)
        {
            cout<<"no";
            return;
        }
        else
        mp[ch]=1;
    }
    cout<<"yes";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define int long long

#define mp make_pair
#define pb push_back
#define mod (int)1e9+7
using namespace std;

signed main(){
    int x,y;
    cin >> x >> y;
    int a,b,c;
    cin >> a >> b >> c;
    int cnt1[a];
    int cnt2[b];
    int cnt3[c];
    for(int i =0;i<a;i++) cin >> cnt1[i];
    for(int i =0;i<b;i++) cin >> cnt2[i];
    for(int i =0;i<c;i++) cin >> cnt3[i];
    multiset<int> s;
    sort(cnt1,cnt1+a);
    sort(cnt2,cnt2+b);
    for(int i = a-1;i >= (a-x);i--) s.insert(cnt1[i]);
    for(int z = b-1;z >= (b-y);z--) s.insert(cnt2[z]);
    for(auto it:cnt3){
        int x = *s.begin();
        if(x < it){
            s.erase(s.begin());
            s.insert(it);
        }
    }
    c = 0;
    for(auto it:s){c += it;}
    cout << c << endl;
}


Measured memory_bytes: 14356
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

#include <queue>

#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define Mabs(a,b) ((a)>(b)?(a)-(b):(b)-(a))
#define Abs(a) (a)>0?(a):(-(a))
template <typename QvQ> inline QvQ Min2(QvQ a,QvQ b){if(a<b) return a;return b;}
template <typename QvQ> inline QvQ Max2(QvQ a,QvQ b){if(a>b) return a;return b;}
template <typename QvQ> inline QvQ Abs2(QvQ a){if(a>0) return a;return -a;}

#define n1kw 10000000
#define inf 0x7f7f7f7f
#define dinf 0x3f3f3f3f
#define llinf 0x7f7f7f7f7f7f7f7f
#define lldinf 0x3f3f3f3f3f3f3f3f

#define ll long long
#define rei register int
#define inv inline void
#define inb inline bool
#define ini inline int

#define bl putchar(' ')
#define ed putchar('\n')
#define test std::cout<<"this:"
#define card system("pause")

#define read2(a,b) read(a),read(b)
#define write2(a,b) write(a),bl,write(b)
#define read3(a,b,c) read(a),read(b),read(c)
#define write3(a,b,c) write(a),bl,write(b),bl,write(c)

//char buf[1<<23],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)

template <typename QvQ>inv read(QvQ &x)
{
	x=0;int f=1;
	char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	x=x*f;
}
template <typename QvQ>inv write(QvQ x)
{
	if(x<0) x=-x,putchar('-');
	if(x>9) write(x/10);
	putchar(x%10+48);
}
using namespace std;
#define MAXN 100005
#define MAXM 200005
ll a,b,c; 
int main()
{
	read3(a,b,c);
	a-=b;
	c-=a;
	if(c<0) c=0;
	write(c);
	return 0;
}

Measured memory_bytes: 256
//20190616
#include <iostream>
#include <vector>
using namespace std;

int main() {
    double w,h,x,y;
    cin >> w >> h >> x >> y;
    double area = w * h/2;

    if(w/2==x && h/2==y)cout << area << " " << 1;
    else cout << area << " " << 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N, M; cin >> N >> M;
  vector<int> a(N + 1, 0);
  REP(i, M) {
    int b; cin >> b;
    a[b] = 1;
  }
  const ll MOD = pow(10, 9) + 7;
  vector<int> dp(N + 1, 0);
  REP(i, N + 1) {
    if(i == 0) {
      dp[i] = 1;
      continue;
    }
    if(a[i] == 1) {
      dp[i] = 0;
      continue;
    } else {
      if(i - 1 >= 0) dp[i] += dp[i - 1];
      if(i - 2 >= 0) dp[i] += dp[i - 2];
      dp[i] %= MOD;
    }
  }
  cout << dp[N] << endl;
}

Measured memory_bytes: 4016
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){
    long long int n, i, j, min, ans=0;
    scanf("%lld", &n);
    long long int p[n];
    for(i=0; i<n; i++) scanf("%lld", &p[i]);

    for(i=0; i<n-2; i++){
        if((p[i]>p[i+1]&&p[i+1]>p[i+2])||(p[i]<p[i+1]&&p[i+1]<p[i+2])) ans++;
    }
    printf("%lld", ans);
}

Measured memory_bytes: 128
s = gets.chomp.split("")

b = 0
l = s.length-1
count = 0

while b<l do
  if s[b] == s[l] then
    b += 1
    l -= 1
  elsif s[b] == "x" then
    count += 1
    b += 1
  elsif s[l] == "x" then
    count += 1
    l -= 1
  else
    puts -1
    exit(0)
  end
end

puts count

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

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


Measured memory_bytes: 3548
/*****/

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

//#define int long long

using namespace std;
using ll = long long;
using ld = long double;
using vecll = vector<ll>;

#define nextline() (std::cerr << "\n")
#define debug(x) (#x " : " + (x))
#define debug_cout(x) (std::cerr << #x << " : " <<  (x) << "\n")
#define debug_tabcout(n, x) (std::cerr << strMulti("\t",n) << #x << " : " <<  (x) << "\n")
#define debug_headcout(h, x) (std::cerr << h << " : " <<  (x) << "\n")
#define debug_tabheadcout(n, h, x) (std::cerr << strMulti("\t",n) << h << " : " <<  (x) << "\n")

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<=i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
constexpr int INF = 2000000100;
constexpr ll DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> T divUp(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
template<class T> T math_C(T m, T n) { T ret = mathP(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
template<class T> bool compare_by_b(pair<T, T> a, pair<T, T> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }
template<class T> T math_gcd(T a, T b) { a = abs(a); b = abs(b); if (a < b) { std::swap(a, b); } T tmp; while (b != 0) { tmp = b; b = a % b; a = tmp; } return a; }
template<class T> T math_lcm(T a, T b) { a = abs(a); b = abs(b); if (a > b) { std::swap(a, b); } if (a == 1) { return b; } T i = a; while (i % b != 0) { i += a; } return i; }

/*****/

void Main()
{
	int n;
	cin >> n;
	vector<int> d(n);
	rep(i, n)	cin >> d[i];

	vector<ll> sum(n + 1);
	rep(i, n)
	{
		sum[i + 1] = sum[i] + d[i];
	}

	ll ret = 0;
	rrep(i, n)
	{
		ret += sum[i] * d[i];
		debug_cout(i);
		debug_tabcout(1, ret);
	}

	cout << ret;
}

/*****/

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

	//std::cout << std::fixed << std::setprecision(10);


	/*
	while (true)
	{
		Main();
		cout << endl;
	}
	//*/


	Main();

	return 0;
}


Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
            int i = 0,j;
            int[] kazu=new int[10000];
            for(i=0;i<10000;i++)
            {
                string inp = Console.ReadLine();
                kazu[i] = int.Parse(inp);
                if (kazu[i] == 0)
                {
                    break;
                }
            }
            for (j = 0; j < i; j++)
            {
                Console.WriteLine("Case {0}: {1}", j + 1, kazu[j]);
            }
    }
}


Measured memory_bytes: 9376
import java.util.Scanner;
import java.util.*;
public class Main {
	
	
	
	public static int Vacation(int n, int h[][]) {
		int dp[][] = new int[n][3];
		
		dp[0][0] = h[0][0];
		dp[0][1] = h[0][1];
		dp[0][2] = h[0][2];
		
		for(int i=1;i<n;i++) {
			for(int j=0;j<3;j++) {
				if(j == 0) {
					dp[i][j] = Math.max(h[i][j] + dp[i-1][1],h[i][j] + dp[i-1][2] );
				}
				else if(j == 1) {
					dp[i][j] = Math.max(h[i][j] + dp[i-1][0],h[i][j] + dp[i-1][2] );
				}
				else if(j == 2) {
					dp[i][j] = Math.max(h[i][j] + dp[i-1][0],h[i][j] + dp[i-1][1] );
				}
			}
		}
		
		int max = Math.max(dp[n-1][0], Math.max(dp[n-1][1], dp[n-1][2]));
		return max;
		
		
	}
    
    public static void main(String[] arg) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int h[][] = new int[n][3];
        for(int i=0;i<n;i++) {
        	int s1 = s.nextInt();
        	int s2 = s.nextInt();
        	int s3 = s.nextInt();
        	h[i][0] =s1;
        	h[i][1] =s2;
        	h[i][2] =s3;
        }
        System.out.println(Vacation(n,h));
    }
}

Measured memory_bytes: 98604
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int n, ans; cin >> n;
    int p[n];
    ans = 0;
    for (int i = 0; i < n; i++)
    {
        int pn;
        cin >> pn;
        p[i] = pn;
    }
    for (int j = 1; j < n - 1; j++)
    {
        if (p[j] != min({p[j - 1], p[j], p[j + 1]}) && p[j] != max({p[j - 1], p[j], p[j + 1]}))
        {
            ans++;
        }
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

bool check(int n){
  bool ret = true;
  string s = to_string(n);
  for(int i = 1; i  < s.size(); i++){
    if(s[i - 1] != s[i])ret = false;
  }
  return ret;
}

int main(){
  int n;
  cin >> n;
  while(!check(n)){
    n++;
  }
  cout << n << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int vy[] = {0, 1, 0, -1}, vx[] = {1, 0, -1, 0};

int H, W, M, cost[3][50][50];
string S[50];
int last[50][50];

bool isgo(int x, int y)
{
  return(0 <= x && x < W && 0 <= y && y < H && S[y][x] == '.');
}

int getCost(int x, int y, int time)
{
  int pv = last[y][x];
  last[y][x] = time;
  if(~pv) {
    return(min(cost[1][y][x] + cost[2][y][x], (time - pv) * cost[0][y][x]));
  } else {
    return(cost[1][y][x] + cost[2][y][x]);
  }
}
int addPath(int px, int py, int x, int y, const int gx, const int gy, int& time)
{
  if(x == gx && y == gy) return(0);
  for(int i = 0; i < 4; i++) {
    int ny = y + vy[i], nx = x + vx[i];
    if((ny != py || nx != px) && isgo(nx, ny)) {
      int ntime = time + 1;
      int next = addPath(x, y, nx, ny, gx, gy, ntime);
      if(~next) {
        int poyo = next + getCost(x, y, time);
        time = ntime;
        return(poyo);
      }
    }
  }
  return(-1);
}

int main()
{
  memset(last, -1, sizeof(last));
  cin >> H >> W >> M;
  for(int i = 0; i < H; i++) {
    cin >> S[i];
  }
  for(int k = 0; k < 3; k++) {
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        cin >> cost[k][i][j];
      }
    }
  }
  int py, px, ret = 0, time = 1;
  for(int i = 0; i < M; i++) {
    int y, x;
    cin >> y >> x;
    if(i > 0) ret += addPath(-1, -1, px, py, x, y, time);
    py = y, px = x;
  }
  cout << ret + getCost(px, py, time) << endl;  
}

Measured memory_bytes: 1392
#include <iostream>
#include <map>

int N, d;
std::map<int, int> mp;

int main() {
    std::cin >> N;
    for (int i=0; i<N; i++) {
        std::cin >> d;
        if (mp.find( d ) != mp.end()) {
            ++mp[d];
        } else {
            mp[d] = 1;
        }
    }
    std::cout << mp.size() << std::endl;
    return 0;
}


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

int main(){
	stack<int> s1;
	stack<pair<int,int> > s2;
	char c;
	int sum=0;
	for(int i=0;cin>>c;i++){
		if(c=='\\')
			s1.push(i);
		else if(c=='/'&&s1.size()){
			int j=s1.top();
			s1.pop();
			int a=i-j;
			sum+=a;
			while(s2.size()&&s2.top().first>j){
				a+=s2.top().second;
				s2.pop();
			}
			s2.push(make_pair(j,a));
		}
	}
	vector<int> v;
	while(s2.size()){
		v.push_back(s2.top().second);
		s2.pop();
	}
	reverse(v.begin(),v.end());
	cout<<sum<<'\n';
	cout<<v.size();
	for(int i=0;i<v.size();i++)
		cout<<" "<<v[i];
	cout<<'\n';
	return 0;
}

Measured memory_bytes: 3180
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	n <- readInt
	as <- sort <$> replicateM n readInt
	let
		coefficients = (  -1 : ( take ( n - 2 ) $ zipWith (*) ( repeat 2 ) ( cycle [ 1, -1 ] ) ) ) ++ [ if n `mod` 2 == 0 then 1 else -1 ]
		f = sum . zipWith (*) as . sort
	print $ uncurry max $ ( f . id &&& f . map negate ) $ coefficients

Measured memory_bytes: 67452
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main(){
  int N,M;
  cin >> N >> M;
  int like[M];
  REP(i,M){
    like[i] = 0;
  }
  REP(i,N){
    int K;
    cin >>K;
    int A;
    REP(j,K){
      cin >>A;
      like[A-1]++;
    }
  }
  int a=0;
  REP(i,M){
    if(like[i]==N){
      a++;
    }
  }
  cout << a <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

int main() {
    int n, m;
    cin >> n >> m;
    cout << ((n - 1) * (m - 1)) << endl;


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        if (a <= 0 && b >= 0) {
            System.out.println("Zero");
            return;
        }
        if (b < 0 && (b - a) % 2 == 0) {
            System.out.println("Negative");
            return;
        }
        System.out.println("Positive");
    }

}


Measured memory_bytes: 21844
#include<cstdio>

int main(){
    unsigned x[5];
    for(int i = 0; i < 5; ++i){
        scanf("%u", x + i);
        if(x[i] != i + 1){
            printf("%u\n", i + 1);
            return 0;
        }
    }
	return 0;
}

Measured memory_bytes: 1708
n = int(input())
a = list(map(int,input().split()))
dic = {}
for i in range(n):
    dic.setdefault(a[i],0)
    dic[a[i]] += 1
ans = 1
for key,value in dic.items():
    #偶数
    if n%2==0:
        if n > key and key%2==1 and value==2:
            ans *= 2
        else:
            ans = 0
            break
    #奇数
    else:
        if n > key and key%2==0:
            if key==0 and value==1:
                ans *= 1
            elif value==2:
                ans *= 2
            else:
                ans = 0
                break
        else:
            ans = 0
            break
print(ans%(10**9+7))

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

struct Ad
{
	int d; //このお菓子を持っている人数
	vector<int> A; //このお菓子を持っているすぬけ君
};

int main()
{
	int N; //すぬけ君の人数
	int K; //お菓子の種類
	cin >> N >> K;

	vector<bool> istrick(N, true);

	vector<Ad> Adall;
	for (int i = 0; i < K; i++)
	{
		Ad tmp;
		cin >> tmp.d;
		for (int j = 0; j < tmp.d; j++)
		{
			int tmp2;
			cin >> tmp2;
			tmp.A.emplace_back(tmp2);

			istrick[tmp2 - 1] = false;
		}
		Adall.emplace_back(tmp);
	}

	int result = 0;
	for (int i = 0; i < N; i++)
	{
		if (istrick[i])
			result++;
	}
	cout << result << endl;


	return 0;
}



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

int main()
{
    int l, r, d;
    cin >> l >> r >> d;

    int ans = 0;
    for(int i = l; i <= r; i++){
        if(i%d==0) ans++;
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  char c;
  bool isFour = false;
  for(int i = 0; i < N; ++i) {
    cin >> c;
    if(c == 'Y') {
      isFour = true;
    }
  }
  cout << (isFour ? "Four" : "Three") << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	#endif
    int l,r,d;
    cin>>l>>r;
    cin>>d;
    l--;
    int ans=r/d- l/d;
    cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define gt(n) scanf("%d", &n)
#define gtll(n) scanf("%ld", &n)
#define out(n) printf("%d", n)
#define outll(n) printf("%ld", n)
#define loop(n) for(int i=0; i<n; i++)
#define MAXX 1001
#define mem(x, y) memset(x, y, sizeof(x))
#define loop1(n) for(int i=1; i<=n; i++)
#define ll long long
#define pb push_back
#define pi acos(-1)
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//(only in c)char[33];itoa(n,buffer,base);printf("%s",buffer);
#define dec_to_bin(n) std::string binary = std::bitset<64>(n).to_string();
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int main()
{
fast;
int k,x;
cin>>k>>x;
for(int i=x-k+1;i<=x+k-1;i++){
cout<<i<<" ";
}
return 0;
}


Measured memory_bytes: 256
K, N = map(int, input().split())
A = [int(x) for x in input().split()]

maxV = 0
ans = 0
for i in range(N-1):
    tmp = A[i+1] - A[i]
    ans += tmp
    maxV = max(tmp, maxV)
ans += K - A[N-1]+A[0]
# print(ans)
maxV = max(maxV, K - A[N-1]+A[0])
print(ans - maxV)
    

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

using namespace std;

#define int long long
#define endl "\n"
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);

void start(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	#ifndef ONLINE_JUDGE
		freopen("in.txt","r",stdin);
		freopen("out.txt","w",stdout);
	#endif

}

double p[3001];
double dp[3001][3001];

double solve(int coins,int head){
	if(head <= 0){
		return 1;
	}

	if(coins ==  0) return 0;

	if(dp[coins][head] > -1) return dp[coins][head];

	double op1 = p[coins] * solve(coins-1,head-1);
	double op2 = (1 - p[coins])*solve(coins-1,head);

	dp[coins][head] = op1+op2;

	return op1+op2;
}



int32_t main(){
	fastIO
	// start();

	memset(dp,-1,sizeof(dp));
	int n;
	cin>>n;

	for(int i=1;i<=n;i++) cin>>p[i];

	cout<<fixed<<setprecision(11)<<solve(n,(n+1)/2);

	// it is said that we need more heads than tails so i 
	// opted for n+1/2 heads

}

Measured memory_bytes: 70784
#!/usr/bin/env python3

cache = {}

def IsOK(n: int):
    if n in [0, 4, 7]:
        return True
    elif n <= 3:
        return False
    elif n in cache:
        return cache[n]
    else:
        cache[n] = IsOK(n - 4) or IsOK(n - 7)
        return cache[n]

N = int(input())
print("Yes" if IsOK(N) else "No")


Measured memory_bytes: 3064