akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  int N; cin>>N;
  vector<int> x(N);
  vector<int> y(N);
  for(int i=0; i<N; i++){
    cin>>x.at(i)>>y.at(i);
  }
   
  double ans=0;
  
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      double A;
      A=sqrt(pow(x.at(i)-x.at(j),2)+pow(y.at(i)-y.at(j), 2))/N;
      ans+=A;
    }
  }
  
  cout<<fixed<<setprecision(13)<<ans<<endl;
}

Measured memory_bytes: 256
import math
a,b,x=map(int,input().split())
if 2*x>=a*a*b:
  y=a*a*b-x
  bb=(2*y)/(a*a)
  ans=math.degrees(math.atan(bb/a))
  
else:
  bb=2*x/(a*b)
  ans=math.degrees(math.atan(b/bb))
  
print(ans)
  

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int cntMinus = 0;
    long long smallest = 10000000000;
    long long tmp;
    for (int i=0; i<n; i++) {
        cin >> tmp;
        cntMinus += (tmp < 0);
        tmp = abs(tmp);
        a[i] = tmp;
        smallest = min(smallest, tmp);
    }
    long long ans = 0;
    for (int i=0; i<n; i++) ans += a[i];
    if (cntMinus % 2 == 1) ans -= smallest * 2;
    cout << ans << endl;
}

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

int main(){
    int N; cin >> N;
    vector<int> v;
    v.push_back(0);
    for(int i=0; i<N; ++i){
        int a; cin >> a;
        v.push_back(a);
    }
    v.push_back(0);
    int S=0;
    for(int i=0; i<v.size()-1; ++i) S+= abs(v[i]-v[i+1]);
    
    for(int i=1; i<v.size()-1; ++i){
        cout << S + abs(v[i-1]-v[i+1]) -(abs(v[i]-v[i-1])+abs(v[i+1]-v[i])) << endl;
    }
}

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

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

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;string s;
  cin >> n >> s;
  int ans = 0;
  rep(i,n-2) if(s.substr(i,3)=="ABC") ++ans;
  cout << ans << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

vector<int> z_algorithm(vector<char> s){
    int n = s.size();
    vector<int> ret(n);
    ret[0] = n;
    int i = 1, j = 0;
    while(i < n){
        while(i+j < n && s[j] == s[i+j]) j++;
        ret[i] = j;
        if(j == 0) {i++; continue;}
        int k = 1;
        while(i+k < n && k+ret[k] < j) {ret[i+k] = ret[k], k++;}
        i += k, j -= k;
    }
    return ret;
}

const int MAX_V = 5e5;
vector<int> es[MAX_V], rs[MAX_V];
vector<int> vs;
vector<bool> used(MAX_V, false);

void add_edge(int from, int to){
    es[from].pb(to), rs[to].pb(from);
}

void dfs(int now){
    used[now] = true;
    for(auto &e: es[now]) if(!used[e]) dfs(e);
    vs.pb(now);
}

bool find_loop(){
    rep(i, MAX_V) if(!used[i]) dfs(i);
    fill(all(used), false);
    rep3(i, (int)vs.size()-1, 0){
        int j = vs[i];
        for(auto &e: rs[j]){
            if(!used[e]) return true;
        }
        used[j] = true;
    }
    return false;
}

vector<int> mp(MAX_V, -1);

int max_path(int now){
    int ret = 0;
    for(auto &e: es[now]){
        if(mp[e] == -1) ret = max(ret, max_path(e)+1);
        else ret = max(ret, mp[e]+1);
    }
    mp[now] = ret;
    return ret;
}

int main(){
    string S, T;
    cin >> S >> T;
    vector<char> s;
    int N = S.size(), M = T.size();
    rep(i, M) s.pb(T[i]);
    int n = 0;
    while(n < N+M){
        rep(i, N) s.pb(S[i]);
        n += N;
    }
    vector<int> res = z_algorithm(s);
    rep(i, N){
        if(res[M+i] >= M){
            int j = (i+M)%N;
            add_edge(i, j);
        }
    }
    if(find_loop()) {cout << -1 << endl; return 0;}
    int ans = 0;
    rep(i, N){
        ans = max(ans, max_path(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 95192
#include <iostream>
#include <iomanip>
#include <utility>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <map>
#include <climits>
#include <bitset>

#define ll long long
const ll INF = 1 << 29;
const ll MOD = 1e9 + 7;

ll Add(ll a, ll b)
{
    ll result = a + b;
    return result % MOD;
}

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

    const ll pattern = 1 << N;
    std::vector<ll> dp(pattern, 0);

    int a[N][N];
    memset(a, 0, sizeof(a));

    for (auto i=0; i<N; ++i)
    {
        for (auto j=0; j<N; ++j)
        {
            std::cin >> a[i][j];
        }
    }

    dp[0] = 1;
    for (auto bit=0; bit< 1<<N; ++bit)
    {
        // すでに男 i 人目までチェック済み
        auto i= __builtin_popcount(bit);
        for (auto j=0; j<N; ++j)
        {
            // 女j とマッチする -> 直前までで j がマッチングしてないとき + この組み合わせ
            if ( ((bit >> j) & 1) == 1 && a[i-1][j] == 1 )
                dp[bit] = Add(dp[bit], dp[bit ^ (1 << j)]);
        }
    }

    std::cout << dp[(1 << N) - 1] << std::endl;
}

Measured memory_bytes: 19596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
map<ll,bool> m;
ll n,i,k;
int main()
{
	cin>>n;
	for (i=1;i<=n;i++)
	{
		scanf("%lld",&k);
		if (m.find(k)!=m.end())
		{
			puts("NO");
			return 0;
		} else m[k]=true;
	}
	puts("YES");
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}



int main() {
	int n,m,flag=0,flag2=0;
	cin >> n;
	vector<string> key(n);
	rep(i, n) {
		cin >> key[i];
	}
	cin >> m;
	int count = 0;
	string str;
	rep(i, m) {
		cin >> str;
		for (auto c : key) {
			count++;
			if (str == c) {
				if (flag == 0) {
					cout << "Opened by " << c << endl;
					flag = 1;
					flag2 = 1;
					break;
				}
				else {
					cout << "Closed by " << c << endl;
					flag = 0;
					flag2 = 1;
					break;
				}
			}
		}
		if (count == n&&flag2==0) {
			cout << "Unknown " << str << endl;
		}
		count = 0;
		flag2 = 0;
	}

}



Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define ll long long
#define MAX 500005
using namespace std;

template<typename T>
void read(T &n){
    n = 0;
    T f = 1;
    char c = getchar();
    while(!isdigit(c) && c != '-') c = getchar();
    if(c == '-') f = -1, c = getchar();
    while(isdigit(c)) n = n*10+c-'0', c = getchar();
    n *= f;
}
template<typename T>
void write(T n){
    if(n < 0) putchar('-'), n = -n;
    if(n > 9) write(n/10);
    putchar(n%10+'0');
}

int n, m;
ll s;

int main()
{
    cin >> s;
    printf("%.10lf", (1.0*s/3)*(1.0*s/3)*(1.0*s/3));

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = []

for i in range(N):
    B.append(A[i] - i - 1)

B = sorted(B)
M = B[int((N - 1)/2)]
ans = 0

for i in range(N):
    t = B[i] - M
    if t < 0:
        t = (-1) * t
    ans += t

print(ans)


Measured memory_bytes: 25200
N=int(input())
A=[list(map(int, input().split())) for _ in range(N)]

ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += A[i][j]

m = set()
for k in range(N):
    for i in range(N):
        if k==i: continue
        for j in range(i+1,N):
            if k==j: continue
            a = A[i][j]
            b = A[i][k] + A[k][j]
            if b == a: m.add((i,j))
            elif b < a:
                print(-1)
                exit()

for i,j in m:
    ans -= A[i][j]

print(ans)

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

using namespace std;

#define ll long long
#define F first
#define S second
#define ii pair < int , int >

const int N=1;

int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int ans=min(b/a , c );
    printf("%d",ans);
}


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

ll solve() {
    string S, T;
    cin >> S >> T;
    ll ans = 100000;
    for ( int i = 0; i < S.size(); i++ ) {
        if ( i + T.size() > S.size() ) break;
        ll c = 0;
        for ( int j = 0; j < T.size(); j++ ) {
            if ( S[i+j] != T[j] ) c++;
        }
        ans = min(ans, c);
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

int n, m, s;
vector<int> et[1000];
vector<int> ec[1000];
int minDist[1000];
int INF = 1e+9;

int main() {
	int i;
	
	cin >> n >> m >> s;
	for (i = 0; i < m; i++) {
		int u, v, d;
		cin >> u >> v >> d;
		et[u].push_back(v);
		ec[u].push_back(d);
	}
	
	for (i = 0; i < n; i++) minDist[i] = INF;
	
	queue<int> que;
	
	minDist[s] = 0;
	que.push(s);
	
	int loopCnt = 0;
	while (!que.empty()) {
		if (loopCnt > n * m + 100) {
			cout << "NEGATIVE CYCLE" << endl;
			return 0;
		}
		int v = que.front(); que.pop();
		for (i = 0; i < et[v].size(); i++) {
			int nv = et[v][i];
			if (minDist[nv] > minDist[v] + ec[v][i]) {
				minDist[nv] = minDist[v] + ec[v][i];
				que.push(nv);
			}
		}
		loopCnt++;
	}
	
	for (i = 0; i < n; i++) {
		if (minDist[i] >= INF) {
			cout << "INF" << endl;
		}
		else {
			cout << minDist[i] << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define Mod 998244353
using namespace std;
using lint = long long;
using vi = vector<lint>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

// cout << fixed << setprecision(12)

int main(){
  lint N;
  cin >> N;
  
  lint letters = 0;
  
  while(N>0){
    letters++;
    N -= pow(26,letters);
  }
  N += pow(26, letters);
  N--;
  
  vi ans(letters);

  for(lint i=letters-1; i>=0; i--){
    ans[i] = N % 26;
    N /= 26;
  }

  vector<char> alp(0);
  for(char c = 'a'; c<='z'; c++){
    alp.PB(c);
  }
  
  for(lint i=0; i<letters; i++){
    cout << alp[ans[i]];
  }
  cout << endl;
  
  return 0;
}
  
 
  


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

int main(){
  string S, T;
  cin >> S >> T;
  
  int res = 0;
  for(int i = 0; i < S.size(); i++){
    if(S[i] == T[i]){
      res++;
    }
  }
  
  cout << res << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1050;
//ここまでテンプレ
vint child[SIZE];
vint X;
//DP[i]=子のXとDPの中から自分のX_i以下になるような選び方の中で、選ばなかったほうの和が一番小さくなるような選び方をしたときの選ばなかったほうの和
int DP[SIZE]={};
bool flag=0;
//DPテーブルを更新する再帰関数
int dp(int idx){
	//DPテーブルに値が入っていればそのまま返す
	if(DP[idx]!=-1)
		return DP[idx];
	//子がないノードであれば0を返す
	if(child[idx].empty()){
		DP[idx]=0;
		return 0;
	}
	//DPをして値を求める
	//DQ[i][j]=i番目の子でjを構築したときの最小の選ばなかったほうの和
	int DQ[2][5050]={};
	for(int i=0;i<2;i++)
		for(int j=0;j<=X[idx];j++)
			DQ[i][j]=INF;
	DQ[1][0]=0;
	for(int i=0;i<child[idx].size();i++){
		int c=child[idx][i];
		//初期化
		for(int j=0;j<=X[idx];j++)
			DQ[i%2][j]=INF;
		for(int j=0;j<=X[idx];j++){
			//Xを選んだとき
			if(j+X[c]<=X[idx])
				DQ[i%2][j+X[c]]=min(DQ[i%2][j+X[c]],DQ[(i+1)%2][j]+dp(c));
			//DPを選んだとき
			if(j+dp(c)<=X[idx])
				DQ[i%2][j+dp(c)]=min(DQ[i%2][j+dp(c)],DQ[(i+1)%2][j]+X[c]);
		}
	}
	//indexがX[i]以下でDQが最小のものを選んで返す
	int ret=INF;
	for(int i=0;i<=X[idx];i++)
		ret=min(ret,DQ[(child[idx].size()+1)%2][i]);
	DP[idx]=ret;
	//構築不可能であればflagをつける
	if(ret==INF)
		flag=1;
	return ret;
}
int main(){
	int N;
	cin>>N;
	for(int i=1;i<N;i++){
		int p;
		cin>>p;
		p--;
		child[p].pb(i);
	}
	for(int i=0;i<N;i++){
		int x;
		cin>>x;
		X.pb(x);
	}
	//DPテーブルを初期化
	for(int i=0;i<SIZE;i++)
		DP[i]=-1;
	//DPする
	dp(0);
	if(flag)
		cout<<"IMPOSSIBLE"<<endl;
	else
		cout<<"POSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 17280
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main 
{
	static Scanner scan = new Scanner(System.in);

	public static void main(String[] args) 
	{
		int n = scan.nextInt();
		
		for(int i = 0; i < n; i++)
		{
			new DataSet();
		}
	}
	
	static class DataSet
	{
		String original = "";
		String train1;
		String train2;
		List<String> traindex = new ArrayList<String>();
		
		
		public DataSet()
		{
			original = scan.next();
			
			for(int i = 1; i < original.length(); i++)
			{
				train1 = original.substring(0, i);
				train2 = original.substring(i);
//				System.out.println("Trains [" + train1 + "] and [" + train2 + "]");
				
				checkTrain(train1 + train2);
				checkTrain(reverseStr(train1) + train2);
				checkTrain(train1 + reverseStr(train2));
				checkTrain(reverseStr(train1) + reverseStr(train2));
				
				checkTrain(train2 + train1);
				checkTrain(reverseStr(train2) + train1);
				checkTrain(train2 + reverseStr(train1));
				checkTrain(reverseStr(train2) + reverseStr(train1));
			}
			
			System.out.println(traindex.size());
			//12.345
			//12.34
		}
		
		public String reverseStr(String str)
		{
			String ret = "";
			
			for(int i = str.length()-1; i >= 0; i--)
			{
				ret += str.substring(i, i+1);
			}
			
//			System.out.println("Reversing " + str + " into " + ret);
			return ret;
		}
		
		void checkTrain(String train)
		{
//			System.out.println("Checking " + train);
			if(!traindex.contains(train))
			{
//				System.out.println(">>> Added " + train);
				traindex.add(train);
			}
		}
	}

}



Measured memory_bytes: 216432
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define iREP(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    int N; cin>>N;
    vector<ll> A(N);
    REP(i,N)cin>>A[i];
    
    map<ll,ll> cnt,ori;
    REP(i,N)cnt[A[i]]=0;
    
    ll x=0;
    iREP(i,cnt){
        i->second=x;
        ori[A[x]]=x;
        x++;
    }
    
    ll ans=0;
    REP(i,N){
        ll diff=abs(cnt[A[i]]-ori[A[i]]);
        if(diff%2==1)ans++;
    }
    
    cout<<ans/2<<endl;
    
    return 0;
}


Measured memory_bytes: 13568
/*  UntilDeathDoesUsApart
    DO   NOT   GIVE   UP!
*/

#include <bits/stdc++.h>

using namespace std;

#define inc(a)           a.begin(), a.end()
#define dec(a)           a.rbegin(), a.rend()
#define Unique(n)        (n).erase(unique(in(n)), (n).end())
#define to(i, a, n)      for(int i=a; i<n; i++)
#define fr(i, a, n)      for(int i=a; i>=n; i--)
#define read(arr, l, r)  for(int i=l; i<r; cin >> arr[i++])
#define prnt(arr, l, r)  for(int i=l; i<r; cout << arr[i++] << " \n"[i==r])

typedef long long ll;
typedef long double ld;

int n, k, d, x, ans, ok[101];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    cin >> n >> k;
    while(k--){
        cin >> d;
        to(i, 0, d)
            cin >> x, ok[x]++;
    }
    to(i, 1, n+1)
        if(!ok[i]) ans++;
    cout << ans;

	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    double a, b, n;
    cin >> a >> b >> n;

    long ok = -1;
    long ng = n + 1;
    long max = 0;

    while (abs(ok - ng) > 1) {
        long mid = (ok + ng) / 2;

        long y = floor(a * mid / b) - a * floor(mid / b);

        if (y >= max) {
            ok = mid;
            max = y;
        } else {
            ng = mid;
        }
    }

    cout << max << endl;
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define lli long long int
#define inf 2147483647
#define infll LLONG_MAX
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    queue<lli> que;
    for(int i=1; i<10; i++) que.push(i);

    lli ans;
    rep(i, n){
        ans = que.front();
        if(i == n-1){
            cout << ans << endl;
            return 0;
        }
        que.pop();
        ans = ans*10 + ans%10;
        if(ans%10 != 0) que.push(ans-1);
        que.push(ans);
        if(ans%10 != 9) que.push(ans+1);
    }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
  
int main(){
 int s,N;
  cin>>N;
  if(N%2==0){
  	s=(N/2)-1;
  }else if(N%2==1){
    s=(N-1)/2;
  }
	cout<<s<<endl;  
  
}

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

using namespace std;

int main()
{
    int conversion_num;
    
    while (cin >> conversion_num) {
        if (conversion_num == 0) break;
        
        map<string, string> ConversionBase;

        for (int i = 0; i < conversion_num; ++i) {
            string str1, str2;
            
            cin >> str1 >> str2;
            
            ConversionBase[str1] = str2;
        }
        
        int string_num;
        
        cin >> string_num;
        
        string ans;
        
        for (int i = 0; i < string_num; ++i) {
            string temp;
            
            cin >> temp;
            
            if (ConversionBase.find(temp) != ConversionBase.end()) {
                ans += ConversionBase[temp];
            } else {
                ans += temp;
            }
        }
        
        cout << ans << endl;
    }

    return 0;
}

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

//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(v) v.begin(),v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;
typedef set<int> si;
const ll mod = 1e9 + 7;
const ll modl=998244353;
const double pie=3.1415926535;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ll gcd(ll x,ll y){
   if(y==0)return x;
   return gcd(y,x%y);
}
                                              // SIEVE

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/
void transpose(int xl,int xr,int yl,int yr){

}
int main(){
    boost;
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
      string s;
      cin>>s;
      map<ll,ll>M;
      ll suffix=0;
      ll ans=0;
      ll multi=1;
      reverse(all(s));
      M[0]=1;
      for(char i : s){
        int d=i - '0';
        suffix=(suffix + d*multi)%2019;
        multi = 10*multi%2019;
        ans+=M[suffix];
        M[suffix]++;
      }
      cout<<ans<<endl;

    }

  }












Measured memory_bytes: 3776
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int count = 0;
		for(int i = a; i<=b; i++) {
			if(c % i == 0)count++;
		}
		System.out.println(count);
		sc.close();
	}
	
}


Measured memory_bytes: 26392
n,k=map(int,input().split())
ans=0
if k==0:
  print(n*n)
else:
  for i in range(k+1,n+1):
    a=n//i
    b=n%i
    c=0
    if b>=k:
      c=b-k+1
    ans=ans+(i-k)*a+c
  print(ans)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(void)
{
    int n,pm[10001],pe[10001],pj[10001];
    while(1){
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            cin>>pm[i]>>pe[i]>>pj[i];
        }
        for(int i=0;i<n;i++){
            if(pm[i]==100||pe[i]==100||pj[i]==100||(pm[i]+pe[i])/2>=90||(pm[i]+pe[i]+pj[i])/3>=80)
                cout<<"A\n";
            else if((pm[i]+pe[i]+pj[i])/3>=70)cout<<"B\n";
            else if((pm[i]>=80||pe[i]>=80)&&(pm[i]+pe[i]+pj[i])/3>=50)cout<<"B\n";
            else cout<<"C\n";
        }
    }
}

Measured memory_bytes: 1128
#include<iostream>
using namespace std;
int g = 0;
int w, h;
int a[50][50];
int ans = 0;
void track(int i, int j) {
	for (int l = -1; l <= 1; l++) {
		for (int m = -1; m <= 1; m++) {
			/*int li = l + i;
			int mj = m + j;*/
			if (l+i < h && m+j < w && l+i >= 0 && m+j >= 0 && a[l+i][m+j] == 1) {
				g = 1;
				a[l+i][m+j] = 0;
				/*for (int i = 0; i < h; i++) {
					for (int j = 0; j < w; j++) {
						cout << a[i][j];
						if (j == 4) { cout << endl; }
					}*/
					track(l+i, m+j);
				}
			}
		}
		/*for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cout << a[i][j];
				if (j == 4)cout << endl;
			}
		}*/
	}
int main() {
	while (1) {
		cin >> w >> h;
		if (w == 0 && h == 0) { return 0; }
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> a[i][j];
			}
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				track(i, j);
				if (g == 1) { ans++; }
				g = 0;
			}
		}
		cout << ans << endl;
		ans = 0;
	}
}

Measured memory_bytes: 3236
#include <stdio.h>
#include <string.h>
#define lop(i, n) for(i=0; i<n; i++)

int main()
{
	int N, M, i, sum=0, cnt=0;
	int A[1000];
	
	scanf("%d %d", &N, &M);
	lop(i, N){
		scanf("%d", &A[i]);
		sum+=A[i];
	}
	
	float rin=sum/(4.0*M);
	
	lop(i, N){
		if(rin<=A[i])cnt++;
	}
	
	if(cnt>=M){ printf("Yes"); }
	else { printf("No"); }
	
return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
int32_t main()
{
	int a[5];int s=0;
	for(int i=0;i<5;i++){cin>>a[i];}
	for(int i=0;i<5;i++){if(a[i]==0){cout<<i+1;return 0;}}
	
}

Measured memory_bytes: 3612
#include "bits/stdc++.h"

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int cnt = 0;
    long long sum = 0;
    long long minv = LLONG_MAX;
    for (size_t i = 0; i < n; ++i) {
        long long a; cin >> a;
        cnt += (a < 0);
        sum += abs(a);
        minv = min<long long>(minv, abs(a));
    }
    if (cnt % 2) {
        sum -= 2 * minv;
    }
    cout << sum << "\n";
    return 0;
}


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

using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;

#define out(a) cout << a << endl
#define out1(a) cout << a
#define in(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define rep(i, N) for (ll i = 0; i < (ll)N; i++)
#define rep1(i, N) for (ll i = 1; i <= (ll)N; i++)
#define repi(i, j, N) for (ll j = (ll)i + 1; j < (ll)N; j++)
#define all(v) v.begin(), v.end()

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;
constexpr ll mod = 1e9 + 7;

void solve();

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

void solve()
{
    int a, b;
    in2(a, b);
    if (a == b)
    {
        out("Yes");
    }
    else
    {
        out("No");
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
const int N=100005;
int n,a[N],b[N];
int main()
{
	int x;
	n=read();
	for(RI i=1;i<=n;++i) a[i]=b[n-i+1]=1+(i-1)*(n+1);
	for(RI i=1;i<=n;++i) x=read(),a[x]+=i-1;
	for(RI i=1;i<=n;++i) printf("%d ",a[i]);
	puts("");
	for(RI i=1;i<=n;++i) printf("%d ",b[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 768
import java.util.*;

import static java.lang.System.*;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = ni();
        int M = ni();

        long cnt = 0;

        if (N == 1) {
            if (M == 1) {
                cnt = 1;
            } else {
                cnt = M - 2;
            }
        } else if (M == 1) {
            cnt = N - 2;
        } else {
            cnt = (long) N * M - 2 * N - 2 * (M - 2);
        }

        out.println(cnt);
    }

    static int ni() {
        return sc.nextInt();
    }

    static long nl() {
        return sc.nextLong();
    }

    static String ns() {
        return sc.next();
    }

    static int[] niarr(int N) {
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        return a;
    }

    static long[] nlarr(int N) {
        long[] a = new long[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextLong();
        }
        return a;
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	vi d{111,222,333,444,555,666,777,888,999};
	rpz(i,d.size()){
		if(d[i]>=N){
			ote(d[i]);
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// bool fun(vector<int>moves,int X,int cs,int i)
// {
//     if(cs==X)
//     return true;
//     if(i==moves.size())
//     return false;
//     bool a=fun(moves,X,cs+moves[i],i+1);
//     bool b=fun(moves,X,cs,i+1);
//     return (a||b);
// }
int main() {
    int h,n;
    cin>>h>>n;
    vector<int>moves(n);
    for(int i=0;i<n;i++)
    cin>>moves[i];
    long int sum=0;
    for(int i=0;i<n;i++)
    sum+=moves[i];
    if(sum<h)
    cout<<"No";
    else cout<<"Yes ";
   // cout<<sum<<" ";
	return 0;
}

Measured memory_bytes: 768
#include <cmath>
#include <iostream>

using namespace std;

static bool IsPrime(int x) {
  if (1 < x && x < 4)
    return true;
  const int z = static_cast<int>(ceil(sqrt(x)));
  for (int i = 2; i <= z; ++i) {
    if (x % i == 0)
      return false;
  }
  return true;
}

int main() {
  int n;

  cin >> n;

  int cnt = 0;
  int x;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    if (IsPrime(x))
      ++cnt;
  }
  cout << cnt << endl;
  return 0;
}

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


void solve()
{
    int N;
    cin >> N;
    int fnum = 0;
    int tnum = 0;
    int other = 0;
    for(int i = 0;i < N;i++)
    {
        int tmp;
        cin >> tmp;
        if(tmp % 4 == 0)
            fnum++;
        else if(tmp % 2 == 0)
            tnum++;
        else
            other++;
    }
    if(fnum == other or fnum >= N / 2)
        cout << "Yes\n";
    else
        cout << "No\n";
}

int main()
{
    solve();
}

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

int main() {
int N; cin >> N;
vector<int> t(N), x(N), y(N);
for (int i = 0; i < N; i++) {
   cin >> t[i] >> x[i] >> y[i];
}
for(int i=0;i<N;i++){
if((t[i]-t[i-1])%2!=(abs(x[i]-x[i-1])+abs(y[i]-y[i-1]))%2||(abs(x[i]-x[i-1])+abs(y[i]-y[i-1]))>(t[i]-t[i-1])||t[0]%2!=(abs(x[0])+abs(y[0]))%2||abs(x[0])+abs(y[0])>t[0]){
   cout<<"No"<<endl;
   return 0;
}
}    
cout<<"Yes"<<endl;
return 0; 
}



Measured memory_bytes: 4196
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;
double pi = 3.14159265358979;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}

int main() {
  int n;
  cin >> n;
  vector<ll> v(5,0);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    char c = s[0];
    if (c == 'M') v[0]++;
    else if (c == 'A') v[1]++;
    else if (c == 'R') v[2]++;
    else if (c == 'C') v[3]++;
    else if (c == 'H') v[4]++;
  }
  ll sum = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = i + 1; j < 4; j++) {
      for (int k = j + 1; k < 5; k++) {
        sum += (v[i] * v[j]* v[k]);
      }
    }
  }
  printf("%lld\n", sum);
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	int ans = 0, h, i;
	for (i = 0; i < n; i++)
	{
		scanf("%d", &h);
		if (h >= k)
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+5;
int a[N];
int main(){
	int n,q,t,k;
	cin>>n>>k>>q;
	//scanf("%d%d%d",&n,&k,&q);
	memset(a,0,sizeof(a));
	for(int i=1;i<=q;i++){
		cin>>t;
		a[t]++;
	}
	for(int i=1;i<=n;i++){
		if((a[i]-q+k)<=0)
			cout<<"No"<<endl;
		else cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
import sys
import os
import bisect, collections, copy, itertools, math, string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int, input().split()))
def LS(): return list(input().split())

def solve():
	ABC = LI()

	def swap(i, j):
		tmp = ABC[i]
		ABC[i] = ABC[j]
		ABC[j] = tmp

	swap(0, 1)
	swap(0, 2)

	print(ABC[0], ABC[1], ABC[2])
	
if __name__ == '__main__':
	solve()


Measured memory_bytes: 4016
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main(){
    int n, k, q;
    cin>>n>>k>>q;
    vector<ll> p(n, 0LL);

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

    for(int i=0;i<n;i++){
        if(k + p[i]-q > 0){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
    
}


Measured memory_bytes: 1408
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
typedef pair<double, double> dd;
const long long mod = 1000000007;
const double eps = 1e-9;
double find_dist(dd a, dd b) {
	return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
}
int main() {
	int N;
	scanf("%d", &N);
	dd p[N];
	double ans = mod;
	for (int i = 0; i < N; ++i) scanf("%lf %lf", &p[i].first, &p[i].second);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			bool can = true;
			dd cent = dd((p[i].first + p[j].first) / 2, (p[i].second + p[j].second) / 2);
			double rad = find_dist(p[i], p[j]) / 2;
			for (int k = 0; k < N; ++k) {
				if (find_dist(cent, p[k]) > rad + eps) can = false;
			}
			if (can) ans = min(ans, rad);
		}
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			for (int k = 0; k < N; ++k) {
				if (abs((p[k].first - p[j].first) * (p[j].second - p[i].second) - (p[k].second - p[j].second) * (p[j].first - p[i].first)) < eps) continue;
				bool can = true;
				double D = 2 * (p[i].first * (p[j].second - p[k].second) + p[j].first * (p[k].second - p[i].second) + p[k].first * (p[i].second - p[j].second));
				dd cent = dd(1 / D * ((p[i].first * p[i].first + p[i].second * p[i].second) * (p[j].second - p[k].second) + (p[j].first * p[j].first + p[j].second * p[j].second) * (p[k].second - p[i].second) + (p[k].first * p[k].first + p[k].second * p[k].second) * (p[i].second - p[j].second)), 1 / D * ((p[i].first * p[i].first + p[i].second * p[i].second) * (p[k].first - p[j].first) + (p[j].first * p[j].first + p[j].second * p[j].second) * (p[i].first - p[k].first) + (p[k].first * p[k].first + p[k].second * p[k].second) * (p[j].first - p[i].first)));
				double rad = find_dist(cent, p[i]);
				for (int k = 0; k < N; ++k) {
					if (find_dist(cent, p[k]) > rad + eps) can = false;
				}
				if (can) ans = min(ans, rad);
			}
		}
	}
	printf("%.9lf", ans);
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef priority_queue<int> pq;
typedef priority_queue<int, vi, greater<int>> mpq;

const ll INF = 1e18;
const int mod = 1e9+7;
const int dX[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

#define whatis(x) cerr << #x << " is " << x << endl;
#define endl "\n"
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ft front()
#define bk back()
#define sz(x) (long long)x.size()
#define all(x) (x).begin(), (x).end()
#define ub upper_bound
#define lb lower_bound
#define FOR(i, a) for(int i = 0; i < a; i++)
#define FoR(i, a) for(int i = 1; i <= a; i++)
#define ROF(i, a) for (int i = (a)-1; i >= 0; i--)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
//-----------------------| Template By: DakDak |----------------------------
int n;
double p[3000];
double dp[3000][3000];
int main(){
    cin >> n;
    FOR(i, n){
        cin >> p[i];
    }
    dp[0][0] = 1.0;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= i; j++){
            if(j == 0){
                dp[i][j] = dp[i-1][j] * (1-p[i-1]);
            }
            else{
                dp[i][j] = (dp[i-1][j] * (1-p[i-1])) + (dp[i-1][j-1] * p[i-1]);
            }
        }
    }
    double ans = 0.0;
    for(int i = (n+1)/2; i <= n; i++){
        ans += dp[n][i];
    }
    cout << setprecision(100) << ans << endl;
    return 0;
    // Read notes to self
}

/* NOTES TO SELF:
 * Check for int vs ll, worst case just switch everything to ll
 * Check for array bounds if you SEGFAULT, especially in range based loops
 * Always initialize everything in global 
 * Edge cases such as n = 1 or 0
 * Make sure to calculate big O complexity
 * You are geniosity you got this
 */





Measured memory_bytes: 68864
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define inf 20021225
#define N 100010
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
struct edge{int to,lt;}e[N<<1];
int d[N],in[N],cnt,n,m,fr1,fr2;
void add(int x,int y)
{
	e[++cnt].to=y; e[cnt].lt=in[x]; in[x]=cnt; d[x]++;
	e[++cnt].to=x; e[cnt].lt=in[y]; in[y]=cnt; d[y]++;
}
bool dfs(int x,int fr)
{
	if(x==fr1&&fr)	return 1;
	if(x==fr2)	return 0;
	for(int i=in[x];i;i=e[i].lt)
	{
		int y=e[i].to; if(y==fr)	continue;
		if(dfs(y,x))	return 1;
	}
	return 0;
}
int main()
{
	n=read(),m=read(); int wei=0,mx=0;
	for(int i=1;i<=m;i++)	add(read(),read());
	for(int i=1;i<=n;i++)	if(d[i]&1)	return puts("No"),0;
	else if(d[i]>4)	mx=d[i];
	else if(d[i]==4)	wei++;
	if(wei>2||mx)	return puts("Yes"),0;
	if(wei<2)	return puts("No"),0;
	for(int i=1;i<=n;i++)	if(d[i]==4){if(!fr1)	fr1=i; else	fr2=i;}
	puts(dfs(fr1,0)?"Yes":"No");
	return 0;
}

Measured memory_bytes: 3712
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#define N_ 201000
using namespace std;
struct point {
	int c, s;
	bool operator<(const point &p)const {
		return (long long)c*p.s < (long long)p.c*s;
	}
};
priority_queue<point>PQ[N_];
vector<int>E[N_];
int Num[N_], w[N_], C[N_];
int n;
long long res;
void DFS(int a, int pp) {
	C[a] = 1;
	int hc = -1, M = -1;
	for (auto &x : E[a]) {
		DFS(x, a);
		C[a] += C[x];
		if (M < C[x])M = C[x], hc = x;
	}
	if (hc == -1) {
		Num[a] = a;
		PQ[a].push({ 1 - w[a], 1 });
		return;
	}
	Num[a] = Num[hc];
	for (auto &x : E[a]) {
		if (x != hc) {
			while (!PQ[Num[x]].empty()) {
				PQ[Num[a]].push(PQ[Num[x]].top());
				PQ[Num[x]].pop();
			}
		}
	}
	if (w[a] == 0) {
		PQ[Num[a]].push({ 1,1 });
		return;
	}
	point tp = PQ[Num[a]].top();
	tp.s++;
	res += tp.c;
	PQ[Num[a]].pop();
	while (!PQ[Num[a]].empty()) {
		point t = PQ[Num[a]].top();
		if (t < tp)break;
		res += 1ll * (tp.s - tp.c)*t.c;
		tp.c += t.c, tp.s += t.s;
		PQ[Num[a]].pop();
	}
	PQ[Num[a]].push(tp);
}
int main() {
	int i, a;
	scanf("%d", &n);
	for (i = 2; i <= n; i++) {
		scanf("%d", &a);
		E[a].push_back(i);
	}
	for (i = 1; i <= n; i++)scanf("%d", &w[i]);
	DFS(1, 0);
	point tp = PQ[Num[1]].top();
	PQ[Num[1]].pop();
	while (!PQ[Num[1]].empty()) {
		point t = PQ[Num[1]].top();
		res += 1ll * (tp.s - tp.c)*t.c;
		tp.c += t.c, tp.s += t.s;
		PQ[Num[1]].pop();
	}
	printf("%lld\n", res);
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    string res = "YES";
    int t = (int) s.size();
    while (t > 0) {
        if (t >= 5 && s.substr(max(t - 5, 0), 5) == "dream") {
            t -= 5;
            continue;
        }
        if (t >= 5 && s.substr(max(t - 5, 0), 5) == "erase") {
            t -= 5;
            continue;
        }   
        if (t >= 7 && s.substr(max(t - 7, 0), 7) == "dreamer") {
            t -= 7;
            continue;
        }
        if (t >= 6 && s.substr(max(t - 6, 0), 6) == "eraser") {
            t -= 6;
            continue;
        }
        res = "NO";
        break;
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 512
n=int(input())
f = [tuple(map(int, input().split( ))) for _ in range(n)]
p = [tuple(map(int, input().split( ))) for _ in range(n)]

bit = 1<<10
ans = -10**10
for i in range(1,bit):
    tmp = 0
    for j in range(n):
        cj = 0
        for k in range(10):
            cj+= f[j][k] & (i>>k)
        tmp += p[j][cj]
    ans = max(ans,tmp)
print(ans)

Measured memory_bytes: 41452
Class Main
    Public Shared Sub Main()
    Dim S As string = console.readline()
    select case S.Substring(S.Length - 1)
    case "3"
          Console.WriteLine("bon")
    case "0","1","6","8" 
      Console.WriteLine("pon")
    case "2","4","5","7","9"
          Console.WriteLine("hon")
    end select
   End Sub
End Class

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

using namespace std;
int main()
{
    int a[1000000];
    int s;

    cin >> s;
    a[0] = s;

    for (int i = 0; i < 1000000 - 1; i++)
    {
        if (a[i] % 2 == 0)
        {
            a[i + 1] = a[i] / 2;
        }
        else
        {
            a[i + 1] = 3 * a[i] + 1;
        }

        for (int j = 0; j < i - 1; j++)
        {
            if (a[i] == a[j])
            {
                cout << i + 1 << endl;
                return 0;
            }
        }
    }
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define ASSERT(expr...) assert((expr))

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
// }}}

constexpr i64 INF = 1'010'000'000'000'000'017LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

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

void solve() {
    
    int a, b;
    cin >> a >> b;
    if(a * b % 2 == 0) {
        cout << "Even" << endl;
    } else {
        cout << "Odd" << endl;
    }
    // cout << ans << "\n";
}

signed main() {
    

    solve();

    return 0;
}

Measured memory_bytes: 256
N, M = map(int,input().split())
B = []

for k in range(M):
    b = list(map(int,input().split()))
    B.append(b[1:])
p = list(map(int,input().split()))

ans = 0
for k in range(2**N):
    a = []
    t = [0 for k in range(M)]
    for l in range(N):
        if (k>>l)&1:
            a.append(l)
    for s in a:
        for l in range(M):
            if s+1 in B[l]:
                t[l] += 1
    u = 0
    for l in range(M):
        if p[l] == t[l]%2:
            u += 1
    if u==M:
        ans+=1
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;


namespace ABC94_4
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            string[] s = ReadLine().Split(' ');
            int[] a = new int[n];
            int[] b = new int[n];
            int ma = 0;
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(s[i]);
                b[i] = int.Parse(s[i]);
                ma = Math.Max(ma, a[i]);
            }



            //Array.Sort(b);
            //int[] m = new int[3];
            //if (n % 2 == 0)
            //{
            //    m[0] = b[n / 2 - 1];
            //    m[1] = b[n / 2];
            //    m[2] = b[n / 2];

            //}
            //else
            //{
            //    m[0] = b[(n - 1) / 2];
            //    m[1] = b[(n - 1) / 2 + 1];
            //    m[2] = b[(n - 1) / 2 + 2];
            //}
            double c = ma;
            int ci = 0;
            for (int i = 0; i < n; i++)
            {
                if (c >= Math.Abs(ma * 0.5 - a[i]))
                {
                    c = Math.Abs(ma * 0.5 - a[i]);
                    ci = i;
                }
            }
            //long mb = 0;
            //int ans = 0;
            //long num = 1;
            //for (int j = 1; j <= m[ci]; j++)
            //{
            //    num = num * (ma - j + 1) / j;
            //}
            //if (num > mb)
            //{
            //    mb = num;
            //    ans = m[ci];
            //}

            WriteLine(ma + " " + a[ci]);
        }
    }
}


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


using namespace std;

int main()
{
  long int n;
  scanf("%ld",&n);
  
  long int a[n],i,max=0;
  for(i=0;i<n;++i)
  {
    scanf("%ld",&a[i]);
    
  }
  sort(a,a+n);
  
  int flag=0;
  for(i=0;i<n-1;++i)
  {
    if(a[i]==a[i+1])
    {
      flag=1;
      break;
    }
  }
  
  if(flag==1)
      printf("NO");
  
  else
     printf("YES");
  
  
}

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

using namespace std;

int main() {
    int H, W;
    cin >> H >> W;

    vector<string> vec;
    for(int h=0; h<H; h++) {
        string str;
        cin >> str;
        
        bool flag=true;
        for(int w=0; w<W; w++) {
            if(str[w]=='#') {
                flag=false;
                break;
            }
        }
        if(!flag) {
            vec.push_back(str);
        }
    }
    
    vector<bool> ans(W, true);
    for(int w=0; w<W; w++) {
        for(int h=0; h<vec.size(); h++) {
            if(vec[h][w]=='#') {
                ans[w]=false;
                break;
            }
        }
    }
    
    for(int h=0; h<vec.size(); h++) {
        for(int w=0; w<W; w++) {
            if(!ans[w]) {
                cout << vec[h][w];
            }
        }
        cout << endl;
    }
    
    
    return 0;
    
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int d, s, i, test = 0;

	while (scanf("%d", &d) != EOF) {
		s = 0;
		for (i = 1; i * d < 601; i++) {	
			if (i * d == 600) {
				test = i;
			}
		}
		if (test == 0) {
			printf("Error!\n");
			continue;
		}


		for (i = 1; i < test; i++) {
			s = s + i * i * d * d * d;
		}

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

Measured memory_bytes: 0