akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int N,K;
   cin >> N >> K;
   int A[N];
   int D[N+1];
   memset(D,0,sizeof(D));
   for (int i = 0; i < N; i++) {
      cin >> A[i];
      D[max(0,i-A[i])]+=1;
      D[min(i+1+A[i],N)]-=1;
   }
   for(int i =0; i<K; i++){
      int cur = D[0];
      for(int j = 0 ; j < N; j++){
         A[j]=cur;
         cur+=D[j+1];
      }
      if(D[0]==N&&D[N]==-N){
         break;
      }
      memset(D,0,sizeof(D));
      for(int j=0;j<N;j++){
         D[max(0,j-A[j])]+=1;
         D[min(j+1+A[j],N)]-=1;
      }
   }
   for(int i=0;i<N;i++){
      cout << A[i] << " " ;
   }
   cout << endl;
   return 0;
}


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

using namespace std;

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

  vector<long long> a(n);
  for(int idx = 0; idx < n; idx++) std::cin >> a[idx];

  bool continuity = true;
  int ans = 0;
  while(continuity){
    continuity = false;
    for(int idx = 0; idx < n; idx++){
      if(a[idx] % 2 == 0){
        a[idx] /= 2;
        ans += 1;
        continuity = true;
      }
    }
  }

  std::cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
 
#define MAX_N 1000000
#define MAX_M 100
#define min(a,b) a < b ? a : b
 
void shellSort(int*,int);
void insertionSort(int*,int,int);
void print(int*,int*,int,int);
 
int cnt;
 
int main(){
  int N,i,a[MAX_N];
 
  scanf("%d" ,&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d" ,a+i);
  }
  shellSort(a,N);
 
  return 0;
}
 
void shellSort(int a[],int N){
  int G[MAX_M],p = 0,m,i;
  cnt = 0;
 
  for(m = 1 ; m*3+1 < N ; m = m*3+1){};
  for(; m > 0 ; m /= 3){
    G[p++] = m;
  }
 
  p = min(p,100);
  for(i = 0 ; i < p ; i++){
    insertionSort(a,N,G[i]);
  }
  print(a,G,N,p);
}
 
void insertionSort(int a[],int N,int g){
  int i,v,j;
 
  for(i = g ; i < N ; i++){
    v = a[i]; j = i - g;
    while(j >= 0 && a[j] > v){
      a[j+g] = a[j];
      j -= g;
      cnt++;
    }
    a[j+g] = v;
  }
}
 
void print(int a[],int G[],int N,int m){
  int i;
   
  printf("%d\n" ,m);
  for(i = 0 ; i < m ; i++){
    if(i != m-1){
      printf("%d " ,G[i]);
    }else{
      printf("%d\n" ,G[i]);
    }
  }
  printf("%d\n" ,cnt);
  for(i = 0 ; i < N ; i++){
    printf("%d\n" ,a[i]);
  }
}



Measured memory_bytes: 5700
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

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

int main()
{
	int N, M, Q;
	cin >> N >> M >> Q;
	vector<vector<int>> dp(N + 1, vector<int>(N + 1));
	for (int i = 0; i < M; i++) {
		int L, R;
		cin >> L >> R;
		dp[L][R]++;
	}
	for (int k = 1; k <= N; k++) {
		for (int i = 1; i + k <= N; i++) {
			int j = i + k;
			dp[i][j] += dp[i + 1][j] + dp[i][j - 1] - dp[i + 1][j - 1];
		}
	}
	for (int i = 0; i < Q; i++) {
		int p, q;
		cin >> p >> q;
		int ans = dp[p][q];
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 1920
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	int gcd(int a, int b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	int gcd(int[] arr) {
		int ans = gcd(arr[0], arr[1]);
		for (int i = 2; i < arr.length; i++) {
			ans = gcd(ans, arr[i]);
		}
		return ans;
	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

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

		if (N == 2) {
			//N==2の場合、小さいほうを大きいほうに書き換えればそれが最大
			out.println(Math.max(a[0],a[1]));
			return;
		}

		int[] left = new int[N];
		int[] right = new int[N];

		left[0] = a[0];
		for (int i = 1; i < N; i++) {
			left[i] = gcd(left[i - 1], a[i]);
		}

		right[N - 1] = a[N - 1];
		for (int i = N - 2; i >= 0; i--) {
			right[i] = gcd(right[i + 1], a[i]);
		}

		int ans = 0;

		for (int i = 0; i < N; i++) {
			if (i == 0) {
				ans = Math.max(ans, right[i + 1]);
			} else if (i == N - 1) {
				ans = Math.max(ans, left[N - 2]);
			} else {
				int l = left[i - 1];
				int r = right[i + 1];

				ans = Math.max(ans, gcd(l, r));
			}
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

int main(){
    ll n;
    cin >> n;
    ll a[n] = {};
    ll cnt = 0,memo = 0;
    rep(i,0,n) cin >> a[i];
    sort(a,a+n);

    rep(i,0,n){
        if(i > 0 && memo*2 < a[i]){
            cnt = 0;
        }
        cnt++;
        memo += a[i];
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 4400
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int N; cin >> N;
    vector<double> d(N);
    rep(i,N){
        cin >> d[i];
    }

    auto d2(d);
    sort(all(d2));

    rep(i,N){
        int i1 = lower_bound(d2.begin(),d2.end(),d[i]) - d2.begin();
        int i2 = upper_bound(d2.begin(),d2.end(),d[i]) - d2.begin();
        cout << i2 - i1 - 1 + 3 * i1 << endl;
    }
}



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

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void solve(long long N){
    string ans;
    
    while(N > 0){
        N -= 1;
        ll x = N % 26;
        ans.push_back(x+'a');
        N /= 26;
    }
    reverse(ALL(ans));
    cout<<ans<<endl;
}
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18;
struct edge{int from;int to;ll cost;};
int main(){
    int n,m;cin >> n >> m;
    vector<vector<int>> g(n);
    vector<edge> h(m);
    for(int i=0;i<m;i++){
        int a,b;cin >> a >> b;
        ll c;cin >> c;
        a--,b--;
        g[b].push_back(a);
        h[i]=edge{a,b,-c};
    }
    vector<bool> f(n);
    stack<int> st;
    st.push(n-1);
    f[n-1]=true;
    while(!st.empty()){
        int p=st.top();
        st.pop();
        for(auto x:g[p]){
            if(!f[x]){
                st.push(x);
                f[x]=true;
            }
        }
    }
    vector<ll> d(n,INF);
    d[0]=0;
    for(int i=0;i<2*n;i++){
        for(int j=0;j<m;j++){
            int fr=h[j].from,to=h[j].to;
            ll co=h[j].cost;
            if(d[fr]!=INF&&d[to]>d[fr]+co){
                d[to]=d[fr]+co;
                if(i>=n-1&&f[to]){
                    cout << "inf" << endl;
                    return 0;
                }
            }
        }
    }
    cout << -d[n-1] << endl;
}


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

int main() {
  int n;
  cin >> n;
  map<string,int> m;
  m["AC"]=0;
  m["WA"]=0;
  m["TLE"]=0;
  m["RE"]=0;
  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    m[s]++;
  }
  cout << "AC" << " " << 'x' << " " << m["AC"] << endl;
  cout << "WA" << " " << 'x' << " " << m["WA"] << endl;
  cout << "TLE" << " " << 'x' << " " << m["TLE"] << endl;
  cout << "RE" << " " << 'x' << " " << m["RE"] << endl;
}



Measured memory_bytes: 3552
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
  char name[11];
  int cnt;
} dic_t;
int compare_string(const void *a, const void *b) {
  return strcmp(( char * )a , ( char * )b );
}
int compare_int(const void *a, const void *b){
  //  return ((dic_t*)a)->cnt - ((dic_t*)b)->cnt;
}

int main(void){
  int i,j;
  //  dic_t dic[200000];
  char ii[200000][11];
  char aa[11];
  int len,flg;
  int cnt,maxcnt;
  scanf("%d",&len);
  for(i=0;i<len;i++){
    scanf("%s\n",ii[i]);
    //    printf("i %d s:%s\n",i,aa);

    /*
      for(j=0;j<i;j++){
          if(strcmp(aa,dic[j].name) == 0){
                dic[j].cnt++;
              break;
            }
      }
      //        printf("i %d j%d\n",i,j);
      if(j==i){
        strcpy(dic[j].name,aa);
        dic[j].cnt++;
        //    printf("cpyi %d s:%s\n",j,dic[j].name);
      }
      printf("i %d s:%s\n",i,dic[i].name);
    */
  }
  //  qsort(dic,  len,sizeof(dic), compare_int);
  qsort(ii,  len,sizeof(ii[0]), compare_string);
maxcnt = 1;	
cnt = 1;
  for(i=1;i<len;i++){
	if (strcmp(ii[i-1],ii[i]) == 0){
		cnt++;	
		if(maxcnt < cnt){
			maxcnt = cnt;
        }
    }
    else{
      cnt=1;
    }
    //    printf("afi %d s:%s cnt:%d\n",i,ii[i].name,dic[i].cnt);
//        printf("afi %d s:%s maxcnt:%d\n",i,ii[i],maxcnt);
  }
//          printf("maxcnt %d\n",maxcnt);
cnt = 1;
  for(i=0;i<len;i++){
//          printf("i %d cnt %d maxcnt %d %s %s\n",i,cnt,maxcnt,ii[i-1],ii[i]);
	if (maxcnt == 1){
        printf("%s\n",ii[i]);
    }

    
    if (strcmp(ii[i-1],ii[i]) == 0){
		cnt++;	
//          printf("cnt %d maxcnt %d\n",cnt,maxcnt);
      if(maxcnt <= cnt){
        printf("%s\n",ii[i]);
        }
    }
    else{
      cnt=1;
    }
  }
  return 0;
}


Measured memory_bytes: 4476
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
 
const int maxn = 2e5 + 20;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	int last = 0 , res = 0;
	for(int i = 0; i < n; i++)
	{
		int p;
		cin >> p;
		p--;

		if(p == i)
			last++;
		else
		{
			res += (last + 1) / 2;
			last = 0;
		}
	}

	res += (last + 1) / 2;
	cout << res << endl;
}


















Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if(N <= 111) cout << 111 << endl;
  else if(N <= 222) cout << 222 << endl;
  else if(N <= 333) cout << 333 << endl;
  else if(N <= 444) cout << 444 << endl;
  else if(N <= 555) cout << 555 << endl;
  else if(N <= 666) cout << 666 << endl;
  else if(N <= 777) cout << 777 << endl;
  else if(N <= 888) cout << 888 << endl;
  else if(N <= 999) cout << 999 << endl;
}

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

#define ll long long
#define ld long double
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define sz(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/
const ll mod=1e9+7;
const ll INF=1e18;
/*****************************************************************************/

using namespace std;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	string s;
	int i;
	cin >>s;
	for (i=0;i<sz(s);i++) {
		if (s[i]=='?') s[i]='D';
	}
	cout <<s;
	return 0;
}
/******************************************************************************
******************************************************************************/


Measured memory_bytes: 3724
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        mut v: [chars; n]
    }
    for i in 0..n {
        v[i].sort();
    }
    v.sort();
    let mut ans: usize = 0;
    let mut c = 1;
    for i in 1..n {
        if v[i] == v[i - 1] {
            c += 1;
        } else {
            ans += c * (c - 1) / 2;
            c = 1;
        }
    }
    ans += c * (c - 1) / 2;
    println!("{}", ans);
}


Measured memory_bytes: 14588
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};

fn main() {
    input! {
        n: usize,
        p: [i64; n],
    }

    let mut cnt = 0;
    for i in 1..n - 1 {
        let a = p[i - 1];
        let b = p[i];
        let c = p[i + 1];
        let mid = a + b + c - min(a, min(b, c)) - max(a, max(b, c));
        if mid == b {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 2080
#include <bits/stdc++.h>
#include<chrono>
#define ll long long
using namespace std;
vector<ll>bit;
ll MOD = 1e9 + 7;
ll A, B, H, N, M, L, K, W, X, Y, Z;
ll ans = 0;

int main() {
	string S;
	cin >> S >> K;
	int i,k = 0;
	for (i = 0; i < S.size(); i++) {
		if (S[i] == '1') {
			k++;
			if (k == K)break;
		}
		else break;
	}
	cout << S[i] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>

#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <iterator>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define INF (1 << 30)
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back

#if DEBUG
#define _DEBUG(x) cout << #x << ": " << x << endl
#define _DDEBUG(x, y) cout << #x << ": " << x << ", " << #y << ": " << y << endl
#else
#define _DEBUG(x) ;
#define _DDEBUG(x, y) ;
#endif

#define ll long long
#define ull unsigned long long
#define MOD 1000000007

/** FOR VECTOR DEBUG */
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v)
{
    if (!v.empty())
    {
        out << '[';
        copy(v.begin(), v.end(), ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

/* template end */

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.precision(16);

    int n;
    cin >> n;
    vector<int> v(n);
    REP(i, n)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end(), std::greater<int>());

    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += v[i] - 1;
    }

#if DEBUG
    cout << "** RESULT **" << endl; // debug
    cout << v << endl;
#endif
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
a['___'],c;
main(i,j)
{
  for(;++i*i<1e6;)for(j=i;a[j+=i]=j<1e6;);
  for(;scanf("%d",&j),i=j;c=!printf("%d\n",c))
    for(;++j<=i*2;)c+=!a[j];
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y;
  cin>>x>>y;
  vector<int> z(y);
  for(int i=0;i<y;i++){
    cin>>z[i];
  }
  int a=0;
  for(int i=0;i<y;i++){
    a+=z[i];
  }
  if(x-a>=0){
  cout<<x-a<<endl;
  }
  else{
    cout<<-1<<endl;
  }
  
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int a, b;

int main() {
	cin >> a >> b;
	if (a==1) a += 13;
	if (b==1) b += 13;
	
	if (a>b) cout << "Alice" << ln;
	else if (a<b) cout << "Bob" << ln;
	else cout << "Draw" << ln;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n=parseInt(readline())
    h=parseMap(split(readline()))
    MAX=0
    ans=0
    for i in 1:n
        if h[i]>=MAX
            ans+=1
            MAX=h[i]
        end
    end
    println(ans)
end
main()

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

const long long MOD=1000000007;

int main(){
  string S;
  cin >> S;
  long long dp[100010][13]={};
  long long d=1;
  dp[S.size()][0]=1;
  for(int i=1; i<13; i++) dp[S.size()][i]=0;
  for(int i=S.size()-1; i>=0; i--){
    if(S[i]=='?'){
      for(int j=0; j<13; j++){
        for(int m=0; m<10; m++){
          dp[i][(j+m*d)%13]+=dp[i+1][j];
          dp[i][(j+m*d)%13]%=MOD;
        }
      }
    }else{
      long long a=S[i]-'0';
      for(int j=0; j<13; j++){
        dp[i][(j+a*d)%13]=dp[i+1][j];
      }
    }
    d=d*10%13;
  }
  cout << dp[0][5] << endl;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef pair<int,int> pairii;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int n,k,ma;
  ma=-1;
  cin>>k>>n;
  int cur=0;
  int c=0;
  int c1;
  cin>>c;
    c1=c;
  rep(i,n){
    
    if(cur>c)c+=k;
    ma=max(c-cur,ma);
    cur=c;
    cin>>c;
    
  }
  c1+=k;cerr<<c1;
  ma=max(c1-cur,ma);
  cout<<k-ma;
}

Measured memory_bytes: 256
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1] * (n + 1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0] * (n + 1)
 
    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if (self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
 
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if (x == y):
            return
            # 違う木に属していた場合rnkを見てくっつける方を決める
        elif (self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
 
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if (self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
 
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)
 
    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]
 
    def members(self, x):
        root = self.Find_Root(x)
        return [i for i in range(self.n) if self.Find_Root(i) == root]
 
    def roots(self):
        return [i for i, x in enumerate(self.root) if x < 0]
 
    def group_count(self):
        return len(self.roots())
 
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
 
    def size(self, x):
        return -self.root[self.Find_Root(x)]
 
 
n, m, k = map(int, input().split())
 
uf = UnionFind(n)
directcount = [0] * n
 
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    directcount[a] += 1
    directcount[b] += 1
    uf.Unite(a, b)
 
res = []
for _ in range(n):
    res.append( [0, -1] )
ures = []
 
for i in range(n):
    res[i][0] = uf.size(i) - directcount[i] -1
    res[i][1] = uf.Find_Root(i)
#print(res)
 
 
for i in range(k):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if res[c][1] == res[d][1]:
        res[c][0] -= 1
        res[d][0] -= 1
 
 
print(" ".join(list(map(lambda x: str(x[0]), res))))

Measured memory_bytes: 102104
import math
def roundup(x):
    return int(math.ceil(x/10))*10


def main():
    import math
    inlis = []
    roundlis = []
    gapdic = {}
    cnt = 0
    for i in range(5):
        a = int(input())
        inlis.append(a)
        roundlis.append(roundup(a))
        gap = roundup(a) - a
        gapdic[i] = gap
    
    gapdic= sorted(gapdic.items(), key = lambda x:x[1])
    num = 1
    ans = 0
    for tup in gapdic:
        if num != len(inlis):
            ans += roundlis[tup[0]]
            #print(tup, roundlis[tup[0]])
        else:
            ans += inlis[tup[0]]
        num += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 62272
<?php
// Here your code !
# $ans = ($a+$b)/($c-$d)
$n = intval(trim(fgets(STDIN)));
$a = explode(' ',trim(fgets(STDIN)));
sort($a);

$ans = 0.0;
$array = range(1, $n);
foreach ($array as $i) {
    $cd = @$a[$i] - $a[$i-1];

    if ($i == $n-1) {
        // ????°???????2??????????¨?
        $ab = $a[$n-3] + $a[$n-4];
    } elseif ($i == $n-2) {
        // ?????§??? + ????°????
        $ab = $a[$n-1] + $a[$n-4];
    } else {
        // ?????§??????2??????????¨?
        $ab = $a[$n-1] + $a[$n-2];
    }
    $ans = max($ans, $ab/$cd);
}
echo $ans . "\n";

Measured memory_bytes: 15728
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1e5 + 1000;
typedef pair<int, int> P;
P p[maxn];

int main()
{
	std::ios::sync_with_stdio(false);
	int N; int M;
	cin >> N >> M;
	for (int i = 1; i <= M; i++)
		cin >> p[i].first >> p[i].second;

	int L = 1; int R = N;
	bool flag = true;
	for (int i = 1; i <= M && flag; i++)
	{
		L = max(L, p[i].first);
		R = min(R, p[i].second);
		if (L > R) flag = false;
	}

	cout << max(0, R - L + 1);
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=6005;
int mod;
inline int Add(int x,int y){
    return (x+=y)>=mod?x-mod:x;
}
inline int Sub(int x,int y){
    return (x-=y)>=0?x:x+mod;
}
inline int Mul(int x,int y){
    return 1ll*x*y%mod;
}
inline int Pow(int x,int y){
    int res=1;
    while(y){
        if(y&1)res=1ll*res*x%mod;
        y>>=1;
        x=1ll*x*x%mod;
    }
    return res;
}
int dp[max_n][max_n*2];
int inv[max_n];
int n;
int main(){
    scanf("%d%d",&n,&mod);
    n*=3;
    inv[1]=1;
    for(int i=2;i<=n;i++)inv[i]=Mul(inv[mod%i],mod-mod/i);
    dp[0][n]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<=2*n;j++){
            if(dp[i][j]==0)continue;
            dp[i+1][j+1]=Add(dp[i+1][j+1],Mul(dp[i][j],inv[i+1]));
            if(j)dp[i+2][j-1]=Add(dp[i+2][j-1],Mul(dp[i][j],inv[i+2]));
            dp[i+3][j]=Add(dp[i+3][j],Mul(dp[i][j],inv[i+3]));
        }
    }
    int ans=0;
    for(int i=0;i<=n;i++)ans=Add(ans,dp[n][i+n]);
    for(int i=1;i<=n;i++)ans=Mul(ans,i);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 279936
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a) = min((a),(b))
#define CHMAX(a,b) (a) = max((a),(b))

int main()
{
    int n,p;
    while(1==1)
    {
        scanf("%d %d\n",&n,&p);
        if(n==0&&p==0)return 0;
        int ko[55]={};
        int zan=p;
        int poi=0;
        int judge=0;
        while(judge==0)
        {
            for(int i=0;i<n;i++)ko[i]+=zan/n;
            zan-=(zan/n)*n;
            while(zan>0)
            {
                ko[poi]++;
                if(ko[poi]==p)
                {
                    printf("%d\n",poi);
                    judge=1;
                    break;
                }
                zan--;
                poi++;
                if(poi>=n)poi-=n;
            }
            if(judge==1)break;
            while(zan==0)
            {
                if(ko[poi]>0)
                {
                    zan=ko[poi];
                    ko[poi]=0;
                }
                poi++;
                if(poi>=n)poi-=n;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3124
import java.util.*;

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

        Set<Integer> numbers = new HashSet<>();
        N = Integer.parseInt(scanner.next());

        for (int i = 0; i < N; i++) {
            numbers.add(Integer.parseInt(scanner.next()));
        }

        System.out.println(numbers.size());
    }
}

Measured memory_bytes: 21844
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	x := nextInt()
	a := nextInt()
	if x < a {
		fmt.Println("0")
	} else {
		fmt.Println("10")
	}
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

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

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
 
#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
 
struct edge {
	int to,cost;
	edge(int t,ll c):to(t),cost(c) {}
};
 
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int ddx[]={1,1,1,0,-1,-1,-1,0},ddy[]={1,0,-1,-1,-1,0,1,1};
 
//-----------------------------------------------------------------------------
 
int n;
map<ll,ll> mp;
const int mod=1e9+7;
 
void calc(ll m) {
	ll a=2;
	while (m>=a*a) {
		if(m%a==0) {
			mp[a]++,m/=a;
		}
		else a++;
	}
	mp[m]++;
}
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	cin>>n;
	if(n==1) {
		cout<<1<<endl;
		return 0;
	}
	FOR(i,2,n+1) {
		calc(i);
	}
 
	ll ans=1;
	for(auto x:mp) {
		(ans*=(x.se+1))%=mod;
	}
	cout<<ans%mod<<endl;
 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <unordered_map>
using namespace std;


int main(){
    int n, q;
    cin >> n >> q;
    char s[n + 1];
    int ac[n + 1];
    for (int i = 1; i <= n; i++){
        cin >> s[i];
        if (i == 1){
            ac[i] = 0;
        }
        else if (s[i] == 'C' && s[i - 1] == 'A'){
            ac[i] = ac[i - 1] + 1;
        }
        else {
            ac[i] = ac[i - 1];
        }
    }
    int l, r;
    for (int i = 0; i < q; i++){
        cin >> l >> r;
        cout << ac[r] - ac[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 n;
vector<int> tree[100005];
vector<int> dist;

void dfs(int v, int d = 0, int p = -1){
    dist[v] = d;
    for(auto u : tree[v]) {
        if(u == p) continue;
        dfs(u, d + 1, v);
    }
}

vector<int> calcDist(int s){
    dist = vector<int>(n);
    dfs(s);
    return dist;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int u, v;
    cin >> n >> u >> v;
    u--; v--;
    rep(i,n-1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    vector<int> distS = calcDist(u);
    vector<int> distT = calcDist(v);
    int ans = 0;
    rep(i,n){
        if(distS[i] < distT[i]) chmax(ans, distT[i]);
    }
    ans--;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10744
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;
const int INF = 1000000007;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);

    int N, W;
    cin >> N >> W;
    int w[N], v[N];
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
    }

    int dp[100005];
    fill(dp, dp+100005, INF);
    dp[0] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 100000; j > 0; j--) {
            if (dp[j] < INF && dp[j] + w[i] <= W) {
                dp[j+v[i]] = min(dp[j+v[i]], dp[j] + w[i]);
            }
        }
        dp[v[i]] = min(dp[v[i]], w[i]);
    }

    for (int i = 100000; i > 0; i--) {
        if (dp[i] < INF) {
            cout << i << "\n";
            break;
        }
    }
    return 0;
}

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

using namespace std;

int main(){
	int N; cin >> N;
	vector<long long> Xs(N);
	vector<long long> Ys(N);
	vector<array<long long, 2>> rooks(N);
	for (int i = 0; i < N; i++) {
		int x, y; cin >> x >> y;
		Xs[i] = x, Ys[i] = y;
		rooks[i] = {x, y};
	}
	sort(Xs.begin(), Xs.end());
	sort(Ys.begin(), Ys.end());
	vector<int> P(N);
	vector<int> invP(N);
	vector<int> rookID(N);
	for (int i = 0; i < N; i++) {
		int x = int(lower_bound(Xs.begin(), Xs.end(), rooks[i][0]) - Xs.begin());
		int y = int(lower_bound(Ys.begin(), Ys.end(), rooks[i][1]) - Ys.begin());
		rookID[x] = i;
		P[x] = y;
		invP[y] = x;
	}

	vector<long long> ans(N);

	vector<array<int, 2>> runs; runs.reserve(N);
	for (int i = 0; i < N; i++) {
		int j = i;
		while (j+1 < N && abs(P[j] - P[j+1]) == 1) {
			j++;
		}
		runs.push_back({i,j});
		i = j;
	}

	int R = int(runs.size());
	for (int st = 0; st < R; st++) {
		int a = st, b = st;
		int x0 = runs[st][0], y0 = P[x0];
		int x1 = runs[st][1], y1 = P[x1];
		long long cost[2][2];
		cost[0][0] = cost[1][1] = 2 * (abs(Xs[x0] - Xs[x1]) + abs(Ys[y0] - Ys[y1]));
		cost[0][1] = cost[1][0] = abs(Xs[x0] - Xs[x1]) + abs(Ys[y0] - Ys[y1]);
		while (true) {
			assert(x0 <= x1 && abs(x0 - x1) == abs(y0 - y1));
			bool can_left = x0-1 >= 0 && abs(P[x0-1] - y1) == 1;
			bool can_right = x1+1 < N && abs(P[x1+1] - y0) == 1;
			if (!(can_left || can_right)) break;
			if (can_left) a--;
			if (can_right) b++;
			int nx0, ny0, nx1, ny1;
			if (can_left) {
				nx0 = runs[a][0];
				ny0 = P[nx0];
			} else {
				nx0 = x0;
				ny0 = y1;
			}
			if (can_right) {
				nx1 = runs[b][1];
				ny1 = P[nx1];
			} else {
				nx1 = x1;
				ny1 = y0;
			}

			for (int s = 0; s < 2; s++) {
				long long nc0 = min(
					cost[s][0] + abs(Xs[x0] - Xs[nx0]) + abs(Ys[y0] - Ys[ny0]),
					cost[s][1] + abs(Xs[x1] - Xs[nx0]) + abs(Ys[y1] - Ys[ny0])
				);
				long long nc1 = min(
					cost[s][0] + abs(Xs[x0] - Xs[nx1]) + abs(Ys[y0] - Ys[ny1]),
					cost[s][1] + abs(Xs[x1] - Xs[nx1]) + abs(Ys[y1] - Ys[ny1])
				);
				long long nd = abs(Xs[nx0] - Xs[nx1]) + abs(Ys[ny0] - Ys[ny1]);
				if (can_left && can_right) {
					cost[s][0] = nc1 + nd;
					cost[s][1] = nc0 + nd;
				} else if (can_left) {
					cost[s][0] = nc0;
					cost[s][1] = nc0 + nd;
				} else if (can_right) {
					cost[s][0] = nc1 + nd;
					cost[s][1] = nc1;
				} else assert(false);
			}

			x0 = nx0;
			y0 = ny0;
			x1 = nx1;
			y1 = ny1;
		}

		int num_rooks = x1 - x0 + 1;
		for (int i = runs[st][0]; i <= runs[st][1]; i++) {
			long long cnds[2];
			for (int z = 0; z < 2; z++) {
				cnds[z] = abs(Xs[i] - Xs[runs[st][z]]) + abs(Ys[P[i]] - Ys[P[runs[st][z]]]) + min(cost[z][0], cost[z][1]);
			}
			ans[rookID[i]] = min(cnds[0], cnds[1]) - (num_rooks - 1);
		}
	}

	for (int i = 0; i < N; i++) {
		cout << ans[i] << '\n';
	}

	return 0;
}


Measured memory_bytes: 14688
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int x;
    cin>>x;
    if (x==3 || x==5 || x==7)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

lint n;
int c[MAX], par[MAX];
vector<int> to[MAX];

lint vec[MAX], sz[MAX], d[MAX];

void dfs(int i, int p){
    lint x = 0;
    par[i] = p;
    for(int j : to[i]){
        if(j == p) continue;
        lint tmp = vec[c[i]];
        dfs(j, i);
        sz[i] += sz[j];
        d[j] = sz[j] - (vec[c[i]] - tmp);
        x += vec[c[i]] - tmp;
    }
    vec[c[i]] += sz[i] - x;
}

lint ans[MAX], sp[MAX];
void solve(){
    rep(i, n) ans[i] = 0;
    rep(i, n) sp[i] = n;

    rep(i, n){
        for(int j : to[i]){
            if(j == par[i]) continue;
            ans[c[i]] += d[j]*(d[j]+1)/2;
            sp[c[i]] -= d[j];
        }
        sp[c[i]]--;
    }

    rep(i, n){
        ans[i] += sp[i]*(sp[i]+1)/2;
    }
}

int main(){
    cin >> n;
    rep(i, n){
        cin >> c[i]; c[i]--;
    }
    rep(i, n-1){
        int a, b; cin >> a >> b; a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    rep(i, n) sz[i] = 1;
    dfs(0, -1);
    solve();

    rep(i, n){
        out(n*(n+1)/2 - ans[i]);
    }
}

Measured memory_bytes: 42684
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in); 
		//int型の値を返す
		int a = scanner.nextInt();
		//int型の値を返す
		int b = scanner.nextInt();
		//int型の値を返す
		int c = scanner.nextInt();
		//入力された3つのint型が「a<b<c」になるか否かを判定する
		String ans = extent(a, b, c);
		System.out.println(ans);
	}
	
	/**
	 * 入力された3つのint型が「a<b<c」になるか否かを判定する
	 * @param int a
	 * @param int b
	 * @param int c
	 * @return ans
	 */
	public static String extent(int a, int b, int c) {
		String ans = "No";
		if(a < b && b < c){
			ans = "Yes";
		}
		return ans;
	}
	
}

/**
 * 3つのint型のa,b,c値を入力する
 * 入力された3つのint型が「a<b<c」になるか否かを判定する
 * (「a<b<c」だとしたら"Yes")
 * (「a<b<c」じゃなかったら"No")
 * 返されたString型を出力をする
 */

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

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

#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()

const int N = 52;

ll n, target, ans, x[N], dp[N][N][N * N]; // prefix, taken, sum

int main() {
	cin >> n >> target;
	for (ll i = 1; i <= n; i++)
		cin >> x[i];	
	for (ll i = 0; i <= n; i++)
		dp[i][0][0] = 1;
	for (ll i = 1; i <= n; i++)
		for (ll s = 0; s <= n * target; s++)
			for (ll j = 1; j <= i; j++) {
					dp[i][j][s] = dp[i - 1][j][s];
					if (x[i] <= s) 
						dp[i][j][s] += dp[i - 1][j - 1][s - x[i]];
				}
	for (ll i = 1; i <= n; i++)
		ans += dp[n][i][i * target];
	cout << ans;
}


Measured memory_bytes: 30820
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define mkt make_tuple
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N;
ll C, x[100002], v[100002], MAX;
pair<ll, lP>r[100002], l[100002], r2[100002], l2[100002];

int main(){
	cin >> N >> C;
	for (int i = 1; i != N + 1; ++i) {
		cin >> x[i] >> v[i];
	}
	x[N + 1] = C;
	for (int i = 1; i != N + 2; ++i) {
		r[i].first = r[i - 1].first + v[i] - x[i] + x[i - 1];
		r2[i].first = r2[i - 1].first + v[i] + (x[i - 1] - x[i]) * 2;
		if (r[i].first > r[i - 1].second.first)
			r[i].second = mkp(r[i].first, i);
		else
			r[i].second = r[i - 1].second;
		if (r2[i].first > r2[i - 1].second.first)
			r2[i].second = mkp(r2[i].first, i);
		else
			r2[i].second = r2[i - 1].second;
	}
	for (int i = N; i != -1; --i) {
		l[i].first = l[i + 1].first + v[i] - x[i + 1] + x[i];
		l2[i].first = l2[i + 1].first + v[i] + (x[i] - x[i + 1]) * 2;
		if (l[i].first > l[i + 1].second.first)
			l[i].second = mkp(l[i].first, i);
		else
			l[i].second = l[i + 1].second;
		if (l2[i].first > l2[i + 1].second.first)
			l2[i].second = mkp(l2[i].first, i);
		else
			l2[i].second = l2[i + 1].second;
	}
	for (int i = 0; i != N + 1; ++i) {
		MAX = max({ MAX,r[i].second.first + l2[i + 1].second.first,r2[i].second.first + l[i + 1].second.first });
	}
	cout << MAX << endl;
	return 0;
}

Measured memory_bytes: 11136
(defun get-max (data start end)
  (if (zerop start)
      (aref data (1- end))
      (- (aref data (1- end))
         (aref data (1- start)))))

(defun get-diff (data start-point second-point end-point)
  (abs (- (get-max data second-point end-point)
          (get-max data start-point second-point))))

(defun equal-cut ()
  (let* ((n (read))
         (data (make-array n :initial-contents (loop repeat n
                                                     sum (read) into summed-a
                                                     collect summed-a))))
    (loop for second-separator from 2 below (1- n)
          with first-separator = 1
          with third-separator = 3
          with minimized-diff = #.(* (* 2 (expt 10 5)) (expt 10 9))
          when (>= second-separator third-separator)
            do (setq third-separator (1+ second-separator))
          do
             (progn (loop (if (and (< first-separator (1- second-separator))
                                   (< (get-diff data 0 (1+ first-separator) second-separator)
                                      (get-diff data 0 first-separator second-separator)))
                              (incf first-separator)
                              (return)))
                    (loop (if (and (< third-separator (1- n))
                                   (< (get-diff data second-separator (1+ third-separator) n)
                                      (get-diff data second-separator third-separator n)))
                              (incf third-separator)
                              (return)))
                    (let* ((max-list (list (get-max data 0 first-separator)
                                           (get-max data first-separator second-separator)
                                           (get-max data second-separator third-separator)
                                           (get-max data third-separator n)))
                           (diff (- (apply #'max max-list) (apply #'min max-list))))
                      (if (< diff minimized-diff)
                          (setq minimized-diff diff))))
          finally (princ minimized-diff))))

(equal-cut)

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

int main() {
    int d,g;
    cin >> d >> g;
    vector<int> p(d),c(d);
    for(int i = 0; i < d; i++)
    {
        cin >> p.at(i) >> c.at(i);
    }
    
    int cnt;
    int min_cnt = 10000;
    int score;
    for(int bit = 0; bit <= pow(2, d) - 1; bit++)
    {
        score = 0;
        cnt = 0;
        for(int i = 0; i < d; i++)
        {
            if (bit & 1<<i) {
                score += p.at(i) * 100 * (i + 1) + c.at(i);
                cnt += p.at(i);
            }
        }
        for (int j = d - 1; j >= 0; j--) {
            if (!(bit & 1<<j)) {
                if (score + (p.at(j) - 1) * 100 * (j + 1) >= g) {
                    while (score < g) {
                        score += 100 * (j + 1);
                        cnt++;
                    }
                }
                break;
            }
        }
        if (score >= g) {
            min_cnt = min(min_cnt, cnt);
        }
    }
    cout << min_cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n, m;
	cin >> n >> m;

	if (n == 1 && m == 1) {
		cout << 1 << endl;
	}
	else if (n == 1 || m == 1) {
		cout << max(n - 2, m - 2) << endl;
	}
	else {
		cout << n * m - 2 * (n + m) + 4 << endl;
	}
}


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

int main() {
  int K, X;
  cin >> K >> X;
  bool first = true;
  for (int i = -1e6; i <= 1e6; i++) {
    if (i >= X - K + 1 && i <= X + K - 1) {
      if (first) {
        first = false;
      } else {
        cout << " ";
      }
      cout << i;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
#define rep(k,n) for(int k = 0 ; k < 7 ; k++)

int main(){
    string str;
    int n;
    
    cin >> n;
    getline(cin,str);
    while(n--){
        getline(cin,str);
        for(int j = 0 ; j < str.length() ; j++){
            string key = str.substr(j,7),repl;
            if(key == "Hoshino"){
                repl = "Hoshina";
                rep(k,n) str[j+k] = repl[k];
            }
        }
        cout << str << endl;
    }
    return 0;
}

Measured memory_bytes: 1220