akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

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


Measured memory_bytes: 4828
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int N, M;
long long memo[301][301][301];
bool visited[301][301][301];
long long f(int m, int p, int q) {
	if (m == 0) return q == N ? 1 : 0;
	if (visited[m][p][q]) return memo[m][p][q];
	visited[m][p][q] = true;
	long long r = 0;
	r += f(m-1, p, p) * q;
	r += f(m-1, p, q) * (p - q);
	if (p < N) r += f(m-1, p+1, q);
	return memo[m][p][q] = r % mod;
}
int main() {
	cin >> N >> M;
	long long r = f(M, 1, 1);
	for (int i = 2; i <= N-1; ++ i) r = (r * i) % mod;
	cout << r << endl;
}


Measured memory_bytes: 121344
def resolve():
    '''
    code here
    '''
    Sd = input()
    T = input()

    r_Sd = Sd[::-1]
    r_T = T[::-1]

    def chk(a, b):
        res = ''
        for j in range(len(b)):
            if a[j] == '?' or a[j] == b[j]:
                res += b[j]
            else:
                return False
        else:
            return res 

    if len(Sd) >= len(T):
        for i in range(len(Sd)- len(T)+1):
            temp_words = r_Sd[i:i+len(T)]
            res = r_Sd[:i]
            
            temp = chk(temp_words, r_T)
            if temp:
                res = res + temp + r_Sd[i+len(T):]                
                print(res.replace('?', 'a')[::-1])
                break
        else:
            print('UNRESTORABLE')
    else:
        print('UNRESTORABLE')

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <sstream>
#include <cstdlib>
using namespace std;
int main(){
	string s,p;
	getline(cin,s);
	s=s+s;
	getline(cin,p);

	if(s.find(p)<s.size()){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

	return 0;
}


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

typedef long long ll;
#define MOD = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) { s >> x; } return s;}
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N,M,X,A; cin >>N>>M>>X;
    vector<int> cost(N+1, 0);
    rep(i, M) {
        cin >> A;
        cost[A] = 1;
    }
    
    int c1 = accumulate(cost.begin(), cost.begin() + X, 0);
    int c2 = accumulate(cost.begin() + X + 1, cost.end(), 0);;

    cout << min(c1, c2) << endl;
}


Measured memory_bytes: 256
//writer：Sakura
//problem：Reversed LCS
//id：021_d
//from：Actor

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

string s;
ll n;
int dp[305][305][305];

int dfs(int l,int r,int sum){
	if(dp[l][r][sum]!=-1)return dp[l][r][sum];
	if(l>r)return 0;
	if(l==r)return 1;
	int ans=0;
	if(sum>0){
		ans=max(ans,dfs(l+1,r-1,sum-1)+2);
	}
	ans=max(ans,dfs(l+1,r,sum));
	ans=max(ans,dfs(l,r-1,sum));
	if(s[l]==s[r])ans=max(ans,dfs(l+1,r-1,sum)+2);
	return dp[l][r][sum]=ans;
}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>s;
	scanf("%lld",&n);
	memset(dp,-1,sizeof(dp));
	int _=dfs(0,s.size()-1,n);
	printf("%lld\n",_);
	return 0;
}


Measured memory_bytes: 111232
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {
	
	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================
	
	int M1, D1, M2, D2;
	cin >> M1>> D1>> M2>> D2;

	if (M1 != M2) {
		cout << 1;
	}
	else {
		cout << 0;
	}




}




Measured memory_bytes: 256
h,w=gets.split.map(&:to_i)
ss = []
h.times do
  ss.push gets.chomp.split
end
x = 0
y = 0
ss.each_index do |i|
  p = ss[i].rindex('snuke')
  if p
    x = i
    y = p
    break
  end
end
wc = ('A'..'Z').to_a[y]
hc = x + 1
puts "#{wc}#{hc}"


Measured memory_bytes: 1788
def bfs(s, t)
  queue = [[s, 0]]
  is_arrived = {}
  
  until queue.empty? do
    current, d = queue.shift
    
    # p [:until, current.i, d]
    
    key = [current, d % 3]
    next if is_arrived[key]
    is_arrived[key] = true
    
    return d / 3 if current == t && d % 3 == 0
    
    current.neighbors.each do |neighbor|
    	queue << [neighbor, d+1]
    end
  end
  
  -1
end

class Node
  attr_accessor :neighbors, :i, :children
  
  def initialize
    self.neighbors = []
    self.children = []
  end
end

N,M = gets.chomp.split.map(&:to_i)
vs = Array::new(N+1){Node::new}
vs.each_with_index{|v,i|v.i = i}
M.times do
  u,v = gets.chomp.split.map(&:to_i)
  vs[u].neighbors << vs[v]
end
S,T = gets.chomp.split.map(&:to_i)

p bfs(vs[S], vs[T])

Measured memory_bytes: 52220
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<UL> A(N); rep(i, N) cin >> A[i];
		sort(A.begin(), A.end());
		UL ans = 1;
		ULL S = A[0];
		for (UL i = 1; i < N; i++) {
			if (S * 2 >= A[i]) { S += A[i]; ans++; }
			else { ans = 1; S += A[i]; }
		}
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m;i>n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
   lli L,R,N,M,K,sum=0,num=0;
   cin >> N >> K;
   if(!K)sum=N*N;
   else rep(i,K,N+1)sum+=(max((N/i)*(i-K),num)+max((N-i*(N/i))-K+1,num));
   Out(sum);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	LD N,M,D;
	cin>>N>>M>>D;
	LD ans=1;
	if(D!=0){
		ans = (N-D)*(M-1)*2/(N*N);
	}else{
		ans = N*(M-1)/(N*N);
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


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

int snuke[105];
int n, k;
int tot = 0;

int main() {
	ios::sync_with_stdio(0);
//	freopen("abc166_b.in", "r", stdin);
//	freopen("abc166_b.out", "w", stdout);

	cin >> n >> k;
	for(int i = 1; i <= k; i++) {
		int d;
		cin >> d;
		for(int j = 1; j <= d; j++) {
			int u;
			cin >> u;
			snuke[u]++;
		}
	}

	for(int i = 1; i <= n; i++)
		if(!snuke[i]) tot++;

	cout << tot << endl;

//	fclose(stdin);
//	fclose(stdout);
	return 0;
}

Measured memory_bytes: 3612
//
//AtCoder Beginner Contest 123
//A
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>
#include <numeric>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    vector<int> a(5);
    REP(i, 5) cin >> a[i];

    int k;
    cin >> k;

    string ans = "Yay!";
    REP(i,4){
        FOR(j, i+1, 4){
            if (a[j]-a[i]>k) {
                ans = ":(";
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}

int okay(string s){
  for( auto c : s){
    if( c == 'A') continue;
    if( c == 'T') continue;
    if( c == 'C') continue;
    if( c == 'G') continue;
    return false;
  }
  return true;
}
void solve(std::string S) {
  int ans = 0;
  for(int i = 0 ; i < S.size() ; i++){
    string x = "";
    for(int j = i ; j < S.size() ; j++){
      x += S[j];
      if(okay(x)){
        ans = max<int>(ans, x.size());
      }
    }
  }
  cout << ans << endl;
}

int main() {
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <vector>
#include <string>

int main() {
  char buf[262144];
  scanf("%s", buf);
  std::string A=buf;
  size_t n=A.length();

  size_t alpha[26]={};
  for (size_t i=0; i<n; ++i)
    ++alpha[A[i]-'a'];

  size_t res=1+n*(n-1)/2;
  for (int i=0; i<26; ++i)
    res -= alpha[i]*(alpha[i]-1)/2;

  printf("%zu\n", res);
}


Measured memory_bytes: 640
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

#define M 100100

//head

ll n;
int x, m;
bitset<M> check;
ll sum[M];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> x >> m;
  int now = x;
  int cnt = 0;
  while(!check.test(now)) {
    check.set(now);
    cnt++;
    sum[cnt] = sum[cnt-1] + now;
    now = ll(now)*now%m;
  }
  int cnt_ = 0;
  check = 0;
  while(!check.test(now)) {
    check.set(now);
    cnt_++;
    now = ll(now)*now%m;
  }
  if(n <= cnt) {
    cout << sum[n] << endl;
    return 0;
  }
  ll ans = sum[cnt];
  n -= cnt;
  ans += n/cnt_ * (sum[cnt]-sum[cnt-cnt_]);
  n %= cnt_;
  cout << ans + sum[n+cnt-cnt_] - sum[cnt-cnt_] << endl;
}

Measured memory_bytes: 4048
//AT2043 AND Grid
#include <cstdio>
using namespace std;

const int MAXH = 505;
char g[MAXH][MAXH];

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (register int i = 0; i < n; i++)
		scanf("%s", &g[i]);
	for (register int i = 0; i < n; i++)
	{
		for (register int j = 0; j < m; j++)
		{
			if (j == 0) printf("#");
			else if (g[i][j] == '#') printf("#");
			else if (j == m-1) printf(".");
			else if (!(i & 1)) printf("#");
			else printf(".");
		}
		printf("\n");
	}
	printf("\n");
	for (register int i = 0; i < n; i++)
	{
		for (register int j = 0; j < m; j++)
		{
			if (j == m-1) printf("#");
			else if (j == 0) printf(".");
			else if (g[i][j] == '#') printf("#");
			else if (i & 1) printf("#");
			else printf(".");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
unordered_set<int> S;
int main() {
	int n,x;
	scanf("%d",&n);
	for(int i=0;i<n;i++) {
		scanf("%d",&x);
		S.insert(x);
	}
	printf("%s\n",(S.size()==n?"YES":"NO"));
	return 0;
}

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

int main() {
 int n;
 cin >> n;
set<char> a;

 rep(i,n){
   char x;
   cin >>x ;
   a.insert(x);
 }
 if(a.size() == 3) cout << "Three" << endl;
 else cout << "Four" << endl;
 } 

Measured memory_bytes: 3580
fun main(args : Array<String>) {
    val D = readLine()!!.toInt()

    if (D == 25) {
        println("Christmas")
        return
    }

    if (D == 24) {
        println("Christmas Eve")
        return
    }

    if (D == 23) {
        println("Christmas Eve Eve")
        return
    }

    println("Christmas Eve Eve Eve")
}

Measured memory_bytes: 31580
#include <iostream>
#include <math.h>

using namespace std;

int main(){
	int i, j, s, p, tmp;

	int primes[1230];
	primes[i = 0] = 2;
	for(p = 3; p <= 10007; p+=2){
		s = sqrt((double)p);
		for(j = 0; j <= i; j++){
			tmp = primes[j];
			if(tmp > s){
				i++;
				primes[i] = p;
				break;
			}else if(p%tmp == 0){
				break;
			}
		}
	}

	int N;
	cin >> N;

	int n, count = 0;

	for(i = 0; i < N; i++){
		cin >> n;
		s = sqrt((double)n);
		for(int p : primes){
			if(p > s){
				count++;
				break;
			}else if(n%p == 0){
				break;
			}
		}
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define pq priority_queue
#define bcnt(n) __builtin_popcountll(n)

using ll = long long;  // long longをllだけにした
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using mll = map<long long, long long>;
using pll = pair<long long, long long>;
using sll = set<long long>;
using vpll = vector<pair<long long, long long>>;
using mlv = map<long long, vector<long long>>;

int main() {
	ll const dekai = 99999999977;
	ll n, k;
	cin >> n >> k;
	vll h(n);
	rep(i, n) cin >> h[i];
	vll cost(n, dekai);
	cost[0] = 0;
	rep(i, n - 1) {
		rep(j, k) { cost[i + j + 1] = min(cost[i + j + 1], cost[i] + abs(h[i] - h[i + j + 1])); }
	}
	cout << cost[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    cout << a*b << " " << 2*a + 2*b << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007

#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p )
{
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v )
{
    os << "{";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v )
{
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v )
{
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v )
{
    os << "[";
    for(auto it = v.begin(); it != v.end(); ++it)
    {
        if( it != v.begin() )
            os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu ()
{
    cerr << endl;
}

template <typename T>
void faltu( T a[], int n )
{
    for(int i = 0; i < n; ++i)
        cerr << a[i] << ' ';
    cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}

void f()
{
    int n,m,p,acc=0,pen=0;
    string s;
    map<int,int>v;

    cin>>n>>m;
    bool ac[n+2]= {0};

    for(int i=1; i<=m; i++)
    {
        cin>>p>>s;
        if(ac[p]==0&&s=="AC")
        {
            acc++;
            ac[p]=1;
            pen+=v[p];
        }
        if(s=="WA")
        {
            v[p]++;
        }
    }
    cout<<acc<<" "<<pen<<nl;
}

int main()
{
    su;
    f();
    return 0;
}


Measured memory_bytes: 8256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

ll n, x;
int a[2001] = {};
int costList[2001][2001] = {};

int main() {

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

	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			if(j == 0){
				costList[i][j] = a[i];
			}else{
				int nowUse = (i - j + n) % n;
				costList[i][j] = min(costList[i][j - 1], a[nowUse]);
			}
		}
	}

	ll minCost = INFLL;
	for(int i = 0;i < n;i++){
		ll nowSum = 0;
		for(int j = 0;j < n;j++){
			nowSum += costList[j][i];
		}
		// cout << nowSum << endl;
		nowSum += x * i;
		minCost = min(minCost, nowSum);
	}

	cout << minCost << endl;
	return 0;
}

Measured memory_bytes: 15872
// Created by ...
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)

using namespace std;
using ll = long long;

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;int m;
  int sum=0;
  cin>>m>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
   for(int i=0;i<n;i++)
    sum+=a[i];
  if(sum>m)
    cout<<"-1"<<endl;
  else
    cout<<m-sum<<endl;

  return 0;
}

Measured memory_bytes: 3656
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

from heapq import heappop, heappush

N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

q = []
push = lambda x,i: heappush(q, (-x,i))
for i,x in enumerate(B):
    push(x,i)

answer = 0
while q:
    x,i = heappop(q)
    x = -x
    if x < A[i]:
        answer = -1
        break
    dx = x-A[i]
    nbd = B[(i-1)%N] + B[(i+1)%N]
    t = dx // nbd
    if t == 0:
        if x == A[i]:
            continue
        answer = -1
        break
    B[i] -= nbd * t
    answer += t
    push(B[i],i)

print(answer)



Measured memory_bytes: 128604
#include<bits/stdc++.h>
using namespace std;
long long n,s,x;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) scanf("%d",&x),s+=x;
	if(s%2==0) cout<<"YES\n";
	  else cout<<"NO\n";
	return 0;
 } 

Measured memory_bytes: 256
pub fn main() {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf);
  buf.clear();

  std::io::stdin().read_line(&mut buf);
  let a: Vec<i64> = buf.split_whitespace().map(|e| e.parse().unwrap()).collect();

  let mut ans:i64 = 0;
  let mut high:i64 = 0;
  for i in a {
    if high > i {
      ans += high - i;
    } else {
      high = i;
    }
  }
  println!("{}", ans);
}


Measured memory_bytes: 5904
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n, c=0, m;

  	cin >> n;
	vector<int> a(n+1);
	a[0] = 1;
	a[1] = 1;
	for(int i=2;i<n+1;i++){
		a[i] = a[i-1] + a[i-2];
	}
	cout<<a[n]<<endl;
}


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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> a(N);
  for (int i=0; i<N; i++) cin >> a[i];

  vector< vector<long long> > v(N);
  for (int i=0; i < N; i++) v[i].resize(K+1, 0);
  // v(i,j) = number of patterns with children i.., and j remainder
  // required answer is v(0,K)

  // last person needs to consumer all
  // hence, if remainder is at most a, there is one way
  // but if the remainder is more than a, not possible to satisfy the requirement
  for (int j=0; j <= a[N-1]; j++) v[N-1][j] = 1;
  // with no remainder, only possibility is to assign no candy
  for (int i=0; i < N-1; i++) v[i][0] = 1;

  /*
  v(i,j) = sum_{k=0}^{min(j, a(i)} v(i+1, j+k)
  */
  long long modulo = 1e9 + 7;
  for (int i=N-2; i >= 0; i--) {
    for (int j=1; j <= a[i]; j++) {
      v[i][j] = (v[i][j-1] + v[i+1][j]) % modulo;
    }
    for (int j=a[i]+1; j<=K; j++) {
      v[i][j] = (v[i][j-1] + v[i+1][j] - v[i+1][j-a[i]-1]) % modulo;
      if (v[i][j] < 0) v[i][j] += modulo;
    }
  }

  /*
  for (int i=0; i<N; i++) {
    for (int j=0; j<=K; j++) {
      cout << v[i][j] << " ";
    }
    cout << "\n";
  }
  */
  cout << v[0][K] << "\n";
  return 0;
}



Measured memory_bytes: 78592
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    n: usize,
    q: usize,
    s: Chars,
    lr: [(Usize1, Usize1); q]
    }
    let mut cul_ac = vec![0; n];
    for i in 1..n {
        cul_ac[i] = cul_ac[i - 1] + if s[i - 1] == 'A' && s[i] == 'C' {1} else {0};
    }
    for i in 0..q {
        let (l, r) = lr[i];
        println!("{}", cul_ac[r] - cul_ac[l])
    }
}


Measured memory_bytes: 5756
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

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

  if(s[0] == 'S'){
    cout << "Cloudy" << endl;
  }else if(s[0] == 'C'){
    cout << "Rainy" << endl;
  }else{
    cout << "Sunny" << endl;  
  }
  return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector <int> a(n);
	for(int i=n-1;i>=0;i--){
		cin >> a[i];
	}
	cout << a[0];
	for(int i=1;i<n;i++) cout << " " << a[i];
	cout << endl;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b;cin>>a>>b;
  if(a==b) print(0);
  else {
    if((a+b)%2==0) print((a+b)/2);
    else print("IMPOSSIBLE");
  }
  return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
ans = [1]*n
h = input().split()
h_int = [int(s) for s in h]
cou = 0
 
for i in range(m):
  x,y = map(int,input().split())
  if h_int[x-1] >= h_int[y-1]:
    ans[y-1] = 0
  if h_int[y-1] >= h_int[x-1]:
    ans[x-1] = 0
 
for i in range(n):
  if ans[i] == 1:
    cou += 1
print(cou)


Measured memory_bytes: 20896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <cstdint>
#include <string.h>
#include <queue>

using namespace std;

char map[50][50];

int main()
{
    int N, A, B;
    cin >> N >> A >> B;

    auto parity = A - B;

    if (parity % 2 == 0) {
        cout << "Alice" << endl;
    } else {
        cout << "Borys" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
def main():
    from itertools import combinations_with_replacement
    n, m, q = map(int, input().split())
    requirements = [list(map(int, input().split())) for _ in range(q)]

    score_max = 0
    for a in combinations_with_replacement(range(1, m+1), n):
        score = 0
        for requirement in requirements:
            if a[requirement[1]-1] - a[requirement[0]-1] == requirement[2]:
                score += requirement[3]
        score_max = max(score, score_max)

    print(score_max)


if __name__ == '__main__':
    main()


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

int main(){
    double time[2];

    while(cin >> time[0] >> time[1]){
        if(time[0] < 35.5 && time[1] < 71.0) cout << "AAA" << endl;
        else if(time[0] < 37.5 && time[1] < 77.0) cout << "AA" << endl;
        else if(time[0] < 40.0 && time[1] < 83.0) cout << "A" << endl;
        else if(time[0] < 43.0 && time[1] < 89.0) cout << "B" << endl;
        else if(time[0] < 50.0 && time[1] < 105.0) cout << "C" << endl;
        else if(time[0] < 55.0 && time[1] < 116.0) cout << "D" << endl;
        else if(time[0] < 70.0 && time[1] < 148.0) cout << "E" << endl;
        else cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(10**3)

n = int(input())
s = [list(map(int, list(input()))) for _ in range(n)]

c = [-1 for _ in range(n)]
e = [[] for _ in range(n)]
for i in range(n-1):
    for j in range(i+1, n):
        if s[i][j] == 1:
            e[i].append(j)
            e[j].append(i)

def dfs(x, p, b):
    c[x] = b
    for f in e[x]:
        if f != p:
            if c[f] >= 0:
                if c[f] == c[x]:
                    print(-1)
                    exit()
            else:
                dfs(f, x, (b+1)%2)


dfs(0, 0, 0)

inf = float('inf')

for i in range(n-1):
    for j in range(i+1, n):
        if s[i][j] == 0:
            s[i][j] = inf
            s[j][i] = inf

def warshall_floyd(d):
    for k in range(n):
        for i in range(n-1):
            for j in range(i+1, n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]
                    d[j][i] = d[i][j]
    return d

s = warshall_floyd(s)

ans = 0
for x in s:
    ans = max(max(x), ans)

print(ans+1)

Measured memory_bytes: 3828
import scala.io.StdIn

object Main extends App {
  val n = StdIn.readLine.toInt
  val ans = if ((n % 7) == 0 || (n % 4) == 0) "Yes"
    else if ((7 until n by 7).exists(i => (n - i) % 4 == 0)) "Yes"
    else "No"
  println(ans)
}

Measured memory_bytes: 25424
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	int n, m;
	n = N;
	m = 0;

	while (n) {
		m += n % 10;
		n /= 10;
	}
	//cout << m << endl;

	cout << (N % m ? "No" : "Yes") << endl;
}

Measured memory_bytes: 3568
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int N=2002020;
char s[N],t[N];
int main()
{
	scanf("%s",s+1);
	scanf("%s",t+1);
	int cnt=0, len=strlen(t+1);
	for(int i=1;i<=len;i++)
		if(s[i]!=t[i])++cnt;
	cout<<cnt<<endl;
	return 0;
}

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

int main(){
    int n,a;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a;
        if(!(a%2) && (a%3)&&(a%5)){
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}

Measured memory_bytes: 256
//Name: Divide the Cake
//Level: 4
//Category: 幾何,Geometry,確率
//Note:

/**
 * 左側の辺に1点を取ったとき、右側の点が動ける範囲は、いちごを半分に分けられる境界線の間の範囲。
 * この境界線が変化するのは、いちごと右側の角のうち2点を通る直線と、左側の辺との交点をまたぐときだけである。
 * また、この区間内で左側の点がεだけ動いた時、右側の点の動ける範囲の変化分は相似な三角形を用いて
 *   ε(W-x1)/x1 - ε(W-x2)/x2
 * と表せる。
 * ただし、x1とx2は境界上のいちごのx座標。
 *
 * 左側の点に対応する境界上のいちごは、偏角でソートして中央にあるものを選べばよい。
 *
 * オーダーはO(N^3 log N)。
 */
#include <iostream>
#include <vector>
#include <complex>
#include <algorithm>
#include <cstdio>

using namespace std;

typedef complex<long double> P;

const long double EPS = 1e-10;

namespace std {
    bool operator <(const P &p1, const P &p2) {
        if(p1.real() != p2.real()) return p1.real() < p2.real();
        return p1.imag() < p2.imag();
    }
};

bool cmp(const P &p1, const P &p2) {
    return p1.imag() < p2.imag();
}

bool eql(const P &p1, const P &p2) {
    return abs(p1 - p2) < EPS;
}

long double calc_at(const P &pa, const P &pb, long double x) {
    P d = pb - pa;
    if(abs(d.real()) < EPS) {
        if(arg(d) < 0) return -1e10;
        else return 1e10;
    }
    return pa.imag() + d.imag() * ((x - pa.real()) / d.real());
}

long double cross(const P &pa, const P &pb) {
    return pa.real()*pb.imag() - pa.imag()*pb.real();
}

bool solve() {
    int W, H, N;
    cin >> W >> H >> N;
    if(!W && !H && !N) return false;
    N *= 2;

    vector<P> ps(N);
    for(int i = 0; i < N; ++i) {
        int x, y;
        cin >> x >> y;
        ps[i] = P(x, y);
    }
    vector<P> events;
    for(int i = 0; i < N; ++i) {
        for(int j = i+1; j < N; ++j) {
            events.push_back(P(0, calc_at(ps[i], ps[j], 0)));
        }
        events.push_back(P(0, calc_at(ps[i], P(W, 0), 0)));
        events.push_back(P(0, calc_at(ps[i], P(W, H), 0)));
    }
    events.push_back(P(0, 0));
    events.push_back(P(0, H));
    sort(events.begin(), events.end(), cmp);
    //events.erase(unique(events.begin(), events.end(), eql), events.end());
    const int M = events.size();
    long double ans = 0;
    for(int i = 0; i < M-1; ++i) {
        const P &pa = events[i];
        const P &pb = events[i+1];
        if(pa.imag() < 0) continue;
        if(pb.imag() > H) break;
        if(pb.imag() - pa.imag() < EPS) continue;
        //cout << pa << ' ' << pb << endl;
        const P m = (pa+pb) / (long double)2.0;
        long double upper = 0, lower = 0;
        vector<pair<long double,P>> v;
        for(const P &p : ps) {
            const P d = p - m;
            v.push_back(make_pair(arg(d), p));
        }
        sort(v.begin(), v.end());
        //cout << v[0].first << ' ' << v[1].first << endl;
        lower = min<long double>(H, max<long double>(0, calc_at(m, v[N/2-1].second, W)));
        upper = min<long double>(H, max<long double>(0, calc_at(m, v[N/2].second, W)));
        //cout << lower << ' ' << upper << endl;
        long double add = (pb.imag()-pa.imag()) * (upper - lower);
        ans += abs(add);
    }
    printf("%.10Lf\n", ans / H / H);
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 2684
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

#define ll long long
#define ldb long double
#define db double
#define str string

#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mll map<ll,ll>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(i,a,b) for (int i = (a); i < (b); ++i)
#define rrof(i,a,b) for (int i = (b)-1; i >= (a); --i)


const int MOD = 1e9+7;
const ldb PI = 4*atan((ldb)1);

ll power(ll a,ll n){
	ll res=1;

	while(n){
		if(n%2)
		res*=a;
		a*=a;
		n/=2;
	}
	
	return res;
}

int main(){
	fast;
	
	ll int n,W;
	cin>>n>>W;
	
	ll int w[n],v[n],sum=0;
	forr(i,0,n){
		cin>>w[i]>>v[i];
		sum+=v[i];
	}
	
	ll int dp[n][sum+1];
	
	for(int i=0;i<n;i++){
		dp[i][0]=0;
		
		forr(j,1,sum+1){
			dp[i][j]=1e18;
		}
	}
	
	for(int i=0;i<n;i++){
		for(int j=0;j<sum+1;j++){
			if(i==0){
				if(j==v[i])
				dp[i][j]=w[i];
			}
			
			else{
				if(j>=v[i])
				dp[i][j]=min(dp[i-1][j-v[i]]+w[i],dp[i-1][j]);
				
				else
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	
	for(int i=sum;i>=0;i--){
		if(dp[n-1][i]<=W){
			cout<<i;
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 78336
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;

    int count = 0;

    reple(i, 1, N)
    {
        int a;
        cin >> a;

        if (i % 2 == 1 && a % 2 == 1) count++;
    }

    cout << count << endl;

    return 0;
}

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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define piii pair<int, pii>
#define vi vector<int>
#define vpii vector<pii>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);
#define pv(v) for (int i : v) { printf("%d ", i); } printf("\n");

const int MOD = 1000000007;
const int MAX = 2005;

vi g[MAX];
bool v[MAX][MAX];
int dist[MAX][MAX];
int n, k;

void dfs(int st, int i) {
    v[st][i] = true;
    for (int j : g[i]) {
        if (!v[st][j]) {
            dist[st][j] = dist[st][i] + 1;
            dfs(st, j);
        }
    }
}

int ct(int r1, int r2) {
    int ans = 0;
    FOR(i, 1, n+1) {
        if (dist[r1][i] <= k/2 || dist[r2][i] <= k/2) { ans++; }
    }
    return ans;
}
int main() {
    scanf("%d %d", &n, &k);
    vector<pii> edges;
    F0R(i, n-1) {
        read2(a, b);
        g[a].pb(b); g[b].pb(a);
        edges.pb(mp(a, b));
    }
    FOR(i, 1, n+1) { dfs(i, i); }
    int maxx = -1;
    if (k%2 == 0) {
        FOR(i, 1, n+1) { maxx = max(maxx, ct(i, i)); }
    }
    else {
        F0R(i, edges.size()) {
            maxx = max(maxx, ct(edges[i].f, edges[i].s));
        }
    }
    cout << n - maxx << endl;
}


Measured memory_bytes: 20096
#include <algorithm>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <math.h>

using namespace std;

int a[4];

string ans = "";

bool dfs(int i, int cur_sum)
{
	if (i == 3) {
		if (cur_sum == 7)
			return true;
		return false;
	}
	if (dfs(i+1, cur_sum+a[i+1])) {
		ans.insert(0, to_string(a[i+1]));
		ans.insert(0, "+");
		return true;
	}
	if (dfs(i+1, cur_sum-a[i+1])) {
		ans.insert(0, to_string(a[i+1]));
		ans.insert(0, "-");
		return true;
	}
	return false;
}

int main(void)
{
	string s;
	cin >> s;
	for (int i = 0; i < 4; i++)
		a[i] = stoi(s.substr(i, 1));
	dfs(0, a[0]);
	ans += "=7";
	ans.insert(0, to_string(a[0]));
	cout << ans << endl;
	return 0;
}


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

const int DEPTH = 17;
class Segtree {
	int value[1 << (DEPTH + 1)];	//????????????????????????
public:
	Segtree() {
		for (int i = 0; i < (1 << (DEPTH + 1)); i++) value[i] = 0;
	}
	void update(int pos, int addValue) {
		pos += (1 << DEPTH) - 1;	//??°??????pos???????????????, value[pos + (1 << DEPTH) - 1]?????\??£????????????
		value[pos] += addValue;
		while (pos > 0) {
			pos = (pos - 1) / 2;
			value[pos] += addValue;
		}
	}
	//[l, r), ?????????id?????°????????????[a, b)??????????????£?????????
	int getSum(int l, int r, int a = 0, int b = (1 << DEPTH), int id = 0) {
		if (a >= r || b <= l) return 0;
		if (l <= a && b <= r) {
			return value[id];
		}
		return getSum(l, r, a, a + (b - a) / 2, id * 2 + 1) + getSum(l, r, a + (b - a) / 2, b, id * 2 + 2);
	}
};

int n, q;
int com, x, y;
Segtree seg;

int main() {
	cin >> n >> q;
	for (int i = 0; i < q; i++) {
		cin >> com >> x >> y;
		if (com == 0) seg.update(x, y);
		else cout << seg.getSum(x, y + 1) << endl;
	}
	return 0;
}

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

namespace ABC123A
{
    class Program
    {
        static void Main(string[] args)
        {
            // 整数の入力
            int n = 5;
            int[] antenna = new int[n];
            for (int i = 0; i < n; i++)
            {
            antenna[i] = int.Parse(Console.ReadLine());
            }
            int k= int.Parse(Console.ReadLine());
            bool ans=true;
            for (int j = 0; j < n; j++)
            {
                if (antenna[j] - antenna[0] > k)
                {
                    ans = false;
                    break;
                }
                else
                {
                    ans = true;
                }
            }
            if (ans == true)
            {
                Console.WriteLine("Yay!");
            }
            else
            {
                Console.WriteLine(":(");
            }
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
#define popcount __builtin_popcount
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
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(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    vector<int> v(N);
    int ini=A[0];
    // for (long long i = 1; i < N; i++) {
    //     if(ini<A[i]){
    //         v[i-1]=1;
    //         ini=A[i];
    //     }else if(ini>A[i]){
    //         v[i-1]=-1;
    //         ini=A[i];
    //     }
    // }
    int j=1;
    for (long long i = 0; i < N-1; ) {
        if(A[i]<=A[j]){
            v[i]=1;
            j++;
            i++;
        }else if(A[i]>A[j]){
            v[i]=-1;
            j++;
            i++;
        }
    }
    // vout(v)
    ll ret = 1000;
    ll stk = 0;
    for (long long i = 0; i < N; i++) {
        if(v[i]==1){
            ret += stk*A[i];
            stk=0;
            stk = (ret/A[i]);
            ret -= (ret/A[i])*A[i];
        }else if(v[i]==-1 || i==N-1){
            ret += stk*A[i];
            stk=0;
        }
        // debg(ret)
        // debg(stk)
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 3604
//                             In The Name Of Allah                                           
//                             	Mohammad Hosseini
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 

const int N = 3e5 + 100, OO = 724249387, T = 4500 + 100, M = 1e9 + 7, P = 6151, SQ = 280, lg = 30;
typedef pair <int, int> pii;
int a[N], n, k, ans = 0;
vector <int> v[N];

int dfs(int x, int y) {
	int mx = 0;
	for(auto u : v[x]) 
		mx = max(dfs(u, x) + 1, mx);
	if(mx < k - 1)
		return mx;
	if(x != 1 && mx == k - 1) {
		if(y != 1)
			ans++;
		return -1;
	}
	return 0;
}

int32_t main() {
 	use_fast;
	cin >> n >> k;
	for(int i = 1; i <= n; i++) 
		cin >> a[i];
	for(int i = 2; i <= n; i++)
		v[a[i]].pb(i);
	dfs(1, 0);
	if(a[1] != 1)
		ans++;
	cout << ans  << endl;
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04 
5- ...
*/



Measured memory_bytes: 20836