akhauriyash/Code-Regression huggingface dataset:
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a+1):
    for n in range(b+1):
        for m in range(c+1):
            if 500 * i + 100 * n + 50 * m == x:
                ans += 1
print(ans)

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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

int main(int argc, char **argv)
{
	ll N; cin >> N;
	string s, res; cin >> s;

	ll cl{0}, cr{0};

	for (auto &e : s)
	{
		if (e == '(')
		{
			++cr;
		}

		if (e == ')')
		{
			if (cr > 0) --cr;
			else ++cl;
		}
		
	}

	REP(x, cl) std::cout << "(";
	std::cout << s;
	REP(x, cr) std::cout << ")";
	std::cout << std::endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

void Main(){

  string S;
  cin>>S;

  if(S[0]=='S') cout<< "Cloudy"<<"\n";
  if(S[0]=='C') cout<< "Rainy"<<"\n";
  if(S[0]=='R') cout<< "Sunny"<<"\n";


}

  //-----------------------------------
  int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
  }
  //-----------------------------------


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long   // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << "(" << pair_var.first << ", " << pair_var.second << ")";return os;}
// head

int x,t,q,m,n,c,res;
int a[5010000] = {};
int b[5010000] = {};
int k[80] = {};
int mrui[5010000] = {};
vector<PII> g[500010];
queue<int> que2;
ll dp[1000100][4]={};
string s;

signed main() {
	std::cin >>n;
	std::cin >>s;
	std::cin >>q;
	rep(i,0,q){
		std::cin >> k[i];
	}
	rep(i,0,n){
		if(s[i]== 'D'){
			b[i] = 1;
		}
		else if(s[i]== 'M'){
			b[i] = 2;
		}
		else if(s[i]== 'C'){
			b[i] = 3;
		}
	}
	rep(i,1,n+1){
		mrui[i] += mrui[i-1];
		if (b[i-1] == 2){
			mrui[i] += 1;
		}
	}
	rep(i,0,q){
		int sa = k[i];
		ll dp[1000100][4]={};
		dp[0][0] = 1;
		rep(j,1,n+1){
			dp[j][0] += dp[j-1][0];
			dp[j][1] += dp[j-1][1];
			dp[j][2] += dp[j-1][2];
			dp[j][3] += dp[j-1][3];
			if (b[j-1] == 1){
				dp[j][1] += dp[j-1][0];
			}
			else if (b[j-1]==2){
				dp[j][2] += dp[j-1][1];
			}
			else if (b[j-1]==3){
				dp[j][3] += dp[j-1][2];
			}
			if (j>=sa){
				if(b[j-sa] == 1){
					dp[j][1] -= 1;
					dp[j][2] -= (mrui[j]-mrui[j-sa+1]);
				}
			}
		}
			std::cout << dp[n][3] << '\n';
	}
}


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

double Kitaichi(int i){
    return (1+i)/2.0;
}

int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll> p(n,0);
    rep(i,n)cin >> p[i];
    vector<double> Cumulative_sum(n+1,0);

    rep(i,n){//累積和
        Cumulative_sum[i+1] += Kitaichi(p[i]) + Cumulative_sum[i];
    }
    double answer=0.0;
    rep(i,n-k+1){
        if(answer < Cumulative_sum[i+k]-Cumulative_sum[i]){
            answer = Cumulative_sum[i+k]-Cumulative_sum[i];
        }
    }
    cout << fixed << setprecision(10) <<answer;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 3328
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    int n;
    cin >> n >> s;
    int i,j,k;
    long sum=0;
    int r_n[n], g_n[n], b_n[n];
    r_n[n-1] = 0;
    g_n[n-1] = 0;
    b_n[n-1] = 0;
    if(s[n-1]=='R')r_n[n-1]++;
    if(s[n-1]=='G')g_n[n-1]++;
    if(s[n-1]=='B')b_n[n-1]++; 
    for(i=1;i<n;i++){
        r_n[n-1-i] = r_n[n-i];
        g_n[n-1-i] = g_n[n-i];
        b_n[n-1-i] = b_n[n-i];
        if(s[n-1-i]=='R')r_n[n-1-i]++;
        if(s[n-1-i]=='G')g_n[n-1-i]++;
        if(s[n-1-i]=='B')b_n[n-1-i]++; 
    }
    for(i=0;i<n-2;i++){
        for(j=i+1;j<n-1;j++){
            if(s[j]!=s[i]){
                if(abs(s[i]-s[j])==11){
                    //RG
                    sum+=b_n[j+1];
                    if(j+(j-i) < n){
                        if(s[j+j-i]=='B')sum--;
                    }
                }
                if(abs(s[i]-s[j])==5){
                    //GB
                    sum+=r_n[j+1];
                    if(j+(j-i) < n){
                        if(s[j+j-i]=='R')sum--;
                    }
                }
                if(abs(s[i]-s[j])==16){
                    //RG
                    sum+=g_n[j+1];
                    if(j+(j-i) < n){
                        if(s[j+j-i]=='G')sum--;
                    }
                }
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3680
#include<stdio.h>
#define INF 1000000
void warshall_floyd(void);
int min(int,int);
int graph[101][101];
int n,c,d;

int main(void){
  int k,i,j,x,e,a,b;

  while(1){

    scanf("%d %d",&n,&k);
    if(n==0 && k==0)break;

    for(i=0;i<=n;i++)
      for(j=0;j<=n;j++)
	graph[i][j] = (i==j?0:INF);

    for(i=0;i<k;i++){
      scanf("%d",&x);
      
      if(x){
	scanf("%d %d %d",&c,&d,&e);
	if(graph[c][d]>e){
	graph[c][d]=graph[d][c]=e;
	warshall_floyd();
	}
      }
      else{
	scanf("%d %d",&a,&b);
	if(graph[a][b]<INF)printf("%d\n",graph[a][b]);
	else printf("-1\n");
      }

    }

  }
  
  return 0;
}

void warshall_floyd(void){
  int i,j;

    for(i=1;i<=n;i++){
      for(j=1;j<=n;j++){
	graph[i][j]=graph[j][i]=min(graph[i][j],graph[i][c]+graph[c][d]+graph[d][j]);
      }
    }
}

int min(int x,int y){
  return (x<y)?x:y;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main()
{
	int N;
	cin >> N;
	string S;
	cin >> S;
	int K, i;
	cin >> K;
	for (i = 0; i < N; i++)
	{
		if (S[i] != S[K - 1])
			S[i] = '*';
	}
	cout << S;

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int l[n], r[n];
  int ans = 0;
  for(int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
    ans += r[i] - l[i] + 1;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> V(N);
  REP(i, N)
  cin >> V[i];
  int ans = 0;
  for (int a = 0; a <= N; ++a) // 操作Aを行う回数を全探索
  {
    for (int b = 0; a + b <= min(N, K); ++b) // 操作Bを行う回数を全探索
    {
      vector<int> have; // 持っている宝石を格納する配列
      REP(i, a)
      have.push_back(V[i]);
      REP(i, b)
      have.push_back(V[N - 1 - i]);
      sort(ALL(have));
      reverse(ALL(have));                                 // 降順にソート
      int count = K - (a + b);                            // 宝石を捨てられる回数
      while (0 < count && have.size() && have.back() < 0) // 配列の最後の要素(価値が最も小さい宝石)が負でなかったらこれ以上捨てる必要はない
      {
        have.pop_back();
        count--;
      }
      int sum = 0;
      REP(i, have.size())
      sum += have[i];
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;
  return 0;
}

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


int main() {
	int N;
	cin >> N;
	vector<int> t(N);
	vector<int> x(N);
	vector<int> y(N);
	bool ans = true;
	for(int i = 0; i < N; i++){
		cin >> t.at(i) >> x.at(i) >> y.at(i);
	}
	for(int i = 0; i < N; i++){
		double t_gap;
		double x_gap;
		double y_gap;
		if(i == 0){
			t_gap = t.at(i);
			x_gap = x.at(i);
			y_gap = y.at(i);	
		}
		else{
			t_gap = t.at(i) - t.at(i - 1);
			x_gap = abs(x.at(i) - x.at(i - 1));
			y_gap = abs(y.at(i) - y.at(i - 1));
		}
		if(t_gap < x_gap + y_gap){
			ans = false;
			break;
		}
		else if(int(t_gap) % 2 != (int(x_gap) + int(y_gap)) % 2){
			ans = false;
			break;
		}
	}
	if(ans){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

int main() {
    int N, M, A, B;
    cin >> N >> M;
    dsu d = dsu(N);
    for (int i = 0; i < M; i++) {
        cin >> A >> B;
        d.merge(A - 1, B - 1);
    }
    cout << d.groups().size() - 1 << endl;
    return 0;
}


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

AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(N):
    S = input()
    if S == 'AC':
        AC += 1
    elif S == 'WA':
        WA += 1
    elif S == 'TLE':
        TLE += 1
    elif S == 'RE':
        RE += 1
print('AC x ' + str(AC))
print('WA x ' + str(WA))
print('TLE x ' + str(TLE))
print('RE x ' + str(RE))


Measured memory_bytes: 74716
#include <iostream>
#include <cstring>
#include <stack>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int,int> > vp;
vector<pair<double,int> > member;
const double eps=1e-9;
typedef pair<int,int> p;
bool loop[105][105];
int board[105][205];
vector<p> a;
int main()
{
  int n;
  while(1)
    {
      int ans=0;
      cin >> n;
      if(!n) break;
      memset(loop,false,sizeof(loop));
      for(int i=0;i<n;i++)
	{
	  for(int j=0;j<n;j++)
	    {
	      int x,y;
	      cin >> x >> y;
	      board[i][2*j]=x;
	      board[i][2*j+1]=y;
	    }
	}
      for(int i=0;i<n;i++)
	{
	  for(int j=0;j<n;j++)
	    {
	      set<p> st;
	      st.clear();
	      int nowx=j;
	      int nowy=i;
	      if(loop[i][j]) continue;
	      vector<p> tmp;
	      while(1)
		{
		  //cout << " nowy nowx (" << nowy << ' ' << nowx << " )" << endl;
		  auto it=st.find(p(nowx,nowy));
		  if(it!=st.end())
		    {
		      bool forg=false;
		      for(int k=0;k<tmp.size();k++)
			{
			  if(!loop[tmp[k].second][tmp[k].first]) loop[tmp[k].second][tmp[k].first]=true;
			  else 
			    {
			      forg=true;
			    }
			}
		      if(!forg) ans++;
		      break;
		    }
		  else
		    {
		      // cout << nowy << ' ' << nowx << endl;
		      st.insert(p(nowx,nowy));
		      tmp.push_back(p(nowx,nowy));
		      int newnowx=board[nowy][nowx*2];
		      int newnowy=board[nowy][(nowx*2)+1];
		      nowx=newnowx;
		      nowy=newnowy;
		    }
		}
	    }
	}
      cout << ans << endl;
    }
  return 0;
}
      



Measured memory_bytes: 3232
import sys
input = sys.stdin.readline

n, m = [int(x) for x in input().split()]
g = [[] for _ in range(n)]

for _ in range(m):
    l, r, d = [int(x) for x in input().split()]
    g[l - 1].append((r - 1, d))
    g[r - 1].append((l - 1, -d))

d = [None] * n
visited = [0] * n

for i in range(n):
    if visited[i] != 0:
        continue
    stack = [i]
    d[i] = 1
    while stack:
        u = stack.pop()
        visited[u] = 1
        for v, d_ in g[u]:
            if d[v] is None:
                d[v] = d[u] + d_
                stack.append(v)
            else:
                if d[v] != d[u] + d_:
                    print("No")
                    sys.exit()
print("Yes")


Measured memory_bytes: 78384
#include<stdio.h>
#include<math.h>
int main(){
int a[10001],b=2,i,c=3,d=0,x,e,f;
for(i=0;i<10000;){
if(b==2){
a[i]=b;
i++;
}
else if(b==1 || b%2==0){
}
else{
while(c<=sqrt(b)){
if(b%c==0){
d++;
break;
}
c++;
}
if(d==0){
a[i]=b;
i++;
}
}
b++,c=3,d=0;
}
while(1){
scanf("%d\n",&x);
if(x==0){
break;
}
else{
for(i=0;a[i+1]<=x;i++){
if(a[i+1]-a[i]==2){
e=a[i],f=a[i+1];
}
}
printf("%d %d\n",e,f);
}
}
return 0;
}


Measured memory_bytes: 2032
#include <bits/stdc++.h>
using namespace std;
int main (){
       int x,y,xx,yy;
       cin >> x >> y >> xx  >> yy;
       int X = xx - x;
       int Y = yy - y;
       
       for(int i = 1; i <= Y; i++)
              cout<<'U';
              
       for(int i = 1; i <= X + 1; i++)
              cout<<'R';
              
       for(int i = 1; i <= Y + 1; i++)
              cout<<'D';
              
       for(int i = 1; i <= X + 1; i++)
              cout<<'L';
              
       cout<<'U';
       cout<<'L';
       
       for(int i = 1; i <= Y + 1; i++)
              cout<<'U';
              
        for(int i = 1; i <= X + 1; i++)
              cout<<'R';
              
       for (int i = 1; i <= Y+1; i++)
              cout<<'D';
       
       for (int i = 1; i <= X; i++)
              cout<<'L';
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	n:=nextInt()
	k:=nextInt()
	q:=nextInt()
	m := map[int]int{}

	for i:=0;i<q ; i++ {
		a := nextInt()
		o, ok := m[a]
		if ok {
			m[a] = o + 1
		} else {
			m[a] = 1
		}
	}

	for i:=1; i<=n ; i++ {
		if k - (q - m[i]) > 0 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
	log.Printf("%+v", m)
}


Measured memory_bytes: 9344
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int q;
	cin>>q;
	vector<ll> A(q),B(q);
	rep(i,q)cin>>A[i]>>B[i];
	rep(i,q){
		ll a=A[i];
		ll b=B[i];
		if(a>b){
			ll tmp = b;
			b=a;
			a=tmp;
		}
		ll ans = 0;

		if(a==b || a+1==b) ans=2*a-2;
		else{
			ll c = floor(sqrt(a*b));
			if(c*c==a*b)c--;
			if(c*(c+1)>=a*b) ans = 2*c-2;
			else ans = 2*c-1;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main()
{
    int n,a[5000];
    while(scanf("%d",&n),n)
    {
        for(int i=0;i<n;i++)scanf("%d",&a[i]);
        for(int i=0;i<n-1;i++)a[i+1]+=a[i];

        int ma=-100000000;

        for(int l=0;l<n;l++){
            for(int r=l;r<n;r++){
                int sum;
                if(l==0)sum=a[r];
                else sum=a[r]-a[l-1];
                if(ma<sum)ma=sum;
            }
        }

        printf("%d\n",ma);
    }
    return 0;
}

Measured memory_bytes: 1048
void main(){
	long n, k, cnt;
	readf("%d %d", &n, &k);
	while(n >= k){
		cnt++;
		n /= k;
	}
	cnt++;
	cnt.writeln();
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2780
/**
 * knapsack problem
 * 0-1 ??¨??°????????????????????????????????§????????????
 */

#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define DEBUG
#undef DEBUG

int N, W;
int VS[101];
int WS[101];

void solve()
{
    // i???????????§??????????????????j?????\????????¨???????????§??????
    int dp[101][10001];

    // ???????????\???????????´??????????????????????????????0
    FOR(j, 0, W+1) {
        dp[0][j] = 0;
    }

    // DP
    // i????????????????????\????????????????????§??´?????????
    // ????????? j < WS[i] ????????\???????????????
    //   ??\???????????´??????dp[i-1][j] ????????§??????
    //   ??\????????´??????VS[i] + dp[i][j-WS[i]] ????????§??????
    //     (0-1 ?????´??????????????? VS[i] + dp[i-1][j-WS[i]] ?????????)
    FOR(i, 1, N+1) {
        FOR(j, 0, W+1) {
            if(j < WS[i]) {
                dp[i][j] = dp[i-1][j];
            }
            else {
                dp[i][j] = max(dp[i-1][j], VS[i] + dp[i][j-WS[i]]);
            }
        }
    }

#ifdef DEBUG
    FOR(i, 0, N+1) {
        FOR(j, 0, W+1) {
            cout << dp[i][j] << " ";
        }
        cout << "\n";
    }
#endif

    cout << dp[N][W] << "\n";
}

int main()
{
    cin >> N >> W;
    REP(i, N) {
        cin >> VS[i+1] >> WS[i+1];
    }

    solve();

    return 0;
}

Measured memory_bytes: 7068
var n,i,tot:longint;
	last,pre,other,anss,a,now:array[0..500007] of longint;
procedure insert(u,v:longint);
begin
  inc(tot);
  other[tot]:=v;
  pre[tot]:=last[u];
  last[u]:=tot;
end;
procedure qsort(lx,rx:longint);
var i,j,m,t:longint;
begin
  i:=lx;j:=rx;m:=now[(lx+rx) div 2];
  repeat
	while (now[i]<m) do inc(i);
	while (now[j]>m) do dec(j);
	if (i<=j) then
	begin
	  t:=now[i];now[i]:=now[j];now[j]:=t;
	  inc(i);dec(j);
	end;
  until (i>j);
  if (i<rx) then qsort(i,rx);
  if (j>lx) then qsort(lx,j);
end;
procedure dfs(u,father:longint);
var q,v,i,tott:longint;
begin
  q:=last[u];
  while (q>0) do
  begin
    v:=other[q];
    if (v<>father) then dfs(v,u);
	q:=pre[q];
  end;
  tott:=0;
  q:=last[u];
  while (q>0) do
  begin
    v:=other[q];
    if (v<>father) then
	begin
	  inc(tott);
	  now[tott]:=anss[v];
	end;
	q:=pre[q];
  end;
if (tott<>0) then
begin
  qsort(1,tott);
  anss[u]:=0;
  for i:=1 to tott do
	if (now[i]+tott+1-i>anss[u]) then anss[u]:=now[i]+tott+1-i;
end else anss[u]:=0;
end;
begin
  readln(n);
  fillchar(a,sizeof(a),0);
  tot:=0;
  for i:=2 to n do
  begin
	readln(a[i]);
    insert(i,a[i]);insert(a[i],i);
  end;
  fillchar(anss,sizeof(anss),0);
  dfs(1,0);
  writeln(anss[1]);
end.
  

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

#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define all(v) v.begin(), v.end()
#define ar array

#define F first
#define S second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
using ld = long double;

// const int mod = 1e9 + 7;
const int mod = 998244353;
const ll inf = 2e9;
const ll INF = 1e18;
const ld EPS = 1e-7;

const int N = 1e6 + 5;

ll a[N];

void solve () {
	int n; ll m;
	cin >> n >> m;
	ll L = 1;
	for (int i = 1 ; i <= n ; ++ i) {
		cin >> a[i];
		L = (L * a[i]) / __gcd (a[i], L);
	}
	ll k = L / 2;
	for (int i = 1 ; i <= n ; ++ i) {
		if (k % a[i] != a[i] / 2) {
			cout << 0;
			return;
		}
	}
	cout << m / L + (m % L >= k);
}

int main () {
	ios;
	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
		cout << "\n";
	}
}




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

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max({a*c,a*d,b*c,b*d})<<'\n';
return 0;


}

//      *   *  *****  *   *  *   *   ****  ****    ****     **  ***
//     *   *  *      **  *  *   *  *      *   *  *        * *  *  *
//    *****  *****  * * *  *   *  *      ****   *       *  *    *
//   *   *      *  *  **  *   *  *      *  *   *       *****  *
//  *   *  *****  *   *   ***    ****  *   *   ****      *  ****

//     ****  *   *  *   *   ***   *   *  *****  *   *
//    *     *   *  *   *  *   *  *   *  *      *   *
//    ***  *****  *   *  *****  * * *  ****   *   *
//      *   *    *   *  *   *  * * *  *      *   *
//  ****   *     ***   *   *   * *   *****   ***

//        ********                                 . O .
//      *           *                               . .
//     *            * *       * ********
//    * ***********    *    *  *         *
//    *                 * *      *********
//                      *                 *
//                 *   *
//                   *  *
//                     **
//                   *  **  *
//              *  *    * **
//                *     ** * *
//            *   **   ** * *  * *
//           *    * * * * * *   **
//          **************************






Measured memory_bytes: 3684
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()

int main() {
	ll x;
	cin >> x;
	ll now = 100;
	ll ans = 0;
	while (now < x) {
		now = (ll)(now * 1.01);
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3188
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int wa10(char* num){
  int ii,wa=0;

  for(ii=0;ii<strlen(num);ii++){
	wa += num[ii] - '0';
  }
  
  return wa;
  
}
int main(){
  int n,a,b,ii;
  long wa,waSum;
  vector<int> vec;

  cin >> n >> a >> b;
  vec.resize(n);
  char num[6];

  for(ii=1;ii<=n;ii++){
	sprintf(num,"%d",ii);
	wa = wa10(num);
	//cout << wa << endl;
	if(wa >= a && wa <= b){
	  vec.push_back(ii);
	}
  }

  waSum = 0;
  for(auto v : vec){
	waSum += v;
  }
  cout << waSum << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	int N, K;
	cin >> N >> K;

	int ret = 0;
	for(int i=0; i<N; i++)
	{
		int x;
		cin >> x;

		ret += min(x, K-x);
	}

	ret *= 2;

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()

a, b = ZIP(M)

a_cnt, b_cnt = Counter(a), Counter(b)

for i in range(1, N+1):
	if (a_cnt[i]+b_cnt[i])%2 != 0:
		print("NO")
		break
else:
	print("YES") 


Measured memory_bytes: 59608
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
typedef long long ll;

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

const ll INFLL = 1e18;
int main() {
    int N,T;
    cin>>N>>T;
    vector<ll> A(N),B(N);
    rep(i,N)cin>>A[i]>>B[i];
    /*
    dp1[i][t]:1~iまでの食べ物でt秒以内に完食して得られる満足度の最大値
    dp2[i][t]:N~iまでの食べ物でt秒以内に完食して得られる満足度の最大値
    => dp1[i-1][t] + dp2[i+1][T-1-t]:i以外の食べ物でT-1秒以内に完食して得られる満足度の最大値
       これにB[i+1]を足せば、OK
    */
    vector<vector<ll>> dp1(N+2,vector<ll>(T,-INFLL));
    vector<vector<ll>> dp2(N+2,vector<ll>(T,-INFLL));
    rep(t,T){
        dp1[0][t] = 0;
        dp2[N+1][t] = 0;
    }
    rep(i,N)rep(t,T){
        chmax(dp1[i+1][t], dp1[i][t]);
        if(t + A[i] < T){
            chmax(dp1[i+1][t+A[i]],dp1[i][t] + B[i]);
        }
    }
    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());
    rep(i,N)rep(t,T){
            chmax(dp2[N+1-i-1][t], dp2[N+1-i][t]);
            if(t + A[i] < T){
                chmax(dp2[N+1-i-1][t + A[i]],dp2[N+1-i][t] + B[i]);
            }
    }
    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());
    ll ans = 0;
    rep(i,N){
        rep(t,T){
            chmax(ans, dp1[i][t] + dp2[i+2][T-1-t] + B[i]);
        }
    }
    cout<<ans<<endl;
}

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

constexpr const std::int_fast64_t INF = std::numeric_limits<std::int_fast64_t>::max();

constexpr std::int_fast64_t safe_sum(const std::int_fast64_t a, const std::int_fast64_t b) {
  return a == INF || b == INF ? INF : a + b;
}

std::vector<std::vector<std::int_fast64_t>> warshall_floyd(const std::vector<std::vector<std::int_fast64_t>>& expected) {
  const std::int_fast64_t n = expected.size();

  std::vector<std::vector<std::int_fast64_t>> actual = expected;
  for (std::int_fast64_t k = 0; k < n; ++k) {
    for (std::int_fast64_t i = 0; i < n; ++i) {
      for (std::int_fast64_t j = 0; j < n; ++j) {
        actual[i][j] = std::min(actual[i][j], safe_sum(actual[i][k], actual[k][j]));
      }
    }
  }
  return actual;
}

std::int_fast64_t calc_answer(const std::vector<std::vector<std::int_fast64_t>>& actual) {
  const std::int_fast64_t n = actual.size();

  std::int_fast64_t answer = 0;
  for (std::int_fast64_t i = 0; i < n; ++i) {
    for (std::int_fast64_t j = 0; j < n; ++j) {
      if (i >= j) continue;

      std::int_fast64_t alternative_distance = INF;
      for (std::int_fast64_t k = 0; k < n; ++k) {
        if (k == i || k == j) continue;
        alternative_distance = std::min(alternative_distance, safe_sum(actual[i][k], actual[k][j]));
      }

      if (actual[i][j] < alternative_distance) answer += actual[i][j];
    }
  }
  return answer;
}

int main() {
  std::int_fast64_t n;
  std::cin >> n;
  std::vector<std::vector<std::int_fast64_t>> a(n, std::vector<std::int_fast64_t>(n));
  for (std::int_fast64_t i = 0; i < n; ++i) {
    for (std::int_fast64_t j = 0; j < n; ++j) {
      std::int_fast64_t a_ij;
      std::cin >> a_ij;
      a[i][j] = a_ij;
    }
  }

  std::cout << (a == warshall_floyd(a) ? calc_answer(a) : -1) << std::endl;
  return 0;
}

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

int main(void){
    string w;
    cin >> w;

    int n = w.size();

    bool flag = true;

    for(int i = 0; i < n; i++){
        int cnt = 0;
        for(int j = 0; j < n; j++){
            if(w.at(j) == w.at(i)) cnt++;
        }
        if(cnt % 2 == 1) flag = false;
    }

    if(flag) {
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	int c;
	int d;

	scanf("%d", &a);

	b=a/3600;
	c=(a%3600)/60;
	d=(a%3600)%60;

	printf("%d:%d:%d\n", b, c, d);

	return 0;

}

Measured memory_bytes: 592
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp11
{
    class Class37
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long sum = A.Sum();
            long a = sum, b = 0;
            long ans = 2020202020;
            for(int i = 0; i < N; i++)
            {
                a -=A[i];
                b += A[i];
                ans = Math.Min(ans, Math.Abs(a - b));
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 39248
#include<iostream>
#include<algorithm>
#include<map>

using namespace std;

typedef long long ll;

int N;
ll A[100000 * 2 + 10];
bool used[100000 * 2 + 10];
map<ll, int> numcnt;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++)cin >> A[i], numcnt[A[i]]++;
	sort(A, A + N);
	int ans = 0;
	for (int i = N - 1; i >= 0; i--) {
		if (used[i])continue;
		for (int j = 33; j >= 0; j--) {
			ll mokuhyo = 1LL << j;
			if (binary_search(A, A + N, mokuhyo - A[i])) {
				if (mokuhyo != A[i] * 2) {
					auto ptr = upper_bound(A, A + N, mokuhyo - A[i]);
					ptr--;
					auto cpyAminus = A;
					cpyAminus--;
					while (ptr != cpyAminus && used[ptr - A])ptr--;
					if (ptr == cpyAminus || mokuhyo - A[i] != *ptr) continue;
					used[i] = true;
					used[ptr - A] = true;
					ans++;
					numcnt[A[i]]--;
					numcnt[A[ptr - A]]--;
					goto nxtnumber;
				}
				else {
					//複数個あるかつ同じもの２つで2^iになるのは、最後にまとめる。
				}
			}
		}
		used[i] = true;
	nxtnumber:;
	}
	for (auto it = numcnt.begin(); it != numcnt.end(); it++) {
		bool f = false;
		for (int i = 0; i < 35; i++) {
			if ((1LL << i) == (*it).first)f = true;
		}
		if (!f)continue;
		ans += (*it).second / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 14464
#include<bits/stdc++.h>
using namespace std;
int n,ans[10010];
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		if(i==0)ans[0]+=x;
		x=n-x;
		for(int j=1;j<n;j++){
			ans[n-j]=(ans[n-j]+x)%n;
			x=(x*i)%n;
		}
	}
	for(int i=0;i<n;i++) cout<<ans[i]<<' ';
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
int main()
{
    int n, k; cin>>n>>k;
    if(k&1){
        cout<<0<<endl;
        return 0;
    }
    ll dp[51][51][2601]={};
    dp[0][0][0]=1;
    for(int i=0; i<n; i++){
        for(int j=0; j<=i; j++){
            for(int l=0; l<=i*i; l+=2){
                (dp[i+1][j][l+2*j]+=dp[i][j][l])%=MOD;
                (dp[i+1][j][l+2*j]+=2*j*dp[i][j][l])%=MOD;
                if(j) (dp[i+1][j-1][l+2*j]+=j*j*dp[i][j][l])%=MOD;
                (dp[i+1][j+1][l+2*j]+=dp[i][j][l])%=MOD;
            }
        }
    }
    cout<<dp[n][0][k]<<endl;
    return 0;
}

Measured memory_bytes: 53120
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair<int, int> pii;  // pair<int, int> に pii という別名を付ける
typedef long long ll;
typedef unsigned long long ull;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ull N;
  cin >> N;
  ull year = 0;

  for (ull account = 100; ; ){
    account = account * 1.01;
    year ++;
    if(account >= N){
      break;
    }
  }

  cout << year << endl;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)turn idx;
#define deg_to_rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad_to_deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)

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

int main() {
  int r;
  cin >> r;
  cout << r * r << endl;
};


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

using namespace std;


void solve() {
    int n; cin >> n;
    vector<vector<int>> a(n, vector<int> (n-1));
    for (int i = 0; i < n; i++) {
        for (int j = n-2; j >= 0; j--) {
            int x; cin >> x;
            a[i][j] = x-1;
        }
    }
    int TOT = n*(n-1)/2;
    set<int> now;
    for (int i = 0; i < n; i++) {
        now.insert(i);
    }
    int tot = TOT;
    for (int d = 1; d <= TOT; d++) {
        int cnt = 0;
        set<int> later;
        for (int i: now) {
            if (a[i].empty() || later.find(i) != later.end()) continue;
            int j = a[i].back();
            if (later.find(j)!=later.end() || a[j].empty() || a[j].back()!=i) continue;
            later.insert(i);
            later.insert(j);
            a[i].pop_back();
            a[j].pop_back();
            cnt++;
        }
        if (cnt == 0) {
            cout << -1; return;
        }
        tot -= cnt;
        if (tot == 0) {
            cout << d; return;
        }
        now = later;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

using namespace std;

int main() {
  int n, q;
  cin >> n >> q;
  string s; cin >> s;

  vector<int> sum(n+1, 0);
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A' && s[i+1] == 'C') {
      sum[i+1] = sum[i] + 1;
    } else {
      sum[i+1] = sum[i];
    }
  }

  while (q--) {
    int l, r; cin >> l >> r;
    l--; r--;
    cout << sum[r] - sum[l] << endl;
  }
  return 0;
}

Measured memory_bytes: 1408
N = int(input())
S = input()

sum_W = [0] * (N+1)
sum_E = [0] * (N+1)

for i in range(N):
    if S[i] == "W":
        sum_W[i+1] = sum_W[i] + 1
        sum_E[i+1] = sum_E[i]
    else:
        sum_W[i+1] = sum_W[i]
        sum_E[i+1] = sum_E[i] + 1

answers = []
for i in range(N):
    answer = sum_W[i] + (sum_E[N] - sum_E[i+1])
    answers.append(answer)

print(min(answers))

Measured memory_bytes: 29708
#include <math.h>

#include <algorithm>
#include <cassert>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  rep(i, N) cin >> p.at(i);

  sort(p.begin(), p.end());

  int sum = 0;

  rep(i, K) { sum += p.at(i); }

  cout << sum << endl;
}


Measured memory_bytes: 3568
#include<stdio.h>
#include<string.h>
main(){
    char S[201];
    scanf("%s",S);
    int len = strlen(S)%2==0?strlen(S)/2-1:strlen(S)/2;
    loop:
        for(int i = 0;i < len;i++){
            if(S[i] != S[i+len]){
                len--;
                goto loop;//偶数列でなかったらもう一回
            }
        }
    printf("%d\n",len*2);
}
/*
偶数列となると仮定して比較
最低でも１文字以上削ることに注意
*/

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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    if(s[3]==s[2]&&s[4]==s[5])
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


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

int main(){
  int N, D, X;
  cin >> N >> D >> X;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  int ans = 0;
  for(int i = 0; i < N; i++){
    for(int j = 1; j <= D; j+=A[i]){
      ans+=1;
    }
  }
  cout << ans + X << endl;
}


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

int dp[100001];

int func(int *a,int i,int n)
{
	if(i>=n-1)
		return 0;
	if(i==n-2)
	{
		return abs(a[n-1]-a[n-2]);
	}
	if(dp[i]!=-1)
	return dp[i];
	dp[i]=min(func(a,i+1,n)+abs(a[i]-a[i+1]),func(a,i+2,n)+abs(a[i]-a[i+2]));
	return dp[i];
}

int main()
{
	for(int i=0;i<100001;i++)
	dp[i]=-1;
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	cout<<func(a,0,n)<<endl;
}


Measured memory_bytes: 8280
#include<bits/stdc++.h>
using namespace std;
#define int long long
int m[1111111];
signed main(){
  int x,y;
  while(cin>>x>>y,x||y){
    int c=0;
    memset(m,-1,sizeof(m));
    while(m[x]<0){
      m[x]=c++;
      x=(x*10)%y;
      if(!x) break;
    }
    if(!x) cout<<c<<" "<<0<<endl;
    else cout<<m[x]<<" "<<c-m[x]<<endl;
  }
  return 0;
}

Measured memory_bytes: 11716
//
// Created on 2020/08/08.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset￿
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;



int main() {
    int n;
    int m;
    cin>>n>>m;
    map<ll,ll, greater<ll>>card;//map降順ソート
    for (int i = 0; i < n; ++i) {
        ll tmp;
        cin>>tmp;
        card[tmp] ++;
    }
    for (int i = 0; i < m; ++i) {
        ll b,c;
        cin>>b>>c;
        card[c] += b;
    }
    ll sum = 0;
    ll now_num = 0;
    for(auto c:card){
        ll card_num = c.first;
        ll num = c.second;
        if(now_num + num <= n){
            sum += card_num * num;
            now_num += num;
        }else{
            sum += card_num * (n - now_num);
            now_num += (n - now_num);
        }
        if(now_num >= n)break;
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 16100
/*
AUTHOR: Aman Raj
LANG: C++
*/

using namespace std;

typedef   long long  int ll;
#include <bits/stdc++.h>


//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
#define fast  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
#define all(a) a.begin(),a.end()
//#define mod 998244353


#define mod   1000000007

#define inf 1e18
//#define mod 3
#define flush fflush(stdout)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<ll, ll, hash< ll > > ht;

// find_by_order()  // order_of_key
typedef tree<
    ll,
    null_type,
    less<ll>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;






ll power1(ll a, ll b)//a raised to power b
   {  if(b<=0) return 1; if(b==1) return a;
       ll c=power1(a,b/2);
        c*=c;c%=mod;if(b%2==1) c*=a;c%=mod;
        return c;
   }
   ll mi(ll a,ll m)
   { ll c= power1(a,m-2);

     return c;
   }



 struct less_then_greater {
    template<typename T, typename U>
    bool operator()(T const& lhs, U const& rhs) const {
        if (lhs.first < rhs.first) return true;
        if (rhs.first < lhs.first) return false;
        return lhs.second > rhs.second;
    }
};

 /*std::priority_queue<std::pair<int, int>,
                    std::vector<std::pair<int, int>>,
                    less_then_greater
                    > pq;*/


  int main()
{  fast;
    string s;cin>>s;
    map<string,ll> mpp;
     mpp["SUN'"]=0; mpp["MON"]=1; mpp["TUE"]=2; mpp["WED"]=3; mpp["THU"]=4; mpp["FRI"]=5;mpp["SAT"]=6;
    ll a=mpp[s];
    cout<<7-a;
   return 0;
}


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

constexpr int64_t MOD = 1000000007;

int64_t Power(int64_t base, int64_t exp) {
  int64_t x = 1;
  while (exp) {
    if (exp % 2) {
      x = x * base % MOD;
    }
    base = base * base % MOD;
    exp /= 2;
  }
  return x;
}

int64_t Inv(int64_t x) {
  return Power(x, MOD - 2);
}

int64_t Factorial(int64_t x) {
  static vector<int64_t> xs;
  if (xs.size() == 0) {
    xs.resize(100002);
    xs[0] = 1;
    for (int i = 1; i < xs.size(); ++i) {
      xs[i] = xs[i - 1] * i % MOD;
    }
  }
  return xs[x];
}

int64_t InvFact(int64_t x) {
  static vector<int64_t> xs;
  if (xs.size() == 0) {
    xs.resize(100002);
    xs[100001] = Inv(Factorial(100001));
    for (int i = 100000; i >= 0; --i) {
      xs[i] = xs[i + 1] * (i + 1) % MOD;
    }
  }
  return xs[x];
}

int64_t Combination(int64_t n, int64_t r) {
  if (n < r) return 0;
  int64_t x = Factorial(n);
  x = x * InvFact(r) % MOD;
  x = x * InvFact(n - r) % MOD;
  return x;
}

int main() {
  int n, l, r;
  cin >> n;
  vector<int> xs(n + 2);
  unordered_map<int, int> indice;  // index from value.
  for (int i = 1; i <= n + 1; ++i) {
    cin >> xs[i];
    if (indice.find(xs[i]) == indice.end()) {
      indice[xs[i]] = i;
    } else {
      l = indice[xs[i]];
      r = i;
    }
  }
  for (int k = 1; k <= n + 1; ++k) {
    int64_t x0, x1, x2;
    x0 = Combination(n + 1, k);
    x1 = Combination((l - 1) + (n + 1 - r), k - 1);
    x2 = (x0 - x1 + MOD) % MOD;
    cout << x2 << endl;
  }
}


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

int main(void) {
	int n, m, l;
	int sum;
	while (cin >> l, l) {
		sum = 0;
		bool f = false;
		for (int i = 0; i < 12; i++) {
			cin >> n >> m;
			sum += n - m;
			if (sum >= l&&f==false) {
				cout << i + 1 << endl;
				f = true;
			}
		}
		if (f == false) cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}



int N;
vector<double> x, y;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> N) {
        x.resize(N); y.resize(N);
        for (int i = 0; i < N; ++i) cin >> x[i] >> y[i];

        double sum = 0;
        vector<int> ord(N);
        for (int i = 0; i < N; ++i) ord[i] = i;
        do {
            double tmp = 0;
            for (int i = 0; i + 1 < N; ++i) {
                double dx = abs(x[ord[i]] - x[ord[i+1]]);
                double dy = abs(y[ord[i]] - y[ord[i+1]]);
                tmp += sqrt(dx * dx + dy * dy);
            }
            sum += tmp;
        } while (next_permutation(ord.begin(), ord.end()));

        for (int i = 1; i <= N; ++i) sum /= i;
        cout << fixed << setprecision(10) << sum << endl;
    }
}


















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

int main(void) {
    int N;
    cin >> N;
    vector<int> w(N,0);
    vector<int> e(N,0);
    string S;
    cin >> S;
    if(S[0] == 'W') w[0] = 1;
    for(int i=1; i<N; i++) {
        if(S[i] == 'W') w[i] = w[i-1] + 1;
        else w[i] = w[i-1];
    }
    if(S[N-1] == 'E') e[N-1] = 1;
    for(int i=N-2; i>=0; i--) {
        if(S[i] == 'E') e[i] = e[i+1] + 1;
        else e[i] = e[i+1];
    }
    int ans = INT_MAX;
    for(int i=0; i<N; i++) ans = min(ans, w[i]+e[i]-1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3204
s=[]
p=[]
a=i=0
for c in input():
 if"\\"==c:s+=[i]
 if"/"==c and s:
  j=s.pop()
  t=i-j
  a+=t
  while p and p[-1][0]>j:t+=p.pop()[1]
  p+=[(j,t)]
 i+=1
print(a)
if p:print(len(p),*list(zip(*p))[1])
else:print(0)



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

int main() {
    int n,h,w;
    cin >> n >> h >> w;
    vector<int> height(n);
    vector<int> wide(n);
    for(int i = 0; i < n; i++){
        cin >> height.at(i) >> wide.at(i);
    }
    int count = 0;
    for(int i = 0; i < n; i++){
        if(height.at(i) >= h && wide.at(i) >= w){
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check
ll INF = 1LL << 60;

void solve(long long N, std::vector<long long> A){
    vll sum(N+1, 0);
    REP(i, N){
        sum[i+1] = sum[i]+A[i];
    }
    ll s = sum[N];
    ll res = INF;
    for(ll i=1; i<= N-1; i++){
        res = min(res, abs(sum[i]-(s-sum[i])));
    }
    cout << res << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 3328