akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, s) for (int i = s; i < (int)(n); i++)
#define twopo(k)  1 << k

typedef vector<int> vec1;
typedef vector<vector<int>> vec2;
typedef vector<vector<char>> cvec2;
typedef pair<int, int> pairi;
typedef map<int, int> mapii;


vec1 vecplus(const vec1 &first, const vec1 &second){
  int length = first.size();
  vec1 answer(length);
  rep(i,length){
    answer.at(i) = first.at(i) + second.at(i);
  }
  return answer;
}

vec2 listmake(const int &row, const int &col){
  vec2 list;
  rep(i,row){
    vec1 v(col);
    rep(j,col){
      cin >> v.at(j);
    }
    list.push_back(v);
  }
  return list;
}


int main(){
  int64_t N;
  cin >> N;
  int64_t ans = 0;
  vector<int64_t> height(N);
  map<int64_t, int64_t> counter;
  for(int64_t i = 0; i < N; i++){
    int64_t a;
    cin >> a;
    height.at(i) = i - a;
    if(counter.count(i + a)){
      counter[i + a]++;
    }else{
      counter[i + a] = 1;
    }
  }
  for(int64_t i = 0; i < N; i++){
    if(counter.count(height.at(i))){
      ans += counter.at(height.at(i));
    }
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 17256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
using namespace std;

int main(){
    int n,m ;
    cin >> n >> m ;
    vector<int> a(n) ;
    for (size_t i = 0; i < n; i++)
    {
        cin >> a.at(i) ;
    }
    a.at(0) %= m ;
    for (size_t i = 0; i < n-1; i++)
    {
        a.at(i+1) += a.at(i) ;
        a.at(i+1) %= m ;
    }
    map<int,int64_t> mod ;
    mod[0] ++ ;
    vector<int> num(1,0) ;
    for (size_t i = 0; i < n; i++)
    {
        mod[a.at(i)] ++ ;
        if (mod[a.at(i)] == 1)
        {
            num.push_back(a.at(i)) ;
        }
        
    }
    int64_t ans = 0 ;
    for (size_t i = 0; i < num.size(); i++)
    {
        ans += mod[num.at(i)] * (mod[num.at(i)] -1) /2 ;
    }
    cout << ans << endl ;
}


Measured memory_bytes: 4860
#include <stdio.h>
int main(void){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a==5 && b==5 && c==7) printf("YES\n");
  else if(a==5 && b==7 && c==5) printf("YES\n");
  else if(a==7 && b==5 && c==5) printf("YES\n");
  else printf("NO\n");
  return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

LL N,A,B,C,D;

int main(){
	cin >> N >> A >> B >> C >> D;
	--N;
	LL X = abs(A-B);
	LL Y = D-C;
	LL Z = 0;
	while(N>=0){
		if(C*N-Y*Z <= X && X <= D*N+Y*Z) return ((cout << "YES" << endl),0);
		N -= 2;
		++Z;
	}
	cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100005
#define NIL -1
  
struct Node{
  int p, left, right;
};
struct Node T[N];
int n;
  
void inorder(int p){
  if(p != NIL) {
    inorder(T[p].left);
    printf(" %d", p);
    inorder(T[p].right);
  }
}
  
void postorder(int p){
if(p != NIL) {
    postorder(T[p].left);
    postorder(T[p].right);
    printf(" %d", p);
  }
}
  
void preorder(int p){
if(p != NIL) {
  printf(" %d", p);
  preorder(T[p].left);
  preorder(T[p].right);
  }
}
  
  
  
main(){
  int i, id;
  
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    T[i].left = T[i].p = T[i].right = NIL;
  }
  for(i = 0; i < n; i++){
    scanf("%d", &id);
    scanf("%d %d", &T[id].left, &T[id].right);
      T[T[id].left].p = id;
      T[T[id].right].p = id;
    }    
  
  printf("Preorder\n");
  for(i = 0; i < n; i++){
    if(T[i].p == NIL){
      preorder(i);
    }
  }
  printf("\nInorder\n");
  for(i = 0; i < n; i++){
    if(T[i].p == NIL){
      inorder(i);
    }
  }
  printf("\nPostorder\n");
  for(i = 0; i < n; i++){
    if(T[i].p == NIL){
      postorder(i);
    }
  }
  printf("\n");
  return 0;
}

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


int main(){
  int n, m;
  cin >> n >> m;
  if (n < m){
  vector<int>vec(m);
  for (int i = 0; i < m ; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  vector<int>change(m-1);
  for (int j = 0; j < m-1; j++){
    change.at(j) = vec.at(j+1)-vec.at(j);
  }
  sort(change.begin(),change.end());
  reverse(change.begin(),change.end());
  int s = 0;
  for (int k = n-1;k<m-1;k++){
    s += change.at(k);
  }
    cout << s <<endl;
  }
  else
    cout << 0 << endl;
}
    
    
      
    


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;
using ll = long long;

static const int MAX_N = 1e5;
static const int MAX_M = 1e5;

bool accepted[MAX_N + 1];
int penalty[MAX_M + 1];

/**
 * main
 */
int main () {
  int N; cin >> N;
  int M; cin >> M;

  REP(i, 0, M) {
    int p; cin >> p;
    string S; cin >> S;

    if (S == "AC") accepted[p] = true;
    if (S == "WA" && !accepted[p]) penalty[p]++;
  }

  int sum_a = 0;
  int sum_p = 0;

  for (int p = 1; p <= N; p++) {
    sum_a += (int) accepted[p];
    sum_p += (accepted[p]) ? penalty[p] : 0;
  }

  printf("%d %d\n", sum_a, sum_p);
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

long long nCkmod(long long n, long long k) {
    long long denomi = 1;
    REP(i, n) {
        denomi *= (i + 1);
        denomi %= mod;
    }
    long long numera = 1;
    for (int i = n - k; i > 0; i--) {
        numera *= i;
        numera %= mod;
    }
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
vector<long long> dijkstra(vector<vector<pair<long long, long long>>> graph, long long s) {
    vector<long long> ans(graph.size(), -1);
    priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>>
        pq;
    pq.push({0, s});
    while (pq.size() > 0) {
        int cur1 = 0;
        int cur2 = 0;
        if (ans[pq.top().second] != -1) {
            pq.pop();
        } else {
            cur1 = pq.top().first;
            cur2 = pq.top().second;
            pq.pop();
            ans[cur2] = cur1;
            for (long long i = 0; i < graph[cur2].size(); i++) {
                pq.push({cur1 + graph[cur2][i].second, graph[cur2][i].first});
            }
        }
    }
    return ans;
}
signed main() {
    int n;
    cin >> n;
    vector<vector<pair<long long, long long>>> graph(n);
    REP(i, n - 1) {
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        graph[u].push_back({v, w});
        graph[v].push_back({u, w});
    }
    vector<long long> dist;
    dist = dijkstra(graph, 0);
    REP(i, n) {
        if (dist[i] % 2 == 0) {
            //cout << dist[i] << endl;
            cout << 0 << endl;
        } else {
            cout << 1 << endl;
        }
    }
}

Measured memory_bytes: 15616
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  
  int N;
  cin >> N;
  vector<int> vec(N);
  rep(i,N) {

    cin >>vec.at(i) ;
  }
  int count=1;
  int counting=0;
  
 repl(i,1,N)  {
   rep(j,i) {
     if (vec.at(j) <=vec.at(i)) {
       counting++;
     }
   }
     if(counting ==i) {
       count++;
       
     }
   counting=0;
   }
   

   cout << count << endl;
 }
   
    
    
  

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

namespace ConsoleApplication
{
    class Program
    {
        static void Main()
        {
            new Solution().answer();
        }
    }

    class Solution
    {
        string input1, input2 , ans;

        public Solution()
        {
            input1 = Console.ReadLine();  //N
            input2 = Console.ReadLine();  //a1 a2 a3....

            string[] input2_split = input2.Split(' ');

            List<int> list1 = new List<int>();  //4k組
            List<int> list2 = new List<int>();  //奇數組
            List<int> list3 = new List<int>();  //2倍數組但不為4的倍數

            int i, k, p;

            for (i = 0; i < Convert.ToInt32(input1); i++)
            {
                p = Convert.ToInt32(input2_split[i]) % 2;
                k = Convert.ToInt32(input2_split[i]) % 4;

                if (p * k == 0)
                {
                    if (k == 0)
                    {
                        list1.Add(Convert.ToInt32(input2_split[i]));
                    }
                    else
                    {
                        list3.Add(Convert.ToInt32(input2_split[i]));
                    }
                }
                else
                {
                    list2.Add(Convert.ToInt32(input2_split[i]));
                }
            }

            if (list3.Count() == 0)
            {
                if ((list1.Count() >= list2.Count())||(list1.Count()+1 == list2.Count()))
                {
                    ans = "Yes";
                }
                else { ans = "No"; }
            }
            else
            {
                if ((list1.Count() >= list2.Count()+1) || (list1.Count() + 1 == list2.Count()+1))
                {
                    ans = "Yes";
                }
                else { ans = "No"; }
            
            }

        }

        public void answer()
        {
            Console.WriteLine(ans);
        }
    }
}

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

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

Measured memory_bytes: 3596
let input = require('fs').readFileSync('/dev/stdin', 'utf8')
// let input = require('fs').readFileSync('./sample_a.txt', 'utf8')
.split(/\n| /)
// .map(item => parseInt(item))
.slice(0,-1)

const [S] = input
if(S.slice(-1) === "s"){
    console.log(`${S}es`)
}else{
    console.log(`${S}s`)
}

Measured memory_bytes: 29688
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

fun main() {
  val (n,w) = readLine()!!.split(' ').map { it.toInt() }
  val dp = LongArray(w+1){0}

  for (i in 0 until n){
    val (weight, cost) = readLine()!!.split(' ').map { it.toInt() }
    for (j in (w-weight) downTo 0){
      dp[j+weight] = max(dp[j+weight], dp[j]+cost)
    }
  }
  var ans = 0L
  dp.forEach { ans = max(ans, it) }
  println(ans)
}

Measured memory_bytes: 41100
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int N, Q; string s;
vector<pair<char, char> > td;
bool Clb(int k){
  REP(i, Q){
    if(td[i].first == s[k-1]){
      k = (td[i].second == 'R') ? k + 1 : k - 1;
      if(k == 0) return true;
      if(k == N + 1) return false;
    }  
  }
  return false;
}

bool Cub(int k){
  REP(i, Q){
    if(td[i].first == s[k-1]){
      k = (td[i].second == 'R') ? k + 1 : k - 1;
      if(k == N + 1) return true;
      if(k == 0) return false;
    }  
  }
  return false;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> Q >> s;
  REP(i, Q){
    char t, d; cin >> t >> d;
    td.push_back({t, d});
  }
  int lb = 0, ub = N + 1;
  while(ub - lb > 1){
    int mid = (lb + ub) / 2;
    if(Clb(mid)) lb = mid;
    else ub = mid;
  }
  int ans1 = lb;
  lb = 0; ub = N + 1;
  while(ub - lb > 1){
    int mid = (lb + ub) / 2;
    if(Cub(mid)) ub = mid;
    else lb = mid;
  }
  int ans2 = ub;
  cout << ans2 - ans1 - 1 << endl;
}


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

struct UnionFind{
    int num;
    vector<int> par,rank;
    UnionFind(int n):num(n),par(n),rank(n,1){
        iota(par.begin(),par.end(),0);
    }
    int root(int x){
        if (par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    bool merge(int x, int y){
        x=root(x),y=root(y);
        if (x==y) return false;
        if (rank[x]<rank[y]) swap(x,y);
        par[y]=x;
        rank[x]+=rank[y];
        --num;
        return true;
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    int size(int x){
        return rank[root(x)];
    }
    int count(){
        return num;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin >> N >> M;
    vector<vector<bool>> edge(N,vector<bool>(N,false));
    for (int i=0;i<M;++i){
        int A,B; cin >> A >> B;
        if (A>B) swap(A,B);
        edge[--A][--B]=true;
    }
    UnionFind uf(2*N);
    for (int i=0;i<N;++i){
        for (int j=i+1;j<N;++j){
            if (!edge[i][j]){
                uf.merge(i,j+N);
                uf.merge(i+N,j);
            }
        }
    }
    for (int i=0;i<N;++i){
        if (uf.same(i,i+N)){
            cout << -1 << '\n';
            return 0;
        }
    }
    vector<bool> check(N,false);
    vector<pair<int,int>> sz;
    for (int i=0;i<N;++i){
        if (!check[i]){
            int red=0,blue=0;
            for (int j=i;j<N;++j){
                if (uf.same(i,j)||uf.same(i,j+N)){
                    ++(uf.same(i,j)?red:blue);
                    check[j]=true;
                }
            }
            sz.emplace_back(red,blue);
        }
    }
    int n=sz.size();
    vector<vector<int>> dp(n+1,vector<int>(N+1,0));
    dp[0][0]=1;
    for (int i=0;i<n;++i){
        for (int j=N;j>=0;--j){
            if (j+sz[i].first<=N) dp[i+1][j+sz[i].first]|=dp[i][j];
            if (j+sz[i].second<=N) dp[i+1][j+sz[i].second]|=dp[i][j];
        }
    }
    int ans=M;
    for (int j=0;j<=N;++j){
        if (dp[n][j]){
            ans=min(ans,j*(j-1)/2+(N-j)*(N-j-1)/2);
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 2304
N, M = map(int, input().split())
A = list(map(int, input().split())) # 要素数N
BC = [list(map(int, input().split())) for _ in range(M)] # 要素数M

A = sorted(A) # 計算量NlogN
BC = sorted(BC, key=lambda x: x[1], reverse=True) # 計算量MlogM

D = []
for i in range(M): # 計算量N(len(D)<Nまでなので)
    for j in range(BC[i][0]):
        D.append(BC[i][1])
        if len(D) == N:
            break
    else:
        continue
    break

n = min(len(D), N)
for i in range(n): # 計算量N
    if A[i] < D[i]:
        A[i] = D[i]
    else:
        break

ans = sum(A)

print(ans)


Measured memory_bytes: 33744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<int,int> P;
#define Mod 1000000007


int main(){
    ll i,j;
    ll n,k;
    cin>>n>>k;

    if(n>=2*k-1) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;



    return 0;
}

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

int n;
string s, t;
int main()
{
    cin >> n >> s >> t;
    string ans = "";
    for (int i = 0; i < n; i++)
        ans += s[i],
        ans += t[i];
    cout << ans;

    return 0;   
}

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

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

    auto rank_one = N % 10;

    switch( rank_one )
    {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon" << endl;
            break;

        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon" << endl;
            break;

        case 3:
            cout << "bon" << endl;
            break;

        default:
            cout << "ERROR!!" << endl;
            break;
    }

    return 0;
}

Measured memory_bytes: 3648
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> as(n); cin >> as;
    vector<ll> accs(n);
    accs[0] = as[0];
    for(int i = 1; i < n; i++){
        accs[i] = accs[i - 1] + as[i];
    }
    ll ans = MLL;
    for(int pend = 2; pend < n - 1; pend++){
        ll s1 = accs[pend - 1];
        int c1 = lower_bound(accs.begin(), accs.end(), s1 / 2) - accs.begin();
        ll mini = MLL;
        ll mi1 = MLL, ma1 = 0;
        for(int i = -1; i <= 1; i++){
            int il = i + c1;
            if(il < 0 || il > pend - 2){ continue; }
            ll l = accs[il], r = accs[pend - 1] - accs[il];
            if(abs(r - l) < mini){
                mini = abs(r - l);
                mi1 = min(l, r);
                ma1 = max(l, r);
            }
        }
        ll s2 = accs[n - 1] - accs[pend - 1];
        int c2 = lower_bound(accs.begin(), accs.end(), s2 / 2 + s1) - accs.begin();
        mini = MLL;
        ll mi2 = MLL, ma2 = 0;
        for(int i = -1; i <= 1; i++){
            int il = i + c2;
            if(il < pend || il > n - 2){ continue; }
            ll l = accs[il] - s1, r = accs[n - 1] - accs[il];
            if(abs(r - l) < mini){
                mini = abs(r - l);
                mi2 = min(l, r);
                ma2 = max(l, r);
            }
        }
        ans = min(ans, max(ma1, ma2) - min(mi1, mi2));
    }
    cout << ans << '\n';
}


Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>

using namespace std;

const int inf = 0x3f3f3f3f;

int h[100100];
int dp[100100];

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

    for(int i=1;i<=n;i++)
        cin>>h[i];
    dp[1] = 0;
    dp[2] = abs(h[2]-h[1]);
    
    for(int i=3;i<=n;i++)
    {   
        int least = inf;
        for(int j=max(1,i-k);j<i;j++)
        {
           least = min(least,dp[j]+abs(h[i]-h[j]));
        }
        dp[i] = least;
    }
    cout<<dp[n];
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n;
    cin >> n;
    ll ans = n * (n - 1) / 2;
    cout << ans;
    
}

Measured memory_bytes: 256
n=int(input());A=[]
for i in range(n):
    A.append(int(input()))
A.sort()
i = 1
count = 0
odd = 1
value = A[0]
while i < n:
    if value != A[i]:
        count += odd%2
        odd = 1
        value = A[i]
    else:
        odd += 1
    i += 1
count+= odd%2
print(count)

Measured memory_bytes: 7388
# 累積和を使う
N, Q = map(int, input().split())  #長さN, Q個の問い

S = str(input())  # 長さNの文字列S(これはA, C, G, Tのいずれかの文字のみ)

starts_ends = []
# 始点lと終点rがQセット与えられる
for _ in range(Q):
    starts_ends.append(list(map(int, input().split())))

# print('hoge')
# print(N)
# print(Q)
# print(S)
# print(starts_ends)

# 'AC'を探す旅に出る
cumulative_sum = [0, 0]
for i in range(1, len(S)):
    if S[i] == 'C' and S[i-1] == 'A':
        cumulative_sum.append(cumulative_sum[i]+1)
    else:
        cumulative_sum.append(cumulative_sum[i])

for i in range(Q):
    start, end = starts_ends[i]
    print(cumulative_sum[end] - cumulative_sum[start])


Measured memory_bytes: 30616
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[n];
    int ans = 0;
    for(int i = 0;i < n;i++)
    {
        cin >> a[i];
        if(i > 0 && a[i] == a[i - 1])
        {
            ans++;
            a[i] = -1;
        }
    }
    cout << ans << "\n";
    
    return 0;
}

Measured memory_bytes: 256
use std::io::{self, Read};

fn main() {
    let mut buffer = String::new();
    io::stdin().read_to_string(&mut buffer).expect("Could't read stdin");
    let v: Vec<i32> = buffer.split_whitespace().map(|n| n.parse().unwrap()).collect();
    let time: i32 = if v[0] - v[1] >= 0 {
        v[0] - v[1]
    } else {
        0
    };
    println!("{}", time);
}

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

using namespace std;

int main() {
  std::string S;
  cin >> S;
  if (S == "Sunny")
      cout << "Cloudy";
  else if (S == "Cloudy")
      cout << "Rainy";
  else if (S == "Rainy")
      cout << "Sunny";
}


Measured memory_bytes: 256
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
n = int(input())
xs = list(map(int,input().split()))
min_x = sum(xs) / n
x_z = Decimal(str(min_x)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
ans = 0
for i in xs:
    ans += (x_z - i)**2
print(ans)

Measured memory_bytes: 5332
#include <iostream>
using namespace std;
//include
//------------------------------------------
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

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

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

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

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

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

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

int n,as[(int)1e6];
int main() {
	int H,W,h,w;
	scanf("%d%d%d%d",&H,&W,&h,&w);
	if(H%h==0 && W%w==0){
		printf("No\n");
	}else{
		printf("Yes\n");
		REP(j,H){
			REP(i,W){
				if(i%w==0 && j%h==0){
					printf("%d ", int(1e9)-1);
				}else if(i%w==w-1 && j%h==h-1){
					printf("%d ", -int(1e9));
				}else{
					printf("%d ", 0);
				}
			}
			printf("\n");
		}
	}

	return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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 gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll d;
  cin>>d;
  vl c(26);
  rep(i,26){
    cin >> c[i];
  }
  vll s(d, vl(26));
  rep(i, 365){
    rep(j,26){
      cin >> s[i][j];
    }
  }
  rep(i, d){
    ll num = i % 26;
    if(num==0){
      num = 26;
    }
    print(num);
  }
}

Measured memory_bytes: 3724
from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil, gcd
from bisect import bisect_left
import random
from itertools import combinations, accumulate
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

class PrimeTool(object):
    def __init__(self, n):
        self.n = n
        self.primes = []
        self.sieves = []

    def generate_primes(self):
        if len(self.primes) == 0 and len(self.sieves) == 0:
            is_prime = [True] * (self.n + 1)
            is_prime[0] = is_prime[1] = False
            self.sieves = [k for k in range(self.n + 1)]
            self.sieves[0] = 1
            for p in range(2, self.n + 1):
                if is_prime[p]:
                    self.primes.append(p)
                    for i in range(p, self.n + 1, p):
                        is_prime[i] = False
                        self.sieves[i] = p
            return self.primes

    def factorization(self, n):
        arr = []
        temp = n
        for i in range(2, int(-(-n**0.5//1))+1):
            if temp % i == 0:
                c = 0
                while temp % i==0:
                    c += 1
                    temp //= i
                arr.append((i, c))
        if temp != 1:
            arr.append((temp, 1))
        return arr

    def fast_factorization(self, num):
        # 1度計算だけ
        self.generate_primes()

        # 試し割りなしのfact
        arr = []
        temp = num
        while temp != 1:
            i = self.sieves[temp]
            c = 0
            while temp % i==0:
                c += 1
                temp //= i
            arr.append((i, c))
        if temp != 1:
            arr.append((temp, 1))
        return arr

def solve(N, A):
    tool = PrimeTool(max(A) + 1)
    primes = tool.generate_primes()
    ct = Counter()

    pair_wise = True
    for i, Ai in enumerate(A):
        arr = tool.fast_factorization(Ai)
        for p, _ in arr:
            ct[p] += 1
            if ct[p] > 1:
                pair_wise = False
                break
        if not pair_wise:
            break

    # 共通gcd
    prod = A[0]
    for k in range(1, N):
        prod = gcd(prod, A[k])
    
    if pair_wise:
        print("pairwise coprime")
    elif prod == 1:
        print("setwise coprime")
    else:
        print("not coprime")

def main():
    from builtins import int, map
    N = int(input())
    A = list(map(int, input().split()))
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 241208
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;
LL gcd( LL a, LL b )
{
  LL c;
  while ( a != 0 ) {
     c = a; a = b%a;  b = c;
  }
  return b;
}
LL lcm( LL m, LL n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;

	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

int main(){
	LL t,a,b,c,d;
	cin>>t;
	FOR(cnt,0,t){
		//cerr<<"cnt:"<<cnt<<" ";
		cin>>a>>b>>c>>d;
		LL gcd1=gcd(b,d);
		//cerr<<gcd1<<endl;
		if(a<b||gcd1+c<b||b>d||(gcd1==b&&a%b>c)){
			cout<<"No"<<endl;
			continue;
		}else{

			cout<<"Yes"<<endl;
		}
	}
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
graph = [[] for _ in range(n+1)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)


def dfs(root):
    now = root[-1]
    ret = []
    for i in graph[now]:
        if i in root:
            pass
        else:
            ret.append(dfs(root + [i]))
    if not ret:
        if len(root) == n:
            return 1
        return 0

    return sum(ret)


print(dfs([1]))


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main (String[] args)
    {
        int h, w, i;
        String[] sh = new String[1000];
        String[] sw = new String[1000];
        Scanner sc = new Scanner(System.in);

        try
        {
            for (i = 0; true; i++)
            {
                sh[i] = sc.next();
                sw[i] = sc.next();
                if (sw[i].equals("0") && sh[i].equals("0")) break;
            }

            sc.close();

            int I = i;

            for (i = 0; i < I; i++)
            {
                h = Integer.parseInt(sh[i]);
                w = Integer.parseInt(sw[i]);

                for (int j = 1; j <= h; j++)
                {
                    for (int k = 1; k <= w; k++)
                    {
                        System.out.print("#");
                    }
                    System.out.println();
                }
                System.out.println();
            }
        }
        catch (NumberFormatException e)
        {
            System.out.println(e);
        }
    }
}


Measured memory_bytes: 33212
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const int N = 1000000 + 5;

int main(){
    fast;
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    while(a > 0 || c > 0){
        c = c - b;
        a = a - d;
        if(c <= 0){
            cout << "Yes";
            break;
        }
        else if(a <= 0){
            cout << "No";
            break;
        }
    }
    return 0;
}
//                                     #!!{*[$um1t_Kum@r]*}!!#


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

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

  int ans = 1;
  rep(i, n - 1) {
    if (s[i] != s[i + 1]) ans++;
  }

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


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		String a = s.next(), b = s.next();
		for (int i = 0; i < a.length(); i++) {
			System.out.print(a.charAt(i) + "" + b.charAt(i));
		}
	}

}


Measured memory_bytes: 23764
# include <bits/stdc++.h>
# define fi first
# define se second
# define mk make_pair
using namespace std;
typedef long long LL;
const int MAXN = 1e2 + 5;
const int MAXM = 5e3 + 5;
const int MOD = 1e9 + 7;
const LL INF = 1e18;
typedef long long LL;
typedef pair<double, int> PDI;
char s[MAXN];

bool checkPalindrome(int l, int r){
    while(l <= r){
        if(s[l] != s[r])  return false;
        ++l;
        --r;
    }
    return true;
}

int main(){
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    bool flag = true;
    flag &= checkPalindrome(1, n);
    flag &= checkPalindrome(1, (n-1)/2);
    flag &= checkPalindrome((n+3)/2, n);
    printf("%s\n", flag ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<vector>
#include<initializer_list>
#include<string>
using namespace std;
  int main(){
 int N;
 cin >> N;
int K;
cin >> K;
int X;
cin >> X;
int Y;
cin >> Y;
    
if (N>K){
cout << K*X + (N-K)*Y << endl;}
    else if (N <= K)
      cout << N*X << endl;
    
    
    
    


}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <chrono>
#include <queue>
#include <string>
#include <cassert>
#include <bitset>
#include <stack> 

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 1000000007
#define BASE 77747
#define PI acos(-1.0)
#define MAXLEN 29

using namespace std;

typedef pair <int, int> pii;
typedef long long ll;
typedef vector <ll> vll;

int n;
vector <int> t[100000];


pair <ll, ll> rec(int cur, int par) {
	pair <ll, ll> ans = make_pair(1, 1);
	for (int i = 0; i < t[cur].size(); i++) {
		if (t[cur][i] == par) continue;
		pair <ll, ll> tmp = rec(t[cur][i], cur);
		ans.first *= (tmp.second + tmp.first) % MOD;
		ans.first %= MOD;
		ans.second *= tmp.first;
		ans.second %= MOD;
	}
	return ans;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--;
		b--;
		t[a].push_back(b);
		t[b].push_back(a);
	}
	pair <ll, ll> ans = rec(0, -1);
	cout << (ans.first + ans.second) % MOD << endl;
	return 0;
}

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

main(){
  string x,y;
  cin>>x;
  y= x;
  reverse(x.begin(), x.end());
  if (x ==y) cout <<"Yes"<<endl;
  else cout <<"No"<<endl;
  return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
#include <string>
using namespace std;
#define N 100009
#define ll long long

int main(){
    int n;
    cin>>n;
    string a;
    cin>>a;
    int l=a.size();
    bool ans=true;
    if (l%2==1) cout<<"No"<<endl;
    else{
        int p=l/2;
        for (int i=0; i<p; i++){
            if (a[i]!=a[p+i]) ans=false;
        }
        if (ans) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 256
N, K = input().split()
P = input().split()
K = int(K)

S = []
count = 0
max_sum = 0
for p in P:
    e = (int(p) + 1) / 2
    if count == 0:
        S.append(e)
    else:
        S.append(S[count-1] + e)
    if count == (K - 1):
        max_sum = S[count]
    elif count > (K - 1):
        sum = S[count] - S[count - K]
        if max_sum < sum:
            max_sum = sum
    count += 1
print(max_sum)

Measured memory_bytes: 23524
package main

import (
	"fmt"
)

func main() {
	var s, t string
	fmt.Scanf("%s", &s)
	fmt.Scanf("%s", &t)

	count := 0
	for i, _ := range s {
		if s[i] != t[i] {
			count++
		}
	}

	fmt.Printf("%d\n", count)
}


Measured memory_bytes: 4588
X, Y = map(int, input().split())
ans = 0
if X == 3:
    ans += 100000
elif X == 2:
    ans += 200000
elif X == 1:
    ans += 300000

if Y == 3:
    ans += 100000
elif Y == 2:
    ans += 200000
elif Y == 1:
    ans += 300000

if X ==1 and Y ==1:
    ans += 400000
print(ans)

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

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto S = RD!string;
	long ans;
	long last;
	long lastCnt;
	foreach (i; 1..S.length)
	{
		if (S[i-1..i+1] == "><" || S[i-1..i+1] == "<>")
		{
			auto cnt = i - last;
			ans += cnt * (cnt+1) / 2;
			if (S[i-1..i+1] == "><")
				ans -= min(cnt, lastCnt);
			last = i;
			lastCnt = cnt;
		}
		debug writeln("i:", i, " ans:", ans);
	}
	auto cnt = S.length - last;
	ans += cnt * (cnt+1) / 2;
	if (S[$-1] == '>')
		ans -= min(cnt, lastCnt);

	writeln(ans);
	stdout.flush();
	debug readln();
}

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

 using namespace std;

 int main() {
   int N;

   cin >> N;

   vector<int> H(N);

   for (int i = 0; i < N; i++) cin >> H.at(i);

   int ans = 1;

   for (int i = 1; i < N; i++) {
     bool view = true;
     for (int j = 0; j < i; j++) {
       if (H.at(i) < H.at(j)) {
         view = false;
         break;
       }
     }
     if(view) ans++;
   }

   cout << ans << endl;

}


Measured memory_bytes: 256
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
// https://atcoder.jp/contests/abc174/tasks/abc174_d
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n;
    string s;
    cin >> n >> s;
    ll totalR = 0;
    ll baseW = 0;
    ll ans = 0;
    for(int i = 0;i<n;i++){
        if(s[i] == 'R') totalR++;
    }
    for(int i = 0;i<totalR;i++){
        if(s[i] == 'W') baseW++;
    }
    ans = baseW;
    cout << ans;
    return 0; 
}

Measured memory_bytes: 3764
#include <iostream>

using namespace std;

int n;
int a[10000];

int main() {
    cin >> n;
    int count;
    for (int i = 1; i < n + 1; ++i) {
        if (i < 10) {
            count++;
        } else if (i > 99 && i < 1000) {
            count++;
        } else if (i > 9999 && i < 100000) {
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 2e5 + 5;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
 
int fac[MAX_N], inv[MAX_N];
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b, bool usemod = true) {ll c = 1LL; while (b > 0) {if (b & 1LL) {if(!usemod)c*=a;else c = a * c%mod;}if (!usemod) a*=a;else a = a * a%mod; b >>= 1LL;}return c;}
void _nCr() {fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) {fac[i] = fac[i - 1LL] * i%mod;}for (int i = 0; i < MAX_N; i++) {inv[i] = POW(fac[i], mod - 2);}}
ll nCr(ll n, ll r) {return (fac[n] * inv[r] % mod)*inv[n - r] % mod;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}

bool solve() {
	int a,b; cin >> a >> b;
	cout << (a + b) % 24 << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const int M = 1e7;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};

int main(){
  int n;
  ll x;
  cin >> n >> x;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

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

  int c = 0;
  rep(i,n) {
    if (x >= a[i]){
      c++;
      x -= a[i];
    } else {
      break;
    }
  }

  if (x != 0 && c == n) c--;
  
  cout << max(c,0) << endl;

  return 0;
}


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

typedef long long ll;
const int mod=1000000007;

ll bp(ll a, ll n){
    ll res=1;
    while(n){
        if(n&1)res=res*a%mod;
        n>>=1;
        a=a*a%mod;
    }
    return res;
}

int n,k;
vector<int> g[100005];

ll dfs(int x,int p){
    if(k<g[x].size())return 0;
    ll can=k-2,res=1;
    can+=p==-1;
    for(int i=0;i<g[x].size();i++){
        int y=g[x][i];
        if(y!=p){
            res*=can;can--;res%=mod;
            res*=dfs(y,x);res%=mod;
        }
    }
    return res;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>k;
    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cout<<dfs(1,-1)*k%mod<<endl;

    return 0;
}

Measured memory_bytes: 11648
use proconio::input;

fn main() {
    input! {
        n: usize,
        xyh: [(isize, isize, isize); n]
    }

    for x in 0..=100 {
        for y in 0..=100 {
            // center: (x, y)
            let mut center_h = -1;
            for &(xi, yi, hi) in &xyh {
                if hi == 0 {
                    continue;
                }
                center_h = hi as isize + (xi - x as isize).abs() + (yi - y as isize).abs();
            }
            let mut is_center = true;
            for &(xi, yi, hi) in &xyh {
                let hi_test = (center_h - (xi - x as isize).abs() - (yi - y as isize).abs()).max(0);
                if hi != hi_test {
                    is_center = false;
                    break;
                }
            }
            if is_center {
                println!("{} {} {}", x, y, center_h);
                return;
            }
        }
    }
}


Measured memory_bytes: 2156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,W;cin >> n >> W;
	vector<pii> a(n);
	int mi=1000000000,ma=0;
	rep(i,n){
		cin >> a.at(i).second >> a.at(i).first;
		mi=min(mi,a.at(i).second);
		ma=max(ma,a.at(i).second);
	}
	vector<int> cnt(4);
	rep(i,n){
		cnt.at(a.at(i).second-mi)++;
	}
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());
	ll ans=0;
	rep(i,cnt[0]+1){
		rep(j,cnt[1]+1){
			rep(k,cnt[2]+1){
				rep(l,cnt[3]+1){
					if(i+j+k+l>n) continue;
					ll sumw=0,sumv=0;
					vector<int> cur(4),cntma(4);
					cntma[0]=i;
					cntma[1]=j;
					cntma[2]=k;
					cntma[3]=l;
					rep(b,4){
						rep(c,n){
							if(a.at(c).second==mi+b && cur.at(b)<cntma[b]){
								if(sumw+a.at(c).second>W) continue;
								sumw+=a.at(c).second;
								sumv+=a.at(c).first;
								cur.at(b)++;
							}
						}
					}
					ans=max(ans,sumv);
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=e-1; i>=s; i--)

int main(){

    ll n, h; cin >> n >> h;
    ll a[n], b[n];
    rep(i, n){
        cin >> a[i] >> b[i];
    }

    ll amax = *max_element(a, a+n);

    sort(b, b+n, greater<ll>());

    ll cnt = 0;

    bool finishflag = false;
    rep(i, n){
        if(b[i] <= amax) continue;

        cnt++;
        h -= b[i];

        if(h <= 0){
            finishflag = true;
            break;
        }
    }

    if(finishflag){
        cout << cnt;
    }
    else{
        if(h % amax == 0){
            cout << cnt + h / amax;
        }
        else{
            cout << cnt + h / amax + 1;
        }
    }

    return 0;
}

Measured memory_bytes: 1792
def traverse
  a = []
  length = 1
  now = 0
  @list[now] = 1
  loop do
   @n.times do |i|
     if @m[now][i] == 1 && @list[i] == 0
       a.push([i, length + 1])
       @data[i].length = length
       @list[i] = 1
     end
   end
   if a.empty?
     return nil
   end
   next_one = a.shift
   now = next_one[0]
   length = next_one[1]
  end
  return @list
end

D = Struct.new(:length)
@n = gets.chomp.to_i
@time = 0
@m = Array.new(@n){Array.new(@n){0}}
@data = Array.new(@n){D.new(-1)}
@list = Array.new(@n){0}
@n.times do
	s = gets.split.map(&:to_i)
	i = s[0] - 1
	s[1].times do |l|
		j = s[l + 2] - 1
		@m[i][j] = 1
	end
end
@data[0].length = 0
traverse

@n.times do |i|
	puts "#{ i + 1 } #{@data[i].length}"
end

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

using namespace std;

int n,k;
long long ans = 0;

int main(){
	scanf("%d %d",&n,&k);
	for(int i=k+1;i<=n;i++){
		ans += (n/i) * (i-k);
		ans += max(0,n%i-k+(k!=0));
	}
	printf("%lld\n",ans);	
	return 0;
}

Measured memory_bytes: 256